| 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" | 11 #include "cc/test/fake_impl_proxy.h" |
| 12 #include "cc/test/fake_layer_tree_host_impl.h" | 12 #include "cc/test/fake_layer_tree_host_impl.h" |
| 13 #include "cc/test/layer_test_common.h" | 13 #include "cc/test/layer_test_common.h" |
| 14 #include "cc/test/mock_quad_culler.h" | 14 #include "cc/test/mock_quad_culler.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) | 21 TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) |
| 22 { | 22 { |
| 23 MockQuadCuller quadCuller; | 23 MockQuadCuller quadCuller; |
| 24 gfx::Size layerSize = gfx::Size(800, 600); | 24 gfx::Size layerSize = gfx::Size(800, 600); |
| 25 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 25 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
| 26 | 26 |
| 27 FakeImplProxy proxy; | 27 FakeImplProxy proxy; |
| 28 FakeLayerTreeHostImpl hostImpl(&proxy); | 28 FakeLayerTreeHostImpl hostImpl(&proxy); |
| 29 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.activeTree(), 1); | 29 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.active_tree(), 1); |
| 30 layer->draw_properties().visible_content_rect = visibleContentRect; | 30 layer->draw_properties().visible_content_rect = visibleContentRect; |
| 31 layer->SetBounds(layerSize); | 31 layer->SetBounds(layerSize); |
| 32 layer->SetContentBounds(layerSize); | 32 layer->SetContentBounds(layerSize); |
| 33 layer->CreateRenderSurface(); | 33 layer->CreateRenderSurface(); |
| 34 layer->draw_properties().render_target = layer.get(); | 34 layer->draw_properties().render_target = layer.get(); |
| 35 | 35 |
| 36 AppendQuadsData data; | 36 AppendQuadsData data; |
| 37 layer->AppendQuads(&quadCuller, &data); | 37 layer->AppendQuads(&quadCuller, &data); |
| 38 | 38 |
| 39 LayerTestCommon::verifyQuadsExactlyCoverRect(quadCuller.quadList(), visibleC
ontentRect); | 39 LayerTestCommon::verifyQuadsExactlyCoverRect(quadCuller.quadList(), visibleC
ontentRect); |
| 40 } | 40 } |
| 41 | 41 |
| 42 TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) | 42 TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) |
| 43 { | 43 { |
| 44 SkColor testColor = 0xFFA55AFF; | 44 SkColor testColor = 0xFFA55AFF; |
| 45 | 45 |
| 46 MockQuadCuller quadCuller; | 46 MockQuadCuller quadCuller; |
| 47 gfx::Size layerSize = gfx::Size(100, 100); | 47 gfx::Size layerSize = gfx::Size(100, 100); |
| 48 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 48 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
| 49 | 49 |
| 50 FakeImplProxy proxy; | 50 FakeImplProxy proxy; |
| 51 FakeLayerTreeHostImpl hostImpl(&proxy); | 51 FakeLayerTreeHostImpl hostImpl(&proxy); |
| 52 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.activeTree(), 1); | 52 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.active_tree(), 1); |
| 53 layer->draw_properties().visible_content_rect = visibleContentRect; | 53 layer->draw_properties().visible_content_rect = visibleContentRect; |
| 54 layer->SetBounds(layerSize); | 54 layer->SetBounds(layerSize); |
| 55 layer->SetContentBounds(layerSize); | 55 layer->SetContentBounds(layerSize); |
| 56 layer->SetBackgroundColor(testColor); | 56 layer->SetBackgroundColor(testColor); |
| 57 layer->CreateRenderSurface(); | 57 layer->CreateRenderSurface(); |
| 58 layer->draw_properties().render_target = layer.get(); | 58 layer->draw_properties().render_target = layer.get(); |
| 59 | 59 |
| 60 AppendQuadsData data; | 60 AppendQuadsData data; |
| 61 layer->AppendQuads(&quadCuller, &data); | 61 layer->AppendQuads(&quadCuller, &data); |
| 62 | 62 |
| 63 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 63 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
| 64 EXPECT_EQ(SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0])->color,
testColor); | 64 EXPECT_EQ(SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0])->color,
testColor); |
| 65 } | 65 } |
| 66 | 66 |
| 67 TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) | 67 TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) |
| 68 { | 68 { |
| 69 const float opacity = 0.5f; | 69 const float opacity = 0.5f; |
| 70 | 70 |
| 71 MockQuadCuller quadCuller; | 71 MockQuadCuller quadCuller; |
| 72 gfx::Size layerSize = gfx::Size(100, 100); | 72 gfx::Size layerSize = gfx::Size(100, 100); |
| 73 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 73 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
| 74 | 74 |
| 75 FakeImplProxy proxy; | 75 FakeImplProxy proxy; |
| 76 FakeLayerTreeHostImpl hostImpl(&proxy); | 76 FakeLayerTreeHostImpl hostImpl(&proxy); |
| 77 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.activeTree(), 1); | 77 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.active_tree(), 1); |
| 78 layer->draw_properties().visible_content_rect = visibleContentRect; | 78 layer->draw_properties().visible_content_rect = visibleContentRect; |
| 79 layer->SetBounds(layerSize); | 79 layer->SetBounds(layerSize); |
| 80 layer->SetContentBounds(layerSize); | 80 layer->SetContentBounds(layerSize); |
| 81 layer->draw_properties().opacity = opacity; | 81 layer->draw_properties().opacity = opacity; |
| 82 layer->CreateRenderSurface(); | 82 layer->CreateRenderSurface(); |
| 83 layer->draw_properties().render_target = layer.get(); | 83 layer->draw_properties().render_target = layer.get(); |
| 84 | 84 |
| 85 AppendQuadsData data; | 85 AppendQuadsData data; |
| 86 layer->AppendQuads(&quadCuller, &data); | 86 layer->AppendQuads(&quadCuller, &data); |
| 87 | 87 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 112 1, | 112 1, |
| 113 1024, | 113 1024, |
| 114 false, | 114 false, |
| 115 renderSurfaceLayerList); | 115 renderSurfaceLayerList); |
| 116 | 116 |
| 117 EXPECT_FALSE(layer->contents_opaque()); | 117 EXPECT_FALSE(layer->contents_opaque()); |
| 118 layer->SetBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); | 118 layer->SetBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); |
| 119 EXPECT_TRUE(layer->contents_opaque()); | 119 EXPECT_TRUE(layer->contents_opaque()); |
| 120 | 120 |
| 121 { | 121 { |
| 122 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::Create(
hostImpl.activeTree(), layer->id()); | 122 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::Create(
hostImpl.active_tree(), layer->id()); |
| 123 layer->PushPropertiesTo(layerImpl.get()); | 123 layer->PushPropertiesTo(layerImpl.get()); |
| 124 | 124 |
| 125 // The impl layer should call itself opaque as well. | 125 // The impl layer should call itself opaque as well. |
| 126 EXPECT_TRUE(layerImpl->contents_opaque()); | 126 EXPECT_TRUE(layerImpl->contents_opaque()); |
| 127 | 127 |
| 128 // Impl layer has 1 opacity, and the color is opaque, so the opaqueRect
should be the full tile. | 128 // Impl layer has 1 opacity, and the color is opaque, so the opaqueRect
should be the full tile. |
| 129 layerImpl->draw_properties().opacity = 1; | 129 layerImpl->draw_properties().opacity = 1; |
| 130 | 130 |
| 131 MockQuadCuller quadCuller; | 131 MockQuadCuller quadCuller; |
| 132 AppendQuadsData data; | 132 AppendQuadsData data; |
| 133 layerImpl->AppendQuads(&quadCuller, &data); | 133 layerImpl->AppendQuads(&quadCuller, &data); |
| 134 | 134 |
| 135 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 135 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
| 136 EXPECT_EQ(visibleContentRect.ToString(), quadCuller.quadList()[0]->opaqu
e_rect.ToString()); | 136 EXPECT_EQ(visibleContentRect.ToString(), quadCuller.quadList()[0]->opaqu
e_rect.ToString()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 EXPECT_TRUE(layer->contents_opaque()); | 139 EXPECT_TRUE(layer->contents_opaque()); |
| 140 layer->SetBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); | 140 layer->SetBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); |
| 141 EXPECT_FALSE(layer->contents_opaque()); | 141 EXPECT_FALSE(layer->contents_opaque()); |
| 142 | 142 |
| 143 { | 143 { |
| 144 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::Create(
hostImpl.activeTree(), layer->id()); | 144 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::Create(
hostImpl.active_tree(), layer->id()); |
| 145 layer->PushPropertiesTo(layerImpl.get()); | 145 layer->PushPropertiesTo(layerImpl.get()); |
| 146 | 146 |
| 147 // The impl layer should callnot itself opaque anymore. | 147 // The impl layer should callnot itself opaque anymore. |
| 148 EXPECT_FALSE(layerImpl->contents_opaque()); | 148 EXPECT_FALSE(layerImpl->contents_opaque()); |
| 149 | 149 |
| 150 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_
rect should be empty. | 150 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_
rect should be empty. |
| 151 layerImpl->draw_properties().opacity = 1; | 151 layerImpl->draw_properties().opacity = 1; |
| 152 | 152 |
| 153 MockQuadCuller quadCuller; | 153 MockQuadCuller quadCuller; |
| 154 AppendQuadsData data; | 154 AppendQuadsData data; |
| 155 layerImpl->AppendQuads(&quadCuller, &data); | 155 layerImpl->AppendQuads(&quadCuller, &data); |
| 156 | 156 |
| 157 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 157 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
| 158 EXPECT_EQ(gfx::Rect().ToString(), quadCuller.quadList()[0]->opaque_rect.
ToString()); | 158 EXPECT_EQ(gfx::Rect().ToString(), quadCuller.quadList()[0]->opaque_rect.
ToString()); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace | 162 } // namespace |
| 163 } // namespace cc | 163 } // namespace cc |
| OLD | NEW |