Don't invoke Render() upon receipt of pause complete signal.
[chromium-blink-merge.git] / cc / layers / ui_resource_layer_impl_unittest.cc
blobdc24e1dd5c0623bebf4ec814ac030df450ba0fb4
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_ui_resource_layer_tree_host_impl.h"
13 #include "cc/test/layer_test_common.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/trees/single_thread_proxy.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/transform.h"
20 namespace cc {
21 namespace {
23 scoped_ptr<UIResourceLayerImpl> GenerateUIResourceLayer(
24 FakeUIResourceLayerTreeHostImpl* host_impl,
25 const gfx::Size& bitmap_size,
26 const gfx::Size& layer_size,
27 bool opaque,
28 UIResourceId uid) {
29 gfx::Rect visible_content_rect(layer_size);
30 scoped_ptr<UIResourceLayerImpl> layer =
31 UIResourceLayerImpl::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();
38 UIResourceBitmap bitmap(bitmap_size, opaque);
40 host_impl->CreateUIResource(uid, bitmap);
41 layer->SetUIResourceId(uid);
43 return layer.Pass();
46 void QuadSizeTest(scoped_ptr<UIResourceLayerImpl> layer,
47 size_t expected_quad_size) {
48 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
50 AppendQuadsData data;
51 layer->AppendQuads(render_pass.get(), Occlusion(), &data);
53 // Verify quad rects
54 const QuadList& quads = render_pass->quad_list;
55 EXPECT_EQ(expected_quad_size, quads.size());
58 TEST(UIResourceLayerImplTest, VerifyDrawQuads) {
59 FakeImplProxy proxy;
60 TestSharedBitmapManager shared_bitmap_manager;
61 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
62 // Make sure we're appending quads when there are valid values.
63 gfx::Size bitmap_size(100, 100);
64 gfx::Size layer_size(100, 100);;
65 size_t expected_quad_size = 1;
66 bool opaque = true;
67 UIResourceId uid = 1;
68 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(&host_impl,
69 bitmap_size,
70 layer_size,
71 opaque,
72 uid);
73 QuadSizeTest(layer.Pass(), expected_quad_size);
75 // Make sure we're not appending quads when there are invalid values.
76 expected_quad_size = 0;
77 uid = 0;
78 layer = GenerateUIResourceLayer(&host_impl,
79 bitmap_size,
80 layer_size,
81 opaque,
82 uid);
83 QuadSizeTest(layer.Pass(), expected_quad_size);
86 void OpaqueBoundsTest(scoped_ptr<UIResourceLayerImpl> layer,
87 const gfx::Rect& expected_opaque_bounds) {
88 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
90 AppendQuadsData data;
91 layer->AppendQuads(render_pass.get(), Occlusion(), &data);
93 // Verify quad rects
94 const QuadList& quads = render_pass->quad_list;
95 EXPECT_GE(quads.size(), (size_t)0);
96 gfx::Rect opaque_rect = quads.front()->opaque_rect;
97 EXPECT_EQ(expected_opaque_bounds, opaque_rect);
100 TEST(UIResourceLayerImplTest, VerifySetOpaqueOnSkBitmap) {
101 FakeImplProxy proxy;
102 TestSharedBitmapManager shared_bitmap_manager;
103 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
105 gfx::Size bitmap_size(100, 100);
106 gfx::Size layer_size(100, 100);;
107 bool opaque = false;
108 UIResourceId uid = 1;
109 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(&host_impl,
110 bitmap_size,
111 layer_size,
112 opaque,
113 uid);
114 gfx::Rect expected_opaque_bounds;
115 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
117 opaque = true;
118 layer = GenerateUIResourceLayer(&host_impl,
119 bitmap_size,
120 layer_size,
121 opaque,
122 uid);
123 expected_opaque_bounds = gfx::Rect(layer->bounds());
124 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
127 TEST(UIResourceLayerImplTest, VerifySetOpaqueOnLayer) {
128 FakeImplProxy proxy;
129 TestSharedBitmapManager shared_bitmap_manager;
130 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
132 gfx::Size bitmap_size(100, 100);
133 gfx::Size layer_size(100, 100);
134 bool skbitmap_opaque = false;
135 UIResourceId uid = 1;
136 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(
137 &host_impl, bitmap_size, layer_size, skbitmap_opaque, uid);
138 layer->SetContentsOpaque(false);
139 gfx::Rect expected_opaque_bounds;
140 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
142 layer = GenerateUIResourceLayer(
143 &host_impl, bitmap_size, layer_size, skbitmap_opaque, uid);
144 layer->SetContentsOpaque(true);
145 expected_opaque_bounds = gfx::Rect(layer->bounds());
146 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
149 TEST(UIResourceLayerImplTest, Occlusion) {
150 gfx::Size layer_size(1000, 1000);
151 gfx::Size viewport_size(1000, 1000);
153 LayerTestCommon::LayerImplTest impl;
155 SkBitmap sk_bitmap;
156 sk_bitmap.allocN32Pixels(10, 10);
157 sk_bitmap.setImmutable();
158 UIResourceId uid = 5;
159 UIResourceBitmap bitmap(sk_bitmap);
160 impl.host_impl()->CreateUIResource(uid, bitmap);
162 UIResourceLayerImpl* ui_resource_layer_impl =
163 impl.AddChildToRoot<UIResourceLayerImpl>();
164 ui_resource_layer_impl->SetBounds(layer_size);
165 ui_resource_layer_impl->SetContentBounds(layer_size);
166 ui_resource_layer_impl->SetDrawsContent(true);
167 ui_resource_layer_impl->SetUIResourceId(uid);
169 impl.CalcDrawProps(viewport_size);
172 SCOPED_TRACE("No occlusion");
173 gfx::Rect occluded;
174 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
176 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
177 gfx::Rect(layer_size));
178 EXPECT_EQ(1u, impl.quad_list().size());
182 SCOPED_TRACE("Full occlusion");
183 gfx::Rect occluded(ui_resource_layer_impl->visible_content_rect());
184 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
186 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
187 EXPECT_EQ(impl.quad_list().size(), 0u);
191 SCOPED_TRACE("Partial occlusion");
192 gfx::Rect occluded(200, 0, 800, 1000);
193 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
195 size_t partially_occluded_count = 0;
196 LayerTestCommon::VerifyQuadsAreOccluded(
197 impl.quad_list(), occluded, &partially_occluded_count);
198 // The layer outputs one quad, which is partially occluded.
199 EXPECT_EQ(1u, impl.quad_list().size());
200 EXPECT_EQ(1u, partially_occluded_count);
204 } // namespace
205 } // namespace cc