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