| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/fetch/MemoryCache.h" | 8 #include "core/fetch/MemoryCache.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 RefPtr<Image> m_image; | 53 RefPtr<Image> m_image; |
| 54 bool m_isOpaque; | 54 bool m_isOpaque; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 FakeImageSource::FakeImageSource(IntSize size, BitmapOpacity opacity) | 57 FakeImageSource::FakeImageSource(IntSize size, BitmapOpacity opacity) |
| 58 : m_size(size) | 58 : m_size(size) |
| 59 , m_isOpaque(opacity == OpaqueBitmap) | 59 , m_isOpaque(opacity == OpaqueBitmap) |
| 60 { | 60 { |
| 61 sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(m_size.width(), m_si
ze.height())); | 61 sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(m_size.width(), m_si
ze.height())); |
| 62 surface->getCanvas()->clear(opacity == OpaqueBitmap ? SK_ColorWHITE : SK_Col
orTRANSPARENT); | 62 surface->getCanvas()->clear(opacity == OpaqueBitmap ? SK_ColorWHITE : SK_Col
orTRANSPARENT); |
| 63 RefPtr<SkImage> image = adoptRef(surface->makeImageSnapshot().release()); | 63 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); |
| 64 m_image = StaticBitmapImage::create(image); | |
| 65 } | 64 } |
| 66 | 65 |
| 67 PassRefPtr<Image> FakeImageSource::getSourceImageForCanvas(SourceImageStatus* st
atus, AccelerationHint, SnapshotReason, const FloatSize&) const | 66 PassRefPtr<Image> FakeImageSource::getSourceImageForCanvas(SourceImageStatus* st
atus, AccelerationHint, SnapshotReason, const FloatSize&) const |
| 68 { | 67 { |
| 69 if (status) | 68 if (status) |
| 70 *status = NormalSourceImageStatus; | 69 *status = NormalSourceImageStatus; |
| 71 return m_image; | 70 return m_image; |
| 72 } | 71 } |
| 73 | 72 |
| 74 class CanvasRenderingContextUsageTrackingTest : public ::testing::Test { | 73 class CanvasRenderingContextUsageTrackingTest : public ::testing::Test { |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 EXPECT_EQ(0, context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::Fi
llRect]); | 493 EXPECT_EQ(0, context2d()->getUsage().numDrawCalls[BaseRenderingContext2D::Fi
llRect]); |
| 495 | 494 |
| 496 for (int i = 0; i < numReps; i++) { | 495 for (int i = 0; i < numReps; i++) { |
| 497 context2d()->fillRect(10, 10, 100, 100); | 496 context2d()->fillRect(10, 10, 100, 100); |
| 498 } | 497 } |
| 499 EXPECT_EQ(numReps, context2d()->getUsage().numDrawCalls[BaseRenderingContext
2D::FillRect]); | 498 EXPECT_EQ(numReps, context2d()->getUsage().numDrawCalls[BaseRenderingContext
2D::FillRect]); |
| 500 } | 499 } |
| 501 | 500 |
| 502 } // namespace UsageTrackingTests | 501 } // namespace UsageTrackingTests |
| 503 } // namespace blink | 502 } // namespace blink |
| OLD | NEW |