blob: 520ec7f4989f30ed1c99c6b7f5b74243bb740f3a [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]c9280762013-08-01 06:28:578#include <list>
[email protected]bf691c22013-03-26 21:15:069#include <string>
10#include <vector>
11
[email protected]c4040a522012-10-21 15:01:4012#include "base/basictypes.h"
[email protected]c9280762013-08-01 06:28:5713#include "base/containers/hash_tables.h"
[email protected]c4040a522012-10-21 15:01:4014#include "base/memory/scoped_ptr.h"
[email protected]1b0df502013-06-27 23:39:5815#include "base/time/time.h"
[email protected]95e4e1a02013-03-18 07:09:0916#include "cc/animation/animation_events.h"
17#include "cc/animation/animation_registrar.h"
[email protected]681ccff2013-03-18 06:13:5218#include "cc/base/cc_export.h"
[email protected]3052b10f2013-03-18 07:41:2119#include "cc/input/input_handler.h"
[email protected]1960a712013-04-30 17:06:4720#include "cc/input/layer_scroll_offset_delegate.h"
[email protected]3052b10f2013-03-18 07:41:2121#include "cc/input/top_controls_manager_client.h"
[email protected]50761e92013-03-29 20:51:2822#include "cc/layers/layer_lists.h"
[email protected]cc3cfaa2013-03-18 09:05:5223#include "cc/layers/render_pass_sink.h"
[email protected]df3c24c92013-06-19 03:54:3524#include "cc/output/begin_frame_args.h"
[email protected]fd32d122013-06-29 13:11:0425#include "cc/output/managed_memory_policy.h"
[email protected]7f0d825f2013-03-18 07:24:3026#include "cc/output/output_surface_client.h"
27#include "cc/output/renderer.h"
[email protected]89e8267a2013-03-18 07:50:5628#include "cc/quads/render_pass.h"
[email protected]c9280762013-08-01 06:28:5729#include "cc/resources/resource_provider.h"
[email protected]e12dd0e2013-03-18 08:24:4030#include "cc/resources/tile_manager.h"
[email protected]c9280762013-08-01 06:28:5731#include "skia/ext/refptr.h"
[email protected]ddf9df82012-10-16 06:52:4632#include "third_party/skia/include/core/SkColor.h"
[email protected]167ed9d52012-10-31 20:47:5833#include "ui/gfx/rect.h"
[email protected]cd57cc5a2012-10-12 22:43:4134
35namespace cc {
36
[email protected]96baf3e2012-10-22 23:09:5537class CompletionEvent;
[email protected]bf189f62012-12-18 03:42:1138class CompositorFrameMetadata;
[email protected]96baf3e2012-10-22 23:09:5539class DebugRectHistory;
40class FrameRateCounter;
[email protected]96baf3e2012-10-22 23:09:5541class LayerImpl;
42class LayerTreeHostImplTimeSourceAdapter;
[email protected]8bef40572012-12-11 21:38:0843class LayerTreeImpl;
[email protected]96baf3e2012-10-22 23:09:5544class PageScaleAnimation;
[email protected]0edbfbe9f2013-01-17 03:33:0345class PaintTimeCounter;
[email protected]1191d9d2013-02-02 06:00:3346class MemoryHistory;
[email protected]372bad5f2013-03-21 16:38:4347class RenderingStatsInstrumentation;
[email protected]96baf3e2012-10-22 23:09:5548class RenderPassDrawQuad;
[email protected]3ba4cae2013-01-16 03:58:3849class TopControlsManager;
[email protected]c9280762013-08-01 06:28:5750class UIResourceBitmap;
[email protected]cd57cc5a2012-10-12 22:43:4151struct RendererCapabilities;
[email protected]c9280762013-08-01 06:28:5752struct UIResourceRequest;
[email protected]cd57cc5a2012-10-12 22:43:4153
[email protected]96baf3e2012-10-22 23:09:5554// LayerTreeHost->Proxy callback interface.
55class LayerTreeHostImplClient {
[email protected]c1bb5af2013-03-13 19:06:2756 public:
57 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;
[email protected]4f48f6e2013-08-27 06:33:3861 virtual void NotifyReadyToActivate() = 0;
[email protected]c1bb5af2013-03-13 19:06:2762 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]34806722013-08-09 23:51:21139 scoped_ptr<base::Value> AsValue() const;
[email protected]cd57cc5a2012-10-12 22:43:41140
[email protected]c1bb5af2013-03-13 19:06:27141 std::vector<gfx::Rect> occluding_screen_space_rects;
142 std::vector<gfx::Rect> non_occluding_screen_space_rects;
143 RenderPassList render_passes;
144 RenderPassIdHashMap render_passes_by_id;
[email protected]50761e92013-03-29 20:51:28145 const LayerImplList* render_surface_layer_list;
146 LayerImplList will_draw_layers;
[email protected]c1bb5af2013-03-13 19:06:27147 bool contains_incomplete_tile;
[email protected]e0341352013-04-06 05:01:20148 bool has_no_damage;
[email protected]cd57cc5a2012-10-12 22:43:41149
[email protected]c1bb5af2013-03-13 19:06:27150 // RenderPassSink implementation.
151 virtual void AppendRenderPass(scoped_ptr<RenderPass> render_pass) OVERRIDE;
152 };
[email protected]cd57cc5a2012-10-12 22:43:41153
[email protected]c1bb5af2013-03-13 19:06:27154 virtual void BeginCommit();
155 virtual void CommitComplete();
156 virtual void Animate(base::TimeTicks monotonic_time,
157 base::Time wall_clock_time);
[email protected]3d9f7432013-04-06 00:35:18158 virtual void UpdateAnimationState(bool start_ready_animations);
[email protected]200a9c062013-05-20 04:34:37159 void MainThreadHasStoppedFlinging();
[email protected]3d9f7432013-04-06 00:35:18160 void UpdateBackgroundAnimateTicking(bool should_background_tick);
[email protected]b9d4a362013-04-23 05:36:27161 void SetViewportDamage(gfx::Rect damage_rect);
[email protected]cd57cc5a2012-10-12 22:43:41162
[email protected]c1bb5af2013-03-13 19:06:27163 void ManageTiles();
[email protected]8947cbe2012-11-28 05:27:43164
[email protected]c1bb5af2013-03-13 19:06:27165 // Returns false if problems occured preparing the frame, and we should try
[email protected]ed511b8d2013-03-25 03:29:29166 // to avoid displaying the frame. If PrepareToDraw is called, DidDrawAllLayers
[email protected]c1bb5af2013-03-13 19:06:27167 // must also be called, regardless of whether DrawLayers is called between the
168 // two.
[email protected]e0341352013-04-06 05:01:20169 virtual bool PrepareToDraw(FrameData* frame,
170 gfx::Rect device_viewport_damage_rect);
[email protected]f0c2a242013-03-15 19:34:52171 virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
[email protected]c1bb5af2013-03-13 19:06:27172 // Must be called if and only if PrepareToDraw was called.
173 void DidDrawAllLayers(const FrameData& frame);
[email protected]cd57cc5a2012-10-12 22:43:41174
[email protected]c1bb5af2013-03-13 19:06:27175 const LayerTreeSettings& settings() const { return settings_; }
[email protected]cd57cc5a2012-10-12 22:43:41176
[email protected]ffb2720f2013-03-15 19:18:37177 // Returns the currently visible viewport size in DIP. This value excludes
178 // the URL bar and non-overlay scrollbars.
179 gfx::SizeF VisibleViewportSize() const;
180
[email protected]0309ba5e02013-06-26 04:11:08181 // Evict all textures by enforcing a memory policy with an allocation of 0.
182 void EvictTexturesForTesting();
183
[email protected]4f48f6e2013-08-27 06:33:38184 // When blocking, this prevents client_->NotifyReadyToActivate() from being
185 // called. When disabled, it calls client_->NotifyReadyToActivate()
186 // immediately if any notifications had been blocked while blocking.
187 virtual void BlockNotifyReadyToActivateForTesting(bool block);
188
[email protected]c1bb5af2013-03-13 19:06:27189 // RendererClient implementation
[email protected]f224cc92013-06-06 23:23:32190 virtual gfx::Rect DeviceViewport() const OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27191 private:
[email protected]94c40e6292013-05-24 22:01:50192 virtual float DeviceScaleFactor() const OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27193 virtual const LayerTreeSettings& Settings() const OVERRIDE;
194 public:
[email protected]c1bb5af2013-03-13 19:06:27195 virtual void SetFullRootLayerDamage() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27196 virtual bool HasImplThread() const OVERRIDE;
197 virtual bool ShouldClearRootRenderPass() const OVERRIDE;
198 virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const OVERRIDE;
[email protected]73673592013-04-03 22:14:32199 virtual bool AllowPartialSwap() const OVERRIDE;
[email protected]c32a1962013-07-30 19:41:17200 virtual bool ExternalStencilTestEnabled() const OVERRIDE;
[email protected]8947cbe2012-11-28 05:27:43201
[email protected]c1bb5af2013-03-13 19:06:27202 // TileManagerClient implementation.
[email protected]94bf75c2013-06-12 13:20:04203 virtual void NotifyReadyToActivate() OVERRIDE;
[email protected]cd57cc5a2012-10-12 22:43:41204
[email protected]c1bb5af2013-03-13 19:06:27205 // OutputSurfaceClient implementation.
[email protected]2b154b22013-06-07 09:03:27206 virtual bool DeferredInitialize(
207 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE;
[email protected]50af3c22013-07-13 03:50:20208 virtual void ReleaseGL() OVERRIDE;
[email protected]1cd9f5552013-04-26 04:22:03209 virtual void SetNeedsRedrawRect(gfx::Rect rect) OVERRIDE;
[email protected]fd32d122013-06-29 13:11:04210 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE;
[email protected]f224cc92013-06-06 23:23:32211 virtual void SetExternalDrawConstraints(const gfx::Transform& transform,
212 gfx::Rect viewport) OVERRIDE;
[email protected]c32a1962013-07-30 19:41:17213 virtual void SetExternalStencilTest(bool enabled) OVERRIDE;
[email protected]049fc7a2013-06-18 12:32:35214 virtual void DidLoseOutputSurface() OVERRIDE;
215 virtual void OnSwapBuffersComplete(const CompositorFrameAck* ack) OVERRIDE;
[email protected]3f2ff112013-08-03 02:41:07216 virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE;
217 virtual void SetDiscardBackBufferWhenNotVisible(bool discard) OVERRIDE;
[email protected]5f07afc2013-07-19 05:17:18218 virtual void SetTreeActivationCallback(const base::Closure& callback)
219 OVERRIDE;
[email protected]3b31c6ac2012-12-06 21:27:29220
[email protected]c1bb5af2013-03-13 19:06:27221 // Called from LayerTreeImpl.
222 void OnCanDrawStateChangedForTree();
[email protected]cd57cc5a2012-10-12 22:43:41223
[email protected]b5174d712013-08-28 08:10:43224 // Implementation.
[email protected]6133cc232013-07-30 18:47:07225 bool CanDraw() const;
[email protected]c1bb5af2013-03-13 19:06:27226 OutputSurface* output_surface() const { return output_surface_.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41227
[email protected]b5174d712013-08-28 08:10:43228 void SetOffscreenContextProvider(
229 const scoped_refptr<ContextProvider>& offscreen_context_provider);
230 ContextProvider* offscreen_context_provider() const {
231 return offscreen_context_provider_.get();
232 }
233
[email protected]c1bb5af2013-03-13 19:06:27234 std::string LayerTreeAsJson() const;
[email protected]cd57cc5a2012-10-12 22:43:41235
[email protected]c1bb5af2013-03-13 19:06:27236 void FinishAllRendering();
237 int SourceAnimationFrameNumber() const;
[email protected]cd57cc5a2012-10-12 22:43:41238
[email protected]c1bb5af2013-03-13 19:06:27239 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
240 bool IsContextLost();
241 TileManager* tile_manager() { return tile_manager_.get(); }
242 Renderer* renderer() { return renderer_.get(); }
243 const RendererCapabilities& GetRendererCapabilities() const;
[email protected]cd57cc5a2012-10-12 22:43:41244
[email protected]e0341352013-04-06 05:01:20245 virtual bool SwapBuffers(const FrameData& frame);
[email protected]c8cbae72013-05-23 10:45:03246 void SetNeedsBeginFrame(bool enable);
[email protected]a23451e2013-06-07 20:58:26247 void SetNeedsManageTiles() { manage_tiles_needed_ = true; }
[email protected]cd57cc5a2012-10-12 22:43:41248
[email protected]c1bb5af2013-03-13 19:06:27249 void Readback(void* pixels, gfx::Rect rect_in_device_viewport);
[email protected]cd57cc5a2012-10-12 22:43:41250
[email protected]c1bb5af2013-03-13 19:06:27251 LayerTreeImpl* active_tree() { return active_tree_.get(); }
252 const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
253 LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
254 const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
255 const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
[email protected]2f0d92f2013-06-11 04:07:20256 virtual void CreatePendingTree();
[email protected]8bb6cfa2013-07-23 00:11:19257 void UpdateVisibleTiles();
[email protected]4f48f6e2013-08-27 06:33:38258 virtual void ActivatePendingTree();
[email protected]cd57cc5a2012-10-12 22:43:41259
[email protected]c1bb5af2013-03-13 19:06:27260 // Shortcuts to layers on the active tree.
261 LayerImpl* RootLayer() const;
262 LayerImpl* RootScrollLayer() const;
263 LayerImpl* CurrentlyScrollingLayer() const;
[email protected]cd57cc5a2012-10-12 22:43:41264
[email protected]c1bb5af2013-03-13 19:06:27265 virtual void SetVisible(bool visible);
266 bool visible() const { return visible_; }
[email protected]cd57cc5a2012-10-12 22:43:41267
[email protected]d7eb8c72013-03-23 22:57:13268 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
[email protected]59adb112013-04-09 04:48:44269 void SetNeedsRedraw() { client_->SetNeedsRedrawOnImplThread(); }
[email protected]d7eb8c72013-03-23 22:57:13270
[email protected]206a3922013-05-17 06:34:12271 ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
272
[email protected]3f2ff112013-08-03 02:41:07273 size_t memory_allocation_limit_bytes() const;
[email protected]cd57cc5a2012-10-12 22:43:41274
[email protected]18ce59702013-04-09 04:58:40275 void SetViewportSize(gfx::Size device_viewport_size);
[email protected]c1bb5af2013-03-13 19:06:27276 gfx::Size device_viewport_size() const { return device_viewport_size_; }
[email protected]cd57cc5a2012-10-12 22:43:41277
[email protected]d9083762013-03-24 01:36:40278 void SetOverdrawBottomHeight(float overdraw_bottom_height);
279 float overdraw_bottom_height() const { return overdraw_bottom_height_; }
280
[email protected]9f4f6a32013-09-04 21:35:12281 void SetOverhangUIResource(UIResourceId overhang_ui_resource_id,
282 gfx::Size overhang_ui_resource_size);
283
[email protected]c1bb5af2013-03-13 19:06:27284 void SetDeviceScaleFactor(float device_scale_factor);
285 float device_scale_factor() const { return device_scale_factor_; }
[email protected]cd57cc5a2012-10-12 22:43:41286
[email protected]f224cc92013-06-06 23:23:32287 const gfx::Transform& DeviceTransform() const;
288
[email protected]c1bb5af2013-03-13 19:06:27289 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
[email protected]cd57cc5a2012-10-12 22:43:41290
[email protected]c1bb5af2013-03-13 19:06:27291 bool needs_animate_layers() const {
292 return !animation_registrar_->active_animation_controllers().empty();
293 }
[email protected]cd57cc5a2012-10-12 22:43:41294
[email protected]c1bb5af2013-03-13 19:06:27295 void SendManagedMemoryStats(
296 size_t memory_visible_bytes,
297 size_t memory_visible_and_nearby_bytes,
[email protected]ed511b8d2013-03-25 03:29:29298 size_t memory_use_bytes);
[email protected]c1bb5af2013-03-13 19:06:27299
[email protected]d7626ffd2013-03-29 00:17:42300 void set_max_memory_needed_bytes(size_t bytes) {
301 max_memory_needed_bytes_ = bytes;
302 }
303
[email protected]c1bb5af2013-03-13 19:06:27304 FrameRateCounter* fps_counter() {
305 return fps_counter_.get();
306 }
307 PaintTimeCounter* paint_time_counter() {
308 return paint_time_counter_.get();
309 }
310 MemoryHistory* memory_history() {
311 return memory_history_.get();
312 }
313 DebugRectHistory* debug_rect_history() {
314 return debug_rect_history_.get();
315 }
316 ResourceProvider* resource_provider() {
317 return resource_provider_.get();
318 }
319 TopControlsManager* top_controls_manager() {
320 return top_controls_manager_.get();
321 }
[email protected]ff762fb2012-12-12 19:18:37322
[email protected]c1bb5af2013-03-13 19:06:27323 Proxy* proxy() const { return proxy_; }
[email protected]cd57cc5a2012-10-12 22:43:41324
[email protected]c1bb5af2013-03-13 19:06:27325 AnimationRegistrar* animation_registrar() const {
326 return animation_registrar_.get();
327 }
[email protected]de4afb5e2012-12-20 00:11:34328
[email protected]6e7fdeb2013-07-09 14:28:38329 void SetDebugState(const LayerTreeDebugState& new_debug_state);
[email protected]c1bb5af2013-03-13 19:06:27330 const LayerTreeDebugState& debug_state() const { return debug_state_; }
[email protected]f511afb2012-11-30 01:55:20331
[email protected]c1bb5af2013-03-13 19:06:27332 class CC_EXPORT CullRenderPassesWithCachedTextures {
333 public:
334 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
335 const FrameData& frame) const;
[email protected]cd57cc5a2012-10-12 22:43:41336
[email protected]c1bb5af2013-03-13 19:06:27337 // Iterates from the root first, in order to remove the surfaces closest
338 // to the root with cached textures, and all surfaces that draw into
339 // them.
340 size_t RenderPassListBegin(const RenderPassList& list) const {
341 return list.size() - 1;
342 }
343 size_t RenderPassListEnd(const RenderPassList& list) const { return 0 - 1; }
344 size_t RenderPassListNext(size_t it) const { return it - 1; }
[email protected]cd57cc5a2012-10-12 22:43:41345
[email protected]bf691c22013-03-26 21:15:06346 explicit CullRenderPassesWithCachedTextures(Renderer* renderer)
[email protected]c1bb5af2013-03-13 19:06:27347 : renderer_(renderer) {}
348 private:
[email protected]bf691c22013-03-26 21:15:06349 Renderer* renderer_;
[email protected]c1bb5af2013-03-13 19:06:27350 };
[email protected]cd57cc5a2012-10-12 22:43:41351
[email protected]c1bb5af2013-03-13 19:06:27352 class CC_EXPORT CullRenderPassesWithNoQuads {
353 public:
354 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
355 const FrameData& frame) const;
[email protected]cd57cc5a2012-10-12 22:43:41356
[email protected]c1bb5af2013-03-13 19:06:27357 // Iterates in draw order, so that when a surface is removed, and its
358 // target becomes empty, then its target can be removed also.
359 size_t RenderPassListBegin(const RenderPassList& list) const { return 0; }
360 size_t RenderPassListEnd(const RenderPassList& list) const {
361 return list.size();
362 }
363 size_t RenderPassListNext(size_t it) const { return it + 1; }
364 };
[email protected]cd57cc5a2012-10-12 22:43:41365
[email protected]c1bb5af2013-03-13 19:06:27366 template <typename RenderPassCuller>
367 static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame);
[email protected]cd57cc5a2012-10-12 22:43:41368
[email protected]a2b5ded2013-05-20 21:32:53369 gfx::Vector2dF accumulated_root_overscroll() const {
370 return accumulated_root_overscroll_;
371 }
372 gfx::Vector2dF current_fling_velocity() const {
373 return current_fling_velocity_;
374 }
375
[email protected]c1bb5af2013-03-13 19:06:27376 bool pinch_gesture_active() const { return pinch_gesture_active_; }
[email protected]166db5c82013-01-09 23:54:31377
[email protected]c1bb5af2013-03-13 19:06:27378 void SetTreePriority(TreePriority priority);
[email protected]362f1e8b2013-01-21 16:54:30379
[email protected]8347d692013-05-17 23:22:38380 void ResetCurrentFrameTimeForNextFrame();
[email protected]fb7425a2013-04-22 16:28:55381 base::TimeTicks CurrentFrameTimeTicks();
382 base::Time CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10383
[email protected]21c9dee72013-06-15 01:20:05384 virtual base::TimeTicks CurrentPhysicalTimeTicks() const;
385
[email protected]34806722013-08-09 23:51:21386 scoped_ptr<base::Value> AsValue() const { return AsValueWithFrame(NULL); }
387 scoped_ptr<base::Value> AsValueWithFrame(FrameData* frame) const;
[email protected]c1bb5af2013-03-13 19:06:27388 scoped_ptr<base::Value> ActivationStateAsValue() const;
[email protected]131a0c22013-02-12 18:31:08389
[email protected]c1bb5af2013-03-13 19:06:27390 bool page_scale_animation_active() const { return !!page_scale_animation_; }
[email protected]498ddd02013-02-28 23:59:25391
[email protected]c9280762013-08-01 06:28:57392 void CreateUIResource(UIResourceId uid,
393 scoped_refptr<UIResourceBitmap> bitmap);
394 // Deletes a UI resource. May safely be called more than once.
395 void DeleteUIResource(UIResourceId uid);
396
397 ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
398
[email protected]c1bb5af2013-03-13 19:06:27399 protected:
[email protected]372bad5f2013-03-21 16:38:43400 LayerTreeHostImpl(
401 const LayerTreeSettings& settings,
402 LayerTreeHostImplClient* client,
403 Proxy* proxy,
404 RenderingStatsInstrumentation* rendering_stats_instrumentation);
[email protected]cd57cc5a2012-10-12 22:43:41405
[email protected]c1bb5af2013-03-13 19:06:27406 // Virtual for testing.
407 virtual void AnimateLayers(base::TimeTicks monotonic_time,
408 base::Time wall_clock_time);
[email protected]cd57cc5a2012-10-12 22:43:41409
[email protected]c1bb5af2013-03-13 19:06:27410 // Virtual for testing.
411 virtual base::TimeDelta LowFrequencyAnimationInterval() const;
[email protected]cd57cc5a2012-10-12 22:43:41412
[email protected]c1bb5af2013-03-13 19:06:27413 const AnimationRegistrar::AnimationControllerMap&
414 active_animation_controllers() const {
415 return animation_registrar_->active_animation_controllers();
416 }
[email protected]de4afb5e2012-12-20 00:11:34417
[email protected]c1bb5af2013-03-13 19:06:27418 LayerTreeHostImplClient* client_;
419 Proxy* proxy_;
[email protected]cd57cc5a2012-10-12 22:43:41420
[email protected]c1bb5af2013-03-13 19:06:27421 private:
[email protected]b5174d712013-08-28 08:10:43422 void CreateAndSetRenderer(
423 OutputSurface* output_surface,
424 ResourceProvider* resource_provider,
425 bool skip_gl_renderer);
[email protected]50af3c22013-07-13 03:50:20426 void CreateAndSetTileManager(ResourceProvider* resource_provider,
427 bool using_map_image);
[email protected]50644642013-06-20 13:58:55428 void ReleaseTreeResources();
429 void EnforceZeroBudget(bool zero_budget);
[email protected]2b154b22013-06-07 09:03:27430
[email protected]c1bb5af2013-03-13 19:06:27431 void AnimatePageScale(base::TimeTicks monotonic_time);
432 void AnimateScrollbars(base::TimeTicks monotonic_time);
[email protected]ffb2720f2013-03-15 19:18:37433 void AnimateTopControls(base::TimeTicks monotonic_time);
[email protected]2d692992012-12-19 01:19:32434
[email protected]c1bb5af2013-03-13 19:06:27435 gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
[email protected]ed511b8d2013-03-25 03:29:29436 LayerImpl* layer_impl,
437 float scale_from_viewport_to_screen_space,
438 gfx::PointF viewport_point,
439 gfx::Vector2dF viewport_delta);
[email protected]615c78a2013-01-24 23:44:16440
[email protected]c1bb5af2013-03-13 19:06:27441 void UpdateMaxScrollOffset();
[email protected]50761e92013-03-29 20:51:28442 void TrackDamageForAllSurfaces(
443 LayerImpl* root_draw_layer,
444 const LayerImplList& render_surface_layer_list);
[email protected]cd57cc5a2012-10-12 22:43:41445
[email protected]8be1a9bf2013-05-01 03:45:19446 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
447
[email protected]c1bb5af2013-03-13 19:06:27448 // Returns false if the frame should not be displayed. This function should
[email protected]ed511b8d2013-03-25 03:29:29449 // only be called from PrepareToDraw, as DidDrawAllLayers must be called
[email protected]c1bb5af2013-03-13 19:06:27450 // if this helper function is called.
451 bool CalculateRenderPasses(FrameData* frame);
[email protected]cd57cc5a2012-10-12 22:43:41452
[email protected]50644642013-06-20 13:58:55453 void SendReleaseResourcesRecursive(LayerImpl* current);
[email protected]c1bb5af2013-03-13 19:06:27454 bool EnsureRenderSurfaceLayerList();
455 void ClearCurrentlyScrollingLayer();
[email protected]cd57cc5a2012-10-12 22:43:41456
[email protected]c1bb5af2013-03-13 19:06:27457 void AnimateScrollbarsRecursive(LayerImpl* layer,
458 base::TimeTicks time);
[email protected]cd57cc5a2012-10-12 22:43:41459
[email protected]21c9dee72013-06-15 01:20:05460 void UpdateCurrentFrameTime(base::TimeTicks* ticks, base::Time* now) const;
461
[email protected]0fc818e2013-03-18 06:45:20462 void StartScrollbarAnimationRecursive(LayerImpl* layer, base::TimeTicks time);
[email protected]3f2ff112013-08-03 02:41:07463 void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy,
464 bool zero_budget);
[email protected]0309ba5e02013-06-26 04:11:08465 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
[email protected]0fc818e2013-03-18 06:45:20466
[email protected]8bb6cfa2013-07-23 00:11:19467 void DidInitializeVisibleTile();
468
[email protected]c9280762013-08-01 06:28:57469 typedef base::hash_map<UIResourceId, ResourceProvider::ResourceId>
470 UIResourceMap;
471 UIResourceMap ui_resource_map_;
472
[email protected]c1bb5af2013-03-13 19:06:27473 scoped_ptr<OutputSurface> output_surface_;
[email protected]b5174d712013-08-28 08:10:43474 scoped_refptr<ContextProvider> offscreen_context_provider_;
[email protected]fbe89f72013-05-21 07:24:24475
476 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
477 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
[email protected]c1bb5af2013-03-13 19:06:27478 scoped_ptr<ResourceProvider> resource_provider_;
[email protected]c1bb5af2013-03-13 19:06:27479 scoped_ptr<TileManager> tile_manager_;
[email protected]fbe89f72013-05-21 07:24:24480 scoped_ptr<Renderer> renderer_;
[email protected]3b31c6ac2012-12-06 21:27:29481
[email protected]c1bb5af2013-03-13 19:06:27482 // Tree currently being drawn.
483 scoped_ptr<LayerTreeImpl> active_tree_;
[email protected]3b31c6ac2012-12-06 21:27:29484
[email protected]c1bb5af2013-03-13 19:06:27485 // In impl-side painting mode, tree with possibly incomplete rasterized
[email protected]4f48f6e2013-08-27 06:33:38486 // content. May be promoted to active by ActivatePendingTree().
[email protected]c1bb5af2013-03-13 19:06:27487 scoped_ptr<LayerTreeImpl> pending_tree_;
[email protected]48871fc2013-01-23 07:36:51488
[email protected]c1bb5af2013-03-13 19:06:27489 // In impl-side painting mode, inert tree with layers that can be recycled
490 // by the next sync from the main thread.
491 scoped_ptr<LayerTreeImpl> recycle_tree_;
[email protected]48871fc2013-01-23 07:36:51492
[email protected]200a9c062013-05-20 04:34:37493 InputHandlerClient* input_handler_client_;
[email protected]c1bb5af2013-03-13 19:06:27494 bool did_lock_scrolling_layer_;
495 bool should_bubble_scrolls_;
496 bool wheel_scrolling_;
[email protected]a23451e2013-06-07 20:58:26497
498 bool manage_tiles_needed_;
499
[email protected]1960a712013-04-30 17:06:47500 // The optional delegate for the root layer scroll offset.
501 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
[email protected]c1bb5af2013-03-13 19:06:27502 LayerTreeSettings settings_;
503 LayerTreeDebugState debug_state_;
[email protected]c1bb5af2013-03-13 19:06:27504 bool visible_;
[email protected]3f2ff112013-08-03 02:41:07505 ManagedMemoryPolicy cached_managed_memory_policy_;
[email protected]cd57cc5a2012-10-12 22:43:41506
[email protected]a2b5ded2013-05-20 21:32:53507 gfx::Vector2dF accumulated_root_overscroll_;
[email protected]6e921bd2013-04-29 21:10:20508 gfx::Vector2dF current_fling_velocity_;
509
[email protected]c1bb5af2013-03-13 19:06:27510 bool pinch_gesture_active_;
511 gfx::Point previous_pinch_anchor_;
[email protected]cd57cc5a2012-10-12 22:43:41512
[email protected]c1bb5af2013-03-13 19:06:27513 // This is set by AnimateLayers() and used by UpdateAnimationState()
514 // when sending animation events to the main thread.
515 base::Time last_animation_time_;
[email protected]6ad55bb22013-02-08 21:34:33516
[email protected]c1bb5af2013-03-13 19:06:27517 scoped_ptr<TopControlsManager> top_controls_manager_;
[email protected]3ba4cae2013-01-16 03:58:38518
[email protected]c1bb5af2013-03-13 19:06:27519 scoped_ptr<PageScaleAnimation> page_scale_animation_;
[email protected]cd57cc5a2012-10-12 22:43:41520
[email protected]c1bb5af2013-03-13 19:06:27521 // This is used for ticking animations slowly when hidden.
522 scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
[email protected]cd57cc5a2012-10-12 22:43:41523
[email protected]c1bb5af2013-03-13 19:06:27524 scoped_ptr<FrameRateCounter> fps_counter_;
525 scoped_ptr<PaintTimeCounter> paint_time_counter_;
526 scoped_ptr<MemoryHistory> memory_history_;
527 scoped_ptr<DebugRectHistory> debug_rect_history_;
[email protected]cd57cc5a2012-10-12 22:43:41528
[email protected]d7626ffd2013-03-29 00:17:42529 // The maximum memory that would be used by the prioritized resource
530 // manager, if there were no limit on memory usage.
531 size_t max_memory_needed_bytes_;
532
[email protected]c1bb5af2013-03-13 19:06:27533 size_t last_sent_memory_visible_bytes_;
534 size_t last_sent_memory_visible_and_nearby_bytes_;
535 size_t last_sent_memory_use_bytes_;
[email protected]50644642013-06-20 13:58:55536 bool zero_budget_;
[email protected]d3afa112012-12-08 06:24:28537
[email protected]f224cc92013-06-06 23:23:32538 // Viewport size passed in from the main thread, in physical pixels.
539 gfx::Size device_viewport_size_;
540
541 // Conversion factor from CSS pixels to physical pixels when
542 // pageScaleFactor=1.
543 float device_scale_factor_;
544
[email protected]9f4f6a32013-09-04 21:35:12545 // UI resource to use for drawing overhang gutters.
546 UIResourceId overhang_ui_resource_id_;
547 gfx::Size overhang_ui_resource_size_;
548
[email protected]f224cc92013-06-06 23:23:32549 // Vertical amount of the viewport size that's known to covered by a
550 // browser-side UI element, such as an on-screen-keyboard. This affects
551 // scrollable size since we want to still be able to scroll to the bottom of
552 // the page when the keyboard is up.
553 float overdraw_bottom_height_;
554
555 // Optional top-level constraints that can be set by the OutputSurface. The
556 // external_viewport_'s size takes precedence over device_viewport_size_ for
557 // DrawQuad generation and Renderer; however, device_viewport_size_ is still
558 // used for scrollable size.
559 gfx::Transform external_transform_;
560 gfx::Rect external_viewport_;
[email protected]c32a1962013-07-30 19:41:17561 bool external_stencil_test_enabled_;
[email protected]f224cc92013-06-06 23:23:32562
[email protected]878705be2013-04-15 22:44:02563 gfx::Rect viewport_damage_rect_;
[email protected]e0341352013-04-06 05:01:20564
[email protected]fb7425a2013-04-22 16:28:55565 base::TimeTicks current_frame_timeticks_;
566 base::Time current_frame_time_;
[email protected]829ad972013-01-28 23:36:10567
[email protected]c1bb5af2013-03-13 19:06:27568 scoped_ptr<AnimationRegistrar> animation_registrar_;
[email protected]de4afb5e2012-12-20 00:11:34569
[email protected]372bad5f2013-03-21 16:38:43570 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
571
[email protected]8bb6cfa2013-07-23 00:11:19572 bool need_to_update_visible_tiles_before_draw_;
[email protected]39643fb2013-07-09 17:28:19573
[email protected]5f07afc2013-07-19 05:17:18574 // Optional callback to notify of new tree activations.
[email protected]2022c672013-07-23 19:55:26575 base::Closure tree_activation_callback_;
[email protected]5f07afc2013-07-19 05:17:18576
[email protected]c1bb5af2013-03-13 19:06:27577 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
[email protected]cd57cc5a2012-10-12 22:43:41578};
579
[email protected]0023e8b2012-10-15 12:52:45580} // namespace cc
[email protected]cd57cc5a2012-10-12 22:43:41581
[email protected]556fd292013-03-18 08:03:04582#endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_