robertphillips@google.com | 9241e33 | 2013-08-21 13:54:44 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2013 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #ifndef SkBitmapDevice_DEFINED |
| 10 | #define SkBitmapDevice_DEFINED |
| 11 | |
| 12 | #include "SkDevice.h" |
| 13 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 14 | /////////////////////////////////////////////////////////////////////////////// |
| 15 | class SK_API SkBitmapDevice : public SkBaseDevice { |
| 16 | public: |
| 17 | SK_DECLARE_INST_COUNT(SkBitmapDevice) |
| 18 | |
| 19 | /** |
| 20 | * Construct a new device with the specified bitmap as its backend. It is |
| 21 | * valid for the bitmap to have no pixels associated with it. In that case, |
| 22 | * any drawing to this device will have no effect. |
| 23 | */ |
| 24 | SkBitmapDevice(const SkBitmap& bitmap); |
reed | e010f1c | 2014-09-17 10:49:38 -0700 | [diff] [blame] | 25 | private: |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 26 | /** |
| 27 | * Construct a new device with the specified bitmap as its backend. It is |
| 28 | * valid for the bitmap to have no pixels associated with it. In that case, |
| 29 | * any drawing to this device will have no effect. |
| 30 | */ |
| 31 | SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties); |
reed | e010f1c | 2014-09-17 10:49:38 -0700 | [diff] [blame] | 32 | static SkBitmapDevice* Create(const SkImageInfo&, const SkDeviceProperties*); |
| 33 | public: |
| 34 | static SkBitmapDevice* Create(const SkImageInfo& info) { |
| 35 | return Create(info, NULL); |
| 36 | } |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 37 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 38 | virtual SkImageInfo imageInfo() const SK_OVERRIDE; |
| 39 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 40 | protected: |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 41 | virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE; |
| 42 | |
| 43 | /** Clears the entire device to the specified color (including alpha). |
| 44 | * Ignores the clip. |
| 45 | */ |
| 46 | virtual void clear(SkColor color) SK_OVERRIDE; |
| 47 | |
| 48 | /** These are called inside the per-device-layer loop for each draw call. |
| 49 | When these are called, we have already applied any saveLayer operations, |
| 50 | and are handling any looping from the paint, and any effects from the |
| 51 | DrawFilter. |
| 52 | */ |
| 53 | virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; |
| 54 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, |
| 55 | const SkPoint[], const SkPaint& paint) SK_OVERRIDE; |
| 56 | virtual void drawRect(const SkDraw&, const SkRect& r, |
| 57 | const SkPaint& paint) SK_OVERRIDE; |
| 58 | virtual void drawOval(const SkDraw&, const SkRect& oval, |
| 59 | const SkPaint& paint) SK_OVERRIDE; |
| 60 | virtual void drawRRect(const SkDraw&, const SkRRect& rr, |
| 61 | const SkPaint& paint) SK_OVERRIDE; |
| 62 | |
| 63 | /** |
| 64 | * If pathIsMutable, then the implementation is allowed to cast path to a |
| 65 | * non-const pointer and modify it in place (as an optimization). Canvas |
| 66 | * may do this to implement helpers such as drawOval, by placing a temp |
| 67 | * path on the stack to hold the representation of the oval. |
| 68 | * |
| 69 | * If prePathMatrix is not null, it should logically be applied before any |
| 70 | * stroking or other effects. If there are no effects on the paint that |
| 71 | * affect the geometry/rasterization, then the pre matrix can just be |
| 72 | * pre-concated with the current matrix. |
| 73 | */ |
| 74 | virtual void drawPath(const SkDraw&, const SkPath& path, |
| 75 | const SkPaint& paint, |
| 76 | const SkMatrix* prePathMatrix = NULL, |
| 77 | bool pathIsMutable = false) SK_OVERRIDE; |
| 78 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
| 79 | const SkMatrix& matrix, const SkPaint& paint) SK_OVERRIDE; |
| 80 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
| 81 | int x, int y, const SkPaint& paint) SK_OVERRIDE; |
| 82 | |
| 83 | /** |
| 84 | * The default impl. will create a bitmap-shader from the bitmap, |
| 85 | * and call drawRect with it. |
| 86 | */ |
| 87 | virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, |
| 88 | const SkRect* srcOrNull, const SkRect& dst, |
| 89 | const SkPaint& paint, |
| 90 | SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE; |
| 91 | |
| 92 | /** |
| 93 | * Does not handle text decoration. |
| 94 | * Decorations (underline and stike-thru) will be handled by SkCanvas. |
| 95 | */ |
| 96 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
| 97 | SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE; |
| 98 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
| 99 | const SkScalar pos[], SkScalar constY, |
| 100 | int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE; |
| 101 | virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
| 102 | const SkPath& path, const SkMatrix* matrix, |
| 103 | const SkPaint& paint) SK_OVERRIDE; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 104 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, |
| 105 | const SkPoint verts[], const SkPoint texs[], |
| 106 | const SkColor colors[], SkXfermode* xmode, |
| 107 | const uint16_t indices[], int indexCount, |
| 108 | const SkPaint& paint) SK_OVERRIDE; |
| 109 | /** The SkBaseDevice passed will be an SkBaseDevice which was returned by a call to |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 110 | onCreateDevice on this device with kSaveLayer_Usage. |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 111 | */ |
| 112 | virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
| 113 | const SkPaint&) SK_OVERRIDE; |
| 114 | |
| 115 | /////////////////////////////////////////////////////////////////////////// |
| 116 | |
| 117 | /** Update as needed the pixel value in the bitmap, so that the caller can |
| 118 | access the pixels directly. Note: only the pixels field should be |
| 119 | altered. The config/width/height/rowbytes must remain unchanged. |
| 120 | @return the device contents as a bitmap |
| 121 | */ |
| 122 | virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE; |
| 123 | |
| 124 | SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
| 125 | // just for subclasses, to assign a custom pixelref |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 126 | SkPixelRef* setPixelRef(SkPixelRef* pr) { |
| 127 | fBitmap.setPixelRef(pr); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 128 | return pr; |
| 129 | } |
| 130 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 131 | virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) SK_OVERRIDE; |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 132 | virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE; |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 133 | virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes) SK_OVERRIDE; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 134 | |
| 135 | /** Called when this device is installed into a Canvas. Balanced by a call |
| 136 | to unlockPixels() when the device is removed from a Canvas. |
| 137 | */ |
| 138 | virtual void lockPixels() SK_OVERRIDE; |
| 139 | virtual void unlockPixels() SK_OVERRIDE; |
| 140 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 141 | private: |
| 142 | friend class SkCanvas; |
| 143 | friend struct DeviceCM; //for setMatrixClip |
| 144 | friend class SkDraw; |
| 145 | friend class SkDrawIter; |
| 146 | friend class SkDeviceFilteredPaint; |
| 147 | friend class SkDeviceImageFilterProxy; |
| 148 | |
| 149 | friend class SkSurface_Raster; |
| 150 | |
| 151 | // used to change the backend's pixels (and possibly config/rowbytes) |
| 152 | // but cannot change the width/height, so there should be no change to |
| 153 | // any clip information. |
| 154 | virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE; |
| 155 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 156 | virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 157 | |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame^] | 158 | virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE; |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 159 | virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 160 | |
senorblanco | be129b2 | 2014-08-08 07:14:35 -0700 | [diff] [blame] | 161 | virtual SkImageFilter::Cache* getImageFilterCache() SK_OVERRIDE; |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 162 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 163 | SkBitmap fBitmap; |
| 164 | |
| 165 | typedef SkBaseDevice INHERITED; |
| 166 | }; |
robertphillips@google.com | 9241e33 | 2013-08-21 13:54:44 +0000 | [diff] [blame] | 167 | |
| 168 | #endif // SkBitmapDevice_DEFINED |