Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef SKY_ENGINE_CORE_PAINTING_CANVAS_H_ | 5 #ifndef SKY_ENGINE_CORE_PAINTING_CANVAS_H_ |
| 6 #define SKY_ENGINE_CORE_PAINTING_CANVAS_H_ | 6 #define SKY_ENGINE_CORE_PAINTING_CANVAS_H_ |
| 7 | 7 |
| 8 #include "sky/engine/core/painting/CanvasPath.h" | 8 #include "sky/engine/core/painting/CanvasPath.h" |
| 9 #include "sky/engine/core/painting/Paint.h" | 9 #include "sky/engine/core/painting/Paint.h" |
| 10 #include "sky/engine/core/painting/Picture.h" | 10 #include "sky/engine/core/painting/Picture.h" |
| 11 #include "sky/engine/core/painting/PictureRecorder.h" | |
| 11 #include "sky/engine/core/painting/RRect.h" | 12 #include "sky/engine/core/painting/RRect.h" |
| 12 #include "sky/engine/core/painting/Rect.h" | 13 #include "sky/engine/core/painting/Rect.h" |
| 13 #include "sky/engine/platform/graphics/DisplayList.h" | 14 #include "sky/engine/platform/graphics/DisplayList.h" |
| 14 #include "sky/engine/tonic/dart_wrappable.h" | 15 #include "sky/engine/tonic/dart_wrappable.h" |
| 15 #include "sky/engine/tonic/float32_list.h" | 16 #include "sky/engine/tonic/float32_list.h" |
| 16 #include "sky/engine/wtf/PassRefPtr.h" | 17 #include "sky/engine/wtf/PassRefPtr.h" |
| 17 #include "sky/engine/wtf/RefCounted.h" | 18 #include "sky/engine/wtf/RefCounted.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | |
| 18 | 20 |
| 19 namespace blink { | 21 namespace blink { |
| 20 class Element; | |
| 21 class CanvasImage; | 22 class CanvasImage; |
| 22 | 23 |
| 23 class Canvas : public RefCounted<Canvas>, public DartWrappable { | 24 class Canvas : public RefCounted<Canvas>, public DartWrappable { |
| 24 DEFINE_WRAPPERTYPEINFO(); | 25 DEFINE_WRAPPERTYPEINFO(); |
| 25 public: | 26 public: |
| 26 Canvas(const FloatSize& size); | 27 static PassRefPtr<Canvas> create(SkCanvas* skCanvas) { |
| 28 ASSERT(skCanvas); | |
| 29 return adoptRef(new Canvas(skCanvas)); | |
| 30 } | |
| 31 | |
| 32 static PassRefPtr<Canvas> create(PassRefPtr<PictureRecorder> recorder, | |
|
abarth-chromium
2015/06/23 02:28:44
I think what Eric is saying is that ideally |PassR
iansf
2015/06/23 22:46:09
Confirmed that |PictureRecorder*| works, and updat
| |
| 33 double width, | |
| 34 double height) { | |
| 35 ASSERT(recorder); | |
| 36 PassRefPtr<Canvas> canvas = create( | |
| 37 recorder->beginRecording(width, height)); | |
| 38 recorder->set_canvas(canvas.get()); | |
|
eseidel
2015/06/23 00:41:32
Who keeps the PictureRecorder alive? , Typically a
abarth-chromium
2015/06/23 02:28:44
Canvas effectively has a weak reference to the pic
| |
| 39 return canvas; | |
| 40 } | |
| 41 | |
| 27 ~Canvas() override; | 42 ~Canvas() override; |
| 28 | 43 |
| 29 // Width/Height define a culling rect which Skia may use for optimizing | |
| 30 // out draw calls issued outside the rect. | |
| 31 float width() const { return m_size.width(); } | |
| 32 float height() const { return m_size.height(); } | |
| 33 | |
| 34 void save(); | 44 void save(); |
| 35 void saveLayer(const Rect& bounds, const Paint* paint = nullptr); | 45 void saveLayer(const Rect& bounds, const Paint* paint = nullptr); |
| 36 void restore(); | 46 void restore(); |
| 37 | 47 |
| 38 void translate(float dx, float dy); | 48 void translate(float dx, float dy); |
| 39 void scale(float sx, float sy); | 49 void scale(float sx, float sy); |
| 40 void rotate(float radians); | 50 void rotate(float radians); |
| 41 void skew(float sx, float sy); | 51 void skew(float sx, float sy); |
| 42 void concat(const Float32List& matrix4); | 52 void concat(const Float32List& matrix4); |
| 43 | 53 |
| 44 void clipRect(const Rect& rect); | 54 void clipRect(const Rect& rect); |
| 45 void clipRRect(const RRect* rrect); | 55 void clipRRect(const RRect* rrect); |
| 46 void clipPath(const CanvasPath* path); | 56 void clipPath(const CanvasPath* path); |
| 47 | 57 |
| 48 void drawLine(float x0, float y0, float x1, float y1, const Paint* paint); | 58 void drawLine(float x0, float y0, float x1, float y1, const Paint* paint); |
| 49 void drawPicture(Picture* picture); | 59 void drawPicture(Picture* picture); |
| 50 void drawPaint(const Paint* paint); | 60 void drawPaint(const Paint* paint); |
| 51 void drawRect(const Rect& rect, const Paint* paint); | 61 void drawRect(const Rect& rect, const Paint* paint); |
| 52 void drawRRect(const RRect* rrect, const Paint* paint); | 62 void drawRRect(const RRect* rrect, const Paint* paint); |
| 53 void drawOval(const Rect& rect, const Paint* paint); | 63 void drawOval(const Rect& rect, const Paint* paint); |
| 54 void drawCircle(float x, float y, float radius, const Paint* paint); | 64 void drawCircle(float x, float y, float radius, const Paint* paint); |
| 55 void drawPath(const CanvasPath* path, const Paint* paint); | 65 void drawPath(const CanvasPath* path, const Paint* paint); |
| 56 void drawImage(const CanvasImage* image, | 66 void drawImage(const CanvasImage* image, |
| 57 float x, | 67 float x, |
| 58 float y, | 68 float y, |
| 59 const Paint* paint); | 69 const Paint* paint); |
| 60 | 70 |
| 61 SkCanvas* skCanvas() { return m_canvas; } | 71 SkCanvas* skCanvas() { return m_canvas; } |
| 72 void clearSkCanvas() { m_canvas = nullptr; } | |
| 73 bool isRecording() const { return m_canvas != nullptr; } | |
|
eseidel
2015/06/23 00:41:32
!!m_canvas works too. This is fine though. :)
iansf
2015/06/23 22:46:09
Acknowledged.
| |
| 62 | 74 |
| 63 protected: | 75 protected: |
| 64 PassRefPtr<DisplayList> finishRecording(); | 76 Canvas(SkCanvas* skCanvas); |
|
abarth-chromium
2015/06/23 02:28:44
Please mark one-argument constructors |explicit|.
iansf
2015/06/23 22:46:09
Done.
| |
| 65 | |
| 66 bool isRecording() const { return m_canvas; } | |
| 67 | 77 |
| 68 private: | 78 private: |
| 69 FloatSize m_size; | 79 // The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording, |
| 70 RefPtr<DisplayList> m_displayList; | 80 // which does not transfer ownership. For this reason, we hold a raw |
| 81 // pointer and manually set the SkCanvas to null in clearSkCanvas. | |
|
abarth-chromium
2015/06/23 02:28:44
@eseidel: Here's the comment that's intended to an
| |
| 71 SkCanvas* m_canvas; | 82 SkCanvas* m_canvas; |
| 72 }; | 83 }; |
| 73 | 84 |
| 74 } // namespace blink | 85 } // namespace blink |
| 75 | 86 |
| 76 #endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_ | 87 #endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_ |
| OLD | NEW |