| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "cc/test/test_context_provider.h" | 14 #include "cc/test/test_context_provider.h" |
| 15 #include "cc/test/test_gpu_memory_buffer_manager.h" | 15 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 16 #include "cc/test/test_web_graphics_context_3d.h" | 16 #include "cc/test/test_web_graphics_context_3d.h" |
| 17 #include "components/display_compositor/gl_helper.h" | 17 #include "components/display_compositor/gl_helper.h" |
| 18 #include "gpu/GLES2/gl2extchromium.h" | 18 #include "gpu/GLES2/gl2extchromium.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/khronos/GLES2/gl2ext.h" | 21 #include "third_party/khronos/GLES2/gl2ext.h" |
| 22 #include "ui/display/types/display_snapshot.h" |
| 22 | 23 |
| 23 using ::testing::_; | 24 using ::testing::_; |
| 24 using ::testing::Expectation; | 25 using ::testing::Expectation; |
| 25 using ::testing::Ne; | 26 using ::testing::Ne; |
| 26 using ::testing::Return; | 27 using ::testing::Return; |
| 27 | 28 |
| 28 namespace display_compositor { | 29 namespace display_compositor { |
| 29 | 30 |
| 30 class StubGpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 31 class StubGpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
| 31 public: | 32 public: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 95 |
| 95 class MockBufferQueue : public BufferQueue { | 96 class MockBufferQueue : public BufferQueue { |
| 96 public: | 97 public: |
| 97 MockBufferQueue(gpu::gles2::GLES2Interface* gl, | 98 MockBufferQueue(gpu::gles2::GLES2Interface* gl, |
| 98 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 99 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 99 unsigned int target, | 100 unsigned int target, |
| 100 unsigned int internalformat) | 101 unsigned int internalformat) |
| 101 : BufferQueue(gl, | 102 : BufferQueue(gl, |
| 102 target, | 103 target, |
| 103 internalformat, | 104 internalformat, |
| 105 ui::DisplaySnapshot::PrimaryFormat(), |
| 104 nullptr, | 106 nullptr, |
| 105 gpu_memory_buffer_manager, | 107 gpu_memory_buffer_manager, |
| 106 kFakeSurfaceHandle) {} | 108 kFakeSurfaceHandle) {} |
| 107 MOCK_METHOD4(CopyBufferDamage, | 109 MOCK_METHOD4(CopyBufferDamage, |
| 108 void(int, int, const gfx::Rect&, const gfx::Rect&)); | 110 void(int, int, const gfx::Rect&, const gfx::Rect&)); |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 class BufferQueueTest : public ::testing::Test { | 113 class BufferQueueTest : public ::testing::Test { |
| 112 public: | 114 public: |
| 113 BufferQueueTest() : doublebuffering_(true), first_frame_(true) {} | 115 BufferQueueTest() : doublebuffering_(true), first_frame_(true) {} |
| 114 | 116 |
| 115 void SetUp() override { | 117 void SetUp() override { |
| 116 InitWithContext(cc::TestWebGraphicsContext3D::Create()); | 118 InitWithContext(cc::TestWebGraphicsContext3D::Create()); |
| 117 } | 119 } |
| 118 | 120 |
| 119 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) { | 121 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) { |
| 120 context_provider_ = cc::TestContextProvider::Create(std::move(context)); | 122 context_provider_ = cc::TestContextProvider::Create(std::move(context)); |
| 121 context_provider_->BindToCurrentThread(); | 123 context_provider_->BindToCurrentThread(); |
| 122 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager); | 124 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager); |
| 123 mock_output_surface_ = new MockBufferQueue(context_provider_->ContextGL(), | 125 mock_output_surface_ = new MockBufferQueue(context_provider_->ContextGL(), |
| 124 gpu_memory_buffer_manager_.get(), | 126 gpu_memory_buffer_manager_.get(), |
| 125 GL_TEXTURE_2D, GL_RGBA); | 127 GL_TEXTURE_2D, GL_RGB); |
| 126 output_surface_.reset(mock_output_surface_); | 128 output_surface_.reset(mock_output_surface_); |
| 127 output_surface_->Initialize(); | 129 output_surface_->Initialize(); |
| 128 } | 130 } |
| 129 | 131 |
| 130 unsigned current_surface() { | 132 unsigned current_surface() { |
| 131 return output_surface_->current_surface_ | 133 return output_surface_->current_surface_ |
| 132 ? output_surface_->current_surface_->image | 134 ? output_surface_->current_surface_->image |
| 133 : 0; | 135 : 0; |
| 134 } | 136 } |
| 135 const std::vector<std::unique_ptr<BufferQueue::AllocatedSurface>>& | 137 const std::vector<std::unique_ptr<BufferQueue::AllocatedSurface>>& |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 cc::TestContextProvider::Create(std::move(owned_context)); | 257 cc::TestContextProvider::Create(std::move(owned_context)); |
| 256 context_provider->BindToCurrentThread(); | 258 context_provider->BindToCurrentThread(); |
| 257 return context_provider; | 259 return context_provider; |
| 258 } | 260 } |
| 259 | 261 |
| 260 std::unique_ptr<BufferQueue> CreateBufferQueue( | 262 std::unique_ptr<BufferQueue> CreateBufferQueue( |
| 261 unsigned int target, | 263 unsigned int target, |
| 262 gpu::gles2::GLES2Interface* gl, | 264 gpu::gles2::GLES2Interface* gl, |
| 263 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | 265 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { |
| 264 std::unique_ptr<BufferQueue> buffer_queue( | 266 std::unique_ptr<BufferQueue> buffer_queue( |
| 265 new BufferQueue(gl, target, GL_RGBA, nullptr, gpu_memory_buffer_manager, | 267 new BufferQueue(gl, target, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), |
| 266 kFakeSurfaceHandle)); | 268 nullptr, gpu_memory_buffer_manager, kFakeSurfaceHandle)); |
| 267 buffer_queue->Initialize(); | 269 buffer_queue->Initialize(); |
| 268 return buffer_queue; | 270 return buffer_queue; |
| 269 } | 271 } |
| 270 | 272 |
| 271 TEST(BufferQueueStandaloneTest, FboInitialization) { | 273 TEST(BufferQueueStandaloneTest, FboInitialization) { |
| 272 MockedContext* context; | 274 MockedContext* context; |
| 273 scoped_refptr<cc::TestContextProvider> context_provider = | 275 scoped_refptr<cc::TestContextProvider> context_provider = |
| 274 CreateMockedContextProvider(&context); | 276 CreateMockedContextProvider(&context); |
| 275 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( | 277 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( |
| 276 new StubGpuMemoryBufferManager); | 278 new StubGpuMemoryBufferManager); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 294 scoped_refptr<cc::TestContextProvider> context_provider = | 296 scoped_refptr<cc::TestContextProvider> context_provider = |
| 295 CreateMockedContextProvider(&context); | 297 CreateMockedContextProvider(&context); |
| 296 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( | 298 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( |
| 297 new StubGpuMemoryBufferManager); | 299 new StubGpuMemoryBufferManager); |
| 298 std::unique_ptr<BufferQueue> output_surface = CreateBufferQueue( | 300 std::unique_ptr<BufferQueue> output_surface = CreateBufferQueue( |
| 299 target, context_provider->ContextGL(), gpu_memory_buffer_manager.get()); | 301 target, context_provider->ContextGL(), gpu_memory_buffer_manager.get()); |
| 300 | 302 |
| 301 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); | 303 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); |
| 302 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); | 304 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); |
| 303 Expectation image = | 305 Expectation image = |
| 304 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA)) | 306 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGB)) |
| 305 .WillOnce(Return(1)); | 307 .WillOnce(Return(1)); |
| 306 Expectation fb = | 308 Expectation fb = |
| 307 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); | 309 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); |
| 308 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); | 310 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); |
| 309 Expectation bind_tex = | 311 Expectation bind_tex = |
| 310 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) | 312 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) |
| 311 .After(tex, image); | 313 .After(tex, image); |
| 312 EXPECT_CALL(*context, | 314 EXPECT_CALL(*context, |
| 313 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 315 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 314 target, Ne(0U), _)) | 316 target, Ne(0U), _)) |
| 315 .After(fb, bind_tex); | 317 .After(fb, bind_tex); |
| 316 | 318 |
| 317 output_surface->BindFramebuffer(); | 319 output_surface->BindFramebuffer(); |
| 318 } | 320 } |
| 319 } | 321 } |
| 320 | 322 |
| 321 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { | 323 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { |
| 322 scoped_refptr<cc::TestContextProvider> context_provider = | 324 scoped_refptr<cc::TestContextProvider> context_provider = |
| 323 cc::TestContextProvider::Create(); | 325 cc::TestContextProvider::Create(); |
| 324 context_provider->BindToCurrentThread(); | 326 context_provider->BindToCurrentThread(); |
| 325 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager; | 327 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager; |
| 326 std::unique_ptr<BufferQueue> output_surface; | 328 std::unique_ptr<BufferQueue> output_surface; |
| 327 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager); | 329 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager); |
| 328 | 330 |
| 329 std::unique_ptr<GLHelper> gl_helper; | 331 std::unique_ptr<GLHelper> gl_helper; |
| 330 gl_helper.reset(new GLHelper(context_provider->ContextGL(), | 332 gl_helper.reset(new GLHelper(context_provider->ContextGL(), |
| 331 context_provider->ContextSupport())); | 333 context_provider->ContextSupport())); |
| 332 | 334 |
| 333 output_surface.reset(new BufferQueue( | 335 output_surface.reset( |
| 334 context_provider->ContextGL(), GL_TEXTURE_2D, GL_RGBA, gl_helper.get(), | 336 new BufferQueue(context_provider->ContextGL(), GL_TEXTURE_2D, GL_RGB, |
| 335 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle)); | 337 ui::DisplaySnapshot::PrimaryFormat(), gl_helper.get(), |
| 338 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle)); |
| 336 output_surface->Initialize(); | 339 output_surface->Initialize(); |
| 337 output_surface->Reshape(screen_size, 1.0f, gfx::ColorSpace()); | 340 output_surface->Reshape(screen_size, 1.0f, gfx::ColorSpace()); |
| 338 // Trigger a sub-buffer copy to exercise all paths. | 341 // Trigger a sub-buffer copy to exercise all paths. |
| 339 output_surface->BindFramebuffer(); | 342 output_surface->BindFramebuffer(); |
| 340 output_surface->SwapBuffers(screen_rect); | 343 output_surface->SwapBuffers(screen_rect); |
| 341 output_surface->PageFlipComplete(); | 344 output_surface->PageFlipComplete(); |
| 342 output_surface->BindFramebuffer(); | 345 output_surface->BindFramebuffer(); |
| 343 output_surface->SwapBuffers(small_damage); | 346 output_surface->SwapBuffers(small_damage); |
| 344 | 347 |
| 345 int current_fbo = 0; | 348 int current_fbo = 0; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 EXPECT_TRUE(displayed_frame()); | 577 EXPECT_TRUE(displayed_frame()); |
| 575 EXPECT_TRUE(current_frame()); | 578 EXPECT_TRUE(current_frame()); |
| 576 | 579 |
| 577 auto* current = current_frame(); | 580 auto* current = current_frame(); |
| 578 auto* displayed = displayed_frame(); | 581 auto* displayed = displayed_frame(); |
| 579 auto* in_flight = in_flight_surfaces().front().get(); | 582 auto* in_flight = in_flight_surfaces().front().get(); |
| 580 auto* available = available_surfaces().front().get(); | 583 auto* available = available_surfaces().front().get(); |
| 581 | 584 |
| 582 // Expect all 4 images to be destroyed, 3 of the existing textures to be | 585 // Expect all 4 images to be destroyed, 3 of the existing textures to be |
| 583 // copied from and 3 new images to be created. | 586 // copied from and 3 new images to be created. |
| 584 EXPECT_CALL(*context_, createImageCHROMIUM(_, 0, 0, GL_RGBA)).Times(3); | 587 EXPECT_CALL(*context_, createImageCHROMIUM(_, 0, 0, GL_RGB)).Times(3); |
| 585 Expectation copy1 = EXPECT_CALL(*mock_output_surface_, | 588 Expectation copy1 = EXPECT_CALL(*mock_output_surface_, |
| 586 CopyBufferDamage(_, displayed->texture, _, _)) | 589 CopyBufferDamage(_, displayed->texture, _, _)) |
| 587 .Times(1); | 590 .Times(1); |
| 588 Expectation copy2 = EXPECT_CALL(*mock_output_surface_, | 591 Expectation copy2 = EXPECT_CALL(*mock_output_surface_, |
| 589 CopyBufferDamage(_, current->texture, _, _)) | 592 CopyBufferDamage(_, current->texture, _, _)) |
| 590 .Times(1); | 593 .Times(1); |
| 591 Expectation copy3 = EXPECT_CALL(*mock_output_surface_, | 594 Expectation copy3 = EXPECT_CALL(*mock_output_surface_, |
| 592 CopyBufferDamage(_, in_flight->texture, _, _)) | 595 CopyBufferDamage(_, in_flight->texture, _, _)) |
| 593 .Times(1); | 596 .Times(1); |
| 594 | 597 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); | 671 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); |
| 669 EXPECT_CALL(*mock_output_surface_, | 672 EXPECT_CALL(*mock_output_surface_, |
| 670 CopyBufferDamage(target_texture, source_texture, small_damage, _)) | 673 CopyBufferDamage(target_texture, source_texture, small_damage, _)) |
| 671 .Times(1); | 674 .Times(1); |
| 672 output_surface_->SwapBuffers(small_damage); | 675 output_surface_->SwapBuffers(small_damage); |
| 673 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); | 676 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); |
| 674 } | 677 } |
| 675 | 678 |
| 676 } // namespace | 679 } // namespace |
| 677 } // namespace display_compositor | 680 } // namespace display_compositor |
| OLD | NEW |