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