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