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

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

Issue 1372463002: Re-land: Make 2D canvas smarter about chosing whether or not to use GPU acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed assert Created 5 years, 2 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
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 "config.h" 5 #include "config.h"
6 #include "modules/canvas2d/CanvasRenderingContext2D.h" 6 #include "modules/canvas2d/CanvasRenderingContext2D.h"
7 7
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 18 matching lines...) Expand all
29 29
30 enum BitmapOpacity { 30 enum BitmapOpacity {
31 OpaqueBitmap, 31 OpaqueBitmap,
32 TransparentBitmap 32 TransparentBitmap
33 }; 33 };
34 34
35 class FakeImageSource : public CanvasImageSource { 35 class FakeImageSource : public CanvasImageSource {
36 public: 36 public:
37 FakeImageSource(IntSize, BitmapOpacity); 37 FakeImageSource(IntSize, BitmapOpacity);
38 38
39 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*) const override ; 39 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, AccelerationHi nt) const override;
40 40
41 bool wouldTaintOrigin(SecurityOrigin* destinationSecurityOrigin) const overr ide { return false; } 41 bool wouldTaintOrigin(SecurityOrigin* destinationSecurityOrigin) const overr ide { return false; }
42 FloatSize elementSize() const override { return FloatSize(m_size); } 42 FloatSize elementSize() const override { return FloatSize(m_size); }
43 bool isOpaque() const override { return m_isOpaque; } 43 bool isOpaque() const override { return m_isOpaque; }
44 44
45 ~FakeImageSource() override { } 45 ~FakeImageSource() override { }
46 46
47 private: 47 private:
48 IntSize m_size; 48 IntSize m_size;
49 RefPtr<Image> m_image; 49 RefPtr<Image> m_image;
50 bool m_isOpaque; 50 bool m_isOpaque;
51 }; 51 };
52 52
53 FakeImageSource::FakeImageSource(IntSize size, BitmapOpacity opacity) 53 FakeImageSource::FakeImageSource(IntSize size, BitmapOpacity opacity)
54 : m_size(size) 54 : m_size(size)
55 , m_isOpaque(opacity == OpaqueBitmap) 55 , m_isOpaque(opacity == OpaqueBitmap)
56 { 56 {
57 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(m_size.width() , m_size.height())); 57 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(m_size.width() , m_size.height()));
58 surface->getCanvas()->clear(opacity == OpaqueBitmap ? SK_ColorWHITE : SK_Col orTRANSPARENT); 58 surface->getCanvas()->clear(opacity == OpaqueBitmap ? SK_ColorWHITE : SK_Col orTRANSPARENT);
59 RefPtr<SkImage> image = adoptRef(surface->newImageSnapshot()); 59 RefPtr<SkImage> image = adoptRef(surface->newImageSnapshot());
60 m_image = StaticBitmapImage::create(image); 60 m_image = StaticBitmapImage::create(image);
61 } 61 }
62 62
63 PassRefPtr<Image> FakeImageSource::getSourceImageForCanvas(SourceImageStatus* st atus) const 63 PassRefPtr<Image> FakeImageSource::getSourceImageForCanvas(SourceImageStatus* st atus, AccelerationHint) const
64 { 64 {
65 if (status) 65 if (status)
66 *status = NormalSourceImageStatus; 66 *status = NormalSourceImageStatus;
67 return m_image; 67 return m_image;
68 } 68 }
69 69
70 //============================================================================ 70 //============================================================================
71 71
72 class CanvasRenderingContext2DTest : public ::testing::Test { 72 class CanvasRenderingContext2DTest : public ::testing::Test {
73 protected: 73 protected:
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // The canvasChanged notification must be immediate, and not deferred until paint time 624 // The canvasChanged notification must be immediate, and not deferred until paint time
625 // because offscreen canvases, which are not painted, also need to emit noti fications. 625 // because offscreen canvases, which are not painted, also need to emit noti fications.
626 EXPECT_CALL(*observer, canvasChanged(&canvasElement(), FloatRect(0, 0, 1, 1) )).Times(1); 626 EXPECT_CALL(*observer, canvasChanged(&canvasElement(), FloatRect(0, 0, 1, 1) )).Times(1);
627 context2d()->fillRect(0, 0, 1, 1); 627 context2d()->fillRect(0, 0, 1, 1);
628 Mock::VerifyAndClearExpectations(observer.get()); 628 Mock::VerifyAndClearExpectations(observer.get());
629 629
630 canvasElement().removeObserver(observer.get()); 630 canvasElement().removeObserver(observer.get());
631 } 631 }
632 632
633 } // namespace blink 633 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698