| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "cdl_picture_recording_canvas.h" |
| 9 |
| 10 #if CDL_ENABLED |
| 11 |
| 12 #include "base/trace_event/trace_event.h" |
| 13 #include "skia/ext/cdl_picture_buffer.h" |
| 14 #include "third_party/skia/include/core/SkSurface.h" |
| 15 #include "third_party/skia/include/utils/SkNoDrawCanvas.h" |
| 16 #include "third_party/skia/include/utils/SkNWayCanvas.h" |
| 17 |
| 18 #define INHERITED(method, ...) this->CdlNoDrawCanvas::method(__VA_ARGS__) |
| 19 |
| 20 CdlPictureRecordingCanvas::CdlPictureRecordingCanvas(CdlPictureBuffer* dl, |
| 21 const SkRect& bounds) |
| 22 : CdlNoDrawCanvas(bounds.roundOut().width(), bounds.roundOut().height()), |
| 23 fDL(dl), |
| 24 fComputeClips(true) {} |
| 25 |
| 26 CdlPictureRecordingCanvas::~CdlPictureRecordingCanvas() {} |
| 27 |
| 28 void CdlPictureRecordingCanvas::reset(CdlPictureBuffer* dl, |
| 29 const SkRect& bounds) { |
| 30 fDL = dl; |
| 31 #ifdef CDL_FRIEND_OF_SKPICTURE |
| 32 canvas_->resetForNextPicture(bounds.roundOut()); |
| 33 #else |
| 34 owned_canvas_.reset( |
| 35 new SkNWayCanvas(bounds.roundOut().width(), bounds.roundOut().height())); |
| 36 canvas_ = owned_canvas_.get(); |
| 37 #endif |
| 38 } |
| 39 |
| 40 int CdlPictureRecordingCanvas::onSave() { |
| 41 fDL->save(); |
| 42 return INHERITED::onSave(); |
| 43 } |
| 44 |
| 45 int CdlPictureRecordingCanvas::onSaveLayer(const SaveLayerRec& rec) { |
| 46 fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fSaveLayerFlags); |
| 47 return INHERITED::onSaveLayer(rec); |
| 48 } |
| 49 |
| 50 void CdlPictureRecordingCanvas::onRestore() { |
| 51 fDL->restore(); |
| 52 INHERITED::onRestore(); |
| 53 } |
| 54 |
| 55 void CdlPictureRecordingCanvas::onConcat(const SkMatrix& matrix) { |
| 56 fDL->concat(matrix); |
| 57 INHERITED::onConcat(matrix); |
| 58 } |
| 59 |
| 60 void CdlPictureRecordingCanvas::onSetMatrix(const SkMatrix& matrix) { |
| 61 fDL->setMatrix(matrix); |
| 62 INHERITED::onSetMatrix(matrix); |
| 63 } |
| 64 |
| 65 void CdlPictureRecordingCanvas::onTranslate(SkScalar dx, SkScalar dy) { |
| 66 fDL->translate(dx, dy); |
| 67 INHERITED::onTranslate(dx, dy); |
| 68 } |
| 69 |
| 70 void CdlPictureRecordingCanvas::onClipRect(const SkRect& rect, |
| 71 SkCanvas::ClipOp op, |
| 72 ClipEdgeStyle style) { |
| 73 fDL->clipRect(rect, op, style == kSoft_ClipEdgeStyle); |
| 74 if (fComputeClips) |
| 75 CdlCanvas::onClipRect(rect, op, style); |
| 76 } |
| 77 void CdlPictureRecordingCanvas::onClipRRect(const SkRRect& rrect, |
| 78 SkCanvas::ClipOp op, |
| 79 ClipEdgeStyle style) { |
| 80 fDL->clipRRect(rrect, op, style == kSoft_ClipEdgeStyle); |
| 81 if (fComputeClips) |
| 82 CdlCanvas::onClipRRect(rrect, op, style); |
| 83 } |
| 84 void CdlPictureRecordingCanvas::onClipPath(const SkPath& path, |
| 85 SkCanvas::ClipOp op, |
| 86 ClipEdgeStyle style) { |
| 87 fDL->clipPath(path, op, style == kSoft_ClipEdgeStyle); |
| 88 if (fComputeClips) |
| 89 CdlCanvas::onClipPath(path, op, style); |
| 90 } |
| 91 void CdlPictureRecordingCanvas::onClipRegion(const SkRegion& region, |
| 92 SkCanvas::ClipOp op) { |
| 93 fDL->clipRegion(region, op); |
| 94 if (fComputeClips) |
| 95 CdlCanvas::onClipRegion(region, op); |
| 96 } |
| 97 |
| 98 void CdlPictureRecordingCanvas::onDrawPaint(const CdlPaint& paint) { |
| 99 fDL->drawPaint(paint); |
| 100 } |
| 101 void CdlPictureRecordingCanvas::onDrawPath(const SkPath& path, |
| 102 const CdlPaint& paint) { |
| 103 fDL->drawPath(path, paint); |
| 104 } |
| 105 void CdlPictureRecordingCanvas::onDrawRect(const SkRect& rect, |
| 106 const CdlPaint& paint) { |
| 107 fDL->drawRect(rect, paint); |
| 108 } |
| 109 |
| 110 void CdlPictureRecordingCanvas::onDrawRRect(const SkRRect& rrect, |
| 111 const CdlPaint& paint) { |
| 112 fDL->drawRRect(rrect, paint); |
| 113 } |
| 114 void CdlPictureRecordingCanvas::onDrawDRRect(const SkRRect& out, |
| 115 const SkRRect& in, |
| 116 const CdlPaint& paint) { |
| 117 fDL->drawDRRect(out, in, paint); |
| 118 } |
| 119 |
| 120 void CdlPictureRecordingCanvas::onDrawOval(const SkRect& oval, |
| 121 const CdlPaint& paint) { |
| 122 fDL->drawOval(oval, paint); |
| 123 } |
| 124 |
| 125 void CdlPictureRecordingCanvas::onDrawPicture(const CdlPicture* picture, |
| 126 const SkMatrix* matrix, |
| 127 const CdlPaint* paint) { |
| 128 fDL->drawPicture(picture, matrix, paint); |
| 129 } |
| 130 |
| 131 void CdlPictureRecordingCanvas::onDrawAnnotation(const SkRect& rect, |
| 132 const char key[], |
| 133 SkData* val) { |
| 134 fDL->drawAnnotation(rect, key, val); |
| 135 } |
| 136 |
| 137 void CdlPictureRecordingCanvas::onDrawText(const void* text, |
| 138 size_t bytes, |
| 139 SkScalar x, |
| 140 SkScalar y, |
| 141 const CdlPaint& paint) { |
| 142 fDL->drawText(text, bytes, x, y, paint); |
| 143 } |
| 144 void CdlPictureRecordingCanvas::onDrawPosText(const void* text, |
| 145 size_t bytes, |
| 146 const SkPoint pos[], |
| 147 const CdlPaint& paint) { |
| 148 fDL->drawPosText(text, bytes, pos, paint); |
| 149 } |
| 150 |
| 151 void CdlPictureRecordingCanvas::onDrawTextBlob(const SkTextBlob* blob, |
| 152 SkScalar x, |
| 153 SkScalar y, |
| 154 const CdlPaint& paint) { |
| 155 fDL->drawTextBlob(blob, x, y, paint); |
| 156 } |
| 157 |
| 158 void CdlPictureRecordingCanvas::onDrawImage(const SkImage* img, |
| 159 SkScalar x, |
| 160 SkScalar y, |
| 161 const CdlPaint* paint) { |
| 162 fDL->drawImage(sk_ref_sp(img), x, y, paint); |
| 163 } |
| 164 |
| 165 void CdlPictureRecordingCanvas::onDrawImageRect( |
| 166 const SkImage* img, |
| 167 const SkRect* src, |
| 168 const SkRect& dst, |
| 169 const CdlPaint* paint, |
| 170 SkCanvas::SrcRectConstraint constraint) { |
| 171 fDL->drawImageRect(sk_ref_sp(img), src, dst, paint, constraint); |
| 172 } |
| 173 |
| 174 void CdlPictureRecordingCanvas::onDrawPoints(SkCanvas::PointMode mode, |
| 175 size_t count, |
| 176 const SkPoint pts[], |
| 177 const CdlPaint& paint) { |
| 178 fDL->drawPoints(mode, count, pts, paint); |
| 179 } |
| 180 |
| 181 #endif // CDL_ENABLED |
| OLD | NEW |