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->resetForNextPicture(bounds);
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
willSave()32 void SkLiteRecorder::willSave() { fDL->save(); }
getSaveLayerStrategy(const SaveLayerRec & rec)33 SkCanvas::SaveLayerStrategy SkLiteRecorder::getSaveLayerStrategy(const SaveLayerRec& rec) {
34 fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fSaveLayerFlags);
35 return SkCanvas::kNoLayer_SaveLayerStrategy;
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 }
onDrawRegion(const SkRegion & region,const SkPaint & paint)69 void SkLiteRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
70 fDL->drawRegion(region, paint);
71 }
onDrawOval(const SkRect & oval,const SkPaint & paint)72 void SkLiteRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) {
73 fDL->drawOval(oval, paint);
74 }
onDrawArc(const SkRect & oval,SkScalar startAngle,SkScalar sweepAngle,bool useCenter,const SkPaint & paint)75 void SkLiteRecorder::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
76 bool useCenter, const SkPaint& paint) {
77 fDL->drawArc(oval, startAngle, sweepAngle, useCenter, paint);
78 }
onDrawRRect(const SkRRect & rrect,const SkPaint & paint)79 void SkLiteRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
80 fDL->drawRRect(rrect, paint);
81 }
onDrawDRRect(const SkRRect & out,const SkRRect & in,const SkPaint & paint)82 void SkLiteRecorder::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) {
83 fDL->drawDRRect(out, in, paint);
84 }
85
onDrawDrawable(SkDrawable * drawable,const SkMatrix * matrix)86 void SkLiteRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
87 fDL->drawDrawable(drawable, matrix);
88 }
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)89 void SkLiteRecorder::onDrawPicture(const SkPicture* picture,
90 const SkMatrix* matrix,
91 const SkPaint* paint) {
92 fDL->drawPicture(picture, matrix, paint);
93 }
onDrawAnnotation(const SkRect & rect,const char key[],SkData * val)94 void SkLiteRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) {
95 fDL->drawAnnotation(rect, key, val);
96 }
97
onDrawText(const void * text,size_t bytes,SkScalar x,SkScalar y,const SkPaint & paint)98 void SkLiteRecorder::onDrawText(const void* text, size_t bytes,
99 SkScalar x, SkScalar y,
100 const SkPaint& paint) {
101 fDL->drawText(text, bytes, x, y, paint);
102 }
onDrawPosText(const void * text,size_t bytes,const SkPoint pos[],const SkPaint & paint)103 void SkLiteRecorder::onDrawPosText(const void* text, size_t bytes,
104 const SkPoint pos[],
105 const SkPaint& paint) {
106 fDL->drawPosText(text, bytes, pos, paint);
107 }
onDrawPosTextH(const void * text,size_t bytes,const SkScalar xs[],SkScalar y,const SkPaint & paint)108 void SkLiteRecorder::onDrawPosTextH(const void* text, size_t bytes,
109 const SkScalar xs[], SkScalar y,
110 const SkPaint& paint) {
111 fDL->drawPosTextH(text, bytes, xs, y, paint);
112 }
onDrawTextOnPath(const void * text,size_t bytes,const SkPath & path,const SkMatrix * matrix,const SkPaint & paint)113 void SkLiteRecorder::onDrawTextOnPath(const void* text, size_t bytes,
114 const SkPath& path, const SkMatrix* matrix,
115 const SkPaint& paint) {
116 fDL->drawTextOnPath(text, bytes, path, matrix, paint);
117 }
onDrawTextRSXform(const void * text,size_t bytes,const SkRSXform xform[],const SkRect * cull,const SkPaint & paint)118 void SkLiteRecorder::onDrawTextRSXform(const void* text, size_t bytes,
119 const SkRSXform xform[], const SkRect* cull,
120 const SkPaint& paint) {
121 fDL->drawTextRSXform(text, bytes, xform, cull, paint);
122 }
onDrawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)123 void SkLiteRecorder::onDrawTextBlob(const SkTextBlob* blob,
124 SkScalar x, SkScalar y,
125 const SkPaint& paint) {
126 fDL->drawTextBlob(blob, x,y, paint);
127 }
128
onDrawBitmap(const SkBitmap & bm,SkScalar x,SkScalar y,const SkPaint * paint)129 void SkLiteRecorder::onDrawBitmap(const SkBitmap& bm,
130 SkScalar x, SkScalar y,
131 const SkPaint* paint) {
132 fDL->drawImage(SkImage::MakeFromBitmap(bm), x,y, paint);
133 }
onDrawBitmapNine(const SkBitmap & bm,const SkIRect & center,const SkRect & dst,const SkPaint * paint)134 void SkLiteRecorder::onDrawBitmapNine(const SkBitmap& bm,
135 const SkIRect& center, const SkRect& dst,
136 const SkPaint* paint) {
137 fDL->drawImageNine(SkImage::MakeFromBitmap(bm), center, dst, paint);
138 }
onDrawBitmapRect(const SkBitmap & bm,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)139 void SkLiteRecorder::onDrawBitmapRect(const SkBitmap& bm,
140 const SkRect* src, const SkRect& dst,
141 const SkPaint* paint, SrcRectConstraint constraint) {
142 fDL->drawImageRect(SkImage::MakeFromBitmap(bm), src, dst, paint, constraint);
143 }
onDrawBitmapLattice(const SkBitmap & bm,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)144 void SkLiteRecorder::onDrawBitmapLattice(const SkBitmap& bm,
145 const SkCanvas::Lattice& lattice, const SkRect& dst,
146 const SkPaint* paint) {
147 fDL->drawImageLattice(SkImage::MakeFromBitmap(bm), lattice, dst, paint);
148 }
149
onDrawImage(const SkImage * img,SkScalar x,SkScalar y,const SkPaint * paint)150 void SkLiteRecorder::onDrawImage(const SkImage* img,
151 SkScalar x, SkScalar y,
152 const SkPaint* paint) {
153 fDL->drawImage(sk_ref_sp(img), x,y, paint);
154 }
onDrawImageNine(const SkImage * img,const SkIRect & center,const SkRect & dst,const SkPaint * paint)155 void SkLiteRecorder::onDrawImageNine(const SkImage* img,
156 const SkIRect& center, const SkRect& dst,
157 const SkPaint* paint) {
158 fDL->drawImageNine(sk_ref_sp(img), center, dst, paint);
159 }
onDrawImageRect(const SkImage * img,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)160 void SkLiteRecorder::onDrawImageRect(const SkImage* img,
161 const SkRect* src, const SkRect& dst,
162 const SkPaint* paint, SrcRectConstraint constraint) {
163 fDL->drawImageRect(sk_ref_sp(img), src, dst, paint, constraint);
164 }
onDrawImageLattice(const SkImage * img,const SkCanvas::Lattice & lattice,const SkRect & dst,const SkPaint * paint)165 void SkLiteRecorder::onDrawImageLattice(const SkImage* img,
166 const SkCanvas::Lattice& lattice, const SkRect& dst,
167 const SkPaint* paint) {
168 fDL->drawImageLattice(sk_ref_sp(img), lattice, dst, paint);
169 }
170
171
onDrawPatch(const SkPoint cubics[12],const SkColor colors[4],const SkPoint texCoords[4],SkBlendMode bmode,const SkPaint & paint)172 void SkLiteRecorder::onDrawPatch(const SkPoint cubics[12],
173 const SkColor colors[4], const SkPoint texCoords[4],
174 SkBlendMode bmode, const SkPaint& paint) {
175 fDL->drawPatch(cubics, colors, texCoords, bmode, paint);
176 }
onDrawPoints(SkCanvas::PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)177 void SkLiteRecorder::onDrawPoints(SkCanvas::PointMode mode,
178 size_t count, const SkPoint pts[],
179 const SkPaint& paint) {
180 fDL->drawPoints(mode, count, pts, paint);
181 }
onDrawVerticesObject(const SkVertices * vertices,SkBlendMode mode,const SkPaint & paint)182 void SkLiteRecorder::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode,
183 const SkPaint& paint) {
184 fDL->drawVertices(vertices, mode, paint);
185 }
onDrawAtlas(const SkImage * atlas,const SkRSXform xforms[],const SkRect texs[],const SkColor colors[],int count,SkBlendMode bmode,const SkRect * cull,const SkPaint * paint)186 void SkLiteRecorder::onDrawAtlas(const SkImage* atlas,
187 const SkRSXform xforms[],
188 const SkRect texs[],
189 const SkColor colors[],
190 int count,
191 SkBlendMode bmode,
192 const SkRect* cull,
193 const SkPaint* paint) {
194 fDL->drawAtlas(atlas, xforms, texs, colors, count, bmode, cull, paint);
195 }
196
didTranslateZ(SkScalar dz)197 void SkLiteRecorder::didTranslateZ(SkScalar dz) {
198 fDL->translateZ(dz);
199 }
onDrawShadowedPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint,const SkShadowParams & params)200 void SkLiteRecorder::onDrawShadowedPicture(const SkPicture* picture,
201 const SkMatrix* matrix,
202 const SkPaint* paint,
203 const SkShadowParams& params) {
204 fDL->drawShadowedPicture(picture, matrix, paint, params);
205 }
206