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/loader/EmptyClients.h" | 14 #include "core/loader/EmptyClients.h" |
14 #include "core/testing/DummyPageHolder.h" | 15 #include "core/testing/DummyPageHolder.h" |
15 #include "modules/canvas2d/CanvasGradient.h" | 16 #include "modules/canvas2d/CanvasGradient.h" |
16 #include "modules/canvas2d/CanvasPattern.h" | 17 #include "modules/canvas2d/CanvasPattern.h" |
17 #include "modules/webgl/WebGLRenderingContext.h" | 18 #include "modules/webgl/WebGLRenderingContext.h" |
18 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 19 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
19 #include "platform/graphics/RecordingImageBufferSurface.h" | 20 #include "platform/graphics/RecordingImageBufferSurface.h" |
20 #include "platform/graphics/StaticBitmapImage.h" | 21 #include "platform/graphics/StaticBitmapImage.h" |
21 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 22 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); | 446 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); |
446 | 447 |
447 NonThrowableExceptionState exceptionState; | 448 NonThrowableExceptionState exceptionState; |
448 RefPtrWillBeRawPtr<Element> sourceCanvasElement = document().createElement(" canvas", exceptionState); | 449 RefPtrWillBeRawPtr<Element> sourceCanvasElement = document().createElement(" canvas", exceptionState); |
449 EXPECT_FALSE(exceptionState.hadException()); | 450 EXPECT_FALSE(exceptionState.hadException()); |
450 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv asElement.get()); | 451 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv asElement.get()); |
451 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma geSizeRatio); | 452 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma geSizeRatio); |
452 OwnPtr<UnacceleratedImageBufferSurface> sourceSurface = adoptPtr(new Unaccel eratedImageBufferSurface(sourceSize, NonOpaque)); | 453 OwnPtr<UnacceleratedImageBufferSurface> sourceSurface = adoptPtr(new Unaccel eratedImageBufferSurface(sourceSize, NonOpaque)); |
453 sourceCanvas->createImageBufferUsingSurfaceForTesting(sourceSurface.release( )); | 454 sourceCanvas->createImageBufferUsingSurfaceForTesting(sourceSurface.release( )); |
454 | 455 |
456 ImageBitmapOptions options; | |
Justin Novosad
2016/02/05 14:46:41
Here, you are not setting any options, and you are
xidachen
2016/02/05 16:47:36
I tried to define this local variable as a global
| |
455 // Go through an ImageBitmap to avoid triggering a display list fallback | 457 // Go through an ImageBitmap to avoid triggering a display list fallback |
456 RefPtrWillBeRawPtr<ImageBitmap> sourceImageBitmap = ImageBitmap::create(sour ceCanvas, IntRect(IntPoint(0, 0), sourceSize)); | 458 RefPtrWillBeRawPtr<ImageBitmap> sourceImageBitmap = ImageBitmap::create(sour ceCanvas, IntRect(IntPoint(0, 0), sourceSize), options); |
457 | 459 |
458 context2d()->drawImage(sourceImageBitmap.get(), 0, 0, 1, 1, 0, 0, 1, 1, exce ptionState); | 460 context2d()->drawImage(sourceImageBitmap.get(), 0, 0, 1, 1, 0, 0, 1, 1, exce ptionState); |
459 EXPECT_FALSE(exceptionState.hadException()); | 461 EXPECT_FALSE(exceptionState.hadException()); |
460 | 462 |
461 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); | 463 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); |
462 } | 464 } |
463 | 465 |
464 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) | 466 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) |
465 { | 467 { |
466 createContext(NonOpaque); | 468 createContext(NonOpaque); |
467 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec tNoFallback), NonOpaque)); | 469 OwnPtr<RecordingImageBufferSurface> surface = adoptPtr(new RecordingImageBuf ferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFactory::Expec tNoFallback), NonOpaque)); |
468 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); | 470 canvasElement().createImageBufferUsingSurfaceForTesting(surface.release()); |
469 | 471 |
470 NonThrowableExceptionState exceptionState; | 472 NonThrowableExceptionState exceptionState; |
471 RefPtrWillBeRawPtr<Element> sourceCanvasElement = document().createElement(" canvas", exceptionState); | 473 RefPtrWillBeRawPtr<Element> sourceCanvasElement = document().createElement(" canvas", exceptionState); |
472 EXPECT_FALSE(exceptionState.hadException()); | 474 EXPECT_FALSE(exceptionState.hadException()); |
473 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv asElement.get()); | 475 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv asElement.get()); |
474 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma geSizeRatio + 1); | 476 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma geSizeRatio + 1); |
475 OwnPtr<UnacceleratedImageBufferSurface> sourceSurface = adoptPtr(new Unaccel eratedImageBufferSurface(sourceSize, NonOpaque)); | 477 OwnPtr<UnacceleratedImageBufferSurface> sourceSurface = adoptPtr(new Unaccel eratedImageBufferSurface(sourceSize, NonOpaque)); |
476 sourceCanvas->createImageBufferUsingSurfaceForTesting(sourceSurface.release( )); | 478 sourceCanvas->createImageBufferUsingSurfaceForTesting(sourceSurface.release( )); |
477 | 479 |
480 ImageBitmapOptions options; | |
478 // Go through an ImageBitmap to avoid triggering a display list fallback | 481 // Go through an ImageBitmap to avoid triggering a display list fallback |
479 RefPtrWillBeRawPtr<ImageBitmap> sourceImageBitmap = ImageBitmap::create(sour ceCanvas, IntRect(IntPoint(0, 0), sourceSize)); | 482 RefPtrWillBeRawPtr<ImageBitmap> sourceImageBitmap = ImageBitmap::create(sour ceCanvas, IntRect(IntPoint(0, 0), sourceSize), options); |
480 | 483 |
481 context2d()->drawImage(sourceImageBitmap.get(), 0, 0, 1, 1, 0, 0, 1, 1, exce ptionState); | 484 context2d()->drawImage(sourceImageBitmap.get(), 0, 0, 1, 1, 0, 0, 1, 1, exce ptionState); |
482 EXPECT_FALSE(exceptionState.hadException()); | 485 EXPECT_FALSE(exceptionState.hadException()); |
483 | 486 |
484 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); | 487 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); |
485 } | 488 } |
486 | 489 |
487 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderExpensivePathPointCoun t) | 490 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderExpensivePathPointCoun t) |
488 { | 491 { |
489 createContext(NonOpaque); | 492 createContext(NonOpaque); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime) | 637 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime) |
635 { | 638 { |
636 NonThrowableExceptionState nonThrowableExceptionState; | 639 NonThrowableExceptionState nonThrowableExceptionState; |
637 RefPtrWillBeRawPtr<Element> canvasElement = document().createElement("canvas ", nonThrowableExceptionState); | 640 RefPtrWillBeRawPtr<Element> canvasElement = document().createElement("canvas ", nonThrowableExceptionState); |
638 EXPECT_FALSE(nonThrowableExceptionState.hadException()); | 641 EXPECT_FALSE(nonThrowableExceptionState.hadException()); |
639 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(canvasElement.ge t()); | 642 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(canvasElement.ge t()); |
640 canvas->setHeight(40); | 643 canvas->setHeight(40); |
641 canvas->setWidth(40); | 644 canvas->setWidth(40); |
642 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapDerived = nullptr; | 645 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapDerived = nullptr; |
643 { | 646 { |
644 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapFromCanvas = ImageBitmap::cre ate(canvas, IntRect(0, 0, canvas->width(), canvas->height())); | 647 ImageBitmapOptions options; |
645 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas.get(), In tRect(0, 0, 20, 20)); | 648 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapFromCanvas = ImageBitmap::cre ate(canvas, IntRect(0, 0, canvas->width(), canvas->height()), options); |
649 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas.get(), In tRect(0, 0, 20, 20), options); | |
646 } | 650 } |
647 CanvasContextCreationAttributes attributes; | 651 CanvasContextCreationAttributes attributes; |
648 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c anvas->getCanvasRenderingContext("2d", attributes)); | 652 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c anvas->getCanvasRenderingContext("2d", attributes)); |
649 TrackExceptionState exceptionState; | 653 TrackExceptionState exceptionState; |
650 CanvasImageSourceUnion imageSource; | 654 CanvasImageSourceUnion imageSource; |
651 imageSource.setImageBitmap(imageBitmapDerived); | 655 imageSource.setImageBitmap(imageBitmapDerived); |
652 context->drawImage(imageSource, 0, 0, exceptionState); | 656 context->drawImage(imageSource, 0, 0, exceptionState); |
653 } | 657 } |
654 | 658 |
655 TEST_F(CanvasRenderingContext2DTest, GPUMemoryUpdateForAcceleratedCanvas) | 659 TEST_F(CanvasRenderingContext2DTest, GPUMemoryUpdateForAcceleratedCanvas) |
(...skipping 30 matching lines...) Expand all Loading... | |
686 canvasElement().setSize(IntSize(20, 20)); | 690 canvasElement().setSize(IntSize(20, 20)); |
687 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); | 691 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); |
688 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); | 692 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); |
689 | 693 |
690 // Tear down the second image buffer | 694 // Tear down the second image buffer |
691 imageBuffer2.clear(); | 695 imageBuffer2.clear(); |
692 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 696 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
693 } | 697 } |
694 | 698 |
695 } // namespace blink | 699 } // namespace blink |
OLD | NEW |