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 "content/browser/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 "content/browser/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 | 22 |
23 using ::testing::_; | 23 using ::testing::_; |
24 using ::testing::Expectation; | 24 using ::testing::Expectation; |
25 using ::testing::Ne; | 25 using ::testing::Ne; |
26 using ::testing::Return; | 26 using ::testing::Return; |
27 | 27 |
28 namespace content { | 28 namespace display_compositor { |
29 | 29 |
30 class StubGpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 30 class StubGpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
31 public: | 31 public: |
32 StubGpuMemoryBufferImpl() {} | 32 StubGpuMemoryBufferImpl() {} |
33 | 33 |
34 // Overridden from gfx::GpuMemoryBuffer: | 34 // Overridden from gfx::GpuMemoryBuffer: |
35 bool Map() override { return false; } | 35 bool Map() override { return false; } |
36 void* memory(size_t plane) override { return nullptr; } | 36 void* memory(size_t plane) override { return nullptr; } |
37 void Unmap() override {} | 37 void Unmap() override {} |
38 gfx::Size GetSize() const override { return gfx::Size(); } | 38 gfx::Size GetSize() const override { return gfx::Size(); } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 GL_TEXTURE_2D, &context, gpu_memory_buffer_manager.get()); | 255 GL_TEXTURE_2D, &context, gpu_memory_buffer_manager.get()); |
256 | 256 |
257 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); | 257 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); |
258 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _)) | 258 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _)) |
259 .WillByDefault(Return()); | 259 .WillByDefault(Return()); |
260 | 260 |
261 output_surface->Reshape(gfx::Size(10, 20), 1.0f); | 261 output_surface->Reshape(gfx::Size(10, 20), 1.0f); |
262 } | 262 } |
263 | 263 |
264 TEST(BufferQueueStandaloneTest, FboBinding) { | 264 TEST(BufferQueueStandaloneTest, FboBinding) { |
265 GLenum targets[] = { GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB }; | 265 GLenum targets[] = {GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB}; |
266 for (size_t i = 0; i < 2; ++i) { | 266 for (size_t i = 0; i < 2; ++i) { |
267 GLenum target = targets[i]; | 267 GLenum target = targets[i]; |
268 MockedContext* context; | 268 MockedContext* context; |
269 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( | 269 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( |
270 new StubGpuMemoryBufferManager); | 270 new StubGpuMemoryBufferManager); |
271 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock( | 271 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock( |
272 target, &context, gpu_memory_buffer_manager.get()); | 272 target, &context, gpu_memory_buffer_manager.get()); |
273 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); | 273 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); |
274 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); | 274 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); |
275 Expectation image = | 275 Expectation image = |
276 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA)) | 276 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA)) |
277 .WillOnce(Return(1)); | 277 .WillOnce(Return(1)); |
278 Expectation fb = | 278 Expectation fb = |
279 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); | 279 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); |
280 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); | 280 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); |
281 Expectation bind_tex = | 281 Expectation bind_tex = |
282 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) | 282 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) |
283 .After(tex, image); | 283 .After(tex, image); |
284 EXPECT_CALL( | 284 EXPECT_CALL(*context, |
285 *context, | 285 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
286 framebufferTexture2D( | 286 target, Ne(0U), _)) |
287 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, Ne(0U), _)) | |
288 .After(fb, bind_tex); | 287 .After(fb, bind_tex); |
289 | 288 |
290 output_surface->BindFramebuffer(); | 289 output_surface->BindFramebuffer(); |
291 } | 290 } |
292 } | 291 } |
293 | 292 |
294 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { | 293 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { |
295 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager; | 294 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager; |
296 std::unique_ptr<BufferQueue> output_surface; | 295 std::unique_ptr<BufferQueue> output_surface; |
297 scoped_refptr<cc::TestContextProvider> context_provider = | 296 scoped_refptr<cc::TestContextProvider> context_provider = |
(...skipping 20 matching lines...) Expand all Loading... |
318 int current_fbo = 0; | 317 int current_fbo = 0; |
319 context_provider->ContextGL()->GetIntegerv(GL_FRAMEBUFFER_BINDING, | 318 context_provider->ContextGL()->GetIntegerv(GL_FRAMEBUFFER_BINDING, |
320 ¤t_fbo); | 319 ¤t_fbo); |
321 EXPECT_EQ(static_cast<int>(output_surface->fbo()), current_fbo); | 320 EXPECT_EQ(static_cast<int>(output_surface->fbo()), current_fbo); |
322 } | 321 } |
323 | 322 |
324 TEST_F(BufferQueueTest, PartialSwapReuse) { | 323 TEST_F(BufferQueueTest, PartialSwapReuse) { |
325 output_surface_->Reshape(screen_size, 1.0f); | 324 output_surface_->Reshape(screen_size, 1.0f); |
326 ASSERT_TRUE(doublebuffering_); | 325 ASSERT_TRUE(doublebuffering_); |
327 EXPECT_CALL(*mock_output_surface_, | 326 EXPECT_CALL(*mock_output_surface_, |
328 CopyBufferDamage(_, _, small_damage, screen_rect)).Times(1); | 327 CopyBufferDamage(_, _, small_damage, screen_rect)) |
| 328 .Times(1); |
329 EXPECT_CALL(*mock_output_surface_, | 329 EXPECT_CALL(*mock_output_surface_, |
330 CopyBufferDamage(_, _, small_damage, small_damage)).Times(1); | 330 CopyBufferDamage(_, _, small_damage, small_damage)) |
| 331 .Times(1); |
331 EXPECT_CALL(*mock_output_surface_, | 332 EXPECT_CALL(*mock_output_surface_, |
332 CopyBufferDamage(_, _, large_damage, small_damage)).Times(1); | 333 CopyBufferDamage(_, _, large_damage, small_damage)) |
| 334 .Times(1); |
333 SendFullFrame(); | 335 SendFullFrame(); |
334 SendDamagedFrame(small_damage); | 336 SendDamagedFrame(small_damage); |
335 SendDamagedFrame(small_damage); | 337 SendDamagedFrame(small_damage); |
336 SendDamagedFrame(large_damage); | 338 SendDamagedFrame(large_damage); |
337 // Verify that the damage has propagated. | 339 // Verify that the damage has propagated. |
338 EXPECT_EQ(next_frame()->damage, large_damage); | 340 EXPECT_EQ(next_frame()->damage, large_damage); |
339 } | 341 } |
340 | 342 |
341 TEST_F(BufferQueueTest, PartialSwapFullFrame) { | 343 TEST_F(BufferQueueTest, PartialSwapFullFrame) { |
342 output_surface_->Reshape(screen_size, 1.0f); | 344 output_surface_->Reshape(screen_size, 1.0f); |
343 ASSERT_TRUE(doublebuffering_); | 345 ASSERT_TRUE(doublebuffering_); |
344 EXPECT_CALL(*mock_output_surface_, | 346 EXPECT_CALL(*mock_output_surface_, |
345 CopyBufferDamage(_, _, small_damage, screen_rect)).Times(1); | 347 CopyBufferDamage(_, _, small_damage, screen_rect)) |
| 348 .Times(1); |
346 SendFullFrame(); | 349 SendFullFrame(); |
347 SendDamagedFrame(small_damage); | 350 SendDamagedFrame(small_damage); |
348 SendFullFrame(); | 351 SendFullFrame(); |
349 SendFullFrame(); | 352 SendFullFrame(); |
350 EXPECT_EQ(next_frame()->damage, screen_rect); | 353 EXPECT_EQ(next_frame()->damage, screen_rect); |
351 } | 354 } |
352 | 355 |
353 TEST_F(BufferQueueTest, PartialSwapOverlapping) { | 356 TEST_F(BufferQueueTest, PartialSwapOverlapping) { |
354 output_surface_->Reshape(screen_size, 1.0f); | 357 output_surface_->Reshape(screen_size, 1.0f); |
355 ASSERT_TRUE(doublebuffering_); | 358 ASSERT_TRUE(doublebuffering_); |
356 EXPECT_CALL(*mock_output_surface_, | 359 EXPECT_CALL(*mock_output_surface_, |
357 CopyBufferDamage(_, _, small_damage, screen_rect)).Times(1); | 360 CopyBufferDamage(_, _, small_damage, screen_rect)) |
358 EXPECT_CALL(*mock_output_surface_, CopyBufferDamage(_, _, overlapping_damage, | 361 .Times(1); |
359 small_damage)).Times(1); | 362 EXPECT_CALL(*mock_output_surface_, |
| 363 CopyBufferDamage(_, _, overlapping_damage, small_damage)) |
| 364 .Times(1); |
360 | 365 |
361 SendFullFrame(); | 366 SendFullFrame(); |
362 SendDamagedFrame(small_damage); | 367 SendDamagedFrame(small_damage); |
363 SendDamagedFrame(overlapping_damage); | 368 SendDamagedFrame(overlapping_damage); |
364 EXPECT_EQ(next_frame()->damage, overlapping_damage); | 369 EXPECT_EQ(next_frame()->damage, overlapping_damage); |
365 } | 370 } |
366 | 371 |
367 TEST_F(BufferQueueTest, MultipleBindCalls) { | 372 TEST_F(BufferQueueTest, MultipleBindCalls) { |
368 // Check that multiple bind calls do not create or change surfaces. | 373 // Check that multiple bind calls do not create or change surfaces. |
369 output_surface_->BindFramebuffer(); | 374 output_surface_->BindFramebuffer(); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 target_texture = current_frame()->texture; | 625 target_texture = current_frame()->texture; |
621 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); | 626 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); |
622 EXPECT_CALL(*mock_output_surface_, | 627 EXPECT_CALL(*mock_output_surface_, |
623 CopyBufferDamage(target_texture, source_texture, small_damage, _)) | 628 CopyBufferDamage(target_texture, source_texture, small_damage, _)) |
624 .Times(1); | 629 .Times(1); |
625 output_surface_->SwapBuffers(small_damage); | 630 output_surface_->SwapBuffers(small_damage); |
626 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); | 631 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); |
627 } | 632 } |
628 | 633 |
629 } // namespace | 634 } // namespace |
630 } // namespace content | 635 } // namespace display_compositor |
OLD | NEW |