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