| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" | 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" |
| 6 | 6 |
| 7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
| 10 #include "cc/test/fake_output_surface.h" | 10 #include "cc/test/fake_output_surface.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 gfx::Transform translation(SkMScalar x, SkMScalar y) | 31 gfx::Transform translation(SkMScalar x, SkMScalar y) |
| 32 { | 32 { |
| 33 gfx::Transform transform; | 33 gfx::Transform transform; |
| 34 transform.Translate(x, y); | 34 transform.Translate(x, y); |
| 35 return transform; | 35 return transform; |
| 36 } | 36 } |
| 37 | 37 |
| 38 EffectPaintPropertyNode* dummyRootEffect() | 38 EffectPaintPropertyNode* dummyRootEffect() |
| 39 { | 39 { |
| 40 DEFINE_STATIC_REF(EffectPaintPropertyNode, node, EffectPaintPropertyNode::cr
eate(1.0)); | 40 DEFINE_STATIC_REF(EffectPaintPropertyNode, node, EffectPaintPropertyNode::cr
eate(nullptr, 1.0)); |
| 41 return node; | 41 return node; |
| 42 } | 42 } |
| 43 | 43 |
| 44 class PaintArtifactCompositorTest : public ::testing::Test { | 44 class PaintArtifactCompositorTest : public ::testing::Test { |
| 45 protected: | 45 protected: |
| 46 void SetUp() override | 46 void SetUp() override |
| 47 { | 47 { |
| 48 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | 48 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); |
| 49 | 49 |
| 50 // Delay constructing the compositor until after the feature is set. | 50 // Delay constructing the compositor until after the feature is set. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 EXPECT_THAT(child->GetPicture(), | 95 EXPECT_THAT(child->GetPicture(), |
| 96 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); | 96 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); |
| 97 EXPECT_EQ(translation(50, -50), child->transform()); | 97 EXPECT_EQ(translation(50, -50), child->transform()); |
| 98 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); | 98 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 TEST_F(PaintArtifactCompositorTest, OneTransform) | 101 TEST_F(PaintArtifactCompositorTest, OneTransform) |
| 102 { | 102 { |
| 103 // A 90 degree clockwise rotation about (100, 100). | 103 // A 90 degree clockwise rotation about (100, 100). |
| 104 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate( | 104 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate( |
| 105 TransformationMatrix().rotate(90), FloatPoint3D(100, 100, 0)); | 105 nullptr, TransformationMatrix().rotate(90), FloatPoint3D(100, 100, 0)); |
| 106 | 106 |
| 107 TestPaintArtifact artifact; | 107 TestPaintArtifact artifact; |
| 108 artifact.chunk(transform, nullptr, dummyRootEffect()) | 108 artifact.chunk(transform, nullptr, dummyRootEffect()) |
| 109 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | 109 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 110 artifact.chunk(nullptr, nullptr, dummyRootEffect()) | 110 artifact.chunk(nullptr, nullptr, dummyRootEffect()) |
| 111 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); | 111 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); |
| 112 artifact.chunk(transform, nullptr, dummyRootEffect()) | 112 artifact.chunk(transform, nullptr, dummyRootEffect()) |
| 113 .rectDrawing(FloatRect(100, 100, 200, 100), Color::black); | 113 .rectDrawing(FloatRect(100, 100, 200, 100), Color::black); |
| 114 update(artifact.build()); | 114 update(artifact.build()); |
| 115 | 115 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 135 gfx::RectF mappedRect(0, 0, 200, 100); | 135 gfx::RectF mappedRect(0, 0, 200, 100); |
| 136 layer->transform().TransformRect(&mappedRect); | 136 layer->transform().TransformRect(&mappedRect); |
| 137 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); | 137 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST_F(PaintArtifactCompositorTest, TransformCombining) | 141 TEST_F(PaintArtifactCompositorTest, TransformCombining) |
| 142 { | 142 { |
| 143 // A translation by (5, 5) within a 2x scale about (10, 10). | 143 // A translation by (5, 5) within a 2x scale about (10, 10). |
| 144 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create( | 144 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create( |
| 145 TransformationMatrix().scale(2), FloatPoint3D(10, 10, 0)); | 145 nullptr, TransformationMatrix().scale(2), FloatPoint3D(10, 10, 0)); |
| 146 RefPtr<TransformPaintPropertyNode> transform2 = TransformPaintPropertyNode::
create( | 146 RefPtr<TransformPaintPropertyNode> transform2 = TransformPaintPropertyNode::
create( |
| 147 TransformationMatrix().translate(5, 5), FloatPoint3D(), transform1); | 147 transform1, TransformationMatrix().translate(5, 5), FloatPoint3D()); |
| 148 | 148 |
| 149 TestPaintArtifact artifact; | 149 TestPaintArtifact artifact; |
| 150 artifact.chunk(transform1, nullptr, dummyRootEffect()) | 150 artifact.chunk(transform1, nullptr, dummyRootEffect()) |
| 151 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); | 151 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); |
| 152 artifact.chunk(transform2, nullptr, dummyRootEffect()) | 152 artifact.chunk(transform2, nullptr, dummyRootEffect()) |
| 153 .rectDrawing(FloatRect(0, 0, 300, 200), Color::black); | 153 .rectDrawing(FloatRect(0, 0, 300, 200), Color::black); |
| 154 update(artifact.build()); | 154 update(artifact.build()); |
| 155 | 155 |
| 156 ASSERT_EQ(2u, rootLayer()->children().size()); | 156 ASSERT_EQ(2u, rootLayer()->children().size()); |
| 157 { | 157 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 168 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); | 168 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); |
| 169 gfx::RectF mappedRect(0, 0, 300, 200); | 169 gfx::RectF mappedRect(0, 0, 300, 200); |
| 170 layer->transform().TransformRect(&mappedRect); | 170 layer->transform().TransformRect(&mappedRect); |
| 171 EXPECT_EQ(gfx::RectF(0, 0, 600, 400), mappedRect); | 171 EXPECT_EQ(gfx::RectF(0, 0, 600, 400), mappedRect); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST_F(PaintArtifactCompositorTest, LayerOriginCancellation) | 175 TEST_F(PaintArtifactCompositorTest, LayerOriginCancellation) |
| 176 { | 176 { |
| 177 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( | 177 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 178 nullptr, FloatRoundedRect(100, 100, 100, 100)); | 178 nullptr, nullptr, FloatRoundedRect(100, 100, 100, 100)); |
| 179 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate( | 179 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate( |
| 180 TransformationMatrix().scale(2), FloatPoint3D()); | 180 nullptr, TransformationMatrix().scale(2), FloatPoint3D()); |
| 181 | 181 |
| 182 TestPaintArtifact artifact; | 182 TestPaintArtifact artifact; |
| 183 artifact.chunk(transform, clip, nullptr) | 183 artifact.chunk(transform, clip, nullptr) |
| 184 .rectDrawing(FloatRect(12, 34, 56, 78), Color::white); | 184 .rectDrawing(FloatRect(12, 34, 56, 78), Color::white); |
| 185 update(artifact.build()); | 185 update(artifact.build()); |
| 186 | 186 |
| 187 ASSERT_EQ(1u, rootLayer()->children().size()); | 187 ASSERT_EQ(1u, rootLayer()->children().size()); |
| 188 cc::Layer* clipLayer = rootLayer()->child_at(0); | 188 cc::Layer* clipLayer = rootLayer()->child_at(0); |
| 189 EXPECT_EQ(gfx::Size(100, 100), clipLayer->bounds()); | 189 EXPECT_EQ(gfx::Size(100, 100), clipLayer->bounds()); |
| 190 EXPECT_EQ(translation(100, 100), clipLayer->transform()); | 190 EXPECT_EQ(translation(100, 100), clipLayer->transform()); |
| 191 EXPECT_TRUE(clipLayer->masks_to_bounds()); | 191 EXPECT_TRUE(clipLayer->masks_to_bounds()); |
| 192 | 192 |
| 193 ASSERT_EQ(1u, clipLayer->children().size()); | 193 ASSERT_EQ(1u, clipLayer->children().size()); |
| 194 cc::Layer* layer = clipLayer->child_at(0); | 194 cc::Layer* layer = clipLayer->child_at(0); |
| 195 EXPECT_EQ(gfx::Size(56, 78), layer->bounds()); | 195 EXPECT_EQ(gfx::Size(56, 78), layer->bounds()); |
| 196 gfx::Transform expectedTransform; | 196 gfx::Transform expectedTransform; |
| 197 expectedTransform.Translate(-100, -100); | 197 expectedTransform.Translate(-100, -100); |
| 198 expectedTransform.Scale(2, 2); | 198 expectedTransform.Scale(2, 2); |
| 199 expectedTransform.Translate(12, 34); | 199 expectedTransform.Translate(12, 34); |
| 200 EXPECT_EQ(expectedTransform, layer->transform()); | 200 EXPECT_EQ(expectedTransform, layer->transform()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST_F(PaintArtifactCompositorTest, OneClip) | 203 TEST_F(PaintArtifactCompositorTest, OneClip) |
| 204 { | 204 { |
| 205 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( | 205 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 206 nullptr, FloatRoundedRect(100, 100, 300, 200)); | 206 nullptr, nullptr, FloatRoundedRect(100, 100, 300, 200)); |
| 207 | 207 |
| 208 TestPaintArtifact artifact; | 208 TestPaintArtifact artifact; |
| 209 artifact.chunk(nullptr, clip, nullptr) | 209 artifact.chunk(nullptr, clip, nullptr) |
| 210 .rectDrawing(FloatRect(220, 80, 300, 200), Color::black); | 210 .rectDrawing(FloatRect(220, 80, 300, 200), Color::black); |
| 211 update(artifact.build()); | 211 update(artifact.build()); |
| 212 | 212 |
| 213 ASSERT_EQ(1u, rootLayer()->children().size()); | 213 ASSERT_EQ(1u, rootLayer()->children().size()); |
| 214 cc::Layer* clipLayer = rootLayer()->child_at(0); | 214 cc::Layer* clipLayer = rootLayer()->child_at(0); |
| 215 EXPECT_TRUE(clipLayer->masks_to_bounds()); | 215 EXPECT_TRUE(clipLayer->masks_to_bounds()); |
| 216 EXPECT_EQ(gfx::Size(300, 200), clipLayer->bounds()); | 216 EXPECT_EQ(gfx::Size(300, 200), clipLayer->bounds()); |
| 217 EXPECT_EQ(translation(100, 100), clipLayer->transform()); | 217 EXPECT_EQ(translation(100, 100), clipLayer->transform()); |
| 218 | 218 |
| 219 ASSERT_EQ(1u, clipLayer->children().size()); | 219 ASSERT_EQ(1u, clipLayer->children().size()); |
| 220 const cc::Layer* layer = clipLayer->child_at(0); | 220 const cc::Layer* layer = clipLayer->child_at(0); |
| 221 EXPECT_THAT(layer->GetPicture(), | 221 EXPECT_THAT(layer->GetPicture(), |
| 222 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); | 222 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); |
| 223 EXPECT_EQ(translation(120, -20), layer->transform()); | 223 EXPECT_EQ(translation(120, -20), layer->transform()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 TEST_F(PaintArtifactCompositorTest, NestedClips) | 226 TEST_F(PaintArtifactCompositorTest, NestedClips) |
| 227 { | 227 { |
| 228 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 228 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 229 nullptr, FloatRoundedRect(100, 100, 700, 700)); | 229 nullptr, nullptr, FloatRoundedRect(100, 100, 700, 700)); |
| 230 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( | 230 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
| 231 nullptr, FloatRoundedRect(200, 200, 700, 100), clip1); | 231 clip1, nullptr, FloatRoundedRect(200, 200, 700, 100)); |
| 232 | 232 |
| 233 TestPaintArtifact artifact; | 233 TestPaintArtifact artifact; |
| 234 artifact.chunk(nullptr, clip1, dummyRootEffect()) | 234 artifact.chunk(nullptr, clip1, dummyRootEffect()) |
| 235 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white); | 235 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white); |
| 236 artifact.chunk(nullptr, clip2, dummyRootEffect()) | 236 artifact.chunk(nullptr, clip2, dummyRootEffect()) |
| 237 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray); | 237 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray); |
| 238 artifact.chunk(nullptr, clip1, dummyRootEffect()) | 238 artifact.chunk(nullptr, clip1, dummyRootEffect()) |
| 239 .rectDrawing(FloatRect(300, 350, 100, 100), Color::darkGray); | 239 .rectDrawing(FloatRect(300, 350, 100, 100), Color::darkGray); |
| 240 artifact.chunk(nullptr, clip2, dummyRootEffect()) | 240 artifact.chunk(nullptr, clip2, dummyRootEffect()) |
| 241 .rectDrawing(FloatRect(300, 350, 100, 100), Color::black); | 241 .rectDrawing(FloatRect(300, 350, 100, 100), Color::black); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black))); | 282 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::black))); |
| 283 EXPECT_EQ(translation(100, 150), blackLayer->transform()); | 283 EXPECT_EQ(translation(100, 150), blackLayer->transform()); |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 TEST_F(PaintArtifactCompositorTest, DeeplyNestedClips) | 287 TEST_F(PaintArtifactCompositorTest, DeeplyNestedClips) |
| 288 { | 288 { |
| 289 Vector<RefPtr<ClipPaintPropertyNode>> clips; | 289 Vector<RefPtr<ClipPaintPropertyNode>> clips; |
| 290 for (unsigned i = 1; i <= 10; i++) { | 290 for (unsigned i = 1; i <= 10; i++) { |
| 291 clips.append(ClipPaintPropertyNode::create( | 291 clips.append(ClipPaintPropertyNode::create( |
| 292 nullptr, FloatRoundedRect(5 * i, 0, 100, 200 - 10 * i), | 292 clips.isEmpty() ? nullptr : clips.last(), |
| 293 clips.isEmpty() ? nullptr : clips.last())); | 293 nullptr, FloatRoundedRect(5 * i, 0, 100, 200 - 10 * i))); |
| 294 } | 294 } |
| 295 | 295 |
| 296 TestPaintArtifact artifact; | 296 TestPaintArtifact artifact; |
| 297 artifact.chunk(nullptr, clips.last(), nullptr) | 297 artifact.chunk(nullptr, clips.last(), nullptr) |
| 298 .rectDrawing(FloatRect(0, 0, 200, 200), Color::white); | 298 .rectDrawing(FloatRect(0, 0, 200, 200), Color::white); |
| 299 update(artifact.build()); | 299 update(artifact.build()); |
| 300 | 300 |
| 301 // Check the clip layers. | 301 // Check the clip layers. |
| 302 cc::Layer* layer = rootLayer(); | 302 cc::Layer* layer = rootLayer(); |
| 303 for (const auto& clipNode : clips) { | 303 for (const auto& clipNode : clips) { |
| 304 ASSERT_EQ(1u, layer->children().size()); | 304 ASSERT_EQ(1u, layer->children().size()); |
| 305 layer = layer->child_at(0); | 305 layer = layer->child_at(0); |
| 306 EXPECT_EQ(clipNode->clipRect().rect().width(), layer->bounds().width()); | 306 EXPECT_EQ(clipNode->clipRect().rect().width(), layer->bounds().width()); |
| 307 EXPECT_EQ(clipNode->clipRect().rect().height(), layer->bounds().height()
); | 307 EXPECT_EQ(clipNode->clipRect().rect().height(), layer->bounds().height()
); |
| 308 EXPECT_EQ(translation(5, 0), layer->transform()); | 308 EXPECT_EQ(translation(5, 0), layer->transform()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 // Check the drawing layer. | 311 // Check the drawing layer. |
| 312 ASSERT_EQ(1u, layer->children().size()); | 312 ASSERT_EQ(1u, layer->children().size()); |
| 313 cc::Layer* drawingLayer = layer->child_at(0); | 313 cc::Layer* drawingLayer = layer->child_at(0); |
| 314 EXPECT_THAT(drawingLayer->GetPicture(), | 314 EXPECT_THAT(drawingLayer->GetPicture(), |
| 315 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); | 315 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); |
| 316 EXPECT_EQ(translation(-50, 0), drawingLayer->transform()); | 316 EXPECT_EQ(translation(-50, 0), drawingLayer->transform()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 TEST_F(PaintArtifactCompositorTest, SiblingClips) | 319 TEST_F(PaintArtifactCompositorTest, SiblingClips) |
| 320 { | 320 { |
| 321 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( | 321 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( |
| 322 nullptr, FloatRoundedRect(0, 0, 800, 600)); | 322 nullptr, nullptr, FloatRoundedRect(0, 0, 800, 600)); |
| 323 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 323 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 324 nullptr, FloatRoundedRect(0, 0, 400, 600), commonClip); | 324 commonClip, nullptr, FloatRoundedRect(0, 0, 400, 600)); |
| 325 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( | 325 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
| 326 nullptr, FloatRoundedRect(400, 0, 400, 600), commonClip); | 326 commonClip, nullptr, FloatRoundedRect(400, 0, 400, 600)); |
| 327 | 327 |
| 328 TestPaintArtifact artifact; | 328 TestPaintArtifact artifact; |
| 329 artifact.chunk(nullptr, clip1, nullptr) | 329 artifact.chunk(nullptr, clip1, nullptr) |
| 330 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white); | 330 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white); |
| 331 artifact.chunk(nullptr, clip2, nullptr) | 331 artifact.chunk(nullptr, clip2, nullptr) |
| 332 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black); | 332 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black); |
| 333 update(artifact.build()); | 333 update(artifact.build()); |
| 334 | 334 |
| 335 ASSERT_EQ(1u, rootLayer()->children().size()); | 335 ASSERT_EQ(1u, rootLayer()->children().size()); |
| 336 cc::Layer* commonClipLayer = rootLayer()->child_at(0); | 336 cc::Layer* commonClipLayer = rootLayer()->child_at(0); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 EXPECT_THAT(child->GetPicture(), | 447 EXPECT_THAT(child->GetPicture(), |
| 448 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); | 448 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); |
| 449 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); | 449 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); |
| 450 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); | 450 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); |
| 451 } | 451 } |
| 452 | 452 |
| 453 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) | 453 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) |
| 454 { | 454 { |
| 455 // A 90 degree clockwise rotation about (100, 100). | 455 // A 90 degree clockwise rotation about (100, 100). |
| 456 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate( | 456 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate( |
| 457 TransformationMatrix().rotate(90), FloatPoint3D(100, 100, 0)); | 457 nullptr, TransformationMatrix().rotate(90), FloatPoint3D(100, 100, 0)); |
| 458 | 458 |
| 459 TestPaintArtifact artifact; | 459 TestPaintArtifact artifact; |
| 460 artifact.chunk(transform, nullptr, dummyRootEffect()) | 460 artifact.chunk(transform, nullptr, dummyRootEffect()) |
| 461 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | 461 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 462 artifact.chunk(nullptr, nullptr, dummyRootEffect()) | 462 artifact.chunk(nullptr, nullptr, dummyRootEffect()) |
| 463 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); | 463 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); |
| 464 artifact.chunk(transform, nullptr, dummyRootEffect()) | 464 artifact.chunk(transform, nullptr, dummyRootEffect()) |
| 465 .rectDrawing(FloatRect(100, 100, 200, 100), Color::black); | 465 .rectDrawing(FloatRect(100, 100, 200, 100), Color::black); |
| 466 update(artifact.build()); | 466 update(artifact.build()); |
| 467 | 467 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 487 gfx::RectF mappedRect(0, 0, 200, 100); | 487 gfx::RectF mappedRect(0, 0, 200, 100); |
| 488 layer->screen_space_transform().TransformRect(&mappedRect); | 488 layer->screen_space_transform().TransformRect(&mappedRect); |
| 489 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); | 489 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); |
| 490 } | 490 } |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformCombining) | 493 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformCombining) |
| 494 { | 494 { |
| 495 // A translation by (5, 5) within a 2x scale about (10, 10). | 495 // A translation by (5, 5) within a 2x scale about (10, 10). |
| 496 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create( | 496 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create( |
| 497 TransformationMatrix().scale(2), FloatPoint3D(10, 10, 0)); | 497 nullptr, TransformationMatrix().scale(2), FloatPoint3D(10, 10, 0)); |
| 498 RefPtr<TransformPaintPropertyNode> transform2 = TransformPaintPropertyNode::
create( | 498 RefPtr<TransformPaintPropertyNode> transform2 = TransformPaintPropertyNode::
create( |
| 499 TransformationMatrix().translate(5, 5), FloatPoint3D(), transform1); | 499 transform1, TransformationMatrix().translate(5, 5), FloatPoint3D()); |
| 500 | 500 |
| 501 TestPaintArtifact artifact; | 501 TestPaintArtifact artifact; |
| 502 artifact.chunk(transform1, nullptr, dummyRootEffect()) | 502 artifact.chunk(transform1, nullptr, dummyRootEffect()) |
| 503 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); | 503 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); |
| 504 artifact.chunk(transform2, nullptr, dummyRootEffect()) | 504 artifact.chunk(transform2, nullptr, dummyRootEffect()) |
| 505 .rectDrawing(FloatRect(0, 0, 300, 200), Color::black); | 505 .rectDrawing(FloatRect(0, 0, 300, 200), Color::black); |
| 506 update(artifact.build()); | 506 update(artifact.build()); |
| 507 | 507 |
| 508 ASSERT_EQ(2u, contentLayerCount()); | 508 ASSERT_EQ(2u, contentLayerCount()); |
| 509 { | 509 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 523 EXPECT_EQ(gfx::RectF(0, 0, 600, 400), mappedRect); | 523 EXPECT_EQ(gfx::RectF(0, 0, 600, 400), mappedRect); |
| 524 } | 524 } |
| 525 EXPECT_NE( | 525 EXPECT_NE( |
| 526 contentLayerAt(0)->transform_tree_index(), | 526 contentLayerAt(0)->transform_tree_index(), |
| 527 contentLayerAt(1)->transform_tree_index()); | 527 contentLayerAt(1)->transform_tree_index()); |
| 528 } | 528 } |
| 529 | 529 |
| 530 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneClip) | 530 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneClip) |
| 531 { | 531 { |
| 532 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( | 532 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 533 nullptr, FloatRoundedRect(100, 100, 300, 200)); | 533 nullptr, nullptr, FloatRoundedRect(100, 100, 300, 200)); |
| 534 | 534 |
| 535 TestPaintArtifact artifact; | 535 TestPaintArtifact artifact; |
| 536 artifact.chunk(nullptr, clip, nullptr) | 536 artifact.chunk(nullptr, clip, nullptr) |
| 537 .rectDrawing(FloatRect(220, 80, 300, 200), Color::black); | 537 .rectDrawing(FloatRect(220, 80, 300, 200), Color::black); |
| 538 update(artifact.build()); | 538 update(artifact.build()); |
| 539 | 539 |
| 540 ASSERT_EQ(1u, contentLayerCount()); | 540 ASSERT_EQ(1u, contentLayerCount()); |
| 541 const cc::Layer* layer = contentLayerAt(0); | 541 const cc::Layer* layer = contentLayerAt(0); |
| 542 EXPECT_THAT(layer->GetPicture(), | 542 EXPECT_THAT(layer->GetPicture(), |
| 543 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); | 543 Pointee(drawsRectangle(FloatRect(0, 0, 300, 200), Color::black))); |
| 544 EXPECT_EQ(translation(220, 80), layer->screen_space_transform()); | 544 EXPECT_EQ(translation(220, 80), layer->screen_space_transform()); |
| 545 | 545 |
| 546 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(layer->clip_tr
ee_index()); | 546 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(layer->clip_tr
ee_index()); |
| 547 EXPECT_TRUE(clipNode->applies_local_clip); | 547 EXPECT_TRUE(clipNode->applies_local_clip); |
| 548 EXPECT_TRUE(clipNode->layers_are_clipped); | 548 EXPECT_TRUE(clipNode->layers_are_clipped); |
| 549 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); | 549 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); |
| 550 } | 550 } |
| 551 | 551 |
| 552 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) | 552 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) |
| 553 { | 553 { |
| 554 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 554 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 555 nullptr, FloatRoundedRect(100, 100, 700, 700)); | 555 nullptr, nullptr, FloatRoundedRect(100, 100, 700, 700)); |
| 556 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( | 556 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
| 557 nullptr, FloatRoundedRect(200, 200, 700, 100), clip1); | 557 clip1, nullptr, FloatRoundedRect(200, 200, 700, 100)); |
| 558 | 558 |
| 559 TestPaintArtifact artifact; | 559 TestPaintArtifact artifact; |
| 560 artifact.chunk(nullptr, clip1, dummyRootEffect()) | 560 artifact.chunk(nullptr, clip1, dummyRootEffect()) |
| 561 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white); | 561 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white); |
| 562 artifact.chunk(nullptr, clip2, dummyRootEffect()) | 562 artifact.chunk(nullptr, clip2, dummyRootEffect()) |
| 563 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray); | 563 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray); |
| 564 artifact.chunk(nullptr, clip1, dummyRootEffect()) | 564 artifact.chunk(nullptr, clip1, dummyRootEffect()) |
| 565 .rectDrawing(FloatRect(300, 350, 100, 100), Color::darkGray); | 565 .rectDrawing(FloatRect(300, 350, 100, 100), Color::darkGray); |
| 566 artifact.chunk(nullptr, clip2, dummyRootEffect()) | 566 artifact.chunk(nullptr, clip2, dummyRootEffect()) |
| 567 .rectDrawing(FloatRect(300, 350, 100, 100), Color::black); | 567 .rectDrawing(FloatRect(300, 350, 100, 100), Color::black); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 EXPECT_TRUE(innerClip->layers_are_clipped); | 601 EXPECT_TRUE(innerClip->layers_are_clipped); |
| 602 EXPECT_EQ(gfx::RectF(200, 200, 700, 100), innerClip->clip); | 602 EXPECT_EQ(gfx::RectF(200, 200, 700, 100), innerClip->clip); |
| 603 EXPECT_EQ(outerClip->id, innerClip->parent_id); | 603 EXPECT_EQ(outerClip->id, innerClip->parent_id); |
| 604 } | 604 } |
| 605 | 605 |
| 606 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips) | 606 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, DeeplyNestedClips) |
| 607 { | 607 { |
| 608 Vector<RefPtr<ClipPaintPropertyNode>> clips; | 608 Vector<RefPtr<ClipPaintPropertyNode>> clips; |
| 609 for (unsigned i = 1; i <= 10; i++) { | 609 for (unsigned i = 1; i <= 10; i++) { |
| 610 clips.append(ClipPaintPropertyNode::create( | 610 clips.append(ClipPaintPropertyNode::create( |
| 611 nullptr, FloatRoundedRect(5 * i, 0, 100, 200 - 10 * i), | 611 clips.isEmpty() ? nullptr : clips.last(), |
| 612 clips.isEmpty() ? nullptr : clips.last())); | 612 nullptr, FloatRoundedRect(5 * i, 0, 100, 200 - 10 * i))); |
| 613 } | 613 } |
| 614 | 614 |
| 615 TestPaintArtifact artifact; | 615 TestPaintArtifact artifact; |
| 616 artifact.chunk(nullptr, clips.last(), dummyRootEffect()) | 616 artifact.chunk(nullptr, clips.last(), dummyRootEffect()) |
| 617 .rectDrawing(FloatRect(0, 0, 200, 200), Color::white); | 617 .rectDrawing(FloatRect(0, 0, 200, 200), Color::white); |
| 618 update(artifact.build()); | 618 update(artifact.build()); |
| 619 | 619 |
| 620 // Check the drawing layer. | 620 // Check the drawing layer. |
| 621 ASSERT_EQ(1u, contentLayerCount()); | 621 ASSERT_EQ(1u, contentLayerCount()); |
| 622 const cc::Layer* drawingLayer = contentLayerAt(0); | 622 const cc::Layer* drawingLayer = contentLayerAt(0); |
| 623 EXPECT_THAT(drawingLayer->GetPicture(), | 623 EXPECT_THAT(drawingLayer->GetPicture(), |
| 624 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); | 624 Pointee(drawsRectangle(FloatRect(0, 0, 200, 200), Color::white))); |
| 625 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform()); | 625 EXPECT_EQ(gfx::Transform(), drawingLayer->screen_space_transform()); |
| 626 | 626 |
| 627 // Check the clip nodes. | 627 // Check the clip nodes. |
| 628 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(drawingLayer->
clip_tree_index()); | 628 const cc::ClipNode* clipNode = propertyTrees().clip_tree.Node(drawingLayer->
clip_tree_index()); |
| 629 for (auto it = clips.rbegin(); it != clips.rend(); ++it) { | 629 for (auto it = clips.rbegin(); it != clips.rend(); ++it) { |
| 630 const ClipPaintPropertyNode* paintClipNode = it->get(); | 630 const ClipPaintPropertyNode* paintClipNode = it->get(); |
| 631 EXPECT_TRUE(clipNode->applies_local_clip); | 631 EXPECT_TRUE(clipNode->applies_local_clip); |
| 632 EXPECT_TRUE(clipNode->layers_are_clipped); | 632 EXPECT_TRUE(clipNode->layers_are_clipped); |
| 633 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->clip); | 633 EXPECT_EQ(paintClipNode->clipRect().rect(), clipNode->clip); |
| 634 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id); | 634 clipNode = propertyTrees().clip_tree.Node(clipNode->parent_id); |
| 635 } | 635 } |
| 636 } | 636 } |
| 637 | 637 |
| 638 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips) | 638 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SiblingClips) |
| 639 { | 639 { |
| 640 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( | 640 RefPtr<ClipPaintPropertyNode> commonClip = ClipPaintPropertyNode::create( |
| 641 nullptr, FloatRoundedRect(0, 0, 800, 600)); | 641 nullptr, nullptr, FloatRoundedRect(0, 0, 800, 600)); |
| 642 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 642 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 643 nullptr, FloatRoundedRect(0, 0, 400, 600), commonClip); | 643 commonClip, nullptr, FloatRoundedRect(0, 0, 400, 600)); |
| 644 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( | 644 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
| 645 nullptr, FloatRoundedRect(400, 0, 400, 600), commonClip); | 645 commonClip, nullptr, FloatRoundedRect(400, 0, 400, 600)); |
| 646 | 646 |
| 647 TestPaintArtifact artifact; | 647 TestPaintArtifact artifact; |
| 648 artifact.chunk(nullptr, clip1, dummyRootEffect()) | 648 artifact.chunk(nullptr, clip1, dummyRootEffect()) |
| 649 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white); | 649 .rectDrawing(FloatRect(0, 0, 640, 480), Color::white); |
| 650 artifact.chunk(nullptr, clip2, dummyRootEffect()) | 650 artifact.chunk(nullptr, clip2, dummyRootEffect()) |
| 651 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black); | 651 .rectDrawing(FloatRect(0, 0, 640, 480), Color::black); |
| 652 update(artifact.build()); | 652 update(artifact.build()); |
| 653 | 653 |
| 654 ASSERT_EQ(2u, contentLayerCount()); | 654 ASSERT_EQ(2u, contentLayerCount()); |
| 655 | 655 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 update(artifact.build()); | 688 update(artifact.build()); |
| 689 | 689 |
| 690 ASSERT_EQ(1u, contentLayerCount()); | 690 ASSERT_EQ(1u, contentLayerCount()); |
| 691 EXPECT_EQ(layer, contentLayerAt(0)); | 691 EXPECT_EQ(layer, contentLayerAt(0)); |
| 692 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); | 692 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); |
| 693 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); | 693 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); |
| 694 } | 694 } |
| 695 | 695 |
| 696 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) | 696 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) |
| 697 { | 697 { |
| 698 RefPtr<EffectPaintPropertyNode> effect1 = EffectPaintPropertyNode::create(0.
5, dummyRootEffect()); | 698 RefPtr<EffectPaintPropertyNode> effect1 = EffectPaintPropertyNode::create(du
mmyRootEffect(), 0.5); |
| 699 RefPtr<EffectPaintPropertyNode> effect2 = EffectPaintPropertyNode::create(0.
3, effect1.get()); | 699 RefPtr<EffectPaintPropertyNode> effect2 = EffectPaintPropertyNode::create(ef
fect1, 0.3); |
| 700 RefPtr<EffectPaintPropertyNode> effect3 = EffectPaintPropertyNode::create(0.
2, dummyRootEffect()); | 700 RefPtr<EffectPaintPropertyNode> effect3 = EffectPaintPropertyNode::create(du
mmyRootEffect(), 0.2); |
| 701 | 701 |
| 702 TestPaintArtifact artifact; | 702 TestPaintArtifact artifact; |
| 703 artifact.chunk(nullptr, nullptr, effect2.get()) | 703 artifact.chunk(nullptr, nullptr, effect2.get()) |
| 704 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | 704 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 705 artifact.chunk(nullptr, nullptr, effect1.get()) | 705 artifact.chunk(nullptr, nullptr, effect1.get()) |
| 706 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | 706 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 707 artifact.chunk(nullptr, nullptr, effect3.get()) | 707 artifact.chunk(nullptr, nullptr, effect3.get()) |
| 708 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | 708 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 709 update(artifact.build()); | 709 update(artifact.build()); |
| 710 | 710 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 730 EXPECT_EQ(convertedDummyRootEffect.id, convertedEffect3.parent_id); | 730 EXPECT_EQ(convertedDummyRootEffect.id, convertedEffect3.parent_id); |
| 731 EXPECT_FLOAT_EQ(0.2, convertedEffect3.opacity); | 731 EXPECT_FLOAT_EQ(0.2, convertedEffect3.opacity); |
| 732 | 732 |
| 733 EXPECT_EQ(convertedEffect2.id, contentLayerAt(0)->effect_tree_index()); | 733 EXPECT_EQ(convertedEffect2.id, contentLayerAt(0)->effect_tree_index()); |
| 734 EXPECT_EQ(convertedEffect1.id, contentLayerAt(1)->effect_tree_index()); | 734 EXPECT_EQ(convertedEffect1.id, contentLayerAt(1)->effect_tree_index()); |
| 735 EXPECT_EQ(convertedEffect3.id, contentLayerAt(2)->effect_tree_index()); | 735 EXPECT_EQ(convertedEffect3.id, contentLayerAt(2)->effect_tree_index()); |
| 736 } | 736 } |
| 737 | 737 |
| 738 } // namespace | 738 } // namespace |
| 739 } // namespace blink | 739 } // namespace blink |
| OLD | NEW |