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
12SkLiteRecorder::SkLiteRecorder()
13    : INHERITED(1, 1)
14    , fDL(nullptr) {}
15
16void SkLiteRecorder::reset(SkLiteDL* dl, const SkIRect& bounds) {
17    this->resetCanvas(bounds.right(), bounds.bottom());
18    fDL = dl;
19}
20
21sk_sp<SkSurface> SkLiteRecorder::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) {
22    return nullptr;
23}
24
25#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
26SkDrawFilter* SkLiteRecorder::setDrawFilter(SkDrawFilter* df) {
27    fDL->setDrawFilter(df);
28    return this->INHERITED::setDrawFilter(df);
29}
30#endif
31
32void SkLiteRecorder::onFlush() { fDL->flush(); }
33
34void SkLiteRecorder::willSave() { fDL->save(); }
35SkCanvas::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}
40void SkLiteRecorder::willRestore() { fDL->restore(); }
41
42void SkLiteRecorder::didConcat   (const SkMatrix& matrix)   { fDL->   concat(matrix); }
43void SkLiteRecorder::didSetMatrix(const SkMatrix& matrix)   { fDL->setMatrix(matrix); }
44void SkLiteRecorder::didTranslate(SkScalar dx, SkScalar dy) { fDL->translate(dx, dy); }
45
46void 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}
50void 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}
54void 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}
58void SkLiteRecorder::onClipRegion(const SkRegion& region, SkClipOp op) {
59    fDL->clipRegion(region, op);
60    this->INHERITED::onClipRegion(region, op);
61}
62
63void SkLiteRecorder::onDrawPaint(const SkPaint& paint) {
64    fDL->drawPaint(paint);
65}
66void SkLiteRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) {
67    fDL->drawPath(path, paint);
68}
69void SkLiteRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) {
70    fDL->drawRect(rect, paint);
71}
72void SkLiteRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
73    fDL->drawRegion(region, paint);
74}
75void SkLiteRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) {
76    fDL->drawOval(oval, paint);
77}
78void SkLiteRecorder::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
79                               bool useCenter, const SkPaint& paint) {
80    fDL->drawArc(oval, startAngle, sweepAngle, useCenter, paint);
81}
82void SkLiteRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
83    fDL->drawRRect(rrect, paint);
84}
85void SkLiteRecorder::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) {
86    fDL->drawDRRect(out, in, paint);
87}
88
89void SkLiteRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
90    fDL->drawDrawable(drawable, matrix);
91}
92void SkLiteRecorder::onDrawPicture(const SkPicture* picture,
93                                   const SkMatrix* matrix,
94                                   const SkPaint* paint) {
95    fDL->drawPicture(picture, matrix, paint);
96}
97void SkLiteRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) {
98    fDL->drawAnnotation(rect, key, val);
99}
100
101void 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}
106void SkLiteRecorder::onDrawPosText(const void* text, size_t bytes,
107                                   const SkPoint pos[],
108                                   const SkPaint& paint) {
109    fDL->drawPosText(text, bytes, pos, paint);
110}
111void 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}
116void 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}
121void 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}
126void SkLiteRecorder::onDrawTextBlob(const SkTextBlob* blob,
127                                    SkScalar x, SkScalar y,
128                                    const SkPaint& paint) {
129    fDL->drawTextBlob(blob, x,y, paint);
130}
131
132void SkLiteRecorder::onDrawBitmap(const SkBitmap& bm,
133                                  SkScalar x, SkScalar y,
134                                  const SkPaint* paint) {
135    fDL->drawImage(SkImage::MakeFromBitmap(bm), x,y, paint);
136}
137void 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}
142void 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}
147void 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
153void 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}
158void 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}
163void 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}
168void 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
175void 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}
180void SkLiteRecorder::onDrawPoints(SkCanvas::PointMode mode,
181                                  size_t count, const SkPoint pts[],
182                                  const SkPaint& paint) {
183    fDL->drawPoints(mode, count, pts, paint);
184}
185void SkLiteRecorder::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode,
186                                          const SkPaint& paint) {
187    fDL->drawVertices(vertices, mode, paint);
188}
189void 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}
199void SkLiteRecorder::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
200    fDL->drawShadowRec(path, rec);
201}
202