[safe browsing] Push missing download BINHASH histograms.
[chromium-blink-merge.git] / cc / trees / layer_tree_impl.h
blob9815c13a76ae0b8d3f32fa6bc31ceb4471335e4d
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 Proxy;
46 class ResourceProvider;
47 class TileManager;
48 class UIResourceRequest;
49 struct RendererCapabilities;
51 typedef std::list<UIResourceRequest> UIResourceRequestQueue;
53 class CC_EXPORT LayerTreeImpl {
54 public:
55 static scoped_ptr<LayerTreeImpl> create(
56 LayerTreeHostImpl* layer_tree_host_impl) {
57 return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
59 virtual ~LayerTreeImpl();
61 void Shutdown();
63 // Methods called by the layer tree that pass-through or access LTHI.
64 // ---------------------------------------------------------------------------
65 const LayerTreeSettings& settings() const;
66 const RendererCapabilitiesImpl& GetRendererCapabilities() const;
67 ContextProvider* context_provider() const;
68 OutputSurface* output_surface() const;
69 ResourceProvider* resource_provider() const;
70 TileManager* tile_manager() const;
71 FrameRateCounter* frame_rate_counter() const;
72 PaintTimeCounter* paint_time_counter() const;
73 MemoryHistory* memory_history() const;
74 bool device_viewport_valid_for_tile_management() const;
75 bool IsActiveTree() const;
76 bool IsPendingTree() const;
77 bool IsRecycleTree() const;
78 LayerImpl* FindActiveTreeLayerById(int id);
79 LayerImpl* FindPendingTreeLayerById(int id);
80 int MaxTextureSize() const;
81 bool PinchGestureActive() const;
82 base::TimeTicks CurrentFrameTimeTicks() const;
83 base::Time CurrentFrameTime() const;
84 base::TimeTicks CurrentPhysicalTimeTicks() const;
85 void SetNeedsCommit();
86 gfx::Size DrawViewportSize() const;
87 void StartScrollbarAnimation();
88 void DidAnimateScrollOffset();
90 // Tree specific methods exposed to layer-impl tree.
91 // ---------------------------------------------------------------------------
92 void SetNeedsRedraw();
94 // TODO(nduca): These are implemented in cc files temporarily, but will become
95 // trivial accessors in a followup patch.
96 const LayerTreeDebugState& debug_state() const;
97 float device_scale_factor() const;
98 DebugRectHistory* debug_rect_history() const;
99 scoped_ptr<base::Value> AsValue() const;
101 // Other public methods
102 // ---------------------------------------------------------------------------
103 LayerImpl* root_layer() const { return root_layer_.get(); }
104 void SetRootLayer(scoped_ptr<LayerImpl>);
105 scoped_ptr<LayerImpl> DetachLayerTree();
107 void PushPropertiesTo(LayerTreeImpl* tree_impl);
109 int source_frame_number() const { return source_frame_number_; }
110 void set_source_frame_number(int frame_number) {
111 source_frame_number_ = frame_number;
114 HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
115 void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
116 hud_layer_ = layer_impl;
119 LayerImpl* InnerViewportScrollLayer() const;
120 // This function may return NULL, it is the caller's responsibility to check.
121 LayerImpl* OuterViewportScrollLayer() const;
122 gfx::Vector2dF TotalScrollOffset() const;
123 gfx::Vector2dF TotalMaxScrollOffset() const;
124 gfx::Vector2dF TotalScrollDelta() const;
126 LayerImpl* RootContainerLayer() const;
127 LayerImpl* CurrentlyScrollingLayer() const;
128 void SetCurrentlyScrollingLayer(LayerImpl* layer);
129 void ClearCurrentlyScrollingLayer();
130 float VerticalAdjust(const LayerImpl* layer) const;
132 void SetViewportLayersFromIds(int page_scale_layer_id,
133 int inner_viewport_scroll_layer_id,
134 int outer_viewport_scroll_layer_id);
135 void ClearViewportLayers();
136 LayerImpl* page_scale_layer() { return page_scale_layer_; }
137 void ApplySentScrollAndScaleDeltasFromAbortedCommit();
138 void ApplyScrollDeltasSinceBeginMainFrame();
140 SkColor background_color() const { return background_color_; }
141 void set_background_color(SkColor color) { background_color_ = color; }
143 bool has_transparent_background() const {
144 return has_transparent_background_;
146 void set_has_transparent_background(bool transparent) {
147 has_transparent_background_ = transparent;
150 void SetPageScaleFactorAndLimits(float page_scale_factor,
151 float min_page_scale_factor, float max_page_scale_factor);
152 void SetPageScaleDelta(float delta);
153 float total_page_scale_factor() const {
154 return page_scale_factor_ * page_scale_delta_;
156 float page_scale_factor() const { return page_scale_factor_; }
157 float min_page_scale_factor() const { return min_page_scale_factor_; }
158 float max_page_scale_factor() const { return max_page_scale_factor_; }
159 float page_scale_delta() const { return page_scale_delta_; }
160 void set_sent_page_scale_delta(float delta) {
161 sent_page_scale_delta_ = delta;
163 float sent_page_scale_delta() const { return sent_page_scale_delta_; }
165 // Updates draw properties and render surface layer list, as well as tile
166 // priorities.
167 void UpdateDrawProperties();
169 void set_needs_update_draw_properties() {
170 needs_update_draw_properties_ = true;
172 bool needs_update_draw_properties() const {
173 return needs_update_draw_properties_;
176 void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
177 bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
179 void ForceRedrawNextActivation() { next_activation_forces_redraw_ = true; }
181 void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
183 const LayerImplList& RenderSurfaceLayerList() const;
185 // These return the size of the root scrollable area and the size of
186 // the user-visible scrolling viewport, in CSS layout coordinates.
187 gfx::Size ScrollableSize() const;
188 gfx::SizeF ScrollableViewportSize() const;
190 gfx::Rect RootScrollLayerDeviceViewportBounds() const;
192 LayerImpl* LayerById(int id);
194 // These should be called by LayerImpl's ctor/dtor.
195 void RegisterLayer(LayerImpl* layer);
196 void UnregisterLayer(LayerImpl* layer);
198 AnimationRegistrar* animationRegistrar() const;
200 void PushPersistedState(LayerTreeImpl* pending_tree);
202 void DidBecomeActive();
204 bool ContentsTexturesPurged() const;
205 void SetContentsTexturesPurged();
206 void ResetContentsTexturesPurged();
208 void SetRequiresHighResToDraw();
209 void ResetRequiresHighResToDraw();
210 bool RequiresHighResToDraw() const;
212 // Set on the active tree when the viewport size recently changed
213 // and the active tree's size is now out of date.
214 bool ViewportSizeInvalid() const;
215 void SetViewportSizeInvalid();
216 void ResetViewportSizeInvalid();
218 // Useful for debug assertions, probably shouldn't be used for anything else.
219 Proxy* proxy() const;
221 void SetRootLayerScrollOffsetDelegate(
222 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
223 void UpdateScrollOffsetDelegate();
224 gfx::Vector2dF GetDelegatedScrollOffset(LayerImpl* layer);
226 // Call this function when you expect there to be a swap buffer.
227 // See swap_promise.h for how to use SwapPromise.
228 void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise);
230 // Take the |new_swap_promise| and append it to |swap_promise_list_|.
231 void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise);
232 void FinishSwapPromises(CompositorFrameMetadata* metadata);
233 void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
235 void DidModifyTilePriorities();
237 ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
238 void ProcessUIResourceRequestQueue();
240 bool IsUIResourceOpaque(UIResourceId uid) const;
242 void AddLayerWithCopyOutputRequest(LayerImpl* layer);
243 void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
244 const std::vector<LayerImpl*>& LayersWithCopyOutputRequest() const;
246 protected:
247 explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
249 void UpdateRootScrollLayerSizeDelta();
251 LayerTreeHostImpl* layer_tree_host_impl_;
252 int source_frame_number_;
253 scoped_ptr<LayerImpl> root_layer_;
254 HeadsUpDisplayLayerImpl* hud_layer_;
255 LayerImpl* currently_scrolling_layer_;
256 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
257 scoped_ptr<LayerScrollOffsetDelegateProxy>
258 inner_viewport_scroll_delegate_proxy_;
259 scoped_ptr<LayerScrollOffsetDelegateProxy>
260 outer_viewport_scroll_delegate_proxy_;
261 SkColor background_color_;
262 bool has_transparent_background_;
264 LayerImpl* page_scale_layer_;
265 LayerImpl* inner_viewport_scroll_layer_;
266 LayerImpl* outer_viewport_scroll_layer_;
268 float page_scale_factor_;
269 float page_scale_delta_;
270 float sent_page_scale_delta_;
271 float min_page_scale_factor_;
272 float max_page_scale_factor_;
274 typedef base::hash_map<int, LayerImpl*> LayerIdMap;
275 LayerIdMap layer_id_map_;
277 std::vector<LayerImpl*> layers_with_copy_output_request_;
279 // Persisted state for non-impl-side-painting.
280 int scrolling_layer_id_from_previous_tree_;
282 // List of visible or hit-testable layers for the most recently prepared
283 // frame. Used for rendering and input event hit testing.
284 LayerImplList render_surface_layer_list_;
286 bool contents_textures_purged_;
287 bool requires_high_res_to_draw_;
288 bool viewport_size_invalid_;
289 bool needs_update_draw_properties_;
291 // In impl-side painting mode, this is true when the tree may contain
292 // structural differences relative to the active tree.
293 bool needs_full_tree_sync_;
295 bool next_activation_forces_redraw_;
297 ScopedPtrVector<SwapPromise> swap_promise_list_;
299 UIResourceRequestQueue ui_resource_request_queue_;
301 private:
302 DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
305 } // namespace cc
307 #endif // CC_TREES_LAYER_TREE_IMPL_H_