1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
|
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/layers/layer_impl.h"
#include <algorithm>
#include "base/memory/raw_ptr.h"
#include "cc/layers/painted_scrollbar_layer_impl.h"
#include "cc/layers/solid_color_scrollbar_layer_impl.h"
#include "cc/paint/filter_operation.h"
#include "cc/paint/filter_operations.h"
#include "cc/test/animation_test_common.h"
#include "cc/test/layer_tree_impl_test_base.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/tree_synchronizer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/test/geometry_util.h"
namespace cc {
namespace {
#define EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(code_to_test) \
root->layer_tree_impl()->ResetAllChangeTracking(); \
code_to_test; \
EXPECT_FALSE(root->LayerPropertyChanged()); \
EXPECT_FALSE(child->LayerPropertyChanged()); \
EXPECT_FALSE(grand_child->LayerPropertyChanged());
#define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \
root->layer_tree_impl()->ResetAllChangeTracking(); \
code_to_test; \
EXPECT_TRUE(root->LayerPropertyChanged()); \
EXPECT_TRUE(root->LayerPropertyChangedFromPropertyTrees()); \
EXPECT_FALSE(root->LayerPropertyChangedNotFromPropertyTrees()); \
EXPECT_TRUE(child->LayerPropertyChanged()); \
EXPECT_TRUE(child->LayerPropertyChangedFromPropertyTrees()); \
EXPECT_FALSE(child->LayerPropertyChangedNotFromPropertyTrees()); \
EXPECT_TRUE(grand_child->LayerPropertyChanged()); \
EXPECT_TRUE(grand_child->LayerPropertyChangedFromPropertyTrees()); \
EXPECT_FALSE(grand_child->LayerPropertyChangedNotFromPropertyTrees());
#define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(code_to_test) \
root->layer_tree_impl()->ResetAllChangeTracking(); \
root->layer_tree_impl()->property_trees()->set_full_tree_damaged(false); \
code_to_test; \
EXPECT_TRUE(root->LayerPropertyChanged()); \
EXPECT_FALSE(root->LayerPropertyChangedFromPropertyTrees()); \
EXPECT_TRUE(root->LayerPropertyChangedNotFromPropertyTrees()); \
EXPECT_FALSE(child->LayerPropertyChanged()); \
EXPECT_FALSE(grand_child->LayerPropertyChanged());
#define VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(code_to_test) \
root->layer_tree_impl()->ResetAllChangeTracking(); \
host_impl()->ForcePrepareToDraw(); \
EXPECT_FALSE(host_impl()->active_tree()->needs_update_draw_properties()); \
code_to_test; \
EXPECT_TRUE(host_impl()->active_tree()->needs_update_draw_properties());
#define VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(code_to_test) \
root->layer_tree_impl()->ResetAllChangeTracking(); \
host_impl()->ForcePrepareToDraw(); \
EXPECT_FALSE(host_impl()->active_tree()->needs_update_draw_properties()); \
code_to_test; \
EXPECT_FALSE(host_impl()->active_tree()->needs_update_draw_properties());
class LayerImplTest : public LayerTreeImplTestBase, public ::testing::Test {
public:
using LayerTreeImplTestBase::LayerTreeImplTestBase;
};
TEST_F(LayerImplTest, VerifyPendingLayerChangesAreTrackedProperly) {
//
// This test checks that LayerPropertyChanged() has the correct behavior.
//
// The constructor on this will fake that we are on the correct thread.
// Create a simple LayerImpl tree:
host_impl()->CreatePendingTree();
LayerImpl* root = EnsureRootLayerInPendingTree();
CreateClipNode(root);
root->layer_tree_impl()->ResetAllChangeTracking();
LayerImpl* child = AddLayerInPendingTree<LayerImpl>();
CopyProperties(root, child);
LayerImpl* grand_child = AddLayerInPendingTree<LayerImpl>();
CopyProperties(child, grand_child);
UpdatePendingTreeDrawProperties();
// Creating children is an internal operation and should not mark layers as
// changed.
EXPECT_FALSE(root->LayerPropertyChanged());
EXPECT_FALSE(child->LayerPropertyChanged());
EXPECT_FALSE(grand_child->LayerPropertyChanged());
float arbitrary_number = 0.352f;
gfx::Size arbitrary_size = gfx::Size(111, 222);
gfx::Point arbitrary_point = gfx::Point(333, 444);
gfx::Rect arbitrary_rect = gfx::Rect(arbitrary_point, arbitrary_size);
SkColor4f arbitrary_color{0.1f, 0.2f, 0.3f, 1.0f};
gfx::Transform arbitrary_transform;
arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f);
FilterOperations arbitrary_filters;
arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
// These properties are internal, and should not be considered "change" when
// they are used.
EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
root->UnionUpdateRect(arbitrary_rect));
EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetBounds(arbitrary_size));
UpdatePendingTreeDrawProperties();
// Changing these properties affects the entire subtree of layers.
EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
host_impl()->pending_tree()->SetFilterMutated(root->element_id(),
arbitrary_filters));
EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
host_impl()->pending_tree()->SetFilterMutated(root->element_id(),
FilterOperations()));
EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
host_impl()->pending_tree()->SetOpacityMutated(root->element_id(),
arbitrary_number));
EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
host_impl()->pending_tree()->SetTransformMutated(root->element_id(),
arbitrary_transform));
// Changing these properties only affects the layer itself.
EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetDrawsContent(true));
EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(
root->SetBackgroundColor(arbitrary_color));
// Changing these properties does not cause the layer to be marked as changed
// but does cause the layer to need to push properties.
EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetElementId(ElementId(2)));
// After setting all these properties already, setting to the exact same
// values again should not cause any change.
EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentsOpaque(true));
EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetDrawsContent(true));
EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetBounds(root->bounds()));
}
TEST_F(LayerImplTest, VerifyNeedsUpdateDrawProperties) {
LayerImpl* root = root_layer();
LayerImpl* layer = AddLayerInActiveTree<LayerImpl>();
layer->SetBounds(gfx::Size(100, 100));
LayerImpl* layer2 = AddLayerInActiveTree<LayerImpl>();
SetElementIdsForTesting();
CopyProperties(root, layer);
CreateTransformNode(layer);
CreateScrollNode(layer, gfx::Size(1, 1));
CopyProperties(root, layer2);
DCHECK(host_impl()->CanDraw());
UpdateActiveTreeDrawProperties();
float arbitrary_number = 0.352f;
gfx::Size arbitrary_size = gfx::Size(111, 222);
gfx::Vector2d arbitrary_vector2d = gfx::Vector2d(111, 222);
gfx::PointF arbitrary_scroll_offset(
gfx::PointAtOffsetFromOrigin(arbitrary_vector2d));
gfx::Size large_size = gfx::Size(1000, 1000);
SkColor4f arbitrary_color{0.1f, 0.2f, 0.3f, 1.0f};
gfx::Transform arbitrary_transform;
arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f);
FilterOperations arbitrary_filters;
arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
// Set layer to draw content so that their draw property by property trees is
// verified.
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetDrawsContent(true));
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer2->SetDrawsContent(true));
// Create a render surface, because we must have a render surface if we have
// filters.
CreateEffectNode(layer).render_surface_reason = RenderSurfaceReason::kTest;
UpdateActiveTreeDrawProperties();
// Related filter functions.
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
host_impl()->active_tree()->SetFilterMutated(root->element_id(),
arbitrary_filters));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
host_impl()->active_tree()->SetFilterMutated(root->element_id(),
arbitrary_filters));
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
host_impl()->active_tree()->SetFilterMutated(root->element_id(),
FilterOperations()));
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
host_impl()->active_tree()->SetFilterMutated(root->element_id(),
arbitrary_filters));
// Related scrolling functions.
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size));
host_impl()->active_tree()->set_needs_update_draw_properties();
UpdateActiveTreeDrawProperties();
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(arbitrary_vector2d));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(gfx::Vector2d()));
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->layer_tree_impl()->DidUpdateScrollOffset(
layer->element_id(), /*pushed_from_main_or_pending_tree=*/false));
layer->layer_tree_impl()
->property_trees()
->scroll_tree_mutable()
.SetScrollOffsetDeltaForTesting(layer->element_id(), gfx::Vector2dF());
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->SetCurrentScrollOffset(arbitrary_scroll_offset));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->SetCurrentScrollOffset(arbitrary_scroll_offset));
// Unrelated functions, always set to new values, always set needs update.
host_impl()->active_tree()->set_needs_update_draw_properties();
UpdateActiveTreeDrawProperties();
CreateClipNode(layer);
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true);
layer->NoteLayerPropertyChanged());
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->SetBackgroundColor(arbitrary_color));
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
host_impl()->active_tree()->SetOpacityMutated(layer->element_id(),
arbitrary_number));
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
host_impl()->active_tree()->SetTransformMutated(layer->element_id(),
arbitrary_transform));
VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size);
layer->NoteLayerPropertyChanged());
// Unrelated functions, set to the same values, no needs update.
GetEffectNode(layer)->filters = arbitrary_filters;
UpdateActiveTreeDrawProperties();
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
host_impl()->active_tree()->SetFilterMutated(layer->element_id(),
arbitrary_filters));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetDrawsContent(true));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
layer->SetBackgroundColor(arbitrary_color));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetElementId(ElementId(2)));
}
TEST_F(LayerImplTest, PerspectiveTransformHasReasonableScale) {
LayerImpl* layer = root_layer();
layer->SetBounds(gfx::Size(10, 10));
layer->set_contributes_to_drawn_render_surface(true);
// Ensure that we are close to the maximum scale for the matrix.
{
gfx::Transform transform;
transform.Scale(10.2f, 15.1f);
transform.ApplyPerspectiveDepth(10);
transform.RotateAboutXAxis(15.0f);
layer->draw_properties().screen_space_transform = transform;
ASSERT_TRUE(layer->ScreenSpaceTransform().HasPerspective());
EXPECT_EQ(gfx::Vector2dF(15.f, 15.f), layer->GetIdealContentsScale());
}
// Ensure that we don't fall below the device scale factor.
{
gfx::Transform transform;
transform.Scale(0.1f, 0.2f);
transform.ApplyPerspectiveDepth(10);
transform.RotateAboutXAxis(15.0f);
layer->draw_properties().screen_space_transform = transform;
ASSERT_TRUE(layer->ScreenSpaceTransform().HasPerspective());
EXPECT_EQ(gfx::Vector2dF(1.f, 1.f), layer->GetIdealContentsScale());
}
// Ensure that large scales don't end up extremely large.
{
gfx::Transform transform;
transform.Scale(10000.1f, 10000.2f);
transform.ApplyPerspectiveDepth(10);
transform.RotateAboutXAxis(15.0f);
layer->draw_properties().screen_space_transform = transform;
ASSERT_TRUE(layer->ScreenSpaceTransform().HasPerspective());
EXPECT_EQ(gfx::Vector2dF(127.f, 127.f), layer->GetIdealContentsScale());
}
// Test case from crbug.com/766021.
{
auto transform = gfx::Transform::RowMajor(
-0.9397f, -0.7019f, 0.2796f, 2383.4521f, // row 1
-0.0038f, 0.0785f, 1.0613f, 1876.4553f, // row 2
-0.0835f, 0.9081f, -0.4105f, -2208.3035f, // row 3
0.0001f, -0.0008f, 0.0003f, 2.8435f); // row 4
layer->draw_properties().screen_space_transform = transform;
ASSERT_TRUE(layer->ScreenSpaceTransform().HasPerspective());
EXPECT_EQ(gfx::Vector2dF(1.f, 1.f), layer->GetIdealContentsScale());
}
}
TEST_F(LayerImplTest, GetDamageReasons) {
LayerImpl* root = root_layer();
TransformNode& transform_node = CreateTransformNode(root);
root->layer_tree_impl()->ResetAllChangeTracking();
EXPECT_TRUE(root->GetDamageReasons().empty());
root->SetBounds(gfx::Size(10, 10));
EXPECT_EQ(root->GetDamageReasons(),
DamageReasonSet{DamageReason::kUntracked});
root->layer_tree_impl()->ResetAllChangeTracking();
EXPECT_TRUE(root->GetDamageReasons().empty());
root->UnionUpdateRect(gfx::Rect(10, 10));
EXPECT_EQ(root->GetDamageReasons(),
DamageReasonSet{DamageReason::kUntracked});
root->layer_tree_impl()->ResetAllChangeTracking();
EXPECT_TRUE(root->GetDamageReasons().empty());
transform_node.SetScrollOffset(gfx::PointF(1, 1),
DamageReason::kCompositorScroll);
EXPECT_EQ(root->GetDamageReasons(),
DamageReasonSet{DamageReason::kCompositorScroll});
}
class LayerImplScrollTest : public LayerImplTest {
public:
LayerImplScrollTest()
: LayerImplScrollTest(CommitToPendingTreeLayerListSettings()) {}
explicit LayerImplScrollTest(const LayerTreeSettings& settings)
: LayerImplTest(settings) {
LayerImpl* root = root_layer();
root->SetBounds(gfx::Size(1, 1));
layer_ = AddLayerInActiveTree<LayerImpl>();
SetElementIdsForTesting();
// Set the max scroll offset by noting that the root layer has bounds (1,1),
// thus whatever bounds are set for the layer will be the max scroll
// offset plus 1 in each direction.
layer_->SetBounds(gfx::Size(51, 81));
CopyProperties(root, layer_);
CreateTransformNode(layer_);
CreateScrollNode(layer_, gfx::Size(1, 1));
UpdateActiveTreeDrawProperties();
}
LayerImpl* layer() { return layer_; }
ScrollTree* scroll_tree(LayerImpl* layer_impl) {
return &layer_impl->layer_tree_impl()
->property_trees()
->scroll_tree_mutable();
}
private:
raw_ptr<LayerImpl> layer_;
};
class CommitToActiveTreeLayerImplScrollTest : public LayerImplScrollTest {
public:
CommitToActiveTreeLayerImplScrollTest()
: LayerImplScrollTest(CommitToActiveTreeLayerListSettings()) {}
};
TEST_F(CommitToActiveTreeLayerImplScrollTest, ScrollByWithZeroOffset) {
// Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll
// offset is bounded by the range [0, max scroll offset].
EXPECT_POINTF_EQ(gfx::PointF(), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(layer()));
layer()->ScrollBy(gfx::Vector2dF(-100, 100));
EXPECT_POINTF_EQ(gfx::PointF(0, 80), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointAtOffsetFromOrigin(ScrollDelta(layer())),
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
layer()->ScrollBy(gfx::Vector2dF(100, -100));
EXPECT_POINTF_EQ(gfx::PointF(50, 0), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointAtOffsetFromOrigin(ScrollDelta(layer())),
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(gfx::PointF(),
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
}
TEST_F(CommitToActiveTreeLayerImplScrollTest, ScrollByWithNonZeroOffset) {
gfx::PointF scroll_offset(10, 5);
scroll_tree(layer())->UpdateScrollOffsetBaseForTesting(layer()->element_id(),
scroll_offset);
EXPECT_POINTF_EQ(scroll_offset, CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(), ScrollDelta(layer()));
layer()->ScrollBy(gfx::Vector2dF(-100, 100));
EXPECT_POINTF_EQ(gfx::PointF(0, 80), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset + ScrollDelta(layer()),
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
layer()->ScrollBy(gfx::Vector2dF(100, -100));
EXPECT_POINTF_EQ(gfx::PointF(50, 0), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset + ScrollDelta(layer()),
CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
}
TEST_F(CommitToActiveTreeLayerImplScrollTest, ApplySentScrollsNoListener) {
gfx::PointF scroll_offset(10, 5);
gfx::Vector2dF scroll_delta(20.5f, 8.5f);
gfx::Vector2d sent_scroll_delta(12, -3);
scroll_tree(layer())->UpdateScrollOffsetBaseForTesting(layer()->element_id(),
scroll_offset);
layer()->ScrollBy(sent_scroll_delta);
scroll_tree(layer())->CollectScrollDeltasForTesting();
layer()->SetCurrentScrollOffset(scroll_offset + scroll_delta);
EXPECT_POINTF_EQ(scroll_offset + scroll_delta, CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_delta, ScrollDelta(layer()));
EXPECT_POINTF_EQ(scroll_offset,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
scroll_tree(layer())->ApplySentScrollDeltasFromAbortedCommit(
/* next_bmf */ false, /* main_frame_applied_deltas */ true);
EXPECT_POINTF_EQ(scroll_offset + scroll_delta, CurrentScrollOffset(layer()));
EXPECT_VECTOR2DF_EQ(scroll_delta - sent_scroll_delta, ScrollDelta(layer()));
EXPECT_POINTF_EQ(scroll_offset + sent_scroll_delta,
scroll_tree(layer())->GetScrollOffsetBaseForTesting(
layer()->element_id()));
}
TEST_F(CommitToActiveTreeLayerImplScrollTest, ScrollUserUnscrollableLayer) {
gfx::PointF scroll_offset(10, 5);
gfx::Vector2dF scroll_delta(20.5f, 8.5f);
GetScrollNode(layer())->user_scrollable_vertical = false;
UpdateDrawProperties(layer()->layer_tree_impl());
scroll_tree(layer())->UpdateScrollOffsetBaseForTesting(layer()->element_id(),
scroll_offset);
gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta);
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 8.5f), unscrolled);
EXPECT_POINTF_EQ(gfx::PointF(30.5f, 5), CurrentScrollOffset(layer()));
}
// |LayerImpl::all_touch_action_regions_| is a cache of all regions on
// |LayerImpl::touch_action_region_| and must be invalidated on changes.
TEST_F(LayerImplScrollTest, TouchActionRegionCacheInvalidation) {
host_impl()->CreatePendingTree();
std::unique_ptr<LayerImpl> pending_layer =
LayerImpl::Create(host_impl()->pending_tree(), 2);
pending_layer->SetElementId(
LayerIdToElementIdForTesting(pending_layer->id()));
TouchActionRegion region;
region.Union(TouchAction::kNone, gfx::Rect(0, 0, 50, 50));
pending_layer->SetTouchActionRegion(region);
// The values for GetAllTouchActionRegions should be correct on both layers.
// Note that querying GetAllTouchActionRegions will update the cached value
// in |LayerImpl::all_touch_action_regions_|.
EXPECT_EQ(pending_layer->GetAllTouchActionRegions(), region.GetAllRegions());
EXPECT_EQ(layer()->GetAllTouchActionRegions(), Region());
pending_layer->PushPropertiesTo(layer());
// After pushing properties, the value for GetAllTouchActionRegions should
// not be stale.
EXPECT_EQ(pending_layer->GetAllTouchActionRegions(), region.GetAllRegions());
EXPECT_EQ(layer()->GetAllTouchActionRegions(), region.GetAllRegions());
}
TEST_F(LayerImplScrollTest, PushPropertiesToMirrorsCurrentScrollOffset) {
gfx::PointF scroll_offset(10, 5);
gfx::Vector2dF scroll_delta(12, 18);
host_impl()->CreatePendingTree();
scroll_tree(layer())->UpdateScrollOffsetBaseForTesting(layer()->element_id(),
scroll_offset);
gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta);
EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 0), unscrolled);
EXPECT_POINTF_EQ(gfx::PointF(22, 23), CurrentScrollOffset(layer()));
scroll_tree(layer())->CollectScrollDeltasForTesting();
std::unique_ptr<LayerImpl> pending_layer =
LayerImpl::Create(host_impl()->sync_tree(), layer()->id());
pending_layer->SetElementId(
LayerIdToElementIdForTesting(pending_layer->id()));
scroll_tree(pending_layer.get())
->UpdateScrollOffsetBaseForTesting(pending_layer->element_id(),
CurrentScrollOffset(layer()));
pending_layer->PushPropertiesTo(layer());
EXPECT_POINTF_EQ(gfx::PointF(22, 23), CurrentScrollOffset(layer()));
EXPECT_POINTF_EQ(CurrentScrollOffset(layer()),
CurrentScrollOffset(pending_layer.get()));
}
} // namespace
} // namespace cc
|