| 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 AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 | |
| 27 #include "platform/graphics/Canvas2DLayerBridge.h" | 26 #include "platform/graphics/Canvas2DLayerBridge.h" |
| 28 | 27 |
| 29 #include "SkDeferredCanvas.h" | 28 #include "SkDeferredCanvas.h" |
| 30 #include "SkSurface.h" | 29 #include "SkSurface.h" |
| 31 #include "platform/graphics/ImageBuffer.h" | 30 #include "platform/graphics/ImageBuffer.h" |
| 32 #include "platform/graphics/test/MockWebGraphicsContext3D.h" | 31 #include "platform/graphics/test/MockWebGraphicsContext3D.h" |
| 33 #include "public/platform/Platform.h" | 32 #include "public/platform/Platform.h" |
| 34 #include "public/platform/WebExternalBitmap.h" | 33 #include "public/platform/WebExternalBitmap.h" |
| 35 #include "public/platform/WebGraphicsContext3DProvider.h" | 34 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 36 #include "public/platform/WebThread.h" | 35 #include "public/platform/WebThread.h" |
| 37 #include "third_party/skia/include/core/SkDevice.h" | 36 #include "third_party/skia/include/core/SkDevice.h" |
| 38 #include "wtf/RefPtr.h" | 37 #include "wtf/RefPtr.h" |
| 39 | |
| 40 #include <gmock/gmock.h> | 38 #include <gmock/gmock.h> |
| 41 #include <gtest/gtest.h> | 39 #include <gtest/gtest.h> |
| 42 | 40 |
| 43 using namespace blink; | |
| 44 using testing::InSequence; | 41 using testing::InSequence; |
| 45 using testing::Return; | 42 using testing::Return; |
| 46 using testing::Test; | 43 using testing::Test; |
| 47 | 44 |
| 45 namespace blink { |
| 46 |
| 48 namespace { | 47 namespace { |
| 49 | 48 |
| 50 class MockCanvasContext : public MockWebGraphicsContext3D { | 49 class MockCanvasContext : public MockWebGraphicsContext3D { |
| 51 public: | 50 public: |
| 52 MOCK_METHOD0(flush, void(void)); | 51 MOCK_METHOD0(flush, void(void)); |
| 53 MOCK_METHOD0(createTexture, unsigned(void)); | 52 MOCK_METHOD0(createTexture, unsigned(void)); |
| 54 MOCK_METHOD1(deleteTexture, void(unsigned)); | 53 MOCK_METHOD1(deleteTexture, void(unsigned)); |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 class MockWebGraphicsContext3DProvider : public WebGraphicsContext3DProvider { | 56 class MockWebGraphicsContext3DProvider : public WebGraphicsContext3DProvider { |
| 58 public: | 57 public: |
| 59 MockWebGraphicsContext3DProvider(WebGraphicsContext3D* context3d) | 58 MockWebGraphicsContext3DProvider(WebGraphicsContext3D* context3d) |
| 60 : m_context3d(context3d) { } | 59 : m_context3d(context3d) { } |
| 61 | 60 |
| 62 WebGraphicsContext3D* context3d() | 61 WebGraphicsContext3D* context3d() override |
| 63 { | 62 { |
| 64 return m_context3d; | 63 return m_context3d; |
| 65 } | 64 } |
| 66 | 65 |
| 67 GrContext* grContext() | 66 GrContext* grContext() override |
| 68 { | 67 { |
| 69 return 0; | 68 return 0; |
| 70 } | 69 } |
| 71 | 70 |
| 72 private: | 71 private: |
| 73 WebGraphicsContext3D* m_context3d; | 72 WebGraphicsContext3D* m_context3d; |
| 74 }; | 73 }; |
| 75 | 74 |
| 76 class Canvas2DLayerBridgePtr { | 75 class Canvas2DLayerBridgePtr { |
| 77 public: | 76 public: |
| 78 Canvas2DLayerBridgePtr(PassRefPtr<Canvas2DLayerBridge> layerBridge) | 77 Canvas2DLayerBridgePtr(PassRefPtr<Canvas2DLayerBridge> layerBridge) |
| 79 : m_layerBridge(layerBridge) { } | 78 : m_layerBridge(layerBridge) { } |
| 80 | 79 |
| 81 ~Canvas2DLayerBridgePtr() | 80 ~Canvas2DLayerBridgePtr() |
| 82 { | 81 { |
| 83 m_layerBridge->beginDestruction(); | 82 m_layerBridge->beginDestruction(); |
| 84 } | 83 } |
| 85 | 84 |
| 86 Canvas2DLayerBridge* operator->() { return m_layerBridge.get(); } | 85 Canvas2DLayerBridge* operator->() { return m_layerBridge.get(); } |
| 87 Canvas2DLayerBridge* get() { return m_layerBridge.get(); } | 86 Canvas2DLayerBridge* get() { return m_layerBridge.get(); } |
| 88 | 87 |
| 89 private: | 88 private: |
| 90 RefPtr<Canvas2DLayerBridge> m_layerBridge; | 89 RefPtr<Canvas2DLayerBridge> m_layerBridge; |
| 91 }; | 90 }; |
| 92 | 91 |
| 93 class NullWebExternalBitmap : public WebExternalBitmap { | 92 class NullWebExternalBitmap : public WebExternalBitmap { |
| 94 public: | 93 public: |
| 95 virtual WebSize size() | 94 WebSize size() override |
| 96 { | 95 { |
| 97 return WebSize(); | 96 return WebSize(); |
| 98 } | 97 } |
| 99 | 98 |
| 100 virtual void setSize(WebSize) | 99 void setSize(WebSize) override |
| 101 { | 100 { |
| 102 } | 101 } |
| 103 | 102 |
| 104 virtual uint8* pixels() | 103 uint8* pixels() override |
| 105 { | 104 { |
| 106 return 0; | 105 return nullptr; |
| 107 } | 106 } |
| 108 }; | 107 }; |
| 109 | 108 |
| 110 } // namespace | 109 } // anonymous namespace |
| 111 | 110 |
| 112 class Canvas2DLayerBridgeTest : public Test { | 111 class Canvas2DLayerBridgeTest : public Test { |
| 113 protected: | 112 protected: |
| 114 void fullLifecycleTest() | 113 void fullLifecycleTest() |
| 115 { | 114 { |
| 116 MockCanvasContext mainMock; | 115 MockCanvasContext mainMock; |
| 117 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); | 116 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); |
| 118 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300,
150)); | 117 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300,
150)); |
| 119 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surf
ace.get())); | 118 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surf
ace.get())); |
| 120 | 119 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 bridge->prepareMailbox(&mailbox, 0); | 209 bridge->prepareMailbox(&mailbox, 0); |
| 211 rawBridge = bridge.get(); | 210 rawBridge = bridge.get(); |
| 212 } // bridge goes out of scope, but object is kept alive by self refe
rences | 211 } // bridge goes out of scope, but object is kept alive by self refe
rences |
| 213 // before fixing crbug.com/411864, the following line you cause a me
mory use after free | 212 // before fixing crbug.com/411864, the following line you cause a me
mory use after free |
| 214 // that sometimes causes a crash in normal builds and crashes consis
tently with ASAN. | 213 // that sometimes causes a crash in normal builds and crashes consis
tently with ASAN. |
| 215 rawBridge->mailboxReleased(mailbox, lostResource); // This should se
lf-destruct the bridge. | 214 rawBridge->mailboxReleased(mailbox, lostResource); // This should se
lf-destruct the bridge. |
| 216 } | 215 } |
| 217 } | 216 } |
| 218 }; | 217 }; |
| 219 | 218 |
| 220 namespace { | |
| 221 | |
| 222 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) | 219 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) |
| 223 { | 220 { |
| 224 fullLifecycleTest(); | 221 fullLifecycleTest(); |
| 225 } | 222 } |
| 226 | 223 |
| 227 TEST_F(Canvas2DLayerBridgeTest, testNoDrawOnContextLost) | 224 TEST_F(Canvas2DLayerBridgeTest, testNoDrawOnContextLost) |
| 228 { | 225 { |
| 229 noDrawOnContextLostTest(); | 226 noDrawOnContextLostTest(); |
| 230 } | 227 } |
| 231 | 228 |
| 232 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxWithBitmap) | 229 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxWithBitmap) |
| 233 { | 230 { |
| 234 prepareMailboxWithBitmapTest(); | 231 prepareMailboxWithBitmapTest(); |
| 235 } | 232 } |
| 236 | 233 |
| 237 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxAndLoseResource) | 234 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxAndLoseResource) |
| 238 { | 235 { |
| 239 prepareMailboxAndLoseResourceTest(); | 236 prepareMailboxAndLoseResourceTest(); |
| 240 } | 237 } |
| 241 | 238 |
| 242 } // namespace | 239 } // namespace blink |
| OLD | NEW |