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

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

Issue 1807103002: Move simple methods [A-E] from WebGraphicsContext3D to GLES2Interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@work
Patch Set: bindFoo: ALLthetests 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 WGC3Denum drawingBufferTextureTarget(bool allowImageChromium) 63 WGC3Denum drawingBufferTextureTarget(bool allowImageChromium)
64 { 64 {
65 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled() && allowImageChromiu m) 65 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled() && allowImageChromiu m)
66 return imageTextureTarget(); 66 return imageTextureTarget();
67 return GL_TEXTURE_2D; 67 return GL_TEXTURE_2D;
68 } 68 }
69 69
70 } // namespace 70 } // namespace
71 71
72 class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub { 72 class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub {
73 };
74
75 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D {
76 public: 73 public:
77 WebGraphicsContext3DForTests(PassOwnPtr<GLES2InterfaceForTests> contextGL) 74 void BindTexture(GLenum target, GLuint texture) override
78 : MockWebGraphicsContext3D()
79 , m_boundTexture(0)
80 , m_boundTextureTarget(0)
81 , m_currentMailboxByte(0)
82 , m_mostRecentlyWaitedSyncToken(0)
83 , m_currentImageId(1)
84 , m_allowImageChromium(true)
85 , m_contextGL(std::move(contextGL))
86 {
87 }
88
89 void bindTexture(WGC3Denum target, WebGLId texture) override
90 { 75 {
91 if (target != m_boundTextureTarget && texture == 0) 76 if (target != m_boundTextureTarget && texture == 0)
92 return; 77 return;
93 78
94 // For simplicity, only allow one target to ever be bound. 79 // For simplicity, only allow one target to ever be bound.
95 ASSERT_TRUE(m_boundTextureTarget == 0 || target == m_boundTextureTarget) ; 80 ASSERT_TRUE(m_boundTextureTarget == 0 || target == m_boundTextureTarget) ;
96 m_boundTextureTarget = target; 81 m_boundTextureTarget = target;
97 m_boundTexture = texture; 82 m_boundTexture = texture;
98 } 83 }
99 84
85 GLuint64 InsertFenceSyncCHROMIUM() override
86 {
87 static WGC3Duint64 syncPointGenerator = 0;
88 return ++syncPointGenerator;
89 }
90
91 void WaitSyncTokenCHROMIUM(const GLbyte* syncToken) override
92 {
93 memcpy(&m_mostRecentlyWaitedSyncToken, syncToken, sizeof(m_mostRecentlyW aitedSyncToken));
94 }
95
96 GLenum CheckFramebufferStatus(GLenum target) override
97 {
98 return GL_FRAMEBUFFER_COMPLETE;
99 }
100
101 uint32_t boundTexture() const { return m_boundTexture; }
102 uint32_t boundTextureTarget() const { return m_boundTextureTarget; }
103 uint32_t mostRecentlyWaitedSyncToken() const { return m_mostRecentlyWaitedSy ncToken; }
104
105 private:
106 uint32_t m_boundTexture = 0;
107 uint32_t m_boundTextureTarget = 0;
108 uint32_t m_mostRecentlyWaitedSyncToken = 0;
109 };
110
111 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D {
112 public:
113 WebGraphicsContext3DForTests(PassOwnPtr<GLES2InterfaceForTests> contextGL)
114 : m_currentMailboxByte(0)
115 , m_currentImageId(1)
116 , m_allowImageChromium(true)
117 , m_contextGL(std::move(contextGL))
118 {
119 }
120
100 void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denu m type, const void* pixels) override 121 void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denu m type, const void* pixels) override
101 { 122 {
102 if (target == GL_TEXTURE_2D && !level) { 123 if (target == GL_TEXTURE_2D && !level) {
103 m_textureSizes.set(m_boundTexture, IntSize(width, height)); 124 m_textureSizes.set(m_contextGL->boundTexture(), IntSize(width, heigh t));
104 } 125 }
105 } 126 }
106 127
107 void genMailboxCHROMIUM(WGC3Dbyte* mailbox) override 128 void genMailboxCHROMIUM(WGC3Dbyte* mailbox) override
108 { 129 {
109 ++m_currentMailboxByte; 130 ++m_currentMailboxByte;
110 WebExternalTextureMailbox temp; 131 WebExternalTextureMailbox temp;
111 memset(mailbox, m_currentMailboxByte, sizeof(temp.name)); 132 memset(mailbox, m_currentMailboxByte, sizeof(temp.name));
112 } 133 }
113 134
114 void produceTextureDirectCHROMIUM(WebGLId texture, WGC3Denum target, const W GC3Dbyte* mailbox) override 135 void produceTextureDirectCHROMIUM(WebGLId texture, WGC3Denum target, const W GC3Dbyte* mailbox) override
115 { 136 {
116 ASSERT_EQ(target, drawingBufferTextureTarget(m_allowImageChromium)); 137 ASSERT_EQ(target, drawingBufferTextureTarget(m_allowImageChromium));
117 ASSERT_TRUE(m_textureSizes.contains(texture)); 138 ASSERT_TRUE(m_textureSizes.contains(texture));
118 m_mostRecentlyProducedSize = m_textureSizes.get(texture); 139 m_mostRecentlyProducedSize = m_textureSizes.get(texture);
119 } 140 }
120 141
121 IntSize mostRecentlyProducedSize() 142 IntSize mostRecentlyProducedSize()
122 { 143 {
123 return m_mostRecentlyProducedSize; 144 return m_mostRecentlyProducedSize;
124 } 145 }
125 146
126 WGC3Duint64 insertFenceSyncCHROMIUM() override
127 {
128 static WGC3Duint64 syncPointGenerator = 0;
129 return ++syncPointGenerator;
130 }
131
132 bool genSyncTokenCHROMIUM(WGC3Duint64 fenceSync, WGC3Dbyte* syncToken) overr ide 147 bool genSyncTokenCHROMIUM(WGC3Duint64 fenceSync, WGC3Dbyte* syncToken) overr ide
133 { 148 {
134 memcpy(syncToken, &fenceSync, sizeof(fenceSync)); 149 memcpy(syncToken, &fenceSync, sizeof(fenceSync));
135 return true; 150 return true;
136 } 151 }
137 152
138 void waitSyncTokenCHROMIUM(const WGC3Dbyte* syncToken) override
139 {
140 memcpy(&m_mostRecentlyWaitedSyncToken, syncToken, sizeof(m_mostRecentlyW aitedSyncToken));
141 }
142
143 WGC3Duint createGpuMemoryBufferImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei he ight, WGC3Denum internalformat, WGC3Denum usage) override 153 WGC3Duint createGpuMemoryBufferImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei he ight, WGC3Denum internalformat, WGC3Denum usage) override
144 { 154 {
145 if (!m_allowImageChromium) 155 if (!m_allowImageChromium)
146 return false; 156 return false;
147 m_imageSizes.set(m_currentImageId, IntSize(width, height)); 157 m_imageSizes.set(m_currentImageId, IntSize(width, height));
148 return m_currentImageId++; 158 return m_currentImageId++;
149 } 159 }
150 160
151 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId)); 161 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId));
152 void destroyImageCHROMIUM(WGC3Duint imageId) 162 void destroyImageCHROMIUM(WGC3Duint imageId)
153 { 163 {
154 m_imageSizes.remove(imageId); 164 m_imageSizes.remove(imageId);
155 // No textures should be bound to this. 165 // No textures should be bound to this.
156 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end()); 166 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end());
157 m_imageSizes.remove(imageId); 167 m_imageSizes.remove(imageId);
158 destroyImageMock(imageId); 168 destroyImageMock(imageId);
159 } 169 }
160 170
161 MOCK_METHOD1(bindTexImage2DMock, void(WGC3Dint imageId)); 171 MOCK_METHOD1(bindTexImage2DMock, void(WGC3Dint imageId));
162 void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId) 172 void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId)
163 { 173 {
164 if (target == imageTextureTarget()) { 174 if (target == imageTextureTarget()) {
165 m_textureSizes.set(m_boundTexture, m_imageSizes.find(imageId)->value ); 175 m_textureSizes.set(m_contextGL->boundTexture(), m_imageSizes.find(im ageId)->value);
166 m_imageToTextureMap.set(imageId, m_boundTexture); 176 m_imageToTextureMap.set(imageId, m_contextGL->boundTexture());
167 bindTexImage2DMock(imageId); 177 bindTexImage2DMock(imageId);
168 } 178 }
169 } 179 }
170 180
171 MOCK_METHOD1(releaseTexImage2DMock, void(WGC3Dint imageId)); 181 MOCK_METHOD1(releaseTexImage2DMock, void(WGC3Dint imageId));
172 void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId) 182 void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId)
173 { 183 {
174 if (target == imageTextureTarget()) { 184 if (target == imageTextureTarget()) {
175 m_imageSizes.set(m_currentImageId, IntSize()); 185 m_imageSizes.set(m_currentImageId, IntSize());
176 m_imageToTextureMap.remove(imageId); 186 m_imageToTextureMap.remove(imageId);
177 releaseTexImage2DMock(imageId); 187 releaseTexImage2DMock(imageId);
178 } 188 }
179 } 189 }
180 190
181 WGC3Duint mostRecentlyWaitedSyncToken() 191 WGC3Duint mostRecentlyWaitedSyncToken()
182 { 192 {
183 return m_mostRecentlyWaitedSyncToken; 193 return m_contextGL->mostRecentlyWaitedSyncToken();
184 } 194 }
185 195
186 WGC3Duint nextImageIdToBeCreated() 196 WGC3Duint nextImageIdToBeCreated()
187 { 197 {
188 return m_currentImageId; 198 return m_currentImageId;
189 } 199 }
190 200
191 void setAllowImageChromium(bool allow) 201 void setAllowImageChromium(bool allow)
192 { 202 {
193 m_allowImageChromium = allow; 203 m_allowImageChromium = allow;
194 } 204 }
195 205
196 gpu::gles2::GLES2Interface* getGLES2Interface() override 206 gpu::gles2::GLES2Interface* getGLES2Interface() override
197 { 207 {
198 return m_contextGL.get(); 208 return m_contextGL.get();
199 } 209 }
200 210
201 private: 211 private:
202 WebGLId m_boundTexture;
203 WGC3Denum m_boundTextureTarget;
204 HashMap<WebGLId, IntSize> m_textureSizes; 212 HashMap<WebGLId, IntSize> m_textureSizes;
205 WGC3Dbyte m_currentMailboxByte; 213 WGC3Dbyte m_currentMailboxByte;
206 IntSize m_mostRecentlyProducedSize; 214 IntSize m_mostRecentlyProducedSize;
207 WGC3Duint m_mostRecentlyWaitedSyncToken;
208 WGC3Duint m_currentImageId; 215 WGC3Duint m_currentImageId;
209 HashMap<WGC3Duint, IntSize> m_imageSizes; 216 HashMap<WGC3Duint, IntSize> m_imageSizes;
210 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap; 217 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap;
211 bool m_allowImageChromium; 218 bool m_allowImageChromium;
212 OwnPtr<GLES2InterfaceForTests> m_contextGL; 219 OwnPtr<GLES2InterfaceForTests> m_contextGL;
213 }; 220 };
214 221
215 static const int initialWidth = 100; 222 static const int initialWidth = 100;
216 static const int initialHeight = 100; 223 static const int initialHeight = 100;
217 static const int alternateHeight = 50; 224 static const int alternateHeight = 50;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 WebExternalTextureMailbox mailbox; 451 WebExternalTextureMailbox mailbox;
445 452
446 // Produce mailboxes. 453 // Produce mailboxes.
447 m_drawingBuffer->markContentsChanged(); 454 m_drawingBuffer->markContentsChanged();
448 EXPECT_EQ(0u, webContext()->mostRecentlyWaitedSyncToken()); 455 EXPECT_EQ(0u, webContext()->mostRecentlyWaitedSyncToken());
449 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); 456 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
450 // prepareMailbox() does not wait for any sync point. 457 // prepareMailbox() does not wait for any sync point.
451 EXPECT_EQ(0u, webContext()->mostRecentlyWaitedSyncToken()); 458 EXPECT_EQ(0u, webContext()->mostRecentlyWaitedSyncToken());
452 459
453 WGC3Duint64 waitSyncToken = 0; 460 WGC3Duint64 waitSyncToken = 0;
454 webContext()->genSyncTokenCHROMIUM(webContext()->insertFenceSyncCHROMIUM(), reinterpret_cast<WGC3Dbyte*>(&waitSyncToken)); 461 webContext()->genSyncTokenCHROMIUM(m_gl->InsertFenceSyncCHROMIUM(), reinterp ret_cast<WGC3Dbyte*>(&waitSyncToken));
455 memcpy(mailbox.syncToken, &waitSyncToken, sizeof(waitSyncToken)); 462 memcpy(mailbox.syncToken, &waitSyncToken, sizeof(waitSyncToken));
456 mailbox.validSyncToken = true; 463 mailbox.validSyncToken = true;
457 m_drawingBuffer->mailboxReleased(mailbox, false); 464 m_drawingBuffer->mailboxReleased(mailbox, false);
458 // m_drawingBuffer will wait for the sync point when recycling. 465 // m_drawingBuffer will wait for the sync point when recycling.
459 EXPECT_EQ(0u, webContext()->mostRecentlyWaitedSyncToken()); 466 EXPECT_EQ(0u, webContext()->mostRecentlyWaitedSyncToken());
460 467
461 m_drawingBuffer->markContentsChanged(); 468 m_drawingBuffer->markContentsChanged();
462 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); 469 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
463 // m_drawingBuffer waits for the sync point when recycling in prepareMailbox (). 470 // m_drawingBuffer waits for the sync point when recycling in prepareMailbox ().
464 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken()); 471 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken());
465 472
466 m_drawingBuffer->beginDestruction(); 473 m_drawingBuffer->beginDestruction();
467 webContext()->genSyncTokenCHROMIUM(webContext()->insertFenceSyncCHROMIUM(), reinterpret_cast<WGC3Dbyte*>(&waitSyncToken)); 474 webContext()->genSyncTokenCHROMIUM(m_gl->InsertFenceSyncCHROMIUM(), reinterp ret_cast<WGC3Dbyte*>(&waitSyncToken));
468 memcpy(mailbox.syncToken, &waitSyncToken, sizeof(waitSyncToken)); 475 memcpy(mailbox.syncToken, &waitSyncToken, sizeof(waitSyncToken));
469 mailbox.validSyncToken = true; 476 mailbox.validSyncToken = true;
470 m_drawingBuffer->mailboxReleased(mailbox, false); 477 m_drawingBuffer->mailboxReleased(mailbox, false);
471 // m_drawingBuffer waits for the sync point because the destruction is in pr ogress. 478 // m_drawingBuffer waits for the sync point because the destruction is in pr ogress.
472 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken()); 479 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken());
473 } 480 }
474 481
475 class DrawingBufferImageChromiumTest : public DrawingBufferTest { 482 class DrawingBufferImageChromiumTest : public DrawingBufferTest {
476 protected: 483 protected:
477 void SetUp() override 484 void SetUp() override
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 break; 587 break;
581 case GL_DEPTH_STENCIL_ATTACHMENT: 588 case GL_DEPTH_STENCIL_ATTACHMENT:
582 m_depthStencilAttachment = renderbuffer; 589 m_depthStencilAttachment = renderbuffer;
583 break; 590 break;
584 default: 591 default:
585 ASSERT_NOT_REACHED(); 592 ASSERT_NOT_REACHED();
586 break; 593 break;
587 } 594 }
588 } 595 }
589 596
597 GLenum CheckFramebufferStatus(GLenum target) override
598 {
599 return GL_FRAMEBUFFER_COMPLETE;
600 }
601
590 uint32_t stencilAttachment() const { return m_stencilAttachment; } 602 uint32_t stencilAttachment() const { return m_stencilAttachment; }
591 uint32_t depthAttachment() const { return m_depthAttachment; } 603 uint32_t depthAttachment() const { return m_depthAttachment; }
592 uint32_t depthStencilAttachment() const { return m_depthStencilAttachment; } 604 uint32_t depthStencilAttachment() const { return m_depthStencilAttachment; }
593 605
594 private: 606 private:
595 uint32_t m_depthAttachment = 0; 607 uint32_t m_depthAttachment = 0;
596 uint32_t m_stencilAttachment = 0; 608 uint32_t m_stencilAttachment = 0;
597 uint32_t m_depthStencilAttachment = 0; 609 uint32_t m_depthStencilAttachment = 0;
598 }; 610 };
599 611
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 } 722 }
711 723
712 TEST_F(DrawingBufferTest, verifySetIsHiddenProperlyAffectsMailboxes) 724 TEST_F(DrawingBufferTest, verifySetIsHiddenProperlyAffectsMailboxes)
713 { 725 {
714 blink::WebExternalTextureMailbox mailbox; 726 blink::WebExternalTextureMailbox mailbox;
715 727
716 // Produce mailboxes. 728 // Produce mailboxes.
717 m_drawingBuffer->markContentsChanged(); 729 m_drawingBuffer->markContentsChanged();
718 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); 730 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
719 731
720 mailbox.validSyncToken = webContext()->genSyncTokenCHROMIUM(webContext()->in sertFenceSyncCHROMIUM(), mailbox.syncToken); 732 mailbox.validSyncToken = webContext()->genSyncTokenCHROMIUM(m_gl->InsertFenc eSyncCHROMIUM(), mailbox.syncToken);
721 m_drawingBuffer->setIsHidden(true); 733 m_drawingBuffer->setIsHidden(true);
722 m_drawingBuffer->mailboxReleased(mailbox); 734 m_drawingBuffer->mailboxReleased(mailbox);
723 // m_drawingBuffer deletes mailbox immediately when hidden. 735 // m_drawingBuffer deletes mailbox immediately when hidden.
724 736
725 WGC3Duint waitSyncToken = 0; 737 WGC3Duint waitSyncToken = 0;
726 memcpy(&waitSyncToken, mailbox.syncToken, sizeof(waitSyncToken)); 738 memcpy(&waitSyncToken, mailbox.syncToken, sizeof(waitSyncToken));
727 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken()); 739 EXPECT_EQ(waitSyncToken, webContext()->mostRecentlyWaitedSyncToken());
728 740
729 m_drawingBuffer->beginDestruction(); 741 m_drawingBuffer->beginDestruction();
730 } 742 }
(...skipping 26 matching lines...) Expand all
757 m_drawingBuffer->markContentsChanged(); 769 m_drawingBuffer->markContentsChanged();
758 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); 770 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
759 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); 771 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
760 EXPECT_FALSE(mailbox.allowOverlay); 772 EXPECT_FALSE(mailbox.allowOverlay);
761 773
762 m_drawingBuffer->mailboxReleased(mailbox, false); 774 m_drawingBuffer->mailboxReleased(mailbox, false);
763 m_drawingBuffer->beginDestruction(); 775 m_drawingBuffer->beginDestruction();
764 } 776 }
765 777
766 } // namespace blink 778 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698