| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 } // anonymous namespace | 108 } // anonymous namespace |
| 109 | 109 |
| 110 class Canvas2DLayerBridgeTest : public Test { | 110 class Canvas2DLayerBridgeTest : public Test { |
| 111 protected: | 111 protected: |
| 112 void fullLifecycleTest() | 112 void fullLifecycleTest() |
| 113 { | 113 { |
| 114 MockCanvasContext mainMock; | 114 MockCanvasContext mainMock; |
| 115 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); | 115 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); |
| 116 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300,
150)); | |
| 117 | 116 |
| 118 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 117 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 119 | 118 |
| 120 { | 119 { |
| 121 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), surface, 0, NonOpaque))); | 120 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Dis
ableAcceleration))); |
| 122 | 121 |
| 123 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 122 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 124 | 123 |
| 125 unsigned textureId = bridge->newImageSnapshot()->getTextureHandle(tr
ue); | 124 unsigned textureId = bridge->newImageSnapshot(PreferAcceleration)->g
etTextureHandle(true); |
| 126 EXPECT_EQ(textureId, 0u); | 125 EXPECT_EQ(textureId, 0u); |
| 127 | 126 |
| 128 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 127 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 129 } // bridge goes out of scope here | 128 } // bridge goes out of scope here |
| 130 | 129 |
| 131 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 130 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 132 } | 131 } |
| 133 | 132 |
| 134 void noDrawOnContextLostTest() | 133 void noDrawOnContextLostTest() |
| 135 { | 134 { |
| 136 MockCanvasContext mainMock; | 135 MockCanvasContext mainMock; |
| 137 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); | 136 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); |
| 138 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300,
150)); | |
| 139 | 137 |
| 140 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 138 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 141 | 139 |
| 142 { | 140 { |
| 143 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), surface, 0, NonOpaque))); | 141 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Ena
bleAcceleration))); |
| 144 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 142 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 145 EXPECT_TRUE(bridge->checkSurfaceValid()); | 143 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 146 SkPaint paint; | 144 SkPaint paint; |
| 147 uint32_t genID = surface->generationID(); | 145 uint32_t genID = bridge->surface()->generationID(); |
| 148 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 146 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 149 EXPECT_EQ(genID, surface->generationID()); | 147 EXPECT_EQ(genID, bridge->surface()->generationID()); |
| 150 mainMock.fakeContextLost(); | 148 mainMock.fakeContextLost(); |
| 151 EXPECT_EQ(genID, surface->generationID()); | 149 EXPECT_EQ(genID, bridge->surface()->generationID()); |
| 152 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 150 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 153 EXPECT_EQ(genID, surface->generationID()); | 151 EXPECT_EQ(genID, bridge->surface()->generationID()); |
| 154 EXPECT_FALSE(bridge->checkSurfaceValid()); | 152 EXPECT_FALSE(bridge->checkSurfaceValid()); // This results in the in
ternal surface being torn down in response to the context loss |
| 155 EXPECT_EQ(genID, surface->generationID()); | 153 EXPECT_EQ(nullptr, bridge->surface()); |
| 154 // The following passes by not crashing |
| 156 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 155 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 157 EXPECT_EQ(genID, surface->generationID()); | |
| 158 bridge->flush(); | 156 bridge->flush(); |
| 159 EXPECT_EQ(genID, surface->generationID()); | |
| 160 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 157 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 161 } | 158 } |
| 162 | 159 |
| 163 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 160 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 164 } | 161 } |
| 165 | 162 |
| 166 void prepareMailboxWithBitmapTest() | 163 void prepareMailboxWithBitmapTest() |
| 167 { | 164 { |
| 168 MockCanvasContext mainMock; | 165 MockCanvasContext mainMock; |
| 169 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300,
150)); | |
| 170 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); | 166 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new
MockWebGraphicsContext3DProvider(&mainMock)); |
| 171 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockP
rovider.release(), surface, 0, NonOpaque))); | 167 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockP
rovider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::EnableA
cceleration))); |
| 172 bridge->m_lastImageId = 1; | 168 bridge->m_lastImageId = 1; |
| 173 | 169 |
| 174 NullWebExternalBitmap bitmap; | 170 NullWebExternalBitmap bitmap; |
| 175 bridge->prepareMailbox(0, &bitmap); | 171 bridge->prepareMailbox(0, &bitmap); |
| 176 EXPECT_EQ(0u, bridge->m_lastImageId); | 172 EXPECT_EQ(0u, bridge->m_lastImageId); |
| 177 } | 173 } |
| 178 | 174 |
| 179 void prepareMailboxAndLoseResourceTest() | 175 void prepareMailboxAndLoseResourceTest() |
| 180 { | 176 { |
| 181 MockCanvasContext mainMock; | 177 MockCanvasContext mainMock; |
| 182 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300,
150)); | |
| 183 bool lostResource = true; | 178 bool lostResource = true; |
| 184 | 179 |
| 185 // Prepare a mailbox, then report the resource as lost. | 180 // Prepare a mailbox, then report the resource as lost. |
| 186 // This test passes by not crashing and not triggering assertions. | 181 // This test passes by not crashing and not triggering assertions. |
| 187 { | 182 { |
| 188 WebExternalTextureMailbox mailbox; | 183 WebExternalTextureMailbox mailbox; |
| 189 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr
(new MockWebGraphicsContext3DProvider(&mainMock)); | 184 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr
(new MockWebGraphicsContext3DProvider(&mainMock)); |
| 190 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), surface, 0, NonOpaque))); | 185 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Ena
bleAcceleration))); |
| 191 bridge->prepareMailbox(&mailbox, 0); | 186 bridge->prepareMailbox(&mailbox, 0); |
| 192 bridge->mailboxReleased(mailbox, lostResource); | 187 bridge->mailboxReleased(mailbox, lostResource); |
| 193 } | 188 } |
| 194 | 189 |
| 195 // Retry with mailbox released while bridge destruction is in progress | 190 // Retry with mailbox released while bridge destruction is in progress |
| 196 { | 191 { |
| 197 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr
(new MockWebGraphicsContext3DProvider(&mainMock)); | 192 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr
(new MockWebGraphicsContext3DProvider(&mainMock)); |
| 198 WebExternalTextureMailbox mailbox; | 193 WebExternalTextureMailbox mailbox; |
| 199 Canvas2DLayerBridge* rawBridge; | 194 Canvas2DLayerBridge* rawBridge; |
| 200 { | 195 { |
| 201 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(m
ainMockProvider.release(), surface, 0, NonOpaque))); | 196 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(m
ainMockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge:
:EnableAcceleration))); |
| 202 bridge->prepareMailbox(&mailbox, 0); | 197 bridge->prepareMailbox(&mailbox, 0); |
| 203 rawBridge = bridge.get(); | 198 rawBridge = bridge.get(); |
| 204 } // bridge goes out of scope, but object is kept alive by self refe
rences | 199 } // bridge goes out of scope, but object is kept alive by self refe
rences |
| 205 // before fixing crbug.com/411864, the following line you cause a me
mory use after free | 200 // before fixing crbug.com/411864, the following line you cause a me
mory use after free |
| 206 // that sometimes causes a crash in normal builds and crashes consis
tently with ASAN. | 201 // that sometimes causes a crash in normal builds and crashes consis
tently with ASAN. |
| 207 rawBridge->mailboxReleased(mailbox, lostResource); // This should se
lf-destruct the bridge. | 202 rawBridge->mailboxReleased(mailbox, lostResource); // This should se
lf-destruct the bridge. |
| 208 } | 203 } |
| 209 } | 204 } |
| 205 |
| 206 void accelerationHintTest() |
| 207 { |
| 208 MockCanvasContext mainMock; |
| 209 { |
| 210 |
| 211 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr
(new MockWebGraphicsContext3DProvider(&mainMock)); |
| 212 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 213 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), IntSize(300, 300), 0, NonOpaque, Canvas2DLayerBridge::Ena
bleAcceleration))); |
| 214 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 215 SkPaint paint; |
| 216 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 217 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferAcceleration)
; |
| 218 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 219 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 220 EXPECT_TRUE(bridge->isAccelerated()); |
| 221 } |
| 222 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 223 |
| 224 { |
| 225 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr
(new MockWebGraphicsContext3DProvider(&mainMock)); |
| 226 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 227 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM
ockProvider.release(), IntSize(300, 300), 0, NonOpaque, Canvas2DLayerBridge::Ena
bleAcceleration))); |
| 228 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 229 SkPaint paint; |
| 230 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 231 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferNoAcceleratio
n); |
| 232 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 233 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 234 EXPECT_FALSE(bridge->isAccelerated()); |
| 235 } |
| 236 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 237 } |
| 210 }; | 238 }; |
| 211 | 239 |
| 212 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) | 240 TEST_F(Canvas2DLayerBridgeTest, FullLifecycleSingleThreaded) |
| 213 { | 241 { |
| 214 fullLifecycleTest(); | 242 fullLifecycleTest(); |
| 215 } | 243 } |
| 216 | 244 |
| 217 TEST_F(Canvas2DLayerBridgeTest, testNoDrawOnContextLost) | 245 TEST_F(Canvas2DLayerBridgeTest, NoDrawOnContextLost) |
| 218 { | 246 { |
| 219 noDrawOnContextLostTest(); | 247 noDrawOnContextLostTest(); |
| 220 } | 248 } |
| 221 | 249 |
| 222 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxWithBitmap) | 250 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxWithBitmap) |
| 223 { | 251 { |
| 224 prepareMailboxWithBitmapTest(); | 252 prepareMailboxWithBitmapTest(); |
| 225 } | 253 } |
| 226 | 254 |
| 227 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxAndLoseResource) | 255 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxAndLoseResource) |
| 228 { | 256 { |
| 229 prepareMailboxAndLoseResourceTest(); | 257 prepareMailboxAndLoseResourceTest(); |
| 230 } | 258 } |
| 231 | 259 |
| 260 TEST_F(Canvas2DLayerBridgeTest, AccelerationHint) |
| 261 { |
| 262 accelerationHintTest(); |
| 263 } |
| 264 |
| 232 } // namespace blink | 265 } // namespace blink |
| OLD | NEW |