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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 void forciblyLoseOldestContext(const String& reason) { } | 55 void forciblyLoseOldestContext(const String& reason) { } |
56 IntSize oldestContextSize() { return IntSize(); } | 56 IntSize oldestContextSize() { return IntSize(); } |
57 }; | 57 }; |
58 | 58 |
59 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { | 59 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { |
60 public: | 60 public: |
61 WebGraphicsContext3DForTests() | 61 WebGraphicsContext3DForTests() |
62 : MockWebGraphicsContext3D() | 62 : MockWebGraphicsContext3D() |
63 , m_boundTexture(0) | 63 , m_boundTexture(0) |
64 , m_currentMailboxByte(0) | 64 , m_currentMailboxByte(0) |
65 , m_mostRecentlyWaitedSyncPoint(0) { } | 65 , m_mostRecentlyWaitedSyncPoint(0) |
| 66 , m_currentImageId(1) { } |
66 | 67 |
67 virtual void bindTexture(WGC3Denum target, WebGLId texture) | 68 virtual void bindTexture(WGC3Denum target, WebGLId texture) |
68 { | 69 { |
69 if (target == GL_TEXTURE_2D) { | 70 if (target == GL_TEXTURE_2D) { |
70 m_boundTexture = texture; | 71 m_boundTexture = texture; |
71 } | 72 } |
72 } | 73 } |
73 | 74 |
74 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal
format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
WGC3Denum type, const void* pixels) | 75 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal
format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
WGC3Denum type, const void* pixels) |
75 { | 76 { |
(...skipping 24 matching lines...) Expand all Loading... |
100 { | 101 { |
101 static unsigned syncPointGenerator = 0; | 102 static unsigned syncPointGenerator = 0; |
102 return ++syncPointGenerator; | 103 return ++syncPointGenerator; |
103 } | 104 } |
104 | 105 |
105 virtual void waitSyncPoint(unsigned syncPoint) | 106 virtual void waitSyncPoint(unsigned syncPoint) |
106 { | 107 { |
107 m_mostRecentlyWaitedSyncPoint = syncPoint; | 108 m_mostRecentlyWaitedSyncPoint = syncPoint; |
108 } | 109 } |
109 | 110 |
| 111 virtual WGC3Duint createImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei height, W
GC3Denum internalformat, WGC3Denum usage) |
| 112 { |
| 113 m_imageSizes.set(m_currentImageId, IntSize(width, height)); |
| 114 return m_currentImageId++; |
| 115 } |
| 116 |
| 117 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId)); |
| 118 void destroyImageCHROMIUM(WGC3Duint imageId) |
| 119 { |
| 120 m_imageSizes.remove(imageId); |
| 121 // No textures should be bound to this. |
| 122 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end()); |
| 123 m_imageSizes.remove(imageId); |
| 124 destroyImageMock(imageId); |
| 125 } |
| 126 |
| 127 MOCK_METHOD1(bindTexImage2DMock, void(WGC3Dint imageId)); |
| 128 void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId) |
| 129 { |
| 130 if (target == GL_TEXTURE_2D) { |
| 131 m_textureSizes.set(m_boundTexture, m_imageSizes.find(imageId)->value
); |
| 132 m_imageToTextureMap.set(imageId, m_boundTexture); |
| 133 bindTexImage2DMock(imageId); |
| 134 } |
| 135 } |
| 136 |
| 137 MOCK_METHOD1(releaseTexImage2DMock, void(WGC3Dint imageId)); |
| 138 void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId) |
| 139 { |
| 140 if (target == GL_TEXTURE_2D) { |
| 141 m_imageSizes.set(m_currentImageId, IntSize()); |
| 142 m_imageToTextureMap.remove(imageId); |
| 143 releaseTexImage2DMock(imageId); |
| 144 } |
| 145 } |
| 146 |
110 unsigned mostRecentlyWaitedSyncPoint() | 147 unsigned mostRecentlyWaitedSyncPoint() |
111 { | 148 { |
112 return m_mostRecentlyWaitedSyncPoint; | 149 return m_mostRecentlyWaitedSyncPoint; |
113 } | 150 } |
114 | 151 |
| 152 WGC3Duint nextImageIdToBeCreated() { return m_currentImageId; } |
| 153 |
115 private: | 154 private: |
116 WebGLId m_boundTexture; | 155 WebGLId m_boundTexture; |
117 HashMap<WebGLId, IntSize> m_textureSizes; | 156 HashMap<WebGLId, IntSize> m_textureSizes; |
118 WGC3Dbyte m_currentMailboxByte; | 157 WGC3Dbyte m_currentMailboxByte; |
119 IntSize m_mostRecentlyProducedSize; | 158 IntSize m_mostRecentlyProducedSize; |
120 unsigned m_mostRecentlyWaitedSyncPoint; | 159 unsigned m_mostRecentlyWaitedSyncPoint; |
| 160 WGC3Duint m_currentImageId; |
| 161 HashMap<WGC3Duint, IntSize> m_imageSizes; |
| 162 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap; |
121 }; | 163 }; |
122 | 164 |
123 static const int initialWidth = 100; | 165 static const int initialWidth = 100; |
124 static const int initialHeight = 100; | 166 static const int initialHeight = 100; |
125 static const int alternateHeight = 50; | 167 static const int alternateHeight = 50; |
126 | 168 |
127 class DrawingBufferForTests : public DrawingBuffer { | 169 class DrawingBufferForTests : public DrawingBuffer { |
128 public: | 170 public: |
129 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic
sContext3D> context, | 171 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic
sContext3D> context, |
130 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE
victionManager> contextEvictionManager) | 172 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE
victionManager> contextEvictionManager, bool useImageChromium) |
131 { | 173 { |
132 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(conte
xt.get()); | 174 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(conte
xt.get()); |
133 RefPtr<DrawingBufferForTests> drawingBuffer = | 175 RefPtr<DrawingBufferForTests> drawingBuffer = |
134 adoptRef(new DrawingBufferForTests(context, extensionsUtil.release()
, preserve, contextEvictionManager)); | 176 adoptRef(new DrawingBufferForTests(context, extensionsUtil.release()
, preserve, contextEvictionManager)); |
| 177 drawingBuffer->setUseImageChromium(useImageChromium); |
135 if (!drawingBuffer->initialize(size)) { | 178 if (!drawingBuffer->initialize(size)) { |
136 drawingBuffer->beginDestruction(); | 179 drawingBuffer->beginDestruction(); |
137 return PassRefPtr<DrawingBufferForTests>(); | 180 return PassRefPtr<DrawingBufferForTests>(); |
138 } | 181 } |
139 return drawingBuffer.release(); | 182 return drawingBuffer.release(); |
140 } | 183 } |
141 | 184 |
142 DrawingBufferForTests(PassOwnPtr<blink::WebGraphicsContext3D> context, | 185 DrawingBufferForTests(PassOwnPtr<blink::WebGraphicsContext3D> context, |
143 PassOwnPtr<Extensions3DUtil> extensionsUtil, | 186 PassOwnPtr<Extensions3DUtil> extensionsUtil, |
144 PreserveDrawingBuffer preserve, | 187 PreserveDrawingBuffer preserve, |
(...skipping 13 matching lines...) Expand all Loading... |
158 }; | 201 }; |
159 | 202 |
160 class DrawingBufferTest : public Test { | 203 class DrawingBufferTest : public Test { |
161 protected: | 204 protected: |
162 virtual void SetUp() | 205 virtual void SetUp() |
163 { | 206 { |
164 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new
FakeContextEvictionManager()); | 207 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new
FakeContextEvictionManager()); |
165 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC
ontext3DForTests); | 208 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC
ontext3DForTests); |
166 m_context = context.get(); | 209 m_context = context.get(); |
167 m_drawingBuffer = DrawingBufferForTests::create(context.release(), | 210 m_drawingBuffer = DrawingBufferForTests::create(context.release(), |
168 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve, conte
xtEvictionManager.release()); | 211 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve, conte
xtEvictionManager.release(), false); |
169 } | 212 } |
170 | 213 |
171 WebGraphicsContext3DForTests* webContext() | 214 WebGraphicsContext3DForTests* webContext() |
172 { | 215 { |
173 return m_context; | 216 return m_context; |
174 } | 217 } |
175 | 218 |
176 WebGraphicsContext3DForTests* m_context; | 219 WebGraphicsContext3DForTests* m_context; |
177 RefPtr<DrawingBufferForTests> m_drawingBuffer; | 220 RefPtr<DrawingBufferForTests> m_drawingBuffer; |
178 }; | 221 }; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); | 393 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); |
351 | 394 |
352 m_drawingBuffer->beginDestruction(); | 395 m_drawingBuffer->beginDestruction(); |
353 waitSyncPoint = webContext()->insertSyncPoint(); | 396 waitSyncPoint = webContext()->insertSyncPoint(); |
354 mailbox.syncPoint = waitSyncPoint; | 397 mailbox.syncPoint = waitSyncPoint; |
355 m_drawingBuffer->mailboxReleased(mailbox); | 398 m_drawingBuffer->mailboxReleased(mailbox); |
356 // m_drawingBuffer waits for the sync point because the destruction is in pr
ogress. | 399 // m_drawingBuffer waits for the sync point because the destruction is in pr
ogress. |
357 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); | 400 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); |
358 } | 401 } |
359 | 402 |
| 403 class DrawingBufferImageChromiumTest : public DrawingBufferTest { |
| 404 protected: |
| 405 virtual void SetUp() |
| 406 { |
| 407 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new
FakeContextEvictionManager()); |
| 408 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC
ontext3DForTests); |
| 409 m_context = context.get(); |
| 410 m_imageId0 = webContext()->nextImageIdToBeCreated(); |
| 411 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId0)).Times(1); |
| 412 m_drawingBuffer = DrawingBufferForTests::create(context.release(), |
| 413 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve, conte
xtEvictionManager.release(), true); |
| 414 testing::Mock::VerifyAndClearExpectations(webContext()); |
| 415 } |
| 416 WGC3Duint m_imageId0; |
| 417 }; |
| 418 |
| 419 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) |
| 420 { |
| 421 blink::WebExternalTextureMailbox mailbox; |
| 422 |
| 423 IntSize initialSize(initialWidth, initialHeight); |
| 424 IntSize alternateSize(initialWidth, alternateHeight); |
| 425 |
| 426 WGC3Duint m_imageId1 = webContext()->nextImageIdToBeCreated(); |
| 427 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId1)).Times(1); |
| 428 // Produce one mailbox at size 100x100. |
| 429 m_drawingBuffer->markContentsChanged(); |
| 430 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 431 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
| 432 testing::Mock::VerifyAndClearExpectations(webContext()); |
| 433 |
| 434 WGC3Duint m_imageId2 = webContext()->nextImageIdToBeCreated(); |
| 435 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId2)).Times(1); |
| 436 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId0)).Times(1); |
| 437 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId0)).Times(1); |
| 438 // Resize to 100x50. |
| 439 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); |
| 440 m_drawingBuffer->mailboxReleased(mailbox); |
| 441 testing::Mock::VerifyAndClearExpectations(webContext()); |
| 442 |
| 443 WGC3Duint m_imageId3 = webContext()->nextImageIdToBeCreated(); |
| 444 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId3)).Times(1); |
| 445 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId1)).Times(1); |
| 446 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId1)).Times(1); |
| 447 // Produce a mailbox at this size. |
| 448 m_drawingBuffer->markContentsChanged(); |
| 449 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 450 EXPECT_EQ(alternateSize, webContext()->mostRecentlyProducedSize()); |
| 451 testing::Mock::VerifyAndClearExpectations(webContext()); |
| 452 |
| 453 WGC3Duint m_imageId4 = webContext()->nextImageIdToBeCreated(); |
| 454 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId4)).Times(1); |
| 455 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId2)).Times(1); |
| 456 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId2)).Times(1); |
| 457 // Reset to initial size. |
| 458 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); |
| 459 m_drawingBuffer->mailboxReleased(mailbox); |
| 460 testing::Mock::VerifyAndClearExpectations(webContext()); |
| 461 |
| 462 WGC3Duint m_imageId5 = webContext()->nextImageIdToBeCreated(); |
| 463 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId5)).Times(1); |
| 464 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId3)).Times(1); |
| 465 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId3)).Times(1); |
| 466 // Prepare another mailbox and verify that it's the correct size. |
| 467 m_drawingBuffer->markContentsChanged(); |
| 468 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 469 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
| 470 testing::Mock::VerifyAndClearExpectations(webContext()); |
| 471 |
| 472 // Prepare one final mailbox and verify that it's the correct size. |
| 473 m_drawingBuffer->mailboxReleased(mailbox); |
| 474 m_drawingBuffer->markContentsChanged(); |
| 475 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 476 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
| 477 m_drawingBuffer->mailboxReleased(mailbox); |
| 478 |
| 479 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId5)).Times(1); |
| 480 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId5)).Times(1); |
| 481 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId4)).Times(1); |
| 482 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId4)).Times(1); |
| 483 m_drawingBuffer->beginDestruction(); |
| 484 testing::Mock::VerifyAndClearExpectations(webContext()); |
| 485 } |
| 486 |
| 487 |
360 } // namespace | 488 } // namespace |
OLD | NEW |