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