| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND |
| 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE | 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE |
| 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 23 * DAMAGE. | 23 * DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "platform/graphics/Canvas2DLayerBridge.h" | 26 #include "platform/graphics/Canvas2DLayerBridge.h" |
| 27 | 27 |
| 28 #include "cc/resources/single_release_callback.h" | 28 #include "cc/resources/single_release_callback.h" |
| 29 #include "cc/resources/texture_mailbox.h" | 29 #include "cc/resources/texture_mailbox.h" |
| 30 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 30 #include "gpu/command_buffer/client/gles2_interface.h" | 31 #include "gpu/command_buffer/client/gles2_interface.h" |
| 31 #include "gpu/command_buffer/common/capabilities.h" | 32 #include "gpu/command_buffer/common/capabilities.h" |
| 32 #include "platform/CrossThreadFunctional.h" | 33 #include "platform/CrossThreadFunctional.h" |
| 33 #include "platform/WaitableEvent.h" | 34 #include "platform/WaitableEvent.h" |
| 34 #include "platform/WebTaskRunner.h" | 35 #include "platform/WebTaskRunner.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/test/FakeGLES2Interface.h" | 38 #include "platform/graphics/test/FakeGLES2Interface.h" |
| 38 #include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h" | 39 #include "platform/graphics/test/FakeWebGraphicsContext3DProvider.h" |
| 39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebExternalBitmap.h" | 41 #include "public/platform/WebExternalBitmap.h" |
| 41 #include "public/platform/WebScheduler.h" | 42 #include "public/platform/WebScheduler.h" |
| 42 #include "public/platform/WebThread.h" | 43 #include "public/platform/WebThread.h" |
| 43 #include "public/platform/WebTraceLocation.h" | 44 #include "public/platform/WebTraceLocation.h" |
| 44 #include "skia/ext/texture_handle.h" | 45 #include "skia/ext/texture_handle.h" |
| 45 #include "testing/gmock/include/gmock/gmock.h" | 46 #include "testing/gmock/include/gmock/gmock.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
| 48 #include "third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h" |
| 47 #include "third_party/skia/include/core/SkCanvas.h" | 49 #include "third_party/skia/include/core/SkCanvas.h" |
| 48 #include "third_party/skia/include/core/SkSurface.h" | 50 #include "third_party/skia/include/core/SkSurface.h" |
| 49 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 51 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
| 50 #include "wtf/PtrUtil.h" | 52 #include "wtf/PtrUtil.h" |
| 51 #include "wtf/RefPtr.h" | 53 #include "wtf/RefPtr.h" |
| 52 | 54 |
| 53 #include <memory> | 55 #include <memory> |
| 54 | 56 |
| 55 using testing::AnyNumber; | 57 using testing::AnyNumber; |
| 56 using testing::AtLeast; | 58 using testing::AtLeast; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 83 m_layerBridge = layerBridge; | 85 m_layerBridge = layerBridge; |
| 84 } | 86 } |
| 85 | 87 |
| 86 Canvas2DLayerBridge* operator->() { return m_layerBridge.get(); } | 88 Canvas2DLayerBridge* operator->() { return m_layerBridge.get(); } |
| 87 Canvas2DLayerBridge* get() { return m_layerBridge.get(); } | 89 Canvas2DLayerBridge* get() { return m_layerBridge.get(); } |
| 88 | 90 |
| 89 private: | 91 private: |
| 90 RefPtr<Canvas2DLayerBridge> m_layerBridge; | 92 RefPtr<Canvas2DLayerBridge> m_layerBridge; |
| 91 }; | 93 }; |
| 92 | 94 |
| 95 class FakeGLES2InterfaceWithImageSupport : public FakeGLES2Interface { |
| 96 public: |
| 97 GLuint CreateImageCHROMIUM(ClientBuffer, GLsizei, GLsizei, GLenum) override { |
| 98 return ++m_createImageCount; |
| 99 } |
| 100 void DestroyImageCHROMIUM(GLuint) override { ++m_destroyImageCount; } |
| 101 |
| 102 GLuint createImageCount() { return m_createImageCount; } |
| 103 GLuint destroyImageCount() { return m_destroyImageCount; } |
| 104 |
| 105 private: |
| 106 GLuint m_createImageCount = 0; |
| 107 GLuint m_destroyImageCount = 0; |
| 108 }; |
| 109 |
| 110 class FakePlatformSupport : public TestingPlatformSupport { |
| 111 gpu::GpuMemoryBufferManager* getGpuMemoryBufferManager() override { |
| 112 return &m_testGpuMemoryBufferManager; |
| 113 } |
| 114 |
| 115 private: |
| 116 cc::TestGpuMemoryBufferManager m_testGpuMemoryBufferManager; |
| 117 }; |
| 118 |
| 93 } // anonymous namespace | 119 } // anonymous namespace |
| 94 | 120 |
| 95 class Canvas2DLayerBridgeTest : public Test { | 121 class Canvas2DLayerBridgeTest : public Test { |
| 96 public: | 122 public: |
| 97 PassRefPtr<Canvas2DLayerBridge> makeBridge( | 123 PassRefPtr<Canvas2DLayerBridge> makeBridge( |
| 98 std::unique_ptr<FakeWebGraphicsContext3DProvider> provider, | 124 std::unique_ptr<FakeWebGraphicsContext3DProvider> provider, |
| 99 const IntSize& size, | 125 const IntSize& size, |
| 100 Canvas2DLayerBridge::AccelerationMode accelerationMode) { | 126 Canvas2DLayerBridge::AccelerationMode accelerationMode) { |
| 101 RefPtr<Canvas2DLayerBridge> bridge = adoptRef( | 127 RefPtr<Canvas2DLayerBridge> bridge = adoptRef( |
| 102 new Canvas2DLayerBridge(std::move(provider), size, 0, NonOpaque, | 128 new Canvas2DLayerBridge(std::move(provider), size, 0, NonOpaque, |
| (...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 1240 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 1215 EXPECT_FALSE( | 1241 EXPECT_FALSE( |
| 1216 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); | 1242 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); |
| 1217 EXPECT_TRUE(bridge->checkSurfaceValid()); | 1243 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 1218 | 1244 |
| 1219 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 1245 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
| 1220 // without crashing due to thread checks | 1246 // without crashing due to thread checks |
| 1221 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 1247 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 1222 } | 1248 } |
| 1223 | 1249 |
| 1250 #if USE_IOSURFACE_FOR_2D_CANVAS |
| 1251 TEST_F(Canvas2DLayerBridgeTest, DeleteIOSurfaceAfterTeardown) |
| 1252 #else |
| 1253 TEST_F(Canvas2DLayerBridgeTest, DISABLED_DeleteIOSurfaceAfterTeardown) |
| 1254 #endif |
| 1255 { |
| 1256 FakeGLES2InterfaceWithImageSupport gl; |
| 1257 FakePlatformSupport testingPlatformSupport; |
| 1258 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
| 1259 wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 1260 |
| 1261 cc::TextureMailbox textureMailbox; |
| 1262 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 1263 |
| 1264 { |
| 1265 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
| 1266 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
| 1267 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, |
| 1268 kN32_SkColorType))); |
| 1269 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback); |
| 1270 } |
| 1271 |
| 1272 bool lostResource = false; |
| 1273 releaseCallback->Run(gpu::SyncToken(), lostResource); |
| 1274 |
| 1275 EXPECT_EQ(1u, gl.createImageCount()); |
| 1276 EXPECT_EQ(1u, gl.destroyImageCount()); |
| 1277 } |
| 1278 |
| 1224 } // namespace blink | 1279 } // namespace blink |
| OLD | NEW |