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