OLD | NEW |
| (Empty) |
1 // Copyright 2011 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. | |
4 | |
5 #ifndef CC_LAYERS_LAYER_IMPL_H_ | |
6 #define CC_LAYERS_LAYER_IMPL_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/logging.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/values.h" | |
16 #include "cc/animation/animation_delegate.h" | |
17 #include "cc/animation/layer_animation_controller.h" | |
18 #include "cc/animation/layer_animation_value_observer.h" | |
19 #include "cc/animation/layer_animation_value_provider.h" | |
20 #include "cc/base/cc_export.h" | |
21 #include "cc/base/region.h" | |
22 #include "cc/base/scoped_ptr_vector.h" | |
23 #include "cc/base/synced_property.h" | |
24 #include "cc/debug/frame_timing_request.h" | |
25 #include "cc/input/input_handler.h" | |
26 #include "cc/input/scrollbar.h" | |
27 #include "cc/layers/draw_properties.h" | |
28 #include "cc/layers/layer_lists.h" | |
29 #include "cc/layers/layer_position_constraint.h" | |
30 #include "cc/layers/render_surface_impl.h" | |
31 #include "cc/layers/scroll_blocks_on.h" | |
32 #include "cc/output/filter_operations.h" | |
33 #include "cc/quads/shared_quad_state.h" | |
34 #include "cc/resources/resource_provider.h" | |
35 #include "cc/resources/tile_priority.h" | |
36 #include "skia/ext/refptr.h" | |
37 #include "third_party/skia/include/core/SkColor.h" | |
38 #include "third_party/skia/include/core/SkImageFilter.h" | |
39 #include "third_party/skia/include/core/SkPicture.h" | |
40 #include "ui/gfx/geometry/point3_f.h" | |
41 #include "ui/gfx/geometry/rect.h" | |
42 #include "ui/gfx/geometry/rect_f.h" | |
43 #include "ui/gfx/geometry/scroll_offset.h" | |
44 #include "ui/gfx/transform.h" | |
45 | |
46 namespace base { | |
47 namespace trace_event { | |
48 class ConvertableToTraceFormat; | |
49 class TracedValue; | |
50 } | |
51 class DictionaryValue; | |
52 } | |
53 | |
54 namespace cc { | |
55 | |
56 class LayerTreeHostImpl; | |
57 class LayerTreeImpl; | |
58 class MicroBenchmarkImpl; | |
59 class Occlusion; | |
60 template <typename LayerType> | |
61 class OcclusionTracker; | |
62 class RenderPass; | |
63 class RenderPassId; | |
64 class Renderer; | |
65 class ScrollbarAnimationController; | |
66 class ScrollbarLayerImplBase; | |
67 class SimpleEnclosedRegion; | |
68 class Tile; | |
69 | |
70 struct AppendQuadsData; | |
71 | |
72 enum DrawMode { | |
73 DRAW_MODE_NONE, | |
74 DRAW_MODE_HARDWARE, | |
75 DRAW_MODE_SOFTWARE, | |
76 DRAW_MODE_RESOURCELESS_SOFTWARE | |
77 }; | |
78 | |
79 class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, | |
80 public LayerAnimationValueProvider, | |
81 public AnimationDelegate { | |
82 public: | |
83 // Allows for the ownership of the total scroll offset to be delegated outside | |
84 // of the layer. | |
85 class ScrollOffsetDelegate { | |
86 public: | |
87 virtual void SetCurrentScrollOffset(const gfx::ScrollOffset& new_value) = 0; | |
88 virtual gfx::ScrollOffset GetCurrentScrollOffset() = 0; | |
89 virtual bool IsExternalFlingActive() const = 0; | |
90 virtual void Update() const = 0; | |
91 }; | |
92 | |
93 typedef SyncedProperty<AdditionGroup<gfx::ScrollOffset>> SyncedScrollOffset; | |
94 typedef LayerImplList RenderSurfaceListType; | |
95 typedef LayerImplList LayerListType; | |
96 typedef RenderSurfaceImpl RenderSurfaceType; | |
97 | |
98 enum RenderingContextConstants { NO_RENDERING_CONTEXT = 0 }; | |
99 | |
100 static scoped_ptr<LayerImpl> Create( | |
101 LayerTreeImpl* tree_impl, | |
102 int id, | |
103 scoped_refptr<SyncedScrollOffset> scroll_offset) { | |
104 return make_scoped_ptr(new LayerImpl(tree_impl, id, scroll_offset)); | |
105 } | |
106 | |
107 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { | |
108 return make_scoped_ptr(new LayerImpl(tree_impl, id)); | |
109 } | |
110 | |
111 ~LayerImpl() override; | |
112 | |
113 int id() const { return layer_id_; } | |
114 | |
115 // LayerAnimationValueProvider implementation. | |
116 gfx::ScrollOffset ScrollOffsetForAnimation() const override; | |
117 | |
118 // LayerAnimationValueObserver implementation. | |
119 void OnFilterAnimated(const FilterOperations& filters) override; | |
120 void OnOpacityAnimated(float opacity) override; | |
121 void OnTransformAnimated(const gfx::Transform& transform) override; | |
122 void OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) override; | |
123 void OnAnimationWaitingForDeletion() override; | |
124 bool IsActive() const override; | |
125 | |
126 // AnimationDelegate implementation. | |
127 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | |
128 Animation::TargetProperty target_property, | |
129 int group) override{}; | |
130 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | |
131 Animation::TargetProperty target_property, | |
132 int group) override; | |
133 | |
134 // Tree structure. | |
135 LayerImpl* parent() { return parent_; } | |
136 const LayerImpl* parent() const { return parent_; } | |
137 const OwnedLayerImplList& children() const { return children_; } | |
138 OwnedLayerImplList& children() { return children_; } | |
139 LayerImpl* child_at(size_t index) const { return children_[index]; } | |
140 void AddChild(scoped_ptr<LayerImpl> child); | |
141 scoped_ptr<LayerImpl> RemoveChild(LayerImpl* child); | |
142 void SetParent(LayerImpl* parent); | |
143 | |
144 // Warning: This does not preserve tree structure invariants. | |
145 void ClearChildList(); | |
146 | |
147 bool HasAncestor(const LayerImpl* ancestor) const; | |
148 | |
149 void SetScrollParent(LayerImpl* parent); | |
150 | |
151 LayerImpl* scroll_parent() { return scroll_parent_; } | |
152 const LayerImpl* scroll_parent() const { return scroll_parent_; } | |
153 | |
154 void SetScrollChildren(std::set<LayerImpl*>* children); | |
155 | |
156 std::set<LayerImpl*>* scroll_children() { return scroll_children_.get(); } | |
157 const std::set<LayerImpl*>* scroll_children() const { | |
158 return scroll_children_.get(); | |
159 } | |
160 | |
161 void SetNumDescendantsThatDrawContent(int num_descendants); | |
162 void SetClipParent(LayerImpl* ancestor); | |
163 | |
164 LayerImpl* clip_parent() { | |
165 return clip_parent_; | |
166 } | |
167 const LayerImpl* clip_parent() const { | |
168 return clip_parent_; | |
169 } | |
170 | |
171 void SetClipChildren(std::set<LayerImpl*>* children); | |
172 | |
173 std::set<LayerImpl*>* clip_children() { return clip_children_.get(); } | |
174 const std::set<LayerImpl*>* clip_children() const { | |
175 return clip_children_.get(); | |
176 } | |
177 | |
178 void PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests); | |
179 // Can only be called when the layer has a copy request. | |
180 void TakeCopyRequestsAndTransformToTarget( | |
181 ScopedPtrVector<CopyOutputRequest>* request); | |
182 bool HasCopyRequest() const { return !copy_requests_.empty(); } | |
183 | |
184 void SetMaskLayer(scoped_ptr<LayerImpl> mask_layer); | |
185 LayerImpl* mask_layer() { return mask_layer_.get(); } | |
186 const LayerImpl* mask_layer() const { return mask_layer_.get(); } | |
187 scoped_ptr<LayerImpl> TakeMaskLayer(); | |
188 | |
189 void SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer); | |
190 LayerImpl* replica_layer() { return replica_layer_.get(); } | |
191 const LayerImpl* replica_layer() const { return replica_layer_.get(); } | |
192 scoped_ptr<LayerImpl> TakeReplicaLayer(); | |
193 | |
194 bool has_mask() const { return mask_layer_; } | |
195 bool has_replica() const { return replica_layer_; } | |
196 bool replica_has_mask() const { | |
197 return replica_layer_ && (mask_layer_ || replica_layer_->mask_layer_); | |
198 } | |
199 | |
200 LayerTreeImpl* layer_tree_impl() const { return layer_tree_impl_; } | |
201 | |
202 void PopulateSharedQuadState(SharedQuadState* state) const; | |
203 void PopulateScaledSharedQuadState(SharedQuadState* state, float scale) const; | |
204 // WillDraw must be called before AppendQuads. If WillDraw returns false, | |
205 // AppendQuads and DidDraw will not be called. If WillDraw returns true, | |
206 // DidDraw is guaranteed to be called before another WillDraw or before | |
207 // the layer is destroyed. To enforce this, any class that overrides | |
208 // WillDraw/DidDraw must call the base class version only if WillDraw | |
209 // returns true. | |
210 virtual bool WillDraw(DrawMode draw_mode, | |
211 ResourceProvider* resource_provider); | |
212 virtual void AppendQuads(RenderPass* render_pass, | |
213 AppendQuadsData* append_quads_data) {} | |
214 virtual void DidDraw(ResourceProvider* resource_provider); | |
215 | |
216 virtual void GetContentsResourceId(ResourceProvider::ResourceId* resource_id, | |
217 gfx::Size* resource_size) const; | |
218 | |
219 virtual bool HasDelegatedContent() const; | |
220 virtual bool HasContributingDelegatedRenderPasses() const; | |
221 virtual RenderPassId FirstContributingRenderPassId() const; | |
222 virtual RenderPassId NextContributingRenderPassId(RenderPassId id) const; | |
223 | |
224 virtual void NotifyTileStateChanged(const Tile* tile) {} | |
225 | |
226 virtual ScrollbarLayerImplBase* ToScrollbarLayer(); | |
227 | |
228 // Returns true if this layer has content to draw. | |
229 void SetDrawsContent(bool draws_content); | |
230 bool DrawsContent() const { return draws_content_; } | |
231 | |
232 int NumDescendantsThatDrawContent() const; | |
233 void SetHideLayerAndSubtree(bool hide); | |
234 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; } | |
235 | |
236 void SetTransformOrigin(const gfx::Point3F& transform_origin); | |
237 gfx::Point3F transform_origin() const { return transform_origin_; } | |
238 | |
239 void SetBackgroundColor(SkColor background_color); | |
240 SkColor background_color() const { return background_color_; } | |
241 // If contents_opaque(), return an opaque color else return a | |
242 // non-opaque color. Tries to return background_color(), if possible. | |
243 SkColor SafeOpaqueBackgroundColor() const; | |
244 | |
245 void SetFilters(const FilterOperations& filters); | |
246 const FilterOperations& filters() const { return filters_; } | |
247 bool FilterIsAnimating() const; | |
248 bool FilterIsAnimatingOnImplOnly() const; | |
249 | |
250 void SetBackgroundFilters(const FilterOperations& filters); | |
251 const FilterOperations& background_filters() const { | |
252 return background_filters_; | |
253 } | |
254 | |
255 void SetMasksToBounds(bool masks_to_bounds); | |
256 bool masks_to_bounds() const { return masks_to_bounds_; } | |
257 | |
258 void SetContentsOpaque(bool opaque); | |
259 bool contents_opaque() const { return contents_opaque_; } | |
260 | |
261 void SetOpacity(float opacity); | |
262 float opacity() const { return opacity_; } | |
263 bool OpacityIsAnimating() const; | |
264 bool OpacityIsAnimatingOnImplOnly() const; | |
265 | |
266 void SetBlendMode(SkXfermode::Mode); | |
267 SkXfermode::Mode blend_mode() const { return blend_mode_; } | |
268 bool uses_default_blend_mode() const { | |
269 return blend_mode_ == SkXfermode::kSrcOver_Mode; | |
270 } | |
271 | |
272 void SetIsRootForIsolatedGroup(bool root); | |
273 bool is_root_for_isolated_group() const { | |
274 return is_root_for_isolated_group_; | |
275 } | |
276 | |
277 void SetPosition(const gfx::PointF& position); | |
278 gfx::PointF position() const { return position_; } | |
279 | |
280 void SetIsContainerForFixedPositionLayers(bool container) { | |
281 is_container_for_fixed_position_layers_ = container; | |
282 } | |
283 // This is a non-trivial function in Layer. | |
284 bool IsContainerForFixedPositionLayers() const { | |
285 return is_container_for_fixed_position_layers_; | |
286 } | |
287 | |
288 gfx::Vector2dF FixedContainerSizeDelta() const; | |
289 | |
290 void SetPositionConstraint(const LayerPositionConstraint& constraint) { | |
291 position_constraint_ = constraint; | |
292 } | |
293 const LayerPositionConstraint& position_constraint() const { | |
294 return position_constraint_; | |
295 } | |
296 | |
297 void SetShouldFlattenTransform(bool flatten); | |
298 bool should_flatten_transform() const { return should_flatten_transform_; } | |
299 | |
300 bool Is3dSorted() const { return sorting_context_id_ != 0; } | |
301 | |
302 void SetUseParentBackfaceVisibility(bool use) { | |
303 use_parent_backface_visibility_ = use; | |
304 } | |
305 bool use_parent_backface_visibility() const { | |
306 return use_parent_backface_visibility_; | |
307 } | |
308 | |
309 bool ShowDebugBorders() const; | |
310 | |
311 // These invalidate the host's render surface layer list. The caller | |
312 // is responsible for calling set_needs_update_draw_properties on the tree | |
313 // so that its list can be recreated. | |
314 void ClearRenderSurfaceLayerList(); | |
315 void SetHasRenderSurface(bool has_render_surface); | |
316 | |
317 RenderSurfaceImpl* render_surface() const { return render_surface_.get(); } | |
318 | |
319 DrawProperties<LayerImpl>& draw_properties() { | |
320 return draw_properties_; | |
321 } | |
322 const DrawProperties<LayerImpl>& draw_properties() const { | |
323 return draw_properties_; | |
324 } | |
325 | |
326 // The following are shortcut accessors to get various information from | |
327 // draw_properties_ | |
328 const gfx::Transform& draw_transform() const { | |
329 return draw_properties_.target_space_transform; | |
330 } | |
331 const gfx::Transform& screen_space_transform() const { | |
332 return draw_properties_.screen_space_transform; | |
333 } | |
334 float draw_opacity() const { return draw_properties_.opacity; } | |
335 SkXfermode::Mode draw_blend_mode() const { | |
336 return draw_properties_.blend_mode; | |
337 } | |
338 bool draw_opacity_is_animating() const { | |
339 return draw_properties_.opacity_is_animating; | |
340 } | |
341 bool draw_transform_is_animating() const { | |
342 return draw_properties_.target_space_transform_is_animating; | |
343 } | |
344 bool screen_space_transform_is_animating() const { | |
345 return draw_properties_.screen_space_transform_is_animating; | |
346 } | |
347 bool screen_space_opacity_is_animating() const { | |
348 return draw_properties_.screen_space_opacity_is_animating; | |
349 } | |
350 bool can_use_lcd_text() const { return draw_properties_.can_use_lcd_text; } | |
351 bool is_clipped() const { return draw_properties_.is_clipped; } | |
352 gfx::Rect clip_rect() const { return draw_properties_.clip_rect; } | |
353 gfx::Rect drawable_content_rect() const { | |
354 return draw_properties_.drawable_content_rect; | |
355 } | |
356 gfx::Rect visible_content_rect() const { | |
357 return draw_properties_.visible_content_rect; | |
358 } | |
359 LayerImpl* render_target() { | |
360 DCHECK(!draw_properties_.render_target || | |
361 draw_properties_.render_target->render_surface()); | |
362 return draw_properties_.render_target; | |
363 } | |
364 const LayerImpl* render_target() const { | |
365 DCHECK(!draw_properties_.render_target || | |
366 draw_properties_.render_target->render_surface()); | |
367 return draw_properties_.render_target; | |
368 } | |
369 | |
370 int num_unclipped_descendants() const { | |
371 return draw_properties_.num_unclipped_descendants; | |
372 } | |
373 | |
374 // The client should be responsible for setting bounds, content bounds and | |
375 // contents scale to appropriate values. LayerImpl doesn't calculate any of | |
376 // them from the other values. | |
377 | |
378 void SetBounds(const gfx::Size& bounds); | |
379 gfx::Size bounds() const; | |
380 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions | |
381 // of pixels) due to use of single precision float. | |
382 gfx::SizeF BoundsForScrolling() const; | |
383 void SetBoundsDelta(const gfx::Vector2dF& bounds_delta); | |
384 gfx::Vector2dF bounds_delta() const { return bounds_delta_; } | |
385 | |
386 void SetContentBounds(const gfx::Size& content_bounds); | |
387 gfx::Size content_bounds() const { return draw_properties_.content_bounds; } | |
388 | |
389 float contents_scale_x() const { return draw_properties_.contents_scale_x; } | |
390 float contents_scale_y() const { return draw_properties_.contents_scale_y; } | |
391 void SetContentsScale(float contents_scale_x, float contents_scale_y); | |
392 | |
393 void SetScrollOffsetDelegate(ScrollOffsetDelegate* scroll_offset_delegate); | |
394 void RefreshFromScrollDelegate(); | |
395 bool IsExternalFlingActive() const; | |
396 | |
397 void SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset); | |
398 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset& scroll_offset); | |
399 // This method is similar to PushScrollOffsetFromMainThread but will cause the | |
400 // scroll offset given to clobber any scroll changes on the active tree in the | |
401 // time until this value is pushed to the active tree. | |
402 void PushScrollOffsetFromMainThreadAndClobberActiveValue( | |
403 const gfx::ScrollOffset& scroll_offset); | |
404 gfx::ScrollOffset PullDeltaForMainThread(); | |
405 gfx::ScrollOffset CurrentScrollOffset() const; | |
406 gfx::ScrollOffset BaseScrollOffset() const; | |
407 gfx::Vector2dF ScrollDelta() const; | |
408 void SetScrollDelta(const gfx::Vector2dF& delta); | |
409 | |
410 gfx::ScrollOffset MaxScrollOffset() const; | |
411 gfx::ScrollOffset ClampScrollOffsetToLimits(gfx::ScrollOffset offset) const; | |
412 gfx::Vector2dF ClampScrollToMaxScrollOffset(); | |
413 void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, | |
414 LayerImpl* scrollbar_clip_layer, | |
415 bool on_resize) const; | |
416 void SetScrollCompensationAdjustment(const gfx::Vector2dF& scroll_offset) { | |
417 scroll_compensation_adjustment_ = scroll_offset; | |
418 } | |
419 gfx::Vector2dF ScrollCompensationAdjustment() const { | |
420 return scroll_compensation_adjustment_; | |
421 } | |
422 | |
423 // Returns the delta of the scroll that was outside of the bounds of the | |
424 // initial scroll | |
425 gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll); | |
426 | |
427 void SetScrollClipLayer(int scroll_clip_layer_id); | |
428 LayerImpl* scroll_clip_layer() const { return scroll_clip_layer_; } | |
429 bool scrollable() const { return !!scroll_clip_layer_; } | |
430 | |
431 void set_user_scrollable_horizontal(bool scrollable) { | |
432 user_scrollable_horizontal_ = scrollable; | |
433 } | |
434 bool user_scrollable_horizontal() const { | |
435 return user_scrollable_horizontal_; | |
436 } | |
437 void set_user_scrollable_vertical(bool scrollable) { | |
438 user_scrollable_vertical_ = scrollable; | |
439 } | |
440 bool user_scrollable_vertical() const { return user_scrollable_vertical_; } | |
441 | |
442 bool user_scrollable(ScrollbarOrientation orientation) const; | |
443 | |
444 void ApplySentScrollDeltasFromAbortedCommit(); | |
445 | |
446 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) { | |
447 should_scroll_on_main_thread_ = should_scroll_on_main_thread; | |
448 } | |
449 bool should_scroll_on_main_thread() const { | |
450 return should_scroll_on_main_thread_; | |
451 } | |
452 | |
453 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers) { | |
454 have_wheel_event_handlers_ = have_wheel_event_handlers; | |
455 } | |
456 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; } | |
457 | |
458 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers) { | |
459 have_scroll_event_handlers_ = have_scroll_event_handlers; | |
460 } | |
461 bool have_scroll_event_handlers() const { | |
462 return have_scroll_event_handlers_; | |
463 } | |
464 | |
465 void SetNonFastScrollableRegion(const Region& region) { | |
466 non_fast_scrollable_region_ = region; | |
467 } | |
468 const Region& non_fast_scrollable_region() const { | |
469 return non_fast_scrollable_region_; | |
470 } | |
471 | |
472 void SetTouchEventHandlerRegion(const Region& region) { | |
473 touch_event_handler_region_ = region; | |
474 } | |
475 const Region& touch_event_handler_region() const { | |
476 return touch_event_handler_region_; | |
477 } | |
478 | |
479 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on) { | |
480 scroll_blocks_on_ = scroll_blocks_on; | |
481 } | |
482 ScrollBlocksOn scroll_blocks_on() const { return scroll_blocks_on_; } | |
483 void SetDrawCheckerboardForMissingTiles(bool checkerboard) { | |
484 draw_checkerboard_for_missing_tiles_ = checkerboard; | |
485 } | |
486 bool draw_checkerboard_for_missing_tiles() const { | |
487 return draw_checkerboard_for_missing_tiles_; | |
488 } | |
489 | |
490 InputHandler::ScrollStatus TryScroll( | |
491 const gfx::PointF& screen_space_point, | |
492 InputHandler::ScrollInputType type, | |
493 ScrollBlocksOn effective_block_mode) const; | |
494 | |
495 void SetDoubleSided(bool double_sided); | |
496 bool double_sided() const { return double_sided_; } | |
497 | |
498 void SetTransform(const gfx::Transform& transform); | |
499 const gfx::Transform& transform() const { return transform_; } | |
500 bool TransformIsAnimating() const; | |
501 bool TransformIsAnimatingOnImplOnly() const; | |
502 void SetTransformAndInvertibility(const gfx::Transform& transform, | |
503 bool transform_is_invertible); | |
504 bool transform_is_invertible() const { return transform_is_invertible_; } | |
505 | |
506 // Note this rect is in layer space (not content space). | |
507 void SetUpdateRect(const gfx::Rect& update_rect); | |
508 gfx::Rect update_rect() const { return update_rect_; } | |
509 | |
510 void AddDamageRect(const gfx::RectF& damage_rect); | |
511 | |
512 const gfx::RectF& damage_rect() const { return damage_rect_; } | |
513 | |
514 virtual base::DictionaryValue* LayerTreeAsJson() const; | |
515 | |
516 void SetStackingOrderChanged(bool stacking_order_changed); | |
517 | |
518 bool LayerPropertyChanged() const { return layer_property_changed_; } | |
519 | |
520 void ResetAllChangeTrackingForSubtree(); | |
521 | |
522 LayerAnimationController* layer_animation_controller() { | |
523 return layer_animation_controller_.get(); | |
524 } | |
525 | |
526 const LayerAnimationController* layer_animation_controller() const { | |
527 return layer_animation_controller_.get(); | |
528 } | |
529 | |
530 virtual SimpleEnclosedRegion VisibleContentOpaqueRegion() const; | |
531 | |
532 virtual void DidBecomeActive(); | |
533 | |
534 virtual void DidBeginTracing(); | |
535 | |
536 // Release resources held by this layer. Called when the output surface | |
537 // that rendered this layer was lost or a rendering mode switch has occured. | |
538 virtual void ReleaseResources(); | |
539 | |
540 // Recreate resources that are required after they were released by a | |
541 // ReleaseResources call. | |
542 virtual void RecreateResources(); | |
543 | |
544 ScrollbarAnimationController* scrollbar_animation_controller() const { | |
545 return scrollbar_animation_controller_.get(); | |
546 } | |
547 | |
548 typedef std::set<ScrollbarLayerImplBase*> ScrollbarSet; | |
549 ScrollbarSet* scrollbars() { return scrollbars_.get(); } | |
550 void ClearScrollbars(); | |
551 void AddScrollbar(ScrollbarLayerImplBase* layer); | |
552 void RemoveScrollbar(ScrollbarLayerImplBase* layer); | |
553 bool HasScrollbar(ScrollbarOrientation orientation) const; | |
554 void ScrollbarParametersDidChange(bool on_resize); | |
555 int clip_height() { | |
556 return scroll_clip_layer_ ? scroll_clip_layer_->bounds().height() : 0; | |
557 } | |
558 | |
559 gfx::Rect LayerRectToContentRect(const gfx::RectF& layer_rect) const; | |
560 | |
561 virtual skia::RefPtr<SkPicture> GetPicture(); | |
562 | |
563 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl); | |
564 virtual void PushPropertiesTo(LayerImpl* layer); | |
565 | |
566 virtual void GetAllTilesAndPrioritiesForTracing( | |
567 std::map<const Tile*, TilePriority>* tile_map) const; | |
568 virtual void AsValueInto(base::trace_event::TracedValue* dict) const; | |
569 | |
570 virtual size_t GPUMemoryUsageInBytes() const; | |
571 | |
572 void SetNeedsPushProperties(); | |
573 void AddDependentNeedsPushProperties(); | |
574 void RemoveDependentNeedsPushProperties(); | |
575 bool parent_should_know_need_push_properties() const { | |
576 return needs_push_properties() || descendant_needs_push_properties(); | |
577 } | |
578 | |
579 bool needs_push_properties() const { return needs_push_properties_; } | |
580 bool descendant_needs_push_properties() const { | |
581 return num_dependents_need_push_properties_ > 0; | |
582 } | |
583 | |
584 virtual void RunMicroBenchmark(MicroBenchmarkImpl* benchmark); | |
585 | |
586 virtual void SetDebugInfo( | |
587 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other); | |
588 | |
589 bool IsDrawnRenderSurfaceLayerListMember() const; | |
590 | |
591 void Set3dSortingContextId(int id); | |
592 int sorting_context_id() { return sorting_context_id_; } | |
593 | |
594 void PassFrameTimingRequests( | |
595 std::vector<FrameTimingRequest>* frame_timing_requests); | |
596 const std::vector<FrameTimingRequest>& frame_timing_requests() const { | |
597 return frame_timing_requests_; | |
598 } | |
599 | |
600 SyncedScrollOffset* synced_scroll_offset() { return scroll_offset_.get(); } | |
601 | |
602 // Get the correct invalidation region instead of conservative Rect | |
603 // for layers that provide it. | |
604 virtual Region GetInvalidationRegion(); | |
605 | |
606 virtual gfx::Rect GetEnclosingRectInTargetSpace() const; | |
607 | |
608 protected: | |
609 LayerImpl(LayerTreeImpl* layer_impl, | |
610 int id, | |
611 scoped_refptr<SyncedScrollOffset> scroll_offset); | |
612 LayerImpl(LayerTreeImpl* layer_impl, int id); | |
613 | |
614 // Get the color and size of the layer's debug border. | |
615 virtual void GetDebugBorderProperties(SkColor* color, float* width) const; | |
616 | |
617 void AppendDebugBorderQuad(RenderPass* render_pass, | |
618 const gfx::Size& content_bounds, | |
619 const SharedQuadState* shared_quad_state, | |
620 AppendQuadsData* append_quads_data) const; | |
621 void AppendDebugBorderQuad(RenderPass* render_pass, | |
622 const gfx::Size& content_bounds, | |
623 const SharedQuadState* shared_quad_state, | |
624 AppendQuadsData* append_quads_data, | |
625 SkColor color, | |
626 float width) const; | |
627 | |
628 void NoteLayerPropertyChanged(); | |
629 void NoteLayerPropertyChangedForSubtree(); | |
630 | |
631 // Note carefully this does not affect the current layer. | |
632 void NoteLayerPropertyChangedForDescendants(); | |
633 | |
634 gfx::Rect GetScaledEnclosingRectInTargetSpace(float scale) const; | |
635 | |
636 private: | |
637 void PushScrollOffset(const gfx::ScrollOffset* scroll_offset); | |
638 void DidUpdateScrollOffset(); | |
639 void NoteLayerPropertyChangedForDescendantsInternal(); | |
640 | |
641 virtual const char* LayerTypeAsString() const; | |
642 | |
643 // Properties internal to LayerImpl | |
644 LayerImpl* parent_; | |
645 OwnedLayerImplList children_; | |
646 | |
647 LayerImpl* scroll_parent_; | |
648 | |
649 // Storing a pointer to a set rather than a set since this will be rarely | |
650 // used. If this pointer turns out to be too heavy, we could have this (and | |
651 // the scroll parent above) be stored in a LayerImpl -> scroll_info | |
652 // map somewhere. | |
653 scoped_ptr<std::set<LayerImpl*>> scroll_children_; | |
654 | |
655 LayerImpl* clip_parent_; | |
656 scoped_ptr<std::set<LayerImpl*>> clip_children_; | |
657 | |
658 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to | |
659 // confirm newly assigned layer is still the previous one | |
660 int mask_layer_id_; | |
661 scoped_ptr<LayerImpl> mask_layer_; | |
662 int replica_layer_id_; // ditto | |
663 scoped_ptr<LayerImpl> replica_layer_; | |
664 int layer_id_; | |
665 LayerTreeImpl* layer_tree_impl_; | |
666 | |
667 // Properties dynamically changeable on active tree. | |
668 scoped_refptr<SyncedScrollOffset> scroll_offset_; | |
669 gfx::Vector2dF bounds_delta_; | |
670 | |
671 // Properties synchronized from the associated Layer. | |
672 gfx::Point3F transform_origin_; | |
673 gfx::Size bounds_; | |
674 ScrollOffsetDelegate* scroll_offset_delegate_; | |
675 LayerImpl* scroll_clip_layer_; | |
676 bool scrollable_ : 1; | |
677 bool should_scroll_on_main_thread_ : 1; | |
678 bool have_wheel_event_handlers_ : 1; | |
679 bool have_scroll_event_handlers_ : 1; | |
680 | |
681 static_assert(SCROLL_BLOCKS_ON_MAX < (1 << 3), "ScrollBlocksOn too big"); | |
682 ScrollBlocksOn scroll_blocks_on_ : 3; | |
683 | |
684 bool user_scrollable_horizontal_ : 1; | |
685 bool user_scrollable_vertical_ : 1; | |
686 bool stacking_order_changed_ : 1; | |
687 // Whether the "back" of this layer should draw. | |
688 bool double_sided_ : 1; | |
689 bool should_flatten_transform_ : 1; | |
690 | |
691 // Tracks if drawing-related properties have changed since last redraw. | |
692 bool layer_property_changed_ : 1; | |
693 | |
694 bool masks_to_bounds_ : 1; | |
695 bool contents_opaque_ : 1; | |
696 bool is_root_for_isolated_group_ : 1; | |
697 bool use_parent_backface_visibility_ : 1; | |
698 bool draw_checkerboard_for_missing_tiles_ : 1; | |
699 bool draws_content_ : 1; | |
700 bool hide_layer_and_subtree_ : 1; | |
701 | |
702 // Cache transform_'s invertibility. | |
703 bool transform_is_invertible_ : 1; | |
704 | |
705 // Set for the layer that other layers are fixed to. | |
706 bool is_container_for_fixed_position_layers_ : 1; | |
707 Region non_fast_scrollable_region_; | |
708 Region touch_event_handler_region_; | |
709 SkColor background_color_; | |
710 | |
711 float opacity_; | |
712 SkXfermode::Mode blend_mode_; | |
713 gfx::PointF position_; | |
714 gfx::Transform transform_; | |
715 | |
716 LayerPositionConstraint position_constraint_; | |
717 | |
718 gfx::Vector2dF scroll_compensation_adjustment_; | |
719 | |
720 int num_descendants_that_draw_content_; | |
721 | |
722 // The global depth value of the center of the layer. This value is used | |
723 // to sort layers from back to front. | |
724 float draw_depth_; | |
725 | |
726 FilterOperations filters_; | |
727 FilterOperations background_filters_; | |
728 | |
729 protected: | |
730 friend class TreeSynchronizer; | |
731 | |
732 // This flag is set when the layer needs to push properties to the active | |
733 // side. | |
734 bool needs_push_properties_; | |
735 | |
736 // The number of direct children or dependent layers that need to be recursed | |
737 // to in order for them or a descendent of them to push properties to the | |
738 // active side. | |
739 int num_dependents_need_push_properties_; | |
740 | |
741 // Layers that share a sorting context id will be sorted together in 3d | |
742 // space. 0 is a special value that means this layer will not be sorted and | |
743 // will be drawn in paint order. | |
744 int sorting_context_id_; | |
745 | |
746 DrawMode current_draw_mode_; | |
747 | |
748 private: | |
749 // Rect indicating what was repainted/updated during update. | |
750 // Note that plugin layers bypass this and leave it empty. | |
751 // Uses layer (not content) space. | |
752 gfx::Rect update_rect_; | |
753 | |
754 // This rect is in layer space. | |
755 gfx::RectF damage_rect_; | |
756 | |
757 // Manages animations for this layer. | |
758 scoped_refptr<LayerAnimationController> layer_animation_controller_; | |
759 | |
760 // Manages scrollbars for this layer | |
761 scoped_ptr<ScrollbarAnimationController> scrollbar_animation_controller_; | |
762 | |
763 scoped_ptr<ScrollbarSet> scrollbars_; | |
764 | |
765 ScopedPtrVector<CopyOutputRequest> copy_requests_; | |
766 | |
767 // Group of properties that need to be computed based on the layer tree | |
768 // hierarchy before layers can be drawn. | |
769 DrawProperties<LayerImpl> draw_properties_; | |
770 | |
771 scoped_refptr<base::trace_event::ConvertableToTraceFormat> debug_info_; | |
772 scoped_ptr<RenderSurfaceImpl> render_surface_; | |
773 | |
774 std::vector<FrameTimingRequest> frame_timing_requests_; | |
775 bool frame_timing_requests_dirty_; | |
776 | |
777 DISALLOW_COPY_AND_ASSIGN(LayerImpl); | |
778 }; | |
779 | |
780 } // namespace cc | |
781 | |
782 #endif // CC_LAYERS_LAYER_IMPL_H_ | |
OLD | NEW |