Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / cc / output / overlay_unittest.cc
blob33c6f4a6795766014b2a00f9b367396dd2cdb820
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 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
157 TextureDrawQuad* overlay_quad =
158 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
159 overlay_quad->SetNew(shared_quad_state,
160 rect,
161 rect,
162 rect,
163 resource_id,
164 premultiplied_alpha,
165 kUVTopLeft,
166 kUVBottomRight,
167 SK_ColorTRANSPARENT,
168 vertex_opacity,
169 flipped);
171 return overlay_quad;
174 TextureDrawQuad* CreateFullscreenCandidateQuad(
175 ResourceProvider* resource_provider,
176 const SharedQuadState* shared_quad_state,
177 RenderPass* render_pass) {
178 return CreateCandidateQuadAt(
179 resource_provider, shared_quad_state, render_pass, kOverlayRect);
182 void CreateCheckeredQuadAt(ResourceProvider* resource_provider,
183 const SharedQuadState* shared_quad_state,
184 RenderPass* render_pass,
185 const gfx::Rect& rect) {
186 CheckerboardDrawQuad* checkerboard_quad =
187 render_pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
188 checkerboard_quad->SetNew(shared_quad_state, rect, rect, SkColor());
191 void CreateFullscreenCheckeredQuad(ResourceProvider* resource_provider,
192 const SharedQuadState* shared_quad_state,
193 RenderPass* render_pass) {
194 CreateCheckeredQuadAt(
195 resource_provider, shared_quad_state, render_pass, kOverlayRect);
198 static void CompareRenderPassLists(const RenderPassList& expected_list,
199 const RenderPassList& actual_list) {
200 EXPECT_EQ(expected_list.size(), actual_list.size());
201 for (size_t i = 0; i < actual_list.size(); ++i) {
202 RenderPass* expected = expected_list[i];
203 RenderPass* actual = actual_list[i];
205 EXPECT_EQ(expected->id, actual->id);
206 EXPECT_RECT_EQ(expected->output_rect, actual->output_rect);
207 EXPECT_EQ(expected->transform_to_root_target,
208 actual->transform_to_root_target);
209 EXPECT_RECT_EQ(expected->damage_rect, actual->damage_rect);
210 EXPECT_EQ(expected->has_transparent_background,
211 actual->has_transparent_background);
213 EXPECT_EQ(expected->shared_quad_state_list.size(),
214 actual->shared_quad_state_list.size());
215 EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size());
217 for (auto exp_iter = expected->quad_list.cbegin(),
218 act_iter = actual->quad_list.cbegin();
219 exp_iter != expected->quad_list.cend();
220 ++exp_iter, ++act_iter) {
221 EXPECT_EQ(exp_iter->rect.ToString(), act_iter->rect.ToString());
222 EXPECT_EQ(exp_iter->shared_quad_state->content_bounds.ToString(),
223 act_iter->shared_quad_state->content_bounds.ToString());
228 TEST(OverlayTest, NoOverlaysByDefault) {
229 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
230 OverlayOutputSurface output_surface(provider);
231 EXPECT_EQ(NULL, output_surface.overlay_candidate_validator());
233 output_surface.InitWithSingleOverlayValidator();
234 EXPECT_TRUE(output_surface.overlay_candidate_validator() != NULL);
237 TEST(OverlayTest, OverlaysProcessorHasStrategy) {
238 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
239 OverlayOutputSurface output_surface(provider);
240 FakeOutputSurfaceClient client;
241 EXPECT_TRUE(output_surface.BindToClient(&client));
242 output_surface.InitWithSingleOverlayValidator();
243 EXPECT_TRUE(output_surface.overlay_candidate_validator() != NULL);
245 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
246 new TestSharedBitmapManager());
247 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
248 &output_surface, shared_bitmap_manager.get(), NULL, NULL, 0, false, 1));
250 scoped_ptr<DefaultOverlayProcessor> overlay_processor(
251 new DefaultOverlayProcessor(&output_surface, resource_provider.get()));
252 overlay_processor->Initialize();
253 EXPECT_GE(1U, overlay_processor->GetStrategyCount());
256 class SingleOverlayOnTopTest : public testing::Test {
257 protected:
258 virtual void SetUp() {
259 provider_ = TestContextProvider::Create();
260 output_surface_.reset(new OverlayOutputSurface(provider_));
261 EXPECT_TRUE(output_surface_->BindToClient(&client_));
262 output_surface_->InitWithSingleOverlayValidator();
263 EXPECT_TRUE(output_surface_->overlay_candidate_validator() != NULL);
265 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
266 resource_provider_ = ResourceProvider::Create(output_surface_.get(),
267 shared_bitmap_manager_.get(),
268 NULL,
269 NULL,
271 false,
274 overlay_processor_.reset(new SingleOverlayProcessor(
275 output_surface_.get(), resource_provider_.get()));
276 overlay_processor_->Initialize();
279 scoped_refptr<TestContextProvider> provider_;
280 scoped_ptr<OverlayOutputSurface> output_surface_;
281 FakeOutputSurfaceClient client_;
282 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
283 scoped_ptr<ResourceProvider> resource_provider_;
284 scoped_ptr<SingleOverlayProcessor> overlay_processor_;
287 TEST_F(SingleOverlayOnTopTest, SuccessfullOverlay) {
288 scoped_ptr<RenderPass> pass = CreateRenderPass();
289 TextureDrawQuad* original_quad =
290 CreateFullscreenCandidateQuad(resource_provider_.get(),
291 pass->shared_quad_state_list.back(),
292 pass.get());
293 unsigned original_resource_id = original_quad->resource_id;
295 // Add something behind it.
296 CreateFullscreenCheckeredQuad(resource_provider_.get(),
297 pass->shared_quad_state_list.back(),
298 pass.get());
299 CreateFullscreenCheckeredQuad(resource_provider_.get(),
300 pass->shared_quad_state_list.back(),
301 pass.get());
303 RenderPassList pass_list;
304 pass_list.push_back(pass.Pass());
306 // Check for potential candidates.
307 OverlayCandidateList candidate_list;
308 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
310 ASSERT_EQ(1U, pass_list.size());
311 ASSERT_EQ(2U, candidate_list.size());
313 RenderPass* main_pass = pass_list.back();
314 // Check that the quad is gone.
315 EXPECT_EQ(2U, main_pass->quad_list.size());
316 const QuadList& quad_list = main_pass->quad_list;
317 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin();
318 it != quad_list.BackToFrontEnd();
319 ++it) {
320 EXPECT_NE(DrawQuad::TEXTURE_CONTENT, it->material);
323 // Check that the right resource id got extracted.
324 EXPECT_EQ(original_resource_id, candidate_list.back().resource_id);
327 TEST_F(SingleOverlayOnTopTest, NoCandidates) {
328 scoped_ptr<RenderPass> pass = CreateRenderPass();
329 CreateFullscreenCheckeredQuad(resource_provider_.get(),
330 pass->shared_quad_state_list.back(),
331 pass.get());
332 CreateFullscreenCheckeredQuad(resource_provider_.get(),
333 pass->shared_quad_state_list.back(),
334 pass.get());
336 RenderPassList pass_list;
337 pass_list.push_back(pass.Pass());
339 RenderPassList original_pass_list;
340 RenderPass::CopyAll(pass_list, &original_pass_list);
342 OverlayCandidateList candidate_list;
343 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
344 EXPECT_EQ(0U, candidate_list.size());
345 // There should be nothing new here.
346 CompareRenderPassLists(pass_list, original_pass_list);
349 TEST_F(SingleOverlayOnTopTest, OccludedCandidates) {
350 scoped_ptr<RenderPass> pass = CreateRenderPass();
351 CreateFullscreenCheckeredQuad(resource_provider_.get(),
352 pass->shared_quad_state_list.back(),
353 pass.get());
354 CreateFullscreenCheckeredQuad(resource_provider_.get(),
355 pass->shared_quad_state_list.back(),
356 pass.get());
358 CreateFullscreenCandidateQuad(resource_provider_.get(),
359 pass->shared_quad_state_list.back(),
360 pass.get());
362 RenderPassList pass_list;
363 pass_list.push_back(pass.Pass());
365 RenderPassList original_pass_list;
366 RenderPass::CopyAll(pass_list, &original_pass_list);
368 OverlayCandidateList candidate_list;
369 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
370 EXPECT_EQ(0U, candidate_list.size());
371 // There should be nothing new here.
372 CompareRenderPassLists(pass_list, original_pass_list);
375 // Test with multiple render passes.
376 TEST_F(SingleOverlayOnTopTest, MultipleRenderPasses) {
377 RenderPassList pass_list;
378 pass_list.push_back(CreateRenderPass());
380 scoped_ptr<RenderPass> pass = CreateRenderPass();
381 CreateFullscreenCandidateQuad(resource_provider_.get(),
382 pass->shared_quad_state_list.back(),
383 pass.get());
385 // Add something behind it.
386 CreateFullscreenCheckeredQuad(resource_provider_.get(),
387 pass->shared_quad_state_list.back(),
388 pass.get());
389 CreateFullscreenCheckeredQuad(resource_provider_.get(),
390 pass->shared_quad_state_list.back(),
391 pass.get());
393 pass_list.push_back(pass.Pass());
395 RenderPassList original_pass_list;
396 RenderPass::CopyAll(pass_list, &original_pass_list);
398 // Check for potential candidates.
399 OverlayCandidateList candidate_list;
400 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
401 EXPECT_EQ(2U, candidate_list.size());
403 // This should be the same.
404 ASSERT_EQ(2U, pass_list.size());
407 TEST_F(SingleOverlayOnTopTest, RejectPremultipliedAlpha) {
408 scoped_ptr<RenderPass> pass = CreateRenderPass();
409 TextureDrawQuad* quad =
410 CreateFullscreenCandidateQuad(resource_provider_.get(),
411 pass->shared_quad_state_list.back(),
412 pass.get());
413 quad->premultiplied_alpha = true;
415 RenderPassList pass_list;
416 pass_list.push_back(pass.Pass());
417 OverlayCandidateList candidate_list;
418 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
419 EXPECT_EQ(1U, pass_list.size());
420 EXPECT_EQ(0U, candidate_list.size());
423 TEST_F(SingleOverlayOnTopTest, RejectBlending) {
424 scoped_ptr<RenderPass> pass = CreateRenderPass();
425 TextureDrawQuad* quad =
426 CreateFullscreenCandidateQuad(resource_provider_.get(),
427 pass->shared_quad_state_list.back(),
428 pass.get());
429 quad->needs_blending = true;
431 RenderPassList pass_list;
432 pass_list.push_back(pass.Pass());
433 OverlayCandidateList candidate_list;
434 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
435 ASSERT_EQ(1U, pass_list.size());
436 EXPECT_EQ(0U, candidate_list.size());
439 TEST_F(SingleOverlayOnTopTest, RejectBackgroundColor) {
440 scoped_ptr<RenderPass> pass = CreateRenderPass();
441 TextureDrawQuad* quad =
442 CreateFullscreenCandidateQuad(resource_provider_.get(),
443 pass->shared_quad_state_list.back(),
444 pass.get());
445 quad->background_color = SK_ColorBLACK;
447 RenderPassList pass_list;
448 pass_list.push_back(pass.Pass());
449 OverlayCandidateList candidate_list;
450 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
451 ASSERT_EQ(1U, pass_list.size());
452 EXPECT_EQ(0U, candidate_list.size());
455 TEST_F(SingleOverlayOnTopTest, RejectBlendMode) {
456 scoped_ptr<RenderPass> pass = CreateRenderPass();
457 CreateFullscreenCandidateQuad(resource_provider_.get(),
458 pass->shared_quad_state_list.back(),
459 pass.get());
460 pass->shared_quad_state_list.back()->blend_mode = SkXfermode::kScreen_Mode;
462 RenderPassList pass_list;
463 pass_list.push_back(pass.Pass());
464 OverlayCandidateList candidate_list;
465 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
466 ASSERT_EQ(1U, pass_list.size());
467 EXPECT_EQ(0U, candidate_list.size());
470 TEST_F(SingleOverlayOnTopTest, RejectOpacity) {
471 scoped_ptr<RenderPass> pass = CreateRenderPass();
472 CreateFullscreenCandidateQuad(resource_provider_.get(),
473 pass->shared_quad_state_list.back(),
474 pass.get());
475 pass->shared_quad_state_list.back()->opacity = 0.5f;
477 RenderPassList pass_list;
478 pass_list.push_back(pass.Pass());
479 OverlayCandidateList candidate_list;
480 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
481 ASSERT_EQ(1U, pass_list.size());
482 EXPECT_EQ(0U, candidate_list.size());
485 TEST_F(SingleOverlayOnTopTest, RejectTransform) {
486 scoped_ptr<RenderPass> pass = CreateRenderPass();
487 CreateFullscreenCandidateQuad(resource_provider_.get(),
488 pass->shared_quad_state_list.back(),
489 pass.get());
490 pass->shared_quad_state_list.back()->content_to_target_transform.Scale(2.f,
491 2.f);
493 RenderPassList pass_list;
494 pass_list.push_back(pass.Pass());
495 OverlayCandidateList candidate_list;
496 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
497 ASSERT_EQ(1U, pass_list.size());
498 EXPECT_EQ(0U, candidate_list.size());
501 TEST_F(SingleOverlayOnTopTest, AllowNotTopIfNotOccluded) {
502 scoped_ptr<RenderPass> pass = CreateRenderPass();
503 CreateCheckeredQuadAt(resource_provider_.get(),
504 pass->shared_quad_state_list.back(),
505 pass.get(),
506 kOverlayTopLeftRect);
507 CreateCandidateQuadAt(resource_provider_.get(),
508 pass->shared_quad_state_list.back(),
509 pass.get(),
510 kOverlayBottomRightRect);
512 RenderPassList pass_list;
513 pass_list.push_back(pass.Pass());
515 RenderPassList original_pass_list;
516 RenderPass::CopyAll(pass_list, &original_pass_list);
518 OverlayCandidateList candidate_list;
519 overlay_processor_->ProcessForOverlays(&pass_list, &candidate_list);
520 EXPECT_EQ(1U, pass_list.size());
521 EXPECT_EQ(2U, candidate_list.size());
524 class OverlayInfoRendererGL : public GLRenderer {
525 public:
526 OverlayInfoRendererGL(RendererClient* client,
527 const RendererSettings* settings,
528 OutputSurface* output_surface,
529 ResourceProvider* resource_provider)
530 : GLRenderer(client,
531 settings,
532 output_surface,
533 resource_provider,
534 NULL,
536 expect_overlays_(false) {}
538 MOCK_METHOD2(DoDrawQuad, void(DrawingFrame* frame, const DrawQuad* quad));
540 using GLRenderer::BeginDrawingFrame;
542 void FinishDrawingFrame(DrawingFrame* frame) override {
543 GLRenderer::FinishDrawingFrame(frame);
545 if (!expect_overlays_) {
546 EXPECT_EQ(0U, frame->overlay_list.size());
547 return;
550 ASSERT_EQ(2U, frame->overlay_list.size());
551 EXPECT_NE(0U, frame->overlay_list.back().resource_id);
554 void set_expect_overlays(bool expect_overlays) {
555 expect_overlays_ = expect_overlays;
558 private:
559 bool expect_overlays_;
562 class FakeRendererClient : public RendererClient {
563 public:
564 // RendererClient methods.
565 void SetFullRootLayerDamage() override {}
568 class MockOverlayScheduler {
569 public:
570 MOCK_METHOD5(Schedule,
571 void(int plane_z_order,
572 gfx::OverlayTransform plane_transform,
573 unsigned overlay_texture_id,
574 const gfx::Rect& display_bounds,
575 const gfx::RectF& uv_rect));
578 class GLRendererWithOverlaysTest : public testing::Test {
579 protected:
580 GLRendererWithOverlaysTest() {
581 provider_ = TestContextProvider::Create();
582 output_surface_.reset(new OverlayOutputSurface(provider_));
583 CHECK(output_surface_->BindToClient(&output_surface_client_));
584 resource_provider_ = ResourceProvider::Create(
585 output_surface_.get(), NULL, NULL, NULL, 0, false, 1);
587 provider_->support()->SetScheduleOverlayPlaneCallback(base::Bind(
588 &MockOverlayScheduler::Schedule, base::Unretained(&scheduler_)));
591 void Init(bool use_validator) {
592 if (use_validator)
593 output_surface_->InitWithSingleOverlayValidator();
595 renderer_ =
596 make_scoped_ptr(new OverlayInfoRendererGL(&renderer_client_,
597 &settings_,
598 output_surface_.get(),
599 resource_provider_.get()));
602 void SwapBuffers() { renderer_->SwapBuffers(CompositorFrameMetadata()); }
604 RendererSettings settings_;
605 FakeOutputSurfaceClient output_surface_client_;
606 scoped_ptr<OverlayOutputSurface> output_surface_;
607 FakeRendererClient renderer_client_;
608 scoped_ptr<ResourceProvider> resource_provider_;
609 scoped_ptr<OverlayInfoRendererGL> renderer_;
610 scoped_refptr<TestContextProvider> provider_;
611 MockOverlayScheduler scheduler_;
614 TEST_F(GLRendererWithOverlaysTest, OverlayQuadNotDrawn) {
615 bool use_validator = true;
616 Init(use_validator);
617 renderer_->set_expect_overlays(true);
618 gfx::Rect viewport_rect(16, 16);
620 scoped_ptr<RenderPass> pass = CreateRenderPass();
622 CreateFullscreenCandidateQuad(resource_provider_.get(),
623 pass->shared_quad_state_list.back(),
624 pass.get());
626 CreateFullscreenCheckeredQuad(resource_provider_.get(),
627 pass->shared_quad_state_list.back(),
628 pass.get());
629 CreateFullscreenCheckeredQuad(resource_provider_.get(),
630 pass->shared_quad_state_list.back(),
631 pass.get());
633 RenderPassList pass_list;
634 pass_list.push_back(pass.Pass());
636 // Candidate pass was taken out and extra skipped pass added,
637 // so only draw 2 quads.
638 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(2);
639 EXPECT_CALL(scheduler_,
640 Schedule(1,
641 gfx::OVERLAY_TRANSFORM_NONE,
643 kOverlayRect,
644 BoundingRect(kUVTopLeft, kUVBottomRight))).Times(1);
645 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
647 SwapBuffers();
649 Mock::VerifyAndClearExpectations(renderer_.get());
650 Mock::VerifyAndClearExpectations(&scheduler_);
653 TEST_F(GLRendererWithOverlaysTest, OccludedQuadDrawn) {
654 bool use_validator = true;
655 Init(use_validator);
656 renderer_->set_expect_overlays(false);
657 gfx::Rect viewport_rect(16, 16);
659 scoped_ptr<RenderPass> pass = CreateRenderPass();
661 CreateFullscreenCheckeredQuad(resource_provider_.get(),
662 pass->shared_quad_state_list.back(),
663 pass.get());
664 CreateFullscreenCheckeredQuad(resource_provider_.get(),
665 pass->shared_quad_state_list.back(),
666 pass.get());
668 CreateFullscreenCandidateQuad(resource_provider_.get(),
669 pass->shared_quad_state_list.back(),
670 pass.get());
672 RenderPassList pass_list;
673 pass_list.push_back(pass.Pass());
675 // 3 quads in the pass, all should draw.
676 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3);
677 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
678 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
680 SwapBuffers();
682 Mock::VerifyAndClearExpectations(renderer_.get());
683 Mock::VerifyAndClearExpectations(&scheduler_);
686 TEST_F(GLRendererWithOverlaysTest, NoValidatorNoOverlay) {
687 bool use_validator = false;
688 Init(use_validator);
689 renderer_->set_expect_overlays(false);
690 gfx::Rect viewport_rect(16, 16);
692 scoped_ptr<RenderPass> pass = CreateRenderPass();
694 CreateFullscreenCandidateQuad(resource_provider_.get(),
695 pass->shared_quad_state_list.back(),
696 pass.get());
698 CreateFullscreenCheckeredQuad(resource_provider_.get(),
699 pass->shared_quad_state_list.back(),
700 pass.get());
701 CreateFullscreenCheckeredQuad(resource_provider_.get(),
702 pass->shared_quad_state_list.back(),
703 pass.get());
705 RenderPassList pass_list;
706 pass_list.push_back(pass.Pass());
708 // Should see no overlays.
709 EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3);
710 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
711 renderer_->DrawFrame(&pass_list, 1.f, viewport_rect, viewport_rect, false);
713 SwapBuffers();
715 Mock::VerifyAndClearExpectations(renderer_.get());
716 Mock::VerifyAndClearExpectations(&scheduler_);
719 TEST_F(GLRendererWithOverlaysTest, ResourcesExportedAndReturned) {
720 bool use_validator = true;
721 Init(use_validator);
722 renderer_->set_expect_overlays(true);
724 ResourceProvider::ResourceId resource1 =
725 CreateResource(resource_provider_.get());
726 ResourceProvider::ResourceId resource2 =
727 CreateResource(resource_provider_.get());
729 scoped_ptr<RenderPass> pass = CreateRenderPass();
730 RenderPassList pass_list;
731 pass_list.push_back(pass.Pass());
733 DirectRenderer::DrawingFrame frame1;
734 frame1.render_passes_in_draw_order = &pass_list;
735 frame1.overlay_list.resize(2);
736 OverlayCandidate& overlay1 = frame1.overlay_list.back();
737 overlay1.resource_id = resource1;
738 overlay1.plane_z_order = 1;
740 DirectRenderer::DrawingFrame frame2;
741 frame2.render_passes_in_draw_order = &pass_list;
742 frame2.overlay_list.resize(2);
743 OverlayCandidate& overlay2 = frame2.overlay_list.back();
744 overlay2.resource_id = resource2;
745 overlay2.plane_z_order = 1;
747 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
748 renderer_->BeginDrawingFrame(&frame1);
749 renderer_->FinishDrawingFrame(&frame1);
750 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
751 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
752 SwapBuffers();
753 Mock::VerifyAndClearExpectations(&scheduler_);
755 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
756 renderer_->BeginDrawingFrame(&frame2);
757 renderer_->FinishDrawingFrame(&frame2);
758 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
759 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
760 SwapBuffers();
761 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
762 Mock::VerifyAndClearExpectations(&scheduler_);
764 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
765 renderer_->BeginDrawingFrame(&frame1);
766 renderer_->FinishDrawingFrame(&frame1);
767 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
768 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
769 SwapBuffers();
770 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
771 Mock::VerifyAndClearExpectations(&scheduler_);
773 // No overlays, release the resource.
774 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
775 DirectRenderer::DrawingFrame frame3;
776 frame3.render_passes_in_draw_order = &pass_list;
777 renderer_->set_expect_overlays(false);
778 renderer_->BeginDrawingFrame(&frame3);
779 renderer_->FinishDrawingFrame(&frame3);
780 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
781 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
782 SwapBuffers();
783 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
784 Mock::VerifyAndClearExpectations(&scheduler_);
786 // Use the same buffer twice.
787 renderer_->set_expect_overlays(true);
788 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
789 renderer_->BeginDrawingFrame(&frame1);
790 renderer_->FinishDrawingFrame(&frame1);
791 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
792 SwapBuffers();
793 Mock::VerifyAndClearExpectations(&scheduler_);
795 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(1);
796 renderer_->BeginDrawingFrame(&frame1);
797 renderer_->FinishDrawingFrame(&frame1);
798 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
799 SwapBuffers();
800 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
801 Mock::VerifyAndClearExpectations(&scheduler_);
803 EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
804 renderer_->set_expect_overlays(false);
805 renderer_->BeginDrawingFrame(&frame3);
806 renderer_->FinishDrawingFrame(&frame3);
807 EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
808 SwapBuffers();
809 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
810 Mock::VerifyAndClearExpectations(&scheduler_);
813 } // namespace
814 } // namespace cc