Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / cc / output / overlay_unittest.cc
blob3b0c65a2806de7be5875d0fe07b530a423ba05ba
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.
5 #include "cc/base/scoped_ptr_vector.h"
6 #include "cc/output/gl_renderer.h"
7 #include "cc/output/output_surface.h"
8 #include "cc/output/output_surface_client.h"
9 #include "cc/output/overlay_candidate_validator.h"
10 #include "cc/output/overlay_processor.h"
11 #include "cc/output/overlay_strategy_single_on_top.h"
12 #include "cc/quads/checkerboard_draw_quad.h"
13 #include "cc/quads/render_pass.h"
14 #include "cc/quads/texture_draw_quad.h"
15 #include "cc/resources/resource_provider.h"
16 #include "cc/resources/texture_mailbox.h"
17 #include "cc/test/fake_output_surface_client.h"
18 #include "cc/test/geometry_test_utils.h"
19 #include "cc/test/test_context_provider.h"
20 #include "cc/test/test_shared_bitmap_manager.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
24 using testing::_;
25 using testing::Mock;
27 namespace cc {
28 namespace {
30 const gfx::Rect kOverlayRect(0, 0, 128, 128);
31 const gfx::PointF kUVTopLeft(0.1f, 0.2f);
32 const gfx::PointF kUVBottomRight(1.0f, 1.0f);
34 void MailboxReleased(unsigned sync_point, bool lost_resource) {}
36 class SingleOverlayValidator : public OverlayCandidateValidator {
37 public:
38 virtual void CheckOverlaySupport(OverlayCandidateList* surfaces) OVERRIDE;
41 void SingleOverlayValidator::CheckOverlaySupport(
42 OverlayCandidateList* surfaces) {
43 ASSERT_EQ(2U, surfaces->size());
45 OverlayCandidate& candidate = surfaces->back();
46 EXPECT_EQ(kOverlayRect.ToString(), candidate.display_rect.ToString());
47 EXPECT_EQ(BoundingRect(kUVTopLeft, kUVBottomRight).ToString(),
48 candidate.uv_rect.ToString());
49 candidate.overlay_handled = true;
52 class SingleOverlayProcessor : public OverlayProcessor {
53 public:
54 SingleOverlayProcessor(OutputSurface* surface,
55 ResourceProvider* resource_provider);
56 // Virtual to allow testing different strategies.
57 virtual void Initialize() OVERRIDE;
60 SingleOverlayProcessor::SingleOverlayProcessor(
61 OutputSurface* surface,
62 ResourceProvider* resource_provider)
63 : OverlayProcessor(surface, resource_provider) {
64 EXPECT_EQ(surface, surface_);
65 EXPECT_EQ(resource_provider, resource_provider_);
68 void SingleOverlayProcessor::Initialize() {
69 OverlayCandidateValidator* candidates =
70 surface_->overlay_candidate_validator();
71 ASSERT_TRUE(candidates != NULL);
72 strategies_.push_back(scoped_ptr<Strategy>(
73 new OverlayStrategySingleOnTop(candidates, resource_provider_)));
76 class DefaultOverlayProcessor : public OverlayProcessor {
77 public:
78 DefaultOverlayProcessor(OutputSurface* surface,
79 ResourceProvider* resource_provider);
80 size_t GetStrategyCount();
83 DefaultOverlayProcessor::DefaultOverlayProcessor(
84 OutputSurface* surface,
85 ResourceProvider* resource_provider)
86 : OverlayProcessor(surface, resource_provider) {}
88 size_t DefaultOverlayProcessor::GetStrategyCount() {
89 return strategies_.size();
92 class OverlayOutputSurface : public OutputSurface {
93 public:
94 explicit OverlayOutputSurface(scoped_refptr<ContextProvider> context_provider)
95 : OutputSurface(context_provider) {}
97 void InitWithSingleOverlayValidator() {
98 overlay_candidate_validator_.reset(new SingleOverlayValidator);
102 scoped_ptr<RenderPass> CreateRenderPass() {
103 RenderPass::Id id(1, 0);
104 gfx::Rect output_rect(0, 0, 256, 256);
105 bool has_transparent_background = true;
107 scoped_ptr<RenderPass> pass = RenderPass::Create();
108 pass->SetAll(id,
109 output_rect,
110 output_rect,
111 gfx::Transform(),
112 has_transparent_background);
114 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create();
115 shared_state->opacity = 1.f;
116 pass->shared_quad_state_list.push_back(shared_state.Pass());
117 return pass.Pass();
120 ResourceProvider::ResourceId CreateResource(
121 ResourceProvider* resource_provider) {
122 unsigned sync_point = 0;
123 TextureMailbox mailbox =
124 TextureMailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point);
125 mailbox.set_allow_overlay(true);
126 scoped_ptr<SingleReleaseCallback> release_callback =
127 SingleReleaseCallback::Create(base::Bind(&MailboxReleased));
129 return resource_provider->CreateResourceFromTextureMailbox(
130 mailbox, release_callback.Pass());
133 scoped_ptr<TextureDrawQuad> CreateCandidateQuad(
134 ResourceProvider* resource_provider,
135 const SharedQuadState* shared_quad_state) {
136 ResourceProvider::ResourceId resource_id = CreateResource(resource_provider);
137 bool premultiplied_alpha = false;
138 bool flipped = false;
139 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
141 scoped_ptr<TextureDrawQuad> overlay_quad = TextureDrawQuad::Create();
142 overlay_quad->SetNew(shared_quad_state,
143 kOverlayRect,
144 kOverlayRect,
145 kOverlayRect,
146 resource_id,
147 premultiplied_alpha,
148 kUVTopLeft,
149 kUVBottomRight,
150 SK_ColorTRANSPARENT,
151 vertex_opacity,
152 flipped);
154 return overlay_quad.Pass();
157 scoped_ptr<DrawQuad> CreateCheckeredQuad(
158 ResourceProvider* resource_provider,
159 const SharedQuadState* shared_quad_state) {
160 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad =
161 CheckerboardDrawQuad::Create();
162 checkerboard_quad->SetNew(
163 shared_quad_state, kOverlayRect, kOverlayRect, SkColor());
164 return checkerboard_quad.PassAs<DrawQuad>();
167 static void CompareRenderPassLists(const RenderPassList& expected_list,
168 const RenderPassList& actual_list) {
169 EXPECT_EQ(expected_list.size(), actual_list.size());
170 for (size_t i = 0; i < actual_list.size(); ++i) {
171 RenderPass* expected = expected_list[i];
172 RenderPass* actual = actual_list[i];
174 EXPECT_EQ(expected->id, actual->id);
175 EXPECT_RECT_EQ(expected->output_rect, actual->output_rect);
176 EXPECT_EQ(expected->transform_to_root_target,
177 actual->transform_to_root_target);
178 EXPECT_RECT_EQ(expected->damage_rect, actual->damage_rect);
179 EXPECT_EQ(expected->has_transparent_background,
180 actual->has_transparent_background);
182 EXPECT_EQ(expected->shared_quad_state_list.size(),
183 actual->shared_quad_state_list.size());
184 EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size());
186 for (size_t i = 0; i < expected->quad_list.size(); ++i) {
187 EXPECT_EQ(expected->quad_list[i]->rect.ToString(),
188 actual->quad_list[i]->rect.ToString());
189 EXPECT_EQ(
190 expected->quad_list[i]->shared_quad_state->content_bounds.ToString(),
191 actual->quad_list[i]->shared_quad_state->content_bounds.ToString());
196 TEST(OverlayTest, NoOverlaysByDefault) {
197 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
198 OverlayOutputSurface output_surface(provider);
199 EXPECT_EQ(NULL, output_surface.overlay_candidate_validator());
201 output_surface.InitWithSingleOverlayValidator();
202 EXPECT_TRUE(output_surface.overlay_candidate_validator() != NULL);
205 TEST(OverlayTest, OverlaysProcessorHasStrategy) {
206 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
207 OverlayOutputSurface output_surface(provider);
208 FakeOutputSurfaceClient client;
209 EXPECT_TRUE(output_surface.BindToClient(&client));
210 output_surface.InitWithSingleOverlayValidator();
211 EXPECT_TRUE(output_surface.overlay_candidate_validator() != NULL);
213 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
214 new TestSharedBitmapManager());
215 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
216 &output_surface, shared_bitmap_manager.get(), 0, false, 1));
218 scoped_ptr<DefaultOverlayProcessor> overlay_processor(
219 new DefaultOverlayProcessor(&output_surface, resource_provider.get()));
220 overlay_processor->Initialize();
221 EXPECT_GE(1U, overlay_processor->GetStrategyCount());
224 class SingleOverlayOnTopTest : public testing::Test {
225 protected:
226 virtual void SetUp() {
227 provider_ = TestContextProvider::Create();
228 output_surface_.reset(new OverlayOutputSurface(provider_));
229 EXPECT_TRUE(output_surface_->BindToClient(&client_));
230 output_surface_->InitWithSingleOverlayValidator();
231 EXPECT_TRUE(output_surface_->overlay_candidate_validator() != NULL);
233 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
234 resource_provider_ = ResourceProvider::Create(
235 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1);
237 overlay_processor_.reset(new SingleOverlayProcessor(
238 output_surface_.get(), resource_provider_.get()));
239 overlay_processor_->Initialize();
242 scoped_refptr<TestContextProvider> provider_;
243 scoped_ptr<OverlayOutputSurface> output_surface_;
244 FakeOutputSurfaceClient client_;
245 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
246 scoped_ptr<ResourceProvider> resource_provider_;
247 scoped_ptr<SingleOverlayProcessor> overlay_processor_;
250 TEST_F(SingleOverlayOnTopTest, SuccessfullOverlay) {
251 scoped_ptr<RenderPass> pass = CreateRenderPass();
252 scoped_ptr<TextureDrawQuad> original_quad = CreateCandidateQuad(
253 resource_provider_.get(), pass->shared_quad_state_list.back());
255 pass->quad_list.push_back(
256 original_quad->Copy(pass->shared_quad_state_list.back()));
257 // Add something behind it.
258 pass->quad_list.push_back(CreateCheckeredQuad(
259 resource_provider_.get(), pass->shared_quad_state_list.back()));
260 pass->quad_list.push_back(CreateCheckeredQuad(
261 resource_provider_.get(), pass->shared_quad_state_list.back()));
263 RenderPassList pass_list;
264 pass_list.push_back(pass.Pass());
266 // Check for potential candidates.
267 OverlayCandidateList candidate_list;
268 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
270 ASSERT_EQ(1U, pass_list.size());
271 ASSERT_EQ(2U, candidate_list.size());
273 RenderPass* main_pass = pass_list.back();
274 // Check that the quad is gone.
275 EXPECT_EQ(2U, main_pass->quad_list.size());
276 const QuadList& quad_list = main_pass->quad_list;
277 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin();
278 it != quad_list.BackToFrontEnd();
279 ++it) {
280 EXPECT_NE(DrawQuad::TEXTURE_CONTENT, (*it)->material);
283 // Check that the right resource id got extracted.
284 EXPECT_EQ(original_quad->resource_id, candidate_list.back().resource_id);
287 TEST_F(SingleOverlayOnTopTest, NoCandidates) {
288 scoped_ptr<RenderPass> pass = CreateRenderPass();
289 pass->quad_list.push_back(CreateCheckeredQuad(
290 resource_provider_.get(), pass->shared_quad_state_list.back()));
291 pass->quad_list.push_back(CreateCheckeredQuad(
292 resource_provider_.get(), pass->shared_quad_state_list.back()));
294 RenderPassList pass_list;
295 pass_list.push_back(pass.Pass());
297 RenderPassList original_pass_list;
298 RenderPass::CopyAll(pass_list, &original_pass_list);
300 OverlayCandidateList candidate_list;
301 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
302 EXPECT_EQ(0U, candidate_list.size());
303 // There should be nothing new here.
304 CompareRenderPassLists(pass_list, original_pass_list);
307 TEST_F(SingleOverlayOnTopTest, OccludedCandidates) {
308 scoped_ptr<RenderPass> pass = CreateRenderPass();
309 pass->quad_list.push_back(CreateCheckeredQuad(
310 resource_provider_.get(), pass->shared_quad_state_list.back()));
311 pass->quad_list.push_back(CreateCheckeredQuad(
312 resource_provider_.get(), pass->shared_quad_state_list.back()));
314 pass->quad_list.push_back(
315 CreateCandidateQuad(resource_provider_.get(),
316 pass->shared_quad_state_list.back())
317 .PassAs<DrawQuad>());
319 RenderPassList pass_list;
320 pass_list.push_back(pass.Pass());
322 RenderPassList original_pass_list;
323 RenderPass::CopyAll(pass_list, &original_pass_list);
325 OverlayCandidateList candidate_list;
326 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
327 EXPECT_EQ(0U, candidate_list.size());
328 // There should be nothing new here.
329 CompareRenderPassLists(pass_list, original_pass_list);
332 // Test with multiple render passes.
333 TEST_F(SingleOverlayOnTopTest, MultipleRenderPasses) {
334 RenderPassList pass_list;
335 pass_list.push_back(CreateRenderPass());
337 scoped_ptr<RenderPass> pass = CreateRenderPass();
338 scoped_ptr<TextureDrawQuad> original_quad = CreateCandidateQuad(
339 resource_provider_.get(), pass->shared_quad_state_list.back());
341 pass->quad_list.push_back(
342 original_quad->Copy(pass->shared_quad_state_list.back()));
343 // Add something behind it.
344 pass->quad_list.push_back(CreateCheckeredQuad(
345 resource_provider_.get(), pass->shared_quad_state_list.back()));
346 pass->quad_list.push_back(CreateCheckeredQuad(
347 resource_provider_.get(), pass->shared_quad_state_list.back()));
349 pass_list.push_back(pass.Pass());
351 RenderPassList original_pass_list;
352 RenderPass::CopyAll(pass_list, &original_pass_list);
354 // Check for potential candidates.
355 OverlayCandidateList candidate_list;
356 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
357 EXPECT_EQ(2U, candidate_list.size());
359 // This should be the same.
360 ASSERT_EQ(2U, pass_list.size());
363 TEST_F(SingleOverlayOnTopTest, RejectPremultipliedAlpha) {
364 scoped_ptr<RenderPass> pass = CreateRenderPass();
365 scoped_ptr<TextureDrawQuad> quad = CreateCandidateQuad(
366 resource_provider_.get(), pass->shared_quad_state_list.back());
367 quad->premultiplied_alpha = true;
369 pass->quad_list.push_back(quad.PassAs<DrawQuad>());
370 RenderPassList pass_list;
371 pass_list.push_back(pass.Pass());
372 OverlayCandidateList candidate_list;
373 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
374 EXPECT_EQ(1U, pass_list.size());
375 EXPECT_EQ(0U, candidate_list.size());
378 TEST_F(SingleOverlayOnTopTest, RejectBlending) {
379 scoped_ptr<RenderPass> pass = CreateRenderPass();
380 scoped_ptr<TextureDrawQuad> quad = CreateCandidateQuad(
381 resource_provider_.get(), pass->shared_quad_state_list.back());
382 quad->needs_blending = true;
384 pass->quad_list.push_back(quad.PassAs<DrawQuad>());
385 RenderPassList pass_list;
386 pass_list.push_back(pass.Pass());
387 OverlayCandidateList candidate_list;
388 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
389 ASSERT_EQ(1U, pass_list.size());
390 EXPECT_EQ(0U, candidate_list.size());
393 TEST_F(SingleOverlayOnTopTest, RejectBackgroundColor) {
394 scoped_ptr<RenderPass> pass = CreateRenderPass();
395 scoped_ptr<TextureDrawQuad> quad = CreateCandidateQuad(
396 resource_provider_.get(), pass->shared_quad_state_list.back());
397 quad->background_color = SK_ColorBLACK;
399 pass->quad_list.push_back(quad.PassAs<DrawQuad>());
400 RenderPassList pass_list;
401 pass_list.push_back(pass.Pass());
402 OverlayCandidateList candidate_list;
403 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
404 ASSERT_EQ(1U, pass_list.size());
405 EXPECT_EQ(0U, candidate_list.size());
408 TEST_F(SingleOverlayOnTopTest, RejectBlendMode) {
409 scoped_ptr<RenderPass> pass = CreateRenderPass();
410 scoped_ptr<TextureDrawQuad> quad = CreateCandidateQuad(
411 resource_provider_.get(), pass->shared_quad_state_list.back());
412 pass->shared_quad_state_list.back()->blend_mode = SkXfermode::kScreen_Mode;
414 pass->quad_list.push_back(quad.PassAs<DrawQuad>());
415 RenderPassList pass_list;
416 pass_list.push_back(pass.Pass());
417 OverlayCandidateList candidate_list;
418 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
419 ASSERT_EQ(1U, pass_list.size());
420 EXPECT_EQ(0U, candidate_list.size());
423 TEST_F(SingleOverlayOnTopTest, RejectOpacity) {
424 scoped_ptr<RenderPass> pass = CreateRenderPass();
425 scoped_ptr<TextureDrawQuad> quad = CreateCandidateQuad(
426 resource_provider_.get(), pass->shared_quad_state_list.back());
427 pass->shared_quad_state_list.back()->opacity = 0.5f;
429 pass->quad_list.push_back(quad.PassAs<DrawQuad>());
430 RenderPassList pass_list;
431 pass_list.push_back(pass.Pass());
432 OverlayCandidateList candidate_list;
433 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
434 ASSERT_EQ(1U, pass_list.size());
435 EXPECT_EQ(0U, candidate_list.size());
438 TEST_F(SingleOverlayOnTopTest, RejectTransform) {
439 scoped_ptr<RenderPass> pass = CreateRenderPass();
440 scoped_ptr<TextureDrawQuad> quad = CreateCandidateQuad(
441 resource_provider_.get(), pass->shared_quad_state_list.back());
442 pass->shared_quad_state_list.back()->content_to_target_transform.Scale(2.f,
443 2.f);
445 pass->quad_list.push_back(quad.PassAs<DrawQuad>());
446 RenderPassList pass_list;
447 pass_list.push_back(pass.Pass());
448 OverlayCandidateList candidate_list;
449 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
450 ASSERT_EQ(1U, pass_list.size());
451 EXPECT_EQ(0U, candidate_list.size());
454 class OverlayInfoRendererGL : public GLRenderer {
455 public:
456 OverlayInfoRendererGL(RendererClient* client,
457 const LayerTreeSettings* settings,
458 OutputSurface* output_surface,
459 ResourceProvider* resource_provider)
460 : GLRenderer(client,
461 settings,
462 output_surface,
463 resource_provider,
464 NULL,
466 expect_overlays_(false) {}
468 MOCK_METHOD2(DoDrawQuad, void(DrawingFrame* frame, const DrawQuad* quad));
470 virtual void FinishDrawingFrame(DrawingFrame* frame) OVERRIDE {
471 GLRenderer::FinishDrawingFrame(frame);
473 if (!expect_overlays_) {
474 EXPECT_EQ(0U, frame->overlay_list.size());
475 return;
478 ASSERT_EQ(2U, frame->overlay_list.size());
479 EXPECT_NE(0U, frame->overlay_list.back().resource_id);
482 void set_expect_overlays(bool expect_overlays) {
483 expect_overlays_ = expect_overlays;
486 private:
487 bool expect_overlays_;
490 class FakeRendererClient : public RendererClient {
491 public:
492 // RendererClient methods.
493 virtual void SetFullRootLayerDamage() OVERRIDE {}
496 class MockOverlayScheduler {
497 public:
498 MOCK_METHOD5(Schedule,
499 void(int plane_z_order,
500 gfx::OverlayTransform plane_transform,
501 unsigned overlay_texture_id,
502 const gfx::Rect& display_bounds,
503 const gfx::RectF& uv_rect));
506 class GLRendererWithOverlaysTest : public testing::Test {
507 protected:
508 GLRendererWithOverlaysTest() {
509 provider_ = TestContextProvider::Create();
510 output_surface_.reset(new OverlayOutputSurface(provider_));
511 CHECK(output_surface_->BindToClient(&output_surface_client_));
512 resource_provider_ =
513 ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1);
515 provider_->support()->SetScheduleOverlayPlaneCallback(base::Bind(
516 &MockOverlayScheduler::Schedule, base::Unretained(&scheduler_)));
519 void Init(bool use_validator) {
520 if (use_validator)
521 output_surface_->InitWithSingleOverlayValidator();
523 renderer_ =
524 make_scoped_ptr(new OverlayInfoRendererGL(&renderer_client_,
525 &settings_,
526 output_surface_.get(),
527 resource_provider_.get()));
530 void SwapBuffers() { renderer_->SwapBuffers(CompositorFrameMetadata()); }
532 LayerTreeSettings settings_;
533 FakeOutputSurfaceClient output_surface_client_;
534 scoped_ptr<OverlayOutputSurface> output_surface_;
535 FakeRendererClient renderer_client_;
536 scoped_ptr<ResourceProvider> resource_provider_;
537 scoped_ptr<OverlayInfoRendererGL> renderer_;
538 scoped_refptr<TestContextProvider> provider_;
539 MockOverlayScheduler scheduler_;
542 TEST_F(GLRendererWithOverlaysTest, OverlayQuadNotDrawn) {
543 bool use_validator = true;
544 Init(use_validator);
545 renderer_->set_expect_overlays(true);
546 gfx::Rect viewport_rect(16, 16);
548 scoped_ptr<RenderPass> pass = CreateRenderPass();
550 pass->quad_list.push_back(
551 CreateCandidateQuad(resource_provider_.get(),
552 pass->shared_quad_state_list.back())
553 .PassAs<DrawQuad>());
555 pass->quad_list.push_back(CreateCheckeredQuad(
556 resource_provider_.get(), pass->shared_quad_state_list.back()));
557 pass->quad_list.push_back(CreateCheckeredQuad(
558 resource_provider_.get(), pass->shared_quad_state_list.back()));
560 RenderPassList pass_list;
561 pass_list.push_back(pass.Pass());
563 // Candidate pass was taken out and extra skipped pass added,
564 // so only draw 2 quads.
565 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(2);
566 EXPECT_CALL(scheduler_,
567 Schedule(1,
568 gfx::OVERLAY_TRANSFORM_NONE,
570 kOverlayRect,
571 BoundingRect(kUVTopLeft, kUVBottomRight))).Times(1);
572 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
574 SwapBuffers();
576 Mock::VerifyAndClearExpectations(renderer_.get());
577 Mock::VerifyAndClearExpectations(&scheduler_);
580 TEST_F(GLRendererWithOverlaysTest, OccludedQuadDrawn) {
581 bool use_validator = true;
582 Init(use_validator);
583 renderer_->set_expect_overlays(false);
584 gfx::Rect viewport_rect(16, 16);
586 scoped_ptr<RenderPass> pass = CreateRenderPass();
588 pass->quad_list.push_back(CreateCheckeredQuad(
589 resource_provider_.get(), pass->shared_quad_state_list.back()));
590 pass->quad_list.push_back(CreateCheckeredQuad(
591 resource_provider_.get(), pass->shared_quad_state_list.back()));
593 pass->quad_list.push_back(
594 CreateCandidateQuad(resource_provider_.get(),
595 pass->shared_quad_state_list.back())
596 .PassAs<DrawQuad>());
598 RenderPassList pass_list;
599 pass_list.push_back(pass.Pass());
601 // 3 quads in the pass, all should draw.
602 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3);
603 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
604 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
606 SwapBuffers();
608 Mock::VerifyAndClearExpectations(renderer_.get());
609 Mock::VerifyAndClearExpectations(&scheduler_);
612 TEST_F(GLRendererWithOverlaysTest, NoValidatorNoOverlay) {
613 bool use_validator = false;
614 Init(use_validator);
615 renderer_->set_expect_overlays(false);
616 gfx::Rect viewport_rect(16, 16);
618 scoped_ptr<RenderPass> pass = CreateRenderPass();
620 pass->quad_list.push_back(
621 CreateCandidateQuad(resource_provider_.get(),
622 pass->shared_quad_state_list.back())
623 .PassAs<DrawQuad>());
625 pass->quad_list.push_back(CreateCheckeredQuad(
626 resource_provider_.get(), pass->shared_quad_state_list.back()));
627 pass->quad_list.push_back(CreateCheckeredQuad(
628 resource_provider_.get(), pass->shared_quad_state_list.back()));
630 RenderPassList pass_list;
631 pass_list.push_back(pass.Pass());
633 // Should see no overlays.
634 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3);
635 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
636 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
638 SwapBuffers();
640 Mock::VerifyAndClearExpectations(renderer_.get());
641 Mock::VerifyAndClearExpectations(&scheduler_);
644 TEST_F(GLRendererWithOverlaysTest, ResourcesExportedAndReturned) {
645 bool use_validator = true;
646 Init(use_validator);
647 renderer_->set_expect_overlays(true);
649 ResourceProvider::ResourceId resource1 =
650 CreateResource(resource_provider_.get());
651 ResourceProvider::ResourceId resource2 =
652 CreateResource(resource_provider_.get());
654 DirectRenderer::DrawingFrame frame1;
655 frame1.overlay_list.resize(2);
656 OverlayCandidate& overlay1 = frame1.overlay_list.back();
657 overlay1.resource_id = resource1;
658 overlay1.plane_z_order = 1;
660 DirectRenderer::DrawingFrame frame2;
661 frame2.overlay_list.resize(2);
662 OverlayCandidate& overlay2 = frame2.overlay_list.back();
663 overlay2.resource_id = resource2;
664 overlay2.plane_z_order = 1;
666 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
667 renderer_->FinishDrawingFrame(&frame1);
668 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
669 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
670 SwapBuffers();
671 Mock::VerifyAndClearExpectations(&scheduler_);
673 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
674 renderer_->FinishDrawingFrame(&frame2);
675 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
676 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
677 SwapBuffers();
678 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
679 Mock::VerifyAndClearExpectations(&scheduler_);
681 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
682 renderer_->FinishDrawingFrame(&frame1);
683 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
684 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
685 SwapBuffers();
686 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
687 Mock::VerifyAndClearExpectations(&scheduler_);
689 // No overlays, release the resource.
690 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
691 DirectRenderer::DrawingFrame frame3;
692 renderer_->set_expect_overlays(false);
693 renderer_->FinishDrawingFrame(&frame3);
694 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
695 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
696 SwapBuffers();
697 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
698 Mock::VerifyAndClearExpectations(&scheduler_);
700 // Use the same buffer twice.
701 renderer_->set_expect_overlays(true);
702 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
703 renderer_->FinishDrawingFrame(&frame1);
704 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
705 SwapBuffers();
706 Mock::VerifyAndClearExpectations(&scheduler_);
708 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
709 renderer_->FinishDrawingFrame(&frame1);
710 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
711 SwapBuffers();
712 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
713 Mock::VerifyAndClearExpectations(&scheduler_);
715 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
716 renderer_->set_expect_overlays(false);
717 renderer_->FinishDrawingFrame(&frame3);
718 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
719 SwapBuffers();
720 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
721 Mock::VerifyAndClearExpectations(&scheduler_);
724 } // namespace
725 } // namespace cc