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.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 gfx::Size layer_size = gfx::Size(100, 100); 100 gfx::Rect visible_content_rect = gfx::Rect(layer_size); 101 102 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create(); 103 layer->SetBounds(layer_size); 104 layer->SetForceRenderSurface(true); 105 106 scoped_refptr<Layer> root = Layer::Create(); 107 root->AddChild(layer); 108 109 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 110 host->SetRootLayer(root); 111 112 RenderSurfaceLayerList render_surface_layer_list; 113 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 114 root, gfx::Size(500, 500), &render_surface_layer_list); 115 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 116 117 EXPECT_FALSE(layer->contents_opaque()); 118 layer->SetBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); 119 EXPECT_TRUE(layer->contents_opaque()); 120 { 121 scoped_ptr<SolidColorLayerImpl> layer_impl = 122 SolidColorLayerImpl::Create(host->host_impl()->active_tree(), 123 layer->id()); 124 layer->PushPropertiesTo(layer_impl.get()); 125 126 // The impl layer should call itself opaque as well. 127 EXPECT_TRUE(layer_impl->contents_opaque()); 128 129 // Impl layer has 1 opacity, and the color is opaque, so the opaque_rect 130 // should be the full tile. 131 layer_impl->draw_properties().opacity = 1; 132 133 MockQuadCuller quad_culler; 134 AppendQuadsData data; 135 layer_impl->AppendQuads(&quad_culler, &data); 136 137 ASSERT_EQ(quad_culler.quad_list().size(), 1U); 138 EXPECT_EQ(visible_content_rect.ToString(), 139 quad_culler.quad_list()[0]->opaque_rect.ToString()); 140 } 141 142 EXPECT_TRUE(layer->contents_opaque()); 143 layer->SetBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); 144 EXPECT_FALSE(layer->contents_opaque()); 145 { 146 scoped_ptr<SolidColorLayerImpl> layer_impl = 147 SolidColorLayerImpl::Create(host->host_impl()->active_tree(), 148 layer->id()); 149 layer->PushPropertiesTo(layer_impl.get()); 150 151 // The impl layer should callnot itself opaque anymore. 152 EXPECT_FALSE(layer_impl->contents_opaque()); 153 154 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_rect 155 // should be empty. 156 layer_impl->draw_properties().opacity = 1; 157 158 MockQuadCuller quad_culler; 159 AppendQuadsData data; 160 layer_impl->AppendQuads(&quad_culler, &data); 161 162 ASSERT_EQ(quad_culler.quad_list().size(), 1U); 163 EXPECT_EQ(gfx::Rect().ToString(), 164 quad_culler.quad_list()[0]->opaque_rect.ToString()); 165 } 166} 167 168} // namespace 169} // namespace cc 170