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 "SkLiteDL.h" 9 #include "SkLiteRecorder.h" 10 #include "SkSurface.h" 11 12 SkLiteRecorder::SkLiteRecorder() 13 : INHERITED(1, 1) 14 , fDL(nullptr) {} 15 16 void SkLiteRecorder::reset(SkLiteDL* dl, const SkIRect& bounds) { 17 this->resetCanvas(bounds.right(), bounds.bottom()); 18 fDL = dl; 19 } 20 21 sk_sp<SkSurface> SkLiteRecorder::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) { 22 return nullptr; 23 } 24 25 void SkLiteRecorder::onFlush() { fDL->flush(); } 26 27 void SkLiteRecorder::willSave() { fDL->save(); } 28 SkCanvas::SaveLayerStrategy SkLiteRecorder::getSaveLayerStrategy(const SaveLayerRec& rec) { 29 fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fClipMask, rec.fClipMatrix, 30 rec.fSaveLayerFlags); 31 return SkCanvas::kNoLayer_SaveLayerStrategy; 32 } 33 bool SkLiteRecorder::onDoSaveBehind(const SkRect* subset) { 34 fDL->saveBehind(subset); 35 return false; 36 } 37 void SkLiteRecorder::willRestore() { fDL->restore(); } 38 39 void SkLiteRecorder::didConcat (const SkMatrix& matrix) { fDL-> concat(matrix); } 40 void SkLiteRecorder::didSetMatrix(const SkMatrix& matrix) { fDL->setMatrix(matrix); } 41 void SkLiteRecorder::didTranslate(SkScalar dx, SkScalar dy) { fDL->translate(dx, dy); } 42 43 void SkLiteRecorder::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle style) { 44 fDL->clipRect(rect, op, style==kSoft_ClipEdgeStyle); 45 this->INHERITED::onClipRect(rect, op, style); 46 } 47 void SkLiteRecorder::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle style) { 48 fDL->clipRRect(rrect, op, style==kSoft_ClipEdgeStyle); 49 this->INHERITED::onClipRRect(rrect, op, style); 50 } 51 void SkLiteRecorder::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle style) { 52 fDL->clipPath(path, op, style==kSoft_ClipEdgeStyle); 53 this->INHERITED::onClipPath(path, op, style); 54 } 55 void SkLiteRecorder::onClipRegion(const SkRegion& region, SkClipOp op) { 56 fDL->clipRegion(region, op); 57 this->INHERITED::onClipRegion(region, op); 58 } 59 60 void SkLiteRecorder::onDrawPaint(const SkPaint& paint) { 61 fDL->drawPaint(paint); 62 } 63 void SkLiteRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) { 64 fDL->drawPath(path, paint); 65 } 66 void SkLiteRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) { 67 fDL->drawRect(rect, paint); 68 } 69 void SkLiteRecorder::onDrawEdgeAARect(const SkRect& rect, SkCanvas::QuadAAFlags aa, SkColor color, 70 SkBlendMode mode) { 71 fDL->drawEdgeAARect(rect, aa, color, mode); 72 } 73 void SkLiteRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) { 74 fDL->drawRegion(region, paint); 75 } 76 void SkLiteRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) { 77 fDL->drawOval(oval, paint); 78 } 79 void SkLiteRecorder::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, 80 bool useCenter, const SkPaint& paint) { 81 fDL->drawArc(oval, startAngle, sweepAngle, useCenter, paint); 82 } 83 void SkLiteRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { 84 fDL->drawRRect(rrect, paint); 85 } 86 void SkLiteRecorder::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) { 87 fDL->drawDRRect(out, in, paint); 88 } 89 90 void SkLiteRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { 91 fDL->drawDrawable(drawable, matrix); 92 } 93 void SkLiteRecorder::onDrawPicture(const SkPicture* picture, 94 const SkMatrix* matrix, 95 const SkPaint* paint) { 96 fDL->drawPicture(picture, matrix, paint); 97 } 98 void SkLiteRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) { 99 fDL->drawAnnotation(rect, key, val); 100 } 101 102 void SkLiteRecorder::onDrawTextBlob(const SkTextBlob* blob, 103 SkScalar x, SkScalar y, 104 const SkPaint& paint) { 105 fDL->drawTextBlob(blob, x,y, paint); 106 } 107 108 void SkLiteRecorder::onDrawBitmap(const SkBitmap& bm, 109 SkScalar x, SkScalar y, 110 const SkPaint* paint) { 111 fDL->drawImage(SkImage::MakeFromBitmap(bm), x,y, paint); 112 } 113 void SkLiteRecorder::onDrawBitmapNine(const SkBitmap& bm, 114 const SkIRect& center, const SkRect& dst, 115 const SkPaint* paint) { 116 fDL->drawImageNine(SkImage::MakeFromBitmap(bm), center, dst, paint); 117 } 118 void SkLiteRecorder::onDrawBitmapRect(const SkBitmap& bm, 119 const SkRect* src, const SkRect& dst, 120 const SkPaint* paint, SrcRectConstraint constraint) { 121 fDL->drawImageRect(SkImage::MakeFromBitmap(bm), src, dst, paint, constraint); 122 } 123 void SkLiteRecorder::onDrawBitmapLattice(const SkBitmap& bm, 124 const SkCanvas::Lattice& lattice, const SkRect& dst, 125 const SkPaint* paint) { 126 fDL->drawImageLattice(SkImage::MakeFromBitmap(bm), lattice, dst, paint); 127 } 128 129 void SkLiteRecorder::onDrawImage(const SkImage* img, 130 SkScalar x, SkScalar y, 131 const SkPaint* paint) { 132 fDL->drawImage(sk_ref_sp(img), x,y, paint); 133 } 134 void SkLiteRecorder::onDrawImageNine(const SkImage* img, 135 const SkIRect& center, const SkRect& dst, 136 const SkPaint* paint) { 137 fDL->drawImageNine(sk_ref_sp(img), center, dst, paint); 138 } 139 void SkLiteRecorder::onDrawImageRect(const SkImage* img, 140 const SkRect* src, const SkRect& dst, 141 const SkPaint* paint, SrcRectConstraint constraint) { 142 fDL->drawImageRect(sk_ref_sp(img), src, dst, paint, constraint); 143 } 144 void SkLiteRecorder::onDrawImageLattice(const SkImage* img, 145 const SkCanvas::Lattice& lattice, const SkRect& dst, 146 const SkPaint* paint) { 147 fDL->drawImageLattice(sk_ref_sp(img), lattice, dst, paint); 148 } 149 150 void SkLiteRecorder::onDrawImageSet(const ImageSetEntry set[], int count, 151 SkFilterQuality filterQuality, SkBlendMode mode) { 152 fDL->drawImageSet(set, count, filterQuality, mode); 153 } 154 155 void SkLiteRecorder::onDrawPatch(const SkPoint cubics[12], 156 const SkColor colors[4], const SkPoint texCoords[4], 157 SkBlendMode bmode, const SkPaint& paint) { 158 fDL->drawPatch(cubics, colors, texCoords, bmode, paint); 159 } 160 void SkLiteRecorder::onDrawPoints(SkCanvas::PointMode mode, 161 size_t count, const SkPoint pts[], 162 const SkPaint& paint) { 163 fDL->drawPoints(mode, count, pts, paint); 164 } 165 void SkLiteRecorder::onDrawVerticesObject(const SkVertices* vertices, 166 const SkVertices::Bone bones[], int boneCount, 167 SkBlendMode mode, const SkPaint& paint) { 168 fDL->drawVertices(vertices, bones, boneCount, mode, paint); 169 } 170 void SkLiteRecorder::onDrawAtlas(const SkImage* atlas, 171 const SkRSXform xforms[], 172 const SkRect texs[], 173 const SkColor colors[], 174 int count, 175 SkBlendMode bmode, 176 const SkRect* cull, 177 const SkPaint* paint) { 178 fDL->drawAtlas(atlas, xforms, texs, colors, count, bmode, cull, paint); 179 } 180 void SkLiteRecorder::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { 181 fDL->drawShadowRec(path, rec); 182 } 183