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

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

Issue 1808403002: Move simple methods [F-S] from WebGraphicsContext3D to GLES2Interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindFoo
Patch Set: simples-fplus: 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void WaitSyncTokenCHROMIUM(const GLbyte* syncToken) override 91 void WaitSyncTokenCHROMIUM(const GLbyte* syncToken) override
92 { 92 {
93 memcpy(&m_mostRecentlyWaitedSyncToken, syncToken, sizeof(m_mostRecentlyW aitedSyncToken)); 93 memcpy(&m_mostRecentlyWaitedSyncToken, syncToken, sizeof(m_mostRecentlyW aitedSyncToken));
94 } 94 }
95 95
96 GLenum CheckFramebufferStatus(GLenum target) override 96 GLenum CheckFramebufferStatus(GLenum target) override
97 { 97 {
98 return GL_FRAMEBUFFER_COMPLETE; 98 return GL_FRAMEBUFFER_COMPLETE;
99 } 99 }
100 100
101 void GetIntegerv(GLenum pname, GLint* value) override
102 {
103 if (pname == GL_MAX_TEXTURE_SIZE)
104 *value = 1024;
105 }
106
107 void GenMailboxCHROMIUM(GLbyte* mailbox) override
108 {
109 ++m_currentMailboxByte;
110 WebExternalTextureMailbox temp;
111 memset(mailbox, m_currentMailboxByte, sizeof(temp.name));
112 }
113
114 void ProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, const GLbyt e* mailbox) override
115 {
116 ASSERT_EQ(target, drawingBufferTextureTarget(m_allowImageChromium));
117 ASSERT_TRUE(m_textureSizes.contains(texture));
118 m_mostRecentlyProducedSize = m_textureSizes.get(texture);
119 }
120
101 uint32_t boundTexture() const { return m_boundTexture; } 121 uint32_t boundTexture() const { return m_boundTexture; }
102 uint32_t boundTextureTarget() const { return m_boundTextureTarget; } 122 uint32_t boundTextureTarget() const { return m_boundTextureTarget; }
103 uint32_t mostRecentlyWaitedSyncToken() const { return m_mostRecentlyWaitedSy ncToken; } 123 uint32_t mostRecentlyWaitedSyncToken() const { return m_mostRecentlyWaitedSy ncToken; }
124 IntSize mostRecentlyProducedSize() const { return m_mostRecentlyProducedSize ; }
125 bool allowImageChromium() const { return m_allowImageChromium; }
126 HashMap<WebGLId, IntSize>& textureSizes() { return m_textureSizes; }
127 const HashMap<WebGLId, IntSize>& textureSizes() const { return m_textureSize s; }
128
129 void setAllowImageChromium(bool allow) { m_allowImageChromium = allow; }
104 130
105 private: 131 private:
106 uint32_t m_boundTexture = 0; 132 uint32_t m_boundTexture = 0;
107 uint32_t m_boundTextureTarget = 0; 133 uint32_t m_boundTextureTarget = 0;
108 uint32_t m_mostRecentlyWaitedSyncToken = 0; 134 uint32_t m_mostRecentlyWaitedSyncToken = 0;
135 HashMap<WebGLId, IntSize> m_textureSizes;
136 WGC3Dbyte m_currentMailboxByte = 0;
137 IntSize m_mostRecentlyProducedSize;
138 bool m_allowImageChromium = true;
109 }; 139 };
110 140
111 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { 141 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D {
112 public: 142 public:
113 WebGraphicsContext3DForTests(PassOwnPtr<GLES2InterfaceForTests> contextGL) 143 WebGraphicsContext3DForTests(PassOwnPtr<GLES2InterfaceForTests> contextGL)
114 : m_currentMailboxByte(0) 144 : m_currentImageId(1)
115 , m_currentImageId(1)
116 , m_allowImageChromium(true)
117 , m_contextGL(std::move(contextGL)) 145 , m_contextGL(std::move(contextGL))
118 { 146 {
119 } 147 }
120 148
121 void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denu m type, const void* pixels) override 149 void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denu m type, const void* pixels) override
122 { 150 {
123 if (target == GL_TEXTURE_2D && !level) { 151 if (target == GL_TEXTURE_2D && !level) {
124 m_textureSizes.set(m_contextGL->boundTexture(), IntSize(width, heigh t)); 152 m_contextGL->textureSizes().set(m_contextGL->boundTexture(), IntSize (width, height));
125 } 153 }
126 } 154 }
127 155
128 void genMailboxCHROMIUM(WGC3Dbyte* mailbox) override
129 {
130 ++m_currentMailboxByte;
131 WebExternalTextureMailbox temp;
132 memset(mailbox, m_currentMailboxByte, sizeof(temp.name));
133 }
134
135 void produceTextureDirectCHROMIUM(WebGLId texture, WGC3Denum target, const W GC3Dbyte* mailbox) override
136 {
137 ASSERT_EQ(target, drawingBufferTextureTarget(m_allowImageChromium));
138 ASSERT_TRUE(m_textureSizes.contains(texture));
139 m_mostRecentlyProducedSize = m_textureSizes.get(texture);
140 }
141
142 IntSize mostRecentlyProducedSize()
143 {
144 return m_mostRecentlyProducedSize;
145 }
146
147 bool genSyncTokenCHROMIUM(WGC3Duint64 fenceSync, WGC3Dbyte* syncToken) overr ide 156 bool genSyncTokenCHROMIUM(WGC3Duint64 fenceSync, WGC3Dbyte* syncToken) overr ide
148 { 157 {
149 memcpy(syncToken, &fenceSync, sizeof(fenceSync)); 158 memcpy(syncToken, &fenceSync, sizeof(fenceSync));
150 return true; 159 return true;
151 } 160 }
152 161
153 WGC3Duint createGpuMemoryBufferImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei he ight, WGC3Denum internalformat, WGC3Denum usage) override 162 WGC3Duint createGpuMemoryBufferImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei he ight, WGC3Denum internalformat, WGC3Denum usage) override
154 { 163 {
155 if (!m_allowImageChromium) 164 if (!m_contextGL->allowImageChromium())
156 return false; 165 return false;
157 m_imageSizes.set(m_currentImageId, IntSize(width, height)); 166 m_imageSizes.set(m_currentImageId, IntSize(width, height));
158 return m_currentImageId++; 167 return m_currentImageId++;
159 } 168 }
160 169
161 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId)); 170 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId));
162 void destroyImageCHROMIUM(WGC3Duint imageId) 171 void destroyImageCHROMIUM(WGC3Duint imageId)
163 { 172 {
164 m_imageSizes.remove(imageId); 173 m_imageSizes.remove(imageId);
165 // No textures should be bound to this. 174 // No textures should be bound to this.
166 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end()); 175 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end());
167 m_imageSizes.remove(imageId); 176 m_imageSizes.remove(imageId);
168 destroyImageMock(imageId); 177 destroyImageMock(imageId);
169 } 178 }
170 179
171 MOCK_METHOD1(bindTexImage2DMock, void(WGC3Dint imageId)); 180 MOCK_METHOD1(bindTexImage2DMock, void(WGC3Dint imageId));
172 void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId) 181 void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId)
173 { 182 {
174 if (target == imageTextureTarget()) { 183 if (target == imageTextureTarget()) {
175 m_textureSizes.set(m_contextGL->boundTexture(), m_imageSizes.find(im ageId)->value); 184 m_contextGL->textureSizes().set(m_contextGL->boundTexture(), m_image Sizes.find(imageId)->value);
176 m_imageToTextureMap.set(imageId, m_contextGL->boundTexture()); 185 m_imageToTextureMap.set(imageId, m_contextGL->boundTexture());
177 bindTexImage2DMock(imageId); 186 bindTexImage2DMock(imageId);
178 } 187 }
179 } 188 }
180 189
181 MOCK_METHOD1(releaseTexImage2DMock, void(WGC3Dint imageId)); 190 MOCK_METHOD1(releaseTexImage2DMock, void(WGC3Dint imageId));
182 void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId) 191 void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId)
183 { 192 {
184 if (target == imageTextureTarget()) { 193 if (target == imageTextureTarget()) {
185 m_imageSizes.set(m_currentImageId, IntSize()); 194 m_imageSizes.set(m_currentImageId, IntSize());
186 m_imageToTextureMap.remove(imageId); 195 m_imageToTextureMap.remove(imageId);
187 releaseTexImage2DMock(imageId); 196 releaseTexImage2DMock(imageId);
188 } 197 }
189 } 198 }
190 199
191 WGC3Duint mostRecentlyWaitedSyncToken() 200 WGC3Duint mostRecentlyWaitedSyncToken()
192 { 201 {
193 return m_contextGL->mostRecentlyWaitedSyncToken(); 202 return m_contextGL->mostRecentlyWaitedSyncToken();
194 } 203 }
195 204
205 IntSize mostRecentlyProducedSize()
206 {
207 return m_contextGL->mostRecentlyProducedSize();
208 }
209
210
196 WGC3Duint nextImageIdToBeCreated() 211 WGC3Duint nextImageIdToBeCreated()
197 { 212 {
198 return m_currentImageId; 213 return m_currentImageId;
199 } 214 }
200 215
201 void setAllowImageChromium(bool allow)
202 {
203 m_allowImageChromium = allow;
204 }
205
206 gpu::gles2::GLES2Interface* getGLES2Interface() override 216 gpu::gles2::GLES2Interface* getGLES2Interface() override
207 { 217 {
208 return m_contextGL.get(); 218 return m_contextGL.get();
209 } 219 }
210 220
211 private: 221 private:
212 HashMap<WebGLId, IntSize> m_textureSizes;
213 WGC3Dbyte m_currentMailboxByte;
214 IntSize m_mostRecentlyProducedSize;
215 WGC3Duint m_currentImageId; 222 WGC3Duint m_currentImageId;
216 HashMap<WGC3Duint, IntSize> m_imageSizes; 223 HashMap<WGC3Duint, IntSize> m_imageSizes;
217 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap; 224 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap;
218 bool m_allowImageChromium;
219 OwnPtr<GLES2InterfaceForTests> m_contextGL; 225 OwnPtr<GLES2InterfaceForTests> m_contextGL;
220 }; 226 };
221 227
222 static const int initialWidth = 100; 228 static const int initialWidth = 100;
223 static const int initialHeight = 100; 229 static const int initialHeight = 100;
224 static const int alternateHeight = 50; 230 static const int alternateHeight = 50;
225 231
226 class DrawingBufferForTests : public DrawingBuffer { 232 class DrawingBufferForTests : public DrawingBuffer {
227 public: 233 public:
228 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<WebGraphicsContex t3D> context, gpu::gles2::GLES2Interface* gl, const IntSize& size, PreserveDrawi ngBuffer preserve) 234 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<WebGraphicsContex t3D> context, gpu::gles2::GLES2Interface* gl, const IntSize& size, PreserveDrawi ngBuffer preserve)
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 ASSERT_NOT_REACHED(); 598 ASSERT_NOT_REACHED();
593 break; 599 break;
594 } 600 }
595 } 601 }
596 602
597 GLenum CheckFramebufferStatus(GLenum target) override 603 GLenum CheckFramebufferStatus(GLenum target) override
598 { 604 {
599 return GL_FRAMEBUFFER_COMPLETE; 605 return GL_FRAMEBUFFER_COMPLETE;
600 } 606 }
601 607
608 void GetIntegerv(GLenum ptype, GLint* value) override
609 {
610 switch (ptype) {
611 case GL_DEPTH_BITS:
612 *value = (m_depthAttachment || m_depthStencilAttachment) ? 24 : 0;
613 return;
614 case GL_STENCIL_BITS:
615 *value = (m_stencilAttachment || m_depthStencilAttachment) ? 8 : 0;
616 return;
617 case GL_MAX_TEXTURE_SIZE:
618 *value = 1024;
619 return;
620 }
621 }
622
602 uint32_t stencilAttachment() const { return m_stencilAttachment; } 623 uint32_t stencilAttachment() const { return m_stencilAttachment; }
603 uint32_t depthAttachment() const { return m_depthAttachment; } 624 uint32_t depthAttachment() const { return m_depthAttachment; }
604 uint32_t depthStencilAttachment() const { return m_depthStencilAttachment; } 625 uint32_t depthStencilAttachment() const { return m_depthStencilAttachment; }
605 626
606 private: 627 private:
607 uint32_t m_depthAttachment = 0; 628 uint32_t m_depthAttachment = 0;
608 uint32_t m_stencilAttachment = 0; 629 uint32_t m_stencilAttachment = 0;
609 uint32_t m_depthStencilAttachment = 0; 630 uint32_t m_depthStencilAttachment = 0;
610 }; 631 };
611 632
(...skipping 13 matching lines...) Expand all
625 return WebString::fromUTF8("GL_OES_packed_depth_stencil"); 646 return WebString::fromUTF8("GL_OES_packed_depth_stencil");
626 } 647 }
627 return WebString(); 648 return WebString();
628 } 649 }
629 650
630 WebGLId createRenderbuffer() override 651 WebGLId createRenderbuffer() override
631 { 652 {
632 return ++m_nextRenderBufferId; 653 return ++m_nextRenderBufferId;
633 } 654 }
634 655
635 void getIntegerv(WGC3Denum ptype, WGC3Dint* value) override
636 {
637 switch (ptype) {
638 case GL_DEPTH_BITS:
639 *value = (depthAttachment() || depthStencilAttachment()) ? 24 : 0;
640 return;
641 case GL_STENCIL_BITS:
642 *value = (stencilAttachment() || depthStencilAttachment()) ? 8 : 0;
643 return;
644 }
645 MockWebGraphicsContext3D::getIntegerv(ptype, value);
646 }
647
648 gpu::gles2::GLES2Interface* getGLES2Interface() override { return &m_context GL; } 656 gpu::gles2::GLES2Interface* getGLES2Interface() override { return &m_context GL; }
649 657
650 private: 658 private:
651 WebGLId m_nextRenderBufferId; 659 WebGLId m_nextRenderBufferId;
652 DepthStencilTrackingGLES2Interface m_contextGL; 660 DepthStencilTrackingGLES2Interface m_contextGL;
653 }; 661 };
654 662
655 struct DepthStencilTestCase { 663 struct DepthStencilTestCase {
656 DepthStencilTestCase(bool requestStencil, bool requestDepth, int expectedRen derBuffers, const char* const testCaseName) 664 DepthStencilTestCase(bool requestStencil, bool requestDepth, int expectedRen derBuffers, const char* const testCaseName)
657 : requestStencil(requestStencil) 665 : requestStencil(requestStencil)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken()); 747 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken());
740 748
741 m_drawingBuffer->beginDestruction(); 749 m_drawingBuffer->beginDestruction();
742 } 750 }
743 751
744 class DrawingBufferImageChromiumFallbackTest : public DrawingBufferTest { 752 class DrawingBufferImageChromiumFallbackTest : public DrawingBufferTest {
745 protected: 753 protected:
746 void SetUp() override 754 void SetUp() override
747 { 755 {
748 OwnPtr<GLES2InterfaceForTests> gl = adoptPtr(new GLES2InterfaceForTests) ; 756 OwnPtr<GLES2InterfaceForTests> gl = adoptPtr(new GLES2InterfaceForTests) ;
757 gl->setAllowImageChromium(false);
749 m_gl = gl.get(); 758 m_gl = gl.get();
750 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests(gl.release())); 759 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests(gl.release()));
751 context->setAllowImageChromium(false);
752 m_context = context.get(); 760 m_context = context.get();
753 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); 761 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true);
754 m_drawingBuffer = DrawingBufferForTests::create(context.release(), m_gl, 762 m_drawingBuffer = DrawingBufferForTests::create(context.release(), m_gl,
755 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); 763 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve);
756 } 764 }
757 765
758 void TearDown() override 766 void TearDown() override
759 { 767 {
760 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); 768 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false);
761 } 769 }
762 }; 770 };
763 771
764 TEST_F(DrawingBufferImageChromiumFallbackTest, verifyImageChromiumFallback) 772 TEST_F(DrawingBufferImageChromiumFallbackTest, verifyImageChromiumFallback)
765 { 773 {
766 WebExternalTextureMailbox mailbox; 774 WebExternalTextureMailbox mailbox;
767 775
768 IntSize initialSize(initialWidth, initialHeight); 776 IntSize initialSize(initialWidth, initialHeight);
769 m_drawingBuffer->markContentsChanged(); 777 m_drawingBuffer->markContentsChanged();
770 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); 778 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
771 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); 779 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
772 EXPECT_FALSE(mailbox.allowOverlay); 780 EXPECT_FALSE(mailbox.allowOverlay);
773 781
774 m_drawingBuffer->mailboxReleased(mailbox, false); 782 m_drawingBuffer->mailboxReleased(mailbox, false);
775 m_drawingBuffer->beginDestruction(); 783 m_drawingBuffer->beginDestruction();
776 } 784 }
777 785
778 } // namespace blink 786 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698