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 | #ifndef SkLiteDL_DEFINED |
| 9 | #define SkLiteDL_DEFINED |
| 10 | |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkPaint.h" |
| 13 | #include "SkPath.h" |
| 14 | #include "SkDrawable.h" |
| 15 | #include "SkRect.h" |
| 16 | #include "SkTDArray.h" |
| 17 | |
| 18 | class SkLiteDL final : public SkDrawable { |
| 19 | public: |
| 20 | static sk_sp<SkLiteDL> New(SkRect); |
mtklein | 883c8ef | 2016-08-16 09:36:18 -0700 | [diff] [blame] | 21 | void reset(SkRect); |
mtklein | 0c753e5 | 2016-08-09 07:40:23 -0700 | [diff] [blame] | 22 | |
mtklein | 03591a7 | 2016-08-07 13:35:46 -0700 | [diff] [blame] | 23 | void makeThreadsafe(); |
mtklein | 1da01c1 | 2016-08-17 10:20:27 -0700 | [diff] [blame] | 24 | bool empty() const { return fUsed == 0; } |
mtklein | ec55959 | 2016-08-06 20:31:30 -0700 | [diff] [blame] | 25 | |
reed | 6ae6969 | 2016-09-02 04:56:53 -0700 | [diff] [blame] | 26 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
| 27 | void setDrawFilter(SkDrawFilter*); |
| 28 | #endif |
| 29 | |
mtklein | f53fcc8 | 2016-09-08 08:49:08 -0700 | [diff] [blame^] | 30 | // Draws as if... |
| 31 | // SkRect bounds = this->getBounds(); |
| 32 | // canvas->saveLayer(&bounds, paint); |
| 33 | // this->draw(canvas, matrix); |
| 34 | // canvas->restore(); |
| 35 | void drawAsLayer(SkCanvas*, const SkMatrix*, const SkPaint*); |
| 36 | |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 37 | void save(); |
mtklein | 29de8d9 | 2016-08-07 11:35:08 -0700 | [diff] [blame] | 38 | void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, SkCanvas::SaveLayerFlags); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 39 | void restore(); |
| 40 | |
| 41 | void concat (const SkMatrix&); |
| 42 | void setMatrix (const SkMatrix&); |
mtklein | cbdf007 | 2016-08-19 09:05:27 -0700 | [diff] [blame] | 43 | void translate(SkScalar, SkScalar); |
mtklein | 29de8d9 | 2016-08-07 11:35:08 -0700 | [diff] [blame] | 44 | void translateZ(SkScalar); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 45 | |
mtklein | 6f8411d | 2016-08-06 15:28:11 -0700 | [diff] [blame] | 46 | void clipPath (const SkPath&, SkRegion::Op, bool aa); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 47 | void clipRect (const SkRect&, SkRegion::Op, bool aa); |
mtklein | 6f8411d | 2016-08-06 15:28:11 -0700 | [diff] [blame] | 48 | void clipRRect (const SkRRect&, SkRegion::Op, bool aa); |
| 49 | void clipRegion(const SkRegion&, SkRegion::Op); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 50 | |
mtklein | 6f8411d | 2016-08-06 15:28:11 -0700 | [diff] [blame] | 51 | void drawPaint (const SkPaint&); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 52 | void drawPath (const SkPath&, const SkPaint&); |
| 53 | void drawRect (const SkRect&, const SkPaint&); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 54 | void drawRegion(const SkRegion&, const SkPaint&); |
mtklein | 6f8411d | 2016-08-06 15:28:11 -0700 | [diff] [blame] | 55 | void drawOval (const SkRect&, const SkPaint&); |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 56 | void drawArc (const SkRect&, SkScalar, SkScalar, bool, const SkPaint&); |
mtklein | 6f8411d | 2016-08-06 15:28:11 -0700 | [diff] [blame] | 57 | void drawRRect (const SkRRect&, const SkPaint&); |
| 58 | void drawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 59 | |
mtklein | 29de8d9 | 2016-08-07 11:35:08 -0700 | [diff] [blame] | 60 | void drawAnnotation (const SkRect&, const char*, SkData*); |
| 61 | void drawDrawable (SkDrawable*, const SkMatrix*); |
| 62 | void drawPicture (const SkPicture*, const SkMatrix*, const SkPaint*); |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 63 | void drawShadowedPicture(const SkPicture*, const SkMatrix*, |
| 64 | const SkPaint*, const SkShadowParams& params); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 65 | |
mtklein | ec55959 | 2016-08-06 20:31:30 -0700 | [diff] [blame] | 66 | void drawText (const void*, size_t, SkScalar, SkScalar, const SkPaint&); |
| 67 | void drawPosText (const void*, size_t, const SkPoint[], const SkPaint&); |
| 68 | void drawPosTextH (const void*, size_t, const SkScalar[], SkScalar, const SkPaint&); |
mtklein | 29de8d9 | 2016-08-07 11:35:08 -0700 | [diff] [blame] | 69 | void drawTextOnPath (const void*, size_t, const SkPath&, const SkMatrix*, const SkPaint&); |
| 70 | void drawTextRSXform(const void*, size_t, const SkRSXform[], const SkRect*, const SkPaint&); |
mtklein | ec55959 | 2016-08-06 20:31:30 -0700 | [diff] [blame] | 71 | void drawTextBlob (const SkTextBlob*, SkScalar,SkScalar, const SkPaint&); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 72 | |
mtklein | ec55959 | 2016-08-06 20:31:30 -0700 | [diff] [blame] | 73 | void drawBitmap (const SkBitmap&, SkScalar, SkScalar, const SkPaint*); |
| 74 | void drawBitmapNine(const SkBitmap&, const SkIRect&, const SkRect&, const SkPaint*); |
| 75 | void drawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*, |
| 76 | SkCanvas::SrcRectConstraint); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 77 | void drawBitmapLattice(const SkBitmap&, const SkCanvas::Lattice&, const SkRect&, |
| 78 | const SkPaint*); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 79 | |
mtklein | ec55959 | 2016-08-06 20:31:30 -0700 | [diff] [blame] | 80 | void drawImage (const SkImage*, SkScalar,SkScalar, const SkPaint*); |
| 81 | void drawImageNine(const SkImage*, const SkIRect&, const SkRect&, const SkPaint*); |
| 82 | void drawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*, |
| 83 | SkCanvas::SrcRectConstraint); |
mtklein | 29de8d9 | 2016-08-07 11:35:08 -0700 | [diff] [blame] | 84 | void drawImageLattice(const SkImage*, const SkCanvas::Lattice&, const SkRect&, const SkPaint*); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 85 | |
| 86 | void drawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], |
mtklein | 03591a7 | 2016-08-07 13:35:46 -0700 | [diff] [blame] | 87 | SkXfermode*, const SkPaint&); |
mtklein | 29de8d9 | 2016-08-07 11:35:08 -0700 | [diff] [blame] | 88 | void drawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 89 | void drawVertices(SkCanvas::VertexMode, int, const SkPoint[], const SkPoint[], const SkColor[], |
mtklein | 03591a7 | 2016-08-07 13:35:46 -0700 | [diff] [blame] | 90 | SkXfermode*, const uint16_t[], int, const SkPaint&); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 91 | void drawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, |
mtklein | 29de8d9 | 2016-08-07 11:35:08 -0700 | [diff] [blame] | 92 | SkXfermode::Mode, const SkRect*, const SkPaint*); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 93 | |
| 94 | private: |
mtklein | 883c8ef | 2016-08-16 09:36:18 -0700 | [diff] [blame] | 95 | SkLiteDL(SkRect); |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 96 | ~SkLiteDL(); |
| 97 | |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 98 | SkRect onGetBounds() override; |
| 99 | void onDraw(SkCanvas*) override; |
| 100 | |
mtklein | b202833 | 2016-08-09 15:13:18 -0700 | [diff] [blame] | 101 | template <typename T, typename... Args> |
| 102 | void* push(size_t, Args&&...); |
| 103 | |
mtklein | 6480619 | 2016-08-16 17:18:27 -0700 | [diff] [blame] | 104 | template <typename Fn, typename... Args> |
| 105 | void map(const Fn[], Args...); |
mtklein | b202833 | 2016-08-09 15:13:18 -0700 | [diff] [blame] | 106 | |
| 107 | SkAutoTMalloc<uint8_t> fBytes; |
| 108 | size_t fUsed; |
| 109 | size_t fReserved; |
| 110 | SkRect fBounds; |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | #endif//SkLiteDL_DEFINED |