| 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/csspaint/PaintRenderingContext2D.h" | 5 #include "modules/csspaint/PaintRenderingContext2D.h" |
| 6 | 6 |
| 7 #include "platform/graphics/ImageBuffer.h" | 7 #include "platform/graphics/ImageBuffer.h" |
| 8 #include "platform/graphics/paint/PaintCanvas.h" | 8 #include "platform/graphics/paint/PaintCanvas.h" |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // explicitly. | 22 // explicitly. |
| 23 DCHECK(image_buffer_); | 23 DCHECK(image_buffer_); |
| 24 image_buffer_->Canvas()->clear(has_alpha ? SK_ColorTRANSPARENT | 24 image_buffer_->Canvas()->clear(has_alpha ? SK_ColorTRANSPARENT |
| 25 : SK_ColorBLACK); | 25 : SK_ColorBLACK); |
| 26 image_buffer_->DidDraw(FloatRect(0, 0, Width(), Height())); | 26 image_buffer_->DidDraw(FloatRect(0, 0, Width(), Height())); |
| 27 | 27 |
| 28 image_buffer_->Canvas()->scale(zoom, zoom); | 28 image_buffer_->Canvas()->scale(zoom, zoom); |
| 29 } | 29 } |
| 30 | 30 |
| 31 int PaintRenderingContext2D::Width() const { | 31 int PaintRenderingContext2D::Width() const { |
| 32 ASSERT(image_buffer_); | 32 DCHECK(image_buffer_); |
| 33 return image_buffer_->size().Width(); | 33 return image_buffer_->size().Width(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 int PaintRenderingContext2D::Height() const { | 36 int PaintRenderingContext2D::Height() const { |
| 37 ASSERT(image_buffer_); | 37 DCHECK(image_buffer_); |
| 38 return image_buffer_->size().Height(); | 38 return image_buffer_->size().Height(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool PaintRenderingContext2D::ParseColorOrCurrentColor( | 41 bool PaintRenderingContext2D::ParseColorOrCurrentColor( |
| 42 Color& color, | 42 Color& color, |
| 43 const String& color_string) const { | 43 const String& color_string) const { |
| 44 // We ignore "currentColor" for PaintRenderingContext2D and just make it | 44 // We ignore "currentColor" for PaintRenderingContext2D and just make it |
| 45 // "black". "currentColor" can be emulated by having "color" as an input | 45 // "black". "currentColor" can be emulated by having "color" as an input |
| 46 // property for the css-paint-api. | 46 // property for the css-paint-api. |
| 47 // https://github.com/w3c/css-houdini-drafts/issues/133 | 47 // https://github.com/w3c/css-houdini-drafts/issues/133 |
| 48 return ::blink::ParseColorOrCurrentColor(color, color_string, nullptr); | 48 return ::blink::ParseColorOrCurrentColor(color, color_string, nullptr); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ColorBehavior PaintRenderingContext2D::DrawImageColorBehavior() const { | 51 ColorBehavior PaintRenderingContext2D::DrawImageColorBehavior() const { |
| 52 return ColorBehavior::TransformToGlobalTarget(); | 52 return ColorBehavior::TransformToGlobalTarget(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 PaintCanvas* PaintRenderingContext2D::DrawingCanvas() const { | 55 PaintCanvas* PaintRenderingContext2D::DrawingCanvas() const { |
| 56 return image_buffer_->Canvas(); | 56 return image_buffer_->Canvas(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 PaintCanvas* PaintRenderingContext2D::ExistingDrawingCanvas() const { | 59 PaintCanvas* PaintRenderingContext2D::ExistingDrawingCanvas() const { |
| 60 ASSERT(image_buffer_); | 60 DCHECK(image_buffer_); |
| 61 return image_buffer_->Canvas(); | 61 return image_buffer_->Canvas(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 AffineTransform PaintRenderingContext2D::BaseTransform() const { | 64 AffineTransform PaintRenderingContext2D::BaseTransform() const { |
| 65 ASSERT(image_buffer_); | 65 DCHECK(image_buffer_); |
| 66 return image_buffer_->BaseTransform(); | 66 return image_buffer_->BaseTransform(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void PaintRenderingContext2D::DidDraw(const SkIRect& dirty_rect) { | 69 void PaintRenderingContext2D::DidDraw(const SkIRect& dirty_rect) { |
| 70 ASSERT(image_buffer_); | 70 DCHECK(image_buffer_); |
| 71 return image_buffer_->DidDraw(SkRect::Make(dirty_rect)); | 71 return image_buffer_->DidDraw(SkRect::Make(dirty_rect)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void PaintRenderingContext2D::ValidateStateStack() const { | 74 void PaintRenderingContext2D::ValidateStateStack() const { |
| 75 #if DCHECK_IS_ON() | 75 #if DCHECK_IS_ON() |
| 76 if (PaintCanvas* sk_canvas = ExistingDrawingCanvas()) { | 76 if (PaintCanvas* sk_canvas = ExistingDrawingCanvas()) { |
| 77 DCHECK_EQ(static_cast<size_t>(sk_canvas->getSaveCount()), | 77 DCHECK_EQ(static_cast<size_t>(sk_canvas->getSaveCount()), |
| 78 state_stack_.size() + 1); | 78 state_stack_.size() + 1); |
| 79 } | 79 } |
| 80 #endif | 80 #endif |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace blink | 83 } // namespace blink |
| OLD | NEW |