| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 | 26 |
| 27 #include "platform/graphics/Canvas2DLayerBridge.h" | 27 #include "platform/graphics/Canvas2DLayerBridge.h" |
| 28 | 28 |
| 29 #include "SkDeferredCanvas.h" | 29 #include "SkDeferredCanvas.h" |
| 30 #include "SkSurface.h" | 30 #include "SkSurface.h" |
| 31 #include "platform/graphics/ImageBuffer.h" | 31 #include "platform/graphics/ImageBuffer.h" |
| 32 #include "public/platform/Platform.h" | 32 #include "public/platform/Platform.h" |
| 33 #include "public/platform/WebExternalBitmap.h" |
| 33 #include "public/platform/WebGraphicsContext3DProvider.h" | 34 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 34 #include "public/platform/WebThread.h" | 35 #include "public/platform/WebThread.h" |
| 35 #include "third_party/skia/include/core/SkDevice.h" | 36 #include "third_party/skia/include/core/SkDevice.h" |
| 36 #include "web/tests/MockWebGraphicsContext3D.h" | 37 #include "web/tests/MockWebGraphicsContext3D.h" |
| 37 #include "wtf/RefPtr.h" | 38 #include "wtf/RefPtr.h" |
| 38 | 39 |
| 39 #include <gmock/gmock.h> | 40 #include <gmock/gmock.h> |
| 40 #include <gtest/gtest.h> | 41 #include <gtest/gtest.h> |
| 41 | 42 |
| 42 using namespace WebCore; | 43 using namespace WebCore; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 m_layerBridge->beginDestruction(); | 84 m_layerBridge->beginDestruction(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 Canvas2DLayerBridge* operator->() { return m_layerBridge.get(); } | 87 Canvas2DLayerBridge* operator->() { return m_layerBridge.get(); } |
| 87 Canvas2DLayerBridge* get() { return m_layerBridge.get(); } | 88 Canvas2DLayerBridge* get() { return m_layerBridge.get(); } |
| 88 | 89 |
| 89 private: | 90 private: |
| 90 RefPtr<Canvas2DLayerBridge> m_layerBridge; | 91 RefPtr<Canvas2DLayerBridge> m_layerBridge; |
| 91 }; | 92 }; |
| 92 | 93 |
| 94 class NullWebExternalBitmap : public WebExternalBitmap { |
| 95 public: |
| 96 virtual WebSize size() |
| 97 { |
| 98 return WebSize(); |
| 99 } |
| 100 |
| 101 virtual void setSize(WebSize) |
| 102 { |
| 103 } |
| 104 |
| 105 virtual uint8* pixels() |
| 106 { |
| 107 return 0; |
| 108 } |
| 109 }; |
| 110 |
| 93 } // namespace | 111 } // namespace |
| 94 | 112 |
| 95 class Canvas2DLayerBridgeTest : public Test { | 113 class Canvas2DLayerBridgeTest : public Test { |
| 96 protected: | 114 protected: |
| 97 void fullLifecycleTest() | 115 void fullLifecycleTest() |
| 98 { | 116 { |
| 99 MockCanvasContext mainMock; | 117 MockCanvasContext mainMock; |
| 100 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); | 118 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); |
| 101 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(SkSu
rface::NewRasterPMColor(300, 150))); | 119 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(SkSu
rface::NewRasterPMColor(300, 150))); |
| 102 | 120 |
| 103 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 121 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 104 | 122 |
| 105 { | 123 { |
| 106 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), canvas.release(), 0, NonOpaque))); | 124 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), canvas.release(), 0, NonOpaque))); |
| 107 | 125 |
| 108 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 126 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 109 | 127 |
| 110 EXPECT_CALL(mainMock, flush()); | 128 EXPECT_CALL(mainMock, flush()); |
| 111 unsigned textureId = bridge->getBackingTexture(); | 129 unsigned textureId = bridge->getBackingTexture(); |
| 112 EXPECT_EQ(textureId, 0u); | 130 EXPECT_EQ(textureId, 0u); |
| 113 | 131 |
| 114 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 132 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 115 } // bridge goes out of scope here | 133 } // bridge goes out of scope here |
| 116 | 134 |
| 117 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 135 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 118 } | 136 } |
| 137 |
| 138 void prepareMailboxWithBitmapTest() |
| 139 { |
| 140 MockCanvasContext mainMock; |
| 141 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(SkSu
rface::NewRasterPMColor(300, 150))); |
| 142 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); |
| 143 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockP
rovider.release(), canvas.release(), 0, NonOpaque))); |
| 144 bridge->m_lastImageId = 1; |
| 145 |
| 146 NullWebExternalBitmap bitmap; |
| 147 bridge->prepareMailbox(0, &bitmap); |
| 148 EXPECT_EQ(0u, bridge->m_lastImageId); |
| 149 } |
| 119 }; | 150 }; |
| 120 | 151 |
| 121 namespace { | 152 namespace { |
| 122 | 153 |
| 123 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) | 154 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) |
| 124 { | 155 { |
| 125 fullLifecycleTest(); | 156 fullLifecycleTest(); |
| 126 } | 157 } |
| 127 | 158 |
| 159 TEST_F(Canvas2DLayerBridgeTest, prepareMailboxWithBitmapTest) |
| 160 { |
| 161 prepareMailboxWithBitmapTest(); |
| 162 } |
| 163 |
| 128 } // namespace | 164 } // namespace |
| OLD | NEW |