solid_color_layer_impl_unittest.cc revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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 RenderSurfaceLayerList render_surface_layer_list; 113 LayerTreeHostCommon::CalculateDrawProperties(root.get(), 114 gfx::Size(500, 500), 115 gfx::Transform(), 116 1.f, 117 1.f, 118 NULL, 119 1024, 120 false, 121 false, 122 &render_surface_layer_list); 123 124 EXPECT_FALSE(layer->contents_opaque()); 125 layer->SetBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); 126 EXPECT_TRUE(layer->contents_opaque()); 127 { 128 scoped_ptr<SolidColorLayerImpl> layer_impl = 129 SolidColorLayerImpl::Create(host_impl.active_tree(), layer->id()); 130 layer->PushPropertiesTo(layer_impl.get()); 131 132 // The impl layer should call itself opaque as well. 133 EXPECT_TRUE(layer_impl->contents_opaque()); 134 135 // Impl layer has 1 opacity, and the color is opaque, so the opaque_rect 136 // should be the full tile. 137 layer_impl->draw_properties().opacity = 1; 138 139 MockQuadCuller quad_culler; 140 AppendQuadsData data; 141 layer_impl->AppendQuads(&quad_culler, &data); 142 143 ASSERT_EQ(quad_culler.quad_list().size(), 1U); 144 EXPECT_EQ(visible_content_rect.ToString(), 145 quad_culler.quad_list()[0]->opaque_rect.ToString()); 146 } 147 148 EXPECT_TRUE(layer->contents_opaque()); 149 layer->SetBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); 150 EXPECT_FALSE(layer->contents_opaque()); 151 { 152 scoped_ptr<SolidColorLayerImpl> layer_impl = 153 SolidColorLayerImpl::Create(host_impl.active_tree(), layer->id()); 154 layer->PushPropertiesTo(layer_impl.get()); 155 156 // The impl layer should callnot itself opaque anymore. 157 EXPECT_FALSE(layer_impl->contents_opaque()); 158 159 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_rect 160 // should be empty. 161 layer_impl->draw_properties().opacity = 1; 162 163 MockQuadCuller quad_culler; 164 AppendQuadsData data; 165 layer_impl->AppendQuads(&quad_culler, &data); 166 167 ASSERT_EQ(quad_culler.quad_list().size(), 1U); 168 EXPECT_EQ(gfx::Rect().ToString(), 169 quad_culler.quad_list()[0]->opaque_rect.ToString()); 170 } 171} 172 173} // namespace 174} // namespace cc 175