| 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 "bindings/core/v8/V8BindingForCore.h" | 7 #include "bindings/core/v8/V8BindingForCore.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 enum BitmapOpacity { kOpaqueBitmap, kTransparentBitmap }; | 35 enum BitmapOpacity { kOpaqueBitmap, kTransparentBitmap }; |
| 36 | 36 |
| 37 class FakeImageSource : public CanvasImageSource { | 37 class FakeImageSource : public CanvasImageSource { |
| 38 public: | 38 public: |
| 39 FakeImageSource(IntSize, BitmapOpacity); | 39 FakeImageSource(IntSize, BitmapOpacity); |
| 40 | 40 |
| 41 PassRefPtr<Image> GetSourceImageForCanvas(SourceImageStatus*, | 41 PassRefPtr<Image> GetSourceImageForCanvas(SourceImageStatus*, |
| 42 AccelerationHint, | 42 AccelerationHint, |
| 43 SnapshotReason, | 43 SnapshotReason, |
| 44 const FloatSize&) const override; | 44 const FloatSize&) override; |
| 45 | 45 |
| 46 bool WouldTaintOrigin( | 46 bool WouldTaintOrigin( |
| 47 SecurityOrigin* destination_security_origin) const override { | 47 SecurityOrigin* destination_security_origin) const override { |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 FloatSize ElementSize(const FloatSize&) const override { | 50 FloatSize ElementSize(const FloatSize&) const override { |
| 51 return FloatSize(size_); | 51 return FloatSize(size_); |
| 52 } | 52 } |
| 53 bool IsOpaque() const override { return is_opaque_; } | 53 bool IsOpaque() const override { return is_opaque_; } |
| 54 bool IsAccelerated() const override { return false; } | 54 bool IsAccelerated() const override { return false; } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 69 SkSurface::MakeRasterN32Premul(size_.Width(), size_.Height())); | 69 SkSurface::MakeRasterN32Premul(size_.Width(), size_.Height())); |
| 70 surface->getCanvas()->clear(opacity == kOpaqueBitmap ? SK_ColorWHITE | 70 surface->getCanvas()->clear(opacity == kOpaqueBitmap ? SK_ColorWHITE |
| 71 : SK_ColorTRANSPARENT); | 71 : SK_ColorTRANSPARENT); |
| 72 image_ = StaticBitmapImage::Create(surface->makeImageSnapshot()); | 72 image_ = StaticBitmapImage::Create(surface->makeImageSnapshot()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 PassRefPtr<Image> FakeImageSource::GetSourceImageForCanvas( | 75 PassRefPtr<Image> FakeImageSource::GetSourceImageForCanvas( |
| 76 SourceImageStatus* status, | 76 SourceImageStatus* status, |
| 77 AccelerationHint, | 77 AccelerationHint, |
| 78 SnapshotReason, | 78 SnapshotReason, |
| 79 const FloatSize&) const { | 79 const FloatSize&) { |
| 80 if (status) | 80 if (status) |
| 81 *status = kNormalSourceImageStatus; | 81 *status = kNormalSourceImageStatus; |
| 82 return image_; | 82 return image_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 class CanvasRenderingContextUsageTrackingTest : public ::testing::Test { | 85 class CanvasRenderingContextUsageTrackingTest : public ::testing::Test { |
| 86 protected: | 86 protected: |
| 87 CanvasRenderingContextUsageTrackingTest(); | 87 CanvasRenderingContextUsageTrackingTest(); |
| 88 void SetUp() override; | 88 void SetUp() override; |
| 89 | 89 |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 for (int i = 0; i < kNumReps; i++) { | 676 for (int i = 0; i < kNumReps; i++) { |
| 677 Context2d()->fillRect(10, 10, 100, 100); | 677 Context2d()->fillRect(10, 10, 100, 100); |
| 678 } | 678 } |
| 679 EXPECT_EQ(kNumReps, Context2d() | 679 EXPECT_EQ(kNumReps, Context2d() |
| 680 ->GetUsage() | 680 ->GetUsage() |
| 681 .num_draw_calls[BaseRenderingContext2D::kFillRect]); | 681 .num_draw_calls[BaseRenderingContext2D::kFillRect]); |
| 682 } | 682 } |
| 683 | 683 |
| 684 } // namespace UsageTrackingTests | 684 } // namespace UsageTrackingTests |
| 685 } // namespace blink | 685 } // namespace blink |
| OLD | NEW |