blob: 37772e9bd8a87d490f13cc75fbd7e949496773f1 [file] [log] [blame]
[email protected]cd57cc5a2012-10-12 22:43:411// Copyright 2010 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]cc3cfaa2013-03-18 09:05:525#ifndef CC_LAYERS_LAYER_H_
6#define CC_LAYERS_LAYER_H_
[email protected]cd57cc5a2012-10-12 22:43:417
[email protected]0e98cdd2013-08-23 00:44:308#include <set>
[email protected]c8686a02012-11-27 08:29:009#include <string>
[email protected]c8686a02012-11-27 08:29:0010
[email protected]18a70192013-04-26 16:18:2511#include "base/callback.h"
[email protected]a8461d82012-10-16 21:11:1412#include "base/memory/ref_counted.h"
[email protected]e10cd022012-12-18 00:32:2613#include "base/observer_list.h"
[email protected]95e4e1a02013-03-18 07:09:0914#include "cc/animation/layer_animation_controller.h"
[email protected]95e4e1a02013-03-18 07:09:0915#include "cc/animation/layer_animation_value_observer.h"
[email protected]b8384e22013-12-03 02:20:4816#include "cc/animation/layer_animation_value_provider.h"
[email protected]681ccff2013-03-18 06:13:5217#include "cc/base/cc_export.h"
18#include "cc/base/region.h"
[email protected]0e5f7142013-05-24 06:45:3619#include "cc/base/scoped_ptr_vector.h"
[email protected]666d7cf2013-10-12 01:30:2920#include "cc/debug/micro_benchmark.h"
[email protected]cc3cfaa2013-03-18 09:05:5221#include "cc/layers/draw_properties.h"
[email protected]50761e92013-03-29 20:51:2822#include "cc/layers/layer_lists.h"
[email protected]fe956c9c42013-04-09 04:26:3323#include "cc/layers/layer_position_constraint.h"
[email protected]445881f2013-04-16 01:11:5924#include "cc/layers/paint_properties.h"
[email protected]cc3cfaa2013-03-18 09:05:5225#include "cc/layers/render_surface.h"
[email protected]ae6b1a72013-06-25 18:49:2926#include "cc/output/filter_operations.h"
[email protected]556fd292013-03-18 08:03:0427#include "cc/trees/occlusion_tracker.h"
[email protected]1940c4e2012-12-04 05:08:1528#include "skia/ext/refptr.h"
[email protected]ddf9df82012-10-16 06:52:4629#include "third_party/skia/include/core/SkColor.h"
[email protected]1940c4e2012-12-04 05:08:1530#include "third_party/skia/include/core/SkImageFilter.h"
[email protected]f7837a92013-08-21 03:00:0531#include "third_party/skia/include/core/SkPicture.h"
[email protected]7bbeaf4e2013-11-26 10:27:2232#include "third_party/skia/include/core/SkXfermode.h"
[email protected]aad0a0072012-11-01 18:15:5833#include "ui/gfx/rect.h"
34#include "ui/gfx/rect_f.h"
[email protected]c8686a02012-11-27 08:29:0035#include "ui/gfx/transform.h"
[email protected]cd57cc5a2012-10-12 22:43:4136
[email protected]db2586f2013-08-15 22:03:1437namespace gfx {
38class BoxF;
39}
40
[email protected]9f3be432013-12-03 03:53:2241namespace base {
42namespace debug {
43class ConvertableToTraceFormat;
44}
45}
46
[email protected]cd57cc5a2012-10-12 22:43:4147namespace cc {
48
[email protected]4d0786a2013-01-07 16:21:2049class Animation;
[email protected]3cae03e2013-06-26 22:13:5250class AnimationDelegate;
[email protected]96baf3e2012-10-22 23:09:5551struct AnimationEvent;
[email protected]0e5f7142013-05-24 06:45:3652class CopyOutputRequest;
[email protected]96baf3e2012-10-22 23:09:5553class LayerAnimationDelegate;
[email protected]7f5605c2013-04-08 18:08:3554class LayerAnimationEventObserver;
[email protected]ae716ce2013-08-16 13:04:2455class LayerClient;
[email protected]96baf3e2012-10-22 23:09:5556class LayerImpl;
57class LayerTreeHost;
[email protected]8bef40572012-12-11 21:38:0858class LayerTreeImpl;
[email protected]96baf3e2012-10-22 23:09:5559class PriorityCalculator;
[email protected]d84116612013-03-29 05:32:4960class RenderingStatsInstrumentation;
[email protected]b4da2032012-10-25 21:22:5561class ResourceUpdateQueue;
[email protected]80413d72013-08-30 20:25:3362class ScrollbarLayerInterface;
[email protected]96baf3e2012-10-22 23:09:5563struct AnimationEvent;
[email protected]cd57cc5a2012-10-12 22:43:4164
65// Base class for composited layers. Special layer types are derived from
66// this class.
[email protected]de4afb5e2012-12-20 00:11:3467class CC_EXPORT Layer : public base::RefCounted<Layer>,
[email protected]b8384e22013-12-03 02:20:4868 public LayerAnimationValueObserver,
69 public LayerAnimationValueProvider {
[email protected]7aba6662013-03-12 10:17:3470 public:
[email protected]44d8e84c2013-10-19 19:13:2271 typedef RenderSurfaceLayerList RenderSurfaceListType;
72 typedef LayerList LayerListType;
73 typedef RenderSurface RenderSurfaceType;
74
[email protected]b7c4783f2013-03-15 23:11:4275 enum LayerIdLabels {
[email protected]b7c4783f2013-03-15 23:11:4276 INVALID_ID = -1,
77 };
[email protected]cd57cc5a2012-10-12 22:43:4178
[email protected]7aba6662013-03-12 10:17:3479 static scoped_refptr<Layer> Create();
[email protected]cd57cc5a2012-10-12 22:43:4180
[email protected]7aba6662013-03-12 10:17:3481 int id() const { return layer_id_; }
[email protected]cd57cc5a2012-10-12 22:43:4182
[email protected]7aba6662013-03-12 10:17:3483 Layer* RootLayer();
84 Layer* parent() { return parent_; }
85 const Layer* parent() const { return parent_; }
86 void AddChild(scoped_refptr<Layer> child);
87 void InsertChild(scoped_refptr<Layer> child, size_t index);
88 void ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer);
89 void RemoveFromParent();
90 void RemoveAllChildren();
91 void SetChildren(const LayerList& children);
[email protected]f659521e2013-07-26 00:27:0692 bool HasAncestor(const Layer* ancestor) const;
[email protected]cd57cc5a2012-10-12 22:43:4193
[email protected]7aba6662013-03-12 10:17:3494 const LayerList& children() const { return children_; }
95 Layer* child_at(size_t index) { return children_[index].get(); }
[email protected]cd57cc5a2012-10-12 22:43:4196
[email protected]0e5f7142013-05-24 06:45:3697 // This requests the layer and its subtree be rendered and given to the
98 // callback. If the copy is unable to be produced (the layer is destroyed
99 // first), then the callback is called with a NULL/empty result.
100 void RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> request);
101 bool HasCopyRequest() const {
102 return !copy_requests_.empty();
[email protected]18a70192013-04-26 16:18:25103 }
104
[email protected]14bc5d682014-01-17 07:26:47105 void SetAnchorPoint(const gfx::PointF& anchor_point);
[email protected]7aba6662013-03-12 10:17:34106 gfx::PointF anchor_point() const { return anchor_point_; }
[email protected]cd57cc5a2012-10-12 22:43:41107
[email protected]7aba6662013-03-12 10:17:34108 void SetAnchorPointZ(float anchor_point_z);
109 float anchor_point_z() const { return anchor_point_z_; }
[email protected]cd57cc5a2012-10-12 22:43:41110
[email protected]7aba6662013-03-12 10:17:34111 virtual void SetBackgroundColor(SkColor background_color);
112 SkColor background_color() const { return background_color_; }
[email protected]2c4cbec2013-06-04 21:14:50113 // If contents_opaque(), return an opaque color else return a
114 // non-opaque color. Tries to return background_color(), if possible.
115 SkColor SafeOpaqueBackgroundColor() const;
[email protected]cd57cc5a2012-10-12 22:43:41116
[email protected]7aba6662013-03-12 10:17:34117 // A layer's bounds are in logical, non-page-scaled pixels (however, the
118 // root layer's bounds are in physical pixels).
[email protected]64348ea2014-01-29 22:58:26119 void SetBounds(const gfx::Size& bounds);
[email protected]7aba6662013-03-12 10:17:34120 gfx::Size bounds() const { return bounds_; }
[email protected]cd57cc5a2012-10-12 22:43:41121
[email protected]7aba6662013-03-12 10:17:34122 void SetMasksToBounds(bool masks_to_bounds);
123 bool masks_to_bounds() const { return masks_to_bounds_; }
[email protected]cd57cc5a2012-10-12 22:43:41124
[email protected]7aba6662013-03-12 10:17:34125 void SetMaskLayer(Layer* mask_layer);
126 Layer* mask_layer() { return mask_layer_.get(); }
127 const Layer* mask_layer() const { return mask_layer_.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41128
[email protected]7aba6662013-03-12 10:17:34129 virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect);
130 void SetNeedsDisplay() { SetNeedsDisplayRect(gfx::RectF(bounds())); }
[email protected]cd57cc5a2012-10-12 22:43:41131
[email protected]7aba6662013-03-12 10:17:34132 void SetOpacity(float opacity);
133 float opacity() const { return opacity_; }
134 bool OpacityIsAnimating() const;
[email protected]b7c4783f2013-03-15 23:11:42135 virtual bool OpacityCanAnimateOnImplThread() const;
[email protected]cd57cc5a2012-10-12 22:43:41136
[email protected]7bbeaf4e2013-11-26 10:27:22137 void SetBlendMode(SkXfermode::Mode blend_mode);
138 SkXfermode::Mode blend_mode() const { return blend_mode_; }
139
140 bool uses_default_blend_mode() const {
141 return blend_mode_ == SkXfermode::kSrcOver_Mode;
142 }
143
144 // A layer is root for an isolated group when it and all its descendants are
145 // drawn over a black and fully transparent background, creating an isolated
146 // group. It should be used along with SetBlendMode(), in order to restrict
147 // layers within the group to blend with layers outside this group.
148 void SetIsRootForIsolatedGroup(bool root);
149 bool is_root_for_isolated_group() const {
150 return is_root_for_isolated_group_;
151 }
152
[email protected]ae6b1a72013-06-25 18:49:29153 void SetFilters(const FilterOperations& filters);
154 const FilterOperations& filters() const { return filters_; }
[email protected]b4c6d812013-10-03 15:48:56155 bool FilterIsAnimating() const;
[email protected]cd57cc5a2012-10-12 22:43:41156
[email protected]7aba6662013-03-12 10:17:34157 // Background filters are filters applied to what is behind this layer, when
158 // they are viewed through non-opaque regions in this layer. They are used
159 // through the WebLayer interface, and are not exposed to HTML.
[email protected]ae6b1a72013-06-25 18:49:29160 void SetBackgroundFilters(const FilterOperations& filters);
161 const FilterOperations& background_filters() const {
[email protected]7aba6662013-03-12 10:17:34162 return background_filters_;
163 }
[email protected]cd57cc5a2012-10-12 22:43:41164
[email protected]7aba6662013-03-12 10:17:34165 virtual void SetContentsOpaque(bool opaque);
166 bool contents_opaque() const { return contents_opaque_; }
[email protected]cd57cc5a2012-10-12 22:43:41167
[email protected]14bc5d682014-01-17 07:26:47168 void SetPosition(const gfx::PointF& position);
[email protected]7aba6662013-03-12 10:17:34169 gfx::PointF position() const { return position_; }
[email protected]cd57cc5a2012-10-12 22:43:41170
[email protected]7aba6662013-03-12 10:17:34171 void SetIsContainerForFixedPositionLayers(bool container);
[email protected]fe956c9c42013-04-09 04:26:33172 bool IsContainerForFixedPositionLayers() const;
[email protected]cd57cc5a2012-10-12 22:43:41173
[email protected]fe956c9c42013-04-09 04:26:33174 void SetPositionConstraint(const LayerPositionConstraint& constraint);
175 const LayerPositionConstraint& position_constraint() const {
176 return position_constraint_;
177 }
[email protected]cd57cc5a2012-10-12 22:43:41178
[email protected]7aba6662013-03-12 10:17:34179 void SetTransform(const gfx::Transform& transform);
180 const gfx::Transform& transform() const { return transform_; }
181 bool TransformIsAnimating() const;
[email protected]cd57cc5a2012-10-12 22:43:41182
[email protected]0e98cdd2013-08-23 00:44:30183 void SetScrollParent(Layer* parent);
184
185 Layer* scroll_parent() { return scroll_parent_; }
186 const Layer* scroll_parent() const { return scroll_parent_; }
187
188 void AddScrollChild(Layer* child);
189 void RemoveScrollChild(Layer* child);
190
191 std::set<Layer*>* scroll_children() { return scroll_children_.get(); }
192 const std::set<Layer*>* scroll_children() const {
193 return scroll_children_.get();
194 }
195
196 void SetClipParent(Layer* ancestor);
197
198 Layer* clip_parent() { return clip_parent_; }
199 const Layer* clip_parent() const {
200 return clip_parent_;
201 }
202
203 void AddClipChild(Layer* child);
204 void RemoveClipChild(Layer* child);
205
206 std::set<Layer*>* clip_children() { return clip_children_.get(); }
207 const std::set<Layer*>* clip_children() const {
208 return clip_children_.get();
209 }
210
[email protected]44d8e84c2013-10-19 19:13:22211 DrawProperties<Layer>& draw_properties() { return draw_properties_; }
212 const DrawProperties<Layer>& draw_properties() const {
[email protected]7aba6662013-03-12 10:17:34213 return draw_properties_;
214 }
[email protected]d76806f82012-12-05 21:41:50215
[email protected]7aba6662013-03-12 10:17:34216 // The following are shortcut accessors to get various information from
217 // draw_properties_
218 const gfx::Transform& draw_transform() const {
219 return draw_properties_.target_space_transform;
220 }
221 const gfx::Transform& screen_space_transform() const {
222 return draw_properties_.screen_space_transform;
223 }
224 float draw_opacity() const { return draw_properties_.opacity; }
225 bool draw_opacity_is_animating() const {
226 return draw_properties_.opacity_is_animating;
227 }
228 bool draw_transform_is_animating() const {
229 return draw_properties_.target_space_transform_is_animating;
230 }
231 bool screen_space_transform_is_animating() const {
232 return draw_properties_.screen_space_transform_is_animating;
233 }
234 bool screen_space_opacity_is_animating() const {
235 return draw_properties_.screen_space_opacity_is_animating;
236 }
237 bool can_use_lcd_text() const { return draw_properties_.can_use_lcd_text; }
238 bool is_clipped() const { return draw_properties_.is_clipped; }
239 gfx::Rect clip_rect() const { return draw_properties_.clip_rect; }
240 gfx::Rect drawable_content_rect() const {
241 return draw_properties_.drawable_content_rect;
242 }
243 gfx::Rect visible_content_rect() const {
244 return draw_properties_.visible_content_rect;
245 }
246 Layer* render_target() {
247 DCHECK(!draw_properties_.render_target ||
248 draw_properties_.render_target->render_surface());
249 return draw_properties_.render_target;
250 }
251 const Layer* render_target() const {
252 DCHECK(!draw_properties_.render_target ||
253 draw_properties_.render_target->render_surface());
254 return draw_properties_.render_target;
255 }
256 RenderSurface* render_surface() const {
257 return draw_properties_.render_surface.get();
258 }
[email protected]420fdf6e2013-08-26 20:36:38259 int num_unclipped_descendants() const {
260 return draw_properties_.num_unclipped_descendants;
261 }
[email protected]cd57cc5a2012-10-12 22:43:41262
[email protected]7aba6662013-03-12 10:17:34263 void SetScrollOffset(gfx::Vector2d scroll_offset);
264 gfx::Vector2d scroll_offset() const { return scroll_offset_; }
[email protected]243e4f12014-02-05 09:18:42265 void SetScrollOffsetFromImplSide(const gfx::Vector2d& scroll_offset);
[email protected]cd57cc5a2012-10-12 22:43:41266
[email protected]adeda572014-01-31 00:49:47267 gfx::Vector2d MaxScrollOffset() const;
[email protected]adeda572014-01-31 00:49:47268 void SetScrollClipLayerId(int clip_layer_id);
269 bool scrollable() const { return scroll_clip_layer_id_ != INVALID_ID; }
[email protected]cd57cc5a2012-10-12 22:43:41270
[email protected]59a7d552013-10-22 03:36:43271 void SetUserScrollable(bool horizontal, bool vertical);
272 bool user_scrollable_horizontal() const {
273 return user_scrollable_horizontal_;
274 }
275 bool user_scrollable_vertical() const { return user_scrollable_vertical_; }
276
[email protected]7aba6662013-03-12 10:17:34277 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread);
278 bool should_scroll_on_main_thread() const {
279 return should_scroll_on_main_thread_;
280 }
[email protected]cd57cc5a2012-10-12 22:43:41281
[email protected]7aba6662013-03-12 10:17:34282 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers);
283 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; }
[email protected]cd57cc5a2012-10-12 22:43:41284
[email protected]7aba6662013-03-12 10:17:34285 void SetNonFastScrollableRegion(const Region& non_fast_scrollable_region);
286 const Region& non_fast_scrollable_region() const {
287 return non_fast_scrollable_region_;
288 }
[email protected]cd57cc5a2012-10-12 22:43:41289
[email protected]7aba6662013-03-12 10:17:34290 void SetTouchEventHandlerRegion(const Region& touch_event_handler_region);
291 const Region& touch_event_handler_region() const {
292 return touch_event_handler_region_;
293 }
[email protected]23d56be2012-11-08 00:33:34294
[email protected]28096ed2013-07-01 07:38:58295 void set_did_scroll_callback(const base::Closure& callback) {
296 did_scroll_callback_ = callback;
[email protected]7aba6662013-03-12 10:17:34297 }
[email protected]cd57cc5a2012-10-12 22:43:41298
[email protected]7aba6662013-03-12 10:17:34299 void SetDrawCheckerboardForMissingTiles(bool checkerboard);
300 bool DrawCheckerboardForMissingTiles() const {
301 return draw_checkerboard_for_missing_tiles_;
302 }
[email protected]cd57cc5a2012-10-12 22:43:41303
[email protected]7aba6662013-03-12 10:17:34304 void SetForceRenderSurface(bool force_render_surface);
305 bool force_render_surface() const { return force_render_surface_; }
[email protected]cd57cc5a2012-10-12 22:43:41306
[email protected]1960a712013-04-30 17:06:47307 gfx::Vector2d ScrollDelta() const { return gfx::Vector2d(); }
[email protected]4ec78f82013-07-11 18:45:47308 gfx::Vector2dF TotalScrollOffset() const {
309 // Floating point to match the LayerImpl version.
310 return scroll_offset() + ScrollDelta();
311 }
[email protected]cd57cc5a2012-10-12 22:43:41312
[email protected]7aba6662013-03-12 10:17:34313 void SetDoubleSided(bool double_sided);
314 bool double_sided() const { return double_sided_; }
[email protected]cd57cc5a2012-10-12 22:43:41315
[email protected]56fffdd2014-02-11 19:50:57316 void SetShouldFlattenTransform(bool flatten);
317 bool should_flatten_transform() const { return should_flatten_transform_; }
318
319 void SetIs3dSorted(bool sorted);
320 bool is_3d_sorted() const { return is_3d_sorted_; }
[email protected]cd57cc5a2012-10-12 22:43:41321
[email protected]7aba6662013-03-12 10:17:34322 void set_use_parent_backface_visibility(bool use) {
323 use_parent_backface_visibility_ = use;
324 }
325 bool use_parent_backface_visibility() const {
326 return use_parent_backface_visibility_;
327 }
[email protected]cd57cc5a2012-10-12 22:43:41328
[email protected]7aba6662013-03-12 10:17:34329 virtual void SetLayerTreeHost(LayerTreeHost* host);
[email protected]cd57cc5a2012-10-12 22:43:41330
[email protected]7aba6662013-03-12 10:17:34331 bool HasDelegatedContent() const { return false; }
332 bool HasContributingDelegatedRenderPasses() const { return false; }
[email protected]cd57cc5a2012-10-12 22:43:41333
[email protected]7aba6662013-03-12 10:17:34334 void SetIsDrawable(bool is_drawable);
[email protected]cd57cc5a2012-10-12 22:43:41335
[email protected]c0ae06c12013-06-24 18:32:19336 void SetHideLayerAndSubtree(bool hide);
337 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; }
338
[email protected]7aba6662013-03-12 10:17:34339 void SetReplicaLayer(Layer* layer);
340 Layer* replica_layer() { return replica_layer_.get(); }
341 const Layer* replica_layer() const { return replica_layer_.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41342
[email protected]22898ed2013-06-01 04:52:30343 bool has_mask() const { return !!mask_layer_.get(); }
344 bool has_replica() const { return !!replica_layer_.get(); }
[email protected]7aba6662013-03-12 10:17:34345 bool replica_has_mask() const {
[email protected]22898ed2013-06-01 04:52:30346 return replica_layer_.get() &&
347 (mask_layer_.get() || replica_layer_->mask_layer_.get());
[email protected]7aba6662013-03-12 10:17:34348 }
[email protected]cd57cc5a2012-10-12 22:43:41349
[email protected]7aba6662013-03-12 10:17:34350 // These methods typically need to be overwritten by derived classes.
351 virtual bool DrawsContent() const;
[email protected]445881f2013-04-16 01:11:59352 virtual void SavePaintProperties();
[email protected]49304bde2013-07-08 21:31:22353 // Returns true iff any resources were updated that need to be committed.
354 virtual bool Update(ResourceUpdateQueue* queue,
355 const OcclusionTracker* occlusion);
[email protected]7aba6662013-03-12 10:17:34356 virtual bool NeedMoreUpdates();
357 virtual void SetIsMask(bool is_mask) {}
[email protected]4830141f2013-05-18 01:36:05358 virtual void ReduceMemoryUsage() {}
[email protected]039fa8c2013-10-09 22:37:28359 virtual void OnOutputSurfaceCreated() {}
[email protected]cd57cc5a2012-10-12 22:43:41360
[email protected]9f3be432013-12-03 03:53:22361 virtual scoped_refptr<base::debug::ConvertableToTraceFormat> TakeDebugInfo();
[email protected]ae716ce2013-08-16 13:04:24362
363 void SetLayerClient(LayerClient* client) { client_ = client; }
364
[email protected]7aba6662013-03-12 10:17:34365 virtual void PushPropertiesTo(LayerImpl* layer);
366
[email protected]7aba6662013-03-12 10:17:34367 void CreateRenderSurface();
[email protected]50761e92013-03-29 20:51:28368 void ClearRenderSurface();
[email protected]7aba6662013-03-12 10:17:34369
[email protected]ed511b8d2013-03-25 03:29:29370 // The contents scale converts from logical, non-page-scaled pixels to target
371 // pixels. The contents scale is 1 for the root layer as it is already in
372 // physical pixels. By default contents scale is forced to be 1 except for
[email protected]7aba6662013-03-12 10:17:34373 // subclasses of ContentsScalingLayer.
374 float contents_scale_x() const { return draw_properties_.contents_scale_x; }
375 float contents_scale_y() const { return draw_properties_.contents_scale_y; }
376 gfx::Size content_bounds() const { return draw_properties_.content_bounds; }
[email protected]cd57cc5a2012-10-12 22:43:41377
[email protected]7aba6662013-03-12 10:17:34378 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:06379 float device_scale_factor,
380 float page_scale_factor,
[email protected]7aba6662013-03-12 10:17:34381 bool animating_transform_to_screen,
382 float* contents_scale_x,
383 float* contents_scale_y,
384 gfx::Size* content_bounds);
[email protected]cd57cc5a2012-10-12 22:43:41385
[email protected]3698e792013-08-24 00:21:16386 LayerTreeHost* layer_tree_host() { return layer_tree_host_; }
387 const LayerTreeHost* layer_tree_host() const { return layer_tree_host_; }
[email protected]cd57cc5a2012-10-12 22:43:41388
[email protected]7aba6662013-03-12 10:17:34389 // Set the priority of all desired textures in this layer.
390 virtual void SetTexturePriorities(const PriorityCalculator& priority_calc) {}
[email protected]cd57cc5a2012-10-12 22:43:41391
[email protected]7aba6662013-03-12 10:17:34392 bool AddAnimation(scoped_ptr<Animation> animation);
393 void PauseAnimation(int animation_id, double time_offset);
394 void RemoveAnimation(int animation_id);
[email protected]cd57cc5a2012-10-12 22:43:41395
[email protected]7aba6662013-03-12 10:17:34396 LayerAnimationController* layer_animation_controller() {
397 return layer_animation_controller_.get();
398 }
[email protected]7f5605c2013-04-08 18:08:35399 void SetLayerAnimationControllerForTest(
[email protected]7aba6662013-03-12 10:17:34400 scoped_refptr<LayerAnimationController> controller);
[email protected]cd57cc5a2012-10-12 22:43:41401
[email protected]3cae03e2013-06-26 22:13:52402 void set_layer_animation_delegate(AnimationDelegate* delegate) {
[email protected]7f5605c2013-04-08 18:08:35403 layer_animation_controller_->set_layer_animation_delegate(delegate);
[email protected]7aba6662013-03-12 10:17:34404 }
[email protected]cd57cc5a2012-10-12 22:43:41405
[email protected]7aba6662013-03-12 10:17:34406 bool HasActiveAnimation() const;
[email protected]cd57cc5a2012-10-12 22:43:41407
[email protected]7aba6662013-03-12 10:17:34408 void AddLayerAnimationEventObserver(
409 LayerAnimationEventObserver* animation_observer);
410 void RemoveLayerAnimationEventObserver(
411 LayerAnimationEventObserver* animation_observer);
[email protected]cd57cc5a2012-10-12 22:43:41412
[email protected]7aba6662013-03-12 10:17:34413 virtual Region VisibleContentOpaqueRegion() const;
[email protected]e10cd022012-12-18 00:32:26414
[email protected]80413d72013-08-30 20:25:33415 virtual ScrollbarLayerInterface* ToScrollbarLayer();
[email protected]cd57cc5a2012-10-12 22:43:41416
[email protected]7aba6662013-03-12 10:17:34417 gfx::Rect LayerRectToContentRect(const gfx::RectF& layer_rect) const;
[email protected]cd57cc5a2012-10-12 22:43:41418
[email protected]f7837a92013-08-21 03:00:05419 virtual skia::RefPtr<SkPicture> GetPicture() const;
420
[email protected]7aba6662013-03-12 10:17:34421 // Constructs a LayerImpl of the correct runtime type for this Layer type.
422 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl);
[email protected]aedf4e52013-01-09 23:24:44423
[email protected]44604642013-08-01 01:14:09424 bool NeedsDisplayForTesting() const { return !update_rect_.IsEmpty(); }
425 void ResetNeedsDisplayForTesting() { update_rect_ = gfx::RectF(); }
[email protected]48871fc2013-01-23 07:36:51426
[email protected]d84116612013-03-29 05:32:49427 RenderingStatsInstrumentation* rendering_stats_instrumentation() const;
428
[email protected]445881f2013-04-16 01:11:59429 const PaintProperties& paint_properties() const {
430 return paint_properties_;
431 }
432
[email protected]35a99a12013-05-09 23:52:29433 // The scale at which contents should be rastered, to match the scale at
434 // which they will drawn to the screen. This scale is a component of the
435 // contents scale but does not include page/device scale factors.
436 // TODO(danakj): This goes away when TiledLayer goes away.
437 void set_raster_scale(float scale) { raster_scale_ = scale; }
438 float raster_scale() const { return raster_scale_; }
439 bool raster_scale_is_unknown() const { return raster_scale_ == 0.f; }
440
[email protected]7924c1852013-05-24 16:18:43441 virtual bool SupportsLCDText() const;
442
[email protected]7a5a9322014-02-25 12:54:57443 void SetNeedsPushProperties();
[email protected]f4e25f92013-07-13 20:54:53444 bool needs_push_properties() const { return needs_push_properties_; }
445 bool descendant_needs_push_properties() const {
446 return num_dependents_need_push_properties_ > 0;
447 }
[email protected]7a5a9322014-02-25 12:54:57448 void reset_needs_push_properties_for_testing() {
449 needs_push_properties_ = false;
450 }
[email protected]f4e25f92013-07-13 20:54:53451
[email protected]666d7cf2013-10-12 01:30:29452 virtual void RunMicroBenchmark(MicroBenchmark* benchmark);
453
[email protected]7aba6662013-03-12 10:17:34454 protected:
455 friend class LayerImpl;
456 friend class TreeSynchronizer;
457 virtual ~Layer();
[email protected]090e1a72013-01-29 07:07:45458
[email protected]7aba6662013-03-12 10:17:34459 Layer();
[email protected]cd57cc5a2012-10-12 22:43:41460
[email protected]3519b872013-07-30 07:17:50461 // These SetNeeds functions are in order of severity of update:
462 //
463 // Called when this layer has been modified in some way, but isn't sure
464 // that it needs a commit yet. It needs CalcDrawProperties and UpdateLayers
465 // before it knows whether or not a commit is required.
466 void SetNeedsUpdate();
467 // Called when a property has been modified in a way that the layer
468 // knows immediately that a commit is required. This implies SetNeedsUpdate
469 // as well as SetNeedsPushProperties to push that property.
[email protected]7aba6662013-03-12 10:17:34470 void SetNeedsCommit();
[email protected]3519b872013-07-30 07:17:50471 // Called when there's been a change in layer structure. Implies both
472 // SetNeedsUpdate and SetNeedsCommit, but not SetNeedsPushProperties.
[email protected]7aba6662013-03-12 10:17:34473 void SetNeedsFullTreeSync();
[email protected]74b43cc2013-08-30 06:29:27474
475 // Called when the next commit should wait until the pending tree is activated
476 // before finishing the commit and unblocking the main thread. Used to ensure
477 // unused resources on the impl thread are returned before commit completes.
478 void SetNextCommitWaitsForActivation();
[email protected]cd57cc5a2012-10-12 22:43:41479
[email protected]7bbeaf4e2013-11-26 10:27:22480 // Called when the blend mode or filters have been changed.
481 void SetNeedsFilterContextIfNeeded();
482
[email protected]f4e25f92013-07-13 20:54:53483 void AddDependentNeedsPushProperties();
484 void RemoveDependentNeedsPushProperties();
485 bool parent_should_know_need_push_properties() const {
486 return needs_push_properties() || descendant_needs_push_properties();
487 }
488
[email protected]74b43cc2013-08-30 06:29:27489 bool IsPropertyChangeAllowed() const;
490
[email protected]0e98cdd2013-08-23 00:44:30491 // If this layer has a scroll parent, it removes |this| from its list of
492 // scroll children.
493 void RemoveFromScrollTree();
494
495 // If this layer has a clip parent, it removes |this| from its list of clip
496 // children.
497 void RemoveFromClipTree();
498
[email protected]35a99a12013-05-09 23:52:29499 void reset_raster_scale_to_unknown() { raster_scale_ = 0.f; }
500
[email protected]f4e25f92013-07-13 20:54:53501 // This flag is set when the layer needs to push properties to the impl
502 // side.
503 bool needs_push_properties_;
504
505 // The number of direct children or dependent layers that need to be recursed
506 // to in order for them or a descendent of them to push properties to the impl
507 // side.
508 int num_dependents_need_push_properties_;
509
[email protected]7aba6662013-03-12 10:17:34510 // Tracks whether this layer may have changed stacking order with its
511 // siblings.
512 bool stacking_order_changed_;
[email protected]cd57cc5a2012-10-12 22:43:41513
[email protected]7aba6662013-03-12 10:17:34514 // The update rect is the region of the compositor resource that was
515 // actually updated by the compositor. For layers that may do updating
516 // outside the compositor's control (i.e. plugin layers), this information
517 // is not available and the update rect will remain empty.
518 // Note this rect is in layer space (not content space).
519 gfx::RectF update_rect_;
[email protected]cd57cc5a2012-10-12 22:43:41520
[email protected]7aba6662013-03-12 10:17:34521 scoped_refptr<Layer> mask_layer_;
[email protected]cd57cc5a2012-10-12 22:43:41522
[email protected]7aba6662013-03-12 10:17:34523 int layer_id_;
[email protected]cd57cc5a2012-10-12 22:43:41524
[email protected]7aba6662013-03-12 10:17:34525 // When true, the layer is about to perform an update. Any commit requests
[email protected]3519b872013-07-30 07:17:50526 // will be handled implicitly after the update completes.
[email protected]7aba6662013-03-12 10:17:34527 bool ignore_set_needs_commit_;
[email protected]cd57cc5a2012-10-12 22:43:41528
[email protected]7aba6662013-03-12 10:17:34529 private:
530 friend class base::RefCounted<Layer>;
[email protected]29493a12012-12-20 01:42:42531
[email protected]7aba6662013-03-12 10:17:34532 void SetParent(Layer* layer);
[email protected]7aba6662013-03-12 10:17:34533 bool DescendantIsFixedToContainerLayer() const;
[email protected]cd57cc5a2012-10-12 22:43:41534
[email protected]7aba6662013-03-12 10:17:34535 // Returns the index of the child or -1 if not found.
536 int IndexOfChild(const Layer* reference);
[email protected]cd57cc5a2012-10-12 22:43:41537
[email protected]7aba6662013-03-12 10:17:34538 // This should only be called from RemoveFromParent().
539 void RemoveChildOrDependent(Layer* child);
[email protected]cd57cc5a2012-10-12 22:43:41540
[email protected]b8384e22013-12-03 02:20:48541 // LayerAnimationValueProvider implementation.
542 virtual gfx::Vector2dF ScrollOffsetForAnimation() const OVERRIDE;
543
[email protected]7aba6662013-03-12 10:17:34544 // LayerAnimationValueObserver implementation.
[email protected]b4c6d812013-10-03 15:48:56545 virtual void OnFilterAnimated(const FilterOperations& filters) OVERRIDE;
[email protected]7aba6662013-03-12 10:17:34546 virtual void OnOpacityAnimated(float opacity) OVERRIDE;
547 virtual void OnTransformAnimated(const gfx::Transform& transform) OVERRIDE;
[email protected]3244c9132014-01-23 10:39:12548 virtual void OnScrollOffsetAnimated(
549 const gfx::Vector2dF& scroll_offset) OVERRIDE;
[email protected]1c24cf2962013-11-18 23:34:51550 virtual void OnAnimationWaitingForDeletion() OVERRIDE;
[email protected]7aba6662013-03-12 10:17:34551 virtual bool IsActive() const OVERRIDE;
[email protected]cd57cc5a2012-10-12 22:43:41552
[email protected]7aba6662013-03-12 10:17:34553 LayerList children_;
554 Layer* parent_;
[email protected]de4afb5e2012-12-20 00:11:34555
[email protected]7aba6662013-03-12 10:17:34556 // Layer instances have a weak pointer to their LayerTreeHost.
557 // This pointer value is nil when a Layer is not in a tree and is
558 // updated via SetLayerTreeHost() if a layer moves between trees.
559 LayerTreeHost* layer_tree_host_;
[email protected]cd57cc5a2012-10-12 22:43:41560
[email protected]7aba6662013-03-12 10:17:34561 scoped_refptr<LayerAnimationController> layer_animation_controller_;
[email protected]de4afb5e2012-12-20 00:11:34562
[email protected]7aba6662013-03-12 10:17:34563 // Layer properties.
564 gfx::Size bounds_;
[email protected]cd57cc5a2012-10-12 22:43:41565
[email protected]7aba6662013-03-12 10:17:34566 gfx::Vector2d scroll_offset_;
[email protected]adeda572014-01-31 00:49:47567 // This variable indicates which ancestor layer (if any) whose size,
568 // transformed relative to this layer, defines the maximum scroll offset for
569 // this layer.
570 int scroll_clip_layer_id_;
[email protected]c55f3fc2013-12-10 05:48:48571 bool scrollable_ : 1;
572 bool should_scroll_on_main_thread_ : 1;
573 bool have_wheel_event_handlers_ : 1;
574 bool user_scrollable_horizontal_ : 1;
575 bool user_scrollable_vertical_ : 1;
576 bool is_root_for_isolated_group_ : 1;
577 bool is_container_for_fixed_position_layers_ : 1;
578 bool is_drawable_ : 1;
579 bool hide_layer_and_subtree_ : 1;
580 bool masks_to_bounds_ : 1;
581 bool contents_opaque_ : 1;
582 bool double_sided_ : 1;
[email protected]56fffdd2014-02-11 19:50:57583 bool should_flatten_transform_ : 1;
[email protected]c55f3fc2013-12-10 05:48:48584 bool use_parent_backface_visibility_ : 1;
585 bool draw_checkerboard_for_missing_tiles_ : 1;
586 bool force_render_surface_ : 1;
[email protected]56fffdd2014-02-11 19:50:57587 bool is_3d_sorted_ : 1;
[email protected]7aba6662013-03-12 10:17:34588 Region non_fast_scrollable_region_;
589 Region touch_event_handler_region_;
590 gfx::PointF position_;
591 gfx::PointF anchor_point_;
592 SkColor background_color_;
[email protected]7aba6662013-03-12 10:17:34593 float opacity_;
[email protected]7bbeaf4e2013-11-26 10:27:22594 SkXfermode::Mode blend_mode_;
[email protected]ae6b1a72013-06-25 18:49:29595 FilterOperations filters_;
596 FilterOperations background_filters_;
[email protected]7aba6662013-03-12 10:17:34597 float anchor_point_z_;
[email protected]fe956c9c42013-04-09 04:26:33598 LayerPositionConstraint position_constraint_;
[email protected]0e98cdd2013-08-23 00:44:30599 Layer* scroll_parent_;
600 scoped_ptr<std::set<Layer*> > scroll_children_;
601
602 Layer* clip_parent_;
603 scoped_ptr<std::set<Layer*> > clip_children_;
[email protected]cd57cc5a2012-10-12 22:43:41604
[email protected]7aba6662013-03-12 10:17:34605 gfx::Transform transform_;
[email protected]cd57cc5a2012-10-12 22:43:41606
[email protected]7aba6662013-03-12 10:17:34607 // Replica layer used for reflections.
608 scoped_refptr<Layer> replica_layer_;
[email protected]cd57cc5a2012-10-12 22:43:41609
[email protected]7aba6662013-03-12 10:17:34610 // Transient properties.
611 float raster_scale_;
[email protected]cd57cc5a2012-10-12 22:43:41612
[email protected]ae716ce2013-08-16 13:04:24613 LayerClient* client_;
614
[email protected]0e5f7142013-05-24 06:45:36615 ScopedPtrVector<CopyOutputRequest> copy_requests_;
[email protected]18a70192013-04-26 16:18:25616
[email protected]28096ed2013-07-01 07:38:58617 base::Closure did_scroll_callback_;
[email protected]cd57cc5a2012-10-12 22:43:41618
[email protected]44d8e84c2013-10-19 19:13:22619 DrawProperties<Layer> draw_properties_;
[email protected]d76806f82012-12-05 21:41:50620
[email protected]445881f2013-04-16 01:11:59621 PaintProperties paint_properties_;
622
[email protected]7aba6662013-03-12 10:17:34623 DISALLOW_COPY_AND_ASSIGN(Layer);
[email protected]cd57cc5a2012-10-12 22:43:41624};
625
[email protected]ddf9df82012-10-16 06:52:46626} // namespace cc
627
[email protected]cc3cfaa2013-03-18 09:05:52628#endif // CC_LAYERS_LAYER_H_