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/RRect.h" | 11 #include "sky/engine/core/painting/RRect.h" |
12 #include "sky/engine/core/painting/Rect.h" | 12 #include "sky/engine/core/painting/Rect.h" |
13 #include "sky/engine/platform/graphics/DisplayList.h" | 13 #include "sky/engine/platform/graphics/DisplayList.h" |
14 #include "sky/engine/tonic/dart_wrappable.h" | 14 #include "sky/engine/tonic/dart_wrappable.h" |
15 #include "sky/engine/tonic/float32_list.h" | 15 #include "sky/engine/tonic/float32_list.h" |
16 #include "sky/engine/wtf/PassRefPtr.h" | 16 #include "sky/engine/wtf/PassRefPtr.h" |
17 #include "sky/engine/wtf/RefCounted.h" | 17 #include "sky/engine/wtf/RefCounted.h" |
| 18 #include "third_party/skia/include/core/SkCanvas.h" |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 class Element; | |
21 class CanvasImage; | 21 class CanvasImage; |
22 | 22 |
23 class Canvas : public RefCounted<Canvas>, public DartWrappable { | 23 class Canvas : public RefCounted<Canvas>, public DartWrappable { |
24 DEFINE_WRAPPERTYPEINFO(); | 24 DEFINE_WRAPPERTYPEINFO(); |
25 public: | 25 public: |
26 Canvas(const FloatSize& size); | 26 static PassRefPtr<Canvas> create(SkCanvas* skCanvas) { |
| 27 ASSERT(skCanvas); |
| 28 return adoptRef(new Canvas(skCanvas)); |
| 29 } |
| 30 |
27 ~Canvas() override; | 31 ~Canvas() override; |
28 | 32 |
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(); | 33 void save(); |
35 void saveLayer(const Rect& bounds, const Paint* paint = nullptr); | 34 void saveLayer(const Rect& bounds, const Paint* paint = nullptr); |
36 void restore(); | 35 void restore(); |
37 | 36 |
38 void translate(float dx, float dy); | 37 void translate(float dx, float dy); |
39 void scale(float sx, float sy); | 38 void scale(float sx, float sy); |
40 void rotate(float radians); | 39 void rotate(float radians); |
41 void skew(float sx, float sy); | 40 void skew(float sx, float sy); |
42 void concat(const Float32List& matrix4); | 41 void concat(const Float32List& matrix4); |
43 | 42 |
44 void clipRect(const Rect& rect); | 43 void clipRect(const Rect& rect); |
45 void clipRRect(const RRect* rrect); | 44 void clipRRect(const RRect* rrect); |
46 void clipPath(const CanvasPath* path); | 45 void clipPath(const CanvasPath* path); |
47 | 46 |
48 void drawLine(float x0, float y0, float x1, float y1, const Paint* paint); | 47 void drawLine(float x0, float y0, float x1, float y1, const Paint* paint); |
49 void drawPicture(Picture* picture); | 48 void drawPicture(Picture* picture); |
50 void drawPaint(const Paint* paint); | 49 void drawPaint(const Paint* paint); |
51 void drawRect(const Rect& rect, const Paint* paint); | 50 void drawRect(const Rect& rect, const Paint* paint); |
52 void drawRRect(const RRect* rrect, const Paint* paint); | 51 void drawRRect(const RRect* rrect, const Paint* paint); |
53 void drawOval(const Rect& rect, const Paint* paint); | 52 void drawOval(const Rect& rect, const Paint* paint); |
54 void drawCircle(float x, float y, float radius, const Paint* paint); | 53 void drawCircle(float x, float y, float radius, const Paint* paint); |
55 void drawPath(const CanvasPath* path, const Paint* paint); | 54 void drawPath(const CanvasPath* path, const Paint* paint); |
56 void drawImage(const CanvasImage* image, | 55 void drawImage(const CanvasImage* image, |
57 float x, | 56 float x, |
58 float y, | 57 float y, |
59 const Paint* paint); | 58 const Paint* paint); |
60 | 59 |
61 SkCanvas* skCanvas() { return m_canvas; } | 60 SkCanvas* skCanvas() { return m_canvas; } |
| 61 void clearSkCanvas() { m_canvas = nullptr; } |
62 | 62 |
63 protected: | 63 protected: |
64 PassRefPtr<DisplayList> finishRecording(); | |
65 | |
66 bool isRecording() const { return m_canvas; } | 64 bool isRecording() const { return m_canvas; } |
| 65 Canvas(SkCanvas* skCanvas); |
67 | 66 |
68 private: | 67 private: |
69 FloatSize m_size; | 68 // The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording, |
70 RefPtr<DisplayList> m_displayList; | 69 // which does not transfer ownership. For this reason, we hold a raw |
| 70 // pointer and manually set the SkCanvas to null in clearSkCanvas. |
71 SkCanvas* m_canvas; | 71 SkCanvas* m_canvas; |
72 }; | 72 }; |
73 | 73 |
74 } // namespace blink | 74 } // namespace blink |
75 | 75 |
76 #endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_ | 76 #endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_ |
OLD | NEW |