OLD | NEW |
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 15 matching lines...) Expand all Loading... |
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 "cc/resources/single_release_callback.h" | 33 #include "cc/resources/single_release_callback.h" |
34 #include "cc/resources/texture_mailbox.h" | 34 #include "cc/resources/texture_mailbox.h" |
35 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 35 #include "gpu/command_buffer/client/gles2_interface_stub.h" |
36 #include "gpu/command_buffer/common/capabilities.h" | |
37 #include "gpu/command_buffer/common/mailbox.h" | 36 #include "gpu/command_buffer/common/mailbox.h" |
38 #include "gpu/command_buffer/common/sync_token.h" | 37 #include "gpu/command_buffer/common/sync_token.h" |
39 #include "platform/RuntimeEnabledFeatures.h" | |
40 #include "platform/graphics/ImageBuffer.h" | 38 #include "platform/graphics/ImageBuffer.h" |
41 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 39 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
42 #include "platform/graphics/gpu/Extensions3DUtil.h" | 40 #include "platform/graphics/gpu/DrawingBufferTestHelpers.h" |
43 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
44 #include "public/platform/WebGraphicsContext3DProvider.h" | |
45 #include "public/platform/functional/WebFunction.h" | 42 #include "public/platform/functional/WebFunction.h" |
46 #include "testing/gmock/include/gmock/gmock.h" | |
47 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "wtf/PtrUtil.h" | 44 #include "wtf/PtrUtil.h" |
49 #include "wtf/RefPtr.h" | 45 #include "wtf/RefPtr.h" |
50 #include <memory> | 46 #include <memory> |
51 | 47 |
52 using testing::Test; | 48 using testing::Test; |
53 using testing::_; | 49 using testing::_; |
54 | 50 |
55 namespace blink { | 51 namespace blink { |
56 | 52 |
57 namespace { | |
58 | |
59 // The target to use when binding a texture to a Chromium image. | |
60 GLenum imageCHROMIUMTextureTarget() | |
61 { | |
62 #if OS(MACOSX) | |
63 return GC3D_TEXTURE_RECTANGLE_ARB; | |
64 #else | |
65 return GL_TEXTURE_2D; | |
66 #endif | |
67 } | |
68 | |
69 // The target to use when preparing a mailbox texture. | |
70 GLenum drawingBufferTextureTarget() | |
71 { | |
72 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) | |
73 return imageCHROMIUMTextureTarget(); | |
74 return GL_TEXTURE_2D; | |
75 } | |
76 | |
77 } // namespace | |
78 | |
79 class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub { | |
80 public: | |
81 void BindTexture(GLenum target, GLuint texture) override | |
82 { | |
83 if (target != m_boundTextureTarget && texture == 0) | |
84 return; | |
85 | |
86 // For simplicity, only allow one target to ever be bound. | |
87 ASSERT_TRUE(m_boundTextureTarget == 0 || target == m_boundTextureTarget)
; | |
88 m_boundTextureTarget = target; | |
89 m_boundTexture = texture; | |
90 } | |
91 | |
92 GLuint64 InsertFenceSyncCHROMIUM() override | |
93 { | |
94 static GLuint64 syncPointGenerator = 0; | |
95 return ++syncPointGenerator; | |
96 } | |
97 | |
98 void WaitSyncTokenCHROMIUM(const GLbyte* syncToken) override | |
99 { | |
100 memcpy(&m_mostRecentlyWaitedSyncToken, syncToken, sizeof(m_mostRecentlyW
aitedSyncToken)); | |
101 } | |
102 | |
103 GLenum CheckFramebufferStatus(GLenum target) override | |
104 { | |
105 return GL_FRAMEBUFFER_COMPLETE; | |
106 } | |
107 | |
108 void GetIntegerv(GLenum pname, GLint* value) override | |
109 { | |
110 if (pname == GL_MAX_TEXTURE_SIZE) | |
111 *value = 1024; | |
112 } | |
113 | |
114 void GenMailboxCHROMIUM(GLbyte* mailbox) override | |
115 { | |
116 ++m_currentMailboxByte; | |
117 memset(mailbox, m_currentMailboxByte, GL_MAILBOX_SIZE_CHROMIUM); | |
118 } | |
119 | |
120 void ProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, const GLbyt
e* mailbox) override | |
121 { | |
122 ASSERT_EQ(target, drawingBufferTextureTarget()); | |
123 | |
124 if (!m_createImageChromiumFail) { | |
125 ASSERT_TRUE(m_textureSizes.contains(texture)); | |
126 m_mostRecentlyProducedSize = m_textureSizes.get(texture); | |
127 } | |
128 } | |
129 | |
130 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei wi
dth, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixel
s) override | |
131 { | |
132 if (target == GL_TEXTURE_2D && !level) { | |
133 m_textureSizes.set(m_boundTexture, IntSize(width, height)); | |
134 } | |
135 } | |
136 | |
137 GLuint CreateGpuMemoryBufferImageCHROMIUM(GLsizei width, GLsizei height, GLe
num internalformat, GLenum usage) override | |
138 { | |
139 if (m_createImageChromiumFail) | |
140 return 0; | |
141 m_imageSizes.set(m_currentImageId, IntSize(width, height)); | |
142 return m_currentImageId++; | |
143 } | |
144 | |
145 MOCK_METHOD1(DestroyImageMock, void(GLuint imageId)); | |
146 void DestroyImageCHROMIUM(GLuint imageId) | |
147 { | |
148 m_imageSizes.remove(imageId); | |
149 // No textures should be bound to this. | |
150 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end()); | |
151 m_imageSizes.remove(imageId); | |
152 DestroyImageMock(imageId); | |
153 } | |
154 | |
155 MOCK_METHOD1(BindTexImage2DMock, void(GLint imageId)); | |
156 void BindTexImage2DCHROMIUM(GLenum target, GLint imageId) | |
157 { | |
158 if (target == imageCHROMIUMTextureTarget()) { | |
159 m_textureSizes.set(m_boundTexture, m_imageSizes.find(imageId)->value
); | |
160 m_imageToTextureMap.set(imageId, m_boundTexture); | |
161 BindTexImage2DMock(imageId); | |
162 } | |
163 } | |
164 | |
165 MOCK_METHOD1(ReleaseTexImage2DMock, void(GLint imageId)); | |
166 void ReleaseTexImage2DCHROMIUM(GLenum target, GLint imageId) | |
167 { | |
168 if (target == imageCHROMIUMTextureTarget()) { | |
169 m_imageSizes.set(m_currentImageId, IntSize()); | |
170 m_imageToTextureMap.remove(imageId); | |
171 ReleaseTexImage2DMock(imageId); | |
172 } | |
173 } | |
174 | |
175 void GenSyncTokenCHROMIUM(GLuint64 fenceSync, GLbyte* syncToken) override | |
176 { | |
177 static uint64_t uniqueId = 1; | |
178 gpu::SyncToken source(gpu::GPU_IO, 1, gpu::CommandBufferId::FromUnsafeVa
lue(uniqueId++), 2); | |
179 memcpy(syncToken, &source, sizeof(source)); | |
180 } | |
181 | |
182 void GenTextures(GLsizei n, GLuint* textures) override | |
183 { | |
184 static GLuint id = 1; | |
185 for (GLsizei i = 0; i < n; ++i) | |
186 textures[i] = id++; | |
187 } | |
188 | |
189 GLuint boundTexture() const { return m_boundTexture; } | |
190 GLuint boundTextureTarget() const { return m_boundTextureTarget; } | |
191 gpu::SyncToken mostRecentlyWaitedSyncToken() const { return m_mostRecentlyWa
itedSyncToken; } | |
192 GLuint nextImageIdToBeCreated() const { return m_currentImageId; } | |
193 IntSize mostRecentlyProducedSize() const { return m_mostRecentlyProducedSize
; } | |
194 | |
195 void setCreateImageChromiumFail(bool fail) { m_createImageChromiumFail = fai
l; } | |
196 | |
197 private: | |
198 GLuint m_boundTexture = 0; | |
199 GLuint m_boundTextureTarget = 0; | |
200 gpu::SyncToken m_mostRecentlyWaitedSyncToken; | |
201 GLbyte m_currentMailboxByte = 0; | |
202 IntSize m_mostRecentlyProducedSize; | |
203 bool m_createImageChromiumFail = false; | |
204 GLuint m_currentImageId = 1; | |
205 HashMap<GLuint, IntSize> m_textureSizes; | |
206 HashMap<GLuint, IntSize> m_imageSizes; | |
207 HashMap<GLuint, GLuint> m_imageToTextureMap; | |
208 }; | |
209 | |
210 static const int initialWidth = 100; | |
211 static const int initialHeight = 100; | |
212 static const int alternateHeight = 50; | |
213 | |
214 class DrawingBufferForTests : public DrawingBuffer { | |
215 public: | |
216 static PassRefPtr<DrawingBufferForTests> create(std::unique_ptr<WebGraphicsC
ontext3DProvider> contextProvider, const IntSize& size, PreserveDrawingBuffer pr
eserve) | |
217 { | |
218 std::unique_ptr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::cre
ate(contextProvider->contextGL()); | |
219 RefPtr<DrawingBufferForTests> drawingBuffer = adoptRef(new DrawingBuffer
ForTests(std::move(contextProvider), std::move(extensionsUtil), preserve)); | |
220 bool multisampleExtensionSupported = false; | |
221 if (!drawingBuffer->initialize(size, multisampleExtensionSupported)) { | |
222 drawingBuffer->beginDestruction(); | |
223 return nullptr; | |
224 } | |
225 return drawingBuffer.release(); | |
226 } | |
227 | |
228 DrawingBufferForTests(std::unique_ptr<WebGraphicsContext3DProvider> contextP
rovider, std::unique_ptr<Extensions3DUtil> extensionsUtil, PreserveDrawingBuffer
preserve) | |
229 : DrawingBuffer(std::move(contextProvider), std::move(extensionsUtil), f
alse /* discardFramebufferSupported */, | |
230 true /* wantAlphaChannel */, false /* premultipliedAlpha */, preserv
e, WebGL1, | |
231 false /* wantDepth */, false /* wantStencil */) | |
232 , m_live(0) | |
233 { } | |
234 | |
235 ~DrawingBufferForTests() override | |
236 { | |
237 if (m_live) | |
238 *m_live = false; | |
239 } | |
240 | |
241 bool* m_live; | |
242 }; | |
243 | |
244 class WebGraphicsContext3DProviderForTests : public WebGraphicsContext3DProvider
{ | |
245 public: | |
246 WebGraphicsContext3DProviderForTests(std::unique_ptr<gpu::gles2::GLES2Interf
ace> gl) | |
247 : m_gl(std::move(gl)) | |
248 { | |
249 } | |
250 | |
251 gpu::gles2::GLES2Interface* contextGL() override { return m_gl.get(); } | |
252 bool isSoftwareRendering() const override { return false; } | |
253 | |
254 // Not used by WebGL code. | |
255 GrContext* grContext() override { return nullptr; } | |
256 bool bindToCurrentThread() override { return false; } | |
257 gpu::Capabilities getCapabilities() override { return gpu::Capabilities(); } | |
258 void setLostContextCallback(WebClosure) {} | |
259 void setErrorMessageCallback(WebFunction<void(const char*, int32_t id)>) {} | |
260 | |
261 private: | |
262 std::unique_ptr<gpu::gles2::GLES2Interface> m_gl; | |
263 }; | |
264 | |
265 class DrawingBufferTest : public Test { | 53 class DrawingBufferTest : public Test { |
266 protected: | 54 protected: |
267 void SetUp() override | 55 void SetUp() override |
268 { | 56 { |
| 57 IntSize initialSize(InitialWidth, InitialHeight); |
269 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa
ceForTests); | 58 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa
ceForTests); |
270 m_gl = gl.get(); | 59 m_gl = gl.get(); |
271 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni
que(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 60 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni
que(new WebGraphicsContext3DProviderForTests(std::move(gl))); |
272 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), Int
Size(initialWidth, initialHeight), DrawingBuffer::Preserve); | 61 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), ini
tialSize, DrawingBuffer::Preserve); |
273 CHECK(m_drawingBuffer); | 62 CHECK(m_drawingBuffer); |
274 } | 63 } |
275 | 64 |
276 GLES2InterfaceForTests* m_gl; | 65 GLES2InterfaceForTests* m_gl; |
277 RefPtr<DrawingBufferForTests> m_drawingBuffer; | 66 RefPtr<DrawingBufferForTests> m_drawingBuffer; |
278 }; | 67 }; |
279 | 68 |
280 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) | 69 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) |
281 { | 70 { |
282 cc::TextureMailbox textureMailbox; | 71 cc::TextureMailbox textureMailbox; |
283 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 72 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
284 | 73 |
285 IntSize initialSize(initialWidth, initialHeight); | 74 IntSize initialSize(InitialWidth, InitialHeight); |
286 IntSize alternateSize(initialWidth, alternateHeight); | 75 IntSize alternateSize(InitialWidth, AlternateHeight); |
287 | 76 |
288 // Produce one mailbox at size 100x100. | 77 // Produce one mailbox at size 100x100. |
289 m_drawingBuffer->markContentsChanged(); | 78 m_drawingBuffer->markContentsChanged(); |
290 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); | 79 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); |
291 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 80 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
292 | 81 |
293 // Resize to 100x50. | 82 // Resize to 100x50. |
294 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); | 83 m_drawingBuffer->reset(alternateSize); |
295 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 84 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
296 | 85 |
297 // Produce a mailbox at this size. | 86 // Produce a mailbox at this size. |
298 m_drawingBuffer->markContentsChanged(); | 87 m_drawingBuffer->markContentsChanged(); |
299 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); | 88 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); |
300 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); | 89 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); |
301 | 90 |
302 // Reset to initial size. | 91 // Reset to initial size. |
303 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); | 92 m_drawingBuffer->reset(initialSize); |
304 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 93 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
305 | 94 |
306 // Prepare another mailbox and verify that it's the correct size. | 95 // Prepare another mailbox and verify that it's the correct size. |
307 m_drawingBuffer->markContentsChanged(); | 96 m_drawingBuffer->markContentsChanged(); |
308 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); | 97 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); |
309 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 98 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
310 | 99 |
311 // Prepare one final mailbox and verify that it's the correct size. | 100 // Prepare one final mailbox and verify that it's the correct size. |
312 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 101 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
313 m_drawingBuffer->markContentsChanged(); | 102 m_drawingBuffer->markContentsChanged(); |
314 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); | 103 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); |
315 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 104 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
316 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 105 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
317 m_drawingBuffer->beginDestruction(); | 106 m_drawingBuffer->beginDestruction(); |
318 } | 107 } |
319 | 108 |
320 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) | 109 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) |
321 { | 110 { |
322 bool live = true; | 111 bool live = true; |
323 m_drawingBuffer->m_live = &live; | 112 m_drawingBuffer->m_live = &live; |
324 | 113 |
325 cc::TextureMailbox textureMailbox1; | 114 cc::TextureMailbox textureMailbox1; |
326 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 115 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; |
327 cc::TextureMailbox textureMailbox2; | 116 cc::TextureMailbox textureMailbox2; |
328 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 117 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; |
329 cc::TextureMailbox textureMailbox3; | 118 cc::TextureMailbox textureMailbox3; |
330 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 119 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; |
331 | 120 |
332 IntSize initialSize(initialWidth, initialHeight); | 121 IntSize initialSize(InitialWidth, InitialHeight); |
333 | 122 |
334 // Produce mailboxes. | 123 // Produce mailboxes. |
335 m_drawingBuffer->markContentsChanged(); | 124 m_drawingBuffer->markContentsChanged(); |
336 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releas
eCallback1)); | 125 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releas
eCallback1)); |
337 m_drawingBuffer->markContentsChanged(); | 126 m_drawingBuffer->markContentsChanged(); |
338 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, &releas
eCallback2)); | 127 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, &releas
eCallback2)); |
339 m_drawingBuffer->markContentsChanged(); | 128 m_drawingBuffer->markContentsChanged(); |
340 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, &releas
eCallback3)); | 129 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, &releas
eCallback3)); |
341 | 130 |
342 m_drawingBuffer->markContentsChanged(); | 131 m_drawingBuffer->markContentsChanged(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 m_gl->GenSyncTokenCHROMIUM(m_gl->InsertFenceSyncCHROMIUM(), waitSyncToken.Ge
tData()); | 260 m_gl->GenSyncTokenCHROMIUM(m_gl->InsertFenceSyncCHROMIUM(), waitSyncToken.Ge
tData()); |
472 releaseCallback->Run(waitSyncToken, false /* lostResource */); | 261 releaseCallback->Run(waitSyncToken, false /* lostResource */); |
473 // m_drawingBuffer waits for the sync point because the destruction is in pr
ogress. | 262 // m_drawingBuffer waits for the sync point because the destruction is in pr
ogress. |
474 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 263 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); |
475 } | 264 } |
476 | 265 |
477 class DrawingBufferImageChromiumTest : public DrawingBufferTest { | 266 class DrawingBufferImageChromiumTest : public DrawingBufferTest { |
478 protected: | 267 protected: |
479 void SetUp() override | 268 void SetUp() override |
480 { | 269 { |
| 270 IntSize initialSize(InitialWidth, InitialHeight); |
481 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa
ceForTests); | 271 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa
ceForTests); |
482 m_gl = gl.get(); | 272 m_gl = gl.get(); |
483 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni
que(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 273 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni
que(new WebGraphicsContext3DProviderForTests(std::move(gl))); |
484 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); | 274 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); |
485 m_imageId0 = m_gl->nextImageIdToBeCreated(); | 275 m_imageId0 = m_gl->nextImageIdToBeCreated(); |
486 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); | 276 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); |
487 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), | 277 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), |
488 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); | 278 initialSize, DrawingBuffer::Preserve); |
489 CHECK(m_drawingBuffer); | 279 CHECK(m_drawingBuffer); |
490 testing::Mock::VerifyAndClearExpectations(m_gl); | 280 testing::Mock::VerifyAndClearExpectations(m_gl); |
491 } | 281 } |
492 | 282 |
493 void TearDown() override | 283 void TearDown() override |
494 { | 284 { |
495 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); | 285 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); |
496 } | 286 } |
497 | 287 |
498 GLuint m_imageId0; | 288 GLuint m_imageId0; |
499 }; | 289 }; |
500 | 290 |
501 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) | 291 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) |
502 { | 292 { |
503 cc::TextureMailbox textureMailbox; | 293 cc::TextureMailbox textureMailbox; |
504 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 294 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
505 | 295 |
506 IntSize initialSize(initialWidth, initialHeight); | 296 IntSize initialSize(InitialWidth, InitialHeight); |
507 IntSize alternateSize(initialWidth, alternateHeight); | 297 IntSize alternateSize(InitialWidth, AlternateHeight); |
508 | 298 |
509 GLuint m_imageId1 = m_gl->nextImageIdToBeCreated(); | 299 GLuint m_imageId1 = m_gl->nextImageIdToBeCreated(); |
510 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1); | 300 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1); |
511 // Produce one mailbox at size 100x100. | 301 // Produce one mailbox at size 100x100. |
512 m_drawingBuffer->markContentsChanged(); | 302 m_drawingBuffer->markContentsChanged(); |
513 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); | 303 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); |
514 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 304 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
515 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 305 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); |
516 testing::Mock::VerifyAndClearExpectations(m_gl); | 306 testing::Mock::VerifyAndClearExpectations(m_gl); |
517 | 307 |
518 GLuint m_imageId2 = m_gl->nextImageIdToBeCreated(); | 308 GLuint m_imageId2 = m_gl->nextImageIdToBeCreated(); |
519 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId2)).Times(1); | 309 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId2)).Times(1); |
520 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1); | 310 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1); |
521 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1); | 311 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1); |
522 // Resize to 100x50. | 312 // Resize to 100x50. |
523 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); | 313 m_drawingBuffer->reset(alternateSize); |
524 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 314 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
525 testing::Mock::VerifyAndClearExpectations(m_gl); | 315 testing::Mock::VerifyAndClearExpectations(m_gl); |
526 | 316 |
527 GLuint m_imageId3 = m_gl->nextImageIdToBeCreated(); | 317 GLuint m_imageId3 = m_gl->nextImageIdToBeCreated(); |
528 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId3)).Times(1); | 318 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId3)).Times(1); |
529 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId1)).Times(1); | 319 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId1)).Times(1); |
530 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId1)).Times(1); | 320 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId1)).Times(1); |
531 // Produce a mailbox at this size. | 321 // Produce a mailbox at this size. |
532 m_drawingBuffer->markContentsChanged(); | 322 m_drawingBuffer->markContentsChanged(); |
533 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); | 323 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); |
534 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); | 324 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); |
535 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 325 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); |
536 testing::Mock::VerifyAndClearExpectations(m_gl); | 326 testing::Mock::VerifyAndClearExpectations(m_gl); |
537 | 327 |
538 GLuint m_imageId4 = m_gl->nextImageIdToBeCreated(); | 328 GLuint m_imageId4 = m_gl->nextImageIdToBeCreated(); |
539 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId4)).Times(1); | 329 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId4)).Times(1); |
540 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1); | 330 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1); |
541 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1); | 331 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1); |
542 // Reset to initial size. | 332 // Reset to initial size. |
543 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); | 333 m_drawingBuffer->reset(initialSize); |
544 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 334 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
545 testing::Mock::VerifyAndClearExpectations(m_gl); | 335 testing::Mock::VerifyAndClearExpectations(m_gl); |
546 | 336 |
547 GLuint m_imageId5 = m_gl->nextImageIdToBeCreated(); | 337 GLuint m_imageId5 = m_gl->nextImageIdToBeCreated(); |
548 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId5)).Times(1); | 338 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId5)).Times(1); |
549 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId3)).Times(1); | 339 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId3)).Times(1); |
550 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId3)).Times(1); | 340 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId3)).Times(1); |
551 // Prepare another mailbox and verify that it's the correct size. | 341 // Prepare another mailbox and verify that it's the correct size. |
552 m_drawingBuffer->markContentsChanged(); | 342 m_drawingBuffer->markContentsChanged(); |
553 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); | 343 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release
Callback)); |
(...skipping 22 matching lines...) Expand all Loading... |
576 cc::TextureMailbox textureMailbox1; | 366 cc::TextureMailbox textureMailbox1; |
577 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 367 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; |
578 cc::TextureMailbox textureMailbox2; | 368 cc::TextureMailbox textureMailbox2; |
579 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 369 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; |
580 cc::TextureMailbox textureMailbox3; | 370 cc::TextureMailbox textureMailbox3; |
581 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 371 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; |
582 | 372 |
583 // Request a mailbox. An image should already be created. Everything works | 373 // Request a mailbox. An image should already be created. Everything works |
584 // as expected. | 374 // as expected. |
585 EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); | 375 EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); |
586 IntSize initialSize(initialWidth, initialHeight); | 376 IntSize initialSize(InitialWidth, InitialHeight); |
587 m_drawingBuffer->markContentsChanged(); | 377 m_drawingBuffer->markContentsChanged(); |
588 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releas
eCallback1)); | 378 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releas
eCallback1)); |
589 EXPECT_TRUE(textureMailbox1.is_overlay_candidate()); | 379 EXPECT_TRUE(textureMailbox1.is_overlay_candidate()); |
590 testing::Mock::VerifyAndClearExpectations(m_gl); | 380 testing::Mock::VerifyAndClearExpectations(m_gl); |
591 | 381 |
592 // Force image CHROMIUM creation failure. Request another mailbox. It should | 382 // Force image CHROMIUM creation failure. Request another mailbox. It should |
593 // still be provided, but this time with allowOverlay = false. | 383 // still be provided, but this time with allowOverlay = false. |
594 m_gl->setCreateImageChromiumFail(true); | 384 m_gl->setCreateImageChromiumFail(true); |
595 m_drawingBuffer->markContentsChanged(); | 385 m_drawingBuffer->markContentsChanged(); |
596 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, &releas
eCallback2)); | 386 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, &releas
eCallback2)); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 m_drawingBuffer->setIsHidden(true); | 560 m_drawingBuffer->setIsHidden(true); |
771 releaseCallback->Run(waitSyncToken, false /* lostResource */); | 561 releaseCallback->Run(waitSyncToken, false /* lostResource */); |
772 // m_drawingBuffer deletes mailbox immediately when hidden. | 562 // m_drawingBuffer deletes mailbox immediately when hidden. |
773 | 563 |
774 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 564 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); |
775 | 565 |
776 m_drawingBuffer->beginDestruction(); | 566 m_drawingBuffer->beginDestruction(); |
777 } | 567 } |
778 | 568 |
779 } // namespace blink | 569 } // namespace blink |
OLD | NEW |