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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 enum BitmapOpacity { | 31 enum BitmapOpacity { |
32 OpaqueBitmap, | 32 OpaqueBitmap, |
33 TransparentBitmap | 33 TransparentBitmap |
34 }; | 34 }; |
35 | 35 |
36 class FakeImageSource : public CanvasImageSource { | 36 class FakeImageSource : public CanvasImageSource { |
37 public: | 37 public: |
38 FakeImageSource(IntSize, BitmapOpacity); | 38 FakeImageSource(IntSize, BitmapOpacity); |
39 | 39 |
40 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, AccelerationHi
nt, SnapshotReason) const override; | 40 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, AccelerationHi
nt, SnapshotReason, const FloatSize&) const override; |
41 | 41 |
42 bool wouldTaintOrigin(SecurityOrigin* destinationSecurityOrigin) const overr
ide { return false; } | 42 bool wouldTaintOrigin(SecurityOrigin* destinationSecurityOrigin) const overr
ide { return false; } |
43 FloatSize elementSize() const override { return FloatSize(m_size); } | 43 FloatSize elementSize(const FloatSize&) const override { return FloatSize(m_
size); } |
44 bool isOpaque() const override { return m_isOpaque; } | 44 bool isOpaque() const override { return m_isOpaque; } |
45 | 45 |
46 ~FakeImageSource() override { } | 46 ~FakeImageSource() override { } |
47 | 47 |
48 private: | 48 private: |
49 IntSize m_size; | 49 IntSize m_size; |
50 RefPtr<Image> m_image; | 50 RefPtr<Image> m_image; |
51 bool m_isOpaque; | 51 bool m_isOpaque; |
52 }; | 52 }; |
53 | 53 |
54 FakeImageSource::FakeImageSource(IntSize size, BitmapOpacity opacity) | 54 FakeImageSource::FakeImageSource(IntSize size, BitmapOpacity opacity) |
55 : m_size(size) | 55 : m_size(size) |
56 , m_isOpaque(opacity == OpaqueBitmap) | 56 , m_isOpaque(opacity == OpaqueBitmap) |
57 { | 57 { |
58 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(m_size.width()
, m_size.height())); | 58 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(m_size.width()
, m_size.height())); |
59 surface->getCanvas()->clear(opacity == OpaqueBitmap ? SK_ColorWHITE : SK_Col
orTRANSPARENT); | 59 surface->getCanvas()->clear(opacity == OpaqueBitmap ? SK_ColorWHITE : SK_Col
orTRANSPARENT); |
60 RefPtr<SkImage> image = adoptRef(surface->newImageSnapshot()); | 60 RefPtr<SkImage> image = adoptRef(surface->newImageSnapshot()); |
61 m_image = StaticBitmapImage::create(image); | 61 m_image = StaticBitmapImage::create(image); |
62 } | 62 } |
63 | 63 |
64 PassRefPtr<Image> FakeImageSource::getSourceImageForCanvas(SourceImageStatus* st
atus, AccelerationHint, SnapshotReason) const | 64 PassRefPtr<Image> FakeImageSource::getSourceImageForCanvas(SourceImageStatus* st
atus, AccelerationHint, SnapshotReason, const FloatSize&) const |
65 { | 65 { |
66 if (status) | 66 if (status) |
67 *status = NormalSourceImageStatus; | 67 *status = NormalSourceImageStatus; |
68 return m_image; | 68 return m_image; |
69 } | 69 } |
70 | 70 |
71 //============================================================================ | 71 //============================================================================ |
72 | 72 |
73 class CanvasRenderingContext2DTest : public ::testing::Test { | 73 class CanvasRenderingContext2DTest : public ::testing::Test { |
74 protected: | 74 protected: |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 canvasElement().setSize(IntSize(20, 20)); | 713 canvasElement().setSize(IntSize(20, 20)); |
714 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); | 714 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); |
715 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); | 715 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); |
716 | 716 |
717 // Tear down the second image buffer | 717 // Tear down the second image buffer |
718 imageBuffer2.clear(); | 718 imageBuffer2.clear(); |
719 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 719 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
720 } | 720 } |
721 | 721 |
722 } // namespace blink | 722 } // namespace blink |
OLD | NEW |