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 }
onDrawPath(const SkPath & path,const SkPaint & paint)63 void SkLiteRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) {
64     fDL->drawPath(path, paint);
65 }
onDrawRect(const SkRect & rect,const SkPaint & paint)66 void SkLiteRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) {
67     fDL->drawRect(rect, paint);
68 }
onDrawEdgeAARect(const SkRect & rect,SkCanvas::QuadAAFlags aa,SkColor color,SkBlendMode mode)69 void SkLiteRecorder::onDrawEdgeAARect(const SkRect& rect, SkCanvas::QuadAAFlags aa, SkColor color,
70                                       SkBlendMode mode) {
71     fDL->drawEdgeAARect(rect, aa, color, mode);
72 }
onDrawRegion(const SkRegion & region,const SkPaint & paint)73 void SkLiteRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
74     fDL->drawRegion(region, paint);
75 }
onDrawOval(const SkRect & oval,const SkPaint & paint)76 void SkLiteRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) {
77     fDL->drawOval(oval, paint);
78 }
onDrawArc(const SkRect & oval,SkScalar startAngle,SkScalar sweepAngle,bool useCenter,const SkPaint & paint)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 }
onDrawRRect(const SkRRect & rrect,const SkPaint & paint)83 void SkLiteRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
84     fDL->drawRRect(rrect, paint);
85 }
onDrawDRRect(const SkRRect & out,const SkRRect & in,const SkPaint & paint)86 void SkLiteRecorder::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) {
87     fDL->drawDRRect(out, in, paint);
88 }
89 
onDrawDrawable(SkDrawable * drawable,const SkMatrix * matrix)90 void SkLiteRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
91     fDL->drawDrawable(drawable, matrix);
92 }
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)93 void SkLiteRecorder::onDrawPicture(const SkPicture* picture,
94                                    const SkMatrix* matrix,
95                                    const SkPaint* paint) {
96     fDL->drawPicture(picture, matrix, paint);
97 }
onDrawAnnotation(const SkRect & rect,const char key[],SkData * val)98 void SkLiteRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) {
99     fDL->drawAnnotation(rect, key, val);
100 }
101 
onDrawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)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 
onDrawBitmap(const SkBitmap & bm,SkScalar x,SkScalar y,const SkPaint * paint)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 }
onDrawBitmapNine(const SkBitmap & bm,const SkIRect & center,const SkRect & dst,const SkPaint * paint)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 }
onDrawBitmapRect(const SkBitmap & bm,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)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 }
onDrawBitmapLattice(const SkBitmap & bm,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)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 
onDrawImage(const SkImage * img,SkScalar x,SkScalar y,const SkPaint * paint)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 }
onDrawImageNine(const SkImage * img,const SkIRect & center,const SkRect & dst,const SkPaint * paint)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 }
onDrawImageRect(const SkImage * img,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)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 }
onDrawImageLattice(const SkImage * img,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)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 
onDrawImageSet(const ImageSetEntry set[],int count,SkFilterQuality filterQuality,SkBlendMode mode)150 void SkLiteRecorder::onDrawImageSet(const ImageSetEntry set[], int count,
151                                     SkFilterQuality filterQuality, SkBlendMode mode) {
152     fDL->drawImageSet(set, count, filterQuality, mode);
153 }
154 
onDrawPatch(const SkPoint cubics[12],const SkColor colors[4],const SkPoint texCoords[4],SkBlendMode bmode,const SkPaint & paint)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 }
onDrawPoints(SkCanvas::PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)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 }
onDrawVerticesObject(const SkVertices * vertices,const SkVertices::Bone bones[],int boneCount,SkBlendMode mode,const SkPaint & paint)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 }
onDrawAtlas(const SkImage * atlas,const SkRSXform xforms[],const SkRect texs[],const SkColor colors[],int count,SkBlendMode bmode,const SkRect * cull,const SkPaint * paint)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 }
onDrawShadowRec(const SkPath & path,const SkDrawShadowRec & rec)180 void SkLiteRecorder::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
181     fDL->drawShadowRec(path, rec);
182 }
183