mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 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 | |
| 12 | SkLiteRecorder::SkLiteRecorder() |
| 13 | : SkCanvas({0,0,1,1}, SkCanvas::kConservativeRasterClip_InitFlag) |
| 14 | , fDL(nullptr) {} |
| 15 | |
| 16 | void SkLiteRecorder::reset(SkLiteDL* dl) { |
| 17 | this->resetForNextPicture(dl->getBounds().roundOut()); |
| 18 | fDL = dl; |
| 19 | } |
| 20 | |
| 21 | sk_sp<SkSurface> SkLiteRecorder::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) { |
| 22 | return nullptr; |
| 23 | } |
| 24 | |
reed | 6ae6969 | 2016-09-02 04:56:53 -0700 | [diff] [blame] | 25 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
| 26 | SkDrawFilter* SkLiteRecorder::setDrawFilter(SkDrawFilter* df) { |
| 27 | fDL->setDrawFilter(df); |
| 28 | return SkCanvas::setDrawFilter(df); |
| 29 | } |
| 30 | #endif |
| 31 | |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 32 | void SkLiteRecorder::willSave() { fDL->save(); } |
| 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 | } |
| 37 | void SkLiteRecorder::willRestore() { fDL->restore(); } |
| 38 | |
mtklein | cbdf007 | 2016-08-19 09:05:27 -0700 | [diff] [blame] | 39 | void SkLiteRecorder::didConcat (const SkMatrix& matrix) { fDL-> concat(matrix); } |
| 40 | void SkLiteRecorder::didSetMatrix(const SkMatrix& matrix) { fDL->setMatrix(matrix); } |
| 41 | void SkLiteRecorder::didTranslate(SkScalar dx, SkScalar dy) { fDL->translate(dx, dy); } |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 42 | |
| 43 | void SkLiteRecorder::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle style) { |
| 44 | fDL->clipRect(rect, op, style==kSoft_ClipEdgeStyle); |
liyuqian | 91c4271 | 2016-09-12 13:00:50 -0700 | [diff] [blame] | 45 | SkCanvas::onClipRect(rect, op, style); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 46 | } |
| 47 | void SkLiteRecorder::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle style) { |
| 48 | fDL->clipRRect(rrect, op, style==kSoft_ClipEdgeStyle); |
liyuqian | 91c4271 | 2016-09-12 13:00:50 -0700 | [diff] [blame] | 49 | SkCanvas::onClipRRect(rrect, op, style); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 50 | } |
| 51 | void SkLiteRecorder::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle style) { |
| 52 | fDL->clipPath(path, op, style==kSoft_ClipEdgeStyle); |
liyuqian | 91c4271 | 2016-09-12 13:00:50 -0700 | [diff] [blame] | 53 | SkCanvas::onClipPath(path, op, style); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 54 | } |
| 55 | void SkLiteRecorder::onClipRegion(const SkRegion& region, SkRegion::Op op) { |
| 56 | fDL->clipRegion(region, op); |
liyuqian | 91c4271 | 2016-09-12 13:00:50 -0700 | [diff] [blame] | 57 | SkCanvas::onClipRegion(region, op); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void SkLiteRecorder::onDrawPaint(const SkPaint& paint) { |
| 61 | fDL->drawPaint(paint); |
| 62 | } |
| 63 | void SkLiteRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) { |
| 64 | fDL->drawPath(path, paint); |
| 65 | } |
| 66 | void SkLiteRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
| 67 | fDL->drawRect(rect, paint); |
| 68 | } |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 69 | void SkLiteRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) { |
| 70 | fDL->drawRegion(region, paint); |
| 71 | } |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 72 | void SkLiteRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 73 | fDL->drawOval(oval, paint); |
| 74 | } |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 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 | } |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 79 | void SkLiteRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 80 | fDL->drawRRect(rrect, paint); |
| 81 | } |
| 82 | void SkLiteRecorder::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) { |
| 83 | fDL->drawDRRect(out, in, paint); |
| 84 | } |
| 85 | |
| 86 | void SkLiteRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { |
| 87 | fDL->drawDrawable(drawable, matrix); |
| 88 | } |
| 89 | void SkLiteRecorder::onDrawPicture(const SkPicture* picture, |
| 90 | const SkMatrix* matrix, |
| 91 | const SkPaint* paint) { |
| 92 | fDL->drawPicture(picture, matrix, paint); |
| 93 | } |
| 94 | void SkLiteRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) { |
| 95 | fDL->drawAnnotation(rect, key, val); |
| 96 | } |
| 97 | |
| 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 | } |
| 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 | } |
| 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 | } |
| 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 | } |
| 118 | void SkLiteRecorder::onDrawTextRSXform(const void* text, size_t bytes, |
| 119 | const SkRSXform xform[], const SkRect* cull, |
| 120 | const SkPaint& paint) { |
mtklein | 29de8d9 | 2016-08-07 11:35:08 -0700 | [diff] [blame] | 121 | fDL->drawTextRSXform(text, bytes, xform, cull, paint); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 122 | } |
| 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 | |
| 129 | void SkLiteRecorder::onDrawBitmap(const SkBitmap& bm, |
| 130 | SkScalar x, SkScalar y, |
| 131 | const SkPaint* paint) { |
| 132 | fDL->drawBitmap(bm, x,y, paint); |
| 133 | } |
| 134 | void SkLiteRecorder::onDrawBitmapNine(const SkBitmap& bm, |
| 135 | const SkIRect& center, const SkRect& dst, |
| 136 | const SkPaint* paint) { |
| 137 | fDL->drawBitmapNine(bm, center, dst, paint); |
| 138 | } |
| 139 | void SkLiteRecorder::onDrawBitmapRect(const SkBitmap& bm, |
| 140 | const SkRect* src, const SkRect& dst, |
| 141 | const SkPaint* paint, SrcRectConstraint constraint) { |
mtklein | ec55959 | 2016-08-06 20:31:30 -0700 | [diff] [blame] | 142 | fDL->drawBitmapRect(bm, src, dst, paint, constraint); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 143 | } |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 144 | void SkLiteRecorder::onDrawBitmapLattice(const SkBitmap& bm, |
| 145 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 146 | const SkPaint* paint) { |
| 147 | fDL->drawBitmapLattice(bm, lattice, dst, paint); |
| 148 | } |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 149 | |
| 150 | void SkLiteRecorder::onDrawImage(const SkImage* img, |
| 151 | SkScalar x, SkScalar y, |
| 152 | const SkPaint* paint) { |
| 153 | fDL->drawImage(img, x,y, paint); |
| 154 | } |
| 155 | void SkLiteRecorder::onDrawImageNine(const SkImage* img, |
| 156 | const SkIRect& center, const SkRect& dst, |
| 157 | const SkPaint* paint) { |
| 158 | fDL->drawImageNine(img, center, dst, paint); |
| 159 | } |
| 160 | void SkLiteRecorder::onDrawImageRect(const SkImage* img, |
| 161 | const SkRect* src, const SkRect& dst, |
| 162 | const SkPaint* paint, SrcRectConstraint constraint) { |
mtklein | ec55959 | 2016-08-06 20:31:30 -0700 | [diff] [blame] | 163 | fDL->drawImageRect(img, src, dst, paint, constraint); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 164 | } |
| 165 | void SkLiteRecorder::onDrawImageLattice(const SkImage* img, |
| 166 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 167 | const SkPaint* paint) { |
| 168 | fDL->drawImageLattice(img, lattice, dst, paint); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | void SkLiteRecorder::onDrawPatch(const SkPoint cubics[12], |
| 173 | const SkColor colors[4], const SkPoint texCoords[4], |
| 174 | SkXfermode* xfermode, const SkPaint& paint) { |
| 175 | fDL->drawPatch(cubics, colors, texCoords, xfermode, paint); |
| 176 | } |
| 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 | } |
| 182 | void SkLiteRecorder::onDrawVertices(SkCanvas::VertexMode mode, |
| 183 | int count, const SkPoint vertices[], |
| 184 | const SkPoint texs[], const SkColor colors[], |
| 185 | SkXfermode* xfermode, |
| 186 | const uint16_t indices[], int indexCount, |
| 187 | const SkPaint& paint) { |
| 188 | fDL->drawVertices(mode, count, vertices, texs, colors, xfermode, indices, indexCount, paint); |
| 189 | } |
| 190 | void SkLiteRecorder::onDrawAtlas(const SkImage* atlas, |
| 191 | const SkRSXform xforms[], |
| 192 | const SkRect texs[], |
| 193 | const SkColor colors[], |
| 194 | int count, |
| 195 | SkXfermode::Mode xfermode, |
| 196 | const SkRect* cull, |
| 197 | const SkPaint* paint) { |
| 198 | fDL->drawAtlas(atlas, xforms, texs, colors, count, xfermode, cull, paint); |
| 199 | } |
| 200 | |
| 201 | void SkLiteRecorder::didTranslateZ(SkScalar dz) { |
| 202 | fDL->translateZ(dz); |
| 203 | } |
| 204 | void SkLiteRecorder::onDrawShadowedPicture(const SkPicture* picture, |
| 205 | const SkMatrix* matrix, |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 206 | const SkPaint* paint, |
| 207 | const SkShadowParams& params) { |
| 208 | fDL->drawShadowedPicture(picture, matrix, paint, params); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 209 | } |