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 
25 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER
setDrawFilter(SkDrawFilter * df)26 SkDrawFilter* SkLiteRecorder::setDrawFilter(SkDrawFilter* df) {
27     fDL->setDrawFilter(df);
28     return this->INHERITED::setDrawFilter(df);
29 }
30 #endif
31 
onFlush()32 void SkLiteRecorder::onFlush() { fDL->flush(); }
33 
willSave()34 void SkLiteRecorder::willSave() { fDL->save(); }
getSaveLayerStrategy(const SaveLayerRec & rec)35 SkCanvas::SaveLayerStrategy SkLiteRecorder::getSaveLayerStrategy(const SaveLayerRec& rec) {
36     fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fClipMask, rec.fClipMatrix,
37                    rec.fSaveLayerFlags);
38     return SkCanvas::kNoLayer_SaveLayerStrategy;
39 }
willRestore()40 void SkLiteRecorder::willRestore() { fDL->restore(); }
41 
didConcat(const SkMatrix & matrix)42 void SkLiteRecorder::didConcat   (const SkMatrix& matrix)   { fDL->   concat(matrix); }
didSetMatrix(const SkMatrix & matrix)43 void SkLiteRecorder::didSetMatrix(const SkMatrix& matrix)   { fDL->setMatrix(matrix); }
didTranslate(SkScalar dx,SkScalar dy)44 void SkLiteRecorder::didTranslate(SkScalar dx, SkScalar dy) { fDL->translate(dx, dy); }
45 
onClipRect(const SkRect & rect,SkClipOp op,ClipEdgeStyle style)46 void SkLiteRecorder::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle style) {
47     fDL->clipRect(rect, op, style==kSoft_ClipEdgeStyle);
48     this->INHERITED::onClipRect(rect, op, style);
49 }
onClipRRect(const SkRRect & rrect,SkClipOp op,ClipEdgeStyle style)50 void SkLiteRecorder::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle style) {
51     fDL->clipRRect(rrect, op, style==kSoft_ClipEdgeStyle);
52     this->INHERITED::onClipRRect(rrect, op, style);
53 }
onClipPath(const SkPath & path,SkClipOp op,ClipEdgeStyle style)54 void SkLiteRecorder::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle style) {
55     fDL->clipPath(path, op, style==kSoft_ClipEdgeStyle);
56     this->INHERITED::onClipPath(path, op, style);
57 }
onClipRegion(const SkRegion & region,SkClipOp op)58 void SkLiteRecorder::onClipRegion(const SkRegion& region, SkClipOp op) {
59     fDL->clipRegion(region, op);
60     this->INHERITED::onClipRegion(region, op);
61 }
62 
onDrawPaint(const SkPaint & paint)63 void SkLiteRecorder::onDrawPaint(const SkPaint& paint) {
64     fDL->drawPaint(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 }
onDrawRegion(const SkRegion & region,const SkPaint & paint)72 void SkLiteRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
73     fDL->drawRegion(region, paint);
74 }
onDrawOval(const SkRect & oval,const SkPaint & paint)75 void SkLiteRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) {
76     fDL->drawOval(oval, paint);
77 }
onDrawArc(const SkRect & oval,SkScalar startAngle,SkScalar sweepAngle,bool useCenter,const SkPaint & paint)78 void SkLiteRecorder::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
79                                bool useCenter, const SkPaint& paint) {
80     fDL->drawArc(oval, startAngle, sweepAngle, useCenter, paint);
81 }
onDrawRRect(const SkRRect & rrect,const SkPaint & paint)82 void SkLiteRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
83     fDL->drawRRect(rrect, paint);
84 }
onDrawDRRect(const SkRRect & out,const SkRRect & in,const SkPaint & paint)85 void SkLiteRecorder::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) {
86     fDL->drawDRRect(out, in, paint);
87 }
88 
onDrawDrawable(SkDrawable * drawable,const SkMatrix * matrix)89 void SkLiteRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
90     fDL->drawDrawable(drawable, matrix);
91 }
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)92 void SkLiteRecorder::onDrawPicture(const SkPicture* picture,
93                                    const SkMatrix* matrix,
94                                    const SkPaint* paint) {
95     fDL->drawPicture(picture, matrix, paint);
96 }
onDrawAnnotation(const SkRect & rect,const char key[],SkData * val)97 void SkLiteRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) {
98     fDL->drawAnnotation(rect, key, val);
99 }
100 
onDrawText(const void * text,size_t bytes,SkScalar x,SkScalar y,const SkPaint & paint)101 void SkLiteRecorder::onDrawText(const void* text, size_t bytes,
102                                 SkScalar x, SkScalar y,
103                                 const SkPaint& paint) {
104     fDL->drawText(text, bytes, x, y, paint);
105 }
onDrawPosText(const void * text,size_t bytes,const SkPoint pos[],const SkPaint & paint)106 void SkLiteRecorder::onDrawPosText(const void* text, size_t bytes,
107                                    const SkPoint pos[],
108                                    const SkPaint& paint) {
109     fDL->drawPosText(text, bytes, pos, paint);
110 }
onDrawPosTextH(const void * text,size_t bytes,const SkScalar xs[],SkScalar y,const SkPaint & paint)111 void SkLiteRecorder::onDrawPosTextH(const void* text, size_t bytes,
112                                     const SkScalar xs[], SkScalar y,
113                                     const SkPaint& paint) {
114     fDL->drawPosTextH(text, bytes, xs, y, paint);
115 }
onDrawTextOnPath(const void * text,size_t bytes,const SkPath & path,const SkMatrix * matrix,const SkPaint & paint)116 void SkLiteRecorder::onDrawTextOnPath(const void* text, size_t bytes,
117                                       const SkPath& path, const SkMatrix* matrix,
118                                       const SkPaint& paint) {
119     fDL->drawTextOnPath(text, bytes, path, matrix, paint);
120 }
onDrawTextRSXform(const void * text,size_t bytes,const SkRSXform xform[],const SkRect * cull,const SkPaint & paint)121 void SkLiteRecorder::onDrawTextRSXform(const void* text, size_t bytes,
122                                        const SkRSXform xform[], const SkRect* cull,
123                                        const SkPaint& paint) {
124     fDL->drawTextRSXform(text, bytes, xform, cull, paint);
125 }
onDrawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)126 void SkLiteRecorder::onDrawTextBlob(const SkTextBlob* blob,
127                                     SkScalar x, SkScalar y,
128                                     const SkPaint& paint) {
129     fDL->drawTextBlob(blob, x,y, paint);
130 }
131 
onDrawBitmap(const SkBitmap & bm,SkScalar x,SkScalar y,const SkPaint * paint)132 void SkLiteRecorder::onDrawBitmap(const SkBitmap& bm,
133                                   SkScalar x, SkScalar y,
134                                   const SkPaint* paint) {
135     fDL->drawImage(SkImage::MakeFromBitmap(bm), x,y, paint);
136 }
onDrawBitmapNine(const SkBitmap & bm,const SkIRect & center,const SkRect & dst,const SkPaint * paint)137 void SkLiteRecorder::onDrawBitmapNine(const SkBitmap& bm,
138                                       const SkIRect& center, const SkRect& dst,
139                                       const SkPaint* paint) {
140     fDL->drawImageNine(SkImage::MakeFromBitmap(bm), center, dst, paint);
141 }
onDrawBitmapRect(const SkBitmap & bm,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)142 void SkLiteRecorder::onDrawBitmapRect(const SkBitmap& bm,
143                                       const SkRect* src, const SkRect& dst,
144                                       const SkPaint* paint, SrcRectConstraint constraint) {
145     fDL->drawImageRect(SkImage::MakeFromBitmap(bm), src, dst, paint, constraint);
146 }
onDrawBitmapLattice(const SkBitmap & bm,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)147 void SkLiteRecorder::onDrawBitmapLattice(const SkBitmap& bm,
148                                          const SkCanvas::Lattice& lattice, const SkRect& dst,
149                                          const SkPaint* paint) {
150     fDL->drawImageLattice(SkImage::MakeFromBitmap(bm), lattice, dst, paint);
151 }
152 
onDrawImage(const SkImage * img,SkScalar x,SkScalar y,const SkPaint * paint)153 void SkLiteRecorder::onDrawImage(const SkImage* img,
154                                   SkScalar x, SkScalar y,
155                                   const SkPaint* paint) {
156     fDL->drawImage(sk_ref_sp(img), x,y, paint);
157 }
onDrawImageNine(const SkImage * img,const SkIRect & center,const SkRect & dst,const SkPaint * paint)158 void SkLiteRecorder::onDrawImageNine(const SkImage* img,
159                                       const SkIRect& center, const SkRect& dst,
160                                       const SkPaint* paint) {
161     fDL->drawImageNine(sk_ref_sp(img), center, dst, paint);
162 }
onDrawImageRect(const SkImage * img,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)163 void SkLiteRecorder::onDrawImageRect(const SkImage* img,
164                                       const SkRect* src, const SkRect& dst,
165                                       const SkPaint* paint, SrcRectConstraint constraint) {
166     fDL->drawImageRect(sk_ref_sp(img), src, dst, paint, constraint);
167 }
onDrawImageLattice(const SkImage * img,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)168 void SkLiteRecorder::onDrawImageLattice(const SkImage* img,
169                                         const SkCanvas::Lattice& lattice, const SkRect& dst,
170                                         const SkPaint* paint) {
171     fDL->drawImageLattice(sk_ref_sp(img), lattice, dst, paint);
172 }
173 
174 
onDrawPatch(const SkPoint cubics[12],const SkColor colors[4],const SkPoint texCoords[4],SkBlendMode bmode,const SkPaint & paint)175 void SkLiteRecorder::onDrawPatch(const SkPoint cubics[12],
176                                  const SkColor colors[4], const SkPoint texCoords[4],
177                                  SkBlendMode bmode, const SkPaint& paint) {
178     fDL->drawPatch(cubics, colors, texCoords, bmode, paint);
179 }
onDrawPoints(SkCanvas::PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)180 void SkLiteRecorder::onDrawPoints(SkCanvas::PointMode mode,
181                                   size_t count, const SkPoint pts[],
182                                   const SkPaint& paint) {
183     fDL->drawPoints(mode, count, pts, paint);
184 }
onDrawVerticesObject(const SkVertices * vertices,SkBlendMode mode,const SkPaint & paint)185 void SkLiteRecorder::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode,
186                                           const SkPaint& paint) {
187     fDL->drawVertices(vertices, mode, paint);
188 }
onDrawAtlas(const SkImage * atlas,const SkRSXform xforms[],const SkRect texs[],const SkColor colors[],int count,SkBlendMode bmode,const SkRect * cull,const SkPaint * paint)189 void SkLiteRecorder::onDrawAtlas(const SkImage* atlas,
190                                  const SkRSXform xforms[],
191                                  const SkRect texs[],
192                                  const SkColor colors[],
193                                  int count,
194                                  SkBlendMode bmode,
195                                  const SkRect* cull,
196                                  const SkPaint* paint) {
197     fDL->drawAtlas(atlas, xforms, texs, colors, count, bmode, cull, paint);
198 }
onDrawShadowRec(const SkPath & path,const SkDrawShadowRec & rec)199 void SkLiteRecorder::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
200     fDL->drawShadowRec(path, rec);
201 }
202