blob: 69bb40a0dae1161c1b53a7fdc4fc4c98b49571d5 [file] [log] [blame]
[email protected]cd57cc5a2012-10-12 22:43:411// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]0fb25002012-10-12 07:20:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]cd57cc5a2012-10-12 22:43:414
[email protected]556fd292013-03-18 08:03:045#ifndef CC_TREES_LAYER_TREE_HOST_IMPL_H_
6#define CC_TREES_LAYER_TREE_HOST_IMPL_H_
[email protected]cd57cc5a2012-10-12 22:43:417
[email protected]bf691c22013-03-26 21:15:068#include <string>
9#include <vector>
10
[email protected]c4040a522012-10-21 15:01:4011#include "base/basictypes.h"
12#include "base/memory/scoped_ptr.h"
[email protected]1b0df502013-06-27 23:39:5813#include "base/time/time.h"
[email protected]95e4e1a02013-03-18 07:09:0914#include "cc/animation/animation_events.h"
15#include "cc/animation/animation_registrar.h"
[email protected]681ccff2013-03-18 06:13:5216#include "cc/base/cc_export.h"
[email protected]3052b10f2013-03-18 07:41:2117#include "cc/input/input_handler.h"
[email protected]1960a712013-04-30 17:06:4718#include "cc/input/layer_scroll_offset_delegate.h"
[email protected]3052b10f2013-03-18 07:41:2119#include "cc/input/top_controls_manager_client.h"
[email protected]50761e92013-03-29 20:51:2820#include "cc/layers/layer_lists.h"
[email protected]cc3cfaa2013-03-18 09:05:5221#include "cc/layers/render_pass_sink.h"
[email protected]df3c24c92013-06-19 03:54:3522#include "cc/output/begin_frame_args.h"
[email protected]fd32d122013-06-29 13:11:0423#include "cc/output/managed_memory_policy.h"
[email protected]7f0d825f2013-03-18 07:24:3024#include "cc/output/output_surface_client.h"
25#include "cc/output/renderer.h"
[email protected]89e8267a2013-03-18 07:50:5626#include "cc/quads/render_pass.h"
[email protected]e12dd0e2013-03-18 08:24:4027#include "cc/resources/tile_manager.h"
[email protected]b9dcf43a2013-01-09 00:15:2928#include "skia/ext/refptr.h"
[email protected]ddf9df82012-10-16 06:52:4629#include "third_party/skia/include/core/SkColor.h"
[email protected]b9dcf43a2013-01-09 00:15:2930#include "third_party/skia/include/core/SkPicture.h"
[email protected]167ed9d52012-10-31 20:47:5831#include "ui/gfx/rect.h"
[email protected]cd57cc5a2012-10-12 22:43:4132
33namespace cc {
34
[email protected]96baf3e2012-10-22 23:09:5535class CompletionEvent;
[email protected]bf189f62012-12-18 03:42:1136class CompositorFrameMetadata;
[email protected]96baf3e2012-10-22 23:09:5537class DebugRectHistory;
38class FrameRateCounter;
[email protected]96baf3e2012-10-22 23:09:5539class LayerImpl;
40class LayerTreeHostImplTimeSourceAdapter;
[email protected]8bef40572012-12-11 21:38:0841class LayerTreeImpl;
[email protected]96baf3e2012-10-22 23:09:5542class PageScaleAnimation;
[email protected]0edbfbe9f2013-01-17 03:33:0343class PaintTimeCounter;
[email protected]1191d9d2013-02-02 06:00:3344class MemoryHistory;
[email protected]372bad5f2013-03-21 16:38:4345class RenderingStatsInstrumentation;
[email protected]96baf3e2012-10-22 23:09:5546class RenderPassDrawQuad;
47class ResourceProvider;
[email protected]3ba4cae2013-01-16 03:58:3848class TopControlsManager;
[email protected]cd57cc5a2012-10-12 22:43:4149struct RendererCapabilities;
[email protected]cd57cc5a2012-10-12 22:43:4150
[email protected]96baf3e2012-10-22 23:09:5551// LayerTreeHost->Proxy callback interface.
52class LayerTreeHostImplClient {
[email protected]c1bb5af2013-03-13 19:06:2753 public:
[email protected]2b154b22013-06-07 09:03:2754 virtual void DidTryInitializeRendererOnImplThread(
55 bool success,
56 scoped_refptr<ContextProvider> offscreen_context_provider) = 0;
[email protected]c1bb5af2013-03-13 19:06:2757 virtual void DidLoseOutputSurfaceOnImplThread() = 0;
58 virtual void OnSwapBuffersCompleteOnImplThread() = 0;
[email protected]df3c24c92013-06-19 03:54:3559 virtual void BeginFrameOnImplThread(const BeginFrameArgs& args) = 0;
[email protected]c1bb5af2013-03-13 19:06:2760 virtual void OnCanDrawStateChanged(bool can_draw) = 0;
61 virtual void OnHasPendingTreeStateChanged(bool has_pending_tree) = 0;
62 virtual void SetNeedsRedrawOnImplThread() = 0;
[email protected]1cd9f5552013-04-26 04:22:0363 virtual void SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) = 0;
[email protected]86126792013-03-16 20:07:5464 virtual void DidInitializeVisibleTileOnImplThread() = 0;
[email protected]c1bb5af2013-03-13 19:06:2765 virtual void SetNeedsCommitOnImplThread() = 0;
[email protected]c1bb5af2013-03-13 19:06:2766 virtual void PostAnimationEventsToMainThreadOnImplThread(
67 scoped_ptr<AnimationEventsVector> events,
68 base::Time wall_clock_time) = 0;
69 // Returns true if resources were deleted by this call.
70 virtual bool ReduceContentsTextureMemoryOnImplThread(
71 size_t limit_bytes,
72 int priority_cutoff) = 0;
73 virtual void ReduceWastedContentsTextureMemoryOnImplThread() = 0;
74 virtual void SendManagedMemoryStats() = 0;
75 virtual bool IsInsideDraw() = 0;
76 virtual void RenewTreePriority() = 0;
[email protected]0fc818e2013-03-18 06:45:2077 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) = 0;
[email protected]2a61ad52013-05-13 14:01:2978 virtual void DidActivatePendingTree() = 0;
[email protected]bf691c22013-03-26 21:15:0679
80 protected:
81 virtual ~LayerTreeHostImplClient() {}
[email protected]cd57cc5a2012-10-12 22:43:4182};
83
[email protected]c1bb5af2013-03-13 19:06:2784// LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
85// state.
[email protected]200a9c062013-05-20 04:34:3786class CC_EXPORT LayerTreeHostImpl
87 : public InputHandler,
88 public RendererClient,
89 public TileManagerClient,
90 public OutputSurfaceClient,
91 public TopControlsManagerClient,
92 public base::SupportsWeakPtr<LayerTreeHostImpl> {
[email protected]e216fef02013-03-20 22:56:1093 public:
[email protected]c1bb5af2013-03-13 19:06:2794 static scoped_ptr<LayerTreeHostImpl> Create(
95 const LayerTreeSettings& settings,
96 LayerTreeHostImplClient* client,
[email protected]372bad5f2013-03-21 16:38:4397 Proxy* proxy,
98 RenderingStatsInstrumentation* rendering_stats_instrumentation);
[email protected]c1bb5af2013-03-13 19:06:2799 virtual ~LayerTreeHostImpl();
[email protected]cd57cc5a2012-10-12 22:43:41100
[email protected]5ff3c9782013-04-29 17:35:12101 // InputHandler implementation
[email protected]200a9c062013-05-20 04:34:37102 virtual void BindToClient(InputHandlerClient* client) OVERRIDE;
[email protected]5ff3c9782013-04-29 17:35:12103 virtual InputHandler::ScrollStatus ScrollBegin(
[email protected]c1bb5af2013-03-13 19:06:27104 gfx::Point viewport_point,
[email protected]5ff3c9782013-04-29 17:35:12105 InputHandler::ScrollInputType type) OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27106 virtual bool ScrollBy(gfx::Point viewport_point,
107 gfx::Vector2dF scroll_delta) OVERRIDE;
[email protected]c28df4c12013-05-22 17:36:49108 virtual bool ScrollVerticallyByPage(gfx::Point viewport_point,
109 ScrollDirection direction) OVERRIDE;
[email protected]1960a712013-04-30 17:06:47110 virtual void SetRootLayerScrollOffsetDelegate(
111 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) OVERRIDE;
112 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27113 virtual void ScrollEnd() OVERRIDE;
[email protected]5ff3c9782013-04-29 17:35:12114 virtual InputHandler::ScrollStatus FlingScrollBegin() OVERRIDE;
[email protected]6e921bd2013-04-29 21:10:20115 virtual void NotifyCurrentFlingVelocity(gfx::Vector2dF velocity) OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27116 virtual void PinchGestureBegin() OVERRIDE;
117 virtual void PinchGestureUpdate(float magnify_delta,
118 gfx::Point anchor) OVERRIDE;
119 virtual void PinchGestureEnd() OVERRIDE;
120 virtual void StartPageScaleAnimation(gfx::Vector2d target_offset,
121 bool anchor_point,
122 float page_scale,
123 base::TimeTicks start_time,
124 base::TimeDelta duration) OVERRIDE;
125 virtual void ScheduleAnimation() OVERRIDE;
126 virtual bool HaveTouchEventHandlersAt(gfx::Point viewport_port) OVERRIDE;
[email protected]b76329d2013-06-11 04:15:08127 virtual void SetLatencyInfoForInputEvent(const ui::LatencyInfo& latency_info)
128 OVERRIDE;
[email protected]cd57cc5a2012-10-12 22:43:41129
[email protected]c1bb5af2013-03-13 19:06:27130 // TopControlsManagerClient implementation.
[email protected]59adb112013-04-09 04:48:44131 virtual void DidChangeTopControlsPosition() OVERRIDE;
132 virtual bool HaveRootScrollLayer() const OVERRIDE;
[email protected]3ba4cae2013-01-16 03:58:38133
[email protected]21c9dee72013-06-15 01:20:05134 void StartScrollbarAnimation();
[email protected]0fc818e2013-03-18 06:45:20135
[email protected]c1bb5af2013-03-13 19:06:27136 struct CC_EXPORT FrameData : public RenderPassSink {
137 FrameData();
[email protected]ca2902e92013-03-28 01:45:35138 virtual ~FrameData();
[email protected]cd57cc5a2012-10-12 22:43:41139
[email protected]c1bb5af2013-03-13 19:06:27140 std::vector<gfx::Rect> occluding_screen_space_rects;
141 std::vector<gfx::Rect> non_occluding_screen_space_rects;
142 RenderPassList render_passes;
143 RenderPassIdHashMap render_passes_by_id;
[email protected]50761e92013-03-29 20:51:28144 const LayerImplList* render_surface_layer_list;
145 LayerImplList will_draw_layers;
[email protected]c1bb5af2013-03-13 19:06:27146 bool contains_incomplete_tile;
[email protected]e0341352013-04-06 05:01:20147 bool has_no_damage;
[email protected]cd57cc5a2012-10-12 22:43:41148
[email protected]c1bb5af2013-03-13 19:06:27149 // RenderPassSink implementation.
150 virtual void AppendRenderPass(scoped_ptr<RenderPass> render_pass) OVERRIDE;
151 };
[email protected]cd57cc5a2012-10-12 22:43:41152
[email protected]c1bb5af2013-03-13 19:06:27153 virtual void BeginCommit();
154 virtual void CommitComplete();
155 virtual void Animate(base::TimeTicks monotonic_time,
156 base::Time wall_clock_time);
[email protected]3d9f7432013-04-06 00:35:18157 virtual void UpdateAnimationState(bool start_ready_animations);
[email protected]200a9c062013-05-20 04:34:37158 void MainThreadHasStoppedFlinging();
[email protected]3d9f7432013-04-06 00:35:18159 void UpdateBackgroundAnimateTicking(bool should_background_tick);
[email protected]b9d4a362013-04-23 05:36:27160 void SetViewportDamage(gfx::Rect damage_rect);
[email protected]cd57cc5a2012-10-12 22:43:41161
[email protected]c1bb5af2013-03-13 19:06:27162 void ManageTiles();
[email protected]8947cbe2012-11-28 05:27:43163
[email protected]c1bb5af2013-03-13 19:06:27164 // Returns false if problems occured preparing the frame, and we should try
[email protected]ed511b8d2013-03-25 03:29:29165 // to avoid displaying the frame. If PrepareToDraw is called, DidDrawAllLayers
[email protected]c1bb5af2013-03-13 19:06:27166 // must also be called, regardless of whether DrawLayers is called between the
167 // two.
[email protected]e0341352013-04-06 05:01:20168 virtual bool PrepareToDraw(FrameData* frame,
169 gfx::Rect device_viewport_damage_rect);
[email protected]f0c2a242013-03-15 19:34:52170 virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
[email protected]c1bb5af2013-03-13 19:06:27171 // Must be called if and only if PrepareToDraw was called.
172 void DidDrawAllLayers(const FrameData& frame);
[email protected]cd57cc5a2012-10-12 22:43:41173
[email protected]c1bb5af2013-03-13 19:06:27174 const LayerTreeSettings& settings() const { return settings_; }
[email protected]cd57cc5a2012-10-12 22:43:41175
[email protected]ffb2720f2013-03-15 19:18:37176 // Returns the currently visible viewport size in DIP. This value excludes
177 // the URL bar and non-overlay scrollbars.
178 gfx::SizeF VisibleViewportSize() const;
179
[email protected]0309ba5e02013-06-26 04:11:08180 // Evict all textures by enforcing a memory policy with an allocation of 0.
181 void EvictTexturesForTesting();
182
[email protected]c1bb5af2013-03-13 19:06:27183 // RendererClient implementation
[email protected]f224cc92013-06-06 23:23:32184 virtual gfx::Rect DeviceViewport() const OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27185 private:
[email protected]94c40e6292013-05-24 22:01:50186 virtual float DeviceScaleFactor() const OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27187 virtual const LayerTreeSettings& Settings() const OVERRIDE;
188 public:
[email protected]c1bb5af2013-03-13 19:06:27189 virtual void SetFullRootLayerDamage() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27190 virtual bool HasImplThread() const OVERRIDE;
191 virtual bool ShouldClearRootRenderPass() const OVERRIDE;
192 virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const OVERRIDE;
[email protected]73673592013-04-03 22:14:32193 virtual bool AllowPartialSwap() const OVERRIDE;
[email protected]8947cbe2012-11-28 05:27:43194
[email protected]c1bb5af2013-03-13 19:06:27195 // TileManagerClient implementation.
[email protected]86126792013-03-16 20:07:54196 virtual void DidInitializeVisibleTile() OVERRIDE;
[email protected]94bf75c2013-06-12 13:20:04197 virtual void NotifyReadyToActivate() OVERRIDE;
[email protected]cd57cc5a2012-10-12 22:43:41198
[email protected]c1bb5af2013-03-13 19:06:27199 // OutputSurfaceClient implementation.
[email protected]2b154b22013-06-07 09:03:27200 virtual bool DeferredInitialize(
201 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE;
[email protected]50af3c22013-07-13 03:50:20202 virtual void ReleaseGL() OVERRIDE;
[email protected]1cd9f5552013-04-26 04:22:03203 virtual void SetNeedsRedrawRect(gfx::Rect rect) OVERRIDE;
[email protected]fd32d122013-06-29 13:11:04204 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE;
[email protected]f224cc92013-06-06 23:23:32205 virtual void SetExternalDrawConstraints(const gfx::Transform& transform,
206 gfx::Rect viewport) OVERRIDE;
[email protected]049fc7a2013-06-18 12:32:35207 virtual void DidLoseOutputSurface() OVERRIDE;
208 virtual void OnSwapBuffersComplete(const CompositorFrameAck* ack) OVERRIDE;
[email protected]fd32d122013-06-29 13:11:04209 virtual void SetMemoryPolicy(
210 const ManagedMemoryPolicy& policy,
211 bool discard_backbuffer_when_not_visible) OVERRIDE;
[email protected]3b31c6ac2012-12-06 21:27:29212
[email protected]c1bb5af2013-03-13 19:06:27213 // Called from LayerTreeImpl.
214 void OnCanDrawStateChangedForTree();
[email protected]cd57cc5a2012-10-12 22:43:41215
[email protected]c1bb5af2013-03-13 19:06:27216 // Implementation
217 bool CanDraw();
218 OutputSurface* output_surface() const { return output_surface_.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41219
[email protected]c1bb5af2013-03-13 19:06:27220 std::string LayerTreeAsJson() const;
[email protected]cd57cc5a2012-10-12 22:43:41221
[email protected]c1bb5af2013-03-13 19:06:27222 void FinishAllRendering();
223 int SourceAnimationFrameNumber() const;
[email protected]cd57cc5a2012-10-12 22:43:41224
[email protected]c1bb5af2013-03-13 19:06:27225 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
226 bool IsContextLost();
227 TileManager* tile_manager() { return tile_manager_.get(); }
228 Renderer* renderer() { return renderer_.get(); }
229 const RendererCapabilities& GetRendererCapabilities() const;
[email protected]cd57cc5a2012-10-12 22:43:41230
[email protected]e0341352013-04-06 05:01:20231 virtual bool SwapBuffers(const FrameData& frame);
[email protected]c8cbae72013-05-23 10:45:03232 void SetNeedsBeginFrame(bool enable);
[email protected]a23451e2013-06-07 20:58:26233 void SetNeedsManageTiles() { manage_tiles_needed_ = true; }
[email protected]cd57cc5a2012-10-12 22:43:41234
[email protected]c1bb5af2013-03-13 19:06:27235 void Readback(void* pixels, gfx::Rect rect_in_device_viewport);
[email protected]cd57cc5a2012-10-12 22:43:41236
[email protected]c1bb5af2013-03-13 19:06:27237 LayerTreeImpl* active_tree() { return active_tree_.get(); }
238 const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
239 LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
240 const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
241 const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
[email protected]2f0d92f2013-06-11 04:07:20242 virtual void CreatePendingTree();
[email protected]c1bb5af2013-03-13 19:06:27243 void CheckForCompletedTileUploads();
[email protected]94bf75c2013-06-12 13:20:04244 virtual void ActivatePendingTreeIfNeeded();
[email protected]cd57cc5a2012-10-12 22:43:41245
[email protected]c1bb5af2013-03-13 19:06:27246 // Shortcuts to layers on the active tree.
247 LayerImpl* RootLayer() const;
248 LayerImpl* RootScrollLayer() const;
249 LayerImpl* CurrentlyScrollingLayer() const;
[email protected]cd57cc5a2012-10-12 22:43:41250
[email protected]c1bb5af2013-03-13 19:06:27251 virtual void SetVisible(bool visible);
252 bool visible() const { return visible_; }
[email protected]cd57cc5a2012-10-12 22:43:41253
[email protected]d7eb8c72013-03-23 22:57:13254 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
[email protected]59adb112013-04-09 04:48:44255 void SetNeedsRedraw() { client_->SetNeedsRedrawOnImplThread(); }
[email protected]d7eb8c72013-03-23 22:57:13256
[email protected]206a3922013-05-17 06:34:12257 ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
258
[email protected]c1bb5af2013-03-13 19:06:27259 size_t memory_allocation_limit_bytes() const {
[email protected]46b8acc2013-03-19 22:38:35260 return managed_memory_policy_.bytes_limit_when_visible;
[email protected]c1bb5af2013-03-13 19:06:27261 }
[email protected]cd57cc5a2012-10-12 22:43:41262
[email protected]18ce59702013-04-09 04:58:40263 void SetViewportSize(gfx::Size device_viewport_size);
[email protected]c1bb5af2013-03-13 19:06:27264 gfx::Size device_viewport_size() const { return device_viewport_size_; }
[email protected]cd57cc5a2012-10-12 22:43:41265
[email protected]d9083762013-03-24 01:36:40266 void SetOverdrawBottomHeight(float overdraw_bottom_height);
267 float overdraw_bottom_height() const { return overdraw_bottom_height_; }
268
[email protected]c1bb5af2013-03-13 19:06:27269 void SetDeviceScaleFactor(float device_scale_factor);
270 float device_scale_factor() const { return device_scale_factor_; }
[email protected]cd57cc5a2012-10-12 22:43:41271
[email protected]f224cc92013-06-06 23:23:32272 const gfx::Transform& DeviceTransform() const;
273
[email protected]c1bb5af2013-03-13 19:06:27274 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
[email protected]cd57cc5a2012-10-12 22:43:41275
[email protected]c1bb5af2013-03-13 19:06:27276 bool needs_animate_layers() const {
277 return !animation_registrar_->active_animation_controllers().empty();
278 }
[email protected]cd57cc5a2012-10-12 22:43:41279
[email protected]c1bb5af2013-03-13 19:06:27280 void SendManagedMemoryStats(
281 size_t memory_visible_bytes,
282 size_t memory_visible_and_nearby_bytes,
[email protected]ed511b8d2013-03-25 03:29:29283 size_t memory_use_bytes);
[email protected]c1bb5af2013-03-13 19:06:27284
[email protected]d7626ffd2013-03-29 00:17:42285 void set_max_memory_needed_bytes(size_t bytes) {
286 max_memory_needed_bytes_ = bytes;
287 }
288
[email protected]c1bb5af2013-03-13 19:06:27289 FrameRateCounter* fps_counter() {
290 return fps_counter_.get();
291 }
292 PaintTimeCounter* paint_time_counter() {
293 return paint_time_counter_.get();
294 }
295 MemoryHistory* memory_history() {
296 return memory_history_.get();
297 }
298 DebugRectHistory* debug_rect_history() {
299 return debug_rect_history_.get();
300 }
301 ResourceProvider* resource_provider() {
302 return resource_provider_.get();
303 }
304 TopControlsManager* top_controls_manager() {
305 return top_controls_manager_.get();
306 }
[email protected]ff762fb2012-12-12 19:18:37307
[email protected]c1bb5af2013-03-13 19:06:27308 Proxy* proxy() const { return proxy_; }
[email protected]cd57cc5a2012-10-12 22:43:41309
[email protected]c1bb5af2013-03-13 19:06:27310 AnimationRegistrar* animation_registrar() const {
311 return animation_registrar_.get();
312 }
[email protected]de4afb5e2012-12-20 00:11:34313
[email protected]6e7fdeb2013-07-09 14:28:38314 void SetDebugState(const LayerTreeDebugState& new_debug_state);
[email protected]c1bb5af2013-03-13 19:06:27315 const LayerTreeDebugState& debug_state() const { return debug_state_; }
[email protected]f511afb2012-11-30 01:55:20316
[email protected]c1bb5af2013-03-13 19:06:27317 class CC_EXPORT CullRenderPassesWithCachedTextures {
318 public:
319 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
320 const FrameData& frame) const;
[email protected]cd57cc5a2012-10-12 22:43:41321
[email protected]c1bb5af2013-03-13 19:06:27322 // Iterates from the root first, in order to remove the surfaces closest
323 // to the root with cached textures, and all surfaces that draw into
324 // them.
325 size_t RenderPassListBegin(const RenderPassList& list) const {
326 return list.size() - 1;
327 }
328 size_t RenderPassListEnd(const RenderPassList& list) const { return 0 - 1; }
329 size_t RenderPassListNext(size_t it) const { return it - 1; }
[email protected]cd57cc5a2012-10-12 22:43:41330
[email protected]bf691c22013-03-26 21:15:06331 explicit CullRenderPassesWithCachedTextures(Renderer* renderer)
[email protected]c1bb5af2013-03-13 19:06:27332 : renderer_(renderer) {}
333 private:
[email protected]bf691c22013-03-26 21:15:06334 Renderer* renderer_;
[email protected]c1bb5af2013-03-13 19:06:27335 };
[email protected]cd57cc5a2012-10-12 22:43:41336
[email protected]c1bb5af2013-03-13 19:06:27337 class CC_EXPORT CullRenderPassesWithNoQuads {
338 public:
339 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
340 const FrameData& frame) const;
[email protected]cd57cc5a2012-10-12 22:43:41341
[email protected]c1bb5af2013-03-13 19:06:27342 // Iterates in draw order, so that when a surface is removed, and its
343 // target becomes empty, then its target can be removed also.
344 size_t RenderPassListBegin(const RenderPassList& list) const { return 0; }
345 size_t RenderPassListEnd(const RenderPassList& list) const {
346 return list.size();
347 }
348 size_t RenderPassListNext(size_t it) const { return it + 1; }
349 };
[email protected]cd57cc5a2012-10-12 22:43:41350
[email protected]c1bb5af2013-03-13 19:06:27351 template <typename RenderPassCuller>
352 static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame);
[email protected]cd57cc5a2012-10-12 22:43:41353
[email protected]c1bb5af2013-03-13 19:06:27354 skia::RefPtr<SkPicture> CapturePicture();
[email protected]b9dcf43a2013-01-09 00:15:29355
[email protected]a2b5ded2013-05-20 21:32:53356 gfx::Vector2dF accumulated_root_overscroll() const {
357 return accumulated_root_overscroll_;
358 }
359 gfx::Vector2dF current_fling_velocity() const {
360 return current_fling_velocity_;
361 }
362
[email protected]c1bb5af2013-03-13 19:06:27363 bool pinch_gesture_active() const { return pinch_gesture_active_; }
[email protected]166db5c82013-01-09 23:54:31364
[email protected]c1bb5af2013-03-13 19:06:27365 void SetTreePriority(TreePriority priority);
[email protected]362f1e8b2013-01-21 16:54:30366
[email protected]8347d692013-05-17 23:22:38367 void ResetCurrentFrameTimeForNextFrame();
[email protected]fb7425a2013-04-22 16:28:55368 base::TimeTicks CurrentFrameTimeTicks();
369 base::Time CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10370
[email protected]21c9dee72013-06-15 01:20:05371 virtual base::TimeTicks CurrentPhysicalTimeTicks() const;
372
[email protected]c1bb5af2013-03-13 19:06:27373 scoped_ptr<base::Value> AsValue() const;
374 scoped_ptr<base::Value> ActivationStateAsValue() const;
[email protected]131a0c22013-02-12 18:31:08375
[email protected]c1bb5af2013-03-13 19:06:27376 bool page_scale_animation_active() const { return !!page_scale_animation_; }
[email protected]498ddd02013-02-28 23:59:25377
[email protected]c1bb5af2013-03-13 19:06:27378 protected:
[email protected]372bad5f2013-03-21 16:38:43379 LayerTreeHostImpl(
380 const LayerTreeSettings& settings,
381 LayerTreeHostImplClient* client,
382 Proxy* proxy,
383 RenderingStatsInstrumentation* rendering_stats_instrumentation);
[email protected]94bf75c2013-06-12 13:20:04384 virtual void ActivatePendingTree();
[email protected]cd57cc5a2012-10-12 22:43:41385
[email protected]c1bb5af2013-03-13 19:06:27386 // Virtual for testing.
387 virtual void AnimateLayers(base::TimeTicks monotonic_time,
388 base::Time wall_clock_time);
[email protected]cd57cc5a2012-10-12 22:43:41389
[email protected]c1bb5af2013-03-13 19:06:27390 // Virtual for testing.
391 virtual base::TimeDelta LowFrequencyAnimationInterval() const;
[email protected]cd57cc5a2012-10-12 22:43:41392
[email protected]c1bb5af2013-03-13 19:06:27393 const AnimationRegistrar::AnimationControllerMap&
394 active_animation_controllers() const {
395 return animation_registrar_->active_animation_controllers();
396 }
[email protected]de4afb5e2012-12-20 00:11:34397
[email protected]c1bb5af2013-03-13 19:06:27398 LayerTreeHostImplClient* client_;
399 Proxy* proxy_;
[email protected]cd57cc5a2012-10-12 22:43:41400
[email protected]c1bb5af2013-03-13 19:06:27401 private:
[email protected]50644642013-06-20 13:58:55402 void CreateAndSetRenderer(OutputSurface* output_surface,
[email protected]50af3c22013-07-13 03:50:20403 ResourceProvider* resource_provider,
404 bool skip_gl_renderer);
405 void CreateAndSetTileManager(ResourceProvider* resource_provider,
406 bool using_map_image);
[email protected]50644642013-06-20 13:58:55407 void ReleaseTreeResources();
408 void EnforceZeroBudget(bool zero_budget);
[email protected]2b154b22013-06-07 09:03:27409
[email protected]c1bb5af2013-03-13 19:06:27410 void AnimatePageScale(base::TimeTicks monotonic_time);
411 void AnimateScrollbars(base::TimeTicks monotonic_time);
[email protected]ffb2720f2013-03-15 19:18:37412 void AnimateTopControls(base::TimeTicks monotonic_time);
[email protected]2d692992012-12-19 01:19:32413
[email protected]c1bb5af2013-03-13 19:06:27414 gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
[email protected]ed511b8d2013-03-25 03:29:29415 LayerImpl* layer_impl,
416 float scale_from_viewport_to_screen_space,
417 gfx::PointF viewport_point,
418 gfx::Vector2dF viewport_delta);
[email protected]615c78a2013-01-24 23:44:16419
[email protected]c1bb5af2013-03-13 19:06:27420 void UpdateMaxScrollOffset();
[email protected]50761e92013-03-29 20:51:28421 void TrackDamageForAllSurfaces(
422 LayerImpl* root_draw_layer,
423 const LayerImplList& render_surface_layer_list);
[email protected]cd57cc5a2012-10-12 22:43:41424
[email protected]8be1a9bf2013-05-01 03:45:19425 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
426
[email protected]c1bb5af2013-03-13 19:06:27427 // Returns false if the frame should not be displayed. This function should
[email protected]ed511b8d2013-03-25 03:29:29428 // only be called from PrepareToDraw, as DidDrawAllLayers must be called
[email protected]c1bb5af2013-03-13 19:06:27429 // if this helper function is called.
430 bool CalculateRenderPasses(FrameData* frame);
[email protected]cd57cc5a2012-10-12 22:43:41431
[email protected]50644642013-06-20 13:58:55432 void SendReleaseResourcesRecursive(LayerImpl* current);
[email protected]c1bb5af2013-03-13 19:06:27433 bool EnsureRenderSurfaceLayerList();
434 void ClearCurrentlyScrollingLayer();
[email protected]cd57cc5a2012-10-12 22:43:41435
[email protected]c1bb5af2013-03-13 19:06:27436 void AnimateScrollbarsRecursive(LayerImpl* layer,
437 base::TimeTicks time);
[email protected]cd57cc5a2012-10-12 22:43:41438
[email protected]c1bb5af2013-03-13 19:06:27439 static LayerImpl* GetNonCompositedContentLayerRecursive(LayerImpl* layer);
[email protected]b9dcf43a2013-01-09 00:15:29440
[email protected]21c9dee72013-06-15 01:20:05441 void UpdateCurrentFrameTime(base::TimeTicks* ticks, base::Time* now) const;
442
[email protected]0fc818e2013-03-18 06:45:20443 void StartScrollbarAnimationRecursive(LayerImpl* layer, base::TimeTicks time);
[email protected]fd32d122013-06-29 13:11:04444 void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
[email protected]0309ba5e02013-06-26 04:11:08445 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
[email protected]0fc818e2013-03-18 06:45:20446
[email protected]c1bb5af2013-03-13 19:06:27447 scoped_ptr<OutputSurface> output_surface_;
[email protected]fbe89f72013-05-21 07:24:24448
449 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
450 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
[email protected]c1bb5af2013-03-13 19:06:27451 scoped_ptr<ResourceProvider> resource_provider_;
[email protected]c1bb5af2013-03-13 19:06:27452 scoped_ptr<TileManager> tile_manager_;
[email protected]fbe89f72013-05-21 07:24:24453 scoped_ptr<Renderer> renderer_;
[email protected]3b31c6ac2012-12-06 21:27:29454
[email protected]c1bb5af2013-03-13 19:06:27455 // Tree currently being drawn.
456 scoped_ptr<LayerTreeImpl> active_tree_;
[email protected]3b31c6ac2012-12-06 21:27:29457
[email protected]c1bb5af2013-03-13 19:06:27458 // In impl-side painting mode, tree with possibly incomplete rasterized
459 // content. May be promoted to active by ActivatePendingTreeIfNeeded().
460 scoped_ptr<LayerTreeImpl> pending_tree_;
[email protected]48871fc2013-01-23 07:36:51461
[email protected]c1bb5af2013-03-13 19:06:27462 // In impl-side painting mode, inert tree with layers that can be recycled
463 // by the next sync from the main thread.
464 scoped_ptr<LayerTreeImpl> recycle_tree_;
[email protected]48871fc2013-01-23 07:36:51465
[email protected]200a9c062013-05-20 04:34:37466 InputHandlerClient* input_handler_client_;
[email protected]c1bb5af2013-03-13 19:06:27467 bool did_lock_scrolling_layer_;
468 bool should_bubble_scrolls_;
469 bool wheel_scrolling_;
[email protected]a23451e2013-06-07 20:58:26470
471 bool manage_tiles_needed_;
472
[email protected]1960a712013-04-30 17:06:47473 // The optional delegate for the root layer scroll offset.
474 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
[email protected]c1bb5af2013-03-13 19:06:27475 LayerTreeSettings settings_;
476 LayerTreeDebugState debug_state_;
[email protected]c1bb5af2013-03-13 19:06:27477 bool visible_;
478 ManagedMemoryPolicy managed_memory_policy_;
[email protected]cd57cc5a2012-10-12 22:43:41479
[email protected]a2b5ded2013-05-20 21:32:53480 gfx::Vector2dF accumulated_root_overscroll_;
[email protected]6e921bd2013-04-29 21:10:20481 gfx::Vector2dF current_fling_velocity_;
482
[email protected]c1bb5af2013-03-13 19:06:27483 bool pinch_gesture_active_;
484 gfx::Point previous_pinch_anchor_;
[email protected]cd57cc5a2012-10-12 22:43:41485
[email protected]c1bb5af2013-03-13 19:06:27486 // This is set by AnimateLayers() and used by UpdateAnimationState()
487 // when sending animation events to the main thread.
488 base::Time last_animation_time_;
[email protected]6ad55bb22013-02-08 21:34:33489
[email protected]c1bb5af2013-03-13 19:06:27490 scoped_ptr<TopControlsManager> top_controls_manager_;
[email protected]3ba4cae2013-01-16 03:58:38491
[email protected]c1bb5af2013-03-13 19:06:27492 scoped_ptr<PageScaleAnimation> page_scale_animation_;
[email protected]cd57cc5a2012-10-12 22:43:41493
[email protected]c1bb5af2013-03-13 19:06:27494 // This is used for ticking animations slowly when hidden.
495 scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
[email protected]cd57cc5a2012-10-12 22:43:41496
[email protected]c1bb5af2013-03-13 19:06:27497 scoped_ptr<FrameRateCounter> fps_counter_;
498 scoped_ptr<PaintTimeCounter> paint_time_counter_;
499 scoped_ptr<MemoryHistory> memory_history_;
500 scoped_ptr<DebugRectHistory> debug_rect_history_;
[email protected]cd57cc5a2012-10-12 22:43:41501
[email protected]d7626ffd2013-03-29 00:17:42502 // The maximum memory that would be used by the prioritized resource
503 // manager, if there were no limit on memory usage.
504 size_t max_memory_needed_bytes_;
505
[email protected]c1bb5af2013-03-13 19:06:27506 size_t last_sent_memory_visible_bytes_;
507 size_t last_sent_memory_visible_and_nearby_bytes_;
508 size_t last_sent_memory_use_bytes_;
[email protected]50644642013-06-20 13:58:55509 bool zero_budget_;
[email protected]d3afa112012-12-08 06:24:28510
[email protected]f224cc92013-06-06 23:23:32511 // Viewport size passed in from the main thread, in physical pixels.
512 gfx::Size device_viewport_size_;
513
514 // Conversion factor from CSS pixels to physical pixels when
515 // pageScaleFactor=1.
516 float device_scale_factor_;
517
518 // Vertical amount of the viewport size that's known to covered by a
519 // browser-side UI element, such as an on-screen-keyboard. This affects
520 // scrollable size since we want to still be able to scroll to the bottom of
521 // the page when the keyboard is up.
522 float overdraw_bottom_height_;
523
524 // Optional top-level constraints that can be set by the OutputSurface. The
525 // external_viewport_'s size takes precedence over device_viewport_size_ for
526 // DrawQuad generation and Renderer; however, device_viewport_size_ is still
527 // used for scrollable size.
528 gfx::Transform external_transform_;
529 gfx::Rect external_viewport_;
530
[email protected]878705be2013-04-15 22:44:02531 gfx::Rect viewport_damage_rect_;
[email protected]e0341352013-04-06 05:01:20532
[email protected]fb7425a2013-04-22 16:28:55533 base::TimeTicks current_frame_timeticks_;
534 base::Time current_frame_time_;
[email protected]829ad972013-01-28 23:36:10535
[email protected]c1bb5af2013-03-13 19:06:27536 scoped_ptr<AnimationRegistrar> animation_registrar_;
[email protected]de4afb5e2012-12-20 00:11:34537
[email protected]372bad5f2013-03-21 16:38:43538 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
539
[email protected]39643fb2013-07-09 17:28:19540 bool need_check_for_completed_tile_uploads_before_draw_;
541
[email protected]c1bb5af2013-03-13 19:06:27542 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
[email protected]cd57cc5a2012-10-12 22:43:41543};
544
[email protected]0023e8b2012-10-15 12:52:45545} // namespace cc
[email protected]cd57cc5a2012-10-12 22:43:41546
[email protected]556fd292013-03-18 08:03:04547#endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_