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 | |
| 25 | void SkLiteRecorder::willSave() { fDL->save(); } |
| 26 | SkCanvas::SaveLayerStrategy SkLiteRecorder::getSaveLayerStrategy(const SaveLayerRec& rec) { |
| 27 | fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fSaveLayerFlags); |
| 28 | return SkCanvas::kNoLayer_SaveLayerStrategy; |
| 29 | } |
| 30 | void SkLiteRecorder::willRestore() { fDL->restore(); } |
| 31 | |
| 32 | void SkLiteRecorder::didConcat (const SkMatrix& matrix) { fDL-> concat(matrix); } |
| 33 | void SkLiteRecorder::didSetMatrix(const SkMatrix& matrix) { fDL->setMatrix(matrix); } |
| 34 | |
| 35 | void SkLiteRecorder::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle style) { |
| 36 | fDL->clipRect(rect, op, style==kSoft_ClipEdgeStyle); |
| 37 | SkCanvas::onClipRect(rect, op, style); |
| 38 | } |
| 39 | void SkLiteRecorder::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle style) { |
| 40 | fDL->clipRRect(rrect, op, style==kSoft_ClipEdgeStyle); |
| 41 | SkCanvas::onClipRRect(rrect, op, style); |
| 42 | } |
| 43 | void SkLiteRecorder::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle style) { |
| 44 | fDL->clipPath(path, op, style==kSoft_ClipEdgeStyle); |
| 45 | SkCanvas::onClipPath(path, op, style); |
| 46 | } |
| 47 | void SkLiteRecorder::onClipRegion(const SkRegion& region, SkRegion::Op op) { |
| 48 | fDL->clipRegion(region, op); |
| 49 | SkCanvas::onClipRegion(region, op); |
| 50 | } |
| 51 | |
| 52 | void SkLiteRecorder::onDrawPaint(const SkPaint& paint) { |
| 53 | fDL->drawPaint(paint); |
| 54 | } |
| 55 | void SkLiteRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) { |
| 56 | fDL->drawPath(path, paint); |
| 57 | } |
| 58 | void SkLiteRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
| 59 | fDL->drawRect(rect, paint); |
| 60 | } |
| 61 | void SkLiteRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
| 62 | fDL->drawOval(oval, paint); |
| 63 | } |
| 64 | void SkLiteRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 65 | fDL->drawRRect(rrect, paint); |
| 66 | } |
| 67 | void SkLiteRecorder::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) { |
| 68 | fDL->drawDRRect(out, in, paint); |
| 69 | } |
| 70 | |
| 71 | void SkLiteRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { |
| 72 | fDL->drawDrawable(drawable, matrix); |
| 73 | } |
| 74 | void SkLiteRecorder::onDrawPicture(const SkPicture* picture, |
| 75 | const SkMatrix* matrix, |
| 76 | const SkPaint* paint) { |
| 77 | fDL->drawPicture(picture, matrix, paint); |
| 78 | } |
| 79 | void SkLiteRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) { |
| 80 | fDL->drawAnnotation(rect, key, val); |
| 81 | } |
| 82 | |
| 83 | void SkLiteRecorder::onDrawText(const void* text, size_t bytes, |
| 84 | SkScalar x, SkScalar y, |
| 85 | const SkPaint& paint) { |
| 86 | fDL->drawText(text, bytes, x, y, paint); |
| 87 | } |
| 88 | void SkLiteRecorder::onDrawPosText(const void* text, size_t bytes, |
| 89 | const SkPoint pos[], |
| 90 | const SkPaint& paint) { |
| 91 | fDL->drawPosText(text, bytes, pos, paint); |
| 92 | } |
| 93 | void SkLiteRecorder::onDrawPosTextH(const void* text, size_t bytes, |
| 94 | const SkScalar xs[], SkScalar y, |
| 95 | const SkPaint& paint) { |
| 96 | fDL->drawPosTextH(text, bytes, xs, y, paint); |
| 97 | } |
| 98 | void SkLiteRecorder::onDrawTextOnPath(const void* text, size_t bytes, |
| 99 | const SkPath& path, const SkMatrix* matrix, |
| 100 | const SkPaint& paint) { |
| 101 | fDL->drawTextOnPath(text, bytes, path, matrix, paint); |
| 102 | } |
| 103 | void SkLiteRecorder::onDrawTextRSXform(const void* text, size_t bytes, |
| 104 | const SkRSXform xform[], const SkRect* cull, |
| 105 | const SkPaint& paint) { |
| 106 | fDL->drawTextRSXForm(text, bytes, xform, cull, paint); |
| 107 | } |
| 108 | void SkLiteRecorder::onDrawTextBlob(const SkTextBlob* blob, |
| 109 | SkScalar x, SkScalar y, |
| 110 | const SkPaint& paint) { |
| 111 | fDL->drawTextBlob(blob, x,y, paint); |
| 112 | } |
| 113 | |
| 114 | void SkLiteRecorder::onDrawBitmap(const SkBitmap& bm, |
| 115 | SkScalar x, SkScalar y, |
| 116 | const SkPaint* paint) { |
| 117 | fDL->drawBitmap(bm, x,y, paint); |
| 118 | } |
| 119 | void SkLiteRecorder::onDrawBitmapNine(const SkBitmap& bm, |
| 120 | const SkIRect& center, const SkRect& dst, |
| 121 | const SkPaint* paint) { |
| 122 | fDL->drawBitmapNine(bm, center, dst, paint); |
| 123 | } |
| 124 | void SkLiteRecorder::onDrawBitmapRect(const SkBitmap& bm, |
| 125 | const SkRect* src, const SkRect& dst, |
| 126 | const SkPaint* paint, SrcRectConstraint constraint) { |
| 127 | fDL->drawBitmapRect(bm, src, dst, paint, constraint == kStrict_SrcRectConstraint); |
| 128 | } |
| 129 | |
| 130 | void SkLiteRecorder::onDrawImage(const SkImage* img, |
| 131 | SkScalar x, SkScalar y, |
| 132 | const SkPaint* paint) { |
| 133 | fDL->drawImage(img, x,y, paint); |
| 134 | } |
| 135 | void SkLiteRecorder::onDrawImageNine(const SkImage* img, |
| 136 | const SkIRect& center, const SkRect& dst, |
| 137 | const SkPaint* paint) { |
| 138 | fDL->drawImageNine(img, center, dst, paint); |
| 139 | } |
| 140 | void SkLiteRecorder::onDrawImageRect(const SkImage* img, |
| 141 | const SkRect* src, const SkRect& dst, |
| 142 | const SkPaint* paint, SrcRectConstraint constraint) { |
| 143 | fDL->drawImageRect(img, src, dst, paint, constraint == kStrict_SrcRectConstraint); |
| 144 | } |
| 145 | void SkLiteRecorder::onDrawImageLattice(const SkImage* img, |
| 146 | const SkCanvas::Lattice& lattice, const SkRect& dst, |
| 147 | const SkPaint* paint) { |
| 148 | fDL->drawImageLattice(img, lattice, dst, paint); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | void SkLiteRecorder::onDrawPatch(const SkPoint cubics[12], |
| 153 | const SkColor colors[4], const SkPoint texCoords[4], |
| 154 | SkXfermode* xfermode, const SkPaint& paint) { |
| 155 | fDL->drawPatch(cubics, colors, texCoords, xfermode, paint); |
| 156 | } |
| 157 | void SkLiteRecorder::onDrawPoints(SkCanvas::PointMode mode, |
| 158 | size_t count, const SkPoint pts[], |
| 159 | const SkPaint& paint) { |
| 160 | fDL->drawPoints(mode, count, pts, paint); |
| 161 | } |
| 162 | void SkLiteRecorder::onDrawVertices(SkCanvas::VertexMode mode, |
| 163 | int count, const SkPoint vertices[], |
| 164 | const SkPoint texs[], const SkColor colors[], |
| 165 | SkXfermode* xfermode, |
| 166 | const uint16_t indices[], int indexCount, |
| 167 | const SkPaint& paint) { |
| 168 | fDL->drawVertices(mode, count, vertices, texs, colors, xfermode, indices, indexCount, paint); |
| 169 | } |
| 170 | void SkLiteRecorder::onDrawAtlas(const SkImage* atlas, |
| 171 | const SkRSXform xforms[], |
| 172 | const SkRect texs[], |
| 173 | const SkColor colors[], |
| 174 | int count, |
| 175 | SkXfermode::Mode xfermode, |
| 176 | const SkRect* cull, |
| 177 | const SkPaint* paint) { |
| 178 | fDL->drawAtlas(atlas, xforms, texs, colors, count, xfermode, cull, paint); |
| 179 | } |
| 180 | |
| 181 | void SkLiteRecorder::didTranslateZ(SkScalar dz) { |
| 182 | fDL->translateZ(dz); |
| 183 | } |
| 184 | void SkLiteRecorder::onDrawShadowedPicture(const SkPicture* picture, |
| 185 | const SkMatrix* matrix, |
| 186 | const SkPaint* paint) { |
| 187 | fDL->drawShadowedPicture(picture, matrix, paint); |
| 188 | } |