Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: components/display_compositor/buffer_queue_unittest.cc

Issue 1905863002: Revert of Introduce components/display_compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/display_compositor/buffer_queue.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <set>
11 #include <utility>
12
13 #include "base/memory/ptr_util.h"
14 #include "cc/test/test_context_provider.h"
15 #include "cc/test/test_gpu_memory_buffer_manager.h"
16 #include "cc/test/test_web_graphics_context_3d.h"
17 #include "components/display_compositor/gl_helper.h"
18 #include "gpu/GLES2/gl2extchromium.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/khronos/GLES2/gl2ext.h"
22
23 using ::testing::_;
24 using ::testing::Expectation;
25 using ::testing::Ne;
26 using ::testing::Return;
27
28 namespace display_compositor {
29
30 class StubGpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
31 public:
32 StubGpuMemoryBufferImpl() {}
33
34 // Overridden from gfx::GpuMemoryBuffer:
35 bool Map() override { return false; }
36 void* memory(size_t plane) override { return nullptr; }
37 void Unmap() override {}
38 gfx::Size GetSize() const override { return gfx::Size(); }
39 gfx::BufferFormat GetFormat() const override {
40 return gfx::BufferFormat::BGRX_8888;
41 }
42 int stride(size_t plane) const override { return 0; }
43 gfx::GpuMemoryBufferId GetId() const override {
44 return gfx::GpuMemoryBufferId(0);
45 }
46 gfx::GpuMemoryBufferHandle GetHandle() const override {
47 return gfx::GpuMemoryBufferHandle();
48 }
49 ClientBuffer AsClientBuffer() override {
50 return reinterpret_cast<ClientBuffer>(this);
51 }
52 };
53
54 class StubGpuMemoryBufferManager : public cc::TestGpuMemoryBufferManager {
55 public:
56 StubGpuMemoryBufferManager() : allocate_succeeds_(true) {}
57
58 void set_allocate_succeeds(bool value) { allocate_succeeds_ = value; }
59
60 std::unique_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
61 const gfx::Size& size,
62 gfx::BufferFormat format,
63 gfx::BufferUsage usage,
64 int32_t surface_id) override {
65 if (!surface_id) {
66 return TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
67 size, format, usage, surface_id);
68 }
69 if (allocate_succeeds_)
70 return base::WrapUnique<gfx::GpuMemoryBuffer>(
71 new StubGpuMemoryBufferImpl);
72 return nullptr;
73 }
74
75 private:
76 bool allocate_succeeds_;
77 };
78
79 class MockBufferQueue : public BufferQueue {
80 public:
81 MockBufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
82 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
83 unsigned int target,
84 unsigned int internalformat)
85 : BufferQueue(context_provider,
86 target,
87 internalformat,
88 nullptr,
89 gpu_memory_buffer_manager,
90 1) {}
91 MOCK_METHOD4(CopyBufferDamage,
92 void(int, int, const gfx::Rect&, const gfx::Rect&));
93 };
94
95 class BufferQueueTest : public ::testing::Test {
96 public:
97 BufferQueueTest() : doublebuffering_(true), first_frame_(true) {}
98
99 void SetUp() override {
100 InitWithContext(cc::TestWebGraphicsContext3D::Create());
101 }
102
103 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) {
104 scoped_refptr<cc::TestContextProvider> context_provider =
105 cc::TestContextProvider::Create(std::move(context));
106 context_provider->BindToCurrentThread();
107 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager);
108 mock_output_surface_ =
109 new MockBufferQueue(context_provider, gpu_memory_buffer_manager_.get(),
110 GL_TEXTURE_2D, GL_RGBA);
111 output_surface_.reset(mock_output_surface_);
112 output_surface_->Initialize();
113 }
114
115 unsigned current_surface() {
116 return output_surface_->current_surface_
117 ? output_surface_->current_surface_->image
118 : 0;
119 }
120 const std::vector<std::unique_ptr<BufferQueue::AllocatedSurface>>&
121 available_surfaces() {
122 return output_surface_->available_surfaces_;
123 }
124 std::deque<std::unique_ptr<BufferQueue::AllocatedSurface>>&
125 in_flight_surfaces() {
126 return output_surface_->in_flight_surfaces_;
127 }
128
129 const BufferQueue::AllocatedSurface* displayed_frame() {
130 return output_surface_->displayed_surface_.get();
131 }
132 const BufferQueue::AllocatedSurface* current_frame() {
133 return output_surface_->current_surface_.get();
134 }
135 const BufferQueue::AllocatedSurface* next_frame() {
136 return output_surface_->available_surfaces_.back().get();
137 }
138 const gfx::Size size() { return output_surface_->size_; }
139
140 int CountBuffers() {
141 int n = available_surfaces().size() + in_flight_surfaces().size() +
142 (displayed_frame() ? 1 : 0);
143 if (current_surface())
144 n++;
145 return n;
146 }
147
148 // Check that each buffer is unique if present.
149 void CheckUnique() {
150 std::set<unsigned> buffers;
151 EXPECT_TRUE(InsertUnique(&buffers, current_surface()));
152 if (displayed_frame())
153 EXPECT_TRUE(InsertUnique(&buffers, displayed_frame()->image));
154 for (auto& surface : available_surfaces())
155 EXPECT_TRUE(InsertUnique(&buffers, surface->image));
156 for (auto& surface : in_flight_surfaces()) {
157 if (surface)
158 EXPECT_TRUE(InsertUnique(&buffers, surface->image));
159 }
160 }
161
162 void SwapBuffers() {
163 output_surface_->SwapBuffers(gfx::Rect(output_surface_->size_));
164 }
165
166 void SendDamagedFrame(const gfx::Rect& damage) {
167 // We don't care about the GL-level implementation here, just how it uses
168 // damage rects.
169 output_surface_->BindFramebuffer();
170 output_surface_->SwapBuffers(damage);
171 if (doublebuffering_ || !first_frame_)
172 output_surface_->PageFlipComplete();
173 first_frame_ = false;
174 }
175
176 void SendFullFrame() { SendDamagedFrame(gfx::Rect(output_surface_->size_)); }
177
178 protected:
179 bool InsertUnique(std::set<unsigned>* set, unsigned value) {
180 if (!value)
181 return true;
182 if (set->find(value) != set->end())
183 return false;
184 set->insert(value);
185 return true;
186 }
187
188 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager_;
189 std::unique_ptr<BufferQueue> output_surface_;
190 MockBufferQueue* mock_output_surface_;
191 bool doublebuffering_;
192 bool first_frame_;
193 };
194
195 namespace {
196 const gfx::Size screen_size = gfx::Size(30, 30);
197 const gfx::Rect screen_rect = gfx::Rect(screen_size);
198 const gfx::Rect small_damage = gfx::Rect(gfx::Size(10, 10));
199 const gfx::Rect large_damage = gfx::Rect(gfx::Size(20, 20));
200 const gfx::Rect overlapping_damage = gfx::Rect(gfx::Size(5, 20));
201
202 GLuint CreateImageDefault() {
203 static GLuint id = 0;
204 return ++id;
205 }
206
207 class MockedContext : public cc::TestWebGraphicsContext3D {
208 public:
209 MockedContext() {
210 ON_CALL(*this, createImageCHROMIUM(_, _, _, _))
211 .WillByDefault(testing::InvokeWithoutArgs(&CreateImageDefault));
212 }
213 MOCK_METHOD2(bindFramebuffer, void(GLenum, GLuint));
214 MOCK_METHOD2(bindTexture, void(GLenum, GLuint));
215 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(GLenum, GLint));
216 MOCK_METHOD4(createImageCHROMIUM,
217 GLuint(ClientBuffer, GLsizei, GLsizei, GLenum));
218 MOCK_METHOD1(destroyImageCHROMIUM, void(GLuint));
219 MOCK_METHOD5(framebufferTexture2D,
220 void(GLenum, GLenum, GLenum, GLuint, GLint));
221 };
222
223 class BufferQueueMockedContextTest : public BufferQueueTest {
224 public:
225 void SetUp() override {
226 context_ = new MockedContext();
227 InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D>(context_));
228 }
229
230 protected:
231 MockedContext* context_;
232 };
233
234 std::unique_ptr<BufferQueue> CreateOutputSurfaceWithMock(
235 unsigned int target,
236 MockedContext** context,
237 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
238 *context = new MockedContext();
239 scoped_refptr<cc::TestContextProvider> context_provider =
240 cc::TestContextProvider::Create(
241 std::unique_ptr<cc::TestWebGraphicsContext3D>(*context));
242 context_provider->BindToCurrentThread();
243 std::unique_ptr<BufferQueue> buffer_queue(
244 new BufferQueue(context_provider, target, GL_RGBA, nullptr,
245 gpu_memory_buffer_manager, 1));
246 buffer_queue->Initialize();
247 return buffer_queue;
248 }
249
250 TEST(BufferQueueStandaloneTest, FboInitialization) {
251 MockedContext* context;
252 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager(
253 new StubGpuMemoryBufferManager);
254 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock(
255 GL_TEXTURE_2D, &context, gpu_memory_buffer_manager.get());
256
257 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
258 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _))
259 .WillByDefault(Return());
260
261 output_surface->Reshape(gfx::Size(10, 20), 1.0f);
262 }
263
264 TEST(BufferQueueStandaloneTest, FboBinding) {
265 GLenum targets[] = {GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB};
266 for (size_t i = 0; i < 2; ++i) {
267 GLenum target = targets[i];
268 MockedContext* context;
269 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager(
270 new StubGpuMemoryBufferManager);
271 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock(
272 target, &context, gpu_memory_buffer_manager.get());
273 EXPECT_CALL(*context, bindTexture(target, Ne(0U)));
274 EXPECT_CALL(*context, destroyImageCHROMIUM(1));
275 Expectation image =
276 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA))
277 .WillOnce(Return(1));
278 Expectation fb =
279 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
280 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U)));
281 Expectation bind_tex =
282 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1))
283 .After(tex, image);
284 EXPECT_CALL(*context,
285 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
286 target, Ne(0U), _))
287 .After(fb, bind_tex);
288
289 output_surface->BindFramebuffer();
290 }
291 }
292
293 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) {
294 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager;
295 std::unique_ptr<BufferQueue> output_surface;
296 scoped_refptr<cc::TestContextProvider> context_provider =
297 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create());
298 context_provider->BindToCurrentThread();
299 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager);
300
301 std::unique_ptr<GLHelper> gl_helper;
302 gl_helper.reset(new GLHelper(context_provider->ContextGL(),
303 context_provider->ContextSupport()));
304
305 output_surface.reset(new BufferQueue(context_provider, GL_TEXTURE_2D, GL_RGBA,
306 gl_helper.get(),
307 gpu_memory_buffer_manager.get(), 1));
308 output_surface->Initialize();
309 output_surface->Reshape(screen_size, 1.0f);
310 // Trigger a sub-buffer copy to exercise all paths.
311 output_surface->BindFramebuffer();
312 output_surface->SwapBuffers(screen_rect);
313 output_surface->PageFlipComplete();
314 output_surface->BindFramebuffer();
315 output_surface->SwapBuffers(small_damage);
316
317 int current_fbo = 0;
318 context_provider->ContextGL()->GetIntegerv(GL_FRAMEBUFFER_BINDING,
319 &current_fbo);
320 EXPECT_EQ(static_cast<int>(output_surface->fbo()), current_fbo);
321 }
322
323 TEST_F(BufferQueueTest, PartialSwapReuse) {
324 output_surface_->Reshape(screen_size, 1.0f);
325 ASSERT_TRUE(doublebuffering_);
326 EXPECT_CALL(*mock_output_surface_,
327 CopyBufferDamage(_, _, small_damage, screen_rect))
328 .Times(1);
329 EXPECT_CALL(*mock_output_surface_,
330 CopyBufferDamage(_, _, small_damage, small_damage))
331 .Times(1);
332 EXPECT_CALL(*mock_output_surface_,
333 CopyBufferDamage(_, _, large_damage, small_damage))
334 .Times(1);
335 SendFullFrame();
336 SendDamagedFrame(small_damage);
337 SendDamagedFrame(small_damage);
338 SendDamagedFrame(large_damage);
339 // Verify that the damage has propagated.
340 EXPECT_EQ(next_frame()->damage, large_damage);
341 }
342
343 TEST_F(BufferQueueTest, PartialSwapFullFrame) {
344 output_surface_->Reshape(screen_size, 1.0f);
345 ASSERT_TRUE(doublebuffering_);
346 EXPECT_CALL(*mock_output_surface_,
347 CopyBufferDamage(_, _, small_damage, screen_rect))
348 .Times(1);
349 SendFullFrame();
350 SendDamagedFrame(small_damage);
351 SendFullFrame();
352 SendFullFrame();
353 EXPECT_EQ(next_frame()->damage, screen_rect);
354 }
355
356 TEST_F(BufferQueueTest, PartialSwapOverlapping) {
357 output_surface_->Reshape(screen_size, 1.0f);
358 ASSERT_TRUE(doublebuffering_);
359 EXPECT_CALL(*mock_output_surface_,
360 CopyBufferDamage(_, _, small_damage, screen_rect))
361 .Times(1);
362 EXPECT_CALL(*mock_output_surface_,
363 CopyBufferDamage(_, _, overlapping_damage, small_damage))
364 .Times(1);
365
366 SendFullFrame();
367 SendDamagedFrame(small_damage);
368 SendDamagedFrame(overlapping_damage);
369 EXPECT_EQ(next_frame()->damage, overlapping_damage);
370 }
371
372 TEST_F(BufferQueueTest, MultipleBindCalls) {
373 // Check that multiple bind calls do not create or change surfaces.
374 output_surface_->BindFramebuffer();
375 EXPECT_EQ(1, CountBuffers());
376 unsigned int fb = current_surface();
377 output_surface_->BindFramebuffer();
378 EXPECT_EQ(1, CountBuffers());
379 EXPECT_EQ(fb, current_surface());
380 }
381
382 TEST_F(BufferQueueTest, CheckDoubleBuffering) {
383 // Check buffer flow through double buffering path.
384 EXPECT_EQ(0, CountBuffers());
385 output_surface_->BindFramebuffer();
386 EXPECT_EQ(1, CountBuffers());
387 EXPECT_NE(0U, current_surface());
388 EXPECT_FALSE(displayed_frame());
389 SwapBuffers();
390 EXPECT_EQ(1U, in_flight_surfaces().size());
391 output_surface_->PageFlipComplete();
392 EXPECT_EQ(0U, in_flight_surfaces().size());
393 EXPECT_TRUE(displayed_frame()->texture);
394 output_surface_->BindFramebuffer();
395 EXPECT_EQ(2, CountBuffers());
396 CheckUnique();
397 EXPECT_NE(0U, current_surface());
398 EXPECT_EQ(0U, in_flight_surfaces().size());
399 EXPECT_TRUE(displayed_frame()->texture);
400 SwapBuffers();
401 CheckUnique();
402 EXPECT_EQ(1U, in_flight_surfaces().size());
403 EXPECT_TRUE(displayed_frame()->texture);
404 output_surface_->PageFlipComplete();
405 CheckUnique();
406 EXPECT_EQ(0U, in_flight_surfaces().size());
407 EXPECT_EQ(1U, available_surfaces().size());
408 EXPECT_TRUE(displayed_frame()->texture);
409 output_surface_->BindFramebuffer();
410 EXPECT_EQ(2, CountBuffers());
411 CheckUnique();
412 EXPECT_TRUE(available_surfaces().empty());
413 }
414
415 TEST_F(BufferQueueTest, CheckTripleBuffering) {
416 // Check buffer flow through triple buffering path.
417
418 // This bit is the same sequence tested in the doublebuffering case.
419 output_surface_->BindFramebuffer();
420 EXPECT_FALSE(displayed_frame());
421 SwapBuffers();
422 output_surface_->PageFlipComplete();
423 output_surface_->BindFramebuffer();
424 SwapBuffers();
425
426 EXPECT_EQ(2, CountBuffers());
427 CheckUnique();
428 EXPECT_EQ(1U, in_flight_surfaces().size());
429 EXPECT_TRUE(displayed_frame()->texture);
430 output_surface_->BindFramebuffer();
431 EXPECT_EQ(3, CountBuffers());
432 CheckUnique();
433 EXPECT_NE(0U, current_surface());
434 EXPECT_EQ(1U, in_flight_surfaces().size());
435 EXPECT_TRUE(displayed_frame()->texture);
436 output_surface_->PageFlipComplete();
437 EXPECT_EQ(3, CountBuffers());
438 CheckUnique();
439 EXPECT_NE(0U, current_surface());
440 EXPECT_EQ(0U, in_flight_surfaces().size());
441 EXPECT_TRUE(displayed_frame()->texture);
442 EXPECT_EQ(1U, available_surfaces().size());
443 }
444
445 TEST_F(BufferQueueTest, CheckCorrectBufferOrdering) {
446 const size_t kSwapCount = 3;
447 for (size_t i = 0; i < kSwapCount; ++i) {
448 output_surface_->BindFramebuffer();
449 SwapBuffers();
450 }
451
452 EXPECT_EQ(kSwapCount, in_flight_surfaces().size());
453 for (size_t i = 0; i < kSwapCount; ++i) {
454 unsigned int next_texture_id = in_flight_surfaces().front()->texture;
455 output_surface_->PageFlipComplete();
456 EXPECT_EQ(displayed_frame()->texture, next_texture_id);
457 }
458 }
459
460 TEST_F(BufferQueueTest, ReshapeWithInFlightSurfaces) {
461 const size_t kSwapCount = 3;
462 for (size_t i = 0; i < kSwapCount; ++i) {
463 output_surface_->BindFramebuffer();
464 SwapBuffers();
465 }
466
467 output_surface_->Reshape(gfx::Size(10, 20), 1.0f);
468 EXPECT_EQ(3u, in_flight_surfaces().size());
469
470 for (size_t i = 0; i < kSwapCount; ++i) {
471 output_surface_->PageFlipComplete();
472 EXPECT_FALSE(displayed_frame());
473 }
474
475 // The dummy surfacess left should be discarded.
476 EXPECT_EQ(0u, available_surfaces().size());
477 }
478
479 TEST_F(BufferQueueTest, SwapAfterReshape) {
480 const size_t kSwapCount = 3;
481 for (size_t i = 0; i < kSwapCount; ++i) {
482 output_surface_->BindFramebuffer();
483 SwapBuffers();
484 }
485
486 output_surface_->Reshape(gfx::Size(10, 20), 1.0f);
487
488 for (size_t i = 0; i < kSwapCount; ++i) {
489 output_surface_->BindFramebuffer();
490 SwapBuffers();
491 }
492
493 EXPECT_EQ(2 * kSwapCount, in_flight_surfaces().size());
494
495 for (size_t i = 0; i < kSwapCount; ++i) {
496 output_surface_->PageFlipComplete();
497 EXPECT_FALSE(displayed_frame());
498 }
499
500 CheckUnique();
501
502 for (size_t i = 0; i < kSwapCount; ++i) {
503 unsigned int next_texture_id = in_flight_surfaces().front()->texture;
504 output_surface_->PageFlipComplete();
505 EXPECT_EQ(displayed_frame()->texture, next_texture_id);
506 EXPECT_TRUE(displayed_frame());
507 }
508 }
509
510 TEST_F(BufferQueueMockedContextTest, RecreateBuffers) {
511 // This setup is to easily get one frame in each of:
512 // - currently bound for drawing.
513 // - in flight to GPU.
514 // - currently displayed.
515 // - free frame.
516 // This tests buffers in all states.
517 // Bind/swap pushes frames into the in flight list, then the PageFlipComplete
518 // calls pull one frame into displayed and another into the free list.
519 output_surface_->BindFramebuffer();
520 SwapBuffers();
521 output_surface_->BindFramebuffer();
522 SwapBuffers();
523 output_surface_->BindFramebuffer();
524 SwapBuffers();
525 output_surface_->BindFramebuffer();
526 output_surface_->PageFlipComplete();
527 output_surface_->PageFlipComplete();
528 // We should have one buffer in each possible state right now, including one
529 // being drawn to.
530 ASSERT_EQ(1U, in_flight_surfaces().size());
531 ASSERT_EQ(1U, available_surfaces().size());
532 EXPECT_TRUE(displayed_frame());
533 EXPECT_TRUE(current_frame());
534
535 auto* current = current_frame();
536 auto* displayed = displayed_frame();
537 auto* in_flight = in_flight_surfaces().front().get();
538 auto* available = available_surfaces().front().get();
539
540 // Expect all 4 images to be destroyed, 3 of the existing textures to be
541 // copied from and 3 new images to be created.
542 EXPECT_CALL(*context_, createImageCHROMIUM(_, 0, 0, GL_RGBA)).Times(3);
543 Expectation copy1 = EXPECT_CALL(*mock_output_surface_,
544 CopyBufferDamage(_, displayed->texture, _, _))
545 .Times(1);
546 Expectation copy2 = EXPECT_CALL(*mock_output_surface_,
547 CopyBufferDamage(_, current->texture, _, _))
548 .Times(1);
549 Expectation copy3 = EXPECT_CALL(*mock_output_surface_,
550 CopyBufferDamage(_, in_flight->texture, _, _))
551 .Times(1);
552
553 EXPECT_CALL(*context_, destroyImageCHROMIUM(displayed->image))
554 .Times(1)
555 .After(copy1);
556 EXPECT_CALL(*context_, destroyImageCHROMIUM(current->image))
557 .Times(1)
558 .After(copy2);
559 EXPECT_CALL(*context_, destroyImageCHROMIUM(in_flight->image))
560 .Times(1)
561 .After(copy3);
562 EXPECT_CALL(*context_, destroyImageCHROMIUM(available->image)).Times(1);
563 // After copying, we expect the framebuffer binding to be updated.
564 EXPECT_CALL(*context_, bindFramebuffer(_, _))
565 .After(copy1)
566 .After(copy2)
567 .After(copy3);
568 EXPECT_CALL(*context_, framebufferTexture2D(_, _, _, _, _))
569 .After(copy1)
570 .After(copy2)
571 .After(copy3);
572
573 output_surface_->RecreateBuffers();
574 testing::Mock::VerifyAndClearExpectations(context_);
575 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
576
577 // All free buffers should be destroyed, the remaining buffers should all
578 // be replaced but still valid.
579 EXPECT_EQ(1U, in_flight_surfaces().size());
580 EXPECT_EQ(0U, available_surfaces().size());
581 EXPECT_TRUE(displayed_frame());
582 EXPECT_TRUE(current_frame());
583 }
584
585 TEST_F(BufferQueueTest, AllocateFails) {
586 output_surface_->Reshape(screen_size, 1.0f);
587
588 // Succeed in the two swaps.
589 output_surface_->BindFramebuffer();
590 EXPECT_TRUE(current_frame());
591 output_surface_->SwapBuffers(screen_rect);
592
593 // Fail the next surface allocation.
594 gpu_memory_buffer_manager_->set_allocate_succeeds(false);
595 output_surface_->BindFramebuffer();
596 EXPECT_FALSE(current_frame());
597 output_surface_->SwapBuffers(screen_rect);
598 EXPECT_FALSE(current_frame());
599
600 // Try another swap. It should copy the buffer damage from the back
601 // surface.
602 gpu_memory_buffer_manager_->set_allocate_succeeds(true);
603 output_surface_->BindFramebuffer();
604 unsigned int source_texture = in_flight_surfaces().front()->texture;
605 unsigned int target_texture = current_frame()->texture;
606 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
607 EXPECT_CALL(*mock_output_surface_,
608 CopyBufferDamage(target_texture, source_texture, small_damage, _))
609 .Times(1);
610 output_surface_->SwapBuffers(small_damage);
611 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
612
613 // Destroy the just-created buffer, and try another swap. The copy should
614 // come from the displayed surface (because both in-flight surfaces are
615 // gone now).
616 output_surface_->PageFlipComplete();
617 in_flight_surfaces().back().reset();
618 EXPECT_EQ(2u, in_flight_surfaces().size());
619 for (auto& surface : in_flight_surfaces())
620 EXPECT_FALSE(surface);
621 output_surface_->BindFramebuffer();
622 source_texture = displayed_frame()->texture;
623 EXPECT_TRUE(current_frame());
624 EXPECT_TRUE(displayed_frame());
625 target_texture = current_frame()->texture;
626 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
627 EXPECT_CALL(*mock_output_surface_,
628 CopyBufferDamage(target_texture, source_texture, small_damage, _))
629 .Times(1);
630 output_surface_->SwapBuffers(small_damage);
631 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
632 }
633
634 } // namespace
635 } // namespace display_compositor
OLDNEW
« no previous file with comments | « components/display_compositor/buffer_queue.cc ('k') | components/display_compositor/display_compositor_export.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698