Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.h
blobea636ca35da5ef4b2c7147612aaf8f8caa2714b0
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_TREES_LAYER_TREE_IMPL_H_
6 #define CC_TREES_LAYER_TREE_IMPL_H_
8 #include <list>
9 #include <string>
10 #include <vector>
12 #include "base/containers/hash_tables.h"
13 #include "base/values.h"
14 #include "cc/base/scoped_ptr_vector.h"
15 #include "cc/base/swap_promise.h"
16 #include "cc/layers/layer_impl.h"
17 #include "cc/output/renderer.h"
18 #include "cc/resources/ui_resource_client.h"
20 #if defined(COMPILER_GCC)
21 namespace BASE_HASH_NAMESPACE {
22 template<>
23 struct hash<cc::LayerImpl*> {
24 size_t operator()(cc::LayerImpl* ptr) const {
25 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
28 } // namespace BASE_HASH_NAMESPACE
29 #endif // COMPILER
31 namespace cc {
33 class ContextProvider;
34 class DebugRectHistory;
35 class FrameRateCounter;
36 class HeadsUpDisplayLayerImpl;
37 class LayerScrollOffsetDelegateProxy;
38 class LayerTreeDebugState;
39 class LayerTreeHostImpl;
40 class LayerTreeImpl;
41 class LayerTreeSettings;
42 class MemoryHistory;
43 class OutputSurface;
44 class PaintTimeCounter;
45 class PictureLayerImpl;
46 class Proxy;
47 class ResourceProvider;
48 class TileManager;
49 class UIResourceRequest;
50 struct RendererCapabilities;
51 struct SelectionHandle;
53 typedef std::list<UIResourceRequest> UIResourceRequestQueue;
55 class CC_EXPORT LayerTreeImpl {
56 public:
57 static scoped_ptr<LayerTreeImpl> create(
58 LayerTreeHostImpl* layer_tree_host_impl) {
59 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
61 virtual ~LayerTreeImpl();
63 void Shutdown();
64 void ReleaseResources();
66 // Methods called by the layer tree that pass-through or access LTHI.
67 // ---------------------------------------------------------------------------
68 const LayerTreeSettings& settings() const;
69 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
70 ContextProvider* context_provider() const;
71 OutputSurface* output_surface() const;
72 ResourceProvider* resource_provider() const;
73 TileManager* tile_manager() const;
74 FrameRateCounter* frame_rate_counter() const;
75 PaintTimeCounter* paint_time_counter() const;
76 MemoryHistory* memory_history() const;
77 bool resourceless_software_draw() const;
78 gfx::Size device_viewport_size() const;
79 bool IsActiveTree() const;
80 bool IsPendingTree() const;
81 bool IsRecycleTree() const;
82 LayerImpl* FindActiveTreeLayerById(int id);
83 LayerImpl* FindPendingTreeLayerById(int id);
84 int MaxTextureSize() const;
85 bool PinchGestureActive() const;
86 base::TimeTicks CurrentFrameTimeTicks() const;
87 base::TimeDelta begin_impl_frame_interval() const;
88 void SetNeedsCommit();
89 gfx::Size DrawViewportSize() const;
90 scoped_ptr<ScrollbarAnimationController> CreateScrollbarAnimationController(
91 LayerImpl* scrolling_layer);
92 void DidAnimateScrollOffset();
93 void InputScrollAnimationFinished();
94 bool use_gpu_rasterization() const;
95 bool create_low_res_tiling() const;
97 // Tree specific methods exposed to layer-impl tree.
98 // ---------------------------------------------------------------------------
99 void SetNeedsRedraw();
101 // TODO(nduca): These are implemented in cc files temporarily, but will become
102 // trivial accessors in a followup patch.
103 const LayerTreeDebugState& debug_state() const;
104 float device_scale_factor() const;
105 DebugRectHistory* debug_rect_history() const;
106 scoped_ptr<base::Value> AsValue() const;
108 // Other public methods
109 // ---------------------------------------------------------------------------
110 LayerImpl* root_layer() const { return root_layer_.get(); }
111 void SetRootLayer(scoped_ptr<LayerImpl>);
112 scoped_ptr<LayerImpl> DetachLayerTree();
114 void PushPropertiesTo(LayerTreeImpl* tree_impl);
116 int source_frame_number() const { return source_frame_number_; }
117 void set_source_frame_number(int frame_number) {
118 source_frame_number_ = frame_number;
121 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
122 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
123 hud_layer_ = layer_impl;
126 LayerImpl* InnerViewportScrollLayer() const;
127 // This function may return NULL, it is the caller's responsibility to check.
128 LayerImpl* OuterViewportScrollLayer() const;
129 gfx::Vector2dF TotalScrollOffset() const;
130 gfx::Vector2dF TotalMaxScrollOffset() const;
131 gfx::Vector2dF TotalScrollDelta() const;
133 LayerImpl* InnerViewportContainerLayer() const;
134 LayerImpl* CurrentlyScrollingLayer() const;
135 void SetCurrentlyScrollingLayer(LayerImpl* layer);
136 void ClearCurrentlyScrollingLayer();
137 float VerticalAdjust(const int clip_layer_id) const;
139 void SetViewportLayersFromIds(int page_scale_layer_id,
140 int inner_viewport_scroll_layer_id,
141 int outer_viewport_scroll_layer_id);
142 void ClearViewportLayers();
143 LayerImpl* page_scale_layer() { return page_scale_layer_; }
144 void ApplySentScrollAndScaleDeltasFromAbortedCommit();
145 void ApplyScrollDeltasSinceBeginMainFrame();
147 SkColor background_color() const { return background_color_; }
148 void set_background_color(SkColor color) { background_color_ = color; }
150 bool has_transparent_background() const {
151 return has_transparent_background_;
153 void set_has_transparent_background(bool transparent) {
154 has_transparent_background_ = transparent;
157 void SetPageScaleFactorAndLimits(float page_scale_factor,
158 float min_page_scale_factor, float max_page_scale_factor);
159 void SetPageScaleDelta(float delta);
160 void SetPageScaleValues(float page_scale_factor,
161 float min_page_scale_factor, float max_page_scale_factor,
162 float page_scale_delta);
163 float total_page_scale_factor() const {
164 return page_scale_factor_ * page_scale_delta_;
166 float page_scale_factor() const { return page_scale_factor_; }
167 float min_page_scale_factor() const { return min_page_scale_factor_; }
168 float max_page_scale_factor() const { return max_page_scale_factor_; }
169 float page_scale_delta() const { return page_scale_delta_; }
170 void set_sent_page_scale_delta(float delta) {
171 sent_page_scale_delta_ = delta;
173 float sent_page_scale_delta() const { return sent_page_scale_delta_; }
175 // Updates draw properties and render surface layer list, as well as tile
176 // priorities. Returns false if it was unable to update.
177 bool UpdateDrawProperties();
179 void set_needs_update_draw_properties() {
180 needs_update_draw_properties_ = true;
182 bool needs_update_draw_properties() const {
183 return needs_update_draw_properties_;
186 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
187 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
189 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
191 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
193 const LayerImplList& RenderSurfaceLayerList() const;
195 // These return the size of the root scrollable area and the size of
196 // the user-visible scrolling viewport, in CSS layout coordinates.
197 gfx::Size ScrollableSize() const;
198 gfx::SizeF ScrollableViewportSize() const;
200 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
202 LayerImpl* LayerById(int id);
204 // These should be called by LayerImpl's ctor/dtor.
205 void RegisterLayer(LayerImpl* layer);
206 void UnregisterLayer(LayerImpl* layer);
208 AnimationRegistrar* animationRegistrar() const;
210 void PushPersistedState(LayerTreeImpl* pending_tree);
212 void DidBecomeActive();
214 bool ContentsTexturesPurged() const;
215 void SetContentsTexturesPurged();
216 void ResetContentsTexturesPurged();
218 void SetRequiresHighResToDraw();
219 void ResetRequiresHighResToDraw();
220 bool RequiresHighResToDraw() const;
222 // Set on the active tree when the viewport size recently changed
223 // and the active tree's size is now out of date.
224 bool ViewportSizeInvalid() const;
225 void SetViewportSizeInvalid();
226 void ResetViewportSizeInvalid();
228 // Useful for debug assertions, probably shouldn't be used for anything else.
229 Proxy* proxy() const;
231 void SetRootLayerScrollOffsetDelegate(
232 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
233 void UpdateScrollOffsetDelegate();
234 gfx::Vector2dF GetDelegatedScrollOffset(LayerImpl* layer);
236 // Call this function when you expect there to be a swap buffer.
237 // See swap_promise.h for how to use SwapPromise.
238 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
240 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
241 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
242 void FinishSwapPromises(CompositorFrameMetadata* metadata);
243 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
245 void DidModifyTilePriorities();
247 ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
248 void ProcessUIResourceRequestQueue();
250 bool IsUIResourceOpaque(UIResourceId uid) const;
252 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
253 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
254 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
256 int current_render_surface_list_id() const {
257 return render_surface_layer_list_id_;
260 LayerImpl* FindFirstScrollingLayerThatIsHitByPoint(
261 const gfx::PointF& screen_space_point);
263 LayerImpl* FindLayerThatIsHitByPoint(const gfx::PointF& screen_space_point);
265 LayerImpl* FindLayerThatIsHitByPointInTouchHandlerRegion(
266 const gfx::PointF& screen_space_point);
268 void RegisterSelection(const LayerSelectionBound& anchor,
269 const LayerSelectionBound& focus);
271 // Compute the current selection handle location and visbility with respect to
272 // the viewport.
273 void GetViewportSelection(ViewportSelectionBound* anchor,
274 ViewportSelectionBound* focus);
276 void RegisterPictureLayerImpl(PictureLayerImpl* layer);
277 void UnregisterPictureLayerImpl(PictureLayerImpl* layer);
279 protected:
280 explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
281 void ReleaseResourcesRecursive(LayerImpl* current);
283 LayerTreeHostImpl* layer_tree_host_impl_;
284 int source_frame_number_;
285 scoped_ptr<LayerImpl> root_layer_;
286 HeadsUpDisplayLayerImpl* hud_layer_;
287 LayerImpl* currently_scrolling_layer_;
288 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
289 scoped_ptr<LayerScrollOffsetDelegateProxy>
290 inner_viewport_scroll_delegate_proxy_;
291 scoped_ptr<LayerScrollOffsetDelegateProxy>
292 outer_viewport_scroll_delegate_proxy_;
293 SkColor background_color_;
294 bool has_transparent_background_;
296 LayerImpl* page_scale_layer_;
297 LayerImpl* inner_viewport_scroll_layer_;
298 LayerImpl* outer_viewport_scroll_layer_;
300 LayerSelectionBound selection_anchor_;
301 LayerSelectionBound selection_focus_;
303 float page_scale_factor_;
304 float page_scale_delta_;
305 float sent_page_scale_delta_;
306 float min_page_scale_factor_;
307 float max_page_scale_factor_;
309 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
310 LayerIdMap layer_id_map_;
312 std::vector<LayerImpl*> layers_with_copy_output_request_;
314 // Persisted state for non-impl-side-painting.
315 int scrolling_layer_id_from_previous_tree_;
317 // List of visible layers for the most recently prepared frame.
318 LayerImplList render_surface_layer_list_;
320 bool contents_textures_purged_;
321 bool requires_high_res_to_draw_;
322 bool viewport_size_invalid_;
323 bool needs_update_draw_properties_;
325 // In impl-side painting mode, this is true when the tree may contain
326 // structural differences relative to the active tree.
327 bool needs_full_tree_sync_;
329 bool next_activation_forces_redraw_;
331 ScopedPtrVector<SwapPromise> swap_promise_list_;
333 UIResourceRequestQueue ui_resource_request_queue_;
335 int render_surface_layer_list_id_;
337 private:
338 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
341 } // namespace cc
343 #endif // CC_TREES_LAYER_TREE_IMPL_H_