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