Commit 8591a64c authored by danakj@chromium.org's avatar danakj@chromium.org

cc: Remove incorrect dcheck for masks.

If a layer has a replica, which has a mask, then the layer itself does not
need to clip to its bounding box. This dcheck verified that it would.

Add some new unit tests and pixel tests that verify behaviour of the mask
texture with masked replicas. The current behaviour is correct. The
replica is masked at the origin of the replicated layer.

Tests:
LayerTreeHostImplTest.ReflectionMaskLayerWithDifferentBounds
LayerTreeHostImplTest.ReflectionMaskLayerForSurfaceWithUnclippedChild
LayerTreeHostImplTest.MaskLayerForSurfaceWithClippedLayer
LayerTreeHostMasksPixelTest.MaskOfLayer
LayerTreeHostMasksPixelTest.ImageMaskOfLayer
LayerTreeHostMasksPixelTest.MaskOfClippedLayer
LayerTreeHostMasksPixelTest.MaskWithReplica
LayerTreeHostMasksPixelTest.MaskWithReplicaOfClippedLayer
LayerTreeHostMasksPixelTest.MaskOfReplica
LayerTreeHostMasksPixelTest.MaskOfReplicaOfClippedLayer

R=enne
BUG=171734

Review URL: https://codereview.chromium.org/14244021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194639 0039d316-1c4b-4281-b951-d872f2087c98
parent 3d0bfec9
......@@ -31,6 +31,7 @@
'trees/layer_tree_host_common_unittest.cc',
'trees/layer_tree_host_impl_unittest.cc',
'trees/layer_tree_host_pixeltest_filters.cc',
'trees/layer_tree_host_pixeltest_masks.cc',
'trees/layer_tree_host_pixeltest_on_demand_raster.cc',
'trees/layer_tree_host_unittest.cc',
'trees/layer_tree_host_unittest_animation.cc',
......
......@@ -250,16 +250,15 @@ void RenderSurfaceImpl::AppendQuads(QuadSink* quad_sink,
gfx::Vector2dF owning_layer_draw_scale =
MathUtil::ComputeTransform2dScaleComponents(
owning_layer_->draw_transform(), 1.f);
gfx::SizeF unclipped_surface_size = gfx::ScaleSize(
gfx::SizeF unclipped_mask_target_size = gfx::ScaleSize(
owning_layer_->content_bounds(),
owning_layer_draw_scale.x(),
owning_layer_draw_scale.y());
// This assumes that the owning layer clips its subtree when a mask is
// present.
DCHECK(gfx::RectF(unclipped_surface_size).Contains(content_rect_));
float uv_scale_x = content_rect_.width() / unclipped_surface_size.width();
float uv_scale_y = content_rect_.height() / unclipped_surface_size.height();
float uv_scale_x =
content_rect_.width() / unclipped_mask_target_size.width();
float uv_scale_y =
content_rect_.height() / unclipped_mask_target_size.height();
mask_uv_rect = gfx::RectF(
uv_scale_x * content_rect_.x() / content_rect_.width(),
......
......@@ -66,7 +66,7 @@ void LayerTreePixelTest::SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
EXPECT_TRUE(PathService::Get(cc::DIR_TEST_DATA, &test_data_dir));
// To rebaseline:
// EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_)));
// EXPECT_TRUE(WritePNGFile(bitmap, test_data_dir.Append(ref_file_), true));
EXPECT_TRUE(MatchesPNGFile(bitmap,
test_data_dir.Append(ref_file_),
......
This diff is collapsed.
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "build/build_config.h"
#include "cc/layers/content_layer.h"
#include "cc/layers/content_layer_client.h"
#include "cc/layers/image_layer.h"
#include "cc/test/layer_tree_pixel_test.h"
#include "cc/test/pixel_comparator.h"
#if !defined(OS_ANDROID)
namespace cc {
namespace {
class LayerTreeHostMasksPixelTest : public LayerTreePixelTest {};
class MaskContentLayerClient : public cc::ContentLayerClient {
public:
MaskContentLayerClient() {}
virtual ~MaskContentLayerClient() {}
virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
virtual void PaintContents(SkCanvas* canvas,
gfx::Rect rect,
gfx::RectF* opaque_rect) OVERRIDE {
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(2));
paint.setColor(SK_ColorWHITE);
canvas->clear(SK_ColorTRANSPARENT);
while (!rect.IsEmpty()) {
rect.Inset(3, 3, 2, 2);
canvas->drawRect(
SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()),
paint);
rect.Inset(3, 3, 2, 2);
}
}
};
TEST_F(LayerTreeHostMasksPixelTest, MaskOfLayer) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
background->AddChild(green);
MaskContentLayerClient client;
scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
mask->SetBounds(gfx::Size(100, 100));
mask->SetIsDrawable(true);
mask->SetIsMask(true);
green->SetMaskLayer(mask);
RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL(
"mask_of_layer.png")));
}
TEST_F(LayerTreeHostMasksPixelTest, ImageMaskOfLayer) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
scoped_refptr<ImageLayer> mask = ImageLayer::Create();
mask->SetIsDrawable(true);
mask->SetIsMask(true);
mask->SetBounds(gfx::Size(100, 100));
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
bitmap.allocPixels();
SkCanvas canvas(bitmap);
canvas.scale(SkIntToScalar(4), SkIntToScalar(4));
MaskContentLayerClient client;
client.PaintContents(&canvas,
gfx::Rect(100, 100),
NULL);
mask->SetBitmap(bitmap);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
green->SetMaskLayer(mask);
background->AddChild(green);
RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL(
"image_mask_of_layer.png")));
}
TEST_F(LayerTreeHostMasksPixelTest, MaskOfClippedLayer) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
// Clip to the top half of the green layer.
scoped_refptr<Layer> clip = Layer::Create();
clip->SetAnchorPoint(gfx::PointF(0.f, 0.f));
clip->SetPosition(gfx::Point(0, 0));
clip->SetBounds(gfx::Size(200, 100));
clip->SetMasksToBounds(true);
background->AddChild(clip);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
clip->AddChild(green);
MaskContentLayerClient client;
scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
mask->SetBounds(gfx::Size(100, 100));
mask->SetIsDrawable(true);
mask->SetIsMask(true);
green->SetMaskLayer(mask);
RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL(
"mask_of_clipped_layer.png")));
}
TEST_F(LayerTreeHostMasksPixelTest, MaskWithReplica) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
MaskContentLayerClient client;
scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
mask->SetBounds(gfx::Size(100, 100));
mask->SetIsDrawable(true);
mask->SetIsMask(true);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
gfx::Rect(0, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
background->AddChild(green);
green->SetMaskLayer(mask);
gfx::Transform replica_transform;
replica_transform.Rotate(-90.0);
scoped_refptr<Layer> replica = Layer::Create();
replica->SetAnchorPoint(gfx::PointF(0.5f, 0.5f));
replica->SetPosition(gfx::Point(100, 100));
replica->SetTransform(replica_transform);
green->SetReplicaLayer(replica);
RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL(
"mask_with_replica.png")));
}
TEST_F(LayerTreeHostMasksPixelTest, MaskWithReplicaOfClippedLayer) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
MaskContentLayerClient client;
scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
mask->SetBounds(gfx::Size(100, 100));
mask->SetIsDrawable(true);
mask->SetIsMask(true);
// Clip to the bottom half of the green layer, and the left half of the
// replica.
scoped_refptr<Layer> clip = Layer::Create();
clip->SetAnchorPoint(gfx::PointF(0.f, 0.f));
clip->SetPosition(gfx::Point(0, 50));
clip->SetBounds(gfx::Size(150, 150));
clip->SetMasksToBounds(true);
background->AddChild(clip);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
gfx::Rect(0, -50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
clip->AddChild(green);
green->SetMaskLayer(mask);
gfx::Transform replica_transform;
replica_transform.Rotate(-90.0);
scoped_refptr<Layer> replica = Layer::Create();
replica->SetAnchorPoint(gfx::PointF(0.5f, 0.5f));
replica->SetPosition(gfx::Point(100, 100));
replica->SetTransform(replica_transform);
green->SetReplicaLayer(replica);
RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL(
"mask_with_replica_of_clipped_layer.png")));
}
TEST_F(LayerTreeHostMasksPixelTest, MaskOfReplica) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
MaskContentLayerClient client;
scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
mask->SetBounds(gfx::Size(100, 100));
mask->SetIsDrawable(true);
mask->SetIsMask(true);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
gfx::Rect(50, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
background->AddChild(green);
scoped_refptr<SolidColorLayer> orange = CreateSolidColorLayer(
gfx::Rect(-50, 50, 50, 50), kCSSOrange);
green->AddChild(orange);
gfx::Transform replica_transform;
replica_transform.Rotate(180.0);
replica_transform.Translate(100.0, 0.0);
scoped_refptr<Layer> replica = Layer::Create();
replica->SetAnchorPoint(gfx::PointF(1.f, 1.f));
replica->SetPosition(gfx::Point());
replica->SetTransform(replica_transform);
replica->SetMaskLayer(mask);
green->SetReplicaLayer(replica);
RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL(
"mask_of_replica.png")));
}
TEST_F(LayerTreeHostMasksPixelTest, MaskOfReplicaOfClippedLayer) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
MaskContentLayerClient client;
scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
mask->SetBounds(gfx::Size(100, 100));
mask->SetIsDrawable(true);
mask->SetIsMask(true);
// Clip to the bottom 3/4 of the green layer, and the top 3/4 of the replica.
scoped_refptr<Layer> clip = Layer::Create();
clip->SetAnchorPoint(gfx::PointF(0.f, 0.f));
clip->SetPosition(gfx::Point(0, 25));
clip->SetBounds(gfx::Size(200, 150));
clip->SetMasksToBounds(true);
background->AddChild(clip);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
gfx::Rect(50, -25, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
clip->AddChild(green);
scoped_refptr<SolidColorLayer> orange = CreateSolidColorLayer(
gfx::Rect(-50, 50, 50, 50), kCSSOrange);
green->AddChild(orange);
gfx::Transform replica_transform;
replica_transform.Rotate(180.0);
replica_transform.Translate(100.0, 0.0);
scoped_refptr<Layer> replica = Layer::Create();
replica->SetAnchorPoint(gfx::PointF(1.f, 1.f));
replica->SetPosition(gfx::Point());
replica->SetTransform(replica_transform);
replica->SetMaskLayer(mask);
green->SetReplicaLayer(replica);
RunPixelTest(background,
base::FilePath(FILE_PATH_LITERAL(
"mask_of_replica_of_clipped_layer.png")));
}
} // namespace
} // namespace cc
#endif // OS_ANDROID
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment