epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkDevice_DEFINED |
| 11 | #define SkDevice_DEFINED |
| 12 | |
| 13 | #include "SkRefCnt.h" |
| 14 | #include "SkBitmap.h" |
| 15 | #include "SkCanvas.h" |
| 16 | #include "SkColor.h" |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame^] | 17 | #include "SkDeviceProperties.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | |
reed@google.com | 46799cd | 2011-02-22 20:56:26 +0000 | [diff] [blame] | 19 | class SkClipStack; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | class SkDraw; |
| 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; |
| 25 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 26 | // This is an opaque class, not interpreted by skia |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 27 | class SkGpuRenderTarget; |
| 28 | |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 29 | class SK_API SkDevice : public SkRefCnt { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | public: |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 31 | SK_DECLARE_INST_COUNT(SkDevice) |
| 32 | |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 33 | /** |
| 34 | * Construct a new device with the specified bitmap as its backend. It is |
| 35 | * valid for the bitmap to have no pixels associated with it. In that case, |
| 36 | * any drawing to this device will have no effect. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | */ |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 38 | SkDevice(const SkBitmap& bitmap); |
| 39 | |
| 40 | /** |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame^] | 41 | * Construct a new device with the specified bitmap as its backend. It is |
| 42 | * valid for the bitmap to have no pixels associated with it. In that case, |
| 43 | * any drawing to this device will have no effect. |
| 44 | */ |
| 45 | SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties); |
| 46 | |
| 47 | /** |
reed@google.com | af951c9 | 2011-06-16 19:10:39 +0000 | [diff] [blame] | 48 | * Create a new raster device and have the pixels be automatically |
| 49 | * allocated. The rowBytes of the device will be computed automatically |
| 50 | * based on the config and the width. |
| 51 | * |
| 52 | * @param config The desired config for the pixels. If the request cannot |
| 53 | * be met, the closest matching support config will be used. |
| 54 | * @param width width (in pixels) of the device |
| 55 | * @param height height (in pixels) of the device |
| 56 | * @param isOpaque Set to true if it is known that all of the pixels will |
| 57 | * be drawn to opaquely. Used as an accelerator when drawing |
| 58 | * these pixels to another device. |
| 59 | */ |
| 60 | SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false); |
| 61 | |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame^] | 62 | /** |
| 63 | * Create a new raster device and have the pixels be automatically |
| 64 | * allocated. The rowBytes of the device will be computed automatically |
| 65 | * based on the config and the width. |
| 66 | * |
| 67 | * @param config The desired config for the pixels. If the request cannot |
| 68 | * be met, the closest matching support config will be used. |
| 69 | * @param width width (in pixels) of the device |
| 70 | * @param height height (in pixels) of the device |
| 71 | * @param isOpaque Set to true if it is known that all of the pixels will |
| 72 | * be drawn to opaquely. Used as an accelerator when drawing |
| 73 | * these pixels to another device. |
| 74 | * @param deviceProperties Properties which affect compositing. |
| 75 | */ |
| 76 | SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque, |
| 77 | const SkDeviceProperties& deviceProperties); |
| 78 | |
reed@google.com | a7d9485 | 2011-03-30 21:23:07 +0000 | [diff] [blame] | 79 | virtual ~SkDevice(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 80 | |
mike@reedtribe.org | ea4ac97 | 2011-04-26 11:48:33 +0000 | [diff] [blame] | 81 | /** |
reed@google.com | 2d54d06 | 2011-06-21 12:19:28 +0000 | [diff] [blame] | 82 | * Creates a device that is of the same type as this device (e.g. SW-raster, |
| 83 | * GPU, or PDF). The backing store for this device is created automatically |
| 84 | * (e.g. offscreen pixels or FBO or whatever is appropriate). |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 85 | * |
reed@google.com | 2d54d06 | 2011-06-21 12:19:28 +0000 | [diff] [blame] | 86 | * @param width width of the device to create |
| 87 | * @param height height of the device to create |
| 88 | * @param isOpaque performance hint, set to true if you know that you will |
| 89 | * draw into this device such that all of the pixels will |
| 90 | * be opaque. |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 91 | */ |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 92 | SkDevice* createCompatibleDevice(SkBitmap::Config config, |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 93 | int width, int height, |
| 94 | bool isOpaque); |
| 95 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 96 | SkMetaData& getMetaData(); |
| 97 | |
vandebo@chromium.org | 35fc62b | 2010-10-26 19:47:30 +0000 | [diff] [blame] | 98 | enum Capabilities { |
| 99 | kGL_Capability = 0x1, //!< mask indicating GL support |
| 100 | kVector_Capability = 0x2, //!< mask indicating a vector representation |
| 101 | kAll_Capabilities = 0x3 |
| 102 | }; |
tomhudson@google.com | 8a0b029 | 2011-09-13 14:41:06 +0000 | [diff] [blame] | 103 | virtual uint32_t getDeviceCapabilities() { return 0; } |
vandebo@chromium.org | 35fc62b | 2010-10-26 19:47:30 +0000 | [diff] [blame] | 104 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | /** Return the width of the device (in pixels). |
| 106 | */ |
tomhudson@google.com | 8a0b029 | 2011-09-13 14:41:06 +0000 | [diff] [blame] | 107 | virtual int width() const { return fBitmap.width(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 108 | /** Return the height of the device (in pixels). |
| 109 | */ |
tomhudson@google.com | 8a0b029 | 2011-09-13 14:41:06 +0000 | [diff] [blame] | 110 | virtual int height() const { return fBitmap.height(); } |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 111 | |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame^] | 112 | /** Return the image properties of the device. */ |
| 113 | virtual const SkDeviceProperties& getDeviceProperties() const { |
| 114 | //Currently, all the properties are leaky. |
| 115 | return fLeakyProperties; |
| 116 | } |
| 117 | |
reed@google.com | d51bfa0 | 2011-08-30 15:56:11 +0000 | [diff] [blame] | 118 | /** |
| 119 | * Return the bounds of the device in the coordinate space of the root |
| 120 | * canvas. The root device will have its top-left at 0,0, but other devices |
| 121 | * such as those associated with saveLayer may have a non-zero origin. |
| 122 | */ |
| 123 | void getGlobalBounds(SkIRect* bounds) const; |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 124 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 125 | /** Returns true if the device's bitmap's config treats every pixels as |
| 126 | implicitly opaque. |
| 127 | */ |
| 128 | bool isOpaque() const { return fBitmap.isOpaque(); } |
reed@google.com | 3dd42b3 | 2011-02-07 22:44:43 +0000 | [diff] [blame] | 129 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 130 | /** Return the bitmap config of the device's pixels |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 131 | */ |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 132 | SkBitmap::Config config() const { return fBitmap.getConfig(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 133 | |
| 134 | /** Return the bitmap associated with this device. Call this each time you need |
| 135 | to access the bitmap, as it notifies the subclass to perform any flushing |
| 136 | etc. before you examine the pixels. |
| 137 | @param changePixels set to true if the caller plans to change the pixels |
| 138 | @return the device's bitmap |
| 139 | */ |
| 140 | const SkBitmap& accessBitmap(bool changePixels); |
| 141 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 142 | /** |
bsalomon@google.com | ae0fb05 | 2011-11-10 22:34:56 +0000 | [diff] [blame] | 143 | * DEPRECATED: This will be made protected once WebKit stops using it. |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 144 | * Instead use Canvas' writePixels method. |
bsalomon@google.com | d58a1cd | 2011-11-10 20:57:43 +0000 | [diff] [blame] | 145 | * |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 146 | * Similar to draw sprite, this method will copy the pixels in bitmap onto |
| 147 | * the device, with the top/left corner specified by (x, y). The pixel |
| 148 | * values in the device are completely replaced: there is no blending. |
bsalomon@google.com | d58a1cd | 2011-11-10 20:57:43 +0000 | [diff] [blame] | 149 | * |
| 150 | * Currently if bitmap is backed by a texture this is a no-op. This may be |
| 151 | * relaxed in the future. |
| 152 | * |
| 153 | * If the bitmap has config kARGB_8888_Config then the config8888 param |
| 154 | * will determines how the pixel valuess are intepreted. If the bitmap is |
| 155 | * not kARGB_8888_Config then this parameter is ignored. |
bsalomon@google.com | 398109c | 2011-04-14 18:40:27 +0000 | [diff] [blame] | 156 | */ |
bsalomon@google.com | d58a1cd | 2011-11-10 20:57:43 +0000 | [diff] [blame] | 157 | virtual void writePixels(const SkBitmap& bitmap, int x, int y, |
bsalomon@google.com | ae0fb05 | 2011-11-10 22:34:56 +0000 | [diff] [blame] | 158 | SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 159 | |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 160 | /** |
| 161 | * Return the device's associated gpu render target, or NULL. |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 162 | */ |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 163 | virtual SkGpuRenderTarget* accessRenderTarget() { return NULL; } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 164 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * Return the device's origin: its offset in device coordinates from |
| 168 | * the default origin in its canvas' matrix/clip |
| 169 | */ |
| 170 | const SkIPoint& getOrigin() const { return fOrigin; } |
| 171 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 172 | /** |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 173 | * onAttachToCanvas is invoked whenever a device is installed in a canvas |
| 174 | * (i.e., setDevice, saveLayer (for the new device created by the save), |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 175 | * and SkCanvas' SkDevice & SkBitmap -taking ctors). It allows the |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 176 | * devices to prepare for drawing (e.g., locking their pixels, etc.) |
| 177 | */ |
| 178 | virtual void onAttachToCanvas(SkCanvas* canvas) { |
bsalomon@google.com | 405d0f4 | 2012-08-29 21:26:13 +0000 | [diff] [blame] | 179 | SkASSERT(!fAttachedToCanvas); |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 180 | this->lockPixels(); |
| 181 | #ifdef SK_DEBUG |
| 182 | fAttachedToCanvas = true; |
| 183 | #endif |
| 184 | }; |
| 185 | |
| 186 | /** |
| 187 | * onDetachFromCanvas notifies a device that it will no longer be drawn to. |
| 188 | * 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] | 189 | * is invoked from setDevice (for the displaced device), restore and |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 190 | * possibly from SkCanvas' dtor. |
| 191 | */ |
| 192 | virtual void onDetachFromCanvas() { |
bsalomon@google.com | 405d0f4 | 2012-08-29 21:26:13 +0000 | [diff] [blame] | 193 | SkASSERT(fAttachedToCanvas); |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 194 | this->unlockPixels(); |
| 195 | #ifdef SK_DEBUG |
| 196 | fAttachedToCanvas = false; |
| 197 | #endif |
| 198 | }; |
| 199 | |
caryclark@google.com | d53f7c2 | 2012-01-05 17:05:05 +0000 | [diff] [blame] | 200 | protected: |
| 201 | enum Usage { |
| 202 | kGeneral_Usage, |
tomhudson@google.com | 1f90287 | 2012-06-01 13:15:47 +0000 | [diff] [blame] | 203 | kSaveLayer_Usage // <! internal use only |
caryclark@google.com | d53f7c2 | 2012-01-05 17:05:05 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 206 | struct TextFlags { |
| 207 | uint32_t fFlags; // SkPaint::getFlags() |
| 208 | SkPaint::Hinting fHinting; |
| 209 | }; |
| 210 | |
| 211 | /** |
| 212 | * Device may filter the text flags for drawing text here. If it wants to |
| 213 | * make a change to the specified values, it should write them into the |
| 214 | * textflags parameter (output) and return true. If the paint is fine as |
| 215 | * is, then ignore the textflags parameter and return false. |
| 216 | * |
| 217 | * The baseclass SkDevice filters based on its depth and blitters. |
| 218 | */ |
| 219 | virtual bool filterTextFlags(const SkPaint& paint, TextFlags*); |
| 220 | |
robertphillips@google.com | 3fffb2e | 2012-10-09 22:30:18 +0000 | [diff] [blame] | 221 | /** |
bsalomon@google.com | a6926b1 | 2012-10-10 15:25:50 +0000 | [diff] [blame] | 222 | * |
| 223 | * DEPRECATED: This will be removed in a future change. Device subclasses |
| 224 | * should use the matrix and clip from the SkDraw passed to draw functions. |
| 225 | * |
robertphillips@google.com | 3fffb2e | 2012-10-09 22:30:18 +0000 | [diff] [blame] | 226 | * Called with the correct matrix and clip before this device is drawn |
| 227 | * to using those settings. If your subclass overrides this, be sure to |
| 228 | * call through to the base class as well. |
| 229 | * |
| 230 | * The clipstack is another view of the clip. It records the actual |
| 231 | * geometry that went into building the region. It is present for devices |
| 232 | * that want to parse it, but is not required: the region is a complete |
| 233 | * picture of the current clip. (i.e. if you regionize all of the geometry |
| 234 | * in the clipstack, you will arrive at an equivalent region to the one |
| 235 | * passed in). |
bsalomon@google.com | a6926b1 | 2012-10-10 15:25:50 +0000 | [diff] [blame] | 236 | */ |
| 237 | virtual void setMatrixClip(const SkMatrix&, const SkRegion&, |
skia.committer@gmail.com | fc84359 | 2012-10-11 02:01:14 +0000 | [diff] [blame] | 238 | const SkClipStack&); |
robertphillips@google.com | 3fffb2e | 2012-10-09 22:30:18 +0000 | [diff] [blame] | 239 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 240 | /** Clears the entire device to the specified color (including alpha). |
| 241 | * Ignores the clip. |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 242 | */ |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 243 | virtual void clear(SkColor color); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 244 | |
| 245 | /** |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 246 | * Deprecated name for clear. |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 247 | */ |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 248 | void eraseColor(SkColor eraseColor) { this->clear(eraseColor); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 249 | |
| 250 | /** These are called inside the per-device-layer loop for each draw call. |
| 251 | When these are called, we have already applied any saveLayer operations, |
| 252 | and are handling any looping from the paint, and any effects from the |
| 253 | DrawFilter. |
| 254 | */ |
| 255 | virtual void drawPaint(const SkDraw&, const SkPaint& paint); |
| 256 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, |
| 257 | const SkPoint[], const SkPaint& paint); |
| 258 | virtual void drawRect(const SkDraw&, const SkRect& r, |
| 259 | const SkPaint& paint); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 260 | virtual void drawOval(const SkDraw&, const SkRect& oval, |
| 261 | const SkPaint& paint); |
reed@google.com | 7ff8d81 | 2011-03-25 15:08:16 +0000 | [diff] [blame] | 262 | /** |
| 263 | * If pathIsMutable, then the implementation is allowed to cast path to a |
| 264 | * non-const pointer and modify it in place (as an optimization). Canvas |
| 265 | * may do this to implement helpers such as drawOval, by placing a temp |
| 266 | * path on the stack to hold the representation of the oval. |
| 267 | * |
| 268 | * If prePathMatrix is not null, it should logically be applied before any |
| 269 | * stroking or other effects. If there are no effects on the paint that |
| 270 | * affect the geometry/rasterization, then the pre matrix can just be |
| 271 | * pre-concated with the current matrix. |
| 272 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 273 | virtual void drawPath(const SkDraw&, const SkPath& path, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 274 | const SkPaint& paint, |
| 275 | const SkMatrix* prePathMatrix = NULL, |
| 276 | bool pathIsMutable = false); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 277 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 278 | const SkIRect* srcRectOrNull, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 279 | const SkMatrix& matrix, const SkPaint& paint); |
| 280 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
| 281 | int x, int y, const SkPaint& paint); |
reed@google.com | 33535f3 | 2012-09-25 15:37:50 +0000 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * The default impl. will create a bitmap-shader from the bitmap, |
| 285 | * and call drawRect with it. |
| 286 | */ |
| 287 | virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, |
| 288 | const SkRect* srcOrNull, const SkRect& dst, |
| 289 | const SkPaint& paint); |
| 290 | |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 291 | /** |
| 292 | * Does not handle text decoration. |
| 293 | * Decorations (underline and stike-thru) will be handled by SkCanvas. |
| 294 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 295 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
| 296 | SkScalar x, SkScalar y, const SkPaint& paint); |
| 297 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
| 298 | const SkScalar pos[], SkScalar constY, |
| 299 | int scalarsPerPos, const SkPaint& paint); |
| 300 | virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
| 301 | const SkPath& path, const SkMatrix* matrix, |
| 302 | const SkPaint& paint); |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 303 | #ifdef SK_BUILD_FOR_ANDROID |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame] | 304 | virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, |
| 305 | const SkPoint pos[], const SkPaint& paint, |
| 306 | const SkPath& path, const SkMatrix* matrix); |
| 307 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 308 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, |
| 309 | const SkPoint verts[], const SkPoint texs[], |
| 310 | const SkColor colors[], SkXfermode* xmode, |
| 311 | const uint16_t indices[], int indexCount, |
| 312 | const SkPaint& paint); |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 313 | /** The SkDevice passed will be an SkDevice which was returned by a call to |
| 314 | onCreateCompatibleDevice on this device with kSaveLayer_Usage. |
| 315 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 316 | virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, |
| 317 | const SkPaint&); |
| 318 | |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 319 | /** |
| 320 | * On success (returns true), copy the device pixels into the bitmap. |
| 321 | * On failure, the bitmap parameter is left unchanged and false is |
| 322 | * returned. |
| 323 | * |
| 324 | * The device's pixels are converted to the bitmap's config. The only |
| 325 | * supported config is kARGB_8888_Config, though this is likely to be |
| 326 | * relaxed in the future. The meaning of config kARGB_8888_Config is |
| 327 | * modified by the enum param config8888. The default value interprets |
| 328 | * kARGB_8888_Config as SkPMColor |
| 329 | * |
| 330 | * If the bitmap has pixels already allocated, the device pixels will be |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 331 | * written there. If not, bitmap->allocPixels() will be called |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 332 | * automatically. If the bitmap is backed by a texture readPixels will |
| 333 | * fail. |
| 334 | * |
| 335 | * The actual pixels written is the intersection of the device's bounds, |
| 336 | * and the rectangle formed by the bitmap's width,height and the specified |
| 337 | * x,y. If bitmap pixels extend outside of that intersection, they will not |
| 338 | * be modified. |
| 339 | * |
| 340 | * Other failure conditions: |
| 341 | * * If the device is not a raster device (e.g. PDF) then readPixels will |
| 342 | * fail. |
| 343 | * * If bitmap is texture-backed then readPixels will fail. (This may be |
| 344 | * relaxed in the future.) |
| 345 | */ |
| 346 | bool readPixels(SkBitmap* bitmap, |
| 347 | int x, int y, |
| 348 | SkCanvas::Config8888 config8888); |
| 349 | |
reed@google.com | 3636ed5 | 2011-01-25 23:50:57 +0000 | [diff] [blame] | 350 | /////////////////////////////////////////////////////////////////////////// |
| 351 | |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 352 | /** Update as needed the pixel value in the bitmap, so that the caller can |
| 353 | access the pixels directly. Note: only the pixels field should be |
| 354 | altered. The config/width/height/rowbytes must remain unchanged. |
| 355 | @param bitmap The device's bitmap |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 356 | @return Echo the bitmap parameter, or an alternate (shadow) bitmap |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 357 | maintained by the subclass. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 358 | */ |
junov@chromium.org | 1f9767c | 2012-02-07 16:27:57 +0000 | [diff] [blame] | 359 | virtual const SkBitmap& onAccessBitmap(SkBitmap*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 360 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 361 | SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
| 362 | // just for subclasses, to assign a custom pixelref |
| 363 | SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) { |
| 364 | fBitmap.setPixelRef(pr, offset); |
| 365 | return pr; |
| 366 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 367 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 368 | /** |
| 369 | * Implements readPixels API. The caller will ensure that: |
| 370 | * 1. bitmap has pixel config kARGB_8888_Config. |
| 371 | * 2. bitmap has pixels. |
| 372 | * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is |
| 373 | * contained in the device bounds. |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 374 | */ |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 375 | virtual bool onReadPixels(const SkBitmap& bitmap, |
| 376 | int x, int y, |
| 377 | SkCanvas::Config8888 config8888); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 378 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 379 | /** Called when this device is installed into a Canvas. Balanaced by a call |
| 380 | to unlockPixels() when the device is removed from a Canvas. |
| 381 | */ |
| 382 | virtual void lockPixels(); |
| 383 | virtual void unlockPixels(); |
| 384 | |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 385 | /** |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 386 | * Returns true if the device allows processing of this imagefilter. If |
| 387 | * false is returned, then the filter is ignored. This may happen for |
| 388 | * some subclasses that do not support pixel manipulations after drawing |
| 389 | * has occurred (e.g. printing). The default implementation returns true. |
| 390 | */ |
| 391 | virtual bool allowImageFilter(SkImageFilter*); |
| 392 | |
| 393 | /** |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 394 | * Override and return true for filters that the device can handle |
| 395 | * intrinsically. Doing so means that SkCanvas will pass-through this |
| 396 | * filter to drawSprite and drawDevice (and potentially filterImage). |
| 397 | * Returning false means the SkCanvas will have apply the filter itself, |
| 398 | * and just pass the resulting image to the device. |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 399 | */ |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 400 | virtual bool canHandleImageFilter(SkImageFilter*); |
| 401 | |
| 402 | /** |
| 403 | * Related (but not required) to canHandleImageFilter, this method returns |
| 404 | * true if the device could apply the filter to the src bitmap and return |
| 405 | * the result (and updates offset as needed). |
| 406 | * If the device does not recognize or support this filter, |
| 407 | * it just returns false and leaves result and offset unchanged. |
| 408 | */ |
| 409 | virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&, |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 410 | SkBitmap* result, SkIPoint* offset); |
| 411 | |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 412 | // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if |
bsalomon@google.com | 6850eab | 2011-11-03 20:29:47 +0000 | [diff] [blame] | 413 | // either is identical to kNative_Premul_Config8888. Otherwise, -1. |
| 414 | static const SkCanvas::Config8888 kPMColorAlias; |
| 415 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 416 | private: |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 417 | friend class SkCanvas; |
robertphillips@google.com | 3fffb2e | 2012-10-09 22:30:18 +0000 | [diff] [blame] | 418 | friend struct DeviceCM; //for setMatrixClip |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 419 | friend class SkDraw; |
| 420 | friend class SkDrawIter; |
| 421 | friend class SkDeviceFilteredPaint; |
senorblanco@chromium.org | 9c39744 | 2012-09-27 21:57:45 +0000 | [diff] [blame] | 422 | friend class SkDeviceImageFilterProxy; |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 423 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 424 | friend class SkSurface_Raster; |
| 425 | // used to change the backend's pixels (and possibly config/rowbytes) |
| 426 | // but cannot change the width/height, so there should be no change to |
| 427 | // any clip information. |
| 428 | void replaceBitmapBackendForRasterSurface(const SkBitmap&); |
| 429 | |
vandebo@chromium.org | 5676b4a | 2011-10-03 19:03:48 +0000 | [diff] [blame] | 430 | // just called by SkCanvas when built as a layer |
| 431 | void setOrigin(int x, int y) { fOrigin.set(x, y); } |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 432 | // just called by SkCanvas for saveLayer |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 433 | SkDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config, |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 434 | int width, int height, |
| 435 | bool isOpaque); |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 436 | |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 437 | /** |
| 438 | * Subclasses should override this to implement createCompatibleDevice. |
| 439 | */ |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 440 | virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, |
| 441 | int width, int height, |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 442 | bool isOpaque, |
| 443 | Usage usage); |
| 444 | |
| 445 | /** Causes any deferred drawing to the device to be completed. |
| 446 | */ |
tomhudson@google.com | 8a0b029 | 2011-09-13 14:41:06 +0000 | [diff] [blame] | 447 | virtual void flush() {} |
bungeman@google.com | 88edf1e | 2011-08-08 19:41:56 +0000 | [diff] [blame] | 448 | |
reed@google.com | 3636ed5 | 2011-01-25 23:50:57 +0000 | [diff] [blame] | 449 | SkBitmap fBitmap; |
reed@google.com | 6f8f292 | 2011-03-04 22:27:10 +0000 | [diff] [blame] | 450 | SkIPoint fOrigin; |
reed@google.com | a7d9485 | 2011-03-30 21:23:07 +0000 | [diff] [blame] | 451 | SkMetaData* fMetaData; |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame^] | 452 | /** |
| 453 | * Leaky properties are those which the device should be applying but it isn't. |
| 454 | * These properties will be applied by the draw, when and as it can. |
| 455 | * If the device does handle a property, that property should be set to the identity value |
| 456 | * for that property, effectively making it non-leaky. |
| 457 | */ |
| 458 | SkDeviceProperties fLeakyProperties; |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 459 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 460 | #ifdef SK_DEBUG |
| 461 | bool fAttachedToCanvas; |
| 462 | #endif |
| 463 | |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 464 | typedef SkRefCnt INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 465 | }; |
| 466 | |
| 467 | #endif |