Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: cc/output/overlay_unittest.cc

Issue 197223003: Start of hardware overlay support in CC with Ubercompositor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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/base/scoped_ptr_vector.h"
6 #include "cc/output/output_surface.h"
7 #include "cc/output/output_surface_client.h"
8 #include "cc/output/overlay_candidate_validator.h"
9 #include "cc/output/overlay_processor.h"
10 #include "cc/output/overlay_strategy_single_on_top.h"
11 #include "cc/quads/checkerboard_draw_quad.h"
12 #include "cc/quads/render_pass.h"
13 #include "cc/quads/texture_draw_quad.h"
14 #include "cc/resources/resource_provider.h"
15 #include "cc/resources/texture_mailbox.h"
16 #include "cc/test/fake_output_surface_client.h"
17 #include "cc/test/geometry_test_utils.h"
18 #include "cc/test/test_context_provider.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 namespace cc {
22 namespace {
23
24 const gfx::Rect kOverlayRect(0, 0, 128, 128);
25 const gfx::PointF kUVTopLeft(0.1f, 0.2f);
26 const gfx::PointF kUVBottomRight(1.0f, 1.0f);
27
28 void MailboxReleased(unsigned sync_point, bool lost_resource) {}
29
30 class SingleOverlayValidator : public OverlayCandidateValidator {
31 public:
32 virtual void CheckOverlaySupport(OverlayCandidateList* surfaces) OVERRIDE;
33 };
34
35 void SingleOverlayValidator::CheckOverlaySupport(
36 OverlayCandidateList* surfaces) {
37 ASSERT_EQ(2U, surfaces->size());
38
39 OverlayCandidate& candidate = surfaces->back();
40 EXPECT_EQ(kOverlayRect.ToString(), candidate.display_rect.ToString());
41 EXPECT_EQ(BoundingRect(kUVTopLeft, kUVBottomRight).ToString(),
42 candidate.uv_rect.ToString());
43 candidate.overlay_handled = true;
44 }
45
46 class SingleOverlayProcessor : public OverlayProcessor {
47 public:
48 SingleOverlayProcessor(OutputSurface* surface,
49 ResourceProvider* resource_provider);
50 // Virtual to allow testing different strategies.
51 virtual void Initialize() OVERRIDE;
52 };
53
54 SingleOverlayProcessor::SingleOverlayProcessor(
55 OutputSurface* surface,
56 ResourceProvider* resource_provider)
57 : OverlayProcessor(surface, resource_provider) {
58 EXPECT_EQ(surface, surface_);
59 EXPECT_EQ(resource_provider, resource_provider_);
60 }
61
62 void SingleOverlayProcessor::Initialize() {
63 OverlayCandidateValidator* candidates =
64 surface_->overlay_candidate_validator();
65 ASSERT_NE(NULL, (intptr_t)candidates);
66 strategies_.push_back(scoped_ptr<Strategy>(
67 new OverlayStrategySingleOnTop(candidates, resource_provider_)));
68 }
69
70 class DefaultOverlayProcessor : public OverlayProcessor {
71 public:
72 DefaultOverlayProcessor(OutputSurface* surface,
73 ResourceProvider* resource_provider);
74 size_t GetStrategyCount();
75 };
76
77 DefaultOverlayProcessor::DefaultOverlayProcessor(
78 OutputSurface* surface,
79 ResourceProvider* resource_provider)
80 : OverlayProcessor(surface, resource_provider) {}
81
82 size_t DefaultOverlayProcessor::GetStrategyCount() {
83 return strategies_.size();
84 }
85
86 class OverlayOutputSurface : public OutputSurface {
87 public:
88 explicit OverlayOutputSurface(scoped_refptr<ContextProvider> context_provider)
89 : OutputSurface(context_provider) {}
90
91 void InitWithSingleOverlayValidator() {
92 overlay_candidate_validator_.reset(new SingleOverlayValidator);
93 }
94 };
95
96 scoped_ptr<RenderPass> CreateRenderPass() {
97 RenderPass::Id id(1, 0);
98 gfx::Rect output_rect(0, 0, 256, 256);
99 bool has_transparent_background = true;
100
101 scoped_ptr<RenderPass> pass = RenderPass::Create();
102 pass->SetAll(id,
103 output_rect,
104 output_rect,
105 gfx::Transform(),
106 has_transparent_background,
107 RenderPass::NO_OVERLAY);
108
109 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create();
110 pass->shared_quad_state_list.push_back(shared_state.Pass());
111 return pass.Pass();
112 }
113
114 scoped_ptr<TextureDrawQuad> CreateCandidateQuad(
115 ResourceProvider* resource_provider,
116 const SharedQuadState* shared_quad_state) {
117 unsigned sync_point = 0;
118 TextureMailbox mailbox =
119 TextureMailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point);
120 mailbox.set_allow_overlay(true);
121 scoped_ptr<SingleReleaseCallback> release_callback =
122 SingleReleaseCallback::Create(base::Bind(&MailboxReleased));
123
124 ResourceProvider::ResourceId resource_id =
125 resource_provider->CreateResourceFromTextureMailbox(
126 mailbox, release_callback.Pass());
127 bool premultiplied_alpha = false;
128 bool flipped = false;
129 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
130
131 scoped_ptr<TextureDrawQuad> overlay_quad = TextureDrawQuad::Create();
132 overlay_quad->SetNew(shared_quad_state,
133 kOverlayRect,
134 kOverlayRect,
135 kOverlayRect,
136 resource_id,
137 premultiplied_alpha,
138 kUVTopLeft,
139 kUVBottomRight,
140 SK_ColorBLACK,
141 vertex_opacity,
142 flipped);
143
144 return overlay_quad.Pass();
145 }
146
147 scoped_ptr<DrawQuad> CreateCheckeredQuad(
148 ResourceProvider* resource_provider,
149 const SharedQuadState* shared_quad_state) {
150 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad =
151 CheckerboardDrawQuad::Create();
152 checkerboard_quad->SetNew(
153 shared_quad_state, kOverlayRect, kOverlayRect, SkColor());
154 return checkerboard_quad.PassAs<DrawQuad>();
155 }
156
157 static void CompareRenderPassLists(const RenderPassList& expected_list,
158 const RenderPassList& actual_list) {
159 EXPECT_EQ(expected_list.size(), actual_list.size());
160 for (size_t i = 0; i < actual_list.size(); ++i) {
161 RenderPass* expected = expected_list[i];
162 RenderPass* actual = actual_list[i];
163
164 EXPECT_EQ(expected->id, actual->id);
165 EXPECT_RECT_EQ(expected->output_rect, actual->output_rect);
166 EXPECT_EQ(expected->transform_to_root_target,
167 actual->transform_to_root_target);
168 EXPECT_RECT_EQ(expected->damage_rect, actual->damage_rect);
169 EXPECT_EQ(expected->has_transparent_background,
170 actual->has_transparent_background);
171 EXPECT_EQ(expected->overlay_state, actual->overlay_state);
172
173 EXPECT_EQ(expected->shared_quad_state_list.size(),
174 actual->shared_quad_state_list.size());
175 EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size());
176
177 for (size_t i = 0; i < expected->quad_list.size(); ++i) {
178 EXPECT_EQ(expected->quad_list[i]->rect.ToString(),
179 actual->quad_list[i]->rect.ToString());
180 EXPECT_EQ(
181 expected->quad_list[i]->shared_quad_state->content_bounds.ToString(),
182 actual->quad_list[i]->shared_quad_state->content_bounds.ToString());
183 }
184 }
185 }
186
187 TEST(OverlayTest, NoOverlaysByDefault) {
188 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
189 OverlayOutputSurface output_surface(provider);
190 EXPECT_EQ(NULL, output_surface.overlay_candidate_validator());
191
192 output_surface.InitWithSingleOverlayValidator();
193 EXPECT_NE(NULL, (intptr_t)output_surface.overlay_candidate_validator());
194 }
195
196 TEST(OverlayTest, OverlaysProcessorHasStrategy) {
197 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
198 OverlayOutputSurface output_surface(provider);
199 FakeOutputSurfaceClient client;
200 EXPECT_TRUE(output_surface.BindToClient(&client));
201 output_surface.InitWithSingleOverlayValidator();
202 EXPECT_NE(NULL, (intptr_t)output_surface.overlay_candidate_validator());
203
204 scoped_ptr<ResourceProvider> resource_provider(
205 ResourceProvider::Create(&output_surface, NULL, 0, false, 1));
206
207 scoped_ptr<DefaultOverlayProcessor> overlay_processor(
208 new DefaultOverlayProcessor(&output_surface, resource_provider.get()));
209 overlay_processor->Initialize();
210 EXPECT_GE(1U, overlay_processor->GetStrategyCount());
211 }
212
213 TEST(OverlayTest, SingleOverlayOnTop) {
214 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
215 OverlayOutputSurface output_surface(provider);
216 FakeOutputSurfaceClient client;
217 EXPECT_TRUE(output_surface.BindToClient(&client));
218 output_surface.InitWithSingleOverlayValidator();
219 EXPECT_NE(NULL, (intptr_t)output_surface.overlay_candidate_validator());
220
221 scoped_ptr<ResourceProvider> resource_provider(
222 ResourceProvider::Create(&output_surface, NULL, 0, false, 1));
223
224 scoped_ptr<SingleOverlayProcessor> overlay_processor(
225 new SingleOverlayProcessor(&output_surface, resource_provider.get()));
226 overlay_processor->Initialize();
227
228 // Test successfull overlay.
229 {
230 scoped_ptr<RenderPass> pass = CreateRenderPass();
231 scoped_ptr<TextureDrawQuad> original_quad = CreateCandidateQuad(
232 resource_provider.get(), pass->shared_quad_state_list.back());
233
234 pass->quad_list.push_back(
235 original_quad->Copy(pass->shared_quad_state_list.back()));
236 // Add something behind it.
237 pass->quad_list.push_back(CreateCheckeredQuad(
238 resource_provider.get(), pass->shared_quad_state_list.back()));
239 pass->quad_list.push_back(CreateCheckeredQuad(
240 resource_provider.get(), pass->shared_quad_state_list.back()));
241
242 RenderPassList pass_list;
243 pass_list.push_back(pass.Pass());
244
245 // Check for potential candidates.
246 overlay_processor->ProcessForOverlays(&pass_list);
247
248 // This should have one more pass with an overlay.
249 ASSERT_EQ(2U, pass_list.size());
250
251 RenderPass* overlay_pass = pass_list.front();
252 EXPECT_EQ(RenderPass::SIMPLE_OVERLAY, overlay_pass->overlay_state);
253 RenderPass* main_pass = pass_list.back();
254 EXPECT_EQ(RenderPass::NO_OVERLAY, main_pass->overlay_state);
255
256 // Check that the quad is what we expect it to be.
257 EXPECT_EQ(1U, overlay_pass->quad_list.size());
258 const DrawQuad* overlay_quad = overlay_pass->quad_list.front();
259 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, overlay_quad->material);
260 EXPECT_EQ(original_quad->resource_id,
261 TextureDrawQuad::MaterialCast(overlay_quad)->resource_id);
262 }
263
264 // Test with no candidates.
265 {
266 scoped_ptr<RenderPass> pass = CreateRenderPass();
267 pass->quad_list.push_back(CreateCheckeredQuad(
268 resource_provider.get(), pass->shared_quad_state_list.back()));
269 pass->quad_list.push_back(CreateCheckeredQuad(
270 resource_provider.get(), pass->shared_quad_state_list.back()));
271
272 RenderPassList pass_list;
273 pass_list.push_back(pass.Pass());
274
275 RenderPassList original_pass_list;
276 RenderPass::CopyAll(pass_list, &original_pass_list);
277
278 overlay_processor->ProcessForOverlays(&pass_list);
279 // There should be nothing new here.
280 CompareRenderPassLists(pass_list, original_pass_list);
281 }
282
283 // Test with occluded candidate.
284 {
285 scoped_ptr<RenderPass> pass = CreateRenderPass();
286 pass->quad_list.push_back(CreateCheckeredQuad(
287 resource_provider.get(), pass->shared_quad_state_list.back()));
288 pass->quad_list.push_back(CreateCheckeredQuad(
289 resource_provider.get(), pass->shared_quad_state_list.back()));
290
291 pass->quad_list.push_back(
292 CreateCandidateQuad(resource_provider.get(),
293 pass->shared_quad_state_list.back())
294 .PassAs<DrawQuad>());
295
296 RenderPassList pass_list;
297 pass_list.push_back(pass.Pass());
298
299 RenderPassList original_pass_list;
300 RenderPass::CopyAll(pass_list, &original_pass_list);
301
302 overlay_processor->ProcessForOverlays(&pass_list);
303 // There should be nothing new here.
304 CompareRenderPassLists(pass_list, original_pass_list);
305 }
306
307 // Test with multiple render passes.
308 {
309 RenderPassList pass_list;
310 pass_list.push_back(CreateRenderPass());
311 pass_list.push_back(CreateRenderPass());
312
313 RenderPassList original_pass_list;
314 RenderPass::CopyAll(pass_list, &original_pass_list);
315
316 overlay_processor->ProcessForOverlays(&pass_list);
317 // There should be nothing new here.
318 CompareRenderPassLists(pass_list, original_pass_list);
319 }
320 }
321
322 } // namespace
323 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698