Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / cc / layers / ui_resource_layer_impl_unittest.cc
blobb725e6d44e9c27ace67cadbba0014a4ca832affd
1 // Copyright 2013 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.
5 #include "cc/layers/append_quads_data.h"
6 #include "cc/layers/ui_resource_layer_impl.h"
7 #include "cc/quads/draw_quad.h"
8 #include "cc/resources/ui_resource_bitmap.h"
9 #include "cc/resources/ui_resource_client.h"
10 #include "cc/test/fake_impl_proxy.h"
11 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_ui_resource_layer_tree_host_impl.h"
14 #include "cc/test/layer_test_common.h"
15 #include "cc/test/test_shared_bitmap_manager.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 #include "ui/gfx/transform.h"
21 namespace cc {
22 namespace {
24 scoped_ptr<UIResourceLayerImpl> GenerateUIResourceLayer(
25 FakeUIResourceLayerTreeHostImpl* host_impl,
26 const gfx::Size& bitmap_size,
27 const gfx::Size& layer_size,
28 bool opaque,
29 UIResourceId uid) {
30 gfx::Rect visible_content_rect(layer_size);
31 scoped_ptr<UIResourceLayerImpl> layer =
32 UIResourceLayerImpl::Create(host_impl->active_tree(), 1);
33 layer->draw_properties().visible_content_rect = visible_content_rect;
34 layer->SetBounds(layer_size);
35 layer->SetContentBounds(layer_size);
36 layer->SetHasRenderSurface(true);
37 layer->draw_properties().render_target = layer.get();
39 UIResourceBitmap bitmap(bitmap_size, opaque);
41 host_impl->CreateUIResource(uid, bitmap);
42 layer->SetUIResourceId(uid);
44 return layer.Pass();
47 void QuadSizeTest(scoped_ptr<UIResourceLayerImpl> layer,
48 size_t expected_quad_size) {
49 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
51 AppendQuadsData data;
52 layer->AppendQuads(render_pass.get(), &data);
54 // Verify quad rects
55 const QuadList& quads = render_pass->quad_list;
56 EXPECT_EQ(expected_quad_size, quads.size());
59 TEST(UIResourceLayerImplTest, VerifyDrawQuads) {
60 FakeImplProxy proxy;
61 TestSharedBitmapManager shared_bitmap_manager;
62 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
63 host_impl.InitializeRenderer(FakeOutputSurface::Create3d());
65 // Make sure we're appending quads when there are valid values.
66 gfx::Size bitmap_size(100, 100);
67 gfx::Size layer_size(100, 100);;
68 size_t expected_quad_size = 1;
69 bool opaque = true;
70 UIResourceId uid = 1;
71 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(&host_impl,
72 bitmap_size,
73 layer_size,
74 opaque,
75 uid);
76 QuadSizeTest(layer.Pass(), expected_quad_size);
78 // Make sure we're not appending quads when there are invalid values.
79 expected_quad_size = 0;
80 uid = 0;
81 layer = GenerateUIResourceLayer(&host_impl,
82 bitmap_size,
83 layer_size,
84 opaque,
85 uid);
86 QuadSizeTest(layer.Pass(), expected_quad_size);
89 void OpaqueBoundsTest(scoped_ptr<UIResourceLayerImpl> layer,
90 const gfx::Rect& expected_opaque_bounds) {
91 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
93 AppendQuadsData data;
94 layer->AppendQuads(render_pass.get(), &data);
96 // Verify quad rects
97 const QuadList& quads = render_pass->quad_list;
98 EXPECT_GE(quads.size(), (size_t)0);
99 gfx::Rect opaque_rect = quads.front()->opaque_rect;
100 EXPECT_EQ(expected_opaque_bounds, opaque_rect);
103 TEST(UIResourceLayerImplTest, VerifySetOpaqueOnSkBitmap) {
104 FakeImplProxy proxy;
105 TestSharedBitmapManager shared_bitmap_manager;
106 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
107 host_impl.InitializeRenderer(FakeOutputSurface::Create3d());
109 gfx::Size bitmap_size(100, 100);
110 gfx::Size layer_size(100, 100);;
111 bool opaque = false;
112 UIResourceId uid = 1;
113 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(&host_impl,
114 bitmap_size,
115 layer_size,
116 opaque,
117 uid);
118 gfx::Rect expected_opaque_bounds;
119 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
121 opaque = true;
122 layer = GenerateUIResourceLayer(&host_impl,
123 bitmap_size,
124 layer_size,
125 opaque,
126 uid);
127 expected_opaque_bounds = gfx::Rect(layer->bounds());
128 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
131 TEST(UIResourceLayerImplTest, VerifySetOpaqueOnLayer) {
132 FakeImplProxy proxy;
133 TestSharedBitmapManager shared_bitmap_manager;
134 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
135 host_impl.InitializeRenderer(FakeOutputSurface::Create3d());
137 gfx::Size bitmap_size(100, 100);
138 gfx::Size layer_size(100, 100);
139 bool skbitmap_opaque = false;
140 UIResourceId uid = 1;
141 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(
142 &host_impl, bitmap_size, layer_size, skbitmap_opaque, uid);
143 layer->SetContentsOpaque(false);
144 gfx::Rect expected_opaque_bounds;
145 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
147 layer = GenerateUIResourceLayer(
148 &host_impl, bitmap_size, layer_size, skbitmap_opaque, uid);
149 layer->SetContentsOpaque(true);
150 expected_opaque_bounds = gfx::Rect(layer->bounds());
151 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
154 TEST(UIResourceLayerImplTest, Occlusion) {
155 gfx::Size layer_size(1000, 1000);
156 gfx::Size viewport_size(1000, 1000);
158 LayerTestCommon::LayerImplTest impl;
160 SkBitmap sk_bitmap;
161 sk_bitmap.allocN32Pixels(10, 10);
162 sk_bitmap.setImmutable();
163 UIResourceId uid = 5;
164 UIResourceBitmap bitmap(sk_bitmap);
165 impl.host_impl()->CreateUIResource(uid, bitmap);
167 UIResourceLayerImpl* ui_resource_layer_impl =
168 impl.AddChildToRoot<UIResourceLayerImpl>();
169 ui_resource_layer_impl->SetBounds(layer_size);
170 ui_resource_layer_impl->SetContentBounds(layer_size);
171 ui_resource_layer_impl->SetDrawsContent(true);
172 ui_resource_layer_impl->SetUIResourceId(uid);
174 impl.CalcDrawProps(viewport_size);
177 SCOPED_TRACE("No occlusion");
178 gfx::Rect occluded;
179 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
181 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
182 gfx::Rect(layer_size));
183 EXPECT_EQ(1u, impl.quad_list().size());
187 SCOPED_TRACE("Full occlusion");
188 gfx::Rect occluded(ui_resource_layer_impl->visible_content_rect());
189 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
191 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
192 EXPECT_EQ(impl.quad_list().size(), 0u);
196 SCOPED_TRACE("Partial occlusion");
197 gfx::Rect occluded(200, 0, 800, 1000);
198 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
200 size_t partially_occluded_count = 0;
201 LayerTestCommon::VerifyQuadsAreOccluded(
202 impl.quad_list(), occluded, &partially_occluded_count);
203 // The layer outputs one quad, which is partially occluded.
204 EXPECT_EQ(1u, impl.quad_list().size());
205 EXPECT_EQ(1u, partially_occluded_count);
209 } // namespace
210 } // namespace cc