| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/canvas2d/CanvasRenderingContext2D.h" | 5 #include "modules/canvas2d/CanvasRenderingContext2D.h" |
| 6 | 6 |
| 7 #include "core/fetch/MemoryCache.h" | 7 #include "core/fetch/MemoryCache.h" |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/ImageBitmap.h" | 9 #include "core/frame/ImageBitmap.h" |
| 10 #include "core/html/HTMLCanvasElement.h" | 10 #include "core/html/HTMLCanvasElement.h" |
| 11 #include "core/html/HTMLDocument.h" | 11 #include "core/html/HTMLDocument.h" |
| 12 #include "core/html/ImageData.h" | 12 #include "core/html/ImageData.h" |
| 13 #include "core/imagebitmap/ImageBitmapOptions.h" | 13 #include "core/imagebitmap/ImageBitmapOptions.h" |
| 14 #include "core/loader/EmptyClients.h" | 14 #include "core/loader/EmptyClients.h" |
| 15 #include "core/testing/DummyPageHolder.h" | 15 #include "core/testing/DummyPageHolder.h" |
| 16 #include "modules/canvas2d/CanvasGradient.h" | 16 #include "modules/canvas2d/CanvasGradient.h" |
| 17 #include "modules/canvas2d/CanvasPattern.h" | 17 #include "modules/canvas2d/CanvasPattern.h" |
| 18 #include "modules/webgl/WebGLRenderingContext.h" | 18 #include "modules/webgl/WebGLRenderingContext.h" |
| 19 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 19 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
| 20 #include "platform/graphics/RecordingImageBufferSurface.h" | 20 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 21 #include "platform/graphics/StaticBitmapImage.h" | 21 #include "platform/graphics/StaticBitmapImage.h" |
| 22 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 22 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "third_party/skia/include/core/SkSurface.h" | 25 #include "third_party/skia/include/core/SkSurface.h" |
| 26 #include "wtf/PtrUtil.h" | |
| 27 #include <memory> | |
| 28 | 26 |
| 29 using ::testing::Mock; | 27 using ::testing::Mock; |
| 30 | 28 |
| 31 namespace blink { | 29 namespace blink { |
| 32 | 30 |
| 33 enum BitmapOpacity { | 31 enum BitmapOpacity { |
| 34 OpaqueBitmap, | 32 OpaqueBitmap, |
| 35 TransparentBitmap | 33 TransparentBitmap |
| 36 }; | 34 }; |
| 37 | 35 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende
ringContext2D*>(canvasElement().renderingContext()); } | 81 CanvasRenderingContext2D* context2d() const { return static_cast<CanvasRende
ringContext2D*>(canvasElement().renderingContext()); } |
| 84 intptr_t getGlobalGPUMemoryUsage() const { return ImageBuffer::getGlobalGPUM
emoryUsage(); } | 82 intptr_t getGlobalGPUMemoryUsage() const { return ImageBuffer::getGlobalGPUM
emoryUsage(); } |
| 85 unsigned getGlobalAcceleratedImageBufferCount() const { return ImageBuffer::
getGlobalAcceleratedImageBufferCount(); } | 83 unsigned getGlobalAcceleratedImageBufferCount() const { return ImageBuffer::
getGlobalAcceleratedImageBufferCount(); } |
| 86 intptr_t getCurrentGPUMemoryUsage() const { return canvasElement().buffer()-
>getGPUMemoryUsage(); } | 84 intptr_t getCurrentGPUMemoryUsage() const { return canvasElement().buffer()-
>getGPUMemoryUsage(); } |
| 87 | 85 |
| 88 void createContext(OpacityMode); | 86 void createContext(OpacityMode); |
| 89 void TearDown(); | 87 void TearDown(); |
| 90 void unrefCanvas(); | 88 void unrefCanvas(); |
| 91 | 89 |
| 92 private: | 90 private: |
| 93 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 91 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 94 Persistent<HTMLDocument> m_document; | 92 Persistent<HTMLDocument> m_document; |
| 95 Persistent<HTMLCanvasElement> m_canvasElement; | 93 Persistent<HTMLCanvasElement> m_canvasElement; |
| 96 Persistent<MemoryCache> m_globalMemoryCache; | 94 Persistent<MemoryCache> m_globalMemoryCache; |
| 97 | 95 |
| 98 class WrapGradients final : public GarbageCollectedFinalized<WrapGradients>
{ | 96 class WrapGradients final : public GarbageCollectedFinalized<WrapGradients>
{ |
| 99 public: | 97 public: |
| 100 static WrapGradients* create() | 98 static WrapGradients* create() |
| 101 { | 99 { |
| 102 return new WrapGradients; | 100 return new WrapGradients; |
| 103 } | 101 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 MockImageBufferSurfaceForOverwriteTesting(const IntSize& size, OpacityMode m
ode) : UnacceleratedImageBufferSurface(size, mode) { } | 202 MockImageBufferSurfaceForOverwriteTesting(const IntSize& size, OpacityMode m
ode) : UnacceleratedImageBufferSurface(size, mode) { } |
| 205 ~MockImageBufferSurfaceForOverwriteTesting() override { } | 203 ~MockImageBufferSurfaceForOverwriteTesting() override { } |
| 206 bool isRecording() const override { return true; } // otherwise overwrites a
re not tracked | 204 bool isRecording() const override { return true; } // otherwise overwrites a
re not tracked |
| 207 | 205 |
| 208 MOCK_METHOD0(willOverwriteCanvas, void()); | 206 MOCK_METHOD0(willOverwriteCanvas, void()); |
| 209 }; | 207 }; |
| 210 | 208 |
| 211 //============================================================================ | 209 //============================================================================ |
| 212 | 210 |
| 213 #define TEST_OVERDRAW_SETUP(EXPECTED_OVERDRAWS) \ | 211 #define TEST_OVERDRAW_SETUP(EXPECTED_OVERDRAWS) \ |
| 214 std::unique_ptr<MockImageBufferSurfaceForOverwriteTesting> mockSurface =
wrapUnique(new MockImageBufferSurfaceForOverwriteTesting(IntSize(10, 10), NonOp
aque)); \ | 212 OwnPtr<MockImageBufferSurfaceForOverwriteTesting> mockSurface = adoptPtr
(new MockImageBufferSurfaceForOverwriteTesting(IntSize(10, 10), NonOpaque)); \ |
| 215 MockImageBufferSurfaceForOverwriteTesting* surfacePtr = mockSurface.get(
); \ | 213 MockImageBufferSurfaceForOverwriteTesting* surfacePtr = mockSurface.get(
); \ |
| 216 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(mockSu
rface)); \ | 214 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(mockSu
rface)); \ |
| 217 EXPECT_CALL(*surfacePtr, willOverwriteCanvas()).Times(EXPECTED_OVERDRAWS
); \ | 215 EXPECT_CALL(*surfacePtr, willOverwriteCanvas()).Times(EXPECTED_OVERDRAWS
); \ |
| 218 context2d()->save(); | 216 context2d()->save(); |
| 219 | 217 |
| 220 #define TEST_OVERDRAW_FINALIZE \ | 218 #define TEST_OVERDRAW_FINALIZE \ |
| 221 context2d()->restore(); \ | 219 context2d()->restore(); \ |
| 222 Mock::VerifyAndClearExpectations(surfacePtr); | 220 Mock::VerifyAndClearExpectations(surfacePtr); |
| 223 | 221 |
| 224 #define TEST_OVERDRAW_1(EXPECTED_OVERDRAWS, CALL1) \ | 222 #define TEST_OVERDRAW_1(EXPECTED_OVERDRAWS, CALL1) \ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } while (0) | 254 } while (0) |
| 257 | 255 |
| 258 //============================================================================ | 256 //============================================================================ |
| 259 | 257 |
| 260 class MockSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory { | 258 class MockSurfaceFactory : public RecordingImageBufferFallbackSurfaceFactory { |
| 261 public: | 259 public: |
| 262 enum FallbackExpectation { | 260 enum FallbackExpectation { |
| 263 ExpectFallback, | 261 ExpectFallback, |
| 264 ExpectNoFallback | 262 ExpectNoFallback |
| 265 }; | 263 }; |
| 266 static std::unique_ptr<MockSurfaceFactory> create(FallbackExpectation expect
ation) { return wrapUnique(new MockSurfaceFactory(expectation)); } | 264 static PassOwnPtr<MockSurfaceFactory> create(FallbackExpectation expectation
) { return adoptPtr(new MockSurfaceFactory(expectation)); } |
| 267 | 265 |
| 268 std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& size, Opaci
tyMode mode) override | 266 PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, OpacityMod
e mode) override |
| 269 { | 267 { |
| 270 EXPECT_EQ(ExpectFallback, m_expectation); | 268 EXPECT_EQ(ExpectFallback, m_expectation); |
| 271 m_didFallback = true; | 269 m_didFallback = true; |
| 272 return wrapUnique(new UnacceleratedImageBufferSurface(size, mode)); | 270 return adoptPtr(new UnacceleratedImageBufferSurface(size, mode)); |
| 273 } | 271 } |
| 274 | 272 |
| 275 ~MockSurfaceFactory() override | 273 ~MockSurfaceFactory() override |
| 276 { | 274 { |
| 277 if (m_expectation == ExpectFallback) { | 275 if (m_expectation == ExpectFallback) { |
| 278 EXPECT_TRUE(m_didFallback); | 276 EXPECT_TRUE(m_didFallback); |
| 279 } | 277 } |
| 280 } | 278 } |
| 281 | 279 |
| 282 private: | 280 private: |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // Test composite operators with an opaque rect that does not cover the enti
re canvas | 400 // Test composite operators with an opaque rect that does not cover the enti
re canvas |
| 403 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("clear")), fillRect(0,
0, 5, 5)); | 401 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("clear")), fillRect(0,
0, 5, 5)); |
| 404 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), fillRect(0,
0, 5, 5)); | 402 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), fillRect(0,
0, 5, 5)); |
| 405 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), fillR
ect(0, 0, 5, 5)); | 403 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), fillR
ect(0, 0, 5, 5)); |
| 406 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), fillRec
t(0, 0, 5, 5)); | 404 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), fillRec
t(0, 0, 5, 5)); |
| 407 } | 405 } |
| 408 | 406 |
| 409 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionByDefault) | 407 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionByDefault) |
| 410 { | 408 { |
| 411 createContext(NonOpaque); | 409 createContext(NonOpaque); |
| 412 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 410 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 413 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 411 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 414 | 412 |
| 415 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 413 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 416 } | 414 } |
| 417 | 415 |
| 418 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderOverdrawLimit) | 416 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderOverdrawLimit) |
| 419 { | 417 { |
| 420 createContext(NonOpaque); | 418 createContext(NonOpaque); |
| 421 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 419 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 422 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 420 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 423 | 421 |
| 424 context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization | 422 context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization |
| 425 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveOverdrawThr
eshold - 1; i++) { | 423 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveOverdrawThr
eshold - 1; i++) { |
| 426 context2d()->fillRect(0, 0, 10, 10); | 424 context2d()->fillRect(0, 0, 10, 10); |
| 427 } | 425 } |
| 428 | 426 |
| 429 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 427 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 430 } | 428 } |
| 431 | 429 |
| 432 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverOverdrawLimit) | 430 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverOverdrawLimit) |
| 433 { | 431 { |
| 434 createContext(NonOpaque); | 432 createContext(NonOpaque); |
| 435 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 433 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 436 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 434 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 437 | 435 |
| 438 context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization | 436 context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization |
| 439 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveOverdrawThr
eshold; i++) { | 437 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveOverdrawThr
eshold; i++) { |
| 440 context2d()->fillRect(0, 0, 10, 10); | 438 context2d()->fillRect(0, 0, 10, 10); |
| 441 } | 439 } |
| 442 | 440 |
| 443 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 441 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
| 444 } | 442 } |
| 445 | 443 |
| 446 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderImageSizeRatioLimit) | 444 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderImageSizeRatioLimit) |
| 447 { | 445 { |
| 448 createContext(NonOpaque); | 446 createContext(NonOpaque); |
| 449 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 447 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 450 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 448 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 451 | 449 |
| 452 NonThrowableExceptionState exceptionState; | 450 NonThrowableExceptionState exceptionState; |
| 453 Element* sourceCanvasElement = document().createElement("canvas", exceptionS
tate); | 451 Element* sourceCanvasElement = document().createElement("canvas", exceptionS
tate); |
| 454 EXPECT_FALSE(exceptionState.hadException()); | 452 EXPECT_FALSE(exceptionState.hadException()); |
| 455 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv
asElement); | 453 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv
asElement); |
| 456 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma
geSizeRatio); | 454 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma
geSizeRatio); |
| 457 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = wrapUnique(
new UnacceleratedImageBufferSurface(sourceSize, NonOpaque)); | 455 OwnPtr<UnacceleratedImageBufferSurface> sourceSurface = adoptPtr(new Unaccel
eratedImageBufferSurface(sourceSize, NonOpaque)); |
| 458 sourceCanvas->createImageBufferUsingSurfaceForTesting(std::move(sourceSurfac
e)); | 456 sourceCanvas->createImageBufferUsingSurfaceForTesting(std::move(sourceSurfac
e)); |
| 459 | 457 |
| 460 const ImageBitmapOptions defaultOptions; | 458 const ImageBitmapOptions defaultOptions; |
| 461 // Go through an ImageBitmap to avoid triggering a display list fallback | 459 // Go through an ImageBitmap to avoid triggering a display list fallback |
| 462 ImageBitmap* sourceImageBitmap = ImageBitmap::create(sourceCanvas, IntRect(I
ntPoint(0, 0), sourceSize), defaultOptions); | 460 ImageBitmap* sourceImageBitmap = ImageBitmap::create(sourceCanvas, IntRect(I
ntPoint(0, 0), sourceSize), defaultOptions); |
| 463 | 461 |
| 464 context2d()->drawImage(canvasElement().getExecutionContext(), sourceImageBit
map, 0, 0, 1, 1, 0, 0, 1, 1, exceptionState); | 462 context2d()->drawImage(canvasElement().getExecutionContext(), sourceImageBit
map, 0, 0, 1, 1, 0, 0, 1, 1, exceptionState); |
| 465 EXPECT_FALSE(exceptionState.hadException()); | 463 EXPECT_FALSE(exceptionState.hadException()); |
| 466 | 464 |
| 467 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 465 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 468 } | 466 } |
| 469 | 467 |
| 470 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) | 468 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) |
| 471 { | 469 { |
| 472 createContext(NonOpaque); | 470 createContext(NonOpaque); |
| 473 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 471 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 474 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 472 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 475 | 473 |
| 476 NonThrowableExceptionState exceptionState; | 474 NonThrowableExceptionState exceptionState; |
| 477 Element* sourceCanvasElement = document().createElement("canvas", exceptionS
tate); | 475 Element* sourceCanvasElement = document().createElement("canvas", exceptionS
tate); |
| 478 EXPECT_FALSE(exceptionState.hadException()); | 476 EXPECT_FALSE(exceptionState.hadException()); |
| 479 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv
asElement); | 477 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv
asElement); |
| 480 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma
geSizeRatio + 1); | 478 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma
geSizeRatio + 1); |
| 481 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = wrapUnique(
new UnacceleratedImageBufferSurface(sourceSize, NonOpaque)); | 479 OwnPtr<UnacceleratedImageBufferSurface> sourceSurface = adoptPtr(new Unaccel
eratedImageBufferSurface(sourceSize, NonOpaque)); |
| 482 sourceCanvas->createImageBufferUsingSurfaceForTesting(std::move(sourceSurfac
e)); | 480 sourceCanvas->createImageBufferUsingSurfaceForTesting(std::move(sourceSurfac
e)); |
| 483 | 481 |
| 484 const ImageBitmapOptions defaultOptions; | 482 const ImageBitmapOptions defaultOptions; |
| 485 // Go through an ImageBitmap to avoid triggering a display list fallback | 483 // Go through an ImageBitmap to avoid triggering a display list fallback |
| 486 ImageBitmap* sourceImageBitmap = ImageBitmap::create(sourceCanvas, IntRect(I
ntPoint(0, 0), sourceSize), defaultOptions); | 484 ImageBitmap* sourceImageBitmap = ImageBitmap::create(sourceCanvas, IntRect(I
ntPoint(0, 0), sourceSize), defaultOptions); |
| 487 | 485 |
| 488 context2d()->drawImage(canvasElement().getExecutionContext(), sourceImageBit
map, 0, 0, 1, 1, 0, 0, 1, 1, exceptionState); | 486 context2d()->drawImage(canvasElement().getExecutionContext(), sourceImageBit
map, 0, 0, 1, 1, 0, 0, 1, 1, exceptionState); |
| 489 EXPECT_FALSE(exceptionState.hadException()); | 487 EXPECT_FALSE(exceptionState.hadException()); |
| 490 | 488 |
| 491 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 489 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
| 492 } | 490 } |
| 493 | 491 |
| 494 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderExpensivePathPointCoun
t) | 492 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderExpensivePathPointCoun
t) |
| 495 { | 493 { |
| 496 createContext(NonOpaque); | 494 createContext(NonOpaque); |
| 497 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 495 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 498 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 496 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 499 | 497 |
| 500 context2d()->beginPath(); | 498 context2d()->beginPath(); |
| 501 context2d()->moveTo(7, 5); | 499 context2d()->moveTo(7, 5); |
| 502 for (int i = 1; i < ExpensiveCanvasHeuristicParameters::ExpensivePathPointCo
unt-1; i++) { | 500 for (int i = 1; i < ExpensiveCanvasHeuristicParameters::ExpensivePathPointCo
unt-1; i++) { |
| 503 float angleRad = twoPiFloat * i / (ExpensiveCanvasHeuristicParameters::E
xpensivePathPointCount - 1); | 501 float angleRad = twoPiFloat * i / (ExpensiveCanvasHeuristicParameters::E
xpensivePathPointCount - 1); |
| 504 context2d()->lineTo(5 + 2 * cos(angleRad), 5 + 2 * sin(angleRad)); | 502 context2d()->lineTo(5 + 2 * cos(angleRad), 5 + 2 * sin(angleRad)); |
| 505 } | 503 } |
| 506 context2d()->fill(); | 504 context2d()->fill(); |
| 507 | 505 |
| 508 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 506 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 509 } | 507 } |
| 510 | 508 |
| 511 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverExpensivePathPointCount) | 509 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverExpensivePathPointCount) |
| 512 { | 510 { |
| 513 createContext(NonOpaque); | 511 createContext(NonOpaque); |
| 514 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 512 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 515 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 513 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 516 | 514 |
| 517 context2d()->beginPath(); | 515 context2d()->beginPath(); |
| 518 context2d()->moveTo(7, 5); | 516 context2d()->moveTo(7, 5); |
| 519 for (int i = 1; i < ExpensiveCanvasHeuristicParameters::ExpensivePathPointCo
unt + 1; i++) { | 517 for (int i = 1; i < ExpensiveCanvasHeuristicParameters::ExpensivePathPointCo
unt + 1; i++) { |
| 520 float angleRad = twoPiFloat * i / (ExpensiveCanvasHeuristicParameters::E
xpensivePathPointCount + 1); | 518 float angleRad = twoPiFloat * i / (ExpensiveCanvasHeuristicParameters::E
xpensivePathPointCount + 1); |
| 521 context2d()->lineTo(5 + 2 * cos(angleRad), 5 + 2 * sin(angleRad)); | 519 context2d()->lineTo(5 + 2 * cos(angleRad), 5 + 2 * sin(angleRad)); |
| 522 } | 520 } |
| 523 context2d()->fill(); | 521 context2d()->fill(); |
| 524 | 522 |
| 525 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 523 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
| 526 } | 524 } |
| 527 | 525 |
| 528 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWhenPathIsConcave) | 526 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWhenPathIsConcave) |
| 529 { | 527 { |
| 530 createContext(NonOpaque); | 528 createContext(NonOpaque); |
| 531 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 529 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 532 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 530 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 533 | 531 |
| 534 context2d()->beginPath(); | 532 context2d()->beginPath(); |
| 535 context2d()->moveTo(1, 1); | 533 context2d()->moveTo(1, 1); |
| 536 context2d()->lineTo(5, 5); | 534 context2d()->lineTo(5, 5); |
| 537 context2d()->lineTo(9, 1); | 535 context2d()->lineTo(9, 1); |
| 538 context2d()->lineTo(5, 9); | 536 context2d()->lineTo(5, 9); |
| 539 context2d()->fill(); | 537 context2d()->fill(); |
| 540 | 538 |
| 541 if (ExpensiveCanvasHeuristicParameters::ConcavePathsAreExpensive) { | 539 if (ExpensiveCanvasHeuristicParameters::ConcavePathsAreExpensive) { |
| 542 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 540 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
| 543 } else { | 541 } else { |
| 544 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 542 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 545 } | 543 } |
| 546 } | 544 } |
| 547 | 545 |
| 548 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithRectangleClip) | 546 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithRectangleClip) |
| 549 { | 547 { |
| 550 createContext(NonOpaque); | 548 createContext(NonOpaque); |
| 551 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 549 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 552 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 550 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 553 | 551 |
| 554 context2d()->beginPath(); | 552 context2d()->beginPath(); |
| 555 context2d()->rect(1, 1, 2, 2); | 553 context2d()->rect(1, 1, 2, 2); |
| 556 context2d()->clip(); | 554 context2d()->clip(); |
| 557 context2d()->fillRect(0, 0, 4, 4); | 555 context2d()->fillRect(0, 0, 4, 4); |
| 558 | 556 |
| 559 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 557 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 560 } | 558 } |
| 561 | 559 |
| 562 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithComplexClip) | 560 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithComplexClip) |
| 563 { | 561 { |
| 564 createContext(NonOpaque); | 562 createContext(NonOpaque); |
| 565 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 563 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 566 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 564 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 567 | 565 |
| 568 context2d()->beginPath(); | 566 context2d()->beginPath(); |
| 569 context2d()->moveTo(1, 1); | 567 context2d()->moveTo(1, 1); |
| 570 context2d()->lineTo(5, 5); | 568 context2d()->lineTo(5, 5); |
| 571 context2d()->lineTo(9, 1); | 569 context2d()->lineTo(9, 1); |
| 572 context2d()->lineTo(5, 9); | 570 context2d()->lineTo(5, 9); |
| 573 context2d()->clip(); | 571 context2d()->clip(); |
| 574 context2d()->fillRect(0, 0, 4, 4); | 572 context2d()->fillRect(0, 0, 4, 4); |
| 575 | 573 |
| 576 if (ExpensiveCanvasHeuristicParameters::ComplexClipsAreExpensive) { | 574 if (ExpensiveCanvasHeuristicParameters::ComplexClipsAreExpensive) { |
| 577 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 575 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
| 578 } else { | 576 } else { |
| 579 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 577 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 580 } | 578 } |
| 581 } | 579 } |
| 582 | 580 |
| 583 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithBlurredShadow) | 581 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithBlurredShadow) |
| 584 { | 582 { |
| 585 createContext(NonOpaque); | 583 createContext(NonOpaque); |
| 586 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 584 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 587 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 585 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 588 | 586 |
| 589 context2d()->setShadowColor(String("red")); | 587 context2d()->setShadowColor(String("red")); |
| 590 context2d()->setShadowBlur(1.0f); | 588 context2d()->setShadowBlur(1.0f); |
| 591 context2d()->fillRect(1, 1, 1, 1); | 589 context2d()->fillRect(1, 1, 1, 1); |
| 592 | 590 |
| 593 if (ExpensiveCanvasHeuristicParameters::BlurredShadowsAreExpensive) { | 591 if (ExpensiveCanvasHeuristicParameters::BlurredShadowsAreExpensive) { |
| 594 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 592 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
| 595 } else { | 593 } else { |
| 596 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 594 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 597 } | 595 } |
| 598 } | 596 } |
| 599 | 597 |
| 600 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithSharpShadow) | 598 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithSharpShadow) |
| 601 { | 599 { |
| 602 createContext(NonOpaque); | 600 createContext(NonOpaque); |
| 603 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 601 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 604 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 602 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 605 | 603 |
| 606 context2d()->setShadowColor(String("red")); | 604 context2d()->setShadowColor(String("red")); |
| 607 context2d()->setShadowOffsetX(1.0f); | 605 context2d()->setShadowOffsetX(1.0f); |
| 608 context2d()->fillRect(1, 1, 1, 1); | 606 context2d()->fillRect(1, 1, 1, 1); |
| 609 | 607 |
| 610 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 608 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
| 611 } | 609 } |
| 612 | 610 |
| 613 TEST_F(CanvasRenderingContext2DTest, NoFallbackWithSmallState) | 611 TEST_F(CanvasRenderingContext2DTest, NoFallbackWithSmallState) |
| 614 { | 612 { |
| 615 createContext(NonOpaque); | 613 createContext(NonOpaque); |
| 616 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 614 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 617 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 615 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 618 | 616 |
| 619 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect | 617 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect |
| 620 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth - 1; ++i) { | 618 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth - 1; ++i) { |
| 621 context2d()->save(); | 619 context2d()->save(); |
| 622 context2d()->translate(1.0f, 0.0f); | 620 context2d()->translate(1.0f, 0.0f); |
| 623 } | 621 } |
| 624 canvasElement().doDeferredPaintInvalidation(); // To close the current frame | 622 canvasElement().doDeferredPaintInvalidation(); // To close the current frame |
| 625 } | 623 } |
| 626 | 624 |
| 627 TEST_F(CanvasRenderingContext2DTest, FallbackWithLargeState) | 625 TEST_F(CanvasRenderingContext2DTest, FallbackWithLargeState) |
| 628 { | 626 { |
| 629 createContext(NonOpaque); | 627 createContext(NonOpaque); |
| 630 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectFallback), NonOpaque)); | 628 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tFallback), NonOpaque)); |
| 631 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 629 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 632 | 630 |
| 633 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect | 631 context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect |
| 634 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth; ++i) { | 632 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth; ++i) { |
| 635 context2d()->save(); | 633 context2d()->save(); |
| 636 context2d()->translate(1.0f, 0.0f); | 634 context2d()->translate(1.0f, 0.0f); |
| 637 } | 635 } |
| 638 canvasElement().doDeferredPaintInvalidation(); // To close the current frame | 636 canvasElement().doDeferredPaintInvalidation(); // To close the current frame |
| 639 } | 637 } |
| 640 | 638 |
| 641 TEST_F(CanvasRenderingContext2DTest, OpaqueDisplayListFallsBackForText) | 639 TEST_F(CanvasRenderingContext2DTest, OpaqueDisplayListFallsBackForText) |
| 642 { | 640 { |
| 643 // Verify that drawing text to an opaque canvas, which is expected to | 641 // Verify that drawing text to an opaque canvas, which is expected to |
| 644 // render with subpixel text anti-aliasing, results in falling out | 642 // render with subpixel text anti-aliasing, results in falling out |
| 645 // of display list mode because the current diplay list implementation | 643 // of display list mode because the current diplay list implementation |
| 646 // does not support pixel geometry settings. | 644 // does not support pixel geometry settings. |
| 647 // See: crbug.com/583809 | 645 // See: crbug.com/583809 |
| 648 createContext(Opaque); | 646 createContext(Opaque); |
| 649 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectFallback), Opaque)); | 647 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tFallback), Opaque)); |
| 650 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 648 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 651 | 649 |
| 652 context2d()->fillText("Text", 0, 5); | 650 context2d()->fillText("Text", 0, 5); |
| 653 } | 651 } |
| 654 | 652 |
| 655 TEST_F(CanvasRenderingContext2DTest, NonOpaqueDisplayListDoesNotFallBackForText) | 653 TEST_F(CanvasRenderingContext2DTest, NonOpaqueDisplayListDoesNotFallBackForText) |
| 656 { | 654 { |
| 657 createContext(NonOpaque); | 655 createContext(NonOpaque); |
| 658 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record
ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac
tory::ExpectNoFallback), NonOpaque)); | 656 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf
ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec
tNoFallback), NonOpaque)); |
| 659 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); | 657 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); |
| 660 | 658 |
| 661 context2d()->fillText("Text", 0, 5); | 659 context2d()->fillText("Text", 0, 5); |
| 662 } | 660 } |
| 663 | 661 |
| 664 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime) | 662 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime) |
| 665 { | 663 { |
| 666 NonThrowableExceptionState nonThrowableExceptionState; | 664 NonThrowableExceptionState nonThrowableExceptionState; |
| 667 Element* canvasElement = document().createElement("canvas", nonThrowableExce
ptionState); | 665 Element* canvasElement = document().createElement("canvas", nonThrowableExce
ptionState); |
| 668 EXPECT_FALSE(nonThrowableExceptionState.hadException()); | 666 EXPECT_FALSE(nonThrowableExceptionState.hadException()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 680 TrackExceptionState exceptionState; | 678 TrackExceptionState exceptionState; |
| 681 CanvasImageSourceUnion imageSource; | 679 CanvasImageSourceUnion imageSource; |
| 682 imageSource.setImageBitmap(imageBitmapDerived); | 680 imageSource.setImageBitmap(imageBitmapDerived); |
| 683 context->drawImage(canvas->getExecutionContext(), imageSource, 0, 0, excepti
onState); | 681 context->drawImage(canvas->getExecutionContext(), imageSource, 0, 0, excepti
onState); |
| 684 } | 682 } |
| 685 | 683 |
| 686 TEST_F(CanvasRenderingContext2DTest, GPUMemoryUpdateForAcceleratedCanvas) | 684 TEST_F(CanvasRenderingContext2DTest, GPUMemoryUpdateForAcceleratedCanvas) |
| 687 { | 685 { |
| 688 createContext(NonOpaque); | 686 createContext(NonOpaque); |
| 689 | 687 |
| 690 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS
urface = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10,
10), NonOpaque)); | 688 OwnPtr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateSurface =
adoptPtr(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10, 10), NonOpa
que)); |
| 691 FakeAcceleratedImageBufferSurfaceForTesting* fakeAccelerateSurfacePtr = fake
AccelerateSurface.get(); | 689 FakeAcceleratedImageBufferSurfaceForTesting* fakeAccelerateSurfacePtr = fake
AccelerateSurface.get(); |
| 692 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele
rateSurface)); | 690 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(fakeAccele
rateSurface)); |
| 693 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per p
ixel per buffer, | 691 // 800 = 10 * 10 * 4 * 2 where 10*10 is canvas size, 4 is num of bytes per p
ixel per buffer, |
| 694 // and 2 is an estimate of num of gpu buffers required | 692 // and 2 is an estimate of num of gpu buffers required |
| 695 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 693 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
| 696 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 694 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
| 697 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 695 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 698 | 696 |
| 699 // Switching accelerated mode to non-accelerated mode | 697 // Switching accelerated mode to non-accelerated mode |
| 700 fakeAccelerateSurfacePtr->setIsAccelerated(false); | 698 fakeAccelerateSurfacePtr->setIsAccelerated(false); |
| 701 canvasElement().buffer()->updateGPUMemoryUsage(); | 699 canvasElement().buffer()->updateGPUMemoryUsage(); |
| 702 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); | 700 EXPECT_EQ(0, getCurrentGPUMemoryUsage()); |
| 703 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 701 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
| 704 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); | 702 EXPECT_EQ(0u, getGlobalAcceleratedImageBufferCount()); |
| 705 | 703 |
| 706 // Switching non-accelerated mode to accelerated mode | 704 // Switching non-accelerated mode to accelerated mode |
| 707 fakeAccelerateSurfacePtr->setIsAccelerated(true); | 705 fakeAccelerateSurfacePtr->setIsAccelerated(true); |
| 708 canvasElement().buffer()->updateGPUMemoryUsage(); | 706 canvasElement().buffer()->updateGPUMemoryUsage(); |
| 709 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 707 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
| 710 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); | 708 EXPECT_EQ(800, getGlobalGPUMemoryUsage()); |
| 711 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 709 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 712 | 710 |
| 713 // Creating a different accelerated image buffer | 711 // Creating a different accelerated image buffer |
| 714 std::unique_ptr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateS
urface2 = wrapUnique(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10,
5), NonOpaque)); | 712 OwnPtr<FakeAcceleratedImageBufferSurfaceForTesting> fakeAccelerateSurface2 =
adoptPtr(new FakeAcceleratedImageBufferSurfaceForTesting(IntSize(10, 5), NonOpa
que)); |
| 715 std::unique_ptr<ImageBuffer> imageBuffer2 = ImageBuffer::create(std::move(fa
keAccelerateSurface2)); | 713 OwnPtr<ImageBuffer> imageBuffer2 = ImageBuffer::create(std::move(fakeAcceler
ateSurface2)); |
| 716 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); | 714 EXPECT_EQ(800, getCurrentGPUMemoryUsage()); |
| 717 EXPECT_EQ(1200, getGlobalGPUMemoryUsage()); | 715 EXPECT_EQ(1200, getGlobalGPUMemoryUsage()); |
| 718 EXPECT_EQ(2u, getGlobalAcceleratedImageBufferCount()); | 716 EXPECT_EQ(2u, getGlobalAcceleratedImageBufferCount()); |
| 719 | 717 |
| 720 // Tear down the first image buffer that resides in current canvas element | 718 // Tear down the first image buffer that resides in current canvas element |
| 721 canvasElement().setSize(IntSize(20, 20)); | 719 canvasElement().setSize(IntSize(20, 20)); |
| 722 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); | 720 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); |
| 723 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); | 721 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); |
| 724 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); | 722 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); |
| 725 | 723 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 745 | 743 |
| 746 TEST_F(CanvasRenderingContext2DTest, ContextDisposedBeforeCanvas) | 744 TEST_F(CanvasRenderingContext2DTest, ContextDisposedBeforeCanvas) |
| 747 { | 745 { |
| 748 createContext(NonOpaque); | 746 createContext(NonOpaque); |
| 749 | 747 |
| 750 canvasElement().detachContext(); | 748 canvasElement().detachContext(); |
| 751 // Passes by not crashing later during teardown | 749 // Passes by not crashing later during teardown |
| 752 } | 750 } |
| 753 | 751 |
| 754 } // namespace blink | 752 } // namespace blink |
| OLD | NEW |