blob: cd5eda59a8eccd59166fd4549fbf25cc4c1f32b4 [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]127bdc1a2013-09-11 01:44:489#include <set>
[email protected]bf691c22013-03-26 21:15:0610#include <string>
11#include <vector>
12
[email protected]c4040a522012-10-21 15:01:4013#include "base/basictypes.h"
[email protected]c9280762013-08-01 06:28:5714#include "base/containers/hash_tables.h"
[email protected]c4040a522012-10-21 15:01:4015#include "base/memory/scoped_ptr.h"
[email protected]1b0df502013-06-27 23:39:5816#include "base/time/time.h"
[email protected]95e4e1a02013-03-18 07:09:0917#include "cc/animation/animation_events.h"
18#include "cc/animation/animation_registrar.h"
[email protected]681ccff2013-03-18 06:13:5219#include "cc/base/cc_export.h"
[email protected]3052b10f2013-03-18 07:41:2120#include "cc/input/input_handler.h"
[email protected]1960a712013-04-30 17:06:4721#include "cc/input/layer_scroll_offset_delegate.h"
[email protected]3052b10f2013-03-18 07:41:2122#include "cc/input/top_controls_manager_client.h"
[email protected]50761e92013-03-29 20:51:2823#include "cc/layers/layer_lists.h"
[email protected]cc3cfaa2013-03-18 09:05:5224#include "cc/layers/render_pass_sink.h"
[email protected]df3c24c92013-06-19 03:54:3525#include "cc/output/begin_frame_args.h"
[email protected]fd32d122013-06-29 13:11:0426#include "cc/output/managed_memory_policy.h"
[email protected]7f0d825f2013-03-18 07:24:3027#include "cc/output/output_surface_client.h"
28#include "cc/output/renderer.h"
[email protected]89e8267a2013-03-18 07:50:5629#include "cc/quads/render_pass.h"
[email protected]c9280762013-08-01 06:28:5730#include "cc/resources/resource_provider.h"
[email protected]e12dd0e2013-03-18 08:24:4031#include "cc/resources/tile_manager.h"
[email protected]c9280762013-08-01 06:28:5732#include "skia/ext/refptr.h"
[email protected]ddf9df82012-10-16 06:52:4633#include "third_party/skia/include/core/SkColor.h"
[email protected]167ed9d52012-10-31 20:47:5834#include "ui/gfx/rect.h"
[email protected]cd57cc5a2012-10-12 22:43:4135
36namespace cc {
37
[email protected]96baf3e2012-10-22 23:09:5538class CompletionEvent;
[email protected]bf189f62012-12-18 03:42:1139class CompositorFrameMetadata;
[email protected]96baf3e2012-10-22 23:09:5540class DebugRectHistory;
41class FrameRateCounter;
[email protected]96baf3e2012-10-22 23:09:5542class LayerImpl;
43class LayerTreeHostImplTimeSourceAdapter;
[email protected]8bef40572012-12-11 21:38:0844class LayerTreeImpl;
[email protected]96baf3e2012-10-22 23:09:5545class PageScaleAnimation;
[email protected]0edbfbe9f2013-01-17 03:33:0346class PaintTimeCounter;
[email protected]1191d9d2013-02-02 06:00:3347class MemoryHistory;
[email protected]372bad5f2013-03-21 16:38:4348class RenderingStatsInstrumentation;
[email protected]96baf3e2012-10-22 23:09:5549class RenderPassDrawQuad;
[email protected]ea468c6c2013-09-10 08:25:1150class TextureMailboxDeleter;
[email protected]3ba4cae2013-01-16 03:58:3851class TopControlsManager;
[email protected]c9280762013-08-01 06:28:5752class UIResourceBitmap;
[email protected]cd57cc5a2012-10-12 22:43:4153struct RendererCapabilities;
[email protected]c9280762013-08-01 06:28:5754struct UIResourceRequest;
[email protected]cd57cc5a2012-10-12 22:43:4155
[email protected]96baf3e2012-10-22 23:09:5556// LayerTreeHost->Proxy callback interface.
57class LayerTreeHostImplClient {
[email protected]c1bb5af2013-03-13 19:06:2758 public:
59 virtual void DidLoseOutputSurfaceOnImplThread() = 0;
60 virtual void OnSwapBuffersCompleteOnImplThread() = 0;
[email protected]df3c24c92013-06-19 03:54:3561 virtual void BeginFrameOnImplThread(const BeginFrameArgs& args) = 0;
[email protected]c1bb5af2013-03-13 19:06:2762 virtual void OnCanDrawStateChanged(bool can_draw) = 0;
[email protected]4f48f6e2013-08-27 06:33:3863 virtual void NotifyReadyToActivate() = 0;
[email protected]c1bb5af2013-03-13 19:06:2764 virtual void SetNeedsRedrawOnImplThread() = 0;
[email protected]1cd9f5552013-04-26 04:22:0365 virtual void SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) = 0;
[email protected]86126792013-03-16 20:07:5466 virtual void DidInitializeVisibleTileOnImplThread() = 0;
[email protected]c1bb5af2013-03-13 19:06:2767 virtual void SetNeedsCommitOnImplThread() = 0;
[email protected]c1bb5af2013-03-13 19:06:2768 virtual void PostAnimationEventsToMainThreadOnImplThread(
69 scoped_ptr<AnimationEventsVector> events,
70 base::Time wall_clock_time) = 0;
71 // Returns true if resources were deleted by this call.
72 virtual bool ReduceContentsTextureMemoryOnImplThread(
73 size_t limit_bytes,
74 int priority_cutoff) = 0;
75 virtual void ReduceWastedContentsTextureMemoryOnImplThread() = 0;
76 virtual void SendManagedMemoryStats() = 0;
77 virtual bool IsInsideDraw() = 0;
78 virtual void RenewTreePriority() = 0;
[email protected]0fc818e2013-03-18 06:45:2079 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) = 0;
[email protected]2a61ad52013-05-13 14:01:2980 virtual void DidActivatePendingTree() = 0;
[email protected]bf691c22013-03-26 21:15:0681
82 protected:
83 virtual ~LayerTreeHostImplClient() {}
[email protected]cd57cc5a2012-10-12 22:43:4184};
85
[email protected]c1bb5af2013-03-13 19:06:2786// LayerTreeHostImpl owns the LayerImpl trees as well as associated rendering
87// state.
[email protected]200a9c062013-05-20 04:34:3788class CC_EXPORT LayerTreeHostImpl
89 : public InputHandler,
90 public RendererClient,
91 public TileManagerClient,
92 public OutputSurfaceClient,
93 public TopControlsManagerClient,
94 public base::SupportsWeakPtr<LayerTreeHostImpl> {
[email protected]e216fef02013-03-20 22:56:1095 public:
[email protected]c1bb5af2013-03-13 19:06:2796 static scoped_ptr<LayerTreeHostImpl> Create(
97 const LayerTreeSettings& settings,
98 LayerTreeHostImplClient* client,
[email protected]372bad5f2013-03-21 16:38:4399 Proxy* proxy,
100 RenderingStatsInstrumentation* rendering_stats_instrumentation);
[email protected]c1bb5af2013-03-13 19:06:27101 virtual ~LayerTreeHostImpl();
[email protected]cd57cc5a2012-10-12 22:43:41102
[email protected]5ff3c9782013-04-29 17:35:12103 // InputHandler implementation
[email protected]200a9c062013-05-20 04:34:37104 virtual void BindToClient(InputHandlerClient* client) OVERRIDE;
[email protected]5ff3c9782013-04-29 17:35:12105 virtual InputHandler::ScrollStatus ScrollBegin(
[email protected]c1bb5af2013-03-13 19:06:27106 gfx::Point viewport_point,
[email protected]5ff3c9782013-04-29 17:35:12107 InputHandler::ScrollInputType type) OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27108 virtual bool ScrollBy(gfx::Point viewport_point,
109 gfx::Vector2dF scroll_delta) OVERRIDE;
[email protected]c28df4c12013-05-22 17:36:49110 virtual bool ScrollVerticallyByPage(gfx::Point viewport_point,
111 ScrollDirection direction) OVERRIDE;
[email protected]1960a712013-04-30 17:06:47112 virtual void SetRootLayerScrollOffsetDelegate(
113 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) OVERRIDE;
114 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27115 virtual void ScrollEnd() OVERRIDE;
[email protected]5ff3c9782013-04-29 17:35:12116 virtual InputHandler::ScrollStatus FlingScrollBegin() OVERRIDE;
[email protected]6e921bd2013-04-29 21:10:20117 virtual void NotifyCurrentFlingVelocity(gfx::Vector2dF velocity) OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27118 virtual void PinchGestureBegin() OVERRIDE;
119 virtual void PinchGestureUpdate(float magnify_delta,
120 gfx::Point anchor) OVERRIDE;
121 virtual void PinchGestureEnd() OVERRIDE;
122 virtual void StartPageScaleAnimation(gfx::Vector2d target_offset,
123 bool anchor_point,
124 float page_scale,
125 base::TimeTicks start_time,
126 base::TimeDelta duration) OVERRIDE;
127 virtual void ScheduleAnimation() OVERRIDE;
128 virtual bool HaveTouchEventHandlersAt(gfx::Point viewport_port) OVERRIDE;
[email protected]b76329d2013-06-11 04:15:08129 virtual void SetLatencyInfoForInputEvent(const ui::LatencyInfo& latency_info)
130 OVERRIDE;
[email protected]cd57cc5a2012-10-12 22:43:41131
[email protected]c1bb5af2013-03-13 19:06:27132 // TopControlsManagerClient implementation.
[email protected]59adb112013-04-09 04:48:44133 virtual void DidChangeTopControlsPosition() OVERRIDE;
134 virtual bool HaveRootScrollLayer() const OVERRIDE;
[email protected]3ba4cae2013-01-16 03:58:38135
[email protected]21c9dee72013-06-15 01:20:05136 void StartScrollbarAnimation();
[email protected]0fc818e2013-03-18 06:45:20137
[email protected]c1bb5af2013-03-13 19:06:27138 struct CC_EXPORT FrameData : public RenderPassSink {
139 FrameData();
[email protected]ca2902e92013-03-28 01:45:35140 virtual ~FrameData();
[email protected]34806722013-08-09 23:51:21141 scoped_ptr<base::Value> AsValue() const;
[email protected]cd57cc5a2012-10-12 22:43:41142
[email protected]c1bb5af2013-03-13 19:06:27143 std::vector<gfx::Rect> occluding_screen_space_rects;
144 std::vector<gfx::Rect> non_occluding_screen_space_rects;
145 RenderPassList render_passes;
146 RenderPassIdHashMap render_passes_by_id;
[email protected]50761e92013-03-29 20:51:28147 const LayerImplList* render_surface_layer_list;
148 LayerImplList will_draw_layers;
[email protected]c1bb5af2013-03-13 19:06:27149 bool contains_incomplete_tile;
[email protected]e0341352013-04-06 05:01:20150 bool has_no_damage;
[email protected]cd57cc5a2012-10-12 22:43:41151
[email protected]c1bb5af2013-03-13 19:06:27152 // RenderPassSink implementation.
153 virtual void AppendRenderPass(scoped_ptr<RenderPass> render_pass) OVERRIDE;
154 };
[email protected]cd57cc5a2012-10-12 22:43:41155
[email protected]c1bb5af2013-03-13 19:06:27156 virtual void BeginCommit();
157 virtual void CommitComplete();
158 virtual void Animate(base::TimeTicks monotonic_time,
159 base::Time wall_clock_time);
[email protected]3d9f7432013-04-06 00:35:18160 virtual void UpdateAnimationState(bool start_ready_animations);
[email protected]200a9c062013-05-20 04:34:37161 void MainThreadHasStoppedFlinging();
[email protected]3d9f7432013-04-06 00:35:18162 void UpdateBackgroundAnimateTicking(bool should_background_tick);
[email protected]b9d4a362013-04-23 05:36:27163 void SetViewportDamage(gfx::Rect damage_rect);
[email protected]cd57cc5a2012-10-12 22:43:41164
[email protected]c1bb5af2013-03-13 19:06:27165 void ManageTiles();
[email protected]8947cbe2012-11-28 05:27:43166
[email protected]c1bb5af2013-03-13 19:06:27167 // Returns false if problems occured preparing the frame, and we should try
[email protected]ed511b8d2013-03-25 03:29:29168 // to avoid displaying the frame. If PrepareToDraw is called, DidDrawAllLayers
[email protected]c1bb5af2013-03-13 19:06:27169 // must also be called, regardless of whether DrawLayers is called between the
170 // two.
[email protected]e0341352013-04-06 05:01:20171 virtual bool PrepareToDraw(FrameData* frame,
172 gfx::Rect device_viewport_damage_rect);
[email protected]f0c2a242013-03-15 19:34:52173 virtual void DrawLayers(FrameData* frame, base::TimeTicks frame_begin_time);
[email protected]c1bb5af2013-03-13 19:06:27174 // Must be called if and only if PrepareToDraw was called.
175 void DidDrawAllLayers(const FrameData& frame);
[email protected]cd57cc5a2012-10-12 22:43:41176
[email protected]c1bb5af2013-03-13 19:06:27177 const LayerTreeSettings& settings() const { return settings_; }
[email protected]cd57cc5a2012-10-12 22:43:41178
[email protected]0309ba5e02013-06-26 04:11:08179 // Evict all textures by enforcing a memory policy with an allocation of 0.
180 void EvictTexturesForTesting();
181
[email protected]4f48f6e2013-08-27 06:33:38182 // When blocking, this prevents client_->NotifyReadyToActivate() from being
183 // called. When disabled, it calls client_->NotifyReadyToActivate()
184 // immediately if any notifications had been blocked while blocking.
185 virtual void BlockNotifyReadyToActivateForTesting(bool block);
186
[email protected]54af03522013-09-05 00:43:28187 bool device_viewport_valid_for_tile_management() const {
188 return device_viewport_valid_for_tile_management_;
189 }
190
191 // Viewport size in draw space: this size is in physical pixels and is used
192 // for draw properties, tilings, quads and render passes.
193 gfx::Size DrawViewportSize() const;
194
195 // Viewport size for scrolling and fixed-position compensation. This value
196 // excludes the URL bar and non-overlay scrollbars and is in DIP (and
197 // invariant relative to page scale).
198 gfx::SizeF UnscaledScrollableViewportSize() const;
199
[email protected]c1bb5af2013-03-13 19:06:27200 // RendererClient implementation
[email protected]54af03522013-09-05 00:43:28201
202 // Viewport rectangle and clip in nonflipped window space. These rects
203 // should only be used by Renderer subclasses to populate glViewport/glClip
204 // and their software-mode equivalents.
[email protected]f224cc92013-06-06 23:23:32205 virtual gfx::Rect DeviceViewport() const OVERRIDE;
[email protected]54af03522013-09-05 00:43:28206 virtual gfx::Rect DeviceClip() const OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27207 virtual void SetFullRootLayerDamage() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:27208 virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const OVERRIDE;
[email protected]8947cbe2012-11-28 05:27:43209
[email protected]c1bb5af2013-03-13 19:06:27210 // TileManagerClient implementation.
[email protected]94bf75c2013-06-12 13:20:04211 virtual void NotifyReadyToActivate() OVERRIDE;
[email protected]cd57cc5a2012-10-12 22:43:41212
[email protected]c1bb5af2013-03-13 19:06:27213 // OutputSurfaceClient implementation.
[email protected]2b154b22013-06-07 09:03:27214 virtual bool DeferredInitialize(
215 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE;
[email protected]50af3c22013-07-13 03:50:20216 virtual void ReleaseGL() OVERRIDE;
[email protected]1cd9f5552013-04-26 04:22:03217 virtual void SetNeedsRedrawRect(gfx::Rect rect) OVERRIDE;
[email protected]fd32d122013-06-29 13:11:04218 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE;
[email protected]54af03522013-09-05 00:43:28219 virtual void SetExternalDrawConstraints(
220 const gfx::Transform& transform,
221 gfx::Rect viewport,
222 gfx::Rect clip,
223 bool valid_for_tile_management) OVERRIDE;
[email protected]049fc7a2013-06-18 12:32:35224 virtual void DidLoseOutputSurface() OVERRIDE;
225 virtual void OnSwapBuffersComplete(const CompositorFrameAck* ack) OVERRIDE;
[email protected]3f2ff112013-08-03 02:41:07226 virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE;
227 virtual void SetDiscardBackBufferWhenNotVisible(bool discard) OVERRIDE;
[email protected]5f07afc2013-07-19 05:17:18228 virtual void SetTreeActivationCallback(const base::Closure& callback)
229 OVERRIDE;
[email protected]3b31c6ac2012-12-06 21:27:29230
[email protected]c1bb5af2013-03-13 19:06:27231 // Called from LayerTreeImpl.
232 void OnCanDrawStateChangedForTree();
[email protected]cd57cc5a2012-10-12 22:43:41233
[email protected]b5174d712013-08-28 08:10:43234 // Implementation.
[email protected]6133cc232013-07-30 18:47:07235 bool CanDraw() const;
[email protected]c1bb5af2013-03-13 19:06:27236 OutputSurface* output_surface() const { return output_surface_.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41237
[email protected]b5174d712013-08-28 08:10:43238 void SetOffscreenContextProvider(
239 const scoped_refptr<ContextProvider>& offscreen_context_provider);
240 ContextProvider* offscreen_context_provider() const {
241 return offscreen_context_provider_.get();
242 }
243
[email protected]c1bb5af2013-03-13 19:06:27244 std::string LayerTreeAsJson() const;
[email protected]cd57cc5a2012-10-12 22:43:41245
[email protected]c1bb5af2013-03-13 19:06:27246 void FinishAllRendering();
247 int SourceAnimationFrameNumber() const;
[email protected]cd57cc5a2012-10-12 22:43:41248
[email protected]c1bb5af2013-03-13 19:06:27249 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface);
250 bool IsContextLost();
251 TileManager* tile_manager() { return tile_manager_.get(); }
252 Renderer* renderer() { return renderer_.get(); }
253 const RendererCapabilities& GetRendererCapabilities() const;
[email protected]cd57cc5a2012-10-12 22:43:41254
[email protected]e0341352013-04-06 05:01:20255 virtual bool SwapBuffers(const FrameData& frame);
[email protected]c8cbae72013-05-23 10:45:03256 void SetNeedsBeginFrame(bool enable);
[email protected]a23451e2013-06-07 20:58:26257 void SetNeedsManageTiles() { manage_tiles_needed_ = true; }
[email protected]cd57cc5a2012-10-12 22:43:41258
[email protected]c1bb5af2013-03-13 19:06:27259 void Readback(void* pixels, gfx::Rect rect_in_device_viewport);
[email protected]cd57cc5a2012-10-12 22:43:41260
[email protected]c1bb5af2013-03-13 19:06:27261 LayerTreeImpl* active_tree() { return active_tree_.get(); }
262 const LayerTreeImpl* active_tree() const { return active_tree_.get(); }
263 LayerTreeImpl* pending_tree() { return pending_tree_.get(); }
264 const LayerTreeImpl* pending_tree() const { return pending_tree_.get(); }
265 const LayerTreeImpl* recycle_tree() const { return recycle_tree_.get(); }
[email protected]2f0d92f2013-06-11 04:07:20266 virtual void CreatePendingTree();
[email protected]1e212c9bb2013-09-07 04:32:14267 virtual void UpdateVisibleTiles();
[email protected]4f48f6e2013-08-27 06:33:38268 virtual void ActivatePendingTree();
[email protected]cd57cc5a2012-10-12 22:43:41269
[email protected]c1bb5af2013-03-13 19:06:27270 // Shortcuts to layers on the active tree.
271 LayerImpl* RootLayer() const;
272 LayerImpl* RootScrollLayer() const;
273 LayerImpl* CurrentlyScrollingLayer() const;
[email protected]cd57cc5a2012-10-12 22:43:41274
[email protected]c1bb5af2013-03-13 19:06:27275 virtual void SetVisible(bool visible);
276 bool visible() const { return visible_; }
[email protected]cd57cc5a2012-10-12 22:43:41277
[email protected]d7eb8c72013-03-23 22:57:13278 void SetNeedsCommit() { client_->SetNeedsCommitOnImplThread(); }
[email protected]59adb112013-04-09 04:48:44279 void SetNeedsRedraw() { client_->SetNeedsRedrawOnImplThread(); }
[email protected]d7eb8c72013-03-23 22:57:13280
[email protected]206a3922013-05-17 06:34:12281 ManagedMemoryPolicy ActualManagedMemoryPolicy() const;
282
[email protected]3f2ff112013-08-03 02:41:07283 size_t memory_allocation_limit_bytes() const;
[email protected]cd57cc5a2012-10-12 22:43:41284
[email protected]18ce59702013-04-09 04:58:40285 void SetViewportSize(gfx::Size device_viewport_size);
[email protected]cd57cc5a2012-10-12 22:43:41286
[email protected]d9083762013-03-24 01:36:40287 void SetOverdrawBottomHeight(float overdraw_bottom_height);
288 float overdraw_bottom_height() const { return overdraw_bottom_height_; }
289
[email protected]9f4f6a32013-09-04 21:35:12290 void SetOverhangUIResource(UIResourceId overhang_ui_resource_id,
291 gfx::Size overhang_ui_resource_size);
292
[email protected]c1bb5af2013-03-13 19:06:27293 void SetDeviceScaleFactor(float device_scale_factor);
294 float device_scale_factor() const { return device_scale_factor_; }
[email protected]cd57cc5a2012-10-12 22:43:41295
[email protected]54af03522013-09-05 00:43:28296 const gfx::Transform& DrawTransform() const;
[email protected]f224cc92013-06-06 23:23:32297
[email protected]c1bb5af2013-03-13 19:06:27298 scoped_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
[email protected]cd57cc5a2012-10-12 22:43:41299
[email protected]c1bb5af2013-03-13 19:06:27300 bool needs_animate_layers() const {
301 return !animation_registrar_->active_animation_controllers().empty();
302 }
[email protected]cd57cc5a2012-10-12 22:43:41303
[email protected]c1bb5af2013-03-13 19:06:27304 void SendManagedMemoryStats(
305 size_t memory_visible_bytes,
306 size_t memory_visible_and_nearby_bytes,
[email protected]ed511b8d2013-03-25 03:29:29307 size_t memory_use_bytes);
[email protected]c1bb5af2013-03-13 19:06:27308
[email protected]d7626ffd2013-03-29 00:17:42309 void set_max_memory_needed_bytes(size_t bytes) {
310 max_memory_needed_bytes_ = bytes;
311 }
312
[email protected]c1bb5af2013-03-13 19:06:27313 FrameRateCounter* fps_counter() {
314 return fps_counter_.get();
315 }
316 PaintTimeCounter* paint_time_counter() {
317 return paint_time_counter_.get();
318 }
319 MemoryHistory* memory_history() {
320 return memory_history_.get();
321 }
322 DebugRectHistory* debug_rect_history() {
323 return debug_rect_history_.get();
324 }
325 ResourceProvider* resource_provider() {
326 return resource_provider_.get();
327 }
328 TopControlsManager* top_controls_manager() {
329 return top_controls_manager_.get();
330 }
[email protected]ff762fb2012-12-12 19:18:37331
[email protected]c1bb5af2013-03-13 19:06:27332 Proxy* proxy() const { return proxy_; }
[email protected]cd57cc5a2012-10-12 22:43:41333
[email protected]c1bb5af2013-03-13 19:06:27334 AnimationRegistrar* animation_registrar() const {
335 return animation_registrar_.get();
336 }
[email protected]de4afb5e2012-12-20 00:11:34337
[email protected]6e7fdeb2013-07-09 14:28:38338 void SetDebugState(const LayerTreeDebugState& new_debug_state);
[email protected]c1bb5af2013-03-13 19:06:27339 const LayerTreeDebugState& debug_state() const { return debug_state_; }
[email protected]f511afb2012-11-30 01:55:20340
[email protected]c1bb5af2013-03-13 19:06:27341 class CC_EXPORT CullRenderPassesWithCachedTextures {
342 public:
343 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
344 const FrameData& frame) const;
[email protected]cd57cc5a2012-10-12 22:43:41345
[email protected]c1bb5af2013-03-13 19:06:27346 // Iterates from the root first, in order to remove the surfaces closest
347 // to the root with cached textures, and all surfaces that draw into
348 // them.
349 size_t RenderPassListBegin(const RenderPassList& list) const {
350 return list.size() - 1;
351 }
352 size_t RenderPassListEnd(const RenderPassList& list) const { return 0 - 1; }
353 size_t RenderPassListNext(size_t it) const { return it - 1; }
[email protected]cd57cc5a2012-10-12 22:43:41354
[email protected]bf691c22013-03-26 21:15:06355 explicit CullRenderPassesWithCachedTextures(Renderer* renderer)
[email protected]c1bb5af2013-03-13 19:06:27356 : renderer_(renderer) {}
357 private:
[email protected]bf691c22013-03-26 21:15:06358 Renderer* renderer_;
[email protected]c1bb5af2013-03-13 19:06:27359 };
[email protected]cd57cc5a2012-10-12 22:43:41360
[email protected]c1bb5af2013-03-13 19:06:27361 class CC_EXPORT CullRenderPassesWithNoQuads {
362 public:
363 bool ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
364 const FrameData& frame) const;
[email protected]cd57cc5a2012-10-12 22:43:41365
[email protected]c1bb5af2013-03-13 19:06:27366 // Iterates in draw order, so that when a surface is removed, and its
367 // target becomes empty, then its target can be removed also.
368 size_t RenderPassListBegin(const RenderPassList& list) const { return 0; }
369 size_t RenderPassListEnd(const RenderPassList& list) const {
370 return list.size();
371 }
372 size_t RenderPassListNext(size_t it) const { return it + 1; }
373 };
[email protected]cd57cc5a2012-10-12 22:43:41374
[email protected]c1bb5af2013-03-13 19:06:27375 template <typename RenderPassCuller>
376 static void RemoveRenderPasses(RenderPassCuller culler, FrameData* frame);
[email protected]cd57cc5a2012-10-12 22:43:41377
[email protected]a2b5ded2013-05-20 21:32:53378 gfx::Vector2dF accumulated_root_overscroll() const {
379 return accumulated_root_overscroll_;
380 }
381 gfx::Vector2dF current_fling_velocity() const {
382 return current_fling_velocity_;
383 }
384
[email protected]c1bb5af2013-03-13 19:06:27385 bool pinch_gesture_active() const { return pinch_gesture_active_; }
[email protected]166db5c82013-01-09 23:54:31386
[email protected]c1bb5af2013-03-13 19:06:27387 void SetTreePriority(TreePriority priority);
[email protected]362f1e8b2013-01-21 16:54:30388
[email protected]8347d692013-05-17 23:22:38389 void ResetCurrentFrameTimeForNextFrame();
[email protected]54af03522013-09-05 00:43:28390 virtual base::TimeTicks CurrentFrameTimeTicks();
[email protected]fb7425a2013-04-22 16:28:55391 base::Time CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10392
[email protected]21c9dee72013-06-15 01:20:05393 virtual base::TimeTicks CurrentPhysicalTimeTicks() const;
394
[email protected]34806722013-08-09 23:51:21395 scoped_ptr<base::Value> AsValue() const { return AsValueWithFrame(NULL); }
396 scoped_ptr<base::Value> AsValueWithFrame(FrameData* frame) const;
[email protected]c1bb5af2013-03-13 19:06:27397 scoped_ptr<base::Value> ActivationStateAsValue() const;
[email protected]131a0c22013-02-12 18:31:08398
[email protected]c1bb5af2013-03-13 19:06:27399 bool page_scale_animation_active() const { return !!page_scale_animation_; }
[email protected]498ddd02013-02-28 23:59:25400
[email protected]c9280762013-08-01 06:28:57401 void CreateUIResource(UIResourceId uid,
402 scoped_refptr<UIResourceBitmap> bitmap);
403 // Deletes a UI resource. May safely be called more than once.
404 void DeleteUIResource(UIResourceId uid);
[email protected]127bdc1a2013-09-11 01:44:48405 void EvictAllUIResources();
406 bool EvictedUIResourcesExist() const;
[email protected]c9280762013-08-01 06:28:57407
408 ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
409
[email protected]1e212c9bb2013-09-07 04:32:14410 void DidInitializeVisibleTileForTesting() { DidInitializeVisibleTile(); }
411
[email protected]c1bb5af2013-03-13 19:06:27412 protected:
[email protected]372bad5f2013-03-21 16:38:43413 LayerTreeHostImpl(
414 const LayerTreeSettings& settings,
415 LayerTreeHostImplClient* client,
416 Proxy* proxy,
417 RenderingStatsInstrumentation* rendering_stats_instrumentation);
[email protected]cd57cc5a2012-10-12 22:43:41418
[email protected]c1bb5af2013-03-13 19:06:27419 // Virtual for testing.
420 virtual void AnimateLayers(base::TimeTicks monotonic_time,
421 base::Time wall_clock_time);
[email protected]cd57cc5a2012-10-12 22:43:41422
[email protected]c1bb5af2013-03-13 19:06:27423 // Virtual for testing.
424 virtual base::TimeDelta LowFrequencyAnimationInterval() const;
[email protected]cd57cc5a2012-10-12 22:43:41425
[email protected]c1bb5af2013-03-13 19:06:27426 const AnimationRegistrar::AnimationControllerMap&
427 active_animation_controllers() const {
428 return animation_registrar_->active_animation_controllers();
429 }
[email protected]de4afb5e2012-12-20 00:11:34430
[email protected]54af03522013-09-05 00:43:28431 bool manage_tiles_needed() const { return manage_tiles_needed_; }
432
[email protected]c1bb5af2013-03-13 19:06:27433 LayerTreeHostImplClient* client_;
434 Proxy* proxy_;
[email protected]cd57cc5a2012-10-12 22:43:41435
[email protected]c1bb5af2013-03-13 19:06:27436 private:
[email protected]b5174d712013-08-28 08:10:43437 void CreateAndSetRenderer(
438 OutputSurface* output_surface,
439 ResourceProvider* resource_provider,
440 bool skip_gl_renderer);
[email protected]50af3c22013-07-13 03:50:20441 void CreateAndSetTileManager(ResourceProvider* resource_provider,
[email protected]b6eb8e332013-09-10 00:51:01442 ContextProvider* context_provider,
[email protected]50af3c22013-07-13 03:50:20443 bool using_map_image);
[email protected]50644642013-06-20 13:58:55444 void ReleaseTreeResources();
445 void EnforceZeroBudget(bool zero_budget);
[email protected]2b154b22013-06-07 09:03:27446
[email protected]c1bb5af2013-03-13 19:06:27447 void AnimatePageScale(base::TimeTicks monotonic_time);
448 void AnimateScrollbars(base::TimeTicks monotonic_time);
[email protected]ffb2720f2013-03-15 19:18:37449 void AnimateTopControls(base::TimeTicks monotonic_time);
[email protected]2d692992012-12-19 01:19:32450
[email protected]c1bb5af2013-03-13 19:06:27451 gfx::Vector2dF ScrollLayerWithViewportSpaceDelta(
[email protected]ed511b8d2013-03-25 03:29:29452 LayerImpl* layer_impl,
453 float scale_from_viewport_to_screen_space,
454 gfx::PointF viewport_point,
455 gfx::Vector2dF viewport_delta);
[email protected]615c78a2013-01-24 23:44:16456
[email protected]c1bb5af2013-03-13 19:06:27457 void UpdateMaxScrollOffset();
[email protected]50761e92013-03-29 20:51:28458 void TrackDamageForAllSurfaces(
459 LayerImpl* root_draw_layer,
460 const LayerImplList& render_surface_layer_list);
[email protected]cd57cc5a2012-10-12 22:43:41461
[email protected]8be1a9bf2013-05-01 03:45:19462 void UpdateTileManagerMemoryPolicy(const ManagedMemoryPolicy& policy);
463
[email protected]c1bb5af2013-03-13 19:06:27464 // Returns false if the frame should not be displayed. This function should
[email protected]ed511b8d2013-03-25 03:29:29465 // only be called from PrepareToDraw, as DidDrawAllLayers must be called
[email protected]c1bb5af2013-03-13 19:06:27466 // if this helper function is called.
467 bool CalculateRenderPasses(FrameData* frame);
[email protected]cd57cc5a2012-10-12 22:43:41468
[email protected]50644642013-06-20 13:58:55469 void SendReleaseResourcesRecursive(LayerImpl* current);
[email protected]c1bb5af2013-03-13 19:06:27470 bool EnsureRenderSurfaceLayerList();
471 void ClearCurrentlyScrollingLayer();
[email protected]cd57cc5a2012-10-12 22:43:41472
[email protected]c1bb5af2013-03-13 19:06:27473 void AnimateScrollbarsRecursive(LayerImpl* layer,
474 base::TimeTicks time);
[email protected]cd57cc5a2012-10-12 22:43:41475
[email protected]21c9dee72013-06-15 01:20:05476 void UpdateCurrentFrameTime(base::TimeTicks* ticks, base::Time* now) const;
477
[email protected]0fc818e2013-03-18 06:45:20478 void StartScrollbarAnimationRecursive(LayerImpl* layer, base::TimeTicks time);
[email protected]3f2ff112013-08-03 02:41:07479 void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy,
480 bool zero_budget);
[email protected]0309ba5e02013-06-26 04:11:08481 void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy);
[email protected]0fc818e2013-03-18 06:45:20482
[email protected]8bb6cfa2013-07-23 00:11:19483 void DidInitializeVisibleTile();
484
[email protected]127bdc1a2013-09-11 01:44:48485 void MarkUIResourceNotEvicted(UIResourceId uid);
486
[email protected]c9280762013-08-01 06:28:57487 typedef base::hash_map<UIResourceId, ResourceProvider::ResourceId>
488 UIResourceMap;
489 UIResourceMap ui_resource_map_;
490
[email protected]127bdc1a2013-09-11 01:44:48491 // Resources that were evicted by EvictAllUIResources. Resources are removed
492 // from this when they are touched by a create or destroy from the UI resource
493 // request queue.
494 std::set<UIResourceId> evicted_ui_resources_;
495
[email protected]c1bb5af2013-03-13 19:06:27496 scoped_ptr<OutputSurface> output_surface_;
[email protected]b5174d712013-08-28 08:10:43497 scoped_refptr<ContextProvider> offscreen_context_provider_;
[email protected]fbe89f72013-05-21 07:24:24498
499 // |resource_provider_| and |tile_manager_| can be NULL, e.g. when using tile-
500 // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice().
[email protected]c1bb5af2013-03-13 19:06:27501 scoped_ptr<ResourceProvider> resource_provider_;
[email protected]c1bb5af2013-03-13 19:06:27502 scoped_ptr<TileManager> tile_manager_;
[email protected]fbe89f72013-05-21 07:24:24503 scoped_ptr<Renderer> renderer_;
[email protected]3b31c6ac2012-12-06 21:27:29504
[email protected]c1bb5af2013-03-13 19:06:27505 // Tree currently being drawn.
506 scoped_ptr<LayerTreeImpl> active_tree_;
[email protected]3b31c6ac2012-12-06 21:27:29507
[email protected]c1bb5af2013-03-13 19:06:27508 // In impl-side painting mode, tree with possibly incomplete rasterized
[email protected]4f48f6e2013-08-27 06:33:38509 // content. May be promoted to active by ActivatePendingTree().
[email protected]c1bb5af2013-03-13 19:06:27510 scoped_ptr<LayerTreeImpl> pending_tree_;
[email protected]48871fc2013-01-23 07:36:51511
[email protected]c1bb5af2013-03-13 19:06:27512 // In impl-side painting mode, inert tree with layers that can be recycled
513 // by the next sync from the main thread.
514 scoped_ptr<LayerTreeImpl> recycle_tree_;
[email protected]48871fc2013-01-23 07:36:51515
[email protected]200a9c062013-05-20 04:34:37516 InputHandlerClient* input_handler_client_;
[email protected]c1bb5af2013-03-13 19:06:27517 bool did_lock_scrolling_layer_;
518 bool should_bubble_scrolls_;
519 bool wheel_scrolling_;
[email protected]a23451e2013-06-07 20:58:26520
521 bool manage_tiles_needed_;
522
[email protected]1960a712013-04-30 17:06:47523 // The optional delegate for the root layer scroll offset.
524 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
[email protected]c1bb5af2013-03-13 19:06:27525 LayerTreeSettings settings_;
526 LayerTreeDebugState debug_state_;
[email protected]c1bb5af2013-03-13 19:06:27527 bool visible_;
[email protected]3f2ff112013-08-03 02:41:07528 ManagedMemoryPolicy cached_managed_memory_policy_;
[email protected]cd57cc5a2012-10-12 22:43:41529
[email protected]a2b5ded2013-05-20 21:32:53530 gfx::Vector2dF accumulated_root_overscroll_;
[email protected]6e921bd2013-04-29 21:10:20531 gfx::Vector2dF current_fling_velocity_;
532
[email protected]c1bb5af2013-03-13 19:06:27533 bool pinch_gesture_active_;
534 gfx::Point previous_pinch_anchor_;
[email protected]cd57cc5a2012-10-12 22:43:41535
[email protected]c1bb5af2013-03-13 19:06:27536 // This is set by AnimateLayers() and used by UpdateAnimationState()
537 // when sending animation events to the main thread.
538 base::Time last_animation_time_;
[email protected]6ad55bb22013-02-08 21:34:33539
[email protected]c1bb5af2013-03-13 19:06:27540 scoped_ptr<TopControlsManager> top_controls_manager_;
[email protected]3ba4cae2013-01-16 03:58:38541
[email protected]c1bb5af2013-03-13 19:06:27542 scoped_ptr<PageScaleAnimation> page_scale_animation_;
[email protected]cd57cc5a2012-10-12 22:43:41543
[email protected]c1bb5af2013-03-13 19:06:27544 // This is used for ticking animations slowly when hidden.
545 scoped_ptr<LayerTreeHostImplTimeSourceAdapter> time_source_client_adapter_;
[email protected]cd57cc5a2012-10-12 22:43:41546
[email protected]c1bb5af2013-03-13 19:06:27547 scoped_ptr<FrameRateCounter> fps_counter_;
548 scoped_ptr<PaintTimeCounter> paint_time_counter_;
549 scoped_ptr<MemoryHistory> memory_history_;
550 scoped_ptr<DebugRectHistory> debug_rect_history_;
[email protected]cd57cc5a2012-10-12 22:43:41551
[email protected]ea468c6c2013-09-10 08:25:11552 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
553
[email protected]d7626ffd2013-03-29 00:17:42554 // The maximum memory that would be used by the prioritized resource
555 // manager, if there were no limit on memory usage.
556 size_t max_memory_needed_bytes_;
557
[email protected]c1bb5af2013-03-13 19:06:27558 size_t last_sent_memory_visible_bytes_;
559 size_t last_sent_memory_visible_and_nearby_bytes_;
560 size_t last_sent_memory_use_bytes_;
[email protected]50644642013-06-20 13:58:55561 bool zero_budget_;
[email protected]d3afa112012-12-08 06:24:28562
[email protected]54af03522013-09-05 00:43:28563 // Viewport size passed in from the main thread, in physical pixels. This
564 // value is the default size for all concepts of physical viewport (draw
565 // viewport, scrolling viewport and device viewport), but it can be
566 // overridden.
[email protected]f224cc92013-06-06 23:23:32567 gfx::Size device_viewport_size_;
568
569 // Conversion factor from CSS pixels to physical pixels when
570 // pageScaleFactor=1.
571 float device_scale_factor_;
572
[email protected]9f4f6a32013-09-04 21:35:12573 // UI resource to use for drawing overhang gutters.
574 UIResourceId overhang_ui_resource_id_;
575 gfx::Size overhang_ui_resource_size_;
576
[email protected]f224cc92013-06-06 23:23:32577 // Vertical amount of the viewport size that's known to covered by a
578 // browser-side UI element, such as an on-screen-keyboard. This affects
579 // scrollable size since we want to still be able to scroll to the bottom of
580 // the page when the keyboard is up.
581 float overdraw_bottom_height_;
582
[email protected]54af03522013-09-05 00:43:28583 // Optional top-level constraints that can be set by the OutputSurface.
584 // - external_transform_ applies a transform above the root layer
585 // - external_viewport_ is used DrawProperties, tile management and
586 // glViewport/window projection matrix.
587 // - external_clip_ specifies a top-level clip rect
588 // - external_stencil_test_enabled_ tells CC to respect existing stencil bits
589 // (When these are specified, device_viewport_size_ remains used only for
590 // scrollable size.)
[email protected]f224cc92013-06-06 23:23:32591 gfx::Transform external_transform_;
592 gfx::Rect external_viewport_;
[email protected]54af03522013-09-05 00:43:28593 gfx::Rect external_clip_;
594 bool device_viewport_valid_for_tile_management_;
[email protected]c32a1962013-07-30 19:41:17595 bool external_stencil_test_enabled_;
[email protected]f224cc92013-06-06 23:23:32596
[email protected]878705be2013-04-15 22:44:02597 gfx::Rect viewport_damage_rect_;
[email protected]e0341352013-04-06 05:01:20598
[email protected]fb7425a2013-04-22 16:28:55599 base::TimeTicks current_frame_timeticks_;
600 base::Time current_frame_time_;
[email protected]829ad972013-01-28 23:36:10601
[email protected]c1bb5af2013-03-13 19:06:27602 scoped_ptr<AnimationRegistrar> animation_registrar_;
[email protected]de4afb5e2012-12-20 00:11:34603
[email protected]372bad5f2013-03-21 16:38:43604 RenderingStatsInstrumentation* rendering_stats_instrumentation_;
605
[email protected]8bb6cfa2013-07-23 00:11:19606 bool need_to_update_visible_tiles_before_draw_;
[email protected]39643fb2013-07-09 17:28:19607
[email protected]5f07afc2013-07-19 05:17:18608 // Optional callback to notify of new tree activations.
[email protected]2022c672013-07-23 19:55:26609 base::Closure tree_activation_callback_;
[email protected]5f07afc2013-07-19 05:17:18610
[email protected]c1bb5af2013-03-13 19:06:27611 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
[email protected]cd57cc5a2012-10-12 22:43:41612};
613
[email protected]0023e8b2012-10-15 12:52:45614} // namespace cc
[email protected]cd57cc5a2012-10-12 22:43:41615
[email protected]556fd292013-03-18 08:03:04616#endif // CC_TREES_LAYER_TREE_HOST_IMPL_H_