| 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 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 | |
| 33 #include "platform/graphics/gpu/DrawingBuffer.h" | 32 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 34 | 33 |
| 35 #include "platform/RuntimeEnabledFeatures.h" | 34 #include "platform/RuntimeEnabledFeatures.h" |
| 36 #include "platform/graphics/ImageBuffer.h" | 35 #include "platform/graphics/ImageBuffer.h" |
| 37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 36 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 38 #include "platform/graphics/gpu/Extensions3DUtil.h" | 37 #include "platform/graphics/gpu/Extensions3DUtil.h" |
| 39 #include "platform/graphics/test/MockWebGraphicsContext3D.h" | 38 #include "platform/graphics/test/MockWebGraphicsContext3D.h" |
| 40 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 41 #include "public/platform/WebExternalTextureMailbox.h" | 40 #include "public/platform/WebExternalTextureMailbox.h" |
| 42 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
| 43 | |
| 44 #include <gmock/gmock.h> | 42 #include <gmock/gmock.h> |
| 45 #include <gtest/gtest.h> | 43 #include <gtest/gtest.h> |
| 46 | 44 |
| 47 using namespace blink; | |
| 48 using testing::Test; | 45 using testing::Test; |
| 49 using testing::_; | 46 using testing::_; |
| 50 | 47 |
| 51 namespace { | 48 namespace blink { |
| 52 | 49 |
| 53 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { | 50 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { |
| 54 public: | 51 public: |
| 55 WebGraphicsContext3DForTests() | 52 WebGraphicsContext3DForTests() |
| 56 : MockWebGraphicsContext3D() | 53 : MockWebGraphicsContext3D() |
| 57 , m_boundTexture(0) | 54 , m_boundTexture(0) |
| 58 , m_currentMailboxByte(0) | 55 , m_currentMailboxByte(0) |
| 59 , m_mostRecentlyWaitedSyncPoint(0) | 56 , m_mostRecentlyWaitedSyncPoint(0) |
| 60 , m_currentImageId(1) { } | 57 , m_currentImageId(1) { } |
| 61 | 58 |
| 62 virtual void bindTexture(WGC3Denum target, WebGLId texture) | 59 void bindTexture(WGC3Denum target, WebGLId texture) override |
| 63 { | 60 { |
| 64 if (target == GL_TEXTURE_2D) { | 61 if (target == GL_TEXTURE_2D) { |
| 65 m_boundTexture = texture; | 62 m_boundTexture = texture; |
| 66 } | 63 } |
| 67 } | 64 } |
| 68 | 65 |
| 69 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal
format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
WGC3Denum type, const void* pixels) | 66 void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat,
WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denu
m type, const void* pixels) override |
| 70 { | 67 { |
| 71 if (target == GL_TEXTURE_2D && !level) { | 68 if (target == GL_TEXTURE_2D && !level) { |
| 72 m_textureSizes.set(m_boundTexture, IntSize(width, height)); | 69 m_textureSizes.set(m_boundTexture, IntSize(width, height)); |
| 73 } | 70 } |
| 74 } | 71 } |
| 75 | 72 |
| 76 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) | 73 void genMailboxCHROMIUM(WGC3Dbyte* mailbox) override |
| 77 { | 74 { |
| 78 ++m_currentMailboxByte; | 75 ++m_currentMailboxByte; |
| 79 WebExternalTextureMailbox temp; | 76 WebExternalTextureMailbox temp; |
| 80 memset(mailbox, m_currentMailboxByte, sizeof(temp.name)); | 77 memset(mailbox, m_currentMailboxByte, sizeof(temp.name)); |
| 81 } | 78 } |
| 82 | 79 |
| 83 virtual void produceTextureDirectCHROMIUM(WebGLId texture, WGC3Denum target,
const WGC3Dbyte* mailbox) | 80 void produceTextureDirectCHROMIUM(WebGLId texture, WGC3Denum target, const W
GC3Dbyte* mailbox) override |
| 84 { | 81 { |
| 85 ASSERT_EQ(target, static_cast<WGC3Denum>(GL_TEXTURE_2D)); | 82 ASSERT_EQ(target, static_cast<WGC3Denum>(GL_TEXTURE_2D)); |
| 86 ASSERT_TRUE(m_textureSizes.contains(texture)); | 83 ASSERT_TRUE(m_textureSizes.contains(texture)); |
| 87 m_mostRecentlyProducedSize = m_textureSizes.get(texture); | 84 m_mostRecentlyProducedSize = m_textureSizes.get(texture); |
| 88 } | 85 } |
| 89 | 86 |
| 90 IntSize mostRecentlyProducedSize() | 87 IntSize mostRecentlyProducedSize() |
| 91 { | 88 { |
| 92 return m_mostRecentlyProducedSize; | 89 return m_mostRecentlyProducedSize; |
| 93 } | 90 } |
| 94 | 91 |
| 95 virtual unsigned insertSyncPoint() | 92 unsigned insertSyncPoint() override |
| 96 { | 93 { |
| 97 static unsigned syncPointGenerator = 0; | 94 static unsigned syncPointGenerator = 0; |
| 98 return ++syncPointGenerator; | 95 return ++syncPointGenerator; |
| 99 } | 96 } |
| 100 | 97 |
| 101 virtual void waitSyncPoint(unsigned syncPoint) | 98 void waitSyncPoint(unsigned syncPoint) override |
| 102 { | 99 { |
| 103 m_mostRecentlyWaitedSyncPoint = syncPoint; | 100 m_mostRecentlyWaitedSyncPoint = syncPoint; |
| 104 } | 101 } |
| 105 | 102 |
| 106 virtual WGC3Duint createGpuMemoryBufferImageCHROMIUM(WGC3Dsizei width, WGC3D
sizei height, WGC3Denum internalformat, WGC3Denum usage) | 103 WGC3Duint createGpuMemoryBufferImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei he
ight, WGC3Denum internalformat, WGC3Denum usage) override |
| 107 { | 104 { |
| 108 m_imageSizes.set(m_currentImageId, IntSize(width, height)); | 105 m_imageSizes.set(m_currentImageId, IntSize(width, height)); |
| 109 return m_currentImageId++; | 106 return m_currentImageId++; |
| 110 } | 107 } |
| 111 | 108 |
| 112 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId)); | 109 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId)); |
| 113 void destroyImageCHROMIUM(WGC3Duint imageId) | 110 void destroyImageCHROMIUM(WGC3Duint imageId) |
| 114 { | 111 { |
| 115 m_imageSizes.remove(imageId); | 112 m_imageSizes.remove(imageId); |
| 116 // No textures should be bound to this. | 113 // No textures should be bound to this. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 177 } |
| 181 | 178 |
| 182 DrawingBufferForTests(PassOwnPtr<WebGraphicsContext3D> context, | 179 DrawingBufferForTests(PassOwnPtr<WebGraphicsContext3D> context, |
| 183 PassOwnPtr<Extensions3DUtil> extensionsUtil, | 180 PassOwnPtr<Extensions3DUtil> extensionsUtil, |
| 184 PreserveDrawingBuffer preserve) | 181 PreserveDrawingBuffer preserve) |
| 185 : DrawingBuffer(context, extensionsUtil, false /* multisampleExtensionSu
pported */, | 182 : DrawingBuffer(context, extensionsUtil, false /* multisampleExtensionSu
pported */, |
| 186 false /* packedDepthStencilExtensionSupported */, false /* discardFr
amebufferSupported */, preserve, WebGraphicsContext3D::Attributes()) | 183 false /* packedDepthStencilExtensionSupported */, false /* discardFr
amebufferSupported */, preserve, WebGraphicsContext3D::Attributes()) |
| 187 , m_live(0) | 184 , m_live(0) |
| 188 { } | 185 { } |
| 189 | 186 |
| 190 virtual ~DrawingBufferForTests() | 187 ~DrawingBufferForTests() override |
| 191 { | 188 { |
| 192 if (m_live) | 189 if (m_live) |
| 193 *m_live = false; | 190 *m_live = false; |
| 194 } | 191 } |
| 195 | 192 |
| 196 bool* m_live; | 193 bool* m_live; |
| 197 }; | 194 }; |
| 198 | 195 |
| 199 class DrawingBufferTest : public Test { | 196 class DrawingBufferTest : public Test { |
| 200 protected: | 197 protected: |
| 201 virtual void SetUp() | 198 void SetUp() override |
| 202 { | 199 { |
| 203 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC
ontext3DForTests); | 200 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC
ontext3DForTests); |
| 204 m_context = context.get(); | 201 m_context = context.get(); |
| 205 m_drawingBuffer = DrawingBufferForTests::create(context.release(), | 202 m_drawingBuffer = DrawingBufferForTests::create(context.release(), |
| 206 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); | 203 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); |
| 207 } | 204 } |
| 208 | 205 |
| 209 WebGraphicsContext3DForTests* webContext() | 206 WebGraphicsContext3DForTests* webContext() |
| 210 { | 207 { |
| 211 return m_context; | 208 return m_context; |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 unsigned waitSyncPoint = webContext()->insertSyncPoint(); | 656 unsigned waitSyncPoint = webContext()->insertSyncPoint(); |
| 660 mailbox.syncPoint = waitSyncPoint; | 657 mailbox.syncPoint = waitSyncPoint; |
| 661 m_drawingBuffer->setIsHidden(true); | 658 m_drawingBuffer->setIsHidden(true); |
| 662 m_drawingBuffer->mailboxReleased(mailbox); | 659 m_drawingBuffer->mailboxReleased(mailbox); |
| 663 // m_drawingBuffer deletes mailbox immediately when hidden. | 660 // m_drawingBuffer deletes mailbox immediately when hidden. |
| 664 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); | 661 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); |
| 665 | 662 |
| 666 m_drawingBuffer->beginDestruction(); | 663 m_drawingBuffer->beginDestruction(); |
| 667 } | 664 } |
| 668 | 665 |
| 669 } // namespace | 666 } // namespace blink |
| OLD | NEW |