| 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 "components/display_compositor/buffer_queue.h" | 5 #include "components/display_compositor/buffer_queue.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( | 277 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( |
| 278 new StubGpuMemoryBufferManager); | 278 new StubGpuMemoryBufferManager); |
| 279 std::unique_ptr<BufferQueue> output_surface = | 279 std::unique_ptr<BufferQueue> output_surface = |
| 280 CreateBufferQueue(GL_TEXTURE_2D, context_provider->ContextGL(), | 280 CreateBufferQueue(GL_TEXTURE_2D, context_provider->ContextGL(), |
| 281 gpu_memory_buffer_manager.get()); | 281 gpu_memory_buffer_manager.get()); |
| 282 | 282 |
| 283 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); | 283 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); |
| 284 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _)) | 284 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _)) |
| 285 .WillByDefault(Return()); | 285 .WillByDefault(Return()); |
| 286 | 286 |
| 287 output_surface->Reshape(gfx::Size(10, 20), 1.0f, gfx::ColorSpace()); | 287 output_surface->Reshape(gfx::Size(10, 20), 1.0f, gfx::ColorSpace(), false); |
| 288 } | 288 } |
| 289 | 289 |
| 290 TEST(BufferQueueStandaloneTest, FboBinding) { | 290 TEST(BufferQueueStandaloneTest, FboBinding) { |
| 291 GLenum targets[] = {GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB}; | 291 GLenum targets[] = {GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB}; |
| 292 for (size_t i = 0; i < 2; ++i) { | 292 for (size_t i = 0; i < 2; ++i) { |
| 293 GLenum target = targets[i]; | 293 GLenum target = targets[i]; |
| 294 | 294 |
| 295 MockedContext* context; | 295 MockedContext* context; |
| 296 scoped_refptr<cc::TestContextProvider> context_provider = | 296 scoped_refptr<cc::TestContextProvider> context_provider = |
| 297 CreateMockedContextProvider(&context); | 297 CreateMockedContextProvider(&context); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 330 |
| 331 std::unique_ptr<GLHelper> gl_helper; | 331 std::unique_ptr<GLHelper> gl_helper; |
| 332 gl_helper.reset(new GLHelper(context_provider->ContextGL(), | 332 gl_helper.reset(new GLHelper(context_provider->ContextGL(), |
| 333 context_provider->ContextSupport())); | 333 context_provider->ContextSupport())); |
| 334 | 334 |
| 335 output_surface.reset(new BufferQueue( | 335 output_surface.reset(new BufferQueue( |
| 336 context_provider->ContextGL(), GL_TEXTURE_2D, GL_RGB, | 336 context_provider->ContextGL(), GL_TEXTURE_2D, GL_RGB, |
| 337 display::DisplaySnapshot::PrimaryFormat(), gl_helper.get(), | 337 display::DisplaySnapshot::PrimaryFormat(), gl_helper.get(), |
| 338 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle)); | 338 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle)); |
| 339 output_surface->Initialize(); | 339 output_surface->Initialize(); |
| 340 output_surface->Reshape(screen_size, 1.0f, gfx::ColorSpace()); | 340 output_surface->Reshape(screen_size, 1.0f, gfx::ColorSpace(), false); |
| 341 // Trigger a sub-buffer copy to exercise all paths. | 341 // Trigger a sub-buffer copy to exercise all paths. |
| 342 output_surface->BindFramebuffer(); | 342 output_surface->BindFramebuffer(); |
| 343 output_surface->SwapBuffers(screen_rect); | 343 output_surface->SwapBuffers(screen_rect); |
| 344 output_surface->PageFlipComplete(); | 344 output_surface->PageFlipComplete(); |
| 345 output_surface->BindFramebuffer(); | 345 output_surface->BindFramebuffer(); |
| 346 output_surface->SwapBuffers(small_damage); | 346 output_surface->SwapBuffers(small_damage); |
| 347 | 347 |
| 348 int current_fbo = 0; | 348 int current_fbo = 0; |
| 349 context_provider->ContextGL()->GetIntegerv(GL_FRAMEBUFFER_BINDING, | 349 context_provider->ContextGL()->GetIntegerv(GL_FRAMEBUFFER_BINDING, |
| 350 ¤t_fbo); | 350 ¤t_fbo); |
| 351 EXPECT_EQ(static_cast<int>(output_surface->fbo()), current_fbo); | 351 EXPECT_EQ(static_cast<int>(output_surface->fbo()), current_fbo); |
| 352 } | 352 } |
| 353 | 353 |
| 354 TEST_F(BufferQueueTest, PartialSwapReuse) { | 354 TEST_F(BufferQueueTest, PartialSwapReuse) { |
| 355 output_surface_->Reshape(screen_size, 1.0f, gfx::ColorSpace()); | 355 output_surface_->Reshape(screen_size, 1.0f, gfx::ColorSpace(), false); |
| 356 ASSERT_TRUE(doublebuffering_); | 356 ASSERT_TRUE(doublebuffering_); |
| 357 EXPECT_CALL(*mock_output_surface_, | 357 EXPECT_CALL(*mock_output_surface_, |
| 358 CopyBufferDamage(_, _, small_damage, screen_rect)) | 358 CopyBufferDamage(_, _, small_damage, screen_rect)) |
| 359 .Times(1); | 359 .Times(1); |
| 360 EXPECT_CALL(*mock_output_surface_, | 360 EXPECT_CALL(*mock_output_surface_, |
| 361 CopyBufferDamage(_, _, small_damage, small_damage)) | 361 CopyBufferDamage(_, _, small_damage, small_damage)) |
| 362 .Times(1); | 362 .Times(1); |
| 363 EXPECT_CALL(*mock_output_surface_, | 363 EXPECT_CALL(*mock_output_surface_, |
| 364 CopyBufferDamage(_, _, large_damage, small_damage)) | 364 CopyBufferDamage(_, _, large_damage, small_damage)) |
| 365 .Times(1); | 365 .Times(1); |
| 366 SendFullFrame(); | 366 SendFullFrame(); |
| 367 SendDamagedFrame(small_damage); | 367 SendDamagedFrame(small_damage); |
| 368 SendDamagedFrame(small_damage); | 368 SendDamagedFrame(small_damage); |
| 369 SendDamagedFrame(large_damage); | 369 SendDamagedFrame(large_damage); |
| 370 // Verify that the damage has propagated. | 370 // Verify that the damage has propagated. |
| 371 EXPECT_EQ(next_frame()->damage, large_damage); | 371 EXPECT_EQ(next_frame()->damage, large_damage); |
| 372 } | 372 } |
| 373 | 373 |
| 374 TEST_F(BufferQueueTest, PartialSwapFullFrame) { | 374 TEST_F(BufferQueueTest, PartialSwapFullFrame) { |
| 375 output_surface_->Reshape(screen_size, 1.0f, gfx::ColorSpace()); | 375 output_surface_->Reshape(screen_size, 1.0f, gfx::ColorSpace(), false); |
| 376 ASSERT_TRUE(doublebuffering_); | 376 ASSERT_TRUE(doublebuffering_); |
| 377 EXPECT_CALL(*mock_output_surface_, | 377 EXPECT_CALL(*mock_output_surface_, |
| 378 CopyBufferDamage(_, _, small_damage, screen_rect)) | 378 CopyBufferDamage(_, _, small_damage, screen_rect)) |
| 379 .Times(1); | 379 .Times(1); |
| 380 SendFullFrame(); | 380 SendFullFrame(); |
| 381 SendDamagedFrame(small_damage); | 381 SendDamagedFrame(small_damage); |
| 382 SendFullFrame(); | 382 SendFullFrame(); |
| 383 SendFullFrame(); | 383 SendFullFrame(); |
| 384 EXPECT_EQ(next_frame()->damage, screen_rect); | 384 EXPECT_EQ(next_frame()->damage, screen_rect); |
| 385 } | 385 } |
| 386 | 386 |
| 387 TEST_F(BufferQueueTest, PartialSwapOverlapping) { | 387 TEST_F(BufferQueueTest, PartialSwapOverlapping) { |
| 388 output_surface_->Reshape(screen_size, 1.0f, gfx::ColorSpace()); | 388 output_surface_->Reshape(screen_size, 1.0f, gfx::ColorSpace(), false); |
| 389 ASSERT_TRUE(doublebuffering_); | 389 ASSERT_TRUE(doublebuffering_); |
| 390 EXPECT_CALL(*mock_output_surface_, | 390 EXPECT_CALL(*mock_output_surface_, |
| 391 CopyBufferDamage(_, _, small_damage, screen_rect)) | 391 CopyBufferDamage(_, _, small_damage, screen_rect)) |
| 392 .Times(1); | 392 .Times(1); |
| 393 EXPECT_CALL(*mock_output_surface_, | 393 EXPECT_CALL(*mock_output_surface_, |
| 394 CopyBufferDamage(_, _, overlapping_damage, small_damage)) | 394 CopyBufferDamage(_, _, overlapping_damage, small_damage)) |
| 395 .Times(1); | 395 .Times(1); |
| 396 | 396 |
| 397 SendFullFrame(); | 397 SendFullFrame(); |
| 398 SendDamagedFrame(small_damage); | 398 SendDamagedFrame(small_damage); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 | 490 |
| 491 TEST_F(BufferQueueTest, ReshapeWithInFlightSurfaces) { | 491 TEST_F(BufferQueueTest, ReshapeWithInFlightSurfaces) { |
| 492 const size_t kSwapCount = 3; | 492 const size_t kSwapCount = 3; |
| 493 for (size_t i = 0; i < kSwapCount; ++i) { | 493 for (size_t i = 0; i < kSwapCount; ++i) { |
| 494 output_surface_->BindFramebuffer(); | 494 output_surface_->BindFramebuffer(); |
| 495 SwapBuffers(); | 495 SwapBuffers(); |
| 496 } | 496 } |
| 497 | 497 |
| 498 output_surface_->Reshape(gfx::Size(10, 20), 1.0f, gfx::ColorSpace()); | 498 output_surface_->Reshape(gfx::Size(10, 20), 1.0f, gfx::ColorSpace(), false); |
| 499 EXPECT_EQ(3u, in_flight_surfaces().size()); | 499 EXPECT_EQ(3u, in_flight_surfaces().size()); |
| 500 | 500 |
| 501 for (size_t i = 0; i < kSwapCount; ++i) { | 501 for (size_t i = 0; i < kSwapCount; ++i) { |
| 502 output_surface_->PageFlipComplete(); | 502 output_surface_->PageFlipComplete(); |
| 503 EXPECT_FALSE(displayed_frame()); | 503 EXPECT_FALSE(displayed_frame()); |
| 504 } | 504 } |
| 505 | 505 |
| 506 // The dummy surfacess left should be discarded. | 506 // The dummy surfacess left should be discarded. |
| 507 EXPECT_EQ(0u, available_surfaces().size()); | 507 EXPECT_EQ(0u, available_surfaces().size()); |
| 508 } | 508 } |
| 509 | 509 |
| 510 TEST_F(BufferQueueTest, SwapAfterReshape) { | 510 TEST_F(BufferQueueTest, SwapAfterReshape) { |
| 511 DCHECK_EQ(0u, gpu_memory_buffer_manager_->set_color_space_count()); | 511 DCHECK_EQ(0u, gpu_memory_buffer_manager_->set_color_space_count()); |
| 512 const size_t kSwapCount = 3; | 512 const size_t kSwapCount = 3; |
| 513 for (size_t i = 0; i < kSwapCount; ++i) { | 513 for (size_t i = 0; i < kSwapCount; ++i) { |
| 514 output_surface_->BindFramebuffer(); | 514 output_surface_->BindFramebuffer(); |
| 515 SwapBuffers(); | 515 SwapBuffers(); |
| 516 } | 516 } |
| 517 DCHECK_EQ(kSwapCount, gpu_memory_buffer_manager_->set_color_space_count()); | 517 DCHECK_EQ(kSwapCount, gpu_memory_buffer_manager_->set_color_space_count()); |
| 518 | 518 |
| 519 output_surface_->Reshape(gfx::Size(10, 20), 1.0f, gfx::ColorSpace()); | 519 output_surface_->Reshape(gfx::Size(10, 20), 1.0f, gfx::ColorSpace(), false); |
| 520 DCHECK_EQ(kSwapCount, gpu_memory_buffer_manager_->set_color_space_count()); | 520 DCHECK_EQ(kSwapCount, gpu_memory_buffer_manager_->set_color_space_count()); |
| 521 | 521 |
| 522 for (size_t i = 0; i < kSwapCount; ++i) { | 522 for (size_t i = 0; i < kSwapCount; ++i) { |
| 523 output_surface_->BindFramebuffer(); | 523 output_surface_->BindFramebuffer(); |
| 524 SwapBuffers(); | 524 SwapBuffers(); |
| 525 } | 525 } |
| 526 DCHECK_EQ(2 * kSwapCount, | 526 DCHECK_EQ(2 * kSwapCount, |
| 527 gpu_memory_buffer_manager_->set_color_space_count()); | 527 gpu_memory_buffer_manager_->set_color_space_count()); |
| 528 EXPECT_EQ(2 * kSwapCount, in_flight_surfaces().size()); | 528 EXPECT_EQ(2 * kSwapCount, in_flight_surfaces().size()); |
| 529 | 529 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 621 |
| 622 // All free buffers should be destroyed, the remaining buffers should all | 622 // All free buffers should be destroyed, the remaining buffers should all |
| 623 // be replaced but still valid. | 623 // be replaced but still valid. |
| 624 EXPECT_EQ(1U, in_flight_surfaces().size()); | 624 EXPECT_EQ(1U, in_flight_surfaces().size()); |
| 625 EXPECT_EQ(0U, available_surfaces().size()); | 625 EXPECT_EQ(0U, available_surfaces().size()); |
| 626 EXPECT_TRUE(displayed_frame()); | 626 EXPECT_TRUE(displayed_frame()); |
| 627 EXPECT_TRUE(current_frame()); | 627 EXPECT_TRUE(current_frame()); |
| 628 } | 628 } |
| 629 | 629 |
| 630 TEST_F(BufferQueueTest, AllocateFails) { | 630 TEST_F(BufferQueueTest, AllocateFails) { |
| 631 output_surface_->Reshape(screen_size, 1.0f, gfx::ColorSpace()); | 631 output_surface_->Reshape(screen_size, 1.0f, gfx::ColorSpace(), false); |
| 632 | 632 |
| 633 // Succeed in the two swaps. | 633 // Succeed in the two swaps. |
| 634 output_surface_->BindFramebuffer(); | 634 output_surface_->BindFramebuffer(); |
| 635 EXPECT_TRUE(current_frame()); | 635 EXPECT_TRUE(current_frame()); |
| 636 output_surface_->SwapBuffers(screen_rect); | 636 output_surface_->SwapBuffers(screen_rect); |
| 637 | 637 |
| 638 // Fail the next surface allocation. | 638 // Fail the next surface allocation. |
| 639 gpu_memory_buffer_manager_->set_allocate_succeeds(false); | 639 gpu_memory_buffer_manager_->set_allocate_succeeds(false); |
| 640 output_surface_->BindFramebuffer(); | 640 output_surface_->BindFramebuffer(); |
| 641 EXPECT_FALSE(current_frame()); | 641 EXPECT_FALSE(current_frame()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 671 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); | 671 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); |
| 672 EXPECT_CALL(*mock_output_surface_, | 672 EXPECT_CALL(*mock_output_surface_, |
| 673 CopyBufferDamage(target_texture, source_texture, small_damage, _)) | 673 CopyBufferDamage(target_texture, source_texture, small_damage, _)) |
| 674 .Times(1); | 674 .Times(1); |
| 675 output_surface_->SwapBuffers(small_damage); | 675 output_surface_->SwapBuffers(small_damage); |
| 676 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); | 676 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); |
| 677 } | 677 } |
| 678 | 678 |
| 679 } // namespace | 679 } // namespace |
| 680 } // namespace display_compositor | 680 } // namespace display_compositor |
| OLD | NEW |