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 | |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame^] | 12 | #include "SkBitmap.h" |
| 13 | #include "SkCanvas.h" |
| 14 | #include "SkColor.h" |
robertphillips@google.com | 9241e33 | 2013-08-21 13:54:44 +0000 | [diff] [blame] | 15 | #include "SkDevice.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame^] | 16 | #include "SkImageFilter.h" |
| 17 | #include "SkImageInfo.h" |
| 18 | #include "SkRect.h" |
| 19 | #include "SkScalar.h" |
| 20 | #include "SkSize.h" |
| 21 | #include "SkSurfaceProps.h" |
| 22 | #include "SkTypes.h" |
| 23 | |
| 24 | class SkDraw; |
| 25 | class SkMatrix; |
| 26 | class SkPaint; |
| 27 | class SkPath; |
| 28 | class SkPixelRef; |
| 29 | class SkPixmap; |
| 30 | class SkRRect; |
| 31 | class SkSurface; |
| 32 | class SkXfermode; |
| 33 | struct SkPoint; |
robertphillips@google.com | 9241e33 | 2013-08-21 13:54:44 +0000 | [diff] [blame] | 34 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 35 | /////////////////////////////////////////////////////////////////////////////// |
| 36 | class SK_API SkBitmapDevice : public SkBaseDevice { |
| 37 | public: |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 38 | /** |
| 39 | * Construct a new device with the specified bitmap as its backend. It is |
| 40 | * valid for the bitmap to have no pixels associated with it. In that case, |
| 41 | * any drawing to this device will have no effect. |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 42 | */ |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 43 | SkBitmapDevice(const SkBitmap& bitmap); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Create a new device along with its requisite pixel memory using |
| 47 | * default SkSurfaceProps (i.e., kLegacyFontHost_InitType-style). |
| 48 | * Note: this entry point is slated for removal - no one should call it. |
| 49 | */ |
| 50 | static SkBitmapDevice* Create(const SkImageInfo& info); |
| 51 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 52 | /** |
| 53 | * Construct a new device with the specified bitmap as its backend. It is |
| 54 | * valid for the bitmap to have no pixels associated with it. In that case, |
| 55 | * any drawing to this device will have no effect. |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 56 | */ |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 57 | SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 58 | |
| 59 | static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 60 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 61 | SkImageInfo imageInfo() const override; |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 62 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 63 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 64 | bool onShouldDisableLCD(const SkPaint&) const override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 65 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 66 | /** These are called inside the per-device-layer loop for each draw call. |
| 67 | When these are called, we have already applied any saveLayer operations, |
| 68 | and are handling any looping from the paint, and any effects from the |
| 69 | DrawFilter. |
| 70 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 71 | void drawPaint(const SkDraw&, const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 72 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 73 | const SkPoint[], const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 74 | virtual void drawRect(const SkDraw&, const SkRect& r, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 75 | const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 76 | virtual void drawOval(const SkDraw&, const SkRect& oval, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 77 | const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 78 | virtual void drawRRect(const SkDraw&, const SkRRect& rr, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 79 | const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * If pathIsMutable, then the implementation is allowed to cast path to a |
| 83 | * non-const pointer and modify it in place (as an optimization). Canvas |
| 84 | * may do this to implement helpers such as drawOval, by placing a temp |
| 85 | * path on the stack to hold the representation of the oval. |
| 86 | * |
| 87 | * If prePathMatrix is not null, it should logically be applied before any |
| 88 | * stroking or other effects. If there are no effects on the paint that |
| 89 | * affect the geometry/rasterization, then the pre matrix can just be |
| 90 | * pre-concated with the current matrix. |
| 91 | */ |
| 92 | virtual void drawPath(const SkDraw&, const SkPath& path, |
| 93 | const SkPaint& paint, |
| 94 | const SkMatrix* prePathMatrix = NULL, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 95 | bool pathIsMutable = false) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 96 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 97 | const SkMatrix& matrix, const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 98 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 99 | int x, int y, const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * The default impl. will create a bitmap-shader from the bitmap, |
| 103 | * and call drawRect with it. |
| 104 | */ |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 105 | void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*, const SkRect&, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 106 | const SkPaint&, SkCanvas::SrcRectConstraint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * Does not handle text decoration. |
| 110 | * Decorations (underline and stike-thru) will be handled by SkCanvas. |
| 111 | */ |
| 112 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 113 | SkScalar x, SkScalar y, const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 114 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 115 | const SkScalar pos[], int scalarsPerPos, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 116 | const SkPoint& offset, const SkPaint& paint) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 117 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, |
| 118 | const SkPoint verts[], const SkPoint texs[], |
| 119 | const SkColor colors[], SkXfermode* xmode, |
| 120 | const uint16_t indices[], int indexCount, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 121 | const SkPaint& paint) override; |
| 122 | virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 123 | |
| 124 | /////////////////////////////////////////////////////////////////////////// |
| 125 | |
| 126 | /** Update as needed the pixel value in the bitmap, so that the caller can |
| 127 | access the pixels directly. Note: only the pixels field should be |
| 128 | altered. The config/width/height/rowbytes must remain unchanged. |
| 129 | @return the device contents as a bitmap |
| 130 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 131 | const SkBitmap& onAccessBitmap() override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 132 | |
| 133 | SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
| 134 | // just for subclasses, to assign a custom pixelref |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 135 | SkPixelRef* setPixelRef(SkPixelRef* pr) { |
| 136 | fBitmap.setPixelRef(pr); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 137 | return pr; |
| 138 | } |
| 139 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 140 | bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) override; |
| 141 | bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override; |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 142 | bool onPeekPixels(SkPixmap*) override; |
| 143 | bool onAccessPixels(SkPixmap*) override; |
reed | cd1d41e | 2015-05-25 21:21:27 -0700 | [diff] [blame] | 144 | void onAttachToCanvas(SkCanvas*) override; |
| 145 | void onDetachFromCanvas() override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 146 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 147 | private: |
| 148 | friend class SkCanvas; |
| 149 | friend struct DeviceCM; //for setMatrixClip |
| 150 | friend class SkDraw; |
| 151 | friend class SkDrawIter; |
| 152 | friend class SkDeviceFilteredPaint; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 153 | |
| 154 | friend class SkSurface_Raster; |
| 155 | |
| 156 | // used to change the backend's pixels (and possibly config/rowbytes) |
| 157 | // but cannot change the width/height, so there should be no change to |
| 158 | // any clip information. |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 159 | void replaceBitmapBackendForRasterSurface(const SkBitmap&) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 160 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 161 | SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 162 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 163 | SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 164 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 165 | SkImageFilter::Cache* getImageFilterCache() override; |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 166 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 167 | SkBitmap fBitmap; |
| 168 | |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 169 | void setNewSize(const SkISize&); // Used by SkCanvas for resetForNextPicture(). |
| 170 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 171 | typedef SkBaseDevice INHERITED; |
| 172 | }; |
robertphillips@google.com | 9241e33 | 2013-08-21 13:54:44 +0000 | [diff] [blame] | 173 | |
| 174 | #endif // SkBitmapDevice_DEFINED |