Home | History | Annotate | Download | only in core
      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     : INHERITED(1, 1)
     14     , fDL(nullptr) {}
     15 
     16 void SkLiteRecorder::reset(SkLiteDL* dl, const SkIRect& bounds) {
     17     this->resetCanvas(bounds.right(), bounds.bottom());
     18     fDL = dl;
     19 }
     20 
     21 sk_sp<SkSurface> SkLiteRecorder::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) {
     22     return nullptr;
     23 }
     24 
     25 void SkLiteRecorder::onFlush() { fDL->flush(); }
     26 
     27 void SkLiteRecorder::willSave() { fDL->save(); }
     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 }
     33 bool SkLiteRecorder::onDoSaveBehind(const SkRect* subset) {
     34     fDL->saveBehind(subset);
     35     return false;
     36 }
     37 void SkLiteRecorder::willRestore() { fDL->restore(); }
     38 
     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); }
     42 
     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 }
     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 }
     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 }
     55 void SkLiteRecorder::onClipRegion(const SkRegion& region, SkClipOp op) {
     56     fDL->clipRegion(region, op);
     57     this->INHERITED::onClipRegion(region, op);
     58 }
     59 
     60 void SkLiteRecorder::onDrawPaint(const SkPaint& paint) {
     61     fDL->drawPaint(paint);
     62 }
     63 void SkLiteRecorder::onDrawBehind(const SkPaint& paint) {
     64     fDL->drawBehind(paint);
     65 }
     66 void SkLiteRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) {
     67     fDL->drawPath(path, paint);
     68 }
     69 void SkLiteRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) {
     70     fDL->drawRect(rect, paint);
     71 }
     72 void SkLiteRecorder::onDrawEdgeAARect(const SkRect& rect, SkCanvas::QuadAAFlags aa, SkColor color,
     73                                       SkBlendMode mode) {
     74     fDL->drawEdgeAARect(rect, aa, color, mode);
     75 }
     76 void SkLiteRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
     77     fDL->drawRegion(region, paint);
     78 }
     79 void SkLiteRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) {
     80     fDL->drawOval(oval, paint);
     81 }
     82 void SkLiteRecorder::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
     83                                bool useCenter, const SkPaint& paint) {
     84     fDL->drawArc(oval, startAngle, sweepAngle, useCenter, paint);
     85 }
     86 void SkLiteRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
     87     fDL->drawRRect(rrect, paint);
     88 }
     89 void SkLiteRecorder::onDrawDRRect(const SkRRect& out, const SkRRect& in, const SkPaint& paint) {
     90     fDL->drawDRRect(out, in, paint);
     91 }
     92 
     93 void SkLiteRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
     94     fDL->drawDrawable(drawable, matrix);
     95 }
     96 void SkLiteRecorder::onDrawPicture(const SkPicture* picture,
     97                                    const SkMatrix* matrix,
     98                                    const SkPaint* paint) {
     99     fDL->drawPicture(picture, matrix, paint);
    100 }
    101 void SkLiteRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* val) {
    102     fDL->drawAnnotation(rect, key, val);
    103 }
    104 
    105 void SkLiteRecorder::onDrawTextBlob(const SkTextBlob* blob,
    106                                     SkScalar x, SkScalar y,
    107                                     const SkPaint& paint) {
    108     fDL->drawTextBlob(blob, x,y, paint);
    109 }
    110 
    111 void SkLiteRecorder::onDrawBitmap(const SkBitmap& bm,
    112                                   SkScalar x, SkScalar y,
    113                                   const SkPaint* paint) {
    114     fDL->drawImage(SkImage::MakeFromBitmap(bm), x,y, paint);
    115 }
    116 void SkLiteRecorder::onDrawBitmapNine(const SkBitmap& bm,
    117                                       const SkIRect& center, const SkRect& dst,
    118                                       const SkPaint* paint) {
    119     fDL->drawImageNine(SkImage::MakeFromBitmap(bm), center, dst, paint);
    120 }
    121 void SkLiteRecorder::onDrawBitmapRect(const SkBitmap& bm,
    122                                       const SkRect* src, const SkRect& dst,
    123                                       const SkPaint* paint, SrcRectConstraint constraint) {
    124     fDL->drawImageRect(SkImage::MakeFromBitmap(bm), src, dst, paint, constraint);
    125 }
    126 void SkLiteRecorder::onDrawBitmapLattice(const SkBitmap& bm,
    127                                          const SkCanvas::Lattice& lattice, const SkRect& dst,
    128                                          const SkPaint* paint) {
    129     fDL->drawImageLattice(SkImage::MakeFromBitmap(bm), lattice, dst, paint);
    130 }
    131 
    132 void SkLiteRecorder::onDrawImage(const SkImage* img,
    133                                   SkScalar x, SkScalar y,
    134                                   const SkPaint* paint) {
    135     fDL->drawImage(sk_ref_sp(img), x,y, paint);
    136 }
    137 void SkLiteRecorder::onDrawImageNine(const SkImage* img,
    138                                       const SkIRect& center, const SkRect& dst,
    139                                       const SkPaint* paint) {
    140     fDL->drawImageNine(sk_ref_sp(img), center, dst, paint);
    141 }
    142 void SkLiteRecorder::onDrawImageRect(const SkImage* img,
    143                                       const SkRect* src, const SkRect& dst,
    144                                       const SkPaint* paint, SrcRectConstraint constraint) {
    145     fDL->drawImageRect(sk_ref_sp(img), src, dst, paint, constraint);
    146 }
    147 void SkLiteRecorder::onDrawImageLattice(const SkImage* img,
    148                                         const SkCanvas::Lattice& lattice, const SkRect& dst,
    149                                         const SkPaint* paint) {
    150     fDL->drawImageLattice(sk_ref_sp(img), lattice, dst, paint);
    151 }
    152 
    153 void SkLiteRecorder::onDrawImageSet(const ImageSetEntry set[], int count,
    154                                     SkFilterQuality filterQuality, SkBlendMode mode) {
    155     fDL->drawImageSet(set, count, filterQuality, mode);
    156 }
    157 
    158 void SkLiteRecorder::onDrawPatch(const SkPoint cubics[12],
    159                                  const SkColor colors[4], const SkPoint texCoords[4],
    160                                  SkBlendMode bmode, const SkPaint& paint) {
    161     fDL->drawPatch(cubics, colors, texCoords, bmode, paint);
    162 }
    163 void SkLiteRecorder::onDrawPoints(SkCanvas::PointMode mode,
    164                                   size_t count, const SkPoint pts[],
    165                                   const SkPaint& paint) {
    166     fDL->drawPoints(mode, count, pts, paint);
    167 }
    168 void SkLiteRecorder::onDrawVerticesObject(const SkVertices* vertices,
    169                                           const SkVertices::Bone bones[], int boneCount,
    170                                           SkBlendMode mode, const SkPaint& paint) {
    171     fDL->drawVertices(vertices, bones, boneCount, mode, paint);
    172 }
    173 void SkLiteRecorder::onDrawAtlas(const SkImage* atlas,
    174                                  const SkRSXform xforms[],
    175                                  const SkRect texs[],
    176                                  const SkColor colors[],
    177                                  int count,
    178                                  SkBlendMode bmode,
    179                                  const SkRect* cull,
    180                                  const SkPaint* paint) {
    181     fDL->drawAtlas(atlas, xforms, texs, colors, count, bmode, cull, paint);
    182 }
    183 void SkLiteRecorder::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
    184     fDL->drawShadowRec(path, rec);
    185 }
    186