| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/solid_color_layer_impl.h" | 5 #include "cc/solid_color_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/append_quads_data.h" | 7 #include "cc/append_quads_data.h" |
| 8 #include "cc/single_thread_proxy.h" | 8 #include "cc/single_thread_proxy.h" |
| 9 #include "cc/solid_color_draw_quad.h" | 9 #include "cc/solid_color_draw_quad.h" |
| 10 #include "cc/solid_color_layer.h" | 10 #include "cc/solid_color_layer.h" |
| 11 #include "cc/test/fake_impl_proxy.h" |
| 12 #include "cc/test/fake_layer_tree_host_impl.h" |
| 11 #include "cc/test/layer_test_common.h" | 13 #include "cc/test/layer_test_common.h" |
| 12 #include "cc/test/mock_quad_culler.h" | 14 #include "cc/test/mock_quad_culler.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 using namespace LayerTestCommon; | 18 using namespace LayerTestCommon; |
| 17 | 19 |
| 18 namespace cc { | 20 namespace cc { |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) | 23 TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) |
| 22 { | 24 { |
| 23 MockQuadCuller quadCuller; | 25 MockQuadCuller quadCuller; |
| 24 gfx::Size layerSize = gfx::Size(800, 600); | 26 gfx::Size layerSize = gfx::Size(800, 600); |
| 25 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 27 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
| 26 | 28 |
| 27 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); | 29 FakeImplProxy proxy; |
| 30 FakeLayerTreeHostImpl hostImpl(&proxy); |
| 31 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(&hostImp
l, 1); |
| 28 layer->drawProperties().visible_content_rect = visibleContentRect; | 32 layer->drawProperties().visible_content_rect = visibleContentRect; |
| 29 layer->setBounds(layerSize); | 33 layer->setBounds(layerSize); |
| 30 layer->setContentBounds(layerSize); | 34 layer->setContentBounds(layerSize); |
| 31 layer->createRenderSurface(); | 35 layer->createRenderSurface(); |
| 32 layer->drawProperties().render_target = layer.get(); | 36 layer->drawProperties().render_target = layer.get(); |
| 33 | 37 |
| 34 AppendQuadsData data; | 38 AppendQuadsData data; |
| 35 layer->appendQuads(quadCuller, data); | 39 layer->appendQuads(quadCuller, data); |
| 36 | 40 |
| 37 verifyQuadsExactlyCoverRect(quadCuller.quadList(), visibleContentRect); | 41 verifyQuadsExactlyCoverRect(quadCuller.quadList(), visibleContentRect); |
| 38 } | 42 } |
| 39 | 43 |
| 40 TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) | 44 TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) |
| 41 { | 45 { |
| 42 SkColor testColor = 0xFFA55AFF; | 46 SkColor testColor = 0xFFA55AFF; |
| 43 | 47 |
| 44 MockQuadCuller quadCuller; | 48 MockQuadCuller quadCuller; |
| 45 gfx::Size layerSize = gfx::Size(100, 100); | 49 gfx::Size layerSize = gfx::Size(100, 100); |
| 46 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 50 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
| 47 | 51 |
| 48 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); | 52 FakeImplProxy proxy; |
| 53 FakeLayerTreeHostImpl hostImpl(&proxy); |
| 54 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(&hostImp
l, 1); |
| 49 layer->drawProperties().visible_content_rect = visibleContentRect; | 55 layer->drawProperties().visible_content_rect = visibleContentRect; |
| 50 layer->setBounds(layerSize); | 56 layer->setBounds(layerSize); |
| 51 layer->setContentBounds(layerSize); | 57 layer->setContentBounds(layerSize); |
| 52 layer->setBackgroundColor(testColor); | 58 layer->setBackgroundColor(testColor); |
| 53 layer->createRenderSurface(); | 59 layer->createRenderSurface(); |
| 54 layer->drawProperties().render_target = layer.get(); | 60 layer->drawProperties().render_target = layer.get(); |
| 55 | 61 |
| 56 AppendQuadsData data; | 62 AppendQuadsData data; |
| 57 layer->appendQuads(quadCuller, data); | 63 layer->appendQuads(quadCuller, data); |
| 58 | 64 |
| 59 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 65 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
| 60 EXPECT_EQ(SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0])->color,
testColor); | 66 EXPECT_EQ(SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0])->color,
testColor); |
| 61 } | 67 } |
| 62 | 68 |
| 63 TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) | 69 TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) |
| 64 { | 70 { |
| 65 const float opacity = 0.5f; | 71 const float opacity = 0.5f; |
| 66 | 72 |
| 67 MockQuadCuller quadCuller; | 73 MockQuadCuller quadCuller; |
| 68 gfx::Size layerSize = gfx::Size(100, 100); | 74 gfx::Size layerSize = gfx::Size(100, 100); |
| 69 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 75 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
| 70 | 76 |
| 71 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); | 77 FakeImplProxy proxy; |
| 78 FakeLayerTreeHostImpl hostImpl(&proxy); |
| 79 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(&hostImp
l, 1); |
| 72 layer->drawProperties().visible_content_rect = visibleContentRect; | 80 layer->drawProperties().visible_content_rect = visibleContentRect; |
| 73 layer->setBounds(layerSize); | 81 layer->setBounds(layerSize); |
| 74 layer->setContentBounds(layerSize); | 82 layer->setContentBounds(layerSize); |
| 75 layer->drawProperties().opacity = opacity; | 83 layer->drawProperties().opacity = opacity; |
| 76 layer->createRenderSurface(); | 84 layer->createRenderSurface(); |
| 77 layer->drawProperties().render_target = layer.get(); | 85 layer->drawProperties().render_target = layer.get(); |
| 78 | 86 |
| 79 AppendQuadsData data; | 87 AppendQuadsData data; |
| 80 layer->appendQuads(quadCuller, data); | 88 layer->appendQuads(quadCuller, data); |
| 81 | 89 |
| 82 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 90 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
| 83 EXPECT_EQ(opacity, SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0]
)->opacity()); | 91 EXPECT_EQ(opacity, SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0]
)->opacity()); |
| 84 } | 92 } |
| 85 | 93 |
| 86 TEST(SolidColorLayerImplTest, verifyOpaqueRect) | 94 TEST(SolidColorLayerImplTest, verifyOpaqueRect) |
| 87 { | 95 { |
| 96 FakeImplProxy proxy; |
| 97 FakeLayerTreeHostImpl hostImpl(&proxy); |
| 98 |
| 88 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create(); | 99 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create(); |
| 89 gfx::Size layerSize = gfx::Size(100, 100); | 100 gfx::Size layerSize = gfx::Size(100, 100); |
| 90 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 101 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
| 91 | 102 |
| 92 layer->drawProperties().visible_content_rect = visibleContentRect; | 103 layer->drawProperties().visible_content_rect = visibleContentRect; |
| 93 layer->setBounds(layerSize); | 104 layer->setBounds(layerSize); |
| 94 layer->createRenderSurface(); | 105 layer->createRenderSurface(); |
| 95 layer->drawProperties().render_target = layer.get(); | 106 layer->drawProperties().render_target = layer.get(); |
| 96 | 107 |
| 97 EXPECT_FALSE(layer->contentsOpaque()); | 108 EXPECT_FALSE(layer->contentsOpaque()); |
| 98 layer->setBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); | 109 layer->setBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); |
| 99 EXPECT_TRUE(layer->contentsOpaque()); | 110 EXPECT_TRUE(layer->contentsOpaque()); |
| 100 | 111 |
| 101 { | 112 { |
| 102 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(
layer->id()); | 113 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(
&hostImpl, layer->id()); |
| 103 layer->pushPropertiesTo(layerImpl.get()); | 114 layer->pushPropertiesTo(layerImpl.get()); |
| 104 | 115 |
| 105 // The impl layer should call itself opaque as well. | 116 // The impl layer should call itself opaque as well. |
| 106 EXPECT_TRUE(layerImpl->contentsOpaque()); | 117 EXPECT_TRUE(layerImpl->contentsOpaque()); |
| 107 | 118 |
| 108 // Impl layer has 1 opacity, and the color is opaque, so the opaqueRect
should be the full tile. | 119 // Impl layer has 1 opacity, and the color is opaque, so the opaqueRect
should be the full tile. |
| 109 layerImpl->drawProperties().opacity = 1; | 120 layerImpl->drawProperties().opacity = 1; |
| 110 | 121 |
| 111 MockQuadCuller quadCuller; | 122 MockQuadCuller quadCuller; |
| 112 AppendQuadsData data; | 123 AppendQuadsData data; |
| 113 layerImpl->appendQuads(quadCuller, data); | 124 layerImpl->appendQuads(quadCuller, data); |
| 114 | 125 |
| 115 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 126 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
| 116 EXPECT_EQ(visibleContentRect.ToString(), quadCuller.quadList()[0]->opaqu
e_rect.ToString()); | 127 EXPECT_EQ(visibleContentRect.ToString(), quadCuller.quadList()[0]->opaqu
e_rect.ToString()); |
| 117 } | 128 } |
| 118 | 129 |
| 119 EXPECT_TRUE(layer->contentsOpaque()); | 130 EXPECT_TRUE(layer->contentsOpaque()); |
| 120 layer->setBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); | 131 layer->setBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); |
| 121 EXPECT_FALSE(layer->contentsOpaque()); | 132 EXPECT_FALSE(layer->contentsOpaque()); |
| 122 | 133 |
| 123 { | 134 { |
| 124 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(
layer->id()); | 135 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(
&hostImpl, layer->id()); |
| 125 layer->pushPropertiesTo(layerImpl.get()); | 136 layer->pushPropertiesTo(layerImpl.get()); |
| 126 | 137 |
| 127 // The impl layer should callnot itself opaque anymore. | 138 // The impl layer should callnot itself opaque anymore. |
| 128 EXPECT_FALSE(layerImpl->contentsOpaque()); | 139 EXPECT_FALSE(layerImpl->contentsOpaque()); |
| 129 | 140 |
| 130 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_
rect should be empty. | 141 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_
rect should be empty. |
| 131 layerImpl->drawProperties().opacity = 1; | 142 layerImpl->drawProperties().opacity = 1; |
| 132 | 143 |
| 133 MockQuadCuller quadCuller; | 144 MockQuadCuller quadCuller; |
| 134 AppendQuadsData data; | 145 AppendQuadsData data; |
| 135 layerImpl->appendQuads(quadCuller, data); | 146 layerImpl->appendQuads(quadCuller, data); |
| 136 | 147 |
| 137 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 148 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
| 138 EXPECT_EQ(gfx::Rect().ToString(), quadCuller.quadList()[0]->opaque_rect.
ToString()); | 149 EXPECT_EQ(gfx::Rect().ToString(), quadCuller.quadList()[0]->opaque_rect.
ToString()); |
| 139 } | 150 } |
| 140 } | 151 } |
| 141 | 152 |
| 142 } // namespace | 153 } // namespace |
| 143 } // namespace cc | 154 } // namespace cc |
| OLD | NEW |