Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: sky/engine/core/painting/Canvas.h

Issue 1190123003: Decouple Canvas from DisplayList and map Picture and PictureRecorder more directly to their Skia co… (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rework the API a bit Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
31 static PassRefPtr<Canvas> create(PassRefPtr<Canvas> canvas) {
32 ASSERT(canvas);
33 return create(canvas->m_canvas);
34 }
35
27 ~Canvas() override; 36 ~Canvas() override;
28 37
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(); 38 void save();
35 void saveLayer(const Rect& bounds, const Paint* paint = nullptr); 39 void saveLayer(const Rect& bounds, const Paint* paint = nullptr);
36 void restore(); 40 void restore();
37 41
38 void translate(float dx, float dy); 42 void translate(float dx, float dy);
39 void scale(float sx, float sy); 43 void scale(float sx, float sy);
40 void rotate(float radians); 44 void rotate(float radians);
41 void skew(float sx, float sy); 45 void skew(float sx, float sy);
42 void concat(const Float32List& matrix4); 46 void concat(const Float32List& matrix4);
43 47
44 void clipRect(const Rect& rect); 48 void clipRect(const Rect& rect);
45 void clipRRect(const RRect* rrect); 49 void clipRRect(const RRect* rrect);
46 void clipPath(const CanvasPath* path); 50 void clipPath(const CanvasPath* path);
47 51
48 void drawLine(float x0, float y0, float x1, float y1, const Paint* paint); 52 void drawLine(float x0, float y0, float x1, float y1, const Paint* paint);
49 void drawPicture(Picture* picture); 53 void drawPicture(Picture* picture);
50 void drawPaint(const Paint* paint); 54 void drawPaint(const Paint* paint);
51 void drawRect(const Rect& rect, const Paint* paint); 55 void drawRect(const Rect& rect, const Paint* paint);
52 void drawRRect(const RRect* rrect, const Paint* paint); 56 void drawRRect(const RRect* rrect, const Paint* paint);
53 void drawOval(const Rect& rect, const Paint* paint); 57 void drawOval(const Rect& rect, const Paint* paint);
54 void drawCircle(float x, float y, float radius, const Paint* paint); 58 void drawCircle(float x, float y, float radius, const Paint* paint);
55 void drawPath(const CanvasPath* path, const Paint* paint); 59 void drawPath(const CanvasPath* path, const Paint* paint);
56 void drawImage(const CanvasImage* image, 60 void drawImage(const CanvasImage* image,
57 float x, 61 float x,
58 float y, 62 float y,
59 const Paint* paint); 63 const Paint* paint);
60 64
61 SkCanvas* skCanvas() { return m_canvas; } 65 SkCanvas* skCanvas() { return m_canvas; }
66 void clearSkCanvas() { m_canvas = nullptr; }
abarth-chromium 2015/06/20 00:50:29 How does this mechanism work with the create(PassR
67 bool isRecording() const { return m_canvas != nullptr; }
abarth-chromium 2015/06/20 00:50:29 Does anyone call this function anymore? If not, w
62 68
63 protected: 69 protected:
64 PassRefPtr<DisplayList> finishRecording(); 70 Canvas(SkCanvas* skCanvas);
abarth-chromium 2015/06/20 00:50:29 Please mark one-argument constructors explicit.
65
66 bool isRecording() const { return m_canvas; }
67 71
68 private: 72 private:
69 FloatSize m_size; 73 // The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording,
70 RefPtr<DisplayList> m_displayList; 74 // which does not transfer ownership. For this reason, we hold a raw
75 // pointer and manually set the SkCanvas to null in clearSkCanvas.
71 SkCanvas* m_canvas; 76 SkCanvas* m_canvas;
72 }; 77 };
73 78
74 } // namespace blink 79 } // namespace blink
75 80
76 #endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_ 81 #endif // SKY_ENGINE_CORE_PAINTING_CANVAS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698