solid_color_layer_impl_unittest.cc revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
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 3// found in the LICENSE file. 4 5#include "cc/layers/solid_color_layer_impl.h" 6 7#include <vector> 8 9#include "cc/layers/append_quads_data.h" 10#include "cc/layers/solid_color_layer.h" 11#include "cc/quads/solid_color_draw_quad.h" 12#include "cc/test/fake_impl_proxy.h" 13#include "cc/test/fake_layer_tree_host_impl.h" 14#include "cc/test/layer_test_common.h" 15#include "cc/test/mock_quad_culler.h" 16#include "cc/trees/single_thread_proxy.h" 17#include "testing/gmock/include/gmock/gmock.h" 18#include "testing/gtest/include/gtest/gtest.h" 19 20namespace cc { 21namespace { 22 23TEST(SolidColorLayerImplTest, VerifyTilingCompleteAndNoOverlap) { 24 MockQuadCuller quad_culler; 25 gfx::Size layer_size = gfx::Size(800, 600); 26 gfx::Rect visible_content_rect = gfx::Rect(layer_size); 27 28 FakeImplProxy proxy; 29 FakeLayerTreeHostImpl host_impl(&proxy); 30 scoped_ptr<SolidColorLayerImpl> layer = 31 SolidColorLayerImpl::Create(host_impl.active_tree(), 1); 32 layer->draw_properties().visible_content_rect = visible_content_rect; 33 layer->SetBounds(layer_size); 34 layer->SetContentBounds(layer_size); 35 layer->CreateRenderSurface(); 36 layer->draw_properties().render_target = layer.get(); 37 38 AppendQuadsData data; 39 layer->AppendQuads(&quad_culler, &data); 40 41 LayerTestCommon::VerifyQuadsExactlyCoverRect(quad_culler.quad_list(), 42 visible_content_rect); 43} 44 45TEST(SolidColorLayerImplTest, VerifyCorrectBackgroundColorInQuad) { 46 SkColor test_color = 0xFFA55AFF; 47 48 MockQuadCuller quad_culler; 49 gfx::Size layer_size = gfx::Size(100, 100); 50 gfx::Rect visible_content_rect = gfx::Rect(layer_size); 51 52 FakeImplProxy proxy; 53 FakeLayerTreeHostImpl host_impl(&proxy); 54 scoped_ptr<SolidColorLayerImpl> layer = 55 SolidColorLayerImpl::Create(host_impl.active_tree(), 1); 56 layer->draw_properties().visible_content_rect = visible_content_rect; 57 layer->SetBounds(layer_size); 58 layer->SetContentBounds(layer_size); 59 layer->SetBackgroundColor(test_color); 60 layer->CreateRenderSurface(); 61 layer->draw_properties().render_target = layer.get(); 62 63 AppendQuadsData data; 64 layer->AppendQuads(&quad_culler, &data); 65 66 ASSERT_EQ(quad_culler.quad_list().size(), 1U); 67 EXPECT_EQ(SolidColorDrawQuad::MaterialCast(quad_culler.quad_list()[0])->color, 68 test_color); 69} 70 71TEST(SolidColorLayerImplTest, VerifyCorrectOpacityInQuad) { 72 const float opacity = 0.5f; 73 74 MockQuadCuller quad_culler; 75 gfx::Size layer_size = gfx::Size(100, 100); 76 gfx::Rect visible_content_rect = gfx::Rect(layer_size); 77 78 FakeImplProxy proxy; 79 FakeLayerTreeHostImpl host_impl(&proxy); 80 scoped_ptr<SolidColorLayerImpl> layer = 81 SolidColorLayerImpl::Create(host_impl.active_tree(), 1); 82 layer->draw_properties().visible_content_rect = visible_content_rect; 83 layer->SetBounds(layer_size); 84 layer->SetContentBounds(layer_size); 85 layer->draw_properties().opacity = opacity; 86 layer->CreateRenderSurface(); 87 layer->draw_properties().render_target = layer.get(); 88 89 AppendQuadsData data; 90 layer->AppendQuads(&quad_culler, &data); 91 92 ASSERT_EQ(quad_culler.quad_list().size(), 1U); 93 EXPECT_EQ(opacity, 94 SolidColorDrawQuad::MaterialCast(quad_culler.quad_list()[0]) 95 ->opacity()); 96} 97 98TEST(SolidColorLayerImplTest, VerifyOpaqueRect) { 99 FakeImplProxy proxy; 100 FakeLayerTreeHostImpl host_impl(&proxy); 101 102 gfx::Size layer_size = gfx::Size(100, 100); 103 gfx::Rect visible_content_rect = gfx::Rect(layer_size); 104 105 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create(); 106 layer->SetBounds(layer_size); 107 layer->SetForceRenderSurface(true); 108 109 scoped_refptr<Layer> root = Layer::Create(); 110 root->AddChild(layer); 111 112 LayerList render_surface_layer_list; 113 LayerTreeHostCommon::CalculateDrawProperties(root, 114 gfx::Size(500, 500), 115 1.f, 116 1.f, 117 NULL, 118 1024, 119 false, 120 false, 121 &render_surface_layer_list); 122 123 EXPECT_FALSE(layer->contents_opaque()); 124 layer->SetBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); 125 EXPECT_TRUE(layer->contents_opaque()); 126 { 127 scoped_ptr<SolidColorLayerImpl> layer_impl = 128 SolidColorLayerImpl::Create(host_impl.active_tree(), layer->id()); 129 layer->PushPropertiesTo(layer_impl.get()); 130 131 // The impl layer should call itself opaque as well. 132 EXPECT_TRUE(layer_impl->contents_opaque()); 133 134 // Impl layer has 1 opacity, and the color is opaque, so the opaque_rect 135 // should be the full tile. 136 layer_impl->draw_properties().opacity = 1; 137 138 MockQuadCuller quad_culler; 139 AppendQuadsData data; 140 layer_impl->AppendQuads(&quad_culler, &data); 141 142 ASSERT_EQ(quad_culler.quad_list().size(), 1U); 143 EXPECT_EQ(visible_content_rect.ToString(), 144 quad_culler.quad_list()[0]->opaque_rect.ToString()); 145 } 146 147 EXPECT_TRUE(layer->contents_opaque()); 148 layer->SetBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); 149 EXPECT_FALSE(layer->contents_opaque()); 150 { 151 scoped_ptr<SolidColorLayerImpl> layer_impl = 152 SolidColorLayerImpl::Create(host_impl.active_tree(), layer->id()); 153 layer->PushPropertiesTo(layer_impl.get()); 154 155 // The impl layer should callnot itself opaque anymore. 156 EXPECT_FALSE(layer_impl->contents_opaque()); 157 158 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_rect 159 // should be empty. 160 layer_impl->draw_properties().opacity = 1; 161 162 MockQuadCuller quad_culler; 163 AppendQuadsData data; 164 layer_impl->AppendQuads(&quad_culler, &data); 165 166 ASSERT_EQ(quad_culler.quad_list().size(), 1U); 167 EXPECT_EQ(gfx::Rect().ToString(), 168 quad_culler.quad_list()[0]->opaque_rect.ToString()); 169 } 170} 171 172} // namespace 173} // namespace cc 174