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

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

Issue 1790753002: Expose GLES2Interface to blink, and delete isContextLost() from WGC3D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wgc3d: deps-for-tests Created 4 years, 9 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/graphics/gpu/DrawingBuffer.h" 31 #include "platform/graphics/gpu/DrawingBuffer.h"
32 32
33 #include "gpu/command_buffer/client/gles2_interface_stub.h"
33 #include "platform/RuntimeEnabledFeatures.h" 34 #include "platform/RuntimeEnabledFeatures.h"
34 #include "platform/graphics/ImageBuffer.h" 35 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 36 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
36 #include "platform/graphics/gpu/Extensions3DUtil.h" 37 #include "platform/graphics/gpu/Extensions3DUtil.h"
37 #include "platform/graphics/test/MockWebGraphicsContext3D.h" 38 #include "platform/graphics/test/MockWebGraphicsContext3D.h"
38 #include "public/platform/Platform.h" 39 #include "public/platform/Platform.h"
39 #include "public/platform/WebExternalTextureMailbox.h" 40 #include "public/platform/WebExternalTextureMailbox.h"
40 #include "testing/gmock/include/gmock/gmock.h" 41 #include "testing/gmock/include/gmock/gmock.h"
41 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
42 #include "wtf/RefPtr.h" 43 #include "wtf/RefPtr.h"
(...skipping 18 matching lines...) Expand all
61 // The target to use when preparing a mailbox texture. 62 // The target to use when preparing a mailbox texture.
62 WGC3Denum drawingBufferTextureTarget(bool allowImageChromium) 63 WGC3Denum drawingBufferTextureTarget(bool allowImageChromium)
63 { 64 {
64 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled() && allowImageChromiu m) 65 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled() && allowImageChromiu m)
65 return imageTextureTarget(); 66 return imageTextureTarget();
66 return GL_TEXTURE_2D; 67 return GL_TEXTURE_2D;
67 } 68 }
68 69
69 } // namespace 70 } // namespace
70 71
72 class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub {
73 };
74
71 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { 75 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D {
72 public: 76 public:
73 WebGraphicsContext3DForTests() 77 WebGraphicsContext3DForTests(PassOwnPtr<GLES2InterfaceForTests> contextGL)
74 : MockWebGraphicsContext3D() 78 : MockWebGraphicsContext3D()
75 , m_boundTexture(0) 79 , m_boundTexture(0)
76 , m_boundTextureTarget(0) 80 , m_boundTextureTarget(0)
77 , m_currentMailboxByte(0) 81 , m_currentMailboxByte(0)
78 , m_mostRecentlyWaitedSyncToken(0) 82 , m_mostRecentlyWaitedSyncToken(0)
79 , m_currentImageId(1) 83 , m_currentImageId(1)
80 , m_allowImageChromium(true) 84 , m_allowImageChromium(true)
85 , m_contextGL(std::move(contextGL))
81 { 86 {
82 } 87 }
83 88
84 void bindTexture(WGC3Denum target, WebGLId texture) override 89 void bindTexture(WGC3Denum target, WebGLId texture) override
85 { 90 {
86 if (target != m_boundTextureTarget && texture == 0) 91 if (target != m_boundTextureTarget && texture == 0)
87 return; 92 return;
88 93
89 // For simplicity, only allow one target to ever be bound. 94 // For simplicity, only allow one target to ever be bound.
90 ASSERT_TRUE(m_boundTextureTarget == 0 || target == m_boundTextureTarget) ; 95 ASSERT_TRUE(m_boundTextureTarget == 0 || target == m_boundTextureTarget) ;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 WGC3Duint nextImageIdToBeCreated() 186 WGC3Duint nextImageIdToBeCreated()
182 { 187 {
183 return m_currentImageId; 188 return m_currentImageId;
184 } 189 }
185 190
186 void setAllowImageChromium(bool allow) 191 void setAllowImageChromium(bool allow)
187 { 192 {
188 m_allowImageChromium = allow; 193 m_allowImageChromium = allow;
189 } 194 }
190 195
196 gpu::gles2::GLES2Interface* getGLES2Interface() override
197 {
198 return m_contextGL.get();
199 }
200
191 private: 201 private:
192 WebGLId m_boundTexture; 202 WebGLId m_boundTexture;
193 WGC3Denum m_boundTextureTarget; 203 WGC3Denum m_boundTextureTarget;
194 HashMap<WebGLId, IntSize> m_textureSizes; 204 HashMap<WebGLId, IntSize> m_textureSizes;
195 WGC3Dbyte m_currentMailboxByte; 205 WGC3Dbyte m_currentMailboxByte;
196 IntSize m_mostRecentlyProducedSize; 206 IntSize m_mostRecentlyProducedSize;
197 WGC3Duint m_mostRecentlyWaitedSyncToken; 207 WGC3Duint m_mostRecentlyWaitedSyncToken;
198 WGC3Duint m_currentImageId; 208 WGC3Duint m_currentImageId;
199 HashMap<WGC3Duint, IntSize> m_imageSizes; 209 HashMap<WGC3Duint, IntSize> m_imageSizes;
200 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap; 210 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap;
201 bool m_allowImageChromium; 211 bool m_allowImageChromium;
212 OwnPtr<GLES2InterfaceForTests> m_contextGL;
202 }; 213 };
203 214
204 static const int initialWidth = 100; 215 static const int initialWidth = 100;
205 static const int initialHeight = 100; 216 static const int initialHeight = 100;
206 static const int alternateHeight = 50; 217 static const int alternateHeight = 50;
207 218
208 class DrawingBufferForTests : public DrawingBuffer { 219 class DrawingBufferForTests : public DrawingBuffer {
209 public: 220 public:
210 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<WebGraphicsContex t3D> context, 221 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<WebGraphicsContex t3D> context, gpu::gles2::GLES2Interface* gl, const IntSize& size, PreserveDrawi ngBuffer preserve)
211 const IntSize& size, PreserveDrawingBuffer preserve)
212 { 222 {
213 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(conte xt.get()); 223 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(conte xt.get(), gl);
214 RefPtr<DrawingBufferForTests> drawingBuffer = 224 RefPtr<DrawingBufferForTests> drawingBuffer = adoptRef(new DrawingBuffer ForTests(context, gl, extensionsUtil.release(), preserve));
215 adoptRef(new DrawingBufferForTests(context, extensionsUtil.release() , preserve));
216 if (!drawingBuffer->initialize(size)) { 225 if (!drawingBuffer->initialize(size)) {
217 drawingBuffer->beginDestruction(); 226 drawingBuffer->beginDestruction();
218 return PassRefPtr<DrawingBufferForTests>(); 227 return PassRefPtr<DrawingBufferForTests>();
219 } 228 }
220 return drawingBuffer.release(); 229 return drawingBuffer.release();
221 } 230 }
222 231
223 DrawingBufferForTests(PassOwnPtr<WebGraphicsContext3D> context, 232 DrawingBufferForTests(PassOwnPtr<WebGraphicsContext3D> context, gpu::gles2:: GLES2Interface* gl, PassOwnPtr<Extensions3DUtil> extensionsUtil, PreserveDrawing Buffer preserve)
224 PassOwnPtr<Extensions3DUtil> extensionsUtil, 233 : DrawingBuffer(context, gl, extensionsUtil, false /* multisampleExtensi onSupported */, false /* discardFramebufferSupported */, preserve, WebGraphicsCo ntext3D::Attributes())
225 PreserveDrawingBuffer preserve)
226 : DrawingBuffer(context, extensionsUtil, false /* multisampleExtensionSu pported */, false /* discardFramebufferSupported */, preserve, WebGraphicsContex t3D::Attributes())
227 , m_live(0) 234 , m_live(0)
228 { } 235 { }
229 236
230 ~DrawingBufferForTests() override 237 ~DrawingBufferForTests() override
231 { 238 {
232 if (m_live) 239 if (m_live)
233 *m_live = false; 240 *m_live = false;
234 } 241 }
235 242
236 bool* m_live; 243 bool* m_live;
237 }; 244 };
238 245
239 class DrawingBufferTest : public Test { 246 class DrawingBufferTest : public Test {
240 protected: 247 protected:
241 void SetUp() override 248 void SetUp() override
242 { 249 {
243 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests); 250 OwnPtr<GLES2InterfaceForTests> gl = adoptPtr(new GLES2InterfaceForTests) ;
251 m_gl = gl.get();
252 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests(gl.release()));
244 m_context = context.get(); 253 m_context = context.get();
245 m_drawingBuffer = DrawingBufferForTests::create(context.release(), 254 m_drawingBuffer = DrawingBufferForTests::create(context.release(), m_gl,
246 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); 255 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve);
247 } 256 }
248 257
249 WebGraphicsContext3DForTests* webContext() 258 WebGraphicsContext3DForTests* webContext()
250 { 259 {
251 return m_context; 260 return m_context;
252 } 261 }
253 262
254 WebGraphicsContext3DForTests* m_context; 263 WebGraphicsContext3DForTests* m_context;
264 gpu::gles2::GLES2Interface* m_gl;
255 RefPtr<DrawingBufferForTests> m_drawingBuffer; 265 RefPtr<DrawingBufferForTests> m_drawingBuffer;
256 }; 266 };
257 267
258 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) 268 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes)
259 { 269 {
260 WebExternalTextureMailbox mailbox; 270 WebExternalTextureMailbox mailbox;
261 271
262 IntSize initialSize(initialWidth, initialHeight); 272 IntSize initialSize(initialWidth, initialHeight);
263 IntSize alternateSize(initialWidth, alternateHeight); 273 IntSize alternateSize(initialWidth, alternateHeight);
264 274
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 mailbox.validSyncToken = true; 469 mailbox.validSyncToken = true;
460 m_drawingBuffer->mailboxReleased(mailbox, false); 470 m_drawingBuffer->mailboxReleased(mailbox, false);
461 // m_drawingBuffer waits for the sync point because the destruction is in pr ogress. 471 // m_drawingBuffer waits for the sync point because the destruction is in pr ogress.
462 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken()); 472 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken());
463 } 473 }
464 474
465 class DrawingBufferImageChromiumTest : public DrawingBufferTest { 475 class DrawingBufferImageChromiumTest : public DrawingBufferTest {
466 protected: 476 protected:
467 void SetUp() override 477 void SetUp() override
468 { 478 {
469 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests); 479 OwnPtr<GLES2InterfaceForTests> gl = adoptPtr(new GLES2InterfaceForTests) ;
480 m_gl = gl.get();
481 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests(gl.release()));
470 m_context = context.get(); 482 m_context = context.get();
471 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); 483 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true);
472 m_imageId0 = webContext()->nextImageIdToBeCreated(); 484 m_imageId0 = webContext()->nextImageIdToBeCreated();
473 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId0)).Times(1); 485 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId0)).Times(1);
474 m_drawingBuffer = DrawingBufferForTests::create(context.release(), 486 m_drawingBuffer = DrawingBufferForTests::create(context.release(), m_gl,
475 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); 487 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve);
476 testing::Mock::VerifyAndClearExpectations(webContext()); 488 testing::Mock::VerifyAndClearExpectations(webContext());
477 } 489 }
478 490
479 void TearDown() override 491 void TearDown() override
480 { 492 {
481 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); 493 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false);
482 } 494 }
483 WGC3Duint m_imageId0; 495 WGC3Duint m_imageId0;
484 }; 496 };
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 case GL_DEPTH_BITS: 618 case GL_DEPTH_BITS:
607 *value = (m_depthAttachment || m_depthStencilAttachment) ? 24 : 0; 619 *value = (m_depthAttachment || m_depthStencilAttachment) ? 24 : 0;
608 return; 620 return;
609 case GL_STENCIL_BITS: 621 case GL_STENCIL_BITS:
610 *value = (m_stencilAttachment || m_depthStencilAttachment) ? 8 : 0; 622 *value = (m_stencilAttachment || m_depthStencilAttachment) ? 8 : 0;
611 return; 623 return;
612 } 624 }
613 MockWebGraphicsContext3D::getIntegerv(ptype, value); 625 MockWebGraphicsContext3D::getIntegerv(ptype, value);
614 } 626 }
615 627
628 gpu::gles2::GLES2Interface* getGLES2Interface() override { return &m_context GL; }
629
616 private: 630 private:
617 WebGLId m_nextRenderBufferId; 631 WebGLId m_nextRenderBufferId;
618 WebGLId m_stencilAttachment; 632 WebGLId m_stencilAttachment;
619 WebGLId m_depthAttachment; 633 WebGLId m_depthAttachment;
620 WebGLId m_depthStencilAttachment; 634 WebGLId m_depthStencilAttachment;
635 gpu::gles2::GLES2InterfaceStub m_contextGL;
621 }; 636 };
622 637
623 struct DepthStencilTestCase { 638 struct DepthStencilTestCase {
624 DepthStencilTestCase(bool requestStencil, bool requestDepth, int expectedRen derBuffers, const char* const testCaseName) 639 DepthStencilTestCase(bool requestStencil, bool requestDepth, int expectedRen derBuffers, const char* const testCaseName)
625 : requestStencil(requestStencil) 640 : requestStencil(requestStencil)
626 , requestDepth(requestDepth) 641 , requestDepth(requestDepth)
627 , expectedRenderBuffers(expectedRenderBuffers) 642 , expectedRenderBuffers(expectedRenderBuffers)
628 , testCaseName(testCaseName) { } 643 , testCaseName(testCaseName) { }
629 644
630 bool requestStencil; 645 bool requestStencil;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 memcpy(&waitSyncToken, mailbox.syncToken, sizeof(waitSyncToken)); 721 memcpy(&waitSyncToken, mailbox.syncToken, sizeof(waitSyncToken));
707 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken()); 722 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken());
708 723
709 m_drawingBuffer->beginDestruction(); 724 m_drawingBuffer->beginDestruction();
710 } 725 }
711 726
712 class DrawingBufferImageChromiumFallbackTest : public DrawingBufferTest { 727 class DrawingBufferImageChromiumFallbackTest : public DrawingBufferTest {
713 protected: 728 protected:
714 void SetUp() override 729 void SetUp() override
715 { 730 {
716 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests); 731 OwnPtr<GLES2InterfaceForTests> gl = adoptPtr(new GLES2InterfaceForTests) ;
732 m_gl = gl.get();
733 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests(gl.release()));
717 context->setAllowImageChromium(false); 734 context->setAllowImageChromium(false);
718 m_context = context.get(); 735 m_context = context.get();
719 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); 736 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true);
720 m_drawingBuffer = DrawingBufferForTests::create(context.release(), 737 m_drawingBuffer = DrawingBufferForTests::create(context.release(), m_gl,
721 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); 738 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve);
722 } 739 }
723 740
724 void TearDown() override 741 void TearDown() override
725 { 742 {
726 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); 743 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false);
727 } 744 }
728 }; 745 };
729 746
730 TEST_F(DrawingBufferImageChromiumFallbackTest, verifyImageChromiumFallback) 747 TEST_F(DrawingBufferImageChromiumFallbackTest, verifyImageChromiumFallback)
731 { 748 {
732 WebExternalTextureMailbox mailbox; 749 WebExternalTextureMailbox mailbox;
733 750
734 IntSize initialSize(initialWidth, initialHeight); 751 IntSize initialSize(initialWidth, initialHeight);
735 m_drawingBuffer->markContentsChanged(); 752 m_drawingBuffer->markContentsChanged();
736 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); 753 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
737 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); 754 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
738 EXPECT_FALSE(mailbox.allowOverlay); 755 EXPECT_FALSE(mailbox.allowOverlay);
739 756
740 m_drawingBuffer->mailboxReleased(mailbox, false); 757 m_drawingBuffer->mailboxReleased(mailbox, false);
741 m_drawingBuffer->beginDestruction(); 758 m_drawingBuffer->beginDestruction();
742 } 759 }
743 760
744 } // namespace blink 761 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698