Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp

Issue 2035113002: Implement ImageBitmapOptions resize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 462
463 NonThrowableExceptionState exceptionState; 463 NonThrowableExceptionState exceptionState;
464 Element* sourceCanvasElement = document().createElement("canvas", exceptionS tate); 464 Element* sourceCanvasElement = document().createElement("canvas", exceptionS tate);
465 EXPECT_FALSE(exceptionState.hadException()); 465 EXPECT_FALSE(exceptionState.hadException());
466 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv asElement); 466 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv asElement);
467 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma geSizeRatio); 467 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma geSizeRatio);
468 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = wrapUnique( new UnacceleratedImageBufferSurface(sourceSize, NonOpaque)); 468 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = wrapUnique( new UnacceleratedImageBufferSurface(sourceSize, NonOpaque));
469 sourceCanvas->createImageBufferUsingSurfaceForTesting(std::move(sourceSurfac e)); 469 sourceCanvas->createImageBufferUsingSurfaceForTesting(std::move(sourceSurfac e));
470 470
471 const ImageBitmapOptions defaultOptions; 471 const ImageBitmapOptions defaultOptions;
472 Optional<IntRect> cropRect = IntRect(IntPoint(0, 0), sourceSize);
472 // Go through an ImageBitmap to avoid triggering a display list fallback 473 // Go through an ImageBitmap to avoid triggering a display list fallback
473 ImageBitmap* sourceImageBitmap = ImageBitmap::create(sourceCanvas, IntRect(I ntPoint(0, 0), sourceSize), defaultOptions); 474 ImageBitmap* sourceImageBitmap = ImageBitmap::create(sourceCanvas, cropRect, defaultOptions);
474 475
475 context2d()->drawImage(canvasElement().getExecutionContext(), sourceImageBit map, 0, 0, 1, 1, 0, 0, 1, 1, exceptionState); 476 context2d()->drawImage(canvasElement().getExecutionContext(), sourceImageBit map, 0, 0, 1, 1, 0, 0, 1, 1, exceptionState);
476 EXPECT_FALSE(exceptionState.hadException()); 477 EXPECT_FALSE(exceptionState.hadException());
477 478
478 EXPECT_FALSE(canvasElement().shouldBeDirectComposited()); 479 EXPECT_FALSE(canvasElement().shouldBeDirectComposited());
479 } 480 }
480 481
481 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) 482 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit)
482 { 483 {
483 createContext(NonOpaque); 484 createContext(NonOpaque);
484 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac tory::ExpectNoFallback), NonOpaque)); 485 std::unique_ptr<RecordingImageBufferSurface> surface = wrapUnique(new Record ingImageBufferSurface(IntSize(10, 10), MockSurfaceFactory::create(MockSurfaceFac tory::ExpectNoFallback), NonOpaque));
485 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface)); 486 canvasElement().createImageBufferUsingSurfaceForTesting(std::move(surface));
486 487
487 NonThrowableExceptionState exceptionState; 488 NonThrowableExceptionState exceptionState;
488 Element* sourceCanvasElement = document().createElement("canvas", exceptionS tate); 489 Element* sourceCanvasElement = document().createElement("canvas", exceptionS tate);
489 EXPECT_FALSE(exceptionState.hadException()); 490 EXPECT_FALSE(exceptionState.hadException());
490 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv asElement); 491 HTMLCanvasElement* sourceCanvas = static_cast<HTMLCanvasElement*>(sourceCanv asElement);
491 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma geSizeRatio + 1); 492 IntSize sourceSize(10, 10 * ExpensiveCanvasHeuristicParameters::ExpensiveIma geSizeRatio + 1);
492 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = wrapUnique( new UnacceleratedImageBufferSurface(sourceSize, NonOpaque)); 493 std::unique_ptr<UnacceleratedImageBufferSurface> sourceSurface = wrapUnique( new UnacceleratedImageBufferSurface(sourceSize, NonOpaque));
493 sourceCanvas->createImageBufferUsingSurfaceForTesting(std::move(sourceSurfac e)); 494 sourceCanvas->createImageBufferUsingSurfaceForTesting(std::move(sourceSurfac e));
494 495
495 const ImageBitmapOptions defaultOptions; 496 const ImageBitmapOptions defaultOptions;
497 Optional<IntRect> cropRect = IntRect(IntPoint(0, 0), sourceSize);
496 // Go through an ImageBitmap to avoid triggering a display list fallback 498 // Go through an ImageBitmap to avoid triggering a display list fallback
497 ImageBitmap* sourceImageBitmap = ImageBitmap::create(sourceCanvas, IntRect(I ntPoint(0, 0), sourceSize), defaultOptions); 499 ImageBitmap* sourceImageBitmap = ImageBitmap::create(sourceCanvas, cropRect, defaultOptions);
498 500
499 context2d()->drawImage(canvasElement().getExecutionContext(), sourceImageBit map, 0, 0, 1, 1, 0, 0, 1, 1, exceptionState); 501 context2d()->drawImage(canvasElement().getExecutionContext(), sourceImageBit map, 0, 0, 1, 1, 0, 0, 1, 1, exceptionState);
500 EXPECT_FALSE(exceptionState.hadException()); 502 EXPECT_FALSE(exceptionState.hadException());
501 503
502 EXPECT_TRUE(canvasElement().shouldBeDirectComposited()); 504 EXPECT_TRUE(canvasElement().shouldBeDirectComposited());
503 } 505 }
504 506
505 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderExpensivePathPointCoun t) 507 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderExpensivePathPointCoun t)
506 { 508 {
507 createContext(NonOpaque); 509 createContext(NonOpaque);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 { 678 {
677 NonThrowableExceptionState nonThrowableExceptionState; 679 NonThrowableExceptionState nonThrowableExceptionState;
678 Element* canvasElement = document().createElement("canvas", nonThrowableExce ptionState); 680 Element* canvasElement = document().createElement("canvas", nonThrowableExce ptionState);
679 EXPECT_FALSE(nonThrowableExceptionState.hadException()); 681 EXPECT_FALSE(nonThrowableExceptionState.hadException());
680 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(canvasElement); 682 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(canvasElement);
681 canvas->setHeight(40); 683 canvas->setHeight(40);
682 canvas->setWidth(40); 684 canvas->setWidth(40);
683 ImageBitmap* imageBitmapDerived = nullptr; 685 ImageBitmap* imageBitmapDerived = nullptr;
684 { 686 {
685 const ImageBitmapOptions defaultOptions; 687 const ImageBitmapOptions defaultOptions;
686 ImageBitmap* imageBitmapFromCanvas = ImageBitmap::create(canvas, IntRect (0, 0, canvas->width(), canvas->height()), defaultOptions); 688 Optional<IntRect> cropRect = IntRect(0, 0, canvas->width(), canvas->heig ht());
687 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas, IntRect( 0, 0, 20, 20), defaultOptions); 689 ImageBitmap* imageBitmapFromCanvas = ImageBitmap::create(canvas, cropRec t, defaultOptions);
690 cropRect = IntRect(0, 0, 20, 20);
691 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas, cropRect , defaultOptions);
688 } 692 }
689 CanvasContextCreationAttributes attributes; 693 CanvasContextCreationAttributes attributes;
690 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c anvas->getCanvasRenderingContext("2d", attributes)); 694 CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(c anvas->getCanvasRenderingContext("2d", attributes));
691 TrackExceptionState exceptionState; 695 TrackExceptionState exceptionState;
692 CanvasImageSourceUnion imageSource; 696 CanvasImageSourceUnion imageSource;
693 imageSource.setImageBitmap(imageBitmapDerived); 697 imageSource.setImageBitmap(imageBitmapDerived);
694 context->drawImage(canvas->getExecutionContext(), imageSource, 0, 0, excepti onState); 698 context->drawImage(canvas->getExecutionContext(), imageSource, 0, 0, excepti onState);
695 } 699 }
696 700
697 TEST_F(CanvasRenderingContext2DTest, GPUMemoryUpdateForAcceleratedCanvas) 701 TEST_F(CanvasRenderingContext2DTest, GPUMemoryUpdateForAcceleratedCanvas)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 EXPECT_TRUE(bridge->isAccelerated()); 795 EXPECT_TRUE(bridge->isAccelerated());
792 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount()); 796 EXPECT_EQ(1u, getGlobalAcceleratedImageBufferCount());
793 EXPECT_EQ(720000, getGlobalGPUMemoryUsage()); 797 EXPECT_EQ(720000, getGlobalGPUMemoryUsage());
794 } 798 }
795 799
796 // Restore global state to prevent side-effects on other tests 800 // Restore global state to prevent side-effects on other tests
797 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(savedFixedRende ringMode); 801 RuntimeEnabledFeatures::setCanvas2dFixedRenderingModeEnabled(savedFixedRende ringMode);
798 } 802 }
799 803
800 } // namespace blink 804 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698