blob: 09c1fa04a73e185e63aeef74dd2af24b1c820696 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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
[email protected]d50c6862012-10-23 02:08:315#include "cc/layer_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]c4040a522012-10-21 15:01:407#include "base/debug/trace_event.h"
8#include "base/stringprintf.h"
[email protected]4a23c374c2012-12-08 08:38:559#include "base/values.h"
[email protected]de4afb5e2012-12-20 00:11:3410#include "cc/animation_registrar.h"
[email protected]aa0a9d32012-10-24 01:58:1011#include "cc/debug_border_draw_quad.h"
[email protected]08d06fa2012-11-16 00:06:3812#include "cc/debug_colors.h"
[email protected]ff762fb2012-12-12 19:18:3713#include "cc/layer_tree_debug_state.h"
[email protected]8bef40572012-12-11 21:38:0814#include "cc/layer_tree_impl.h"
[email protected]ff762fb2012-12-12 19:18:3715#include "cc/layer_tree_settings.h"
[email protected]55a124d02012-10-22 03:07:1316#include "cc/math_util.h"
17#include "cc/proxy.h"
18#include "cc/quad_sink.h"
[email protected]c4040a522012-10-21 15:01:4019#include "cc/scrollbar_animation_controller.h"
[email protected]aad0a0072012-11-01 18:15:5820#include "ui/gfx/point_conversions.h"
21#include "ui/gfx/rect_conversions.h"
[email protected]94f206c12012-08-25 00:09:1422
[email protected]9c88e562012-09-14 22:21:3023namespace cc {
[email protected]94f206c12012-08-25 00:09:1424
[email protected]8bef40572012-12-11 21:38:0825LayerImpl::LayerImpl(LayerTreeImpl* treeImpl, int id)
[email protected]94f206c12012-08-25 00:09:1426 : m_parent(0)
27 , m_maskLayerId(-1)
28 , m_replicaLayerId(-1)
29 , m_layerId(id)
[email protected]8bef40572012-12-11 21:38:0830 , m_layerTreeImpl(treeImpl)
[email protected]94f206c12012-08-25 00:09:1431 , m_anchorPoint(0.5, 0.5)
32 , m_anchorPointZ(0)
[email protected]94f206c12012-08-25 00:09:1433 , m_scrollable(false)
34 , m_shouldScrollOnMainThread(false)
35 , m_haveWheelEventHandlers(false)
36 , m_backgroundColor(0)
37 , m_doubleSided(true)
38 , m_layerPropertyChanged(false)
39 , m_layerSurfacePropertyChanged(false)
40 , m_masksToBounds(false)
[email protected]048634c2012-10-02 22:33:1441 , m_contentsOpaque(false)
[email protected]df1ec1a2012-12-08 17:01:1842 , m_opacity(1.0)
[email protected]94f206c12012-08-25 00:09:1443 , m_preserves3D(false)
44 , m_useParentBackfaceVisibility(false)
45 , m_drawCheckerboardForMissingTiles(false)
[email protected]94f206c12012-08-25 00:09:1446 , m_drawsContent(false)
47 , m_forceRenderSurface(false)
48 , m_isContainerForFixedPositionLayers(false)
49 , m_fixedToContainerLayer(false)
[email protected]94f206c12012-08-25 00:09:1450 , m_drawDepth(0)
[email protected]e7f87cfb2012-10-17 01:25:1851#ifndef NDEBUG
[email protected]94f206c12012-08-25 00:09:1452 , m_betweenWillDrawAndDidDraw(false)
53#endif
[email protected]94f206c12012-08-25 00:09:1454{
[email protected]1d993172012-10-18 18:15:0455 DCHECK(m_layerId > 0);
[email protected]8bef40572012-12-11 21:38:0856 DCHECK(m_layerTreeImpl);
[email protected]361bc00d2012-12-14 07:03:2457 m_layerTreeImpl->RegisterLayer(this);
[email protected]de4afb5e2012-12-20 00:11:3458 AnimationRegistrar* registrar = m_layerTreeImpl->animationRegistrar();
59 m_layerAnimationController = registrar->GetAnimationControllerForId(m_layerId);
60 m_layerAnimationController->addObserver(this);
[email protected]94f206c12012-08-25 00:09:1461}
62
[email protected]96baf3e2012-10-22 23:09:5563LayerImpl::~LayerImpl()
[email protected]94f206c12012-08-25 00:09:1464{
[email protected]e7f87cfb2012-10-17 01:25:1865#ifndef NDEBUG
[email protected]1d993172012-10-18 18:15:0466 DCHECK(!m_betweenWillDrawAndDidDraw);
[email protected]e7f87cfb2012-10-17 01:25:1867#endif
[email protected]361bc00d2012-12-14 07:03:2468 m_layerTreeImpl->UnregisterLayer(this);
[email protected]de4afb5e2012-12-20 00:11:3469 m_layerAnimationController->removeObserver(this);
[email protected]94f206c12012-08-25 00:09:1470}
71
[email protected]96baf3e2012-10-22 23:09:5572void LayerImpl::addChild(scoped_ptr<LayerImpl> child)
[email protected]94f206c12012-08-25 00:09:1473{
74 child->setParent(this);
[email protected]ff762fb2012-12-12 19:18:3775 DCHECK_EQ(layerTreeImpl(), child->layerTreeImpl());
[email protected]e0bd43a2012-10-12 16:54:2176 m_children.append(child.Pass());
[email protected]ff762fb2012-12-12 19:18:3777 layerTreeImpl()->SetNeedsUpdateDrawProperties();
[email protected]94f206c12012-08-25 00:09:1478}
79
[email protected]30461f12012-12-10 01:30:2080scoped_ptr<LayerImpl> LayerImpl::removeChild(LayerImpl* child)
[email protected]94f206c12012-08-25 00:09:1481{
[email protected]30461f12012-12-10 01:30:2082 for (size_t i = 0; i < m_children.size(); ++i) {
83 if (m_children[i] == child) {
84 scoped_ptr<LayerImpl> ret = m_children.take(i);
85 m_children.remove(i);
[email protected]ff762fb2012-12-12 19:18:3786 layerTreeImpl()->SetNeedsUpdateDrawProperties();
[email protected]30461f12012-12-10 01:30:2087 return ret.Pass();
[email protected]94f206c12012-08-25 00:09:1488 }
89 }
[email protected]30461f12012-12-10 01:30:2090 return scoped_ptr<LayerImpl>();
[email protected]94f206c12012-08-25 00:09:1491}
92
[email protected]96baf3e2012-10-22 23:09:5593void LayerImpl::removeAllChildren()
[email protected]94f206c12012-08-25 00:09:1494{
[email protected]30461f12012-12-10 01:30:2095 m_children.clear();
[email protected]ff762fb2012-12-12 19:18:3796 layerTreeImpl()->SetNeedsUpdateDrawProperties();
[email protected]94f206c12012-08-25 00:09:1497}
98
[email protected]96baf3e2012-10-22 23:09:5599void LayerImpl::clearChildList()
[email protected]94f206c12012-08-25 00:09:14100{
[email protected]0ede3bb2012-12-09 09:14:39101 if (m_children.isEmpty())
102 return;
103
[email protected]94f206c12012-08-25 00:09:14104 m_children.clear();
[email protected]ff762fb2012-12-12 19:18:37105 layerTreeImpl()->SetNeedsUpdateDrawProperties();
[email protected]94f206c12012-08-25 00:09:14106}
107
[email protected]96baf3e2012-10-22 23:09:55108void LayerImpl::createRenderSurface()
[email protected]94f206c12012-08-25 00:09:14109{
[email protected]d76806f82012-12-05 21:41:50110 DCHECK(!m_drawProperties.render_surface);
111 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurfaceImpl(this));
112 m_drawProperties.render_target = this;
[email protected]94f206c12012-08-25 00:09:14113}
114
[email protected]96baf3e2012-10-22 23:09:55115scoped_ptr<SharedQuadState> LayerImpl::createSharedQuadState() const
[email protected]94f206c12012-08-25 00:09:14116{
[email protected]cb7af742012-11-21 04:02:24117 scoped_ptr<SharedQuadState> state = SharedQuadState::Create();
[email protected]d76806f82012-12-05 21:41:50118 state->SetAll(m_drawProperties.target_space_transform,
119 m_drawProperties.visible_content_rect,
120 m_drawProperties.drawable_content_rect,
121 m_drawProperties.clip_rect,
122 m_drawProperties.is_clipped,
123 m_drawProperties.opacity);
[email protected]cb7af742012-11-21 04:02:24124 return state.Pass();
[email protected]94f206c12012-08-25 00:09:14125}
126
[email protected]96baf3e2012-10-22 23:09:55127void LayerImpl::willDraw(ResourceProvider*)
[email protected]94f206c12012-08-25 00:09:14128{
[email protected]e7f87cfb2012-10-17 01:25:18129#ifndef NDEBUG
[email protected]94f206c12012-08-25 00:09:14130 // willDraw/didDraw must be matched.
[email protected]1d993172012-10-18 18:15:04131 DCHECK(!m_betweenWillDrawAndDidDraw);
[email protected]94f206c12012-08-25 00:09:14132 m_betweenWillDrawAndDidDraw = true;
133#endif
134}
135
[email protected]96baf3e2012-10-22 23:09:55136void LayerImpl::didDraw(ResourceProvider*)
[email protected]94f206c12012-08-25 00:09:14137{
[email protected]e7f87cfb2012-10-17 01:25:18138#ifndef NDEBUG
[email protected]1d993172012-10-18 18:15:04139 DCHECK(m_betweenWillDrawAndDidDraw);
[email protected]94f206c12012-08-25 00:09:14140 m_betweenWillDrawAndDidDraw = false;
141#endif
142}
143
[email protected]3dce37232012-11-15 01:47:44144bool LayerImpl::showDebugBorders() const
145{
[email protected]ff762fb2012-12-12 19:18:37146 return layerTreeImpl()->debug_state().showDebugBorders;
[email protected]3dce37232012-11-15 01:47:44147}
148
149void LayerImpl::getDebugBorderProperties(SkColor* color, float* width) const
150{
151 if (m_drawsContent) {
[email protected]08d06fa2012-11-16 00:06:38152 *color = DebugColors::ContentLayerBorderColor();
[email protected]ff762fb2012-12-12 19:18:37153 *width = DebugColors::ContentLayerBorderWidth(layerTreeImpl());
[email protected]3dce37232012-11-15 01:47:44154 return;
155 }
156
157 if (m_masksToBounds) {
[email protected]08d06fa2012-11-16 00:06:38158 *color = DebugColors::MaskingLayerBorderColor();
[email protected]ff762fb2012-12-12 19:18:37159 *width = DebugColors::MaskingLayerBorderWidth(layerTreeImpl());
[email protected]3dce37232012-11-15 01:47:44160 return;
161 }
162
[email protected]08d06fa2012-11-16 00:06:38163 *color = DebugColors::ContainerLayerBorderColor();
[email protected]ff762fb2012-12-12 19:18:37164 *width = DebugColors::ContainerLayerBorderWidth(layerTreeImpl());
[email protected]3dce37232012-11-15 01:47:44165}
166
[email protected]96baf3e2012-10-22 23:09:55167void LayerImpl::appendDebugBorderQuad(QuadSink& quadList, const SharedQuadState* sharedQuadState, AppendQuadsData& appendQuadsData) const
[email protected]94f206c12012-08-25 00:09:14168{
[email protected]3dce37232012-11-15 01:47:44169 if (!showDebugBorders())
[email protected]94f206c12012-08-25 00:09:14170 return;
171
[email protected]3dce37232012-11-15 01:47:44172 SkColor color;
173 float width;
174 getDebugBorderProperties(&color, &width);
175
[email protected]aad0a0072012-11-01 18:15:58176 gfx::Rect contentRect(gfx::Point(), contentBounds());
[email protected]c22418b2012-11-20 23:06:26177 scoped_ptr<DebugBorderDrawQuad> debugBorderQuad = DebugBorderDrawQuad::Create();
178 debugBorderQuad->SetNew(sharedQuadState, contentRect, color, width);
179 quadList.append(debugBorderQuad.PassAs<DrawQuad>(), appendQuadsData);
[email protected]94f206c12012-08-25 00:09:14180}
181
[email protected]b5b1fce2012-12-12 22:49:36182bool LayerImpl::hasDelegatedContent() const
183{
184 return false;
185}
186
[email protected]96baf3e2012-10-22 23:09:55187bool LayerImpl::hasContributingDelegatedRenderPasses() const
[email protected]76481592012-09-21 16:47:06188{
189 return false;
190}
191
[email protected]96baf3e2012-10-22 23:09:55192RenderPass::Id LayerImpl::firstContributingRenderPassId() const
[email protected]76481592012-09-21 16:47:06193{
[email protected]96baf3e2012-10-22 23:09:55194 return RenderPass::Id(0, 0);
[email protected]76481592012-09-21 16:47:06195}
196
[email protected]96baf3e2012-10-22 23:09:55197RenderPass::Id LayerImpl::nextContributingRenderPassId(RenderPass::Id) const
[email protected]76481592012-09-21 16:47:06198{
[email protected]96baf3e2012-10-22 23:09:55199 return RenderPass::Id(0, 0);
[email protected]76481592012-09-21 16:47:06200}
201
[email protected]96baf3e2012-10-22 23:09:55202ResourceProvider::ResourceId LayerImpl::contentsResourceId() const
[email protected]94f206c12012-08-25 00:09:14203{
[email protected]1d993172012-10-18 18:15:04204 NOTREACHED();
[email protected]94f206c12012-08-25 00:09:14205 return 0;
206}
207
[email protected]caa567d2012-12-20 07:56:16208void LayerImpl::setSentScrollDelta(const gfx::Vector2d& sentScrollDelta)
209{
210 m_sentScrollDelta = sentScrollDelta;
211 if (layerTreeImpl()->IsActiveTree())
212 {
213 LayerImpl* pending_twin = layerTreeImpl()->FindPendingTreeLayerById(id());
214 if (pending_twin)
215 pending_twin->setSentScrollDelta(sentScrollDelta);
216 }
217}
218
[email protected]c9c1ebe2012-11-05 20:46:13219gfx::Vector2dF LayerImpl::scrollBy(const gfx::Vector2dF& scroll)
[email protected]94f206c12012-08-25 00:09:14220{
[email protected]c9c1ebe2012-11-05 20:46:13221 gfx::Vector2dF minDelta = -m_scrollOffset;
222 gfx::Vector2dF maxDelta = m_maxScrollOffset - m_scrollOffset;
[email protected]94f206c12012-08-25 00:09:14223 // Clamp newDelta so that position + delta stays within scroll bounds.
[email protected]c9c1ebe2012-11-05 20:46:13224 gfx::Vector2dF newDelta = (m_scrollDelta + scroll);
[email protected]fe07b642012-11-10 00:07:59225 newDelta.ClampToMin(minDelta);
226 newDelta.ClampToMax(maxDelta);
[email protected]c9c1ebe2012-11-05 20:46:13227 gfx::Vector2dF unscrolled = m_scrollDelta + scroll - newDelta;
[email protected]94f206c12012-08-25 00:09:14228
229 if (m_scrollDelta == newDelta)
[email protected]1c0c9bc2012-10-08 22:41:48230 return unscrolled;
[email protected]94f206c12012-08-25 00:09:14231
[email protected]caa567d2012-12-20 07:56:16232 if (layerTreeImpl()->IsActiveTree())
233 {
234 LayerImpl* pending_twin = layerTreeImpl()->FindPendingTreeLayerById(id());
235 if (pending_twin) {
236 // Don't send the full scroll to the new layer, as if it is larger
237 // then it may cause a jump during tree activation. Instead,
238 // scroll it by the clamped amount that this layer scrolled.
239 pending_twin->scrollBy(newDelta - m_scrollDelta);
240 }
241 }
242
[email protected]94f206c12012-08-25 00:09:14243 m_scrollDelta = newDelta;
244 if (m_scrollbarAnimationController)
245 m_scrollbarAnimationController->updateScrollOffset(this);
246 noteLayerPropertyChangedForSubtree();
[email protected]1c0c9bc2012-10-08 22:41:48247
248 return unscrolled;
[email protected]94f206c12012-08-25 00:09:14249}
250
[email protected]d455d552012-11-02 00:19:06251InputHandlerClient::ScrollStatus LayerImpl::tryScroll(const gfx::PointF& screenSpacePoint, InputHandlerClient::ScrollInputType type) const
[email protected]94f206c12012-08-25 00:09:14252{
253 if (shouldScrollOnMainThread()) {
[email protected]96baf3e2012-10-22 23:09:55254 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed shouldScrollOnMainThread");
255 return InputHandlerClient::ScrollOnMainThread;
[email protected]94f206c12012-08-25 00:09:14256 }
257
[email protected]c8686a02012-11-27 08:29:00258 if (!screenSpaceTransform().IsInvertible()) {
[email protected]96baf3e2012-10-22 23:09:55259 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored nonInvertibleTransform");
260 return InputHandlerClient::ScrollIgnored;
[email protected]94f206c12012-08-25 00:09:14261 }
262
[email protected]d0f98362012-11-01 23:02:38263 if (!nonFastScrollableRegion().IsEmpty()) {
[email protected]94f206c12012-08-25 00:09:14264 bool clipped = false;
[email protected]c8686a02012-11-27 08:29:00265 gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(MathUtil::inverse(screenSpaceTransform()), screenSpacePoint, clipped);
[email protected]faf56352012-11-09 21:44:13266 gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContentSpace, 1 / contentsScaleX(), 1 / contentsScaleY());
[email protected]a90aa702012-11-07 04:48:24267 if (!clipped && nonFastScrollableRegion().Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpace))) {
[email protected]96baf3e2012-10-22 23:09:55268 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed nonFastScrollableRegion");
269 return InputHandlerClient::ScrollOnMainThread;
[email protected]94f206c12012-08-25 00:09:14270 }
271 }
272
[email protected]96baf3e2012-10-22 23:09:55273 if (type == InputHandlerClient::Wheel && haveWheelEventHandlers()) {
274 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed wheelEventHandlers");
275 return InputHandlerClient::ScrollOnMainThread;
[email protected]94f206c12012-08-25 00:09:14276 }
277
278 if (!scrollable()) {
[email protected]96baf3e2012-10-22 23:09:55279 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
280 return InputHandlerClient::ScrollIgnored;
[email protected]94f206c12012-08-25 00:09:14281 }
282
[email protected]96baf3e2012-10-22 23:09:55283 return InputHandlerClient::ScrollStarted;
[email protected]94f206c12012-08-25 00:09:14284}
285
[email protected]96baf3e2012-10-22 23:09:55286bool LayerImpl::drawCheckerboardForMissingTiles() const
[email protected]15dabb72012-10-04 20:07:29287{
[email protected]ff762fb2012-12-12 19:18:37288 return m_drawCheckerboardForMissingTiles && !layerTreeImpl()->settings().backgroundColorInsteadOfCheckerboard;
[email protected]15dabb72012-10-04 20:07:29289}
290
[email protected]aad0a0072012-11-01 18:15:58291gfx::Rect LayerImpl::layerRectToContentRect(const gfx::RectF& layerRect) const
[email protected]e1324f252012-09-24 21:39:15292{
[email protected]aad0a0072012-11-01 18:15:58293 gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), contentsScaleY());
[email protected]904e9132012-11-01 00:12:47294 // Intersect with content rect to avoid the extra pixel because for some
295 // values x and y, ceil((x / y) * y) may be x + 1.
[email protected]aad0a0072012-11-01 18:15:58296 contentRect.Intersect(gfx::Rect(gfx::Point(), contentBounds()));
297 return gfx::ToEnclosingRect(contentRect);
[email protected]e1324f252012-09-24 21:39:15298}
299
[email protected]96baf3e2012-10-22 23:09:55300std::string LayerImpl::indentString(int indent)
[email protected]94f206c12012-08-25 00:09:14301{
[email protected]515e8d232012-09-10 19:15:27302 std::string str;
[email protected]94f206c12012-08-25 00:09:14303 for (int i = 0; i != indent; ++i)
[email protected]515e8d232012-09-10 19:15:27304 str.append(" ");
305 return str;
[email protected]94f206c12012-08-25 00:09:14306}
307
[email protected]96baf3e2012-10-22 23:09:55308void LayerImpl::dumpLayerProperties(std::string* str, int indent) const
[email protected]94f206c12012-08-25 00:09:14309{
[email protected]515e8d232012-09-10 19:15:27310 std::string indentStr = indentString(indent);
311 str->append(indentStr);
312 base::StringAppendF(str, "layer ID: %d\n", m_layerId);
[email protected]94f206c12012-08-25 00:09:14313
[email protected]515e8d232012-09-10 19:15:27314 str->append(indentStr);
315 base::StringAppendF(str, "bounds: %d, %d\n", bounds().width(), bounds().height());
[email protected]94f206c12012-08-25 00:09:14316
[email protected]d76806f82012-12-05 21:41:50317 if (m_drawProperties.render_target) {
[email protected]515e8d232012-09-10 19:15:27318 str->append(indentStr);
[email protected]d76806f82012-12-05 21:41:50319 base::StringAppendF(str, "renderTarget: %d\n", m_drawProperties.render_target->m_layerId);
[email protected]94f206c12012-08-25 00:09:14320 }
321
[email protected]515e8d232012-09-10 19:15:27322 str->append(indentStr);
[email protected]9a5710432012-11-09 20:52:35323 base::StringAppendF(str, "position: %f, %f\n", m_position.x(), m_position.y());
324
325 str->append(indentStr);
326 base::StringAppendF(str, "contentsOpaque: %d\n", m_contentsOpaque);
327
328 str->append(indentStr);
[email protected]d76806f82012-12-05 21:41:50329 const gfx::Transform& transform = m_drawProperties.target_space_transform;
[email protected]515e8d232012-09-10 19:15:27330 base::StringAppendF(str, "drawTransform: %f, %f, %f, %f // %f, %f, %f, %f // %f, %f, %f, %f // %f, %f, %f, %f\n",
[email protected]d76806f82012-12-05 21:41:50331 transform.matrix().getDouble(0, 0), transform.matrix().getDouble(0, 1), transform.matrix().getDouble(0, 2), transform.matrix().getDouble(0, 3),
332 transform.matrix().getDouble(1, 0), transform.matrix().getDouble(1, 1), transform.matrix().getDouble(1, 2), transform.matrix().getDouble(1, 3),
333 transform.matrix().getDouble(2, 0), transform.matrix().getDouble(2, 1), transform.matrix().getDouble(2, 2), transform.matrix().getDouble(2, 3),
334 transform.matrix().getDouble(3, 0), transform.matrix().getDouble(3, 1), transform.matrix().getDouble(3, 2), transform.matrix().getDouble(3, 3));
[email protected]94f206c12012-08-25 00:09:14335
[email protected]515e8d232012-09-10 19:15:27336 str->append(indentStr);
337 base::StringAppendF(str, "drawsContent: %s\n", m_drawsContent ? "yes" : "no");
[email protected]94f206c12012-08-25 00:09:14338}
339
[email protected]96baf3e2012-10-22 23:09:55340std::string LayerImpl::layerTreeAsText() const
[email protected]94f206c12012-08-25 00:09:14341{
[email protected]515e8d232012-09-10 19:15:27342 std::string str;
343 dumpLayer(&str, 0);
344 return str;
[email protected]94f206c12012-08-25 00:09:14345}
346
[email protected]96baf3e2012-10-22 23:09:55347void LayerImpl::dumpLayer(std::string* str, int indent) const
[email protected]94f206c12012-08-25 00:09:14348{
[email protected]515e8d232012-09-10 19:15:27349 str->append(indentString(indent));
350 base::StringAppendF(str, "%s(%s)\n", layerTypeAsString(), m_debugName.data());
351 dumpLayerProperties(str, indent+2);
[email protected]94f206c12012-08-25 00:09:14352 if (m_replicaLayer) {
[email protected]515e8d232012-09-10 19:15:27353 str->append(indentString(indent+2));
354 str->append("Replica:\n");
355 m_replicaLayer->dumpLayer(str, indent+3);
[email protected]94f206c12012-08-25 00:09:14356 }
357 if (m_maskLayer) {
[email protected]515e8d232012-09-10 19:15:27358 str->append(indentString(indent+2));
359 str->append("Mask:\n");
360 m_maskLayer->dumpLayer(str, indent+3);
[email protected]94f206c12012-08-25 00:09:14361 }
362 for (size_t i = 0; i < m_children.size(); ++i)
[email protected]515e8d232012-09-10 19:15:27363 m_children[i]->dumpLayer(str, indent+1);
[email protected]94f206c12012-08-25 00:09:14364}
365
[email protected]4a23c374c2012-12-08 08:38:55366base::DictionaryValue* LayerImpl::layerTreeAsJson() const
367{
368 base::ListValue* list;
369 base::DictionaryValue* result = new base::DictionaryValue;
370 result->SetString("LayerType", layerTypeAsString());
371
372 list = new base::ListValue;
373 list->AppendInteger(bounds().width());
374 list->AppendInteger(bounds().height());
375 result->Set("Bounds", list);
376
377 list = new base::ListValue;
378 list->AppendDouble(m_position.x());
379 list->AppendDouble(m_position.y());
380 result->Set("Position", list);
381
382 const gfx::Transform& gfxTransform = m_drawProperties.target_space_transform;
383 double transform[16];
384 gfxTransform.matrix().asColMajord(transform);
385 list = new base::ListValue;
386 for (int i = 0; i < 16; ++i)
387 list->AppendDouble(transform[i]);
388 result->Set("DrawTransform", list);
389
390 result->SetBoolean("DrawsContent", m_drawsContent);
391 result->SetDouble("Opacity", opacity());
392
393 list = new base::ListValue;
394 for (size_t i = 0; i < m_children.size(); ++i)
395 list->Append(m_children[i]->layerTreeAsJson());
396 result->Set("Children", list);
397
398 return result;
399}
400
[email protected]96baf3e2012-10-22 23:09:55401void LayerImpl::setStackingOrderChanged(bool stackingOrderChanged)
[email protected]94f206c12012-08-25 00:09:14402{
403 // We don't need to store this flag; we only need to track that the change occurred.
404 if (stackingOrderChanged)
405 noteLayerPropertyChangedForSubtree();
406}
407
[email protected]96baf3e2012-10-22 23:09:55408bool LayerImpl::layerSurfacePropertyChanged() const
[email protected]94f206c12012-08-25 00:09:14409{
410 if (m_layerSurfacePropertyChanged)
411 return true;
412
413 // If this layer's surface property hasn't changed, we want to see if
414 // some layer above us has changed this property. This is done for the
415 // case when such parent layer does not draw content, and therefore will
416 // not be traversed by the damage tracker. We need to make sure that
417 // property change on such layer will be caught by its descendants.
[email protected]96baf3e2012-10-22 23:09:55418 LayerImpl* current = this->m_parent;
[email protected]d76806f82012-12-05 21:41:50419 while (current && !current->m_drawProperties.render_surface) {
[email protected]94f206c12012-08-25 00:09:14420 if (current->m_layerSurfacePropertyChanged)
421 return true;
422 current = current->m_parent;
423 }
424
425 return false;
426}
427
[email protected]0ede3bb2012-12-09 09:14:39428void LayerImpl::noteLayerSurfacePropertyChanged()
429{
430 m_layerSurfacePropertyChanged = true;
[email protected]ff762fb2012-12-12 19:18:37431 layerTreeImpl()->SetNeedsUpdateDrawProperties();
[email protected]0ede3bb2012-12-09 09:14:39432}
433
434void LayerImpl::noteLayerPropertyChanged()
[email protected]94f206c12012-08-25 00:09:14435{
436 m_layerPropertyChanged = true;
[email protected]ff762fb2012-12-12 19:18:37437 layerTreeImpl()->SetNeedsUpdateDrawProperties();
[email protected]0ede3bb2012-12-09 09:14:39438}
439
440void LayerImpl::noteLayerPropertyChangedForSubtree()
441{
442 noteLayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14443 noteLayerPropertyChangedForDescendants();
444}
445
[email protected]96baf3e2012-10-22 23:09:55446void LayerImpl::noteLayerPropertyChangedForDescendants()
[email protected]94f206c12012-08-25 00:09:14447{
[email protected]ff762fb2012-12-12 19:18:37448 layerTreeImpl()->SetNeedsUpdateDrawProperties();
[email protected]94f206c12012-08-25 00:09:14449 for (size_t i = 0; i < m_children.size(); ++i)
450 m_children[i]->noteLayerPropertyChangedForSubtree();
451}
452
[email protected]96baf3e2012-10-22 23:09:55453const char* LayerImpl::layerTypeAsString() const
[email protected]493067512012-09-19 23:34:10454{
[email protected]96baf3e2012-10-22 23:09:55455 return "Layer";
[email protected]493067512012-09-19 23:34:10456}
457
[email protected]96baf3e2012-10-22 23:09:55458void LayerImpl::resetAllChangeTrackingForSubtree()
[email protected]94f206c12012-08-25 00:09:14459{
460 m_layerPropertyChanged = false;
461 m_layerSurfacePropertyChanged = false;
462
[email protected]aad0a0072012-11-01 18:15:58463 m_updateRect = gfx::RectF();
[email protected]94f206c12012-08-25 00:09:14464
[email protected]d76806f82012-12-05 21:41:50465 if (m_drawProperties.render_surface)
466 m_drawProperties.render_surface->resetPropertyChangedFlag();
[email protected]94f206c12012-08-25 00:09:14467
468 if (m_maskLayer)
469 m_maskLayer->resetAllChangeTrackingForSubtree();
470
471 if (m_replicaLayer)
472 m_replicaLayer->resetAllChangeTrackingForSubtree(); // also resets the replica mask, if it exists.
473
474 for (size_t i = 0; i < m_children.size(); ++i)
475 m_children[i]->resetAllChangeTrackingForSubtree();
476}
477
[email protected]96baf3e2012-10-22 23:09:55478bool LayerImpl::layerIsAlwaysDamaged() const
[email protected]493067512012-09-19 23:34:10479{
480 return false;
481}
482
[email protected]96baf3e2012-10-22 23:09:55483int LayerImpl::id() const
[email protected]493067512012-09-19 23:34:10484{
485 return m_layerId;
486}
487
[email protected]de4afb5e2012-12-20 00:11:34488void LayerImpl::OnOpacityAnimated(float opacity)
[email protected]df1ec1a2012-12-08 17:01:18489{
490 setOpacity(opacity);
491}
492
[email protected]de4afb5e2012-12-20 00:11:34493void LayerImpl::OnTransformAnimated(const gfx::Transform& transform)
[email protected]df1ec1a2012-12-08 17:01:18494{
495 setTransform(transform);
496}
497
[email protected]aad0a0072012-11-01 18:15:58498void LayerImpl::setBounds(const gfx::Size& bounds)
[email protected]94f206c12012-08-25 00:09:14499{
500 if (m_bounds == bounds)
501 return;
502
503 m_bounds = bounds;
504
505 if (masksToBounds())
506 noteLayerPropertyChangedForSubtree();
507 else
[email protected]0ede3bb2012-12-09 09:14:39508 noteLayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14509}
510
[email protected]96baf3e2012-10-22 23:09:55511void LayerImpl::setMaskLayer(scoped_ptr<LayerImpl> maskLayer)
[email protected]94f206c12012-08-25 00:09:14512{
[email protected]361bc00d2012-12-14 07:03:24513 int newLayerId = maskLayer ? maskLayer->id() : -1;
[email protected]94f206c12012-08-25 00:09:14514
[email protected]361bc00d2012-12-14 07:03:24515 if (maskLayer) {
516 DCHECK_EQ(layerTreeImpl(), maskLayer->layerTreeImpl());
517 DCHECK_NE(newLayerId, m_maskLayerId);
518 } else if (newLayerId == m_maskLayerId)
[email protected]94f206c12012-08-25 00:09:14519 return;
520
[email protected]361bc00d2012-12-14 07:03:24521 m_maskLayer = maskLayer.Pass();
[email protected]94f206c12012-08-25 00:09:14522 m_maskLayerId = newLayerId;
523 noteLayerPropertyChangedForSubtree();
524}
525
[email protected]361bc00d2012-12-14 07:03:24526scoped_ptr<LayerImpl> LayerImpl::takeMaskLayer()
527{
528 m_maskLayerId = -1;
529 return m_maskLayer.Pass();
530}
531
[email protected]96baf3e2012-10-22 23:09:55532void LayerImpl::setReplicaLayer(scoped_ptr<LayerImpl> replicaLayer)
[email protected]94f206c12012-08-25 00:09:14533{
[email protected]361bc00d2012-12-14 07:03:24534 int newLayerId = replicaLayer ? replicaLayer->id() : -1;
[email protected]94f206c12012-08-25 00:09:14535
[email protected]361bc00d2012-12-14 07:03:24536 if (replicaLayer) {
537 DCHECK_EQ(layerTreeImpl(), replicaLayer->layerTreeImpl());
538 DCHECK_NE(newLayerId, m_replicaLayerId);
539 } else if (newLayerId == m_replicaLayerId)
[email protected]94f206c12012-08-25 00:09:14540 return;
541
[email protected]361bc00d2012-12-14 07:03:24542 m_replicaLayer = replicaLayer.Pass();
[email protected]94f206c12012-08-25 00:09:14543 m_replicaLayerId = newLayerId;
544 noteLayerPropertyChangedForSubtree();
545}
546
[email protected]361bc00d2012-12-14 07:03:24547scoped_ptr<LayerImpl> LayerImpl::takeReplicaLayer()
548{
549 m_replicaLayerId = -1;
550 return m_replicaLayer.Pass();
551}
552
[email protected]96baf3e2012-10-22 23:09:55553void LayerImpl::setDrawsContent(bool drawsContent)
[email protected]94f206c12012-08-25 00:09:14554{
555 if (m_drawsContent == drawsContent)
556 return;
557
558 m_drawsContent = drawsContent;
[email protected]0ede3bb2012-12-09 09:14:39559 noteLayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14560}
561
[email protected]aad0a0072012-11-01 18:15:58562void LayerImpl::setAnchorPoint(const gfx::PointF& anchorPoint)
[email protected]94f206c12012-08-25 00:09:14563{
564 if (m_anchorPoint == anchorPoint)
565 return;
566
567 m_anchorPoint = anchorPoint;
568 noteLayerPropertyChangedForSubtree();
569}
570
[email protected]96baf3e2012-10-22 23:09:55571void LayerImpl::setAnchorPointZ(float anchorPointZ)
[email protected]94f206c12012-08-25 00:09:14572{
573 if (m_anchorPointZ == anchorPointZ)
574 return;
575
576 m_anchorPointZ = anchorPointZ;
577 noteLayerPropertyChangedForSubtree();
578}
579
[email protected]96baf3e2012-10-22 23:09:55580void LayerImpl::setBackgroundColor(SkColor backgroundColor)
[email protected]94f206c12012-08-25 00:09:14581{
582 if (m_backgroundColor == backgroundColor)
583 return;
584
585 m_backgroundColor = backgroundColor;
[email protected]0ede3bb2012-12-09 09:14:39586 noteLayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14587}
588
[email protected]96baf3e2012-10-22 23:09:55589void LayerImpl::setFilters(const WebKit::WebFilterOperations& filters)
[email protected]94f206c12012-08-25 00:09:14590{
591 if (m_filters == filters)
592 return;
593
[email protected]589029c2012-10-23 18:32:54594 DCHECK(!m_filter);
[email protected]94f206c12012-08-25 00:09:14595 m_filters = filters;
596 noteLayerPropertyChangedForSubtree();
597}
598
[email protected]96baf3e2012-10-22 23:09:55599void LayerImpl::setBackgroundFilters(const WebKit::WebFilterOperations& backgroundFilters)
[email protected]94f206c12012-08-25 00:09:14600{
601 if (m_backgroundFilters == backgroundFilters)
602 return;
603
604 m_backgroundFilters = backgroundFilters;
[email protected]0ede3bb2012-12-09 09:14:39605 noteLayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14606}
607
[email protected]1940c4e2012-12-04 05:08:15608void LayerImpl::setFilter(const skia::RefPtr<SkImageFilter>& filter)
[email protected]4000abf2012-10-23 04:45:45609{
[email protected]1940c4e2012-12-04 05:08:15610 if (m_filter.get() == filter.get())
[email protected]4000abf2012-10-23 04:45:45611 return;
612
[email protected]589029c2012-10-23 18:32:54613 DCHECK(m_filters.isEmpty());
[email protected]1940c4e2012-12-04 05:08:15614 m_filter = filter;
[email protected]4000abf2012-10-23 04:45:45615 noteLayerPropertyChangedForSubtree();
616}
617
[email protected]96baf3e2012-10-22 23:09:55618void LayerImpl::setMasksToBounds(bool masksToBounds)
[email protected]94f206c12012-08-25 00:09:14619{
620 if (m_masksToBounds == masksToBounds)
621 return;
622
623 m_masksToBounds = masksToBounds;
624 noteLayerPropertyChangedForSubtree();
625}
626
[email protected]96baf3e2012-10-22 23:09:55627void LayerImpl::setContentsOpaque(bool opaque)
[email protected]94f206c12012-08-25 00:09:14628{
[email protected]048634c2012-10-02 22:33:14629 if (m_contentsOpaque == opaque)
[email protected]94f206c12012-08-25 00:09:14630 return;
631
[email protected]048634c2012-10-02 22:33:14632 m_contentsOpaque = opaque;
[email protected]94f206c12012-08-25 00:09:14633 noteLayerPropertyChangedForSubtree();
634}
635
[email protected]96baf3e2012-10-22 23:09:55636void LayerImpl::setOpacity(float opacity)
[email protected]94f206c12012-08-25 00:09:14637{
[email protected]df1ec1a2012-12-08 17:01:18638 if (m_opacity == opacity)
[email protected]94f206c12012-08-25 00:09:14639 return;
[email protected]94f206c12012-08-25 00:09:14640
[email protected]df1ec1a2012-12-08 17:01:18641 m_opacity = opacity;
[email protected]0ede3bb2012-12-09 09:14:39642 noteLayerSurfacePropertyChanged();
[email protected]0a9fd4d2012-12-07 07:37:08643}
644
[email protected]de4afb5e2012-12-20 00:11:34645float LayerImpl::opacity() const
646{
647 return m_opacity;
648}
649
[email protected]96baf3e2012-10-22 23:09:55650bool LayerImpl::opacityIsAnimating() const
[email protected]94f206c12012-08-25 00:09:14651{
[email protected]96baf3e2012-10-22 23:09:55652 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opacity);
[email protected]94f206c12012-08-25 00:09:14653}
654
[email protected]aad0a0072012-11-01 18:15:58655void LayerImpl::setPosition(const gfx::PointF& position)
[email protected]94f206c12012-08-25 00:09:14656{
657 if (m_position == position)
658 return;
659
660 m_position = position;
661 noteLayerPropertyChangedForSubtree();
662}
663
[email protected]96baf3e2012-10-22 23:09:55664void LayerImpl::setPreserves3D(bool preserves3D)
[email protected]94f206c12012-08-25 00:09:14665{
666 if (m_preserves3D == preserves3D)
667 return;
668
669 m_preserves3D = preserves3D;
670 noteLayerPropertyChangedForSubtree();
671}
672
[email protected]c8686a02012-11-27 08:29:00673void LayerImpl::setSublayerTransform(const gfx::Transform& sublayerTransform)
[email protected]94f206c12012-08-25 00:09:14674{
675 if (m_sublayerTransform == sublayerTransform)
676 return;
677
678 m_sublayerTransform = sublayerTransform;
679 // sublayer transform does not affect the current layer; it affects only its children.
680 noteLayerPropertyChangedForDescendants();
681}
682
[email protected]c8686a02012-11-27 08:29:00683void LayerImpl::setTransform(const gfx::Transform& transform)
[email protected]94f206c12012-08-25 00:09:14684{
[email protected]df1ec1a2012-12-08 17:01:18685 if (m_transform == transform)
[email protected]94f206c12012-08-25 00:09:14686 return;
[email protected]94f206c12012-08-25 00:09:14687
[email protected]df1ec1a2012-12-08 17:01:18688 m_transform = transform;
[email protected]0ede3bb2012-12-09 09:14:39689 noteLayerSurfacePropertyChanged();
[email protected]0a9fd4d2012-12-07 07:37:08690}
691
[email protected]de4afb5e2012-12-20 00:11:34692const gfx::Transform& LayerImpl::transform() const
693{
694 return m_transform;
695}
696
[email protected]96baf3e2012-10-22 23:09:55697bool LayerImpl::transformIsAnimating() const
[email protected]94f206c12012-08-25 00:09:14698{
[email protected]96baf3e2012-10-22 23:09:55699 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Transform);
[email protected]94f206c12012-08-25 00:09:14700}
701
[email protected]aad0a0072012-11-01 18:15:58702void LayerImpl::setContentBounds(const gfx::Size& contentBounds)
[email protected]94f206c12012-08-25 00:09:14703{
[email protected]344e58d02012-12-16 04:52:53704 if (this->contentBounds() == contentBounds)
[email protected]94f206c12012-08-25 00:09:14705 return;
706
[email protected]344e58d02012-12-16 04:52:53707 m_drawProperties.content_bounds = contentBounds;
[email protected]0ede3bb2012-12-09 09:14:39708 noteLayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14709}
710
[email protected]904e9132012-11-01 00:12:47711void LayerImpl::setContentsScale(float contentsScaleX, float contentsScaleY)
712{
[email protected]344e58d02012-12-16 04:52:53713 if (this->contentsScaleX() == contentsScaleX && this->contentsScaleY() == contentsScaleY)
[email protected]904e9132012-11-01 00:12:47714 return;
715
[email protected]344e58d02012-12-16 04:52:53716 m_drawProperties.contents_scale_x = contentsScaleX;
717 m_drawProperties.contents_scale_y = contentsScaleY;
[email protected]0ede3bb2012-12-09 09:14:39718 noteLayerPropertyChanged();
[email protected]904e9132012-11-01 00:12:47719}
720
[email protected]c9c1ebe2012-11-05 20:46:13721void LayerImpl::setScrollOffset(gfx::Vector2d scrollOffset)
[email protected]94f206c12012-08-25 00:09:14722{
[email protected]c9c1ebe2012-11-05 20:46:13723 if (m_scrollOffset == scrollOffset)
[email protected]94f206c12012-08-25 00:09:14724 return;
725
[email protected]c9c1ebe2012-11-05 20:46:13726 m_scrollOffset = scrollOffset;
[email protected]94f206c12012-08-25 00:09:14727 noteLayerPropertyChangedForSubtree();
728}
729
[email protected]c9c1ebe2012-11-05 20:46:13730void LayerImpl::setScrollDelta(const gfx::Vector2dF& scrollDelta)
[email protected]94f206c12012-08-25 00:09:14731{
732 if (m_scrollDelta == scrollDelta)
733 return;
734
735 m_scrollDelta = scrollDelta;
736 noteLayerPropertyChangedForSubtree();
737}
738
[email protected]c8686a02012-11-27 08:29:00739void LayerImpl::setImplTransform(const gfx::Transform& transform)
[email protected]94f206c12012-08-25 00:09:14740{
[email protected]1c0c9bc2012-10-08 22:41:48741 if (m_implTransform == transform)
[email protected]94f206c12012-08-25 00:09:14742 return;
743
[email protected]1c0c9bc2012-10-08 22:41:48744 m_implTransform = transform;
[email protected]94f206c12012-08-25 00:09:14745 noteLayerPropertyChangedForSubtree();
746}
747
[email protected]96baf3e2012-10-22 23:09:55748void LayerImpl::setDoubleSided(bool doubleSided)
[email protected]94f206c12012-08-25 00:09:14749{
750 if (m_doubleSided == doubleSided)
751 return;
752
753 m_doubleSided = doubleSided;
754 noteLayerPropertyChangedForSubtree();
755}
756
[email protected]96baf3e2012-10-22 23:09:55757Region LayerImpl::visibleContentOpaqueRegion() const
[email protected]94f206c12012-08-25 00:09:14758{
[email protected]048634c2012-10-02 22:33:14759 if (contentsOpaque())
[email protected]d0f98362012-11-01 23:02:38760 return visibleContentRect();
[email protected]94f206c12012-08-25 00:09:14761 return Region();
762}
763
[email protected]3be2171d2012-12-06 06:13:20764void LayerImpl::didLoseOutputSurface()
[email protected]94f206c12012-08-25 00:09:14765{
766}
767
[email protected]c9c1ebe2012-11-05 20:46:13768void LayerImpl::setMaxScrollOffset(gfx::Vector2d maxScrollOffset)
[email protected]94f206c12012-08-25 00:09:14769{
[email protected]0ede3bb2012-12-09 09:14:39770 if (m_maxScrollOffset == maxScrollOffset)
771 return;
[email protected]c9c1ebe2012-11-05 20:46:13772 m_maxScrollOffset = maxScrollOffset;
[email protected]94f206c12012-08-25 00:09:14773
[email protected]ff762fb2012-12-12 19:18:37774 layerTreeImpl()->SetNeedsUpdateDrawProperties();
[email protected]0ede3bb2012-12-09 09:14:39775
[email protected]94f206c12012-08-25 00:09:14776 if (!m_scrollbarAnimationController)
777 return;
778 m_scrollbarAnimationController->updateScrollOffset(this);
779}
780
[email protected]da3a2952012-11-21 04:19:52781ScrollbarLayerImpl* LayerImpl::horizontalScrollbarLayer()
782{
783 return m_scrollbarAnimationController ? m_scrollbarAnimationController->horizontalScrollbarLayer() : 0;
784}
785
786const ScrollbarLayerImpl* LayerImpl::horizontalScrollbarLayer() const
[email protected]94f206c12012-08-25 00:09:14787{
788 return m_scrollbarAnimationController ? m_scrollbarAnimationController->horizontalScrollbarLayer() : 0;
789}
790
[email protected]96baf3e2012-10-22 23:09:55791void LayerImpl::setHorizontalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer)
[email protected]94f206c12012-08-25 00:09:14792{
793 if (!m_scrollbarAnimationController)
[email protected]96baf3e2012-10-22 23:09:55794 m_scrollbarAnimationController = ScrollbarAnimationController::create(this);
[email protected]94f206c12012-08-25 00:09:14795 m_scrollbarAnimationController->setHorizontalScrollbarLayer(scrollbarLayer);
796 m_scrollbarAnimationController->updateScrollOffset(this);
797}
798
[email protected]da3a2952012-11-21 04:19:52799ScrollbarLayerImpl* LayerImpl::verticalScrollbarLayer()
800{
801 return m_scrollbarAnimationController ? m_scrollbarAnimationController->verticalScrollbarLayer() : 0;
802}
803
804const ScrollbarLayerImpl* LayerImpl::verticalScrollbarLayer() const
[email protected]94f206c12012-08-25 00:09:14805{
806 return m_scrollbarAnimationController ? m_scrollbarAnimationController->verticalScrollbarLayer() : 0;
807}
808
[email protected]96baf3e2012-10-22 23:09:55809void LayerImpl::setVerticalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer)
[email protected]94f206c12012-08-25 00:09:14810{
811 if (!m_scrollbarAnimationController)
[email protected]96baf3e2012-10-22 23:09:55812 m_scrollbarAnimationController = ScrollbarAnimationController::create(this);
[email protected]94f206c12012-08-25 00:09:14813 m_scrollbarAnimationController->setVerticalScrollbarLayer(scrollbarLayer);
814 m_scrollbarAnimationController->updateScrollOffset(this);
815}
816
[email protected]bc5e77c2012-11-05 20:00:49817} // namespace cc