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

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

Issue 2362473002: Adding unit test for DrawingBuffer's bitmap recycling mechanism (Closed)
Patch Set: minor cleanup Created 4 years, 2 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 15 matching lines...) Expand all
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 {
269 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa ceForTests); 57 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa ceForTests);
270 m_gl = gl.get(); 58 m_gl = gl.get();
271 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni que(new WebGraphicsContext3DProviderForTests(std::move(gl))); 59 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); 60 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), Int Size(InitialWidth, InitialHeight), DrawingBuffer::Preserve);
273 CHECK(m_drawingBuffer); 61 CHECK(m_drawingBuffer);
274 } 62 }
275 63
276 GLES2InterfaceForTests* m_gl; 64 GLES2InterfaceForTests* m_gl;
277 RefPtr<DrawingBufferForTests> m_drawingBuffer; 65 RefPtr<DrawingBufferForTests> m_drawingBuffer;
278 }; 66 };
279 67
280 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) 68 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes)
281 { 69 {
282 cc::TextureMailbox textureMailbox; 70 cc::TextureMailbox textureMailbox;
283 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; 71 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback;
284 72
285 IntSize initialSize(initialWidth, initialHeight); 73 IntSize initialSize(InitialWidth, InitialHeight);
286 IntSize alternateSize(initialWidth, alternateHeight); 74 IntSize alternateSize(InitialWidth, AlternateHeight);
287 75
288 // Produce one mailbox at size 100x100. 76 // Produce one mailbox at size 100x100.
289 m_drawingBuffer->markContentsChanged(); 77 m_drawingBuffer->markContentsChanged();
290 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback)); 78 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback));
291 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); 79 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize());
292 80
293 // Resize to 100x50. 81 // Resize to 100x50.
294 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); 82 m_drawingBuffer->reset(IntSize(InitialWidth, AlternateHeight));
xidachen 2016/09/22 01:48:16 This is not introduced by your CL, but to be consi
295 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); 83 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */);
296 84
297 // Produce a mailbox at this size. 85 // Produce a mailbox at this size.
298 m_drawingBuffer->markContentsChanged(); 86 m_drawingBuffer->markContentsChanged();
299 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback)); 87 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback));
300 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); 88 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize());
301 89
302 // Reset to initial size. 90 // Reset to initial size.
303 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); 91 m_drawingBuffer->reset(IntSize(InitialWidth, InitialHeight));
304 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); 92 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */);
305 93
306 // Prepare another mailbox and verify that it's the correct size. 94 // Prepare another mailbox and verify that it's the correct size.
307 m_drawingBuffer->markContentsChanged(); 95 m_drawingBuffer->markContentsChanged();
308 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback)); 96 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback));
309 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); 97 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize());
310 98
311 // Prepare one final mailbox and verify that it's the correct size. 99 // Prepare one final mailbox and verify that it's the correct size.
312 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); 100 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */);
313 m_drawingBuffer->markContentsChanged(); 101 m_drawingBuffer->markContentsChanged();
314 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback)); 102 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback));
315 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); 103 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize());
316 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); 104 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */);
317 m_drawingBuffer->beginDestruction(); 105 m_drawingBuffer->beginDestruction();
318 } 106 }
319 107
320 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) 108 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased)
321 { 109 {
322 bool live = true; 110 bool live = true;
323 m_drawingBuffer->m_live = &live; 111 m_drawingBuffer->m_live = &live;
324 112
325 cc::TextureMailbox textureMailbox1; 113 cc::TextureMailbox textureMailbox1;
326 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; 114 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1;
327 cc::TextureMailbox textureMailbox2; 115 cc::TextureMailbox textureMailbox2;
328 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; 116 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2;
329 cc::TextureMailbox textureMailbox3; 117 cc::TextureMailbox textureMailbox3;
330 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; 118 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3;
331 119
332 IntSize initialSize(initialWidth, initialHeight); 120 IntSize initialSize(InitialWidth, InitialHeight);
Ken Russell (switch to Gerrit) 2016/09/22 00:57:59 Unused?
333 121
334 // Produce mailboxes. 122 // Produce mailboxes.
335 m_drawingBuffer->markContentsChanged(); 123 m_drawingBuffer->markContentsChanged();
336 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releas eCallback1)); 124 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releas eCallback1));
337 m_drawingBuffer->markContentsChanged(); 125 m_drawingBuffer->markContentsChanged();
338 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, &releas eCallback2)); 126 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, &releas eCallback2));
339 m_drawingBuffer->markContentsChanged(); 127 m_drawingBuffer->markContentsChanged();
340 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, &releas eCallback3)); 128 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, &releas eCallback3));
341 129
342 m_drawingBuffer->markContentsChanged(); 130 m_drawingBuffer->markContentsChanged();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 protected: 266 protected:
479 void SetUp() override 267 void SetUp() override
480 { 268 {
481 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa ceForTests); 269 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa ceForTests);
482 m_gl = gl.get(); 270 m_gl = gl.get();
483 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni que(new WebGraphicsContext3DProviderForTests(std::move(gl))); 271 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni que(new WebGraphicsContext3DProviderForTests(std::move(gl)));
484 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); 272 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true);
485 m_imageId0 = m_gl->nextImageIdToBeCreated(); 273 m_imageId0 = m_gl->nextImageIdToBeCreated();
486 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); 274 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1);
487 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), 275 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider),
488 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); 276 IntSize(InitialWidth, InitialHeight), DrawingBuffer::Preserve);
489 CHECK(m_drawingBuffer); 277 CHECK(m_drawingBuffer);
490 testing::Mock::VerifyAndClearExpectations(m_gl); 278 testing::Mock::VerifyAndClearExpectations(m_gl);
491 } 279 }
492 280
493 void TearDown() override 281 void TearDown() override
494 { 282 {
495 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); 283 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false);
496 } 284 }
497 285
498 GLuint m_imageId0; 286 GLuint m_imageId0;
499 }; 287 };
500 288
501 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) 289 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages)
502 { 290 {
503 cc::TextureMailbox textureMailbox; 291 cc::TextureMailbox textureMailbox;
504 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; 292 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback;
505 293
506 IntSize initialSize(initialWidth, initialHeight); 294 IntSize initialSize(InitialWidth, InitialHeight);
507 IntSize alternateSize(initialWidth, alternateHeight); 295 IntSize alternateSize(InitialWidth, AlternateHeight);
508 296
509 GLuint m_imageId1 = m_gl->nextImageIdToBeCreated(); 297 GLuint m_imageId1 = m_gl->nextImageIdToBeCreated();
510 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1); 298 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1);
511 // Produce one mailbox at size 100x100. 299 // Produce one mailbox at size 100x100.
512 m_drawingBuffer->markContentsChanged(); 300 m_drawingBuffer->markContentsChanged();
513 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback)); 301 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback));
514 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); 302 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize());
515 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); 303 EXPECT_TRUE(textureMailbox.is_overlay_candidate());
516 testing::Mock::VerifyAndClearExpectations(m_gl); 304 testing::Mock::VerifyAndClearExpectations(m_gl);
517 305
518 GLuint m_imageId2 = m_gl->nextImageIdToBeCreated(); 306 GLuint m_imageId2 = m_gl->nextImageIdToBeCreated();
519 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId2)).Times(1); 307 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId2)).Times(1);
520 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1); 308 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1);
521 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1); 309 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1);
522 // Resize to 100x50. 310 // Resize to 100x50.
523 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); 311 m_drawingBuffer->reset(IntSize(InitialWidth, AlternateHeight));
524 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); 312 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */);
525 testing::Mock::VerifyAndClearExpectations(m_gl); 313 testing::Mock::VerifyAndClearExpectations(m_gl);
526 314
527 GLuint m_imageId3 = m_gl->nextImageIdToBeCreated(); 315 GLuint m_imageId3 = m_gl->nextImageIdToBeCreated();
528 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId3)).Times(1); 316 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId3)).Times(1);
529 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId1)).Times(1); 317 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId1)).Times(1);
530 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId1)).Times(1); 318 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId1)).Times(1);
531 // Produce a mailbox at this size. 319 // Produce a mailbox at this size.
532 m_drawingBuffer->markContentsChanged(); 320 m_drawingBuffer->markContentsChanged();
533 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback)); 321 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback));
534 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); 322 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize());
535 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); 323 EXPECT_TRUE(textureMailbox.is_overlay_candidate());
536 testing::Mock::VerifyAndClearExpectations(m_gl); 324 testing::Mock::VerifyAndClearExpectations(m_gl);
537 325
538 GLuint m_imageId4 = m_gl->nextImageIdToBeCreated(); 326 GLuint m_imageId4 = m_gl->nextImageIdToBeCreated();
539 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId4)).Times(1); 327 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId4)).Times(1);
540 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1); 328 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1);
541 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1); 329 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1);
542 // Reset to initial size. 330 // Reset to initial size.
543 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); 331 m_drawingBuffer->reset(initialSize);
544 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); 332 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */);
545 testing::Mock::VerifyAndClearExpectations(m_gl); 333 testing::Mock::VerifyAndClearExpectations(m_gl);
546 334
547 GLuint m_imageId5 = m_gl->nextImageIdToBeCreated(); 335 GLuint m_imageId5 = m_gl->nextImageIdToBeCreated();
548 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId5)).Times(1); 336 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId5)).Times(1);
549 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId3)).Times(1); 337 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId3)).Times(1);
550 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId3)).Times(1); 338 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId3)).Times(1);
551 // Prepare another mailbox and verify that it's the correct size. 339 // Prepare another mailbox and verify that it's the correct size.
552 m_drawingBuffer->markContentsChanged(); 340 m_drawingBuffer->markContentsChanged();
553 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback)); 341 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &release Callback));
(...skipping 22 matching lines...) Expand all
576 cc::TextureMailbox textureMailbox1; 364 cc::TextureMailbox textureMailbox1;
577 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; 365 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1;
578 cc::TextureMailbox textureMailbox2; 366 cc::TextureMailbox textureMailbox2;
579 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; 367 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2;
580 cc::TextureMailbox textureMailbox3; 368 cc::TextureMailbox textureMailbox3;
581 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; 369 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3;
582 370
583 // Request a mailbox. An image should already be created. Everything works 371 // Request a mailbox. An image should already be created. Everything works
584 // as expected. 372 // as expected.
585 EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); 373 EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1);
586 IntSize initialSize(initialWidth, initialHeight); 374 IntSize initialSize(InitialWidth, InitialHeight);
587 m_drawingBuffer->markContentsChanged(); 375 m_drawingBuffer->markContentsChanged();
588 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releas eCallback1)); 376 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, &releas eCallback1));
589 EXPECT_TRUE(textureMailbox1.is_overlay_candidate()); 377 EXPECT_TRUE(textureMailbox1.is_overlay_candidate());
590 testing::Mock::VerifyAndClearExpectations(m_gl); 378 testing::Mock::VerifyAndClearExpectations(m_gl);
591 379
592 // Force image CHROMIUM creation failure. Request another mailbox. It should 380 // Force image CHROMIUM creation failure. Request another mailbox. It should
593 // still be provided, but this time with allowOverlay = false. 381 // still be provided, but this time with allowOverlay = false.
594 m_gl->setCreateImageChromiumFail(true); 382 m_gl->setCreateImageChromiumFail(true);
595 m_drawingBuffer->markContentsChanged(); 383 m_drawingBuffer->markContentsChanged();
596 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, &releas eCallback2)); 384 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, &releas eCallback2));
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 m_drawingBuffer->setIsHidden(true); 558 m_drawingBuffer->setIsHidden(true);
771 releaseCallback->Run(waitSyncToken, false /* lostResource */); 559 releaseCallback->Run(waitSyncToken, false /* lostResource */);
772 // m_drawingBuffer deletes mailbox immediately when hidden. 560 // m_drawingBuffer deletes mailbox immediately when hidden.
773 561
774 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); 562 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken());
775 563
776 m_drawingBuffer->beginDestruction(); 564 m_drawingBuffer->beginDestruction();
777 } 565 }
778 566
779 } // namespace blink 567 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698