| 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 18 matching lines...) Expand all Loading... |
| 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*, AccelerationHi
nt) const override; | 39 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, AccelerationHi
nt, SnapshotReason) 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, AccelerationHint) const | 63 PassRefPtr<Image> FakeImageSource::getSourceImageForCanvas(SourceImageStatus* st
atus, AccelerationHint, SnapshotReason) 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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 canvasElement().setSize(IntSize(20, 20)); | 709 canvasElement().setSize(IntSize(20, 20)); |
| 710 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); | 710 Mock::VerifyAndClearExpectations(fakeAccelerateSurfacePtr); |
| 711 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); | 711 EXPECT_EQ(400, getGlobalGPUMemoryUsage()); |
| 712 | 712 |
| 713 // Tear down the second image buffer | 713 // Tear down the second image buffer |
| 714 imageBuffer2.clear(); | 714 imageBuffer2.clear(); |
| 715 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); | 715 EXPECT_EQ(0, getGlobalGPUMemoryUsage()); |
| 716 } | 716 } |
| 717 | 717 |
| 718 } // namespace blink | 718 } // namespace blink |
| OLD | NEW |