Chromium Code Reviews| 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 |
| 133 void fallbackToSoftwareIfContextLost() | |
| 134 { | |
| 135 MockCanvasContext mainMock; | |
| 136 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock)); | |
| 137 | |
| 138 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 139 | |
| 140 { | |
| 141 mainMock.fakeContextLost(); | |
|
Stephen White
2015/09/23 14:13:26
I was actually hoping that we could test the fallb
| |
| 142 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration))); | |
| 143 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 144 EXPECT_TRUE(bridge->checkSurfaceValid()); | |
| 145 EXPECT_FALSE(bridge->isAccelerated()); | |
| 146 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 147 } | |
| 148 | |
| 149 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 150 } | |
| 151 | |
| 134 void noDrawOnContextLostTest() | 152 void noDrawOnContextLostTest() |
| 135 { | 153 { |
| 136 MockCanvasContext mainMock; | 154 MockCanvasContext mainMock; |
| 137 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock)); | 155 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock)); |
| 138 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300, 150)); | |
| 139 | 156 |
| 140 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 157 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 141 | 158 |
| 142 { | 159 { |
| 143 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), surface, 0, NonOpaque))); | 160 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::For ceAccelerationForTesting))); |
| 144 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 161 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 145 EXPECT_TRUE(bridge->checkSurfaceValid()); | 162 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 146 SkPaint paint; | 163 SkPaint paint; |
| 147 uint32_t genID = surface->generationID(); | 164 uint32_t genID = bridge->getOrCreateSurface()->generationID(); |
| 148 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 165 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 149 EXPECT_EQ(genID, surface->generationID()); | 166 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
| 150 mainMock.fakeContextLost(); | 167 mainMock.fakeContextLost(); |
| 151 EXPECT_EQ(genID, surface->generationID()); | 168 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
| 152 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 169 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 153 EXPECT_EQ(genID, surface->generationID()); | 170 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
| 154 EXPECT_FALSE(bridge->checkSurfaceValid()); | 171 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()); | 172 EXPECT_EQ(nullptr, bridge->getOrCreateSurface()); |
| 173 // The following passes by not crashing | |
| 156 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 174 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 157 EXPECT_EQ(genID, surface->generationID()); | |
| 158 bridge->flush(); | 175 bridge->flush(); |
| 159 EXPECT_EQ(genID, surface->generationID()); | |
| 160 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 176 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 161 } | 177 } |
| 162 | 178 |
| 163 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 179 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 164 } | 180 } |
| 165 | 181 |
| 166 void prepareMailboxWithBitmapTest() | 182 void prepareMailboxWithBitmapTest() |
| 167 { | 183 { |
| 168 MockCanvasContext mainMock; | 184 MockCanvasContext mainMock; |
| 169 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300, 150)); | |
| 170 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock)); | 185 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock)); |
| 171 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockP rovider.release(), surface, 0, NonOpaque))); | 186 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockP rovider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::ForceAc celerationForTesting))); |
| 172 bridge->m_lastImageId = 1; | 187 bridge->m_lastImageId = 1; |
| 173 | 188 |
| 174 NullWebExternalBitmap bitmap; | 189 NullWebExternalBitmap bitmap; |
| 175 bridge->prepareMailbox(0, &bitmap); | 190 bridge->prepareMailbox(0, &bitmap); |
| 176 EXPECT_EQ(0u, bridge->m_lastImageId); | 191 EXPECT_EQ(0u, bridge->m_lastImageId); |
| 177 } | 192 } |
| 178 | 193 |
| 179 void prepareMailboxAndLoseResourceTest() | 194 void prepareMailboxAndLoseResourceTest() |
| 180 { | 195 { |
| 181 MockCanvasContext mainMock; | 196 MockCanvasContext mainMock; |
| 182 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(300, 150)); | |
| 183 bool lostResource = true; | 197 bool lostResource = true; |
| 184 | 198 |
| 185 // Prepare a mailbox, then report the resource as lost. | 199 // Prepare a mailbox, then report the resource as lost. |
| 186 // This test passes by not crashing and not triggering assertions. | 200 // This test passes by not crashing and not triggering assertions. |
| 187 { | 201 { |
| 188 WebExternalTextureMailbox mailbox; | 202 WebExternalTextureMailbox mailbox; |
| 189 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); | 203 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); |
| 190 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), surface, 0, NonOpaque))); | 204 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::For ceAccelerationForTesting))); |
| 191 bridge->prepareMailbox(&mailbox, 0); | 205 bridge->prepareMailbox(&mailbox, 0); |
| 192 bridge->mailboxReleased(mailbox, lostResource); | 206 bridge->mailboxReleased(mailbox, lostResource); |
| 193 } | 207 } |
| 194 | 208 |
| 195 // Retry with mailbox released while bridge destruction is in progress | 209 // Retry with mailbox released while bridge destruction is in progress |
| 196 { | 210 { |
| 197 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); | 211 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); |
| 198 WebExternalTextureMailbox mailbox; | 212 WebExternalTextureMailbox mailbox; |
| 199 Canvas2DLayerBridge* rawBridge; | 213 Canvas2DLayerBridge* rawBridge; |
| 200 { | 214 { |
| 201 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(m ainMockProvider.release(), surface, 0, NonOpaque))); | 215 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(m ainMockProvider.release(), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge: :ForceAccelerationForTesting))); |
| 202 bridge->prepareMailbox(&mailbox, 0); | 216 bridge->prepareMailbox(&mailbox, 0); |
| 203 rawBridge = bridge.get(); | 217 rawBridge = bridge.get(); |
| 204 } // bridge goes out of scope, but object is kept alive by self refe rences | 218 } // 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 | 219 // 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. | 220 // 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. | 221 rawBridge->mailboxReleased(mailbox, lostResource); // This should se lf-destruct the bridge. |
| 208 } | 222 } |
| 209 } | 223 } |
| 224 | |
| 225 void accelerationHintTest() | |
| 226 { | |
| 227 MockCanvasContext mainMock; | |
| 228 { | |
| 229 | |
| 230 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); | |
| 231 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 232 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 300), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration))); | |
| 233 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 234 SkPaint paint; | |
| 235 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | |
| 236 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferAcceleration) ; | |
| 237 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 238 EXPECT_TRUE(bridge->checkSurfaceValid()); | |
| 239 EXPECT_TRUE(bridge->isAccelerated()); | |
| 240 } | |
| 241 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 242 | |
| 243 { | |
| 244 OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr (new MockWebGraphicsContext3DProvider(&mainMock)); | |
| 245 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 246 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainM ockProvider.release(), IntSize(300, 300), 0, NonOpaque, Canvas2DLayerBridge::Ena bleAcceleration))); | |
| 247 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 248 SkPaint paint; | |
| 249 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | |
| 250 RefPtr<SkImage> image = bridge->newImageSnapshot(PreferNoAcceleratio n); | |
| 251 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 252 EXPECT_TRUE(bridge->checkSurfaceValid()); | |
| 253 EXPECT_FALSE(bridge->isAccelerated()); | |
| 254 } | |
| 255 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | |
| 256 } | |
| 210 }; | 257 }; |
| 211 | 258 |
| 212 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) | 259 TEST_F(Canvas2DLayerBridgeTest, FullLifecycleSingleThreaded) |
| 213 { | 260 { |
| 214 fullLifecycleTest(); | 261 fullLifecycleTest(); |
| 215 } | 262 } |
| 216 | 263 |
| 217 TEST_F(Canvas2DLayerBridgeTest, testNoDrawOnContextLost) | 264 TEST_F(Canvas2DLayerBridgeTest, NoDrawOnContextLost) |
| 218 { | 265 { |
| 219 noDrawOnContextLostTest(); | 266 noDrawOnContextLostTest(); |
| 220 } | 267 } |
| 221 | 268 |
| 222 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxWithBitmap) | 269 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxWithBitmap) |
| 223 { | 270 { |
| 224 prepareMailboxWithBitmapTest(); | 271 prepareMailboxWithBitmapTest(); |
| 225 } | 272 } |
| 226 | 273 |
| 227 TEST_F(Canvas2DLayerBridgeTest, testPrepareMailboxAndLoseResource) | 274 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxAndLoseResource) |
| 228 { | 275 { |
| 229 prepareMailboxAndLoseResourceTest(); | 276 prepareMailboxAndLoseResourceTest(); |
| 230 } | 277 } |
| 231 | 278 |
| 279 TEST_F(Canvas2DLayerBridgeTest, AccelerationHint) | |
| 280 { | |
| 281 accelerationHintTest(); | |
| 282 } | |
| 283 | |
| 284 TEST_F(Canvas2DLayerBridgeTest, FallbackToSoftwareIfContextLost) | |
| 285 { | |
| 286 fallbackToSoftwareIfContextLost(); | |
| 287 } | |
| 288 | |
| 232 } // namespace blink | 289 } // namespace blink |
| OLD | NEW |