| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void SetUp() override { | 115 void SetUp() override { |
| 116 InitWithContext(cc::TestWebGraphicsContext3D::Create()); | 116 InitWithContext(cc::TestWebGraphicsContext3D::Create()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) { | 119 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) { |
| 120 context_provider_ = cc::TestContextProvider::Create(std::move(context)); | 120 context_provider_ = cc::TestContextProvider::Create(std::move(context)); |
| 121 context_provider_->BindToCurrentThread(); | 121 context_provider_->BindToCurrentThread(); |
| 122 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager); | 122 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager); |
| 123 mock_output_surface_ = new MockBufferQueue(context_provider_->ContextGL(), | 123 mock_output_surface_ = new MockBufferQueue(context_provider_->ContextGL(), |
| 124 gpu_memory_buffer_manager_.get(), | 124 gpu_memory_buffer_manager_.get(), |
| 125 GL_TEXTURE_2D, GL_RGBA); | 125 GL_TEXTURE_2D, GL_RGB); |
| 126 output_surface_.reset(mock_output_surface_); | 126 output_surface_.reset(mock_output_surface_); |
| 127 output_surface_->Initialize(); | 127 output_surface_->Initialize(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 unsigned current_surface() { | 130 unsigned current_surface() { |
| 131 return output_surface_->current_surface_ | 131 return output_surface_->current_surface_ |
| 132 ? output_surface_->current_surface_->image | 132 ? output_surface_->current_surface_->image |
| 133 : 0; | 133 : 0; |
| 134 } | 134 } |
| 135 const std::vector<std::unique_ptr<BufferQueue::AllocatedSurface>>& | 135 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)); | 255 cc::TestContextProvider::Create(std::move(owned_context)); |
| 256 context_provider->BindToCurrentThread(); | 256 context_provider->BindToCurrentThread(); |
| 257 return context_provider; | 257 return context_provider; |
| 258 } | 258 } |
| 259 | 259 |
| 260 std::unique_ptr<BufferQueue> CreateBufferQueue( | 260 std::unique_ptr<BufferQueue> CreateBufferQueue( |
| 261 unsigned int target, | 261 unsigned int target, |
| 262 gpu::gles2::GLES2Interface* gl, | 262 gpu::gles2::GLES2Interface* gl, |
| 263 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | 263 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { |
| 264 std::unique_ptr<BufferQueue> buffer_queue( | 264 std::unique_ptr<BufferQueue> buffer_queue( |
| 265 new BufferQueue(gl, target, GL_RGBA, nullptr, gpu_memory_buffer_manager, | 265 new BufferQueue(gl, target, GL_RGB, nullptr, gpu_memory_buffer_manager, |
| 266 kFakeSurfaceHandle)); | 266 kFakeSurfaceHandle)); |
| 267 buffer_queue->Initialize(); | 267 buffer_queue->Initialize(); |
| 268 return buffer_queue; | 268 return buffer_queue; |
| 269 } | 269 } |
| 270 | 270 |
| 271 TEST(BufferQueueStandaloneTest, FboInitialization) { | 271 TEST(BufferQueueStandaloneTest, FboInitialization) { |
| 272 MockedContext* context; | 272 MockedContext* context; |
| 273 scoped_refptr<cc::TestContextProvider> context_provider = | 273 scoped_refptr<cc::TestContextProvider> context_provider = |
| 274 CreateMockedContextProvider(&context); | 274 CreateMockedContextProvider(&context); |
| 275 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( | 275 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 294 scoped_refptr<cc::TestContextProvider> context_provider = | 294 scoped_refptr<cc::TestContextProvider> context_provider = |
| 295 CreateMockedContextProvider(&context); | 295 CreateMockedContextProvider(&context); |
| 296 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( | 296 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( |
| 297 new StubGpuMemoryBufferManager); | 297 new StubGpuMemoryBufferManager); |
| 298 std::unique_ptr<BufferQueue> output_surface = CreateBufferQueue( | 298 std::unique_ptr<BufferQueue> output_surface = CreateBufferQueue( |
| 299 target, context_provider->ContextGL(), gpu_memory_buffer_manager.get()); | 299 target, context_provider->ContextGL(), gpu_memory_buffer_manager.get()); |
| 300 | 300 |
| 301 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); | 301 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); |
| 302 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); | 302 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); |
| 303 Expectation image = | 303 Expectation image = |
| 304 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA)) | 304 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGB)) |
| 305 .WillOnce(Return(1)); | 305 .WillOnce(Return(1)); |
| 306 Expectation fb = | 306 Expectation fb = |
| 307 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); | 307 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); |
| 308 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); | 308 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); |
| 309 Expectation bind_tex = | 309 Expectation bind_tex = |
| 310 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) | 310 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) |
| 311 .After(tex, image); | 311 .After(tex, image); |
| 312 EXPECT_CALL(*context, | 312 EXPECT_CALL(*context, |
| 313 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 313 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 314 target, Ne(0U), _)) | 314 target, Ne(0U), _)) |
| 315 .After(fb, bind_tex); | 315 .After(fb, bind_tex); |
| 316 | 316 |
| 317 output_surface->BindFramebuffer(); | 317 output_surface->BindFramebuffer(); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { | 321 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { |
| 322 scoped_refptr<cc::TestContextProvider> context_provider = | 322 scoped_refptr<cc::TestContextProvider> context_provider = |
| 323 cc::TestContextProvider::Create(); | 323 cc::TestContextProvider::Create(); |
| 324 context_provider->BindToCurrentThread(); | 324 context_provider->BindToCurrentThread(); |
| 325 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager; | 325 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager; |
| 326 std::unique_ptr<BufferQueue> output_surface; | 326 std::unique_ptr<BufferQueue> output_surface; |
| 327 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager); | 327 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager); |
| 328 | 328 |
| 329 std::unique_ptr<GLHelper> gl_helper; | 329 std::unique_ptr<GLHelper> gl_helper; |
| 330 gl_helper.reset(new GLHelper(context_provider->ContextGL(), | 330 gl_helper.reset(new GLHelper(context_provider->ContextGL(), |
| 331 context_provider->ContextSupport())); | 331 context_provider->ContextSupport())); |
| 332 | 332 |
| 333 output_surface.reset(new BufferQueue( | 333 output_surface.reset(new BufferQueue( |
| 334 context_provider->ContextGL(), GL_TEXTURE_2D, GL_RGBA, gl_helper.get(), | 334 context_provider->ContextGL(), GL_TEXTURE_2D, GL_RGB, gl_helper.get(), |
| 335 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle)); | 335 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle)); |
| 336 output_surface->Initialize(); | 336 output_surface->Initialize(); |
| 337 output_surface->Reshape(screen_size, 1.0f, gfx::ColorSpace()); | 337 output_surface->Reshape(screen_size, 1.0f, gfx::ColorSpace()); |
| 338 // Trigger a sub-buffer copy to exercise all paths. | 338 // Trigger a sub-buffer copy to exercise all paths. |
| 339 output_surface->BindFramebuffer(); | 339 output_surface->BindFramebuffer(); |
| 340 output_surface->SwapBuffers(screen_rect); | 340 output_surface->SwapBuffers(screen_rect); |
| 341 output_surface->PageFlipComplete(); | 341 output_surface->PageFlipComplete(); |
| 342 output_surface->BindFramebuffer(); | 342 output_surface->BindFramebuffer(); |
| 343 output_surface->SwapBuffers(small_damage); | 343 output_surface->SwapBuffers(small_damage); |
| 344 | 344 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 EXPECT_TRUE(displayed_frame()); | 574 EXPECT_TRUE(displayed_frame()); |
| 575 EXPECT_TRUE(current_frame()); | 575 EXPECT_TRUE(current_frame()); |
| 576 | 576 |
| 577 auto* current = current_frame(); | 577 auto* current = current_frame(); |
| 578 auto* displayed = displayed_frame(); | 578 auto* displayed = displayed_frame(); |
| 579 auto* in_flight = in_flight_surfaces().front().get(); | 579 auto* in_flight = in_flight_surfaces().front().get(); |
| 580 auto* available = available_surfaces().front().get(); | 580 auto* available = available_surfaces().front().get(); |
| 581 | 581 |
| 582 // Expect all 4 images to be destroyed, 3 of the existing textures to be | 582 // Expect all 4 images to be destroyed, 3 of the existing textures to be |
| 583 // copied from and 3 new images to be created. | 583 // copied from and 3 new images to be created. |
| 584 EXPECT_CALL(*context_, createImageCHROMIUM(_, 0, 0, GL_RGBA)).Times(3); | 584 EXPECT_CALL(*context_, createImageCHROMIUM(_, 0, 0, GL_RGB)).Times(3); |
| 585 Expectation copy1 = EXPECT_CALL(*mock_output_surface_, | 585 Expectation copy1 = EXPECT_CALL(*mock_output_surface_, |
| 586 CopyBufferDamage(_, displayed->texture, _, _)) | 586 CopyBufferDamage(_, displayed->texture, _, _)) |
| 587 .Times(1); | 587 .Times(1); |
| 588 Expectation copy2 = EXPECT_CALL(*mock_output_surface_, | 588 Expectation copy2 = EXPECT_CALL(*mock_output_surface_, |
| 589 CopyBufferDamage(_, current->texture, _, _)) | 589 CopyBufferDamage(_, current->texture, _, _)) |
| 590 .Times(1); | 590 .Times(1); |
| 591 Expectation copy3 = EXPECT_CALL(*mock_output_surface_, | 591 Expectation copy3 = EXPECT_CALL(*mock_output_surface_, |
| 592 CopyBufferDamage(_, in_flight->texture, _, _)) | 592 CopyBufferDamage(_, in_flight->texture, _, _)) |
| 593 .Times(1); | 593 .Times(1); |
| 594 | 594 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); | 668 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); |
| 669 EXPECT_CALL(*mock_output_surface_, | 669 EXPECT_CALL(*mock_output_surface_, |
| 670 CopyBufferDamage(target_texture, source_texture, small_damage, _)) | 670 CopyBufferDamage(target_texture, source_texture, small_damage, _)) |
| 671 .Times(1); | 671 .Times(1); |
| 672 output_surface_->SwapBuffers(small_damage); | 672 output_surface_->SwapBuffers(small_damage); |
| 673 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); | 673 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); |
| 674 } | 674 } |
| 675 | 675 |
| 676 } // namespace | 676 } // namespace |
| 677 } // namespace display_compositor | 677 } // namespace display_compositor |
| OLD | NEW |