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 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/time/time.h"
#include "cc/test/fake_picture_layer.h"
#include "cc/test/fake_recording_source.h"
#include "cc/test/layer_tree_test.h"
#include "cc/test/property_tree_test_utils.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/quads/compositor_render_pass_draw_quad.h"
namespace cc {
namespace {
class LayerTreeTestMaskLayerForSurfaceWithContentRectNotAtOrigin
: public LayerTreeTest {
protected:
void SetupTree() override {
// The masked layer has bounds 50x50, but it has a child that causes
// the surface bounds to be larger. It also has a parent that clips the
// masked layer and its surface.
SetInitialRootBounds(gfx::Size(100, 100));
LayerTreeTest::SetupTree();
Layer* root = layer_tree_host()->root_layer();
scoped_refptr<FakePictureLayer> content_layer =
FakePictureLayer::Create(&client_);
mask_client_.set_fill_with_nonsolid_color(true);
auto mask_layer = FakePictureLayer::Create(&mask_client_);
content_layer->SetMaskLayer(mask_layer);
gfx::Size layer_size(100, 100);
content_layer->SetBounds(layer_size);
gfx::Size mask_size(100, 100);
mask_layer->SetBounds(mask_size);
mask_client_.set_bounds(mask_size);
mask_layer_id_ = mask_layer->id();
scoped_refptr<Layer> clip_layer = Layer::Create();
clip_layer->SetBounds(gfx::Size(50, 50));
clip_layer->SetMasksToBounds(true);
scoped_refptr<Layer> scroll_layer = Layer::Create();
scroll_layer->SetBounds(layer_size);
scroll_layer->SetScrollable(gfx::Size(50, 50));
scroll_layer->SetMasksToBounds(true);
scroll_layer->SetElementId(
LayerIdToElementIdForTesting(scroll_layer->id()));
root->AddChild(clip_layer);
clip_layer->AddChild(scroll_layer);
scroll_layer->AddChild(content_layer);
client_.set_bounds(root->bounds());
scroll_layer->SetScrollOffset(gfx::PointF(50, 50));
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(3u, frame.render_pass_list.size());
viz::CompositorRenderPass* root_pass = frame.render_pass_list.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
EXPECT_EQ(viz::DrawQuad::Material::kSolidColor,
root_pass->quad_list.back()->material);
EXPECT_EQ(viz::DrawQuad::Material::kCompositorRenderPass,
root_pass->quad_list.front()->material);
const viz::CompositorRenderPassDrawQuad* render_pass_quad =
viz::CompositorRenderPassDrawQuad::MaterialCast(
root_pass->quad_list.front());
gfx::Rect rect_in_target_space = MathUtil::MapEnclosingClippedRect(
render_pass_quad->shared_quad_state->quad_to_target_transform,
render_pass_quad->rect);
EXPECT_EQ(gfx::Rect(0, 0, 50, 50), rect_in_target_space);
// We use kDstIn blend mode instead of the mask feature of RenderPass.
EXPECT_EQ(gfx::RectF(), render_pass_quad->mask_uv_rect);
viz::CompositorRenderPass* mask_pass = frame.render_pass_list[1].get();
EXPECT_EQ(SkBlendMode::kDstIn,
mask_pass->quad_list.front()->shared_quad_state->blend_mode);
EndTest();
++display_count_;
}
void AfterTest() override { EXPECT_EQ(1, display_count_); }
int mask_layer_id_;
FakeContentLayerClient client_;
FakeContentLayerClient mask_client_;
int display_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeTestMaskLayerForSurfaceWithContentRectNotAtOrigin);
class LayerTreeTestMaskLayerForSurfaceWithContentRectNotAtOriginWithLayerList
: public LayerTreeTest {
protected:
LayerTreeTestMaskLayerForSurfaceWithContentRectNotAtOriginWithLayerList() {
SetUseLayerLists();
}
void SetupTree() override {
// The masked layer has bounds 50x50, but it has a child that causes
// the surface bounds to be larger. It also has a parent that clips the
// masked layer and its surface.
SetInitialRootBounds(gfx::Size(100, 100));
LayerTreeTest::SetupTree();
Layer* root = layer_tree_host()->root_layer();
gfx::Size layer_size(100, 100);
SetupViewport(root, gfx::Size(50, 50), layer_size);
auto* scroll = layer_tree_host()->OuterViewportScrollLayerForTesting();
SetScrollOffset(scroll, gfx::PointF(50, 50));
client_.set_bounds(root->bounds());
client_.set_fill_with_nonsolid_color(true);
auto content_layer = FakePictureLayer::Create(&client_);
content_layer->SetBounds(layer_size);
CopyProperties(scroll, content_layer.get());
root->AddChild(content_layer);
auto mask_layer = FakePictureLayer::Create(&client_);
SetupMaskProperties(content_layer.get(), mask_layer.get());
root->AddChild(mask_layer);
mask_layer_id_ = mask_layer->id();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(1u, frame.render_pass_list.size());
viz::CompositorRenderPass* pass = frame.render_pass_list.back().get();
EXPECT_EQ(3u, pass->quad_list.size());
// There's a solid color quad under everything.
EXPECT_EQ(viz::DrawQuad::Material::kSolidColor,
pass->quad_list.back()->material);
EXPECT_EQ(viz::DrawQuad::Material::kTiledContent,
pass->quad_list.ElementAt(1)->material);
auto* mask_quad = pass->quad_list.front();
EXPECT_EQ(viz::DrawQuad::Material::kTiledContent, mask_quad->material);
gfx::Rect rect_in_target_space = MathUtil::MapEnclosingClippedRect(
mask_quad->shared_quad_state->quad_to_target_transform,
mask_quad->rect);
EXPECT_EQ(gfx::Rect(0, 0, 50, 50), rect_in_target_space);
// We use kDstIn blend mode for mask.
EXPECT_EQ(SkBlendMode::kDstIn, mask_quad->shared_quad_state->blend_mode);
EndTest();
++display_count_;
}
void AfterTest() override { EXPECT_EQ(1, display_count_); }
int mask_layer_id_;
FakeContentLayerClient client_;
int display_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeTestMaskLayerForSurfaceWithContentRectNotAtOriginWithLayerList);
class LayerTreeTestMaskLayerForSurfaceWithClippedLayer : public LayerTreeTest {
protected:
void SetupTree() override {
// The masked layer has bounds 50x50, but it has a child that causes
// the surface bounds to be larger. It also has a parent that clips the
// masked layer and its surface.
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> clipping_layer = Layer::Create();
root->AddChild(clipping_layer);
scoped_refptr<FakePictureLayer> content_layer =
FakePictureLayer::Create(&client_);
clipping_layer->AddChild(content_layer);
scoped_refptr<FakePictureLayer> content_child_layer =
FakePictureLayer::Create(&client_);
content_layer->AddChild(content_child_layer);
mask_client_.set_fill_with_nonsolid_color(true);
auto mask_layer = FakePictureLayer::Create(&mask_client_);
content_layer->SetMaskLayer(mask_layer);
gfx::Size root_size(100, 100);
root->SetBounds(root_size);
gfx::PointF clipping_origin(20.f, 10.f);
gfx::Size clipping_size(10, 20);
clipping_layer->SetBounds(clipping_size);
clipping_layer->SetPosition(clipping_origin);
clipping_layer->SetMasksToBounds(true);
gfx::Size layer_size(50, 50);
content_layer->SetBounds(layer_size);
content_layer->SetPosition(gfx::PointF() -
clipping_origin.OffsetFromOrigin());
gfx::Size child_size(50, 50);
content_child_layer->SetBounds(child_size);
content_child_layer->SetPosition(gfx::PointF(20.f, 0.f));
gfx::Size mask_size(50, 50);
mask_layer->SetBounds(mask_size);
mask_client_.set_bounds(mask_size);
mask_layer_id_ = mask_layer->id();
layer_tree_host()->SetRootLayer(root);
LayerTreeTest::SetupTree();
client_.set_bounds(root->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(3u, frame.render_pass_list.size());
viz::CompositorRenderPass* root_pass = frame.render_pass_list.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
EXPECT_EQ(viz::DrawQuad::Material::kSolidColor,
root_pass->quad_list.back()->material);
// The surface is clipped to 10x20.
EXPECT_EQ(viz::DrawQuad::Material::kCompositorRenderPass,
root_pass->quad_list.front()->material);
const viz::CompositorRenderPassDrawQuad* render_pass_quad =
viz::CompositorRenderPassDrawQuad::MaterialCast(
root_pass->quad_list.front());
gfx::Rect rect_in_target_space = MathUtil::MapEnclosingClippedRect(
render_pass_quad->shared_quad_state->quad_to_target_transform,
render_pass_quad->rect);
EXPECT_EQ(gfx::Rect(20, 10, 10, 20).ToString(),
rect_in_target_space.ToString());
// We use kDstIn blend mode instead of the mask feature of RenderPass.
EXPECT_EQ(gfx::RectF(), render_pass_quad->mask_uv_rect);
viz::CompositorRenderPass* mask_pass = frame.render_pass_list[1].get();
EXPECT_EQ(SkBlendMode::kDstIn,
mask_pass->quad_list.front()->shared_quad_state->blend_mode);
EndTest();
++display_count_;
}
void AfterTest() override { EXPECT_EQ(1, display_count_); }
int mask_layer_id_;
FakeContentLayerClient client_;
FakeContentLayerClient mask_client_;
int display_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeTestMaskLayerForSurfaceWithClippedLayer);
class LayerTreeTestMaskLayerForSurfaceWithDifferentScale
: public LayerTreeTest {
protected:
void SetupTree() override {
// The masked layer has bounds 50x50, but it has a child that causes
// the surface bounds to be larger. It also has a parent that clips the
// masked layer and its surface.
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> clipping_scaling_layer = Layer::Create();
root->AddChild(clipping_scaling_layer);
scoped_refptr<FakePictureLayer> content_layer =
FakePictureLayer::Create(&client_);
clipping_scaling_layer->AddChild(content_layer);
scoped_refptr<FakePictureLayer> content_child_layer =
FakePictureLayer::Create(&client_);
content_layer->AddChild(content_child_layer);
mask_client_.set_fill_with_nonsolid_color(true);
auto mask_layer = FakePictureLayer::Create(&mask_client_);
content_layer->SetMaskLayer(mask_layer);
gfx::Size root_size(100, 100);
root->SetBounds(root_size);
gfx::Transform scale;
scale.Scale(2, 2);
gfx::PointF clipping_origin(20.f, 10.f);
gfx::Size clipping_size(10, 20);
clipping_scaling_layer->SetBounds(clipping_size);
clipping_scaling_layer->SetPosition(clipping_origin);
// This changes scale between contributing layer and render surface to 2.
clipping_scaling_layer->SetTransform(scale);
clipping_scaling_layer->SetMasksToBounds(true);
gfx::Size layer_size(50, 50);
content_layer->SetBounds(layer_size);
content_layer->SetPosition(gfx::PointF() -
clipping_origin.OffsetFromOrigin());
gfx::Size child_size(50, 50);
content_child_layer->SetBounds(child_size);
content_child_layer->SetPosition(gfx::PointF(20.f, 0.f));
gfx::Size mask_size(50, 50);
mask_layer->SetBounds(mask_size);
mask_client_.set_bounds(mask_size);
mask_layer_id_ = mask_layer->id();
layer_tree_host()->SetRootLayer(root);
LayerTreeTest::SetupTree();
client_.set_bounds(root->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(3u, frame.render_pass_list.size());
viz::CompositorRenderPass* root_pass = frame.render_pass_list.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
EXPECT_EQ(viz::DrawQuad::Material::kSolidColor,
root_pass->quad_list.back()->material);
// The surface is clipped to 10x20, and then scaled by 2, which ends up
// being 20x40.
EXPECT_EQ(viz::DrawQuad::Material::kCompositorRenderPass,
root_pass->quad_list.front()->material);
const viz::CompositorRenderPassDrawQuad* render_pass_quad =
viz::CompositorRenderPassDrawQuad::MaterialCast(
root_pass->quad_list.front());
gfx::Rect rect_in_target_space = MathUtil::MapEnclosingClippedRect(
render_pass_quad->shared_quad_state->quad_to_target_transform,
render_pass_quad->rect);
EXPECT_EQ(gfx::Rect(20, 10, 20, 40).ToString(),
rect_in_target_space.ToString());
gfx::Rect visible_rect_in_target_space = MathUtil::MapEnclosingClippedRect(
render_pass_quad->shared_quad_state->quad_to_target_transform,
render_pass_quad->visible_rect);
EXPECT_EQ(gfx::Rect(20, 10, 20, 40).ToString(),
visible_rect_in_target_space.ToString());
// We use kDstIn blend mode instead of the mask feature of RenderPass.
EXPECT_EQ(gfx::RectF(), render_pass_quad->mask_uv_rect);
viz::CompositorRenderPass* mask_pass = frame.render_pass_list[1].get();
EXPECT_EQ(SkBlendMode::kDstIn,
mask_pass->quad_list.front()->shared_quad_state->blend_mode);
EndTest();
++display_count_;
}
void AfterTest() override { EXPECT_EQ(1, display_count_); }
int mask_layer_id_;
FakeContentLayerClient client_;
FakeContentLayerClient mask_client_;
int display_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeTestMaskLayerForSurfaceWithDifferentScale);
class LayerTreeTestMaskLayerWithScaling : public LayerTreeTest {
protected:
void SetupTree() override {
// Root
// |
// +-- Scaling Layer (adds a 2x scale)
// |
// +-- Content Layer
// +--Mask
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> scaling_layer = Layer::Create();
root->AddChild(scaling_layer);
scoped_refptr<FakePictureLayer> content_layer =
FakePictureLayer::Create(&client_);
scaling_layer->AddChild(content_layer);
mask_client_.set_fill_with_nonsolid_color(true);
auto mask_layer = FakePictureLayer::Create(&mask_client_);
content_layer->SetMaskLayer(mask_layer);
gfx::Size root_size(100, 100);
root->SetBounds(root_size);
gfx::Size scaling_layer_size(50, 50);
scaling_layer->SetBounds(scaling_layer_size);
gfx::Transform scale;
scale.Scale(2.f, 2.f);
scaling_layer->SetTransform(scale);
content_layer->SetBounds(scaling_layer_size);
mask_layer->SetBounds(scaling_layer_size);
mask_client_.set_bounds(scaling_layer_size);
layer_tree_host()->SetRootLayer(root);
LayerTreeTest::SetupTree();
client_.set_bounds(root->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(3u, frame.render_pass_list.size());
viz::CompositorRenderPass* root_pass = frame.render_pass_list.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
EXPECT_EQ(viz::DrawQuad::Material::kSolidColor,
root_pass->quad_list.back()->material);
EXPECT_EQ(viz::DrawQuad::Material::kCompositorRenderPass,
root_pass->quad_list.front()->material);
const viz::CompositorRenderPassDrawQuad* render_pass_quad =
viz::CompositorRenderPassDrawQuad::MaterialCast(
root_pass->quad_list.front());
gfx::Rect rect_in_target_space = MathUtil::MapEnclosingClippedRect(
render_pass_quad->shared_quad_state->quad_to_target_transform,
render_pass_quad->rect);
// We use kDstIn blend mode instead of the mask feature of RenderPass.
EXPECT_EQ(gfx::RectF(), render_pass_quad->mask_uv_rect);
viz::CompositorRenderPass* mask_pass = frame.render_pass_list[1].get();
EXPECT_EQ(SkBlendMode::kDstIn,
mask_pass->quad_list.front()->shared_quad_state->blend_mode);
switch (display_count_) {
case 0:
// Check that the tree scaling is correctly taken into account for the
// mask, that should fully map onto the quad.
EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
rect_in_target_space.ToString());
break;
case 1:
// Applying a DSF should change the render surface size, but won't
// affect which part of the mask is used.
EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(),
rect_in_target_space.ToString());
EndTest();
break;
}
++display_count_;
}
void DidCommitAndDrawFrame() override {
switch (commit_count_) {
case 0:
gfx::Size double_root_size(200, 200);
GenerateNewLocalSurfaceId();
layer_tree_host()->SetViewportRectAndScale(
gfx::Rect(double_root_size), 2.f, GetCurrentLocalSurfaceId());
break;
}
++commit_count_;
}
void AfterTest() override {
EXPECT_EQ(2, commit_count_);
EXPECT_EQ(2, display_count_);
}
FakeContentLayerClient client_;
FakeContentLayerClient mask_client_;
int commit_count_ = 0;
int display_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMaskLayerWithScaling);
class LayerTreeTestMaskWithNonExactTextureSize : public LayerTreeTest {
protected:
void SetupTree() override {
// The masked layer has bounds 100x100, but is allocated a 120x150 texture.
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<FakePictureLayer> content_layer =
FakePictureLayer::Create(&client_);
root->AddChild(content_layer);
mask_client_.set_fill_with_nonsolid_color(true);
auto mask_layer = FakePictureLayer::Create(&mask_client_);
content_layer->SetMaskLayer(mask_layer);
gfx::Size root_size(100, 100);
root->SetBounds(root_size);
gfx::Size layer_size(100, 100);
content_layer->SetBounds(layer_size);
gfx::Size mask_size(100, 100);
gfx::Size mask_texture_size(120, 150);
mask_layer->SetBounds(mask_size);
mask_client_.set_bounds(mask_size);
mask_layer->set_fixed_tile_size(mask_texture_size);
layer_tree_host()->SetRootLayer(root);
LayerTreeTest::SetupTree();
client_.set_bounds(root->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(3u, frame.render_pass_list.size());
viz::CompositorRenderPass* root_pass = frame.render_pass_list.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
EXPECT_EQ(viz::DrawQuad::Material::kSolidColor,
root_pass->quad_list.back()->material);
// The surface is 100x100
EXPECT_EQ(viz::DrawQuad::Material::kCompositorRenderPass,
root_pass->quad_list.front()->material);
const viz::CompositorRenderPassDrawQuad* render_pass_quad =
viz::CompositorRenderPassDrawQuad::MaterialCast(
root_pass->quad_list.front());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
render_pass_quad->rect.ToString());
// We use kDstIn blend mode instead of the mask feature of RenderPass.
EXPECT_EQ(gfx::RectF(), render_pass_quad->mask_uv_rect);
viz::CompositorRenderPass* mask_pass = frame.render_pass_list[1].get();
EXPECT_EQ(SkBlendMode::kDstIn,
mask_pass->quad_list.front()->shared_quad_state->blend_mode);
EndTest();
++display_count_;
}
void AfterTest() override { EXPECT_EQ(1, display_count_); }
int mask_layer_id_;
FakeContentLayerClient client_;
FakeContentLayerClient mask_client_;
int display_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMaskWithNonExactTextureSize);
} // namespace
} // namespace cc
|