Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 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 "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "platform/graphics/gpu/DrawingBuffer.h" | 33 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 34 | 34 |
| 35 #include "RuntimeEnabledFeatures.h" | |
| 35 #include "platform/graphics/ImageBuffer.h" | 36 #include "platform/graphics/ImageBuffer.h" |
| 36 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 37 #include "platform/graphics/gpu/Extensions3DUtil.h" | 38 #include "platform/graphics/gpu/Extensions3DUtil.h" |
| 38 #include "platform/graphics/test/MockWebGraphicsContext3D.h" | 39 #include "platform/graphics/test/MockWebGraphicsContext3D.h" |
| 39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebExternalTextureMailbox.h" | 41 #include "public/platform/WebExternalTextureMailbox.h" |
| 41 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
| 42 | 43 |
| 43 #include <gmock/gmock.h> | 44 #include <gmock/gmock.h> |
| 44 #include <gtest/gtest.h> | 45 #include <gtest/gtest.h> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 55 void forciblyLoseOldestContext(const String& reason) { } | 56 void forciblyLoseOldestContext(const String& reason) { } |
| 56 IntSize oldestContextSize() { return IntSize(); } | 57 IntSize oldestContextSize() { return IntSize(); } |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { | 60 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { |
| 60 public: | 61 public: |
| 61 WebGraphicsContext3DForTests() | 62 WebGraphicsContext3DForTests() |
| 62 : MockWebGraphicsContext3D() | 63 : MockWebGraphicsContext3D() |
| 63 , m_boundTexture(0) | 64 , m_boundTexture(0) |
| 64 , m_currentMailboxByte(0) | 65 , m_currentMailboxByte(0) |
| 65 , m_mostRecentlyWaitedSyncPoint(0) { } | 66 , m_mostRecentlyWaitedSyncPoint(0) |
| 67 , m_currentImageId(1) { } | |
| 66 | 68 |
| 67 virtual void bindTexture(WGC3Denum target, WebGLId texture) | 69 virtual void bindTexture(WGC3Denum target, WebGLId texture) |
| 68 { | 70 { |
| 69 if (target == GL_TEXTURE_2D) { | 71 if (target == GL_TEXTURE_2D) { |
| 70 m_boundTexture = texture; | 72 m_boundTexture = texture; |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 | 75 |
| 74 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denum type, const void* pixels) | 76 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denum type, const void* pixels) |
| 75 { | 77 { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 100 { | 102 { |
| 101 static unsigned syncPointGenerator = 0; | 103 static unsigned syncPointGenerator = 0; |
| 102 return ++syncPointGenerator; | 104 return ++syncPointGenerator; |
| 103 } | 105 } |
| 104 | 106 |
| 105 virtual void waitSyncPoint(unsigned syncPoint) | 107 virtual void waitSyncPoint(unsigned syncPoint) |
| 106 { | 108 { |
| 107 m_mostRecentlyWaitedSyncPoint = syncPoint; | 109 m_mostRecentlyWaitedSyncPoint = syncPoint; |
| 108 } | 110 } |
| 109 | 111 |
| 112 virtual WGC3Duint createImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei height, W GC3Denum internalformat, WGC3Denum usage) | |
| 113 { | |
| 114 m_imageSizes.set(m_currentImageId, IntSize(width, height)); | |
| 115 return m_currentImageId++; | |
| 116 } | |
| 117 | |
| 118 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId)); | |
| 119 void destroyImageCHROMIUM(WGC3Duint imageId) | |
| 120 { | |
| 121 m_imageSizes.remove(imageId); | |
| 122 // No textures should be bound to this. | |
| 123 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end()); | |
| 124 m_imageSizes.remove(imageId); | |
| 125 destroyImageMock(imageId); | |
| 126 } | |
| 127 | |
| 128 MOCK_METHOD1(bindTexImage2DMock, void(WGC3Dint imageId)); | |
| 129 void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId) | |
| 130 { | |
| 131 if (target == GL_TEXTURE_2D) { | |
| 132 m_textureSizes.set(m_boundTexture, m_imageSizes.find(imageId)->value ); | |
| 133 m_imageToTextureMap.set(imageId, m_boundTexture); | |
| 134 bindTexImage2DMock(imageId); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 MOCK_METHOD1(releaseTexImage2DMock, void(WGC3Dint imageId)); | |
| 139 void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId) | |
| 140 { | |
| 141 if (target == GL_TEXTURE_2D) { | |
| 142 m_imageSizes.set(m_currentImageId, IntSize()); | |
| 143 m_imageToTextureMap.remove(imageId); | |
| 144 releaseTexImage2DMock(imageId); | |
| 145 } | |
| 146 } | |
| 147 | |
| 110 unsigned mostRecentlyWaitedSyncPoint() | 148 unsigned mostRecentlyWaitedSyncPoint() |
| 111 { | 149 { |
| 112 return m_mostRecentlyWaitedSyncPoint; | 150 return m_mostRecentlyWaitedSyncPoint; |
| 113 } | 151 } |
| 114 | 152 |
| 153 WGC3Duint nextImageIdToBeCreated() { return m_currentImageId; } | |
| 154 | |
| 115 private: | 155 private: |
| 116 WebGLId m_boundTexture; | 156 WebGLId m_boundTexture; |
| 117 HashMap<WebGLId, IntSize> m_textureSizes; | 157 HashMap<WebGLId, IntSize> m_textureSizes; |
| 118 WGC3Dbyte m_currentMailboxByte; | 158 WGC3Dbyte m_currentMailboxByte; |
| 119 IntSize m_mostRecentlyProducedSize; | 159 IntSize m_mostRecentlyProducedSize; |
| 120 unsigned m_mostRecentlyWaitedSyncPoint; | 160 unsigned m_mostRecentlyWaitedSyncPoint; |
| 161 WGC3Duint m_currentImageId; | |
| 162 HashMap<WGC3Duint, IntSize> m_imageSizes; | |
| 163 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap; | |
| 121 }; | 164 }; |
| 122 | 165 |
| 123 static const int initialWidth = 100; | 166 static const int initialWidth = 100; |
| 124 static const int initialHeight = 100; | 167 static const int initialHeight = 100; |
| 125 static const int alternateHeight = 50; | 168 static const int alternateHeight = 50; |
| 126 | 169 |
| 127 class DrawingBufferForTests : public DrawingBuffer { | 170 class DrawingBufferForTests : public DrawingBuffer { |
| 128 public: | 171 public: |
| 129 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic sContext3D> context, | 172 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic sContext3D> context, |
| 130 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE victionManager> contextEvictionManager) | 173 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE victionManager> contextEvictionManager) |
| (...skipping 219 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 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); | |
|
Ken Russell (switch to Gerrit)
2014/05/14 22:11:33
Does this get set back to false somehow when the t
alexst (slow to review)
2014/05/14 22:29:55
Good point, I'll force it back off on teardown.
| |
| 411 m_imageId0 = webContext()->nextImageIdToBeCreated(); | |
| 412 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId0)).Times(1); | |
| 413 m_drawingBuffer = DrawingBufferForTests::create(context.release(), | |
| 414 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve, conte xtEvictionManager.release()); | |
| 415 testing::Mock::VerifyAndClearExpectations(webContext()); | |
| 416 } | |
| 417 WGC3Duint m_imageId0; | |
| 418 }; | |
| 419 | |
| 420 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) | |
| 421 { | |
| 422 blink::WebExternalTextureMailbox mailbox; | |
| 423 | |
| 424 IntSize initialSize(initialWidth, initialHeight); | |
| 425 IntSize alternateSize(initialWidth, alternateHeight); | |
| 426 | |
| 427 WGC3Duint m_imageId1 = webContext()->nextImageIdToBeCreated(); | |
| 428 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId1)).Times(1); | |
| 429 // Produce one mailbox at size 100x100. | |
| 430 m_drawingBuffer->markContentsChanged(); | |
| 431 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); | |
| 432 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); | |
| 433 EXPECT_TRUE(mailbox.allowOverlay); | |
| 434 testing::Mock::VerifyAndClearExpectations(webContext()); | |
| 435 | |
| 436 WGC3Duint m_imageId2 = webContext()->nextImageIdToBeCreated(); | |
| 437 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId2)).Times(1); | |
| 438 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId0)).Times(1); | |
| 439 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId0)).Times(1); | |
| 440 // Resize to 100x50. | |
| 441 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); | |
| 442 m_drawingBuffer->mailboxReleased(mailbox); | |
| 443 testing::Mock::VerifyAndClearExpectations(webContext()); | |
| 444 | |
| 445 WGC3Duint m_imageId3 = webContext()->nextImageIdToBeCreated(); | |
| 446 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId3)).Times(1); | |
| 447 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId1)).Times(1); | |
| 448 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId1)).Times(1); | |
| 449 // Produce a mailbox at this size. | |
| 450 m_drawingBuffer->markContentsChanged(); | |
| 451 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); | |
| 452 EXPECT_EQ(alternateSize, webContext()->mostRecentlyProducedSize()); | |
| 453 EXPECT_TRUE(mailbox.allowOverlay); | |
| 454 testing::Mock::VerifyAndClearExpectations(webContext()); | |
| 455 | |
| 456 WGC3Duint m_imageId4 = webContext()->nextImageIdToBeCreated(); | |
| 457 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId4)).Times(1); | |
| 458 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId2)).Times(1); | |
| 459 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId2)).Times(1); | |
| 460 // Reset to initial size. | |
| 461 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); | |
| 462 m_drawingBuffer->mailboxReleased(mailbox); | |
| 463 testing::Mock::VerifyAndClearExpectations(webContext()); | |
| 464 | |
| 465 WGC3Duint m_imageId5 = webContext()->nextImageIdToBeCreated(); | |
| 466 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId5)).Times(1); | |
| 467 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId3)).Times(1); | |
| 468 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId3)).Times(1); | |
| 469 // Prepare another mailbox and verify that it's the correct size. | |
| 470 m_drawingBuffer->markContentsChanged(); | |
| 471 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); | |
| 472 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); | |
| 473 EXPECT_TRUE(mailbox.allowOverlay); | |
| 474 testing::Mock::VerifyAndClearExpectations(webContext()); | |
| 475 | |
| 476 // Prepare one final mailbox and verify that it's the correct size. | |
| 477 m_drawingBuffer->mailboxReleased(mailbox); | |
| 478 m_drawingBuffer->markContentsChanged(); | |
| 479 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); | |
| 480 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); | |
| 481 EXPECT_TRUE(mailbox.allowOverlay); | |
| 482 m_drawingBuffer->mailboxReleased(mailbox); | |
| 483 | |
| 484 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId5)).Times(1); | |
| 485 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId5)).Times(1); | |
| 486 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId4)).Times(1); | |
| 487 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId4)).Times(1); | |
| 488 m_drawingBuffer->beginDestruction(); | |
| 489 testing::Mock::VerifyAndClearExpectations(webContext()); | |
| 490 } | |
| 491 | |
| 360 } // namespace | 492 } // namespace |
| OLD | NEW |