tools/gn: Remove unused private fields
[chromium-blink-merge.git] / cc / output / overlay_unittest.cc
blob8fa35cb3cb31fba226944bade89ef99aad0efd80
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::Rect kOverlayTopLeftRect(0, 0, 64, 64);
32 const gfx::Rect kOverlayBottomRightRect(64, 64, 64, 64);
33 const gfx::PointF kUVTopLeft(0.1f, 0.2f);
34 const gfx::PointF kUVBottomRight(1.0f, 1.0f);
36 void MailboxReleased(unsigned sync_point,
37 bool lost_resource,
38 BlockingTaskRunner* main_thread_task_runner) {
41 class SingleOverlayValidator : public OverlayCandidateValidator {
42 public:
43 void CheckOverlaySupport(OverlayCandidateList* surfaces) override;
46 void SingleOverlayValidator::CheckOverlaySupport(
47 OverlayCandidateList* surfaces) {
48 ASSERT_EQ(2U, surfaces->size());
50 OverlayCandidate& candidate = surfaces->back();
51 if (candidate.display_rect.width() == 64)
52 EXPECT_EQ(kOverlayBottomRightRect, candidate.display_rect);
53 else
54 EXPECT_EQ(kOverlayRect, candidate.display_rect);
55 EXPECT_EQ(BoundingRect(kUVTopLeft, kUVBottomRight).ToString(),
56 candidate.uv_rect.ToString());
57 candidate.overlay_handled = true;
60 class SingleOverlayProcessor : public OverlayProcessor {
61 public:
62 SingleOverlayProcessor(OutputSurface* surface,
63 ResourceProvider* resource_provider);
64 // Virtual to allow testing different strategies.
65 void Initialize() override;
68 SingleOverlayProcessor::SingleOverlayProcessor(
69 OutputSurface* surface,
70 ResourceProvider* resource_provider)
71 : OverlayProcessor(surface, resource_provider) {
72 EXPECT_EQ(surface, surface_);
73 EXPECT_EQ(resource_provider, resource_provider_);
76 void SingleOverlayProcessor::Initialize() {
77 OverlayCandidateValidator* candidates =
78 surface_->overlay_candidate_validator();
79 ASSERT_TRUE(candidates != NULL);
80 strategies_.push_back(scoped_ptr<Strategy>(
81 new OverlayStrategySingleOnTop(candidates, resource_provider_)));
84 class DefaultOverlayProcessor : public OverlayProcessor {
85 public:
86 DefaultOverlayProcessor(OutputSurface* surface,
87 ResourceProvider* resource_provider);
88 size_t GetStrategyCount();
91 DefaultOverlayProcessor::DefaultOverlayProcessor(
92 OutputSurface* surface,
93 ResourceProvider* resource_provider)
94 : OverlayProcessor(surface, resource_provider) {}
96 size_t DefaultOverlayProcessor::GetStrategyCount() {
97 return strategies_.size();
100 class OverlayOutputSurface : public OutputSurface {
101 public:
102 explicit OverlayOutputSurface(scoped_refptr<ContextProvider> context_provider)
103 : OutputSurface(context_provider) {}
105 // OutputSurface implementation
106 void SwapBuffers(CompositorFrame* frame) override;
108 void InitWithSingleOverlayValidator() {
109 overlay_candidate_validator_.reset(new SingleOverlayValidator);
113 void OverlayOutputSurface::SwapBuffers(CompositorFrame* frame) {
114 client_->DidSwapBuffers();
115 client_->DidSwapBuffersComplete();
118 scoped_ptr<RenderPass> CreateRenderPass() {
119 RenderPassId id(1, 0);
120 gfx::Rect output_rect(0, 0, 256, 256);
121 bool has_transparent_background = true;
123 scoped_ptr<RenderPass> pass = RenderPass::Create();
124 pass->SetAll(id,
125 output_rect,
126 output_rect,
127 gfx::Transform(),
128 has_transparent_background);
130 SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
131 shared_state->opacity = 1.f;
132 return pass.Pass();
135 ResourceProvider::ResourceId CreateResource(
136 ResourceProvider* resource_provider) {
137 unsigned sync_point = 0;
138 TextureMailbox mailbox =
139 TextureMailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point);
140 mailbox.set_allow_overlay(true);
141 scoped_ptr<SingleReleaseCallbackImpl> release_callback =
142 SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased));
144 return resource_provider->CreateResourceFromTextureMailbox(
145 mailbox, release_callback.Pass());
148 TextureDrawQuad* CreateCandidateQuadAt(ResourceProvider* resource_provider,
149 const SharedQuadState* shared_quad_state,
150 RenderPass* render_pass,
151 const gfx::Rect& rect) {
152 ResourceProvider::ResourceId resource_id = CreateResource(resource_provider);
153 bool premultiplied_alpha = false;
154 bool flipped = false;
155 bool nearest_neighbor = false;
156 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
158 TextureDrawQuad* overlay_quad =
159 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
160 overlay_quad->SetNew(shared_quad_state,
161 rect,
162 rect,
163 rect,
164 resource_id,
165 premultiplied_alpha,
166 kUVTopLeft,
167 kUVBottomRight,
168 SK_ColorTRANSPARENT,
169 vertex_opacity,
170 flipped,
171 nearest_neighbor);
173 return overlay_quad;
176 TextureDrawQuad* CreateFullscreenCandidateQuad(
177 ResourceProvider* resource_provider,
178 const SharedQuadState* shared_quad_state,
179 RenderPass* render_pass) {
180 return CreateCandidateQuadAt(
181 resource_provider, shared_quad_state, render_pass, kOverlayRect);
184 void CreateCheckeredQuadAt(ResourceProvider* resource_provider,
185 const SharedQuadState* shared_quad_state,
186 RenderPass* render_pass,
187 const gfx::Rect& rect) {
188 CheckerboardDrawQuad* checkerboard_quad =
189 render_pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
190 checkerboard_quad->SetNew(shared_quad_state, rect, rect, SkColor());
193 void CreateFullscreenCheckeredQuad(ResourceProvider* resource_provider,
194 const SharedQuadState* shared_quad_state,
195 RenderPass* render_pass) {
196 CreateCheckeredQuadAt(
197 resource_provider, shared_quad_state, render_pass, kOverlayRect);
200 static void CompareRenderPassLists(const RenderPassList& expected_list,
201 const RenderPassList& actual_list) {
202 EXPECT_EQ(expected_list.size(), actual_list.size());
203 for (size_t i = 0; i < actual_list.size(); ++i) {
204 RenderPass* expected = expected_list[i];
205 RenderPass* actual = actual_list[i];
207 EXPECT_EQ(expected->id, actual->id);
208 EXPECT_EQ(expected->output_rect, actual->output_rect);
209 EXPECT_EQ(expected->transform_to_root_target,
210 actual->transform_to_root_target);
211 EXPECT_EQ(expected->damage_rect, actual->damage_rect);
212 EXPECT_EQ(expected->has_transparent_background,
213 actual->has_transparent_background);
215 EXPECT_EQ(expected->shared_quad_state_list.size(),
216 actual->shared_quad_state_list.size());
217 EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size());
219 for (auto exp_iter = expected->quad_list.cbegin(),
220 act_iter = actual->quad_list.cbegin();
221 exp_iter != expected->quad_list.cend();
222 ++exp_iter, ++act_iter) {
223 EXPECT_EQ(exp_iter->rect.ToString(), act_iter->rect.ToString());
224 EXPECT_EQ(exp_iter->shared_quad_state->content_bounds.ToString(),
225 act_iter->shared_quad_state->content_bounds.ToString());
230 TEST(OverlayTest, NoOverlaysByDefault) {
231 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
232 OverlayOutputSurface output_surface(provider);
233 EXPECT_EQ(NULL, output_surface.overlay_candidate_validator());
235 output_surface.InitWithSingleOverlayValidator();
236 EXPECT_TRUE(output_surface.overlay_candidate_validator() != NULL);
239 TEST(OverlayTest, OverlaysProcessorHasStrategy) {
240 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
241 OverlayOutputSurface output_surface(provider);
242 FakeOutputSurfaceClient client;
243 EXPECT_TRUE(output_surface.BindToClient(&client));
244 output_surface.InitWithSingleOverlayValidator();
245 EXPECT_TRUE(output_surface.overlay_candidate_validator() != NULL);
247 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
248 new TestSharedBitmapManager());
249 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
250 &output_surface, shared_bitmap_manager.get(), NULL, NULL, 0, false, 1));
252 scoped_ptr<DefaultOverlayProcessor> overlay_processor(
253 new DefaultOverlayProcessor(&output_surface, resource_provider.get()));
254 overlay_processor->Initialize();
255 EXPECT_GE(1U, overlay_processor->GetStrategyCount());
258 class SingleOverlayOnTopTest : public testing::Test {
259 protected:
260 void SetUp() override {
261 provider_ = TestContextProvider::Create();
262 output_surface_.reset(new OverlayOutputSurface(provider_));
263 EXPECT_TRUE(output_surface_->BindToClient(&client_));
264 output_surface_->InitWithSingleOverlayValidator();
265 EXPECT_TRUE(output_surface_->overlay_candidate_validator() != NULL);
267 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
268 resource_provider_ = ResourceProvider::Create(output_surface_.get(),
269 shared_bitmap_manager_.get(),
270 NULL,
271 NULL,
273 false,
276 overlay_processor_.reset(new SingleOverlayProcessor(
277 output_surface_.get(), resource_provider_.get()));
278 overlay_processor_->Initialize();
281 scoped_refptr<TestContextProvider> provider_;
282 scoped_ptr<OverlayOutputSurface> output_surface_;
283 FakeOutputSurfaceClient client_;
284 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
285 scoped_ptr<ResourceProvider> resource_provider_;
286 scoped_ptr<SingleOverlayProcessor> overlay_processor_;
289 TEST_F(SingleOverlayOnTopTest, SuccessfullOverlay) {
290 scoped_ptr<RenderPass> pass = CreateRenderPass();
291 TextureDrawQuad* original_quad =
292 CreateFullscreenCandidateQuad(resource_provider_.get(),
293 pass->shared_quad_state_list.back(),
294 pass.get());
295 unsigned original_resource_id = original_quad->resource_id;
297 // Add something behind it.
298 CreateFullscreenCheckeredQuad(resource_provider_.get(),
299 pass->shared_quad_state_list.back(),
300 pass.get());
301 CreateFullscreenCheckeredQuad(resource_provider_.get(),
302 pass->shared_quad_state_list.back(),
303 pass.get());
305 RenderPassList pass_list;
306 pass_list.push_back(pass.Pass());
308 // Check for potential candidates.
309 OverlayCandidateList candidate_list;
310 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
312 ASSERT_EQ(1U, pass_list.size());
313 ASSERT_EQ(2U, candidate_list.size());
315 RenderPass* main_pass = pass_list.back();
316 // Check that the quad is gone.
317 EXPECT_EQ(2U, main_pass->quad_list.size());
318 const QuadList& quad_list = main_pass->quad_list;
319 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin();
320 it != quad_list.BackToFrontEnd();
321 ++it) {
322 EXPECT_NE(DrawQuad::TEXTURE_CONTENT, it->material);
325 // Check that the right resource id got extracted.
326 EXPECT_EQ(original_resource_id, candidate_list.back().resource_id);
329 TEST_F(SingleOverlayOnTopTest, NoCandidates) {
330 scoped_ptr<RenderPass> pass = CreateRenderPass();
331 CreateFullscreenCheckeredQuad(resource_provider_.get(),
332 pass->shared_quad_state_list.back(),
333 pass.get());
334 CreateFullscreenCheckeredQuad(resource_provider_.get(),
335 pass->shared_quad_state_list.back(),
336 pass.get());
338 RenderPassList pass_list;
339 pass_list.push_back(pass.Pass());
341 RenderPassList original_pass_list;
342 RenderPass::CopyAll(pass_list, &original_pass_list);
344 OverlayCandidateList candidate_list;
345 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
346 EXPECT_EQ(0U, candidate_list.size());
347 // There should be nothing new here.
348 CompareRenderPassLists(pass_list, original_pass_list);
351 TEST_F(SingleOverlayOnTopTest, OccludedCandidates) {
352 scoped_ptr<RenderPass> pass = CreateRenderPass();
353 CreateFullscreenCheckeredQuad(resource_provider_.get(),
354 pass->shared_quad_state_list.back(),
355 pass.get());
356 CreateFullscreenCheckeredQuad(resource_provider_.get(),
357 pass->shared_quad_state_list.back(),
358 pass.get());
360 CreateFullscreenCandidateQuad(resource_provider_.get(),
361 pass->shared_quad_state_list.back(),
362 pass.get());
364 RenderPassList pass_list;
365 pass_list.push_back(pass.Pass());
367 RenderPassList original_pass_list;
368 RenderPass::CopyAll(pass_list, &original_pass_list);
370 OverlayCandidateList candidate_list;
371 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
372 EXPECT_EQ(0U, candidate_list.size());
373 // There should be nothing new here.
374 CompareRenderPassLists(pass_list, original_pass_list);
377 // Test with multiple render passes.
378 TEST_F(SingleOverlayOnTopTest, MultipleRenderPasses) {
379 RenderPassList pass_list;
380 pass_list.push_back(CreateRenderPass());
382 scoped_ptr<RenderPass> pass = CreateRenderPass();
383 CreateFullscreenCandidateQuad(resource_provider_.get(),
384 pass->shared_quad_state_list.back(),
385 pass.get());
387 // Add something behind it.
388 CreateFullscreenCheckeredQuad(resource_provider_.get(),
389 pass->shared_quad_state_list.back(),
390 pass.get());
391 CreateFullscreenCheckeredQuad(resource_provider_.get(),
392 pass->shared_quad_state_list.back(),
393 pass.get());
395 pass_list.push_back(pass.Pass());
397 RenderPassList original_pass_list;
398 RenderPass::CopyAll(pass_list, &original_pass_list);
400 // Check for potential candidates.
401 OverlayCandidateList candidate_list;
402 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
403 EXPECT_EQ(2U, candidate_list.size());
405 // This should be the same.
406 ASSERT_EQ(2U, pass_list.size());
409 TEST_F(SingleOverlayOnTopTest, RejectPremultipliedAlpha) {
410 scoped_ptr<RenderPass> pass = CreateRenderPass();
411 TextureDrawQuad* quad =
412 CreateFullscreenCandidateQuad(resource_provider_.get(),
413 pass->shared_quad_state_list.back(),
414 pass.get());
415 quad->premultiplied_alpha = true;
417 RenderPassList pass_list;
418 pass_list.push_back(pass.Pass());
419 OverlayCandidateList candidate_list;
420 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
421 EXPECT_EQ(1U, pass_list.size());
422 EXPECT_EQ(0U, candidate_list.size());
425 TEST_F(SingleOverlayOnTopTest, RejectBlending) {
426 scoped_ptr<RenderPass> pass = CreateRenderPass();
427 TextureDrawQuad* quad =
428 CreateFullscreenCandidateQuad(resource_provider_.get(),
429 pass->shared_quad_state_list.back(),
430 pass.get());
431 quad->needs_blending = true;
433 RenderPassList pass_list;
434 pass_list.push_back(pass.Pass());
435 OverlayCandidateList candidate_list;
436 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
437 ASSERT_EQ(1U, pass_list.size());
438 EXPECT_EQ(0U, candidate_list.size());
441 TEST_F(SingleOverlayOnTopTest, RejectBackgroundColor) {
442 scoped_ptr<RenderPass> pass = CreateRenderPass();
443 TextureDrawQuad* quad =
444 CreateFullscreenCandidateQuad(resource_provider_.get(),
445 pass->shared_quad_state_list.back(),
446 pass.get());
447 quad->background_color = SK_ColorBLACK;
449 RenderPassList pass_list;
450 pass_list.push_back(pass.Pass());
451 OverlayCandidateList candidate_list;
452 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
453 ASSERT_EQ(1U, pass_list.size());
454 EXPECT_EQ(0U, candidate_list.size());
457 TEST_F(SingleOverlayOnTopTest, RejectBlendMode) {
458 scoped_ptr<RenderPass> pass = CreateRenderPass();
459 CreateFullscreenCandidateQuad(resource_provider_.get(),
460 pass->shared_quad_state_list.back(),
461 pass.get());
462 pass->shared_quad_state_list.back()->blend_mode = SkXfermode::kScreen_Mode;
464 RenderPassList pass_list;
465 pass_list.push_back(pass.Pass());
466 OverlayCandidateList candidate_list;
467 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
468 ASSERT_EQ(1U, pass_list.size());
469 EXPECT_EQ(0U, candidate_list.size());
472 TEST_F(SingleOverlayOnTopTest, RejectOpacity) {
473 scoped_ptr<RenderPass> pass = CreateRenderPass();
474 CreateFullscreenCandidateQuad(resource_provider_.get(),
475 pass->shared_quad_state_list.back(),
476 pass.get());
477 pass->shared_quad_state_list.back()->opacity = 0.5f;
479 RenderPassList pass_list;
480 pass_list.push_back(pass.Pass());
481 OverlayCandidateList candidate_list;
482 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
483 ASSERT_EQ(1U, pass_list.size());
484 EXPECT_EQ(0U, candidate_list.size());
487 TEST_F(SingleOverlayOnTopTest, RejectTransform) {
488 scoped_ptr<RenderPass> pass = CreateRenderPass();
489 CreateFullscreenCandidateQuad(resource_provider_.get(),
490 pass->shared_quad_state_list.back(),
491 pass.get());
492 pass->shared_quad_state_list.back()->content_to_target_transform.Scale(2.f,
493 2.f);
495 RenderPassList pass_list;
496 pass_list.push_back(pass.Pass());
497 OverlayCandidateList candidate_list;
498 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
499 ASSERT_EQ(1U, pass_list.size());
500 EXPECT_EQ(0U, candidate_list.size());
503 TEST_F(SingleOverlayOnTopTest, AllowNotTopIfNotOccluded) {
504 scoped_ptr<RenderPass> pass = CreateRenderPass();
505 CreateCheckeredQuadAt(resource_provider_.get(),
506 pass->shared_quad_state_list.back(),
507 pass.get(),
508 kOverlayTopLeftRect);
509 CreateCandidateQuadAt(resource_provider_.get(),
510 pass->shared_quad_state_list.back(),
511 pass.get(),
512 kOverlayBottomRightRect);
514 RenderPassList pass_list;
515 pass_list.push_back(pass.Pass());
517 RenderPassList original_pass_list;
518 RenderPass::CopyAll(pass_list, &original_pass_list);
520 OverlayCandidateList candidate_list;
521 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
522 EXPECT_EQ(1U, pass_list.size());
523 EXPECT_EQ(2U, candidate_list.size());
526 class OverlayInfoRendererGL : public GLRenderer {
527 public:
528 OverlayInfoRendererGL(RendererClient* client,
529 const RendererSettings* settings,
530 OutputSurface* output_surface,
531 ResourceProvider* resource_provider)
532 : GLRenderer(client,
533 settings,
534 output_surface,
535 resource_provider,
536 NULL,
538 expect_overlays_(false) {}
540 MOCK_METHOD2(DoDrawQuad, void(DrawingFrame* frame, const DrawQuad* quad));
542 using GLRenderer::BeginDrawingFrame;
544 void FinishDrawingFrame(DrawingFrame* frame) override {
545 GLRenderer::FinishDrawingFrame(frame);
547 if (!expect_overlays_) {
548 EXPECT_EQ(0U, frame->overlay_list.size());
549 return;
552 ASSERT_EQ(2U, frame->overlay_list.size());
553 EXPECT_NE(0U, frame->overlay_list.back().resource_id);
556 void set_expect_overlays(bool expect_overlays) {
557 expect_overlays_ = expect_overlays;
560 private:
561 bool expect_overlays_;
564 class FakeRendererClient : public RendererClient {
565 public:
566 // RendererClient methods.
567 void SetFullRootLayerDamage() override {}
570 class MockOverlayScheduler {
571 public:
572 MOCK_METHOD5(Schedule,
573 void(int plane_z_order,
574 gfx::OverlayTransform plane_transform,
575 unsigned overlay_texture_id,
576 const gfx::Rect& display_bounds,
577 const gfx::RectF& uv_rect));
580 class GLRendererWithOverlaysTest : public testing::Test {
581 protected:
582 GLRendererWithOverlaysTest() {
583 provider_ = TestContextProvider::Create();
584 output_surface_.reset(new OverlayOutputSurface(provider_));
585 CHECK(output_surface_->BindToClient(&output_surface_client_));
586 resource_provider_ = ResourceProvider::Create(
587 output_surface_.get(), NULL, NULL, NULL, 0, false, 1);
589 provider_->support()->SetScheduleOverlayPlaneCallback(base::Bind(
590 &MockOverlayScheduler::Schedule, base::Unretained(&scheduler_)));
593 void Init(bool use_validator) {
594 if (use_validator)
595 output_surface_->InitWithSingleOverlayValidator();
597 renderer_ =
598 make_scoped_ptr(new OverlayInfoRendererGL(&renderer_client_,
599 &settings_,
600 output_surface_.get(),
601 resource_provider_.get()));
604 void SwapBuffers() { renderer_->SwapBuffers(CompositorFrameMetadata()); }
606 RendererSettings settings_;
607 FakeOutputSurfaceClient output_surface_client_;
608 scoped_ptr<OverlayOutputSurface> output_surface_;
609 FakeRendererClient renderer_client_;
610 scoped_ptr<ResourceProvider> resource_provider_;
611 scoped_ptr<OverlayInfoRendererGL> renderer_;
612 scoped_refptr<TestContextProvider> provider_;
613 MockOverlayScheduler scheduler_;
616 TEST_F(GLRendererWithOverlaysTest, OverlayQuadNotDrawn) {
617 bool use_validator = true;
618 Init(use_validator);
619 renderer_->set_expect_overlays(true);
620 gfx::Rect viewport_rect(16, 16);
622 scoped_ptr<RenderPass> pass = CreateRenderPass();
624 CreateFullscreenCandidateQuad(resource_provider_.get(),
625 pass->shared_quad_state_list.back(),
626 pass.get());
628 CreateFullscreenCheckeredQuad(resource_provider_.get(),
629 pass->shared_quad_state_list.back(),
630 pass.get());
631 CreateFullscreenCheckeredQuad(resource_provider_.get(),
632 pass->shared_quad_state_list.back(),
633 pass.get());
635 RenderPassList pass_list;
636 pass_list.push_back(pass.Pass());
638 // Candidate pass was taken out and extra skipped pass added,
639 // so only draw 2 quads.
640 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(2);
641 EXPECT_CALL(scheduler_,
642 Schedule(1,
643 gfx::OVERLAY_TRANSFORM_NONE,
645 kOverlayRect,
646 BoundingRect(kUVTopLeft, kUVBottomRight))).Times(1);
647 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
649 SwapBuffers();
651 Mock::VerifyAndClearExpectations(renderer_.get());
652 Mock::VerifyAndClearExpectations(&scheduler_);
655 TEST_F(GLRendererWithOverlaysTest, OccludedQuadDrawn) {
656 bool use_validator = true;
657 Init(use_validator);
658 renderer_->set_expect_overlays(false);
659 gfx::Rect viewport_rect(16, 16);
661 scoped_ptr<RenderPass> pass = CreateRenderPass();
663 CreateFullscreenCheckeredQuad(resource_provider_.get(),
664 pass->shared_quad_state_list.back(),
665 pass.get());
666 CreateFullscreenCheckeredQuad(resource_provider_.get(),
667 pass->shared_quad_state_list.back(),
668 pass.get());
670 CreateFullscreenCandidateQuad(resource_provider_.get(),
671 pass->shared_quad_state_list.back(),
672 pass.get());
674 RenderPassList pass_list;
675 pass_list.push_back(pass.Pass());
677 // 3 quads in the pass, all should draw.
678 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3);
679 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
680 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
682 SwapBuffers();
684 Mock::VerifyAndClearExpectations(renderer_.get());
685 Mock::VerifyAndClearExpectations(&scheduler_);
688 TEST_F(GLRendererWithOverlaysTest, NoValidatorNoOverlay) {
689 bool use_validator = false;
690 Init(use_validator);
691 renderer_->set_expect_overlays(false);
692 gfx::Rect viewport_rect(16, 16);
694 scoped_ptr<RenderPass> pass = CreateRenderPass();
696 CreateFullscreenCandidateQuad(resource_provider_.get(),
697 pass->shared_quad_state_list.back(),
698 pass.get());
700 CreateFullscreenCheckeredQuad(resource_provider_.get(),
701 pass->shared_quad_state_list.back(),
702 pass.get());
703 CreateFullscreenCheckeredQuad(resource_provider_.get(),
704 pass->shared_quad_state_list.back(),
705 pass.get());
707 RenderPassList pass_list;
708 pass_list.push_back(pass.Pass());
710 // Should see no overlays.
711 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3);
712 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
713 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
715 SwapBuffers();
717 Mock::VerifyAndClearExpectations(renderer_.get());
718 Mock::VerifyAndClearExpectations(&scheduler_);
721 TEST_F(GLRendererWithOverlaysTest, ResourcesExportedAndReturned) {
722 bool use_validator = true;
723 Init(use_validator);
724 renderer_->set_expect_overlays(true);
726 ResourceProvider::ResourceId resource1 =
727 CreateResource(resource_provider_.get());
728 ResourceProvider::ResourceId resource2 =
729 CreateResource(resource_provider_.get());
731 scoped_ptr<RenderPass> pass = CreateRenderPass();
732 RenderPassList pass_list;
733 pass_list.push_back(pass.Pass());
735 DirectRenderer::DrawingFrame frame1;
736 frame1.render_passes_in_draw_order = &pass_list;
737 frame1.overlay_list.resize(2);
738 OverlayCandidate& overlay1 = frame1.overlay_list.back();
739 overlay1.resource_id = resource1;
740 overlay1.plane_z_order = 1;
742 DirectRenderer::DrawingFrame frame2;
743 frame2.render_passes_in_draw_order = &pass_list;
744 frame2.overlay_list.resize(2);
745 OverlayCandidate& overlay2 = frame2.overlay_list.back();
746 overlay2.resource_id = resource2;
747 overlay2.plane_z_order = 1;
749 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
750 renderer_->BeginDrawingFrame(&frame1);
751 renderer_->FinishDrawingFrame(&frame1);
752 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
753 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
754 SwapBuffers();
755 Mock::VerifyAndClearExpectations(&scheduler_);
757 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
758 renderer_->BeginDrawingFrame(&frame2);
759 renderer_->FinishDrawingFrame(&frame2);
760 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
761 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
762 SwapBuffers();
763 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
764 Mock::VerifyAndClearExpectations(&scheduler_);
766 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
767 renderer_->BeginDrawingFrame(&frame1);
768 renderer_->FinishDrawingFrame(&frame1);
769 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
770 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
771 SwapBuffers();
772 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
773 Mock::VerifyAndClearExpectations(&scheduler_);
775 // No overlays, release the resource.
776 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
777 DirectRenderer::DrawingFrame frame3;
778 frame3.render_passes_in_draw_order = &pass_list;
779 renderer_->set_expect_overlays(false);
780 renderer_->BeginDrawingFrame(&frame3);
781 renderer_->FinishDrawingFrame(&frame3);
782 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
783 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
784 SwapBuffers();
785 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
786 Mock::VerifyAndClearExpectations(&scheduler_);
788 // Use the same buffer twice.
789 renderer_->set_expect_overlays(true);
790 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
791 renderer_->BeginDrawingFrame(&frame1);
792 renderer_->FinishDrawingFrame(&frame1);
793 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
794 SwapBuffers();
795 Mock::VerifyAndClearExpectations(&scheduler_);
797 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
798 renderer_->BeginDrawingFrame(&frame1);
799 renderer_->FinishDrawingFrame(&frame1);
800 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
801 SwapBuffers();
802 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
803 Mock::VerifyAndClearExpectations(&scheduler_);
805 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
806 renderer_->set_expect_overlays(false);
807 renderer_->BeginDrawingFrame(&frame3);
808 renderer_->FinishDrawingFrame(&frame3);
809 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
810 SwapBuffers();
811 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
812 Mock::VerifyAndClearExpectations(&scheduler_);
815 } // namespace
816 } // namespace cc