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

Side by Side Diff: cc/paint/paint_canvas.h

Issue 2752593002: cc: Make PaintCanvas abstract (Closed)
Patch Set: Separate files Created 3 years, 9 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 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 <memory>
9
10 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
11 #include "base/logging.h"
12 #include "base/macros.h" 9 #include "base/macros.h"
13 #include "build/build_config.h" 10 #include "build/build_config.h"
14 #include "cc/paint/paint_export.h" 11 #include "cc/paint/paint_export.h"
15 #include "cc/paint/paint_flags.h"
16 #include "cc/paint/paint_record.h" 12 #include "cc/paint/paint_record.h"
17 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
18 #include "third_party/skia/include/utils/SkNoDrawCanvas.h"
19 14
20 namespace cc { 15 namespace cc {
21 16
22 class PaintFlags; 17 class PaintFlags;
23 18
24 class CC_PAINT_EXPORT PaintCanvas { 19 class CC_PAINT_EXPORT PaintCanvas {
25 public: 20 public:
26 // TODO(enne): remove all constructors but the one that takes an SkCanvas 21 virtual SkMetaData& getMetaData() = 0;
27 // and a future one that will take a PaintOpBuffer to build a PaintRecord. 22 virtual SkImageInfo imageInfo() const = 0;
28 explicit PaintCanvas(SkCanvas* canvas); 23 virtual bool getProps(SkSurfaceProps* props) const = 0;
29 explicit PaintCanvas(const SkBitmap& bitmap); 24
30 explicit PaintCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
31 ~PaintCanvas();
32
33 ALWAYS_INLINE SkMetaData& getMetaData() { return canvas_->getMetaData(); }
34 ALWAYS_INLINE SkImageInfo imageInfo() const { return canvas_->imageInfo(); }
35 ALWAYS_INLINE bool getProps(SkSurfaceProps* props) const {
36 return canvas_->getProps(props);
37 }
38 // TODO(enne): It would be nice to get rid of flush() entirely, as it 25 // TODO(enne): It would be nice to get rid of flush() entirely, as it
39 // doesn't really make sense for recording. However, this gets used by 26 // doesn't really make sense for recording. However, this gets used by
40 // SkCanvasVideoRenderer which takes a PaintCanvas to paint both 27 // SkCanvasVideoRenderer which takes a PaintCanvas to paint both
41 // software and hardware video. This is super entangled with ImageBuffer 28 // software and hardware video. This is super entangled with ImageBuffer
42 // and canvas/video painting in Blink where the same paths are used for 29 // and canvas/video painting in Blink where the same paths are used for
43 // both recording and gpu work. 30 // both recording and gpu work.
44 ALWAYS_INLINE void flush() { canvas_->flush(); } 31 virtual void flush() = 0;
45 32
46 ALWAYS_INLINE SkISize getBaseLayerSize() const { 33 virtual SkISize getBaseLayerSize() const = 0;
47 return canvas_->getBaseLayerSize(); 34 virtual bool peekPixels(SkPixmap* pixmap) = 0;
48 } 35 virtual bool readPixels(const SkImageInfo& dest_info,
49 ALWAYS_INLINE bool peekPixels(SkPixmap* pixmap) { 36 void* dest_pixels,
50 return canvas_->peekPixels(pixmap); 37 size_t dest_row_bytes,
51 } 38 int src_x,
52 ALWAYS_INLINE bool readPixels(const SkImageInfo& dest_info, 39 int src_y) = 0;
53 void* dest_pixels, 40 virtual bool readPixels(SkBitmap* bitmap, int src_x, int src_y) = 0;
54 size_t dest_row_bytes, 41 virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) = 0;
55 int src_x, 42 virtual bool writePixels(const SkImageInfo& info,
56 int src_y) { 43 const void* pixels,
57 return canvas_->readPixels(dest_info, dest_pixels, dest_row_bytes, src_x, 44 size_t row_bytes,
58 src_y); 45 int x,
59 } 46 int y) = 0;
60 ALWAYS_INLINE bool readPixels(SkBitmap* bitmap, int src_x, int src_y) { 47 virtual int save() = 0;
61 return canvas_->readPixels(bitmap, src_x, src_y); 48 virtual int saveLayer(const SkRect* bounds, const PaintFlags* flags) = 0;
62 } 49 virtual int saveLayer(const SkRect& bounds, const PaintFlags* flags) = 0;
63 ALWAYS_INLINE bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { 50 virtual int saveLayerPreserveLCDTextRequests(const SkRect* bounds,
64 return canvas_->readPixels(srcRect, bitmap); 51 const PaintFlags* flags) = 0;
65 } 52 virtual int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) = 0;
66 ALWAYS_INLINE bool writePixels(const SkImageInfo& info, 53
67 const void* pixels, 54 virtual void restore() = 0;
68 size_t row_bytes, 55 virtual int getSaveCount() const = 0;
69 int x, 56 virtual void restoreToCount(int save_count) = 0;
70 int y) { 57 virtual void translate(SkScalar dx, SkScalar dy) = 0;
71 return canvas_->writePixels(info, pixels, row_bytes, x, y); 58 virtual void scale(SkScalar sx, SkScalar sy) = 0;
72 } 59 virtual void rotate(SkScalar degrees) = 0;
73 ALWAYS_INLINE int save() { return canvas_->save(); } 60 virtual void rotate(SkScalar degrees, SkScalar px, SkScalar py) = 0;
74 ALWAYS_INLINE int saveLayer(const SkRect* bounds, const PaintFlags* flags) { 61 virtual void skew(SkScalar sx, SkScalar sy) = 0;
75 return canvas_->saveLayer(bounds, ToSkPaint(flags)); 62 virtual void concat(const SkMatrix& matrix) = 0;
76 } 63 virtual void setMatrix(const SkMatrix& matrix) = 0;
77 ALWAYS_INLINE int saveLayer(const SkRect& bounds, const PaintFlags* flags) { 64 virtual void resetMatrix() = 0;
78 return canvas_->saveLayer(bounds, ToSkPaint(flags)); 65 virtual void clipRect(const SkRect& rect,
79 } 66 SkClipOp op,
80 ALWAYS_INLINE int saveLayerPreserveLCDTextRequests(const SkRect* bounds, 67 bool do_anti_alias = false) = 0;
81 const PaintFlags* flags) { 68 virtual void clipRect(const SkRect& rect, bool do_anti_alias = false) = 0;
82 return canvas_->saveLayerPreserveLCDTextRequests(bounds, ToSkPaint(flags)); 69 virtual void clipRRect(const SkRRect& rrect,
83 } 70 SkClipOp op,
84 ALWAYS_INLINE int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { 71 bool do_anti_alias) = 0;
85 return canvas_->saveLayerAlpha(bounds, alpha); 72 virtual void clipRRect(const SkRRect& rrect, SkClipOp op) = 0;
86 } 73 virtual void clipRRect(const SkRRect& rrect, bool do_anti_alias = false) = 0;
87 74 virtual void clipPath(const SkPath& path,
88 ALWAYS_INLINE void restore() { canvas_->restore(); } 75 SkClipOp op,
89 ALWAYS_INLINE int getSaveCount() const { return canvas_->getSaveCount(); } 76 bool do_anti_alias) = 0;
90 ALWAYS_INLINE void restoreToCount(int save_count) { 77 virtual void clipPath(const SkPath& path, SkClipOp op) = 0;
91 canvas_->restoreToCount(save_count); 78 virtual void clipPath(const SkPath& path, bool do_anti_alias = false) = 0;
92 } 79 virtual void clipRegion(const SkRegion& device_region,
93 ALWAYS_INLINE void translate(SkScalar dx, SkScalar dy) { 80 SkClipOp op = SkClipOp::kIntersect) = 0;
94 canvas_->translate(dx, dy); 81 virtual bool quickReject(const SkRect& rect) const = 0;
95 } 82 virtual bool quickReject(const SkPath& path) const = 0;
96 ALWAYS_INLINE void scale(SkScalar sx, SkScalar sy) { canvas_->scale(sx, sy); } 83 virtual SkRect getLocalClipBounds() const = 0;
97 ALWAYS_INLINE void rotate(SkScalar degrees) { canvas_->rotate(degrees); } 84 virtual bool getLocalClipBounds(SkRect* bounds) const = 0;
98 ALWAYS_INLINE void rotate(SkScalar degrees, SkScalar px, SkScalar py) { 85 virtual SkIRect getDeviceClipBounds() const = 0;
99 canvas_->rotate(degrees, px, py); 86 virtual bool getDeviceClipBounds(SkIRect* bounds) const = 0;
100 } 87 virtual void drawColor(SkColor color,
101 ALWAYS_INLINE void skew(SkScalar sx, SkScalar sy) { canvas_->skew(sx, sy); } 88 SkBlendMode mode = SkBlendMode::kSrcOver) = 0;
102 ALWAYS_INLINE void concat(const SkMatrix& matrix) { canvas_->concat(matrix); } 89 virtual void clear(SkColor color) = 0;
103 ALWAYS_INLINE void setMatrix(const SkMatrix& matrix) { 90 virtual void discard() = 0;
104 canvas_->setMatrix(matrix); 91
105 } 92 virtual void drawLine(SkScalar x0,
106 ALWAYS_INLINE void resetMatrix() { canvas_->resetMatrix(); } 93 SkScalar y0,
107 ALWAYS_INLINE void clipRect(const SkRect& rect, 94 SkScalar x1,
108 SkClipOp op, 95 SkScalar y1,
109 bool do_anti_alias = false) { 96 const PaintFlags& flags) = 0;
110 canvas_->clipRect(rect, op, do_anti_alias); 97 virtual void drawRect(const SkRect& rect, const PaintFlags& flags) = 0;
111 } 98 virtual void drawIRect(const SkIRect& rect, const PaintFlags& flags) = 0;
112 ALWAYS_INLINE void clipRect(const SkRect& rect, bool do_anti_alias = false) { 99 virtual void drawOval(const SkRect& oval, const PaintFlags& flags) = 0;
113 canvas_->clipRect(rect, do_anti_alias); 100 virtual void drawRRect(const SkRRect& rrect, const PaintFlags& flags) = 0;
114 } 101 virtual void drawDRRect(const SkRRect& outer,
115 ALWAYS_INLINE void clipRRect(const SkRRect& rrect, 102 const SkRRect& inner,
116 SkClipOp op, 103 const PaintFlags& flags) = 0;
117 bool do_anti_alias) { 104 virtual void drawCircle(SkScalar cx,
118 canvas_->clipRRect(rrect, op, do_anti_alias); 105 SkScalar cy,
119 } 106 SkScalar radius,
120 ALWAYS_INLINE void clipRRect(const SkRRect& rrect, SkClipOp op) { 107 const PaintFlags& flags) = 0;
121 canvas_->clipRRect(rrect, op); 108 virtual void drawArc(const SkRect& oval,
122 } 109 SkScalar start_angle,
123 ALWAYS_INLINE void clipRRect(const SkRRect& rrect, 110 SkScalar sweep_angle,
124 bool do_anti_alias = false) { 111 bool use_center,
125 canvas_->clipRRect(rrect, do_anti_alias); 112 const PaintFlags& flags) = 0;
126 } 113 virtual void drawRoundRect(const SkRect& rect,
127 ALWAYS_INLINE void clipPath(const SkPath& path, 114 SkScalar rx,
128 SkClipOp op, 115 SkScalar ry,
129 bool do_anti_alias) { 116 const PaintFlags& flags) = 0;
130 canvas_->clipPath(path, op, do_anti_alias); 117 virtual void drawPath(const SkPath& path, const PaintFlags& flags) = 0;
131 } 118 virtual void drawImage(const SkImage* image,
132 ALWAYS_INLINE void clipPath(const SkPath& path, SkClipOp op) { 119 SkScalar left,
133 canvas_->clipPath(path, op); 120 SkScalar top,
134 } 121 const PaintFlags* flags = nullptr) = 0;
135 ALWAYS_INLINE void clipPath(const SkPath& path, bool do_anti_alias = false) { 122 virtual void drawImage(const sk_sp<SkImage>& image,
136 canvas_->clipPath(path, do_anti_alias); 123 SkScalar left,
137 } 124 SkScalar top,
138 ALWAYS_INLINE void clipRegion(const SkRegion& device_region, 125 const PaintFlags* flags = nullptr) = 0;
139 SkClipOp op = SkClipOp::kIntersect) {
140 canvas_->clipRegion(device_region, op);
141 }
142 ALWAYS_INLINE bool quickReject(const SkRect& rect) const {
143 return canvas_->quickReject(rect);
144 }
145 ALWAYS_INLINE bool quickReject(const SkPath& path) const {
146 return canvas_->quickReject(path);
147 }
148 ALWAYS_INLINE SkRect getLocalClipBounds() const {
149 return canvas_->getLocalClipBounds();
150 }
151 ALWAYS_INLINE bool getLocalClipBounds(SkRect* bounds) const {
152 return canvas_->getLocalClipBounds(bounds);
153 }
154 ALWAYS_INLINE SkIRect getDeviceClipBounds() const {
155 return canvas_->getDeviceClipBounds();
156 }
157 ALWAYS_INLINE bool getDeviceClipBounds(SkIRect* bounds) const {
158 return canvas_->getDeviceClipBounds(bounds);
159 }
160 ALWAYS_INLINE void drawColor(SkColor color,
161 SkBlendMode mode = SkBlendMode::kSrcOver) {
162 canvas_->drawColor(color, mode);
163 }
164 ALWAYS_INLINE void clear(SkColor color) { canvas_->clear(color); }
165 ALWAYS_INLINE void discard() { canvas_->discard(); }
166
167 ALWAYS_INLINE void drawLine(SkScalar x0,
168 SkScalar y0,
169 SkScalar x1,
170 SkScalar y1,
171 const PaintFlags& flags) {
172 canvas_->drawLine(x0, y0, x1, y1, ToSkPaint(flags));
173 }
174 ALWAYS_INLINE void drawRect(const SkRect& rect, const PaintFlags& flags) {
175 canvas_->drawRect(rect, ToSkPaint(flags));
176 }
177 ALWAYS_INLINE void drawIRect(const SkIRect& rect, const PaintFlags& flags) {
178 canvas_->drawIRect(rect, ToSkPaint(flags));
179 }
180 ALWAYS_INLINE void drawOval(const SkRect& oval, const PaintFlags& flags) {
181 canvas_->drawOval(oval, ToSkPaint(flags));
182 }
183 ALWAYS_INLINE void drawRRect(const SkRRect& rrect, const PaintFlags& flags) {
184 canvas_->drawRRect(rrect, ToSkPaint(flags));
185 }
186 ALWAYS_INLINE void drawDRRect(const SkRRect& outer,
187 const SkRRect& inner,
188 const PaintFlags& flags) {
189 canvas_->drawDRRect(outer, inner, ToSkPaint(flags));
190 }
191 ALWAYS_INLINE void drawCircle(SkScalar cx,
192 SkScalar cy,
193 SkScalar radius,
194 const PaintFlags& flags) {
195 canvas_->drawCircle(cx, cy, radius, ToSkPaint(flags));
196 }
197 ALWAYS_INLINE void drawArc(const SkRect& oval,
198 SkScalar start_angle,
199 SkScalar sweep_angle,
200 bool use_center,
201 const PaintFlags& flags) {
202 canvas_->drawArc(oval, start_angle, sweep_angle, use_center,
203 ToSkPaint(flags));
204 }
205 ALWAYS_INLINE void drawRoundRect(const SkRect& rect,
206 SkScalar rx,
207 SkScalar ry,
208 const PaintFlags& flags) {
209 canvas_->drawRoundRect(rect, rx, ry, ToSkPaint(flags));
210 }
211 ALWAYS_INLINE void drawPath(const SkPath& path, const PaintFlags& flags) {
212 canvas_->drawPath(path, ToSkPaint(flags));
213 }
214 ALWAYS_INLINE void drawImage(const SkImage* image,
215 SkScalar left,
216 SkScalar top,
217 const PaintFlags* flags = nullptr) {
218 canvas_->drawImage(image, left, top, ToSkPaint(flags));
219 }
220 ALWAYS_INLINE void drawImage(const sk_sp<SkImage>& image,
221 SkScalar left,
222 SkScalar top,
223 const PaintFlags* flags = nullptr) {
224 canvas_->drawImage(image, left, top, ToSkPaint(flags));
225 }
226 126
227 enum SrcRectConstraint { 127 enum SrcRectConstraint {
228 kStrict_SrcRectConstraint = SkCanvas::kStrict_SrcRectConstraint, 128 kStrict_SrcRectConstraint = SkCanvas::kStrict_SrcRectConstraint,
229 kFast_SrcRectConstraint = SkCanvas::kFast_SrcRectConstraint, 129 kFast_SrcRectConstraint = SkCanvas::kFast_SrcRectConstraint,
230 }; 130 };
231 131
232 ALWAYS_INLINE void drawImageRect( 132 virtual void drawImageRect(
233 const SkImage* image, 133 const SkImage* image,
234 const SkRect& src, 134 const SkRect& src,
235 const SkRect& dst, 135 const SkRect& dst,
236 const PaintFlags* flags, 136 const PaintFlags* flags,
237 SrcRectConstraint constraint = kStrict_SrcRectConstraint) { 137 SrcRectConstraint constraint = kStrict_SrcRectConstraint) = 0;
238 canvas_->drawImageRect( 138 virtual void drawImageRect(
239 image, src, dst, ToSkPaint(flags),
240 static_cast<SkCanvas::SrcRectConstraint>(constraint));
241 }
242 ALWAYS_INLINE void drawImageRect(
243 const SkImage* image, 139 const SkImage* image,
244 const SkIRect& isrc, 140 const SkIRect& isrc,
245 const SkRect& dst, 141 const SkRect& dst,
246 const PaintFlags* flags, 142 const PaintFlags* flags,
247 SrcRectConstraint constraint = kStrict_SrcRectConstraint) { 143 SrcRectConstraint constraint = kStrict_SrcRectConstraint) = 0;
248 canvas_->drawImageRect( 144 virtual void drawImageRect(
249 image, isrc, dst, ToSkPaint(flags),
250 static_cast<SkCanvas::SrcRectConstraint>(constraint));
251 }
252 ALWAYS_INLINE void drawImageRect(
253 const SkImage* image, 145 const SkImage* image,
254 const SkRect& dst, 146 const SkRect& dst,
255 const PaintFlags* flags, 147 const PaintFlags* flags,
256 SrcRectConstraint constraint = kStrict_SrcRectConstraint) { 148 SrcRectConstraint constraint = kStrict_SrcRectConstraint) = 0;
257 canvas_->drawImageRect( 149 virtual void drawImageRect(
258 image, dst, ToSkPaint(flags),
259 static_cast<SkCanvas::SrcRectConstraint>(constraint));
260 }
261 ALWAYS_INLINE void drawImageRect(
262 const sk_sp<SkImage>& image, 150 const sk_sp<SkImage>& image,
263 const SkRect& src, 151 const SkRect& src,
264 const SkRect& dst, 152 const SkRect& dst,
265 const PaintFlags* flags, 153 const PaintFlags* flags,
266 SrcRectConstraint constraint = kStrict_SrcRectConstraint) { 154 SrcRectConstraint constraint = kStrict_SrcRectConstraint) = 0;
267 canvas_->drawImageRect( 155 virtual void drawImageRect(
268 image, src, dst, ToSkPaint(flags),
269 static_cast<SkCanvas::SrcRectConstraint>(constraint));
270 }
271 ALWAYS_INLINE void drawImageRect(
272 const sk_sp<SkImage>& image, 156 const sk_sp<SkImage>& image,
273 const SkIRect& isrc, 157 const SkIRect& isrc,
274 const SkRect& dst, 158 const SkRect& dst,
275 const PaintFlags* flags, 159 const PaintFlags* flags,
276 SrcRectConstraint cons = kStrict_SrcRectConstraint) { 160 SrcRectConstraint cons = kStrict_SrcRectConstraint) = 0;
277 canvas_->drawImageRect(image, isrc, dst, ToSkPaint(flags), 161 virtual void drawImageRect(
278 static_cast<SkCanvas::SrcRectConstraint>(cons));
279 }
280 ALWAYS_INLINE void drawImageRect(
281 const sk_sp<SkImage>& image, 162 const sk_sp<SkImage>& image,
282 const SkRect& dst, 163 const SkRect& dst,
283 const PaintFlags* flags, 164 const PaintFlags* flags,
284 SrcRectConstraint cons = kStrict_SrcRectConstraint) { 165 SrcRectConstraint cons = kStrict_SrcRectConstraint) = 0;
285 canvas_->drawImageRect(image, dst, ToSkPaint(flags), 166 virtual void drawBitmap(const SkBitmap& bitmap,
286 static_cast<SkCanvas::SrcRectConstraint>(cons)); 167 SkScalar left,
287 } 168 SkScalar top,
288 ALWAYS_INLINE void drawBitmap(const SkBitmap& bitmap, 169 const PaintFlags* flags = nullptr) = 0;
289 SkScalar left, 170 virtual void drawBitmapRect(
290 SkScalar top,
291 const PaintFlags* flags = nullptr) {
292 canvas_->drawBitmap(bitmap, left, top, ToSkPaint(flags));
293 }
294 ALWAYS_INLINE void drawBitmapRect(
295 const SkBitmap& bitmap, 171 const SkBitmap& bitmap,
296 const SkRect& src, 172 const SkRect& src,
297 const SkRect& dst, 173 const SkRect& dst,
298 const PaintFlags* flags, 174 const PaintFlags* flags,
299 SrcRectConstraint constraint = kStrict_SrcRectConstraint) { 175 SrcRectConstraint constraint = kStrict_SrcRectConstraint) = 0;
300 canvas_->drawBitmapRect( 176 virtual void drawBitmapRect(
301 bitmap, src, dst, ToSkPaint(flags),
302 static_cast<SkCanvas::SrcRectConstraint>(constraint));
303 }
304 ALWAYS_INLINE void drawBitmapRect(
305 const SkBitmap& bitmap, 177 const SkBitmap& bitmap,
306 const SkIRect& isrc, 178 const SkIRect& isrc,
307 const SkRect& dst, 179 const SkRect& dst,
308 const PaintFlags* flags, 180 const PaintFlags* flags,
309 SrcRectConstraint constraint = kStrict_SrcRectConstraint) { 181 SrcRectConstraint constraint = kStrict_SrcRectConstraint) = 0;
310 canvas_->drawBitmapRect( 182 virtual void drawBitmapRect(
311 bitmap, isrc, dst, ToSkPaint(flags),
312 static_cast<SkCanvas::SrcRectConstraint>(constraint));
313 }
314 ALWAYS_INLINE void drawBitmapRect(
315 const SkBitmap& bitmap, 183 const SkBitmap& bitmap,
316 const SkRect& dst, 184 const SkRect& dst,
317 const PaintFlags* flags, 185 const PaintFlags* flags,
318 SrcRectConstraint constraint = kStrict_SrcRectConstraint) { 186 SrcRectConstraint constraint = kStrict_SrcRectConstraint) = 0;
319 canvas_->drawBitmapRect( 187
320 bitmap, dst, ToSkPaint(flags), 188 virtual void drawText(const void* text,
321 static_cast<SkCanvas::SrcRectConstraint>(constraint)); 189 size_t byte_length,
322 } 190 SkScalar x,
323 191 SkScalar y,
324 ALWAYS_INLINE void drawText(const void* text, 192 const PaintFlags& flags) = 0;
325 size_t byte_length, 193 virtual void drawPosText(const void* text,
326 SkScalar x, 194 size_t byte_length,
327 SkScalar y, 195 const SkPoint pos[],
328 const PaintFlags& flags) { 196 const PaintFlags& flags) = 0;
329 canvas_->drawText(text, byte_length, x, y, ToSkPaint(flags)); 197 virtual void drawTextBlob(const SkTextBlob* blob,
330 } 198 SkScalar x,
331 ALWAYS_INLINE void drawPosText(const void* text, 199 SkScalar y,
332 size_t byte_length, 200 const PaintFlags& flags) = 0;
333 const SkPoint pos[], 201 virtual void drawTextBlob(const sk_sp<SkTextBlob>& blob,
334 const PaintFlags& flags) { 202 SkScalar x,
335 canvas_->drawPosText(text, byte_length, pos, ToSkPaint(flags)); 203 SkScalar y,
336 } 204 const PaintFlags& flags) = 0;
337 ALWAYS_INLINE void drawTextBlob(const SkTextBlob* blob, 205
338 SkScalar x, 206 virtual void drawPicture(const PaintRecord* record) = 0;
339 SkScalar y, 207 virtual void drawPicture(const PaintRecord* record,
340 const PaintFlags& flags) { 208 const SkMatrix* matrix,
341 canvas_->drawTextBlob(blob, x, y, ToSkPaint(flags)); 209 const PaintFlags* flags) = 0;
342 } 210 virtual void drawPicture(sk_sp<PaintRecord> record) = 0;
343 ALWAYS_INLINE void drawTextBlob(const sk_sp<SkTextBlob>& blob, 211
344 SkScalar x, 212 virtual bool isClipEmpty() const = 0;
345 SkScalar y, 213 virtual bool isClipRect() const = 0;
346 const PaintFlags& flags) { 214 virtual const SkMatrix& getTotalMatrix() const = 0;
347 canvas_->drawTextBlob(blob, x, y, ToSkPaint(flags));
348 }
349
350 ALWAYS_INLINE void drawPicture(const PaintRecord* record) {
351 canvas_->drawPicture(ToSkPicture(record));
352 }
353 ALWAYS_INLINE void drawPicture(const PaintRecord* record,
354 const SkMatrix* matrix,
355 const PaintFlags* flags) {
356 canvas_->drawPicture(ToSkPicture(record), matrix, ToSkPaint(flags));
357 }
358 ALWAYS_INLINE void drawPicture(sk_sp<PaintRecord> record) {
359 drawPicture(record.get());
360 }
361
362 ALWAYS_INLINE bool isClipEmpty() const { return canvas_->isClipEmpty(); }
363 ALWAYS_INLINE bool isClipRect() const { return canvas_->isClipRect(); }
364 ALWAYS_INLINE const SkMatrix& getTotalMatrix() const {
365 return canvas_->getTotalMatrix();
366 }
367 215
368 // For GraphicsContextCanvas only. Maybe this could be rewritten? 216 // For GraphicsContextCanvas only. Maybe this could be rewritten?
369 ALWAYS_INLINE void temporary_internal_describeTopLayer(SkMatrix* matrix, 217 virtual void temporary_internal_describeTopLayer(SkMatrix* matrix,
370 SkIRect* clip_bounds) { 218 SkIRect* clip_bounds) = 0;
371 return canvas_->temporary_internal_describeTopLayer(matrix, clip_bounds); 219
372 } 220 virtual bool ToPixmap(SkPixmap* output) = 0;
221 virtual void AnnotateRectWithURL(const SkRect& rect, SkData* data) = 0;
222 virtual void AnnotateNamedDestination(const SkPoint& point, SkData* data) = 0;
223 virtual void AnnotateLinkToDestination(const SkRect& rect, SkData* data) = 0;
373 224
374 protected: 225 protected:
375 friend class PaintSurface; 226 friend class PaintSurface;
376 friend class PaintRecorder; 227 friend class PaintRecorder;
377 friend CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL( 228 friend CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL(
378 PaintCanvas* canvas, 229 PaintCanvas* canvas,
379 const SkRect& rect, 230 const SkRect& rect,
380 SkData* data); 231 SkData* data);
381 friend CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination( 232 friend CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination(
382 PaintCanvas* canvas, 233 PaintCanvas* canvas,
383 const SkPoint& point, 234 const SkPoint& point,
384 SkData* data); 235 SkData* data);
385 friend CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination( 236 friend CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(
386 PaintCanvas* canvas, 237 PaintCanvas* canvas,
387 const SkRect& rect, 238 const SkRect& rect,
388 SkData* data); 239 SkData* data);
389 friend CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); 240 friend CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output);
390
391 private:
392 SkCanvas* canvas_;
393 std::unique_ptr<SkCanvas> owned_;
394
395 DISALLOW_COPY_AND_ASSIGN(PaintCanvas);
396 }; 241 };
397 242
398 class CC_PAINT_EXPORT PaintCanvasAutoRestore { 243 class CC_PAINT_EXPORT PaintCanvasAutoRestore {
399 public: 244 public:
400 ALWAYS_INLINE PaintCanvasAutoRestore(PaintCanvas* canvas, bool save) 245 PaintCanvasAutoRestore(PaintCanvas* canvas, bool save) : canvas_(canvas) {
401 : canvas_(canvas) {
402 if (canvas_) { 246 if (canvas_) {
403 save_count_ = canvas_->getSaveCount(); 247 save_count_ = canvas_->getSaveCount();
404 if (save) { 248 if (save) {
405 canvas_->save(); 249 canvas_->save();
406 } 250 }
407 } 251 }
408 } 252 }
409 253
410 ALWAYS_INLINE ~PaintCanvasAutoRestore() { 254 ~PaintCanvasAutoRestore() {
411 if (canvas_) { 255 if (canvas_) {
412 canvas_->restoreToCount(save_count_); 256 canvas_->restoreToCount(save_count_);
413 } 257 }
414 } 258 }
415 259
416 ALWAYS_INLINE void restore() { 260 void restore() {
417 if (canvas_) { 261 if (canvas_) {
418 canvas_->restoreToCount(save_count_); 262 canvas_->restoreToCount(save_count_);
419 canvas_ = nullptr; 263 canvas_ = nullptr;
420 } 264 }
421 } 265 }
422 266
423 private: 267 private:
424 PaintCanvas* canvas_ = nullptr; 268 PaintCanvas* canvas_ = nullptr;
425 int save_count_ = 0; 269 int save_count_ = 0;
426 }; 270 };
(...skipping 21 matching lines...) Expand all
448 const SkPoint& point, 292 const SkPoint& point,
449 SkData* data); 293 SkData* data);
450 294
451 CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas, 295 CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas,
452 const SkRect& rect, 296 const SkRect& rect,
453 SkData* data); 297 SkData* data);
454 298
455 } // namespace cc 299 } // namespace cc
456 300
457 #endif // CC_PAINT_PAINT_CANVAS_H_ 301 #endif // CC_PAINT_PAINT_CANVAS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698