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