reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkDevice_DEFINED |
| 9 | #define SkDevice_DEFINED |
| 10 | |
| 11 | #include "SkRefCnt.h" |
| 12 | #include "SkBitmap.h" |
| 13 | #include "SkCanvas.h" |
| 14 | #include "SkColor.h" |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 15 | #include "SkImageFilter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
reed@google.com | 46799cd | 2011-02-22 20:56:26 +0000 | [diff] [blame] | 17 | class SkClipStack; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | class SkDraw; |
| 19 | struct SkIRect; |
| 20 | class SkMatrix; |
reed@google.com | a7d9485 | 2011-03-30 21:23:07 +0000 | [diff] [blame] | 21 | class SkMetaData; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | class SkRegion; |
reed | e010f1c | 2014-09-17 10:49:38 -0700 | [diff] [blame] | 23 | struct SkDeviceProperties; |
commit-bot@chromium.org | b8d00db | 2013-06-26 19:18:23 +0000 | [diff] [blame] | 24 | class GrRenderTarget; |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 25 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 26 | class SK_API SkBaseDevice : public SkRefCnt { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | public: |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 28 | SK_DECLARE_INST_COUNT(SkBaseDevice) |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 29 | |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 30 | /** |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 31 | * Construct a new device. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | */ |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 33 | SkBaseDevice(); |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 34 | virtual ~SkBaseDevice(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 36 | SkBaseDevice* createCompatibleDevice(const SkImageInfo&); |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 37 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 38 | SkMetaData& getMetaData(); |
| 39 | |
reed@google.com | d51bfa0 | 2011-08-30 15:56:11 +0000 | [diff] [blame] | 40 | /** |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 41 | * Return ImageInfo for this device. If the canvas is not backed by pixels |
| 42 | * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType. |
| 43 | */ |
| 44 | virtual SkImageInfo imageInfo() const; |
| 45 | |
| 46 | /** |
reed@google.com | d51bfa0 | 2011-08-30 15:56:11 +0000 | [diff] [blame] | 47 | * Return the bounds of the device in the coordinate space of the root |
| 48 | * canvas. The root device will have its top-left at 0,0, but other devices |
| 49 | * such as those associated with saveLayer may have a non-zero origin. |
| 50 | */ |
reed@google.com | ec3ca87 | 2013-11-13 16:02:18 +0000 | [diff] [blame] | 51 | void getGlobalBounds(SkIRect* bounds) const { |
| 52 | SkASSERT(bounds); |
| 53 | const SkIPoint& origin = this->getOrigin(); |
| 54 | bounds->setXYWH(origin.x(), origin.y(), this->width(), this->height()); |
| 55 | } |
skia.committer@gmail.com | 73a5d53 | 2013-11-14 07:02:31 +0000 | [diff] [blame] | 56 | |
reed | f252f64 | 2014-06-14 04:24:56 -0700 | [diff] [blame] | 57 | int width() const { |
| 58 | return this->imageInfo().width(); |
| 59 | } |
reed | 620fc60 | 2014-07-07 13:51:48 -0700 | [diff] [blame] | 60 | |
reed | f252f64 | 2014-06-14 04:24:56 -0700 | [diff] [blame] | 61 | int height() const { |
| 62 | return this->imageInfo().height(); |
| 63 | } |
reed | 620fc60 | 2014-07-07 13:51:48 -0700 | [diff] [blame] | 64 | |
reed | f252f64 | 2014-06-14 04:24:56 -0700 | [diff] [blame] | 65 | bool isOpaque() const { |
| 66 | return this->imageInfo().isOpaque(); |
| 67 | } |
skia.committer@gmail.com | 772c4e6 | 2013-08-30 07:01:34 +0000 | [diff] [blame] | 68 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | /** Return the bitmap associated with this device. Call this each time you need |
| 70 | to access the bitmap, as it notifies the subclass to perform any flushing |
| 71 | etc. before you examine the pixels. |
| 72 | @param changePixels set to true if the caller plans to change the pixels |
| 73 | @return the device's bitmap |
| 74 | */ |
| 75 | const SkBitmap& accessBitmap(bool changePixels); |
| 76 | |
commit-bot@chromium.org | 4ef54f8 | 2014-03-17 17:03:18 +0000 | [diff] [blame] | 77 | bool writePixels(const SkImageInfo&, const void*, size_t rowBytes, int x, int y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 79 | void* accessPixels(SkImageInfo* info, size_t* rowBytes); |
| 80 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 81 | /** |
| 82 | * Return the device's associated gpu render target, or NULL. |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 83 | */ |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 84 | virtual GrRenderTarget* accessRenderTarget() { return NULL; } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 85 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Return the device's origin: its offset in device coordinates from |
| 89 | * the default origin in its canvas' matrix/clip |
| 90 | */ |
| 91 | const SkIPoint& getOrigin() const { return fOrigin; } |
| 92 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 93 | /** |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 94 | * onAttachToCanvas is invoked whenever a device is installed in a canvas |
| 95 | * (i.e., setDevice, saveLayer (for the new device created by the save), |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 96 | * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 97 | * devices to prepare for drawing (e.g., locking their pixels, etc.) |
| 98 | */ |
sugoi@google.com | e0e385c | 2013-03-11 18:50:03 +0000 | [diff] [blame] | 99 | virtual void onAttachToCanvas(SkCanvas*) { |
bsalomon@google.com | 405d0f4 | 2012-08-29 21:26:13 +0000 | [diff] [blame] | 100 | SkASSERT(!fAttachedToCanvas); |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 101 | this->lockPixels(); |
| 102 | #ifdef SK_DEBUG |
| 103 | fAttachedToCanvas = true; |
| 104 | #endif |
| 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * onDetachFromCanvas notifies a device that it will no longer be drawn to. |
| 109 | * It gives the device a chance to clean up (e.g., unlock its pixels). It |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 110 | * is invoked from setDevice (for the displaced device), restore and |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 111 | * possibly from SkCanvas' dtor. |
| 112 | */ |
| 113 | virtual void onDetachFromCanvas() { |
bsalomon@google.com | 405d0f4 | 2012-08-29 21:26:13 +0000 | [diff] [blame] | 114 | SkASSERT(fAttachedToCanvas); |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 115 | this->unlockPixels(); |
| 116 | #ifdef SK_DEBUG |
| 117 | fAttachedToCanvas = false; |
| 118 | #endif |
| 119 | }; |
| 120 | |
caryclark@google.com | d53f7c2 | 2012-01-05 17:05:05 +0000 | [diff] [blame] | 121 | protected: |
| 122 | enum Usage { |
| 123 | kGeneral_Usage, |
tomhudson@google.com | 1f90287 | 2012-06-01 13:15:47 +0000 | [diff] [blame] | 124 | kSaveLayer_Usage // <! internal use only |
caryclark@google.com | d53f7c2 | 2012-01-05 17:05:05 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 127 | struct TextFlags { |
reed | 3375c80 | 2014-09-16 12:27:55 -0700 | [diff] [blame] | 128 | uint32_t fFlags; // SkPaint::getFlags() |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | /** |
| 132 | * Device may filter the text flags for drawing text here. If it wants to |
| 133 | * make a change to the specified values, it should write them into the |
| 134 | * textflags parameter (output) and return true. If the paint is fine as |
| 135 | * is, then ignore the textflags parameter and return false. |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 136 | */ |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 137 | virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) { return false; } |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 138 | |
robertphillips@google.com | 3fffb2e | 2012-10-09 22:30:18 +0000 | [diff] [blame] | 139 | /** |
bsalomon@google.com | a6926b1 | 2012-10-10 15:25:50 +0000 | [diff] [blame] | 140 | * |
| 141 | * DEPRECATED: This will be removed in a future change. Device subclasses |
| 142 | * should use the matrix and clip from the SkDraw passed to draw functions. |
| 143 | * |
robertphillips@google.com | 3fffb2e | 2012-10-09 22:30:18 +0000 | [diff] [blame] | 144 | * Called with the correct matrix and clip before this device is drawn |
| 145 | * to using those settings. If your subclass overrides this, be sure to |
| 146 | * call through to the base class as well. |
| 147 | * |
| 148 | * The clipstack is another view of the clip. It records the actual |
| 149 | * geometry that went into building the region. It is present for devices |
| 150 | * that want to parse it, but is not required: the region is a complete |
| 151 | * picture of the current clip. (i.e. if you regionize all of the geometry |
| 152 | * in the clipstack, you will arrive at an equivalent region to the one |
| 153 | * passed in). |
bsalomon@google.com | a6926b1 | 2012-10-10 15:25:50 +0000 | [diff] [blame] | 154 | */ |
| 155 | virtual void setMatrixClip(const SkMatrix&, const SkRegion&, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 156 | const SkClipStack&) {}; |
robertphillips@google.com | 3fffb2e | 2012-10-09 22:30:18 +0000 | [diff] [blame] | 157 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 158 | /** Clears the entire device to the specified color (including alpha). |
| 159 | * Ignores the clip. |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 160 | */ |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 161 | virtual void clear(SkColor color) = 0; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 162 | |
tfarina@chromium.org | 62f1048 | 2014-01-15 00:19:21 +0000 | [diff] [blame] | 163 | SK_ATTR_DEPRECATED("use clear() instead") |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 164 | void eraseColor(SkColor eraseColor) { this->clear(eraseColor); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 165 | |
| 166 | /** These are called inside the per-device-layer loop for each draw call. |
| 167 | When these are called, we have already applied any saveLayer operations, |
| 168 | and are handling any looping from the paint, and any effects from the |
| 169 | DrawFilter. |
| 170 | */ |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 171 | virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 172 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 173 | const SkPoint[], const SkPaint& paint) = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 174 | virtual void drawRect(const SkDraw&, const SkRect& r, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 175 | const SkPaint& paint) = 0; |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 176 | virtual void drawOval(const SkDraw&, const SkRect& oval, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 177 | const SkPaint& paint) = 0; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 178 | virtual void drawRRect(const SkDraw&, const SkRRect& rr, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 179 | const SkPaint& paint) = 0; |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 180 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 181 | // Default impl calls drawPath() |
| 182 | virtual void drawDRRect(const SkDraw&, const SkRRect& outer, |
| 183 | const SkRRect& inner, const SkPaint&); |
| 184 | |
reed@google.com | 7ff8d81 | 2011-03-25 15:08:16 +0000 | [diff] [blame] | 185 | /** |
| 186 | * If pathIsMutable, then the implementation is allowed to cast path to a |
| 187 | * non-const pointer and modify it in place (as an optimization). Canvas |
| 188 | * may do this to implement helpers such as drawOval, by placing a temp |
| 189 | * path on the stack to hold the representation of the oval. |
| 190 | * |
| 191 | * If prePathMatrix is not null, it should logically be applied before any |
| 192 | * stroking or other effects. If there are no effects on the paint that |
| 193 | * affect the geometry/rasterization, then the pre matrix can just be |
| 194 | * pre-concated with the current matrix. |
| 195 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 196 | virtual void drawPath(const SkDraw&, const SkPath& path, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 197 | const SkPaint& paint, |
| 198 | const SkMatrix* prePathMatrix = NULL, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 199 | bool pathIsMutable = false) = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 200 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 201 | const SkMatrix& matrix, const SkPaint& paint) = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 202 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 203 | int x, int y, const SkPaint& paint) = 0; |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 204 | |
| 205 | /** |
| 206 | * The default impl. will create a bitmap-shader from the bitmap, |
| 207 | * and call drawRect with it. |
| 208 | */ |
| 209 | virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, |
| 210 | const SkRect* srcOrNull, const SkRect& dst, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 211 | const SkPaint& paint, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 212 | SkCanvas::DrawBitmapRectFlags flags) = 0; |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 213 | |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 214 | /** |
| 215 | * Does not handle text decoration. |
| 216 | * Decorations (underline and stike-thru) will be handled by SkCanvas. |
| 217 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 218 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 219 | SkScalar x, SkScalar y, const SkPaint& paint) = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 220 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
| 221 | const SkScalar pos[], SkScalar constY, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 222 | int scalarsPerPos, const SkPaint& paint) = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 223 | virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
| 224 | const SkPath& path, const SkMatrix* matrix, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 225 | const SkPaint& paint) = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 226 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, |
| 227 | const SkPoint verts[], const SkPoint texs[], |
| 228 | const SkColor colors[], SkXfermode* xmode, |
| 229 | const uint16_t indices[], int indexCount, |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 230 | const SkPaint& paint) = 0; |
fmalita | aa1b912 | 2014-08-28 14:32:24 -0700 | [diff] [blame] | 231 | // default implementation unrolls the blob runs. |
| 232 | virtual void drawTextBlob(const SkDraw&, const SkTextBlob*, SkScalar x, SkScalar y, |
| 233 | const SkPaint& paint); |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 234 | // default implementation calls drawVertices |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 235 | virtual void drawPatch(const SkDraw&, const SkPoint cubics[12], const SkColor colors[4], |
| 236 | const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint); |
robertphillips@google.com | 9b051a3 | 2013-08-20 20:06:40 +0000 | [diff] [blame] | 237 | /** The SkDevice passed will be an SkDevice which was returned by a call to |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 238 | onCreateDevice on this device with kSaveLayer_Usage. |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 239 | */ |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 240 | virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
| 241 | const SkPaint&) = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 242 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 243 | bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y); |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 244 | |
reed@google.com | 3636ed5 | 2011-01-25 23:50:57 +0000 | [diff] [blame] | 245 | /////////////////////////////////////////////////////////////////////////// |
| 246 | |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 247 | /** Update as needed the pixel value in the bitmap, so that the caller can |
skia.committer@gmail.com | 772c4e6 | 2013-08-30 07:01:34 +0000 | [diff] [blame] | 248 | access the pixels directly. |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 249 | @return The device contents as a bitmap |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 250 | */ |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 251 | virtual const SkBitmap& onAccessBitmap() = 0; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 252 | |
robertphillips@google.com | 07f81a5 | 2013-09-17 12:26:23 +0000 | [diff] [blame] | 253 | /** Called when this device is installed into a Canvas. Balanced by a call |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 254 | to unlockPixels() when the device is removed from a Canvas. |
| 255 | */ |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 256 | virtual void lockPixels() {} |
| 257 | virtual void unlockPixels() {} |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 258 | |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 259 | /** |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 260 | * Returns true if the device allows processing of this imagefilter. If |
| 261 | * false is returned, then the filter is ignored. This may happen for |
| 262 | * some subclasses that do not support pixel manipulations after drawing |
| 263 | * has occurred (e.g. printing). The default implementation returns true. |
| 264 | */ |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 265 | virtual bool allowImageFilter(const SkImageFilter*) { return true; } |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 266 | |
| 267 | /** |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 268 | * Override and return true for filters that the device can handle |
| 269 | * intrinsically. Doing so means that SkCanvas will pass-through this |
| 270 | * filter to drawSprite and drawDevice (and potentially filterImage). |
| 271 | * Returning false means the SkCanvas will have apply the filter itself, |
| 272 | * and just pass the resulting image to the device. |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 273 | */ |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 274 | virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 275 | |
| 276 | /** |
| 277 | * Related (but not required) to canHandleImageFilter, this method returns |
| 278 | * true if the device could apply the filter to the src bitmap and return |
| 279 | * the result (and updates offset as needed). |
| 280 | * If the device does not recognize or support this filter, |
| 281 | * it just returns false and leaves result and offset unchanged. |
| 282 | */ |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 283 | virtual bool filterImage(const SkImageFilter*, const SkBitmap&, |
| 284 | const SkImageFilter::Context& ctx, |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 285 | SkBitmap* result, SkIPoint* offset) { |
| 286 | return false; |
| 287 | } |
robertphillips@google.com | 9b051a3 | 2013-08-20 20:06:40 +0000 | [diff] [blame] | 288 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 289 | protected: |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 290 | // default impl returns NULL |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame^] | 291 | virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&); |
skia.committer@gmail.com | 02d6f54 | 2014-02-14 03:02:05 +0000 | [diff] [blame] | 292 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 293 | // default impl returns NULL |
| 294 | virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes); |
skia.committer@gmail.com | 02d6f54 | 2014-02-14 03:02:05 +0000 | [diff] [blame] | 295 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 296 | /** |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 297 | * The caller is responsible for "pre-clipping" the dst. The impl can assume that the dst |
| 298 | * image at the specified x,y offset will fit within the device's bounds. |
| 299 | * |
| 300 | * This is explicitly asserted in readPixels(), the public way to call this. |
| 301 | */ |
| 302 | virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y); |
commit-bot@chromium.org | 2cccf83 | 2014-03-12 03:04:08 +0000 | [diff] [blame] | 303 | |
| 304 | /** |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 305 | * The caller is responsible for "pre-clipping" the src. The impl can assume that the src |
| 306 | * image at the specified x,y offset will fit within the device's bounds. |
| 307 | * |
| 308 | * This is explicitly asserted in writePixelsDirect(), the public way to call this. |
| 309 | */ |
| 310 | virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y); |
| 311 | |
| 312 | /** |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 313 | * Default impl returns NULL. |
| 314 | */ |
| 315 | virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes); |
| 316 | |
| 317 | /** |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 318 | * Leaky properties are those which the device should be applying but it isn't. |
| 319 | * These properties will be applied by the draw, when and as it can. |
| 320 | * If the device does handle a property, that property should be set to the identity value |
| 321 | * for that property, effectively making it non-leaky. |
| 322 | */ |
reed | e010f1c | 2014-09-17 10:49:38 -0700 | [diff] [blame] | 323 | const SkDeviceProperties& getLeakyProperties() const { |
| 324 | return *fLeakyProperties; |
| 325 | } |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 326 | |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 327 | /** |
| 328 | * PRIVATE / EXPERIMENTAL -- do not call |
| 329 | * Construct an acceleration object and attach it to 'picture' |
| 330 | */ |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 331 | virtual void EXPERIMENTAL_optimize(const SkPicture* picture); |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * PRIVATE / EXPERIMENTAL -- do not call |
| 335 | * This entry point gives the backend an opportunity to take over the rendering |
| 336 | * of 'picture'. If optimization data is available (due to an earlier |
| 337 | * 'optimize' call) this entry point should make use of it and return true |
| 338 | * if all rendering has been done. If false is returned, SkCanvas will |
skia.committer@gmail.com | eb849e5 | 2014-03-17 03:02:17 +0000 | [diff] [blame] | 339 | * perform its own rendering pass. It is acceptable for the backend |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 340 | * to perform some device-specific warm up tasks and then let SkCanvas |
| 341 | * perform the main rendering loop (by return false from here). |
| 342 | */ |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 343 | virtual bool EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const SkMatrix*, |
| 344 | const SkPaint*); |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 345 | |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame^] | 346 | void setPixelGeometry(SkPixelGeometry geo); |
| 347 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 348 | private: |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 349 | friend class SkCanvas; |
robertphillips@google.com | 3fffb2e | 2012-10-09 22:30:18 +0000 | [diff] [blame] | 350 | friend struct DeviceCM; //for setMatrixClip |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 351 | friend class SkDraw; |
| 352 | friend class SkDrawIter; |
| 353 | friend class SkDeviceFilteredPaint; |
senorblanco@chromium.org | 9c39744 | 2012-09-27 21:57:45 +0000 | [diff] [blame] | 354 | friend class SkDeviceImageFilterProxy; |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 355 | friend class SkDeferredDevice; // for newSurface |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 356 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 357 | friend class SkSurface_Raster; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 358 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 359 | // used to change the backend's pixels (and possibly config/rowbytes) |
| 360 | // but cannot change the width/height, so there should be no change to |
| 361 | // any clip information. |
reed@google.com | ec3ca87 | 2013-11-13 16:02:18 +0000 | [diff] [blame] | 362 | // TODO: move to SkBitmapDevice |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 363 | virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) {} |
robertphillips@google.com | 9b051a3 | 2013-08-20 20:06:40 +0000 | [diff] [blame] | 364 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 365 | virtual bool forceConservativeRasterClip() const { return false; } |
| 366 | |
robertphillips@google.com | 9b051a3 | 2013-08-20 20:06:40 +0000 | [diff] [blame] | 367 | // just called by SkCanvas when built as a layer |
| 368 | void setOrigin(int x, int y) { fOrigin.set(x, y); } |
| 369 | // just called by SkCanvas for saveLayer |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 370 | SkBaseDevice* createCompatibleDeviceForSaveLayer(const SkImageInfo&); |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 371 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 372 | virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) { |
| 373 | return NULL; |
| 374 | } |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 375 | |
| 376 | /** Causes any deferred drawing to the device to be completed. |
| 377 | */ |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 378 | virtual void flush() {} |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 379 | |
senorblanco | be129b2 | 2014-08-08 07:14:35 -0700 | [diff] [blame] | 380 | virtual SkImageFilter::Cache* getImageFilterCache() { return NULL; } |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 381 | |
robertphillips@google.com | 9b051a3 | 2013-08-20 20:06:40 +0000 | [diff] [blame] | 382 | SkIPoint fOrigin; |
| 383 | SkMetaData* fMetaData; |
reed | e010f1c | 2014-09-17 10:49:38 -0700 | [diff] [blame] | 384 | SkDeviceProperties* fLeakyProperties; // will always exist. |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 385 | |
robertphillips@google.com | 9b051a3 | 2013-08-20 20:06:40 +0000 | [diff] [blame] | 386 | #ifdef SK_DEBUG |
| 387 | bool fAttachedToCanvas; |
| 388 | #endif |
| 389 | |
| 390 | typedef SkRefCnt INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 391 | }; |
| 392 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 393 | #endif |