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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/gpu/DrawingBufferTest.cpp

Issue 2905633002: Bind framebuffer to fbo_ object before readPixels, rather than multisample_fbo_ (Closed)
Patch Set: rebase code Created 3 years, 6 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
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } // anonymous namespace 66 } // anonymous namespace
67 67
68 class DrawingBufferTest : public Test { 68 class DrawingBufferTest : public Test {
69 protected: 69 protected:
70 void SetUp() override { Init(kDisableMultisampling); } 70 void SetUp() override { Init(kDisableMultisampling); }
71 71
72 void Init(UseMultisampling use_multisampling) { 72 void Init(UseMultisampling use_multisampling) {
73 IntSize initial_size(kInitialWidth, kInitialHeight); 73 IntSize initial_size(kInitialWidth, kInitialHeight);
74 std::unique_ptr<GLES2InterfaceForTests> gl = 74 std::unique_ptr<GLES2InterfaceForTests> gl =
75 WTF::WrapUnique(new GLES2InterfaceForTests); 75 WTF::WrapUnique(new GLES2InterfaceForTests);
76 gl_ = gl.get();
77 SetAndSaveRestoreState(false);
78 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = 76 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider =
79 WTF::WrapUnique( 77 WTF::WrapUnique(
80 new WebGraphicsContext3DProviderForTests(std::move(gl))); 78 new WebGraphicsContext3DProviderForTests(std::move(gl)));
79 GLES2InterfaceForTests* gl_ =
80 static_cast<GLES2InterfaceForTests*>(provider->ContextGL());
81 drawing_buffer_ = DrawingBufferForTests::Create( 81 drawing_buffer_ = DrawingBufferForTests::Create(
82 std::move(provider), gl_, initial_size, DrawingBuffer::kPreserve, 82 std::move(provider), gl_, initial_size, DrawingBuffer::kPreserve,
83 use_multisampling); 83 use_multisampling);
84 CHECK(drawing_buffer_); 84 CHECK(drawing_buffer_);
85 SetAndSaveRestoreState(false);
85 } 86 }
86 87
87 // Initialize GL state with unusual values, to verify that they are restored. 88 // Initialize GL state with unusual values, to verify that they are restored.
88 // The |invert| parameter will reverse all boolean parameters, so that all 89 // The |invert| parameter will reverse all boolean parameters, so that all
89 // values are tested. 90 // values are tested.
90 void SetAndSaveRestoreState(bool invert) { 91 void SetAndSaveRestoreState(bool invert) {
92 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests();
91 GLboolean scissor_enabled = !invert; 93 GLboolean scissor_enabled = !invert;
92 GLfloat clear_color[4] = {0.1, 0.2, 0.3, 0.4}; 94 GLfloat clear_color[4] = {0.1, 0.2, 0.3, 0.4};
93 GLfloat clear_depth = 0.8; 95 GLfloat clear_depth = 0.8;
94 GLint clear_stencil = 37; 96 GLint clear_stencil = 37;
95 GLboolean color_mask[4] = {invert, !invert, !invert, invert}; 97 GLboolean color_mask[4] = {invert, !invert, !invert, invert};
96 GLboolean depth_mask = invert; 98 GLboolean depth_mask = invert;
97 GLboolean stencil_mask = invert; 99 GLboolean stencil_mask = invert;
98 GLint pack_alignment = 7; 100 GLint pack_alignment = 7;
99 GLuint active_texture2d_binding = 0xbeef1; 101 GLuint active_texture2d_binding = 0xbeef1;
100 GLuint renderbuffer_binding = 0xbeef2; 102 GLuint renderbuffer_binding = 0xbeef2;
(...skipping 16 matching lines...) Expand all
117 gl_->PixelStorei(GL_PACK_ALIGNMENT, pack_alignment); 119 gl_->PixelStorei(GL_PACK_ALIGNMENT, pack_alignment);
118 gl_->BindTexture(GL_TEXTURE_2D, active_texture2d_binding); 120 gl_->BindTexture(GL_TEXTURE_2D, active_texture2d_binding);
119 gl_->BindRenderbuffer(GL_RENDERBUFFER, renderbuffer_binding); 121 gl_->BindRenderbuffer(GL_RENDERBUFFER, renderbuffer_binding);
120 gl_->BindFramebuffer(GL_DRAW_FRAMEBUFFER, draw_framebuffer_binding); 122 gl_->BindFramebuffer(GL_DRAW_FRAMEBUFFER, draw_framebuffer_binding);
121 gl_->BindFramebuffer(GL_READ_FRAMEBUFFER, read_framebuffer_binding); 123 gl_->BindFramebuffer(GL_READ_FRAMEBUFFER, read_framebuffer_binding);
122 gl_->BindBuffer(GL_PIXEL_UNPACK_BUFFER, pixel_unpack_buffer_binding); 124 gl_->BindBuffer(GL_PIXEL_UNPACK_BUFFER, pixel_unpack_buffer_binding);
123 125
124 gl_->SaveState(); 126 gl_->SaveState();
125 } 127 }
126 128
127 void VerifyStateWasRestored() { gl_->VerifyStateHasNotChangedSinceSave(); } 129 void VerifyStateWasRestored() {
130 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests();
131 gl_->VerifyStateHasNotChangedSinceSave();
132 }
128 133
129 GLES2InterfaceForTests* gl_;
130 RefPtr<DrawingBufferForTests> drawing_buffer_; 134 RefPtr<DrawingBufferForTests> drawing_buffer_;
131 }; 135 };
132 136
133 class DrawingBufferTestMultisample : public DrawingBufferTest { 137 class DrawingBufferTestMultisample : public DrawingBufferTest {
134 protected: 138 protected:
135 void SetUp() override { Init(kEnableMultisampling); } 139 void SetUp() override { Init(kEnableMultisampling); }
136 }; 140 };
137 141
138 TEST_F(DrawingBufferTestMultisample, verifyMultisampleResolve) { 142 TEST_F(DrawingBufferTestMultisample, verifyMultisampleResolve) {
139 // Initial state: already marked changed, multisampled 143 // Initial state: already marked changed, multisampled
140 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); 144 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged());
141 EXPECT_TRUE(drawing_buffer_->ExplicitResolveOfMultisampleData()); 145 EXPECT_TRUE(drawing_buffer_->ExplicitResolveOfMultisampleData());
142 146
143 // Resolve the multisample buffer 147 // Resolve the multisample buffer
144 drawing_buffer_->ResolveAndBindForReadAndDraw(); 148 drawing_buffer_->ResolveAndBindForReadAndDraw();
145 149
146 // After resolve, acknowledge new content 150 // After resolve, acknowledge new content
147 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged()); 151 EXPECT_TRUE(drawing_buffer_->MarkContentsChanged());
148 // No new content 152 // No new content
149 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); 153 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged());
150 154
151 drawing_buffer_->BeginDestruction(); 155 drawing_buffer_->BeginDestruction();
152 } 156 }
153 157
154 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) { 158 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) {
159 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests();
155 VerifyStateWasRestored(); 160 VerifyStateWasRestored();
156 cc::TextureMailbox texture_mailbox; 161 cc::TextureMailbox texture_mailbox;
157 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 162 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
158 163
159 IntSize initial_size(kInitialWidth, kInitialHeight); 164 IntSize initial_size(kInitialWidth, kInitialHeight);
160 IntSize alternate_size(kInitialWidth, kAlternateHeight); 165 IntSize alternate_size(kInitialWidth, kAlternateHeight);
161 166
162 // Produce one mailbox at size 100x100. 167 // Produce one mailbox at size 100x100.
163 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); 168 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged());
164 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, 169 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 EXPECT_NE(texture_mailbox1.mailbox(), recycled_texture_mailbox2.mailbox()); 347 EXPECT_NE(texture_mailbox1.mailbox(), recycled_texture_mailbox2.mailbox());
343 EXPECT_NE(texture_mailbox2.mailbox(), recycled_texture_mailbox2.mailbox()); 348 EXPECT_NE(texture_mailbox2.mailbox(), recycled_texture_mailbox2.mailbox());
344 EXPECT_NE(texture_mailbox3.mailbox(), recycled_texture_mailbox2.mailbox()); 349 EXPECT_NE(texture_mailbox3.mailbox(), recycled_texture_mailbox2.mailbox());
345 350
346 recycled_release_callback1->Run(gpu::SyncToken(), false /* lostResource */); 351 recycled_release_callback1->Run(gpu::SyncToken(), false /* lostResource */);
347 recycled_release_callback2->Run(gpu::SyncToken(), false /* lostResource */); 352 recycled_release_callback2->Run(gpu::SyncToken(), false /* lostResource */);
348 drawing_buffer_->BeginDestruction(); 353 drawing_buffer_->BeginDestruction();
349 } 354 }
350 355
351 TEST_F(DrawingBufferTest, verifyInsertAndWaitSyncTokenCorrectly) { 356 TEST_F(DrawingBufferTest, verifyInsertAndWaitSyncTokenCorrectly) {
357 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests();
352 cc::TextureMailbox texture_mailbox; 358 cc::TextureMailbox texture_mailbox;
353 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 359 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
354 360
355 // Produce mailboxes. 361 // Produce mailboxes.
356 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); 362 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged());
357 EXPECT_EQ(gpu::SyncToken(), gl_->MostRecentlyWaitedSyncToken()); 363 EXPECT_EQ(gpu::SyncToken(), gl_->MostRecentlyWaitedSyncToken());
358 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, 364 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox,
359 &release_callback)); 365 &release_callback));
360 // PrepareTextureMailbox() does not wait for any sync point. 366 // PrepareTextureMailbox() does not wait for any sync point.
361 EXPECT_EQ(gpu::SyncToken(), gl_->MostRecentlyWaitedSyncToken()); 367 EXPECT_EQ(gpu::SyncToken(), gl_->MostRecentlyWaitedSyncToken());
(...skipping 22 matching lines...) Expand all
384 } 390 }
385 391
386 class DrawingBufferImageChromiumTest : public DrawingBufferTest { 392 class DrawingBufferImageChromiumTest : public DrawingBufferTest {
387 protected: 393 protected:
388 void SetUp() override { 394 void SetUp() override {
389 platform_.reset(new ScopedTestingPlatformSupport<FakePlatformSupport>); 395 platform_.reset(new ScopedTestingPlatformSupport<FakePlatformSupport>);
390 396
391 IntSize initial_size(kInitialWidth, kInitialHeight); 397 IntSize initial_size(kInitialWidth, kInitialHeight);
392 std::unique_ptr<GLES2InterfaceForTests> gl = 398 std::unique_ptr<GLES2InterfaceForTests> gl =
393 WTF::WrapUnique(new GLES2InterfaceForTests); 399 WTF::WrapUnique(new GLES2InterfaceForTests);
394 gl_ = gl.get();
395 SetAndSaveRestoreState(true);
396 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = 400 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider =
397 WTF::WrapUnique( 401 WTF::WrapUnique(
398 new WebGraphicsContext3DProviderForTests(std::move(gl))); 402 new WebGraphicsContext3DProviderForTests(std::move(gl)));
399 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); 403 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true);
404 GLES2InterfaceForTests* gl_ =
405 static_cast<GLES2InterfaceForTests*>(provider->ContextGL());
400 image_id0_ = gl_->NextImageIdToBeCreated(); 406 image_id0_ = gl_->NextImageIdToBeCreated();
401 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id0_)).Times(1); 407 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id0_)).Times(1);
402 drawing_buffer_ = DrawingBufferForTests::Create( 408 drawing_buffer_ = DrawingBufferForTests::Create(
403 std::move(provider), gl_, initial_size, DrawingBuffer::kPreserve, 409 std::move(provider), gl_, initial_size, DrawingBuffer::kPreserve,
404 kDisableMultisampling); 410 kDisableMultisampling);
405 CHECK(drawing_buffer_); 411 CHECK(drawing_buffer_);
412 SetAndSaveRestoreState(true);
406 testing::Mock::VerifyAndClearExpectations(gl_); 413 testing::Mock::VerifyAndClearExpectations(gl_);
407 } 414 }
408 415
409 void TearDown() override { 416 void TearDown() override {
410 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); 417 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false);
411 platform_.reset(); 418 platform_.reset();
412 } 419 }
413 420
414 GLuint image_id0_; 421 GLuint image_id0_;
415 std::unique_ptr<ScopedTestingPlatformSupport<FakePlatformSupport>> platform_; 422 std::unique_ptr<ScopedTestingPlatformSupport<FakePlatformSupport>> platform_;
416 }; 423 };
417 424
418 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) { 425 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) {
426 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests();
419 cc::TextureMailbox texture_mailbox; 427 cc::TextureMailbox texture_mailbox;
420 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 428 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
421 429
422 IntSize initial_size(kInitialWidth, kInitialHeight); 430 IntSize initial_size(kInitialWidth, kInitialHeight);
423 IntSize alternate_size(kInitialWidth, kAlternateHeight); 431 IntSize alternate_size(kInitialWidth, kAlternateHeight);
424 432
425 GLuint image_id1 = gl_->NextImageIdToBeCreated(); 433 GLuint image_id1 = gl_->NextImageIdToBeCreated();
426 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id1)).Times(1); 434 EXPECT_CALL(*gl_, BindTexImage2DMock(image_id1)).Times(1);
427 // Produce one mailbox at size 100x100. 435 // Produce one mailbox at size 100x100.
428 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); 436 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 498
491 EXPECT_CALL(*gl_, DestroyImageMock(image_id5)).Times(1); 499 EXPECT_CALL(*gl_, DestroyImageMock(image_id5)).Times(1);
492 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id5)).Times(1); 500 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id5)).Times(1);
493 EXPECT_CALL(*gl_, DestroyImageMock(image_id4)).Times(1); 501 EXPECT_CALL(*gl_, DestroyImageMock(image_id4)).Times(1);
494 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id4)).Times(1); 502 EXPECT_CALL(*gl_, ReleaseTexImage2DMock(image_id4)).Times(1);
495 drawing_buffer_->BeginDestruction(); 503 drawing_buffer_->BeginDestruction();
496 testing::Mock::VerifyAndClearExpectations(gl_); 504 testing::Mock::VerifyAndClearExpectations(gl_);
497 } 505 }
498 506
499 TEST_F(DrawingBufferImageChromiumTest, allocationFailure) { 507 TEST_F(DrawingBufferImageChromiumTest, allocationFailure) {
508 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests();
500 cc::TextureMailbox texture_mailbox1; 509 cc::TextureMailbox texture_mailbox1;
501 std::unique_ptr<cc::SingleReleaseCallback> release_callback1; 510 std::unique_ptr<cc::SingleReleaseCallback> release_callback1;
502 cc::TextureMailbox texture_mailbox2; 511 cc::TextureMailbox texture_mailbox2;
503 std::unique_ptr<cc::SingleReleaseCallback> release_callback2; 512 std::unique_ptr<cc::SingleReleaseCallback> release_callback2;
504 cc::TextureMailbox texture_mailbox3; 513 cc::TextureMailbox texture_mailbox3;
505 std::unique_ptr<cc::SingleReleaseCallback> release_callback3; 514 std::unique_ptr<cc::SingleReleaseCallback> release_callback3;
506 515
507 // Request a mailbox. An image should already be created. Everything works 516 // Request a mailbox. An image should already be created. Everything works
508 // as expected. 517 // as expected.
509 EXPECT_CALL(*gl_, BindTexImage2DMock(_)).Times(1); 518 EXPECT_CALL(*gl_, BindTexImage2DMock(_)).Times(1);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 EXPECT_EQ(0u, tracking_gl->DepthStencilAttachment()); 697 EXPECT_EQ(0u, tracking_gl->DepthStencilAttachment());
689 EXPECT_EQ(0u, tracking_gl->DepthAttachment()); 698 EXPECT_EQ(0u, tracking_gl->DepthAttachment());
690 EXPECT_EQ(0u, tracking_gl->StencilAttachment()); 699 EXPECT_EQ(0u, tracking_gl->StencilAttachment());
691 } 700 }
692 701
693 drawing_buffer->BeginDestruction(); 702 drawing_buffer->BeginDestruction();
694 } 703 }
695 } 704 }
696 705
697 TEST_F(DrawingBufferTest, verifySetIsHiddenProperlyAffectsMailboxes) { 706 TEST_F(DrawingBufferTest, verifySetIsHiddenProperlyAffectsMailboxes) {
707 GLES2InterfaceForTests* gl_ = drawing_buffer_->ContextGLForTests();
698 cc::TextureMailbox texture_mailbox; 708 cc::TextureMailbox texture_mailbox;
699 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 709 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
700 710
701 // Produce mailboxes. 711 // Produce mailboxes.
702 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged()); 712 EXPECT_FALSE(drawing_buffer_->MarkContentsChanged());
703 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox, 713 EXPECT_TRUE(drawing_buffer_->PrepareTextureMailbox(&texture_mailbox,
704 &release_callback)); 714 &release_callback));
705 715
706 gpu::SyncToken wait_sync_token; 716 gpu::SyncToken wait_sync_token;
707 gl_->GenSyncTokenCHROMIUM(gl_->InsertFenceSyncCHROMIUM(), 717 gl_->GenSyncTokenCHROMIUM(gl_->InsertFenceSyncCHROMIUM(),
708 wait_sync_token.GetData()); 718 wait_sync_token.GetData());
709 drawing_buffer_->SetIsHidden(true); 719 drawing_buffer_->SetIsHidden(true);
710 release_callback->Run(wait_sync_token, false /* lostResource */); 720 release_callback->Run(wait_sync_token, false /* lostResource */);
711 // m_drawingBuffer deletes mailbox immediately when hidden. 721 // m_drawingBuffer deletes mailbox immediately when hidden.
712 722
713 EXPECT_EQ(wait_sync_token, gl_->MostRecentlyWaitedSyncToken()); 723 EXPECT_EQ(wait_sync_token, gl_->MostRecentlyWaitedSyncToken());
714 724
715 drawing_buffer_->BeginDestruction(); 725 drawing_buffer_->BeginDestruction();
716 } 726 }
717 727
718 } // namespace blink 728 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698