OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "cc/base/region.h" | 10 #include "cc/base/region.h" |
11 #include "cc/output/compositor_frame.h" | 11 #include "cc/output/compositor_frame.h" |
12 #include "cc/output/compositor_frame_metadata.h" | 12 #include "cc/output/compositor_frame_metadata.h" |
13 #include "cc/output/gl_renderer.h" | 13 #include "cc/output/gl_renderer.h" |
14 #include "cc/output/output_surface.h" | 14 #include "cc/output/output_surface.h" |
15 #include "cc/output/output_surface_client.h" | 15 #include "cc/output/output_surface_client.h" |
16 #include "cc/output/overlay_candidate_validator.h" | 16 #include "cc/output/overlay_candidate_validator.h" |
17 #include "cc/output/overlay_processor.h" | 17 #include "cc/output/overlay_processor.h" |
| 18 #include "cc/output/overlay_strategy_fullscreen.h" |
18 #include "cc/output/overlay_strategy_single_on_top.h" | 19 #include "cc/output/overlay_strategy_single_on_top.h" |
19 #include "cc/output/overlay_strategy_underlay.h" | 20 #include "cc/output/overlay_strategy_underlay.h" |
20 #include "cc/quads/render_pass.h" | 21 #include "cc/quads/render_pass.h" |
21 #include "cc/quads/solid_color_draw_quad.h" | 22 #include "cc/quads/solid_color_draw_quad.h" |
22 #include "cc/quads/stream_video_draw_quad.h" | 23 #include "cc/quads/stream_video_draw_quad.h" |
23 #include "cc/quads/texture_draw_quad.h" | 24 #include "cc/quads/texture_draw_quad.h" |
24 #include "cc/resources/resource_provider.h" | 25 #include "cc/resources/resource_provider.h" |
25 #include "cc/resources/texture_mailbox.h" | 26 #include "cc/resources/texture_mailbox.h" |
26 #include "cc/test/fake_output_surface_client.h" | 27 #include "cc/test/fake_output_surface_client.h" |
27 #include "cc/test/fake_resource_provider.h" | 28 #include "cc/test/fake_resource_provider.h" |
(...skipping 26 matching lines...) Expand all Loading... |
54 gfx::Transform(0.9f, 0, 0, -0.8f, 0.1f, 1.0f); // x,y -> x,1-y. | 55 gfx::Transform(0.9f, 0, 0, -0.8f, 0.1f, 1.0f); // x,y -> x,1-y. |
55 const gfx::Transform kBothMirrorTransform = | 56 const gfx::Transform kBothMirrorTransform = |
56 gfx::Transform(-0.9f, 0, 0, -0.8f, 1.0f, 1.0f); // x,y -> 1-x,1-y. | 57 gfx::Transform(-0.9f, 0, 0, -0.8f, 1.0f, 1.0f); // x,y -> 1-x,1-y. |
57 const gfx::Transform kSwapTransform = | 58 const gfx::Transform kSwapTransform = |
58 gfx::Transform(0, 1, 1, 0, 0, 0); // x,y -> y,x. | 59 gfx::Transform(0, 1, 1, 0, 0, 0); // x,y -> y,x. |
59 | 60 |
60 void MailboxReleased(const gpu::SyncToken& sync_token, | 61 void MailboxReleased(const gpu::SyncToken& sync_token, |
61 bool lost_resource, | 62 bool lost_resource, |
62 BlockingTaskRunner* main_thread_task_runner) {} | 63 BlockingTaskRunner* main_thread_task_runner) {} |
63 | 64 |
| 65 class FullscreenOverlayValidator : public OverlayCandidateValidator { |
| 66 public: |
| 67 void GetStrategies(OverlayProcessor::StrategyList* strategies) override { |
| 68 strategies->push_back(base::WrapUnique(new OverlayStrategyFullscreen())); |
| 69 } |
| 70 bool AllowCALayerOverlays() override { return false; } |
| 71 void CheckOverlaySupport(OverlayCandidateList* surfaces) override { |
| 72 // We're not checking for support. |
| 73 ASSERT_TRUE(false); |
| 74 } |
| 75 }; |
| 76 |
64 class SingleOverlayValidator : public OverlayCandidateValidator { | 77 class SingleOverlayValidator : public OverlayCandidateValidator { |
65 public: | 78 public: |
66 void GetStrategies(OverlayProcessor::StrategyList* strategies) override { | 79 void GetStrategies(OverlayProcessor::StrategyList* strategies) override { |
67 strategies->push_back( | 80 strategies->push_back( |
68 base::WrapUnique(new OverlayStrategySingleOnTop(this))); | 81 base::WrapUnique(new OverlayStrategySingleOnTop(this))); |
69 strategies->push_back(base::WrapUnique(new OverlayStrategyUnderlay(this))); | 82 strategies->push_back(base::WrapUnique(new OverlayStrategyUnderlay(this))); |
70 } | 83 } |
71 bool AllowCALayerOverlays() override { return false; } | 84 bool AllowCALayerOverlays() override { return false; } |
72 void CheckOverlaySupport(OverlayCandidateList* surfaces) override { | 85 void CheckOverlaySupport(OverlayCandidateList* surfaces) override { |
73 // We may have 1 or 2 surfaces depending on whether this ran through the | 86 // We may have 1 or 2 surfaces depending on whether this ran through the |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 237 } |
225 | 238 |
226 TextureDrawQuad* CreateCandidateQuadAt(ResourceProvider* resource_provider, | 239 TextureDrawQuad* CreateCandidateQuadAt(ResourceProvider* resource_provider, |
227 const SharedQuadState* shared_quad_state, | 240 const SharedQuadState* shared_quad_state, |
228 RenderPass* render_pass, | 241 RenderPass* render_pass, |
229 const gfx::Rect& rect) { | 242 const gfx::Rect& rect) { |
230 bool premultiplied_alpha = false; | 243 bool premultiplied_alpha = false; |
231 bool flipped = false; | 244 bool flipped = false; |
232 bool nearest_neighbor = false; | 245 bool nearest_neighbor = false; |
233 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | 246 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
234 gfx::Size resource_size_in_pixels = gfx::Size(64, 64); | 247 gfx::Size resource_size_in_pixels = rect.size(); |
235 bool is_overlay_candidate = true; | 248 bool is_overlay_candidate = true; |
236 ResourceId resource_id = CreateResource( | 249 ResourceId resource_id = CreateResource( |
237 resource_provider, resource_size_in_pixels, is_overlay_candidate); | 250 resource_provider, resource_size_in_pixels, is_overlay_candidate); |
238 | 251 |
239 TextureDrawQuad* overlay_quad = | 252 TextureDrawQuad* overlay_quad = |
240 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 253 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
241 overlay_quad->SetNew(shared_quad_state, rect, rect, rect, resource_id, | 254 overlay_quad->SetNew(shared_quad_state, rect, rect, rect, resource_id, |
242 premultiplied_alpha, kUVTopLeft, kUVBottomRight, | 255 premultiplied_alpha, kUVTopLeft, kUVBottomRight, |
243 SK_ColorTRANSPARENT, vertex_opacity, flipped, | 256 SK_ColorTRANSPARENT, vertex_opacity, flipped, |
244 nearest_neighbor, false); | 257 nearest_neighbor, false); |
245 overlay_quad->set_resource_size_in_pixels(resource_size_in_pixels); | 258 overlay_quad->set_resource_size_in_pixels(resource_size_in_pixels); |
246 | 259 |
247 return overlay_quad; | 260 return overlay_quad; |
248 } | 261 } |
249 | 262 |
250 StreamVideoDrawQuad* CreateCandidateVideoQuadAt( | 263 StreamVideoDrawQuad* CreateCandidateVideoQuadAt( |
251 ResourceProvider* resource_provider, | 264 ResourceProvider* resource_provider, |
252 const SharedQuadState* shared_quad_state, | 265 const SharedQuadState* shared_quad_state, |
253 RenderPass* render_pass, | 266 RenderPass* render_pass, |
254 const gfx::Rect& rect, | 267 const gfx::Rect& rect, |
255 const gfx::Transform& transform) { | 268 const gfx::Transform& transform) { |
256 gfx::Size resource_size_in_pixels = gfx::Size(64, 64); | 269 gfx::Size resource_size_in_pixels = rect.size(); |
257 bool is_overlay_candidate = true; | 270 bool is_overlay_candidate = true; |
258 ResourceId resource_id = CreateResource( | 271 ResourceId resource_id = CreateResource( |
259 resource_provider, resource_size_in_pixels, is_overlay_candidate); | 272 resource_provider, resource_size_in_pixels, is_overlay_candidate); |
260 | 273 |
261 StreamVideoDrawQuad* overlay_quad = | 274 StreamVideoDrawQuad* overlay_quad = |
262 render_pass->CreateAndAppendDrawQuad<StreamVideoDrawQuad>(); | 275 render_pass->CreateAndAppendDrawQuad<StreamVideoDrawQuad>(); |
263 overlay_quad->SetNew(shared_quad_state, rect, rect, rect, resource_id, | 276 overlay_quad->SetNew(shared_quad_state, rect, rect, rect, resource_id, |
264 resource_size_in_pixels, transform); | 277 resource_size_in_pixels, transform); |
265 | 278 |
266 return overlay_quad; | 279 return overlay_quad; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 363 |
351 scoped_refptr<TestContextProvider> provider_; | 364 scoped_refptr<TestContextProvider> provider_; |
352 std::unique_ptr<OverlayOutputSurface> output_surface_; | 365 std::unique_ptr<OverlayOutputSurface> output_surface_; |
353 FakeOutputSurfaceClient client_; | 366 FakeOutputSurfaceClient client_; |
354 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; | 367 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; |
355 std::unique_ptr<ResourceProvider> resource_provider_; | 368 std::unique_ptr<ResourceProvider> resource_provider_; |
356 std::unique_ptr<OverlayProcessor> overlay_processor_; | 369 std::unique_ptr<OverlayProcessor> overlay_processor_; |
357 gfx::Rect damage_rect_; | 370 gfx::Rect damage_rect_; |
358 }; | 371 }; |
359 | 372 |
| 373 typedef OverlayTest<FullscreenOverlayValidator> FullscreenOverlayTest; |
360 typedef OverlayTest<SingleOnTopOverlayValidator> SingleOverlayOnTopTest; | 374 typedef OverlayTest<SingleOnTopOverlayValidator> SingleOverlayOnTopTest; |
361 typedef OverlayTest<UnderlayOverlayValidator> UnderlayTest; | 375 typedef OverlayTest<UnderlayOverlayValidator> UnderlayTest; |
362 typedef OverlayTest<CALayerValidator> CALayerOverlayTest; | 376 typedef OverlayTest<CALayerValidator> CALayerOverlayTest; |
363 | 377 |
364 TEST(OverlayTest, NoOverlaysByDefault) { | 378 TEST(OverlayTest, NoOverlaysByDefault) { |
365 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); | 379 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
366 OverlayOutputSurface output_surface(provider); | 380 OverlayOutputSurface output_surface(provider); |
367 EXPECT_EQ(NULL, output_surface.GetOverlayCandidateValidator()); | 381 EXPECT_EQ(NULL, output_surface.GetOverlayCandidateValidator()); |
368 | 382 |
369 output_surface.SetOverlayCandidateValidator(new SingleOverlayValidator); | 383 output_surface.SetOverlayCandidateValidator(new SingleOverlayValidator); |
(...skipping 12 matching lines...) Expand all Loading... |
382 std::unique_ptr<ResourceProvider> resource_provider = | 396 std::unique_ptr<ResourceProvider> resource_provider = |
383 FakeResourceProvider::Create(&output_surface, | 397 FakeResourceProvider::Create(&output_surface, |
384 shared_bitmap_manager.get()); | 398 shared_bitmap_manager.get()); |
385 | 399 |
386 std::unique_ptr<DefaultOverlayProcessor> overlay_processor( | 400 std::unique_ptr<DefaultOverlayProcessor> overlay_processor( |
387 new DefaultOverlayProcessor(&output_surface)); | 401 new DefaultOverlayProcessor(&output_surface)); |
388 overlay_processor->Initialize(); | 402 overlay_processor->Initialize(); |
389 EXPECT_GE(2U, overlay_processor->GetStrategyCount()); | 403 EXPECT_GE(2U, overlay_processor->GetStrategyCount()); |
390 } | 404 } |
391 | 405 |
| 406 TEST_F(FullscreenOverlayTest, SuccessfulOverlay) { |
| 407 std::unique_ptr<RenderPass> pass = CreateRenderPass(); |
| 408 TextureDrawQuad* original_quad = CreateFullscreenCandidateQuad( |
| 409 resource_provider_.get(), pass->shared_quad_state_list.back(), |
| 410 pass.get()); |
| 411 unsigned original_resource_id = original_quad->resource_id(); |
| 412 |
| 413 // Add something behind it. |
| 414 CreateFullscreenOpaqueQuad(resource_provider_.get(), |
| 415 pass->shared_quad_state_list.back(), pass.get()); |
| 416 |
| 417 // Check for potential candidates. |
| 418 OverlayCandidateList candidate_list; |
| 419 overlay_processor_->ProcessForOverlays(resource_provider_.get(), pass.get(), |
| 420 &candidate_list, nullptr, |
| 421 &damage_rect_); |
| 422 ASSERT_EQ(1U, candidate_list.size()); |
| 423 |
| 424 RenderPass* main_pass = pass.get(); |
| 425 // Check that the quad is gone. |
| 426 EXPECT_EQ(1U, main_pass->quad_list.size()); |
| 427 // Check that the right resource id got extracted. |
| 428 EXPECT_EQ(original_resource_id, candidate_list.back().resource_id); |
| 429 } |
| 430 |
| 431 TEST_F(FullscreenOverlayTest, ResourceSizeInPixelsFail) { |
| 432 std::unique_ptr<RenderPass> pass = CreateRenderPass(); |
| 433 TextureDrawQuad* original_quad = CreateFullscreenCandidateQuad( |
| 434 resource_provider_.get(), pass->shared_quad_state_list.back(), |
| 435 pass.get()); |
| 436 original_quad->set_resource_size_in_pixels(gfx::Size(64, 64)); |
| 437 |
| 438 // Check for potential candidates. |
| 439 OverlayCandidateList candidate_list; |
| 440 overlay_processor_->ProcessForOverlays(resource_provider_.get(), pass.get(), |
| 441 &candidate_list, nullptr, |
| 442 &damage_rect_); |
| 443 ASSERT_EQ(0U, candidate_list.size()); |
| 444 |
| 445 RenderPass* main_pass = pass.get(); |
| 446 // Check that the quad is not gone. |
| 447 EXPECT_EQ(1U, main_pass->quad_list.size()); |
| 448 } |
| 449 |
| 450 TEST_F(FullscreenOverlayTest, OnTopFail) { |
| 451 std::unique_ptr<RenderPass> pass = CreateRenderPass(); |
| 452 |
| 453 // Add something in front of it. |
| 454 CreateOpaqueQuadAt(resource_provider_.get(), |
| 455 pass->shared_quad_state_list.back(), pass.get(), |
| 456 kOverlayTopLeftRect); |
| 457 |
| 458 CreateFullscreenCandidateQuad(resource_provider_.get(), |
| 459 pass->shared_quad_state_list.back(), |
| 460 pass.get()); |
| 461 |
| 462 // Check for potential candidates. |
| 463 OverlayCandidateList candidate_list; |
| 464 overlay_processor_->ProcessForOverlays(resource_provider_.get(), pass.get(), |
| 465 &candidate_list, nullptr, |
| 466 &damage_rect_); |
| 467 ASSERT_EQ(0U, candidate_list.size()); |
| 468 |
| 469 RenderPass* main_pass = pass.get(); |
| 470 // Check that the 2 quads are not gone. |
| 471 EXPECT_EQ(2U, main_pass->quad_list.size()); |
| 472 } |
| 473 |
| 474 TEST_F(FullscreenOverlayTest, NotCoveringFullscreenFail) { |
| 475 std::unique_ptr<RenderPass> pass = CreateRenderPass(); |
| 476 gfx::Rect inset_rect = pass->output_rect; |
| 477 inset_rect.Inset(0, 1, 0, 1); |
| 478 CreateCandidateQuadAt(resource_provider_.get(), |
| 479 pass->shared_quad_state_list.back(), pass.get(), |
| 480 inset_rect); |
| 481 |
| 482 // Check for potential candidates. |
| 483 OverlayCandidateList candidate_list; |
| 484 overlay_processor_->ProcessForOverlays(resource_provider_.get(), pass.get(), |
| 485 &candidate_list, nullptr, |
| 486 &damage_rect_); |
| 487 ASSERT_EQ(0U, candidate_list.size()); |
| 488 |
| 489 RenderPass* main_pass = pass.get(); |
| 490 // Check that the quad is not gone. |
| 491 EXPECT_EQ(1U, main_pass->quad_list.size()); |
| 492 } |
| 493 |
392 TEST_F(SingleOverlayOnTopTest, SuccessfulOverlay) { | 494 TEST_F(SingleOverlayOnTopTest, SuccessfulOverlay) { |
393 std::unique_ptr<RenderPass> pass = CreateRenderPass(); | 495 std::unique_ptr<RenderPass> pass = CreateRenderPass(); |
394 TextureDrawQuad* original_quad = | 496 TextureDrawQuad* original_quad = |
395 CreateFullscreenCandidateQuad(resource_provider_.get(), | 497 CreateFullscreenCandidateQuad(resource_provider_.get(), |
396 pass->shared_quad_state_list.back(), | 498 pass->shared_quad_state_list.back(), |
397 pass.get()); | 499 pass.get()); |
398 unsigned original_resource_id = original_quad->resource_id(); | 500 unsigned original_resource_id = original_quad->resource_id(); |
399 | 501 |
400 // Add something behind it. | 502 // Add something behind it. |
401 CreateFullscreenOpaqueQuad(resource_provider_.get(), | 503 CreateFullscreenOpaqueQuad(resource_provider_.get(), |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 | 1737 |
1636 ReturnResourceInUseQuery(resource2); | 1738 ReturnResourceInUseQuery(resource2); |
1637 ReturnResourceInUseQuery(resource3); | 1739 ReturnResourceInUseQuery(resource3); |
1638 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1)); | 1740 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1)); |
1639 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2)); | 1741 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2)); |
1640 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource3)); | 1742 EXPECT_FALSE(resource_provider_->InUseByConsumer(resource3)); |
1641 } | 1743 } |
1642 | 1744 |
1643 } // namespace | 1745 } // namespace |
1644 } // namespace cc | 1746 } // namespace cc |
OLD | NEW |