OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CC_PAINT_PAINT_CANVAS_H_ | 5 #ifndef CC_PAINT_PAINT_CANVAS_H_ |
6 #define CC_PAINT_PAINT_CANVAS_H_ | 6 #define CC_PAINT_PAINT_CANVAS_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "cc/paint/paint_export.h" | 12 #include "cc/paint/paint_export.h" |
13 #include "cc/paint/paint_record.h" | |
14 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
15 | 14 |
16 namespace cc { | 15 namespace cc { |
17 | 16 |
18 class DisplayItemList; | 17 class DisplayItemList; |
19 class PaintFlags; | 18 class PaintFlags; |
| 19 class PaintOpBuffer; |
| 20 |
| 21 using PaintRecord = PaintOpBuffer; |
20 | 22 |
21 class CC_PAINT_EXPORT PaintCanvas { | 23 class CC_PAINT_EXPORT PaintCanvas { |
22 public: | 24 public: |
23 virtual ~PaintCanvas() {} | 25 virtual ~PaintCanvas() {} |
24 | 26 |
25 virtual SkMetaData& getMetaData() = 0; | 27 virtual SkMetaData& getMetaData() = 0; |
| 28 |
| 29 // TODO(enne): this only appears to mostly be used to determine if this is |
| 30 // recording or not, so could be simplified or removed. |
26 virtual SkImageInfo imageInfo() const = 0; | 31 virtual SkImageInfo imageInfo() const = 0; |
27 | 32 |
28 // TODO(enne): It would be nice to get rid of flush() entirely, as it | 33 // TODO(enne): It would be nice to get rid of flush() entirely, as it |
29 // doesn't really make sense for recording. However, this gets used by | 34 // doesn't really make sense for recording. However, this gets used by |
30 // SkCanvasVideoRenderer which takes a PaintCanvas to paint both | 35 // SkCanvasVideoRenderer which takes a PaintCanvas to paint both |
31 // software and hardware video. This is super entangled with ImageBuffer | 36 // software and hardware video. This is super entangled with ImageBuffer |
32 // and canvas/video painting in Blink where the same paths are used for | 37 // and canvas/video painting in Blink where the same paths are used for |
33 // both recording and gpu work. | 38 // both recording and gpu work. |
34 virtual void flush() = 0; | 39 virtual void flush() = 0; |
35 | 40 |
36 virtual SkISize getBaseLayerSize() const = 0; | 41 virtual SkISize getBaseLayerSize() const = 0; |
37 virtual bool readPixels(const SkImageInfo& dest_info, | 42 virtual bool readPixels(const SkImageInfo& dest_info, |
38 void* dest_pixels, | 43 void* dest_pixels, |
39 size_t dest_row_bytes, | 44 size_t dest_row_bytes, |
40 int src_x, | 45 int src_x, |
41 int src_y) = 0; | 46 int src_y) = 0; |
42 virtual bool readPixels(SkBitmap* bitmap, int src_x, int src_y) = 0; | 47 virtual bool readPixels(SkBitmap* bitmap, int src_x, int src_y) = 0; |
43 virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) = 0; | 48 virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) = 0; |
44 virtual bool writePixels(const SkImageInfo& info, | 49 virtual bool writePixels(const SkImageInfo& info, |
45 const void* pixels, | 50 const void* pixels, |
46 size_t row_bytes, | 51 size_t row_bytes, |
47 int x, | 52 int x, |
48 int y) = 0; | 53 int y) = 0; |
49 virtual int save() = 0; | 54 virtual int save() = 0; |
50 virtual int saveLayer(const SkRect* bounds, const PaintFlags* flags) = 0; | 55 virtual int saveLayer(const SkRect* bounds, const PaintFlags* flags) = 0; |
51 virtual int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) = 0; | 56 virtual int saveLayerAlpha(const SkRect* bounds, uint8_t alpha) = 0; |
52 | 57 |
53 virtual void restore() = 0; | 58 virtual void restore() = 0; |
54 virtual int getSaveCount() const = 0; | 59 virtual int getSaveCount() const = 0; |
55 virtual void restoreToCount(int save_count) = 0; | 60 virtual void restoreToCount(int save_count) = 0; |
56 virtual void translate(SkScalar dx, SkScalar dy) = 0; | 61 virtual void translate(SkScalar dx, SkScalar dy) = 0; |
57 virtual void scale(SkScalar sx, SkScalar sy) = 0; | 62 virtual void scale(SkScalar sx, SkScalar sy) = 0; |
58 virtual void rotate(SkScalar degrees) = 0; | 63 virtual void rotate(SkScalar degrees) = 0; |
59 virtual void concat(const SkMatrix& matrix) = 0; | 64 virtual void concat(const SkMatrix& matrix) = 0; |
60 virtual void setMatrix(const SkMatrix& matrix) = 0; | 65 virtual void setMatrix(const SkMatrix& matrix) = 0; |
61 | 66 |
(...skipping 30 matching lines...) Expand all Loading... |
92 } | 97 } |
93 | 98 |
94 virtual bool quickReject(const SkRect& rect) const = 0; | 99 virtual bool quickReject(const SkRect& rect) const = 0; |
95 virtual bool quickReject(const SkPath& path) const = 0; | 100 virtual bool quickReject(const SkPath& path) const = 0; |
96 virtual SkRect getLocalClipBounds() const = 0; | 101 virtual SkRect getLocalClipBounds() const = 0; |
97 virtual bool getLocalClipBounds(SkRect* bounds) const = 0; | 102 virtual bool getLocalClipBounds(SkRect* bounds) const = 0; |
98 virtual SkIRect getDeviceClipBounds() const = 0; | 103 virtual SkIRect getDeviceClipBounds() const = 0; |
99 virtual bool getDeviceClipBounds(SkIRect* bounds) const = 0; | 104 virtual bool getDeviceClipBounds(SkIRect* bounds) const = 0; |
100 virtual void drawColor(SkColor color, SkBlendMode mode) = 0; | 105 virtual void drawColor(SkColor color, SkBlendMode mode) = 0; |
101 void drawColor(SkColor color) { drawColor(color, SkBlendMode::kSrcOver); } | 106 void drawColor(SkColor color) { drawColor(color, SkBlendMode::kSrcOver); } |
| 107 |
| 108 // TODO(enne): This is a synonym for drawColor with kSrc. Remove it. |
102 virtual void clear(SkColor color) = 0; | 109 virtual void clear(SkColor color) = 0; |
103 | 110 |
104 virtual void drawLine(SkScalar x0, | 111 virtual void drawLine(SkScalar x0, |
105 SkScalar y0, | 112 SkScalar y0, |
106 SkScalar x1, | 113 SkScalar x1, |
107 SkScalar y1, | 114 SkScalar y1, |
108 const PaintFlags& flags) = 0; | 115 const PaintFlags& flags) = 0; |
109 virtual void drawRect(const SkRect& rect, const PaintFlags& flags) = 0; | 116 virtual void drawRect(const SkRect& rect, const PaintFlags& flags) = 0; |
110 virtual void drawIRect(const SkIRect& rect, const PaintFlags& flags) = 0; | 117 virtual void drawIRect(const SkIRect& rect, const PaintFlags& flags) = 0; |
111 virtual void drawOval(const SkRect& oval, const PaintFlags& flags) = 0; | 118 virtual void drawOval(const SkRect& oval, const PaintFlags& flags) = 0; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 181 |
175 virtual bool isClipEmpty() const = 0; | 182 virtual bool isClipEmpty() const = 0; |
176 virtual bool isClipRect() const = 0; | 183 virtual bool isClipRect() const = 0; |
177 virtual const SkMatrix& getTotalMatrix() const = 0; | 184 virtual const SkMatrix& getTotalMatrix() const = 0; |
178 | 185 |
179 // For GraphicsContextCanvas only. Maybe this could be rewritten? | 186 // For GraphicsContextCanvas only. Maybe this could be rewritten? |
180 virtual void temporary_internal_describeTopLayer(SkMatrix* matrix, | 187 virtual void temporary_internal_describeTopLayer(SkMatrix* matrix, |
181 SkIRect* clip_bounds) = 0; | 188 SkIRect* clip_bounds) = 0; |
182 | 189 |
183 virtual bool ToPixmap(SkPixmap* output) = 0; | 190 virtual bool ToPixmap(SkPixmap* output) = 0; |
184 virtual void AnnotateRectWithURL(const SkRect& rect, SkData* data) = 0; | 191 |
185 virtual void AnnotateNamedDestination(const SkPoint& point, SkData* data) = 0; | 192 enum class AnnotationType { |
186 virtual void AnnotateLinkToDestination(const SkRect& rect, SkData* data) = 0; | 193 URL, |
| 194 NAMED_DESTINATION, |
| 195 LINK_TO_DESTINATION, |
| 196 }; |
| 197 virtual void Annotate(AnnotationType type, |
| 198 const SkRect& rect, |
| 199 sk_sp<SkData> data) = 0; |
187 | 200 |
188 // TODO(enne): maybe this should live on PaintRecord, but that's not | 201 // TODO(enne): maybe this should live on PaintRecord, but that's not |
189 // possible when PaintRecord is a typedef. | 202 // possible when PaintRecord is a typedef. |
190 virtual void PlaybackPaintRecord(sk_sp<const PaintRecord> record) = 0; | 203 virtual void PlaybackPaintRecord(sk_sp<const PaintRecord> record) = 0; |
191 | 204 |
192 protected: | 205 protected: |
193 friend class PaintSurface; | 206 friend class PaintSurface; |
194 friend class PaintRecorder; | 207 friend class PaintRecorder; |
195 friend CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL( | |
196 PaintCanvas* canvas, | |
197 const SkRect& rect, | |
198 SkData* data); | |
199 friend CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination( | |
200 PaintCanvas* canvas, | |
201 const SkPoint& point, | |
202 SkData* data); | |
203 friend CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination( | |
204 PaintCanvas* canvas, | |
205 const SkRect& rect, | |
206 SkData* data); | |
207 friend CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); | 208 friend CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); |
208 }; | 209 }; |
209 | 210 |
210 class CC_PAINT_EXPORT PaintCanvasAutoRestore { | 211 class CC_PAINT_EXPORT PaintCanvasAutoRestore { |
211 public: | 212 public: |
212 PaintCanvasAutoRestore(PaintCanvas* canvas, bool save) : canvas_(canvas) { | 213 PaintCanvasAutoRestore(PaintCanvas* canvas, bool save) : canvas_(canvas) { |
213 if (canvas_) { | 214 if (canvas_) { |
214 save_count_ = canvas_->getSaveCount(); | 215 save_count_ = canvas_->getSaveCount(); |
215 if (save) { | 216 if (save) { |
216 canvas_->save(); | 217 canvas_->save(); |
(...skipping 27 matching lines...) Expand all Loading... |
244 // PaintCanvas equivalent of skia::GetWritablePixels. | 245 // PaintCanvas equivalent of skia::GetWritablePixels. |
245 CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); | 246 CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); |
246 | 247 |
247 // Following routines are used in print preview workflow to mark the | 248 // Following routines are used in print preview workflow to mark the |
248 // preview metafile. | 249 // preview metafile. |
249 #if defined(OS_MACOSX) | 250 #if defined(OS_MACOSX) |
250 CC_PAINT_EXPORT void SetIsPreviewMetafile(PaintCanvas* canvas, bool is_preview); | 251 CC_PAINT_EXPORT void SetIsPreviewMetafile(PaintCanvas* canvas, bool is_preview); |
251 CC_PAINT_EXPORT bool IsPreviewMetafile(PaintCanvas* canvas); | 252 CC_PAINT_EXPORT bool IsPreviewMetafile(PaintCanvas* canvas); |
252 #endif | 253 #endif |
253 | 254 |
254 CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL(PaintCanvas* canvas, | |
255 const SkRect& rect, | |
256 SkData* data); | |
257 | |
258 CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination(PaintCanvas* canvas, | |
259 const SkPoint& point, | |
260 SkData* data); | |
261 | |
262 CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas, | |
263 const SkRect& rect, | |
264 SkData* data); | |
265 | |
266 } // namespace cc | 255 } // namespace cc |
267 | 256 |
268 #endif // CC_PAINT_PAINT_CANVAS_H_ | 257 #endif // CC_PAINT_PAINT_CANVAS_H_ |
OLD | NEW |