tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 SkAndroidSDKCanvas_DEFINED |
| 9 | #define SkAndroidSDKCanvas_DEFINED |
| 10 | |
| 11 | #include "SkBitmap.h" |
| 12 | #include "SkCanvas.h" |
| 13 | #include "SkPaint.h" |
| 14 | #include "SkPath.h" |
| 15 | #include "SkRect.h" |
| 16 | |
| 17 | /** SkDrawFilter is likely to be deprecated; this is a proxy |
| 18 | canvas that does the same thing: alter SkPaint fields. |
| 19 | |
| 20 | onDraw*() functions may have their SkPaint modified, and are then |
| 21 | passed on to the same function on proxyTarget. THIS BREAKS CONSTNESS! |
| 22 | |
| 23 | This still suffers one of the same architectural flaws as SkDrawFilter: |
| 24 | TextBlob paints are incomplete when filter is called. |
| 25 | */ |
| 26 | |
| 27 | class SkAndroidSDKCanvas : public SkCanvas { |
| 28 | public: |
| 29 | SkAndroidSDKCanvas(); |
| 30 | void reset(SkCanvas* newTarget); |
| 31 | |
| 32 | protected: |
| 33 | |
| 34 | // FILTERING |
| 35 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 36 | void onDrawPaint(const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 37 | void onDrawPoints(PointMode pMode, size_t count, const SkPoint pts[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 38 | const SkPaint& paint) override; |
| 39 | void onDrawOval(const SkRect& r, const SkPaint& paint) override; |
| 40 | void onDrawRect(const SkRect& r, const SkPaint& paint) override; |
| 41 | void onDrawRRect(const SkRRect& r, const SkPaint& paint) override; |
| 42 | void onDrawPath(const SkPath& path, const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 43 | void onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 44 | const SkPaint* paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 45 | void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 46 | const SkPaint* paint, DrawBitmapRectFlags flags) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 47 | void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 48 | const SkRect& dst, const SkPaint* paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 49 | void onDrawSprite(const SkBitmap& bitmap, int left, int top, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 50 | const SkPaint* paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 51 | void onDrawVertices(VertexMode vMode, int vertexCount, const SkPoint vertices[], |
| 52 | const SkPoint texs[], const SkColor colors[], SkXfermode* xMode, |
| 53 | const uint16_t indices[], int indexCount, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 54 | const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 55 | |
| 56 | void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 57 | const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 58 | |
| 59 | void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 60 | const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 61 | void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 62 | const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 63 | void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 64 | SkScalar constY, const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 65 | void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 66 | const SkMatrix* matrix, const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 67 | void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 68 | const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 69 | |
| 70 | void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 71 | const SkPoint texCoords[4], SkXfermode* xmode, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 72 | const SkPaint& paint) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 73 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 74 | void onDrawImage(const SkImage*, SkScalar, SkScalar, const SkPaint*) override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 75 | void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*) |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 76 | override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 77 | void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*); |
| 78 | |
| 79 | // PASS THROUGH |
| 80 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 81 | void onDrawDrawable(SkDrawable*) override; |
| 82 | SkISize getBaseLayerSize() const override; |
| 83 | bool getClipBounds(SkRect*) const override; |
| 84 | bool getClipDeviceBounds(SkIRect*) const override; |
| 85 | bool isClipEmpty() const override; |
| 86 | bool isClipRect() const override; |
| 87 | SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
| 88 | const void* onPeekPixels(SkImageInfo*, size_t*) override; |
| 89 | void* onAccessTopLayerPixels(SkImageInfo*, size_t*) override; |
| 90 | void willSave() override; |
| 91 | void willRestore() override; |
| 92 | void didRestore() override; |
| 93 | void didConcat(const SkMatrix&) override; |
| 94 | void didSetMatrix(const SkMatrix&) override; |
| 95 | void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override; |
| 96 | void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override; |
| 97 | void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override; |
| 98 | void onClipRegion(const SkRegion&, SkRegion::Op) override; |
| 99 | void onDiscard() override; |
tomhudson | f7edcde | 2015-03-23 12:51:20 -0700 | [diff] [blame] | 100 | |
| 101 | protected: |
| 102 | SkCanvas* fProxyTarget; |
| 103 | }; |
| 104 | |
| 105 | #endif // SkAndroidSDKCanvas_DEFINED |
| 106 | |