[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0fb2500 | 2012-10-12 07:20:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #ifndef CC_TREES_LAYER_TREE_HOST_IMPL_H_ |
| 6 | #define CC_TREES_LAYER_TREE_HOST_IMPL_H_ |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 7 | |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 11 | #include "base/basictypes.h" |
| 12 | #include "base/memory/scoped_ptr.h" |
| 13 | #include "base/time.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 14 | #include "cc/animation/animation_events.h" |
| 15 | #include "cc/animation/animation_registrar.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 16 | #include "cc/base/cc_export.h" |
[email protected] | e4c3c87a | 2013-04-22 02:28:40 | [diff] [blame] | 17 | #include "cc/debug/latency_info.h" |
[email protected] | 3052b10f | 2013-03-18 07:41:21 | [diff] [blame] | 18 | #include "cc/input/input_handler.h" |
| 19 | #include "cc/input/top_controls_manager_client.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 20 | #include "cc/layers/layer_lists.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 21 | #include "cc/layers/render_pass_sink.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 22 | #include "cc/output/output_surface_client.h" |
| 23 | #include "cc/output/renderer.h" |
[email protected] | 89e8267a | 2013-03-18 07:50:56 | [diff] [blame] | 24 | #include "cc/quads/render_pass.h" |
[email protected] | e12dd0e | 2013-03-18 08:24:40 | [diff] [blame] | 25 | #include "cc/resources/tile_manager.h" |
[email protected] | b9dcf43a | 2013-01-09 00:15:29 | [diff] [blame] | 26 | #include "skia/ext/refptr.h" |
[email protected] | ddf9df8 | 2012-10-16 06:52:46 | [diff] [blame] | 27 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | b9dcf43a | 2013-01-09 00:15:29 | [diff] [blame] | 28 | #include "third_party/skia/include/core/SkPicture.h" |
[email protected] | 167ed9d5 | 2012-10-31 20:47:58 | [diff] [blame] | 29 | #include "ui/gfx/rect.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 30 | |
| 31 | namespace cc { |
| 32 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 33 | class CompletionEvent; |
[email protected] | bf189f6 | 2012-12-18 03:42:11 | [diff] [blame] | 34 | class CompositorFrameMetadata; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 35 | class DebugRectHistory; |
| 36 | class FrameRateCounter; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 37 | class LayerImpl; |
| 38 | class LayerTreeHostImplTimeSourceAdapter; |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 39 | class LayerTreeImpl; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 40 | class PageScaleAnimation; |
[email protected] | 0edbfbe9f | 2013-01-17 03:33:03 | [diff] [blame] | 41 | class PaintTimeCounter; |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 42 | class MemoryHistory; |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 43 | class RenderingStatsInstrumentation; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 44 | class RenderPassDrawQuad; |
| 45 | class ResourceProvider; |
[email protected] | 3ba4cae | 2013-01-16 03:58:38 | [diff] [blame] | 46 | class TopControlsManager; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 47 | struct RendererCapabilities; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 48 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 49 | // LayerTreeHost->Proxy callback interface. |
| 50 | class LayerTreeHostImplClient { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 51 | public: |
| 52 | virtual void DidLoseOutputSurfaceOnImplThread() = 0; |
| 53 | virtual void OnSwapBuffersCompleteOnImplThread() = 0; |
| 54 | virtual void OnVSyncParametersChanged(base::TimeTicks timebase, |
| 55 | base::TimeDelta interval) = 0; |
[email protected] | 7ed4751 | 2013-03-26 22:28:45 | [diff] [blame] | 56 | virtual void DidVSync(base::TimeTicks frame_time) = 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 57 | virtual void OnCanDrawStateChanged(bool can_draw) = 0; |
| 58 | virtual void OnHasPendingTreeStateChanged(bool has_pending_tree) = 0; |
| 59 | virtual void SetNeedsRedrawOnImplThread() = 0; |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame^] | 60 | virtual void SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) = 0; |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 61 | virtual void DidInitializeVisibleTileOnImplThread() = 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 62 | virtual void SetNeedsCommitOnImplThread() = 0; |
| 63 | virtual void SetNeedsManageTilesOnImplThread() = 0; |
| 64 | virtual void PostAnimationEventsToMainThreadOnImplThread( |
| 65 | scoped_ptr<AnimationEventsVector> events, |
| 66 | base::Time wall_clock_time) = 0; |
| 67 | // Returns true if resources were deleted by this call. |
| 68 | virtual bool ReduceContentsTextureMemoryOnImplThread( |
| 69 | size_t limit_bytes, |
| 70 | int priority_cutoff) = 0; |
| 71 | virtual void ReduceWastedContentsTextureMemoryOnImplThread() = 0; |
| 72 | virtual void SendManagedMemoryStats() = 0; |
| 73 | virtual bool IsInsideDraw() = 0; |
| 74 | virtual void RenewTreePriority() = 0; |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 75 | virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) = 0; |
[email protected] | ef915f53 | 2013-04-22 20:56:32 | [diff] [blame] | 76 | virtual void DidReceiveLastInputEventForVSync(base::TimeTicks frame_time) = 0; |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 77 | |
| 78 | protected: |
| 79 | virtual ~LayerTreeHostImplClient() {} |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 80 | }; |
| 81 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 82 | // LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering |
| 83 | // state. |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 84 | class CC_EXPORT LayerTreeHostImpl : public InputHandlerClient, |
| 85 | public RendererClient, |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 86 | public TileManagerClient, |
[email protected] | 3ba4cae | 2013-01-16 03:58:38 | [diff] [blame] | 87 | public OutputSurfaceClient, |
| 88 | public TopControlsManagerClient { |
[email protected] | e216fef0 | 2013-03-20 22:56:10 | [diff] [blame] | 89 | public: |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 90 | static scoped_ptr<LayerTreeHostImpl> Create( |
| 91 | const LayerTreeSettings& settings, |
| 92 | LayerTreeHostImplClient* client, |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 93 | Proxy* proxy, |
| 94 | RenderingStatsInstrumentation* rendering_stats_instrumentation); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 95 | virtual ~LayerTreeHostImpl(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 96 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 97 | // InputHandlerClient implementation |
| 98 | virtual InputHandlerClient::ScrollStatus ScrollBegin( |
| 99 | gfx::Point viewport_point, |
| 100 | InputHandlerClient::ScrollInputType type) OVERRIDE; |
| 101 | virtual bool ScrollBy(gfx::Point viewport_point, |
| 102 | gfx::Vector2dF scroll_delta) OVERRIDE; |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 103 | virtual bool ScrollVerticallyByPage( |
| 104 | gfx::Point viewport_point, |
| 105 | WebKit::WebScrollbar::ScrollDirection direction) OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 106 | virtual void ScrollEnd() OVERRIDE; |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 107 | virtual InputHandlerClient::ScrollStatus FlingScrollBegin() OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 108 | virtual void PinchGestureBegin() OVERRIDE; |
| 109 | virtual void PinchGestureUpdate(float magnify_delta, |
| 110 | gfx::Point anchor) OVERRIDE; |
| 111 | virtual void PinchGestureEnd() OVERRIDE; |
| 112 | virtual void StartPageScaleAnimation(gfx::Vector2d target_offset, |
| 113 | bool anchor_point, |
| 114 | float page_scale, |
| 115 | base::TimeTicks start_time, |
| 116 | base::TimeDelta duration) OVERRIDE; |
| 117 | virtual void ScheduleAnimation() OVERRIDE; |
| 118 | virtual bool HaveTouchEventHandlersAt(gfx::Point viewport_port) OVERRIDE; |
[email protected] | ef915f53 | 2013-04-22 20:56:32 | [diff] [blame] | 119 | virtual void DidReceiveLastInputEventForVSync( |
| 120 | base::TimeTicks frame_time) OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 121 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 122 | // TopControlsManagerClient implementation. |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 123 | virtual void DidChangeTopControlsPosition() OVERRIDE; |
| 124 | virtual bool HaveRootScrollLayer() const OVERRIDE; |
[email protected] | 3ba4cae | 2013-01-16 03:58:38 | [diff] [blame] | 125 | |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 126 | void StartScrollbarAnimation(base::TimeTicks now); |
| 127 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 128 | struct CC_EXPORT FrameData : public RenderPassSink { |
| 129 | FrameData(); |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 130 | virtual ~FrameData(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 131 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 132 | std::vector<gfx::Rect> occluding_screen_space_rects; |
| 133 | std::vector<gfx::Rect> non_occluding_screen_space_rects; |
| 134 | RenderPassList render_passes; |
| 135 | RenderPassIdHashMap render_passes_by_id; |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 136 | const LayerImplList* render_surface_layer_list; |
| 137 | LayerImplList will_draw_layers; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 138 | bool contains_incomplete_tile; |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 139 | bool has_no_damage; |
[email protected] | e4c3c87a | 2013-04-22 02:28:40 | [diff] [blame] | 140 | LatencyInfo latency_info; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 141 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 142 | // RenderPassSink implementation. |
| 143 | virtual void AppendRenderPass(scoped_ptr<RenderPass> render_pass) OVERRIDE; |
| 144 | }; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 145 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 146 | virtual void BeginCommit(); |
| 147 | virtual void CommitComplete(); |
| 148 | virtual void Animate(base::TimeTicks monotonic_time, |
| 149 | base::Time wall_clock_time); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 150 | virtual void UpdateAnimationState(bool start_ready_animations); |
| 151 | void UpdateBackgroundAnimateTicking(bool should_background_tick); |
[email protected] | b9d4a36 | 2013-04-23 05:36:27 | [diff] [blame] | 152 | void SetViewportDamage(gfx::Rect damage_rect); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 153 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 154 | void ManageTiles(); |
[email protected] | f845661 | 2013-03-19 20:56:09 | [diff] [blame] | 155 | void SetAnticipatedDrawTime(base::TimeTicks time); |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 156 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 157 | // Returns false if problems occured preparing the frame, and we should try |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 158 | // to avoid displaying the frame. If PrepareToDraw is called, DidDrawAllLayers |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 159 | // must also be called, regardless of whether DrawLayers is called between the |
| 160 | // two. |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 161 | virtual bool PrepareToDraw(FrameData* frame, |
| 162 | gfx::Rect device_viewport_damage_rect); |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 163 | virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 164 | // Must be called if and only if PrepareToDraw was called. |
| 165 | void DidDrawAllLayers(const FrameData& frame); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 166 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 167 | const LayerTreeSettings& settings() const { return settings_; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 168 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 169 | // Returns the currently visible viewport size in DIP. This value excludes |
| 170 | // the URL bar and non-overlay scrollbars. |
| 171 | gfx::SizeF VisibleViewportSize() const; |
| 172 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 173 | // RendererClient implementation |
| 174 | private: |
| 175 | virtual gfx::Size DeviceViewportSize() const OVERRIDE; |
| 176 | virtual const LayerTreeSettings& Settings() const OVERRIDE; |
| 177 | public: |
| 178 | virtual void DidLoseOutputSurface() OVERRIDE; |
| 179 | virtual void OnSwapBuffersComplete() OVERRIDE; |
| 180 | virtual void SetFullRootLayerDamage() OVERRIDE; |
| 181 | virtual void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy) |
| 182 | OVERRIDE; |
| 183 | virtual void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) |
| 184 | OVERRIDE; |
| 185 | virtual bool HasImplThread() const OVERRIDE; |
| 186 | virtual bool ShouldClearRootRenderPass() const OVERRIDE; |
| 187 | virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const OVERRIDE; |
[email protected] | 7367359 | 2013-04-03 22:14:32 | [diff] [blame] | 188 | virtual bool AllowPartialSwap() const OVERRIDE; |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 189 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 190 | // TileManagerClient implementation. |
| 191 | virtual void ScheduleManageTiles() OVERRIDE; |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 192 | virtual void DidInitializeVisibleTile() OVERRIDE; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 193 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 194 | // OutputSurfaceClient implementation. |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame^] | 195 | virtual void SetNeedsRedrawRect(gfx::Rect rect) OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 196 | virtual void OnVSyncParametersChanged(base::TimeTicks timebase, |
| 197 | base::TimeDelta interval) OVERRIDE; |
[email protected] | 7ed4751 | 2013-03-26 22:28:45 | [diff] [blame] | 198 | virtual void DidVSync(base::TimeTicks frame_time) OVERRIDE; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 199 | virtual void OnSendFrameToParentCompositorAck(const CompositorFrameAck& ack) |
| 200 | OVERRIDE; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 201 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 202 | // Called from LayerTreeImpl. |
| 203 | void OnCanDrawStateChangedForTree(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 204 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 205 | // Implementation |
| 206 | bool CanDraw(); |
| 207 | OutputSurface* output_surface() const { return output_surface_.get(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 208 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 209 | std::string LayerTreeAsText() const; |
| 210 | std::string LayerTreeAsJson() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 211 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 212 | void FinishAllRendering(); |
| 213 | int SourceAnimationFrameNumber() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 214 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 215 | virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface); |
| 216 | bool IsContextLost(); |
| 217 | TileManager* tile_manager() { return tile_manager_.get(); } |
| 218 | Renderer* renderer() { return renderer_.get(); } |
| 219 | const RendererCapabilities& GetRendererCapabilities() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 220 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 221 | virtual bool SwapBuffers(const FrameData& frame); |
[email protected] | 7ed4751 | 2013-03-26 22:28:45 | [diff] [blame] | 222 | void EnableVSyncNotification(bool enable); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 223 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 224 | void Readback(void* pixels, gfx::Rect rect_in_device_viewport); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 225 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 226 | LayerTreeImpl* active_tree() { return active_tree_.get(); } |
| 227 | const LayerTreeImpl* active_tree() const { return active_tree_.get(); } |
| 228 | LayerTreeImpl* pending_tree() { return pending_tree_.get(); } |
| 229 | const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); } |
| 230 | const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); } |
| 231 | void CreatePendingTree(); |
| 232 | void CheckForCompletedTileUploads(); |
| 233 | virtual bool ActivatePendingTreeIfNeeded(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 234 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 235 | // Shortcuts to layers on the active tree. |
| 236 | LayerImpl* RootLayer() const; |
| 237 | LayerImpl* RootScrollLayer() const; |
| 238 | LayerImpl* CurrentlyScrollingLayer() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 239 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 240 | virtual void SetVisible(bool visible); |
| 241 | bool visible() const { return visible_; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 242 | |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 243 | void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); } |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 244 | void SetNeedsRedraw() { client_->SetNeedsRedrawOnImplThread(); } |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 245 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 246 | size_t memory_allocation_limit_bytes() const { |
[email protected] | 46b8acc | 2013-03-19 22:38:35 | [diff] [blame] | 247 | return managed_memory_policy_.bytes_limit_when_visible; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 248 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 249 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 250 | void SetViewportSize(gfx::Size device_viewport_size); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 251 | gfx::Size device_viewport_size() const { return device_viewport_size_; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 252 | |
[email protected] | d908376 | 2013-03-24 01:36:40 | [diff] [blame] | 253 | void SetOverdrawBottomHeight(float overdraw_bottom_height); |
| 254 | float overdraw_bottom_height() const { return overdraw_bottom_height_; } |
| 255 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 256 | void SetDeviceScaleFactor(float device_scale_factor); |
| 257 | float device_scale_factor() const { return device_scale_factor_; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 258 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 259 | scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 260 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 261 | bool needs_animate_layers() const { |
| 262 | return !animation_registrar_->active_animation_controllers().empty(); |
| 263 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 264 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 265 | void SendManagedMemoryStats( |
| 266 | size_t memory_visible_bytes, |
| 267 | size_t memory_visible_and_nearby_bytes, |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 268 | size_t memory_use_bytes); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 269 | |
[email protected] | d7626ffd | 2013-03-29 00:17:42 | [diff] [blame] | 270 | void set_max_memory_needed_bytes(size_t bytes) { |
| 271 | max_memory_needed_bytes_ = bytes; |
| 272 | } |
| 273 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 274 | FrameRateCounter* fps_counter() { |
| 275 | return fps_counter_.get(); |
| 276 | } |
| 277 | PaintTimeCounter* paint_time_counter() { |
| 278 | return paint_time_counter_.get(); |
| 279 | } |
| 280 | MemoryHistory* memory_history() { |
| 281 | return memory_history_.get(); |
| 282 | } |
| 283 | DebugRectHistory* debug_rect_history() { |
| 284 | return debug_rect_history_.get(); |
| 285 | } |
| 286 | ResourceProvider* resource_provider() { |
| 287 | return resource_provider_.get(); |
| 288 | } |
| 289 | TopControlsManager* top_controls_manager() { |
| 290 | return top_controls_manager_.get(); |
| 291 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 292 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 293 | Proxy* proxy() const { return proxy_; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 294 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 295 | AnimationRegistrar* animation_registrar() const { |
| 296 | return animation_registrar_.get(); |
| 297 | } |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 298 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 299 | void SetDebugState(const LayerTreeDebugState& debug_state); |
| 300 | const LayerTreeDebugState& debug_state() const { return debug_state_; } |
[email protected] | f511afb | 2012-11-30 01:55:20 | [diff] [blame] | 301 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 302 | class CC_EXPORT CullRenderPassesWithCachedTextures { |
| 303 | public: |
| 304 | bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad, |
| 305 | const FrameData& frame) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 306 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 307 | // Iterates from the root first, in order to remove the surfaces closest |
| 308 | // to the root with cached textures, and all surfaces that draw into |
| 309 | // them. |
| 310 | size_t RenderPassListBegin(const RenderPassList& list) const { |
| 311 | return list.size() - 1; |
| 312 | } |
| 313 | size_t RenderPassListEnd(const RenderPassList& list) const { return 0 - 1; } |
| 314 | size_t RenderPassListNext(size_t it) const { return it - 1; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 315 | |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 316 | explicit CullRenderPassesWithCachedTextures(Renderer* renderer) |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 317 | : renderer_(renderer) {} |
| 318 | private: |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 319 | Renderer* renderer_; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 320 | }; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 321 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 322 | class CC_EXPORT CullRenderPassesWithNoQuads { |
| 323 | public: |
| 324 | bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad, |
| 325 | const FrameData& frame) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 326 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 327 | // Iterates in draw order, so that when a surface is removed, and its |
| 328 | // target becomes empty, then its target can be removed also. |
| 329 | size_t RenderPassListBegin(const RenderPassList& list) const { return 0; } |
| 330 | size_t RenderPassListEnd(const RenderPassList& list) const { |
| 331 | return list.size(); |
| 332 | } |
| 333 | size_t RenderPassListNext(size_t it) const { return it + 1; } |
| 334 | }; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 335 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 336 | template <typename RenderPassCuller> |
| 337 | static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 338 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 339 | skia::RefPtr<SkPicture> CapturePicture(); |
[email protected] | b9dcf43a | 2013-01-09 00:15:29 | [diff] [blame] | 340 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 341 | bool pinch_gesture_active() const { return pinch_gesture_active_; } |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 342 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 343 | void SetTreePriority(TreePriority priority); |
[email protected] | 362f1e8b | 2013-01-21 16:54:30 | [diff] [blame] | 344 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 345 | void BeginNextFrame(); |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 346 | base::TimeTicks CurrentFrameTimeTicks(); |
| 347 | base::Time CurrentFrameTime(); |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 348 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 349 | scoped_ptr<base::Value> AsValue() const; |
| 350 | scoped_ptr<base::Value> ActivationStateAsValue() const; |
| 351 | scoped_ptr<base::Value> FrameStateAsValue() const; |
[email protected] | 131a0c2 | 2013-02-12 18:31:08 | [diff] [blame] | 352 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 353 | bool page_scale_animation_active() const { return !!page_scale_animation_; } |
[email protected] | 498ddd0 | 2013-02-28 23:59:25 | [diff] [blame] | 354 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 355 | protected: |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 356 | LayerTreeHostImpl( |
| 357 | const LayerTreeSettings& settings, |
| 358 | LayerTreeHostImplClient* client, |
| 359 | Proxy* proxy, |
| 360 | RenderingStatsInstrumentation* rendering_stats_instrumentation); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 361 | void ActivatePendingTree(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 362 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 363 | // Virtual for testing. |
| 364 | virtual void AnimateLayers(base::TimeTicks monotonic_time, |
| 365 | base::Time wall_clock_time); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 366 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 367 | // Virtual for testing. |
| 368 | virtual base::TimeDelta LowFrequencyAnimationInterval() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 369 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 370 | const AnimationRegistrar::AnimationControllerMap& |
| 371 | active_animation_controllers() const { |
| 372 | return animation_registrar_->active_animation_controllers(); |
| 373 | } |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 374 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 375 | LayerTreeHostImplClient* client_; |
| 376 | Proxy* proxy_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 377 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 378 | private: |
| 379 | void AnimatePageScale(base::TimeTicks monotonic_time); |
| 380 | void AnimateScrollbars(base::TimeTicks monotonic_time); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 381 | void AnimateTopControls(base::TimeTicks monotonic_time); |
[email protected] | 2d69299 | 2012-12-19 01:19:32 | [diff] [blame] | 382 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 383 | gfx::Vector2dF ScrollLayerWithViewportSpaceDelta( |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 384 | LayerImpl* layer_impl, |
| 385 | float scale_from_viewport_to_screen_space, |
| 386 | gfx::PointF viewport_point, |
| 387 | gfx::Vector2dF viewport_delta); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 388 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 389 | void UpdateMaxScrollOffset(); |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 390 | void TrackDamageForAllSurfaces( |
| 391 | LayerImpl* root_draw_layer, |
| 392 | const LayerImplList& render_surface_layer_list); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 393 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 394 | // Returns false if the frame should not be displayed. This function should |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 395 | // only be called from PrepareToDraw, as DidDrawAllLayers must be called |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 396 | // if this helper function is called. |
| 397 | bool CalculateRenderPasses(FrameData* frame); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 398 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 399 | void SendDidLoseOutputSurfaceRecursive(LayerImpl* current); |
| 400 | void ClearRenderSurfaces(); |
| 401 | bool EnsureRenderSurfaceLayerList(); |
| 402 | void ClearCurrentlyScrollingLayer(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 403 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 404 | void AnimateScrollbarsRecursive(LayerImpl* layer, |
| 405 | base::TimeTicks time); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 406 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 407 | void DumpRenderSurfaces(std::string* str, |
| 408 | int indent, |
| 409 | const LayerImpl* layer) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 410 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 411 | static LayerImpl* GetNonCompositedContentLayerRecursive(LayerImpl* layer); |
[email protected] | b9dcf43a | 2013-01-09 00:15:29 | [diff] [blame] | 412 | |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 413 | void StartScrollbarAnimationRecursive(LayerImpl* layer, base::TimeTicks time); |
| 414 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 415 | scoped_ptr<OutputSurface> output_surface_; |
| 416 | scoped_ptr<ResourceProvider> resource_provider_; |
| 417 | scoped_ptr<Renderer> renderer_; |
| 418 | scoped_ptr<TileManager> tile_manager_; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 419 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 420 | // Tree currently being drawn. |
| 421 | scoped_ptr<LayerTreeImpl> active_tree_; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 422 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 423 | // In impl-side painting mode, tree with possibly incomplete rasterized |
| 424 | // content. May be promoted to active by ActivatePendingTreeIfNeeded(). |
| 425 | scoped_ptr<LayerTreeImpl> pending_tree_; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 426 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 427 | // In impl-side painting mode, inert tree with layers that can be recycled |
| 428 | // by the next sync from the main thread. |
| 429 | scoped_ptr<LayerTreeImpl> recycle_tree_; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 430 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 431 | bool did_lock_scrolling_layer_; |
| 432 | bool should_bubble_scrolls_; |
| 433 | bool wheel_scrolling_; |
| 434 | LayerTreeSettings settings_; |
| 435 | LayerTreeDebugState debug_state_; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 436 | gfx::Size device_viewport_size_; |
[email protected] | d908376 | 2013-03-24 01:36:40 | [diff] [blame] | 437 | float overdraw_bottom_height_; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 438 | float device_scale_factor_; |
| 439 | bool visible_; |
| 440 | ManagedMemoryPolicy managed_memory_policy_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 441 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 442 | bool pinch_gesture_active_; |
| 443 | gfx::Point previous_pinch_anchor_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 444 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 445 | // This is set by AnimateLayers() and used by UpdateAnimationState() |
| 446 | // when sending animation events to the main thread. |
| 447 | base::Time last_animation_time_; |
[email protected] | 6ad55bb2 | 2013-02-08 21:34:33 | [diff] [blame] | 448 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 449 | scoped_ptr<TopControlsManager> top_controls_manager_; |
[email protected] | 3ba4cae | 2013-01-16 03:58:38 | [diff] [blame] | 450 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 451 | scoped_ptr<PageScaleAnimation> page_scale_animation_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 452 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 453 | // This is used for ticking animations slowly when hidden. |
| 454 | scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 455 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 456 | scoped_ptr<FrameRateCounter> fps_counter_; |
| 457 | scoped_ptr<PaintTimeCounter> paint_time_counter_; |
| 458 | scoped_ptr<MemoryHistory> memory_history_; |
| 459 | scoped_ptr<DebugRectHistory> debug_rect_history_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 460 | |
[email protected] | d7626ffd | 2013-03-29 00:17:42 | [diff] [blame] | 461 | // The maximum memory that would be used by the prioritized resource |
| 462 | // manager, if there were no limit on memory usage. |
| 463 | size_t max_memory_needed_bytes_; |
| 464 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 465 | size_t last_sent_memory_visible_bytes_; |
| 466 | size_t last_sent_memory_visible_and_nearby_bytes_; |
| 467 | size_t last_sent_memory_use_bytes_; |
[email protected] | d3afa11 | 2012-12-08 06:24:28 | [diff] [blame] | 468 | |
[email protected] | 878705be | 2013-04-15 22:44:02 | [diff] [blame] | 469 | gfx::Rect viewport_damage_rect_; |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 470 | |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 471 | base::TimeTicks current_frame_timeticks_; |
| 472 | base::Time current_frame_time_; |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 473 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 474 | scoped_ptr<AnimationRegistrar> animation_registrar_; |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 475 | |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 476 | RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 477 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 478 | DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 479 | }; |
| 480 | |
[email protected] | 0023e8b | 2012-10-15 12:52:45 | [diff] [blame] | 481 | } // namespace cc |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 482 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 483 | #endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_ |