blob: e3a23be6cab1c648fe98e0ca96db7457da6081a7 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#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.com532470f2013-01-22 19:25:14 +000017#include "SkDeviceProperties.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000018
reed@google.com46799cd2011-02-22 20:56:26 +000019class SkClipStack;
reed@android.com8a1c16f2008-12-17 15:59:43 +000020class SkDraw;
21struct SkIRect;
22class SkMatrix;
reed@google.coma7d94852011-03-30 21:23:07 +000023class SkMetaData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000024class SkRegion;
25
commit-bot@chromium.orgb8d00db2013-06-26 19:18:23 +000026class GrRenderTarget;
bsalomon@google.comd9f826c2011-07-18 15:25:04 +000027
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000028class SK_API SkBaseDevice : public SkRefCnt {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029public:
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000030 SK_DECLARE_INST_COUNT(SkBaseDevice)
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000031
reed@google.comaf951c92011-06-16 19:10:39 +000032 /**
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000033 * Construct a new device.
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000035 SkBaseDevice();
reed@google.comaf951c92011-06-16 19:10:39 +000036
37 /**
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000038 * Construct a new device.
bungeman@google.com532470f2013-01-22 19:25:14 +000039 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000040 SkBaseDevice(const SkDeviceProperties& deviceProperties);
bungeman@google.com532470f2013-01-22 19:25:14 +000041
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000042 virtual ~SkBaseDevice();
reed@android.com8a1c16f2008-12-17 15:59:43 +000043
mike@reedtribe.orgea4ac972011-04-26 11:48:33 +000044 /**
reed@google.com2d54d062011-06-21 12:19:28 +000045 * 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.come97f0852011-06-17 13:10:25 +000048 *
reed@google.com2d54d062011-06-21 12:19:28 +000049 * @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.come97f0852011-06-17 13:10:25 +000054 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000055 SkBaseDevice* createCompatibleDevice(SkBitmap::Config config,
56 int width, int height,
57 bool isOpaque);
bsalomon@google.come97f0852011-06-17 13:10:25 +000058
bungeman@google.com88edf1e2011-08-08 19:41:56 +000059 SkMetaData& getMetaData();
60
vandebo@chromium.org35fc62b2010-10-26 19:47:30 +000061 enum Capabilities {
reed@google.comfdbd5042014-02-04 17:49:52 +000062 kVector_Capability = 0x1, //!< mask indicating a vector representation
vandebo@chromium.org35fc62b2010-10-26 19:47:30 +000063 };
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000064 virtual uint32_t getDeviceCapabilities() = 0;
vandebo@chromium.org35fc62b2010-10-26 19:47:30 +000065
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 /** Return the width of the device (in pixels).
67 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000068 virtual int width() const = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 /** Return the height of the device (in pixels).
70 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000071 virtual int height() const = 0;
reed@google.com6f8f2922011-03-04 22:27:10 +000072
bungeman@google.com532470f2013-01-22 19:25:14 +000073 /** Return the image properties of the device. */
74 virtual const SkDeviceProperties& getDeviceProperties() const {
75 //Currently, all the properties are leaky.
76 return fLeakyProperties;
77 }
78
reed@google.comd51bfa02011-08-30 15:56:11 +000079 /**
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000080 * Return ImageInfo for this device. If the canvas is not backed by pixels
81 * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
82 */
83 virtual SkImageInfo imageInfo() const;
84
85 /**
reed@google.comd51bfa02011-08-30 15:56:11 +000086 * Return the bounds of the device in the coordinate space of the root
87 * canvas. The root device will have its top-left at 0,0, but other devices
88 * such as those associated with saveLayer may have a non-zero origin.
89 */
reed@google.comec3ca872013-11-13 16:02:18 +000090 void getGlobalBounds(SkIRect* bounds) const {
91 SkASSERT(bounds);
92 const SkIPoint& origin = this->getOrigin();
93 bounds->setXYWH(origin.x(), origin.y(), this->width(), this->height());
94 }
skia.committer@gmail.com73a5d532013-11-14 07:02:31 +000095
bungeman@google.com88edf1e2011-08-08 19:41:56 +000096
robertphillips@google.com07f81a52013-09-17 12:26:23 +000097 /** Returns true if the device's bitmap's config treats every pixel as
reed@android.com8a1c16f2008-12-17 15:59:43 +000098 implicitly opaque.
99 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000100 virtual bool isOpaque() const = 0;
skia.committer@gmail.com772c4e62013-08-30 07:01:34 +0000101
reed@google.com44699382013-10-31 17:28:30 +0000102 /** Return the bitmap config of the device's pixels
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000103 */
reed@google.com44699382013-10-31 17:28:30 +0000104 SK_ATTR_DEPRECATED("want to hide configness of the device -- don't use")
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000105 virtual SkBitmap::Config config() const = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000106
107 /** Return the bitmap associated with this device. Call this each time you need
108 to access the bitmap, as it notifies the subclass to perform any flushing
109 etc. before you examine the pixels.
110 @param changePixels set to true if the caller plans to change the pixels
111 @return the device's bitmap
112 */
113 const SkBitmap& accessBitmap(bool changePixels);
114
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000115 /**
bsalomon@google.comae0fb052011-11-10 22:34:56 +0000116 * DEPRECATED: This will be made protected once WebKit stops using it.
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000117 * Instead use Canvas' writePixels method.
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000118 *
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000119 * Similar to draw sprite, this method will copy the pixels in bitmap onto
120 * the device, with the top/left corner specified by (x, y). The pixel
121 * values in the device are completely replaced: there is no blending.
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000122 *
123 * Currently if bitmap is backed by a texture this is a no-op. This may be
124 * relaxed in the future.
125 *
126 * If the bitmap has config kARGB_8888_Config then the config8888 param
127 * will determines how the pixel valuess are intepreted. If the bitmap is
128 * not kARGB_8888_Config then this parameter is ignored.
bsalomon@google.com398109c2011-04-14 18:40:27 +0000129 */
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000130 virtual void writePixels(const SkBitmap& bitmap, int x, int y,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000131 SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000132
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000133 /**
134 * Return the device's associated gpu render target, or NULL.
reed@android.comf2b98d62010-12-20 18:26:13 +0000135 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000136 virtual GrRenderTarget* accessRenderTarget() = 0;
reed@android.comf2b98d62010-12-20 18:26:13 +0000137
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000138
139 /**
140 * Return the device's origin: its offset in device coordinates from
141 * the default origin in its canvas' matrix/clip
142 */
143 const SkIPoint& getOrigin() const { return fOrigin; }
144
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000145 /**
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000146 * onAttachToCanvas is invoked whenever a device is installed in a canvas
147 * (i.e., setDevice, saveLayer (for the new device created by the save),
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000148 * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000149 * devices to prepare for drawing (e.g., locking their pixels, etc.)
150 */
sugoi@google.come0e385c2013-03-11 18:50:03 +0000151 virtual void onAttachToCanvas(SkCanvas*) {
bsalomon@google.com405d0f42012-08-29 21:26:13 +0000152 SkASSERT(!fAttachedToCanvas);
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000153 this->lockPixels();
154#ifdef SK_DEBUG
155 fAttachedToCanvas = true;
156#endif
157 };
158
159 /**
160 * onDetachFromCanvas notifies a device that it will no longer be drawn to.
161 * It gives the device a chance to clean up (e.g., unlock its pixels). It
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000162 * is invoked from setDevice (for the displaced device), restore and
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000163 * possibly from SkCanvas' dtor.
164 */
165 virtual void onDetachFromCanvas() {
bsalomon@google.com405d0f42012-08-29 21:26:13 +0000166 SkASSERT(fAttachedToCanvas);
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000167 this->unlockPixels();
168#ifdef SK_DEBUG
169 fAttachedToCanvas = false;
170#endif
171 };
172
caryclark@google.comd53f7c22012-01-05 17:05:05 +0000173protected:
174 enum Usage {
175 kGeneral_Usage,
tomhudson@google.com1f902872012-06-01 13:15:47 +0000176 kSaveLayer_Usage // <! internal use only
caryclark@google.comd53f7c22012-01-05 17:05:05 +0000177 };
178
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000179 struct TextFlags {
180 uint32_t fFlags; // SkPaint::getFlags()
181 SkPaint::Hinting fHinting;
182 };
183
184 /**
185 * Device may filter the text flags for drawing text here. If it wants to
186 * make a change to the specified values, it should write them into the
187 * textflags parameter (output) and return true. If the paint is fine as
188 * is, then ignore the textflags parameter and return false.
189 *
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000190 * The baseclass SkBaseDevice filters based on its depth and blitters.
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000191 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000192 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000193
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000194 /**
bsalomon@google.coma6926b12012-10-10 15:25:50 +0000195 *
196 * DEPRECATED: This will be removed in a future change. Device subclasses
197 * should use the matrix and clip from the SkDraw passed to draw functions.
198 *
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000199 * Called with the correct matrix and clip before this device is drawn
200 * to using those settings. If your subclass overrides this, be sure to
201 * call through to the base class as well.
202 *
203 * The clipstack is another view of the clip. It records the actual
204 * geometry that went into building the region. It is present for devices
205 * that want to parse it, but is not required: the region is a complete
206 * picture of the current clip. (i.e. if you regionize all of the geometry
207 * in the clipstack, you will arrive at an equivalent region to the one
208 * passed in).
bsalomon@google.coma6926b12012-10-10 15:25:50 +0000209 */
210 virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000211 const SkClipStack&) {};
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000212
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000213 /** Clears the entire device to the specified color (including alpha).
214 * Ignores the clip.
reed@android.comf2b98d62010-12-20 18:26:13 +0000215 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000216 virtual void clear(SkColor color) = 0;
reed@android.comf2b98d62010-12-20 18:26:13 +0000217
tfarina@chromium.org62f10482014-01-15 00:19:21 +0000218 SK_ATTR_DEPRECATED("use clear() instead")
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000219 void eraseColor(SkColor eraseColor) { this->clear(eraseColor); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000220
221 /** These are called inside the per-device-layer loop for each draw call.
222 When these are called, we have already applied any saveLayer operations,
223 and are handling any looping from the paint, and any effects from the
224 DrawFilter.
225 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000226 virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000227 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000228 const SkPoint[], const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000229 virtual void drawRect(const SkDraw&, const SkRect& r,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000230 const SkPaint& paint) = 0;
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000231 virtual void drawOval(const SkDraw&, const SkRect& oval,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000232 const SkPaint& paint) = 0;
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000233 virtual void drawRRect(const SkDraw&, const SkRRect& rr,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000234 const SkPaint& paint) = 0;
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000235
reed@google.com7ff8d812011-03-25 15:08:16 +0000236 /**
237 * If pathIsMutable, then the implementation is allowed to cast path to a
238 * non-const pointer and modify it in place (as an optimization). Canvas
239 * may do this to implement helpers such as drawOval, by placing a temp
240 * path on the stack to hold the representation of the oval.
241 *
242 * If prePathMatrix is not null, it should logically be applied before any
243 * stroking or other effects. If there are no effects on the paint that
244 * affect the geometry/rasterization, then the pre matrix can just be
245 * pre-concated with the current matrix.
246 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000247 virtual void drawPath(const SkDraw&, const SkPath& path,
reed@android.comf2b98d62010-12-20 18:26:13 +0000248 const SkPaint& paint,
249 const SkMatrix* prePathMatrix = NULL,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000250 bool pathIsMutable = false) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000251 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000252 const SkMatrix& matrix, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000253 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000254 int x, int y, const SkPaint& paint) = 0;
reed@google.com33535f32012-09-25 15:37:50 +0000255
256 /**
257 * The default impl. will create a bitmap-shader from the bitmap,
258 * and call drawRect with it.
259 */
260 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
261 const SkRect* srcOrNull, const SkRect& dst,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000262 const SkPaint& paint,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000263 SkCanvas::DrawBitmapRectFlags flags) = 0;
reed@google.com33535f32012-09-25 15:37:50 +0000264
bungeman@google.com52c748b2011-08-22 21:30:43 +0000265 /**
266 * Does not handle text decoration.
267 * Decorations (underline and stike-thru) will be handled by SkCanvas.
268 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000269 virtual void drawText(const SkDraw&, const void* text, size_t len,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000270 SkScalar x, SkScalar y, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000271 virtual void drawPosText(const SkDraw&, const void* text, size_t len,
272 const SkScalar pos[], SkScalar constY,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000273 int scalarsPerPos, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000274 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
275 const SkPath& path, const SkMatrix* matrix,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000276 const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000277 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
278 const SkPoint verts[], const SkPoint texs[],
279 const SkColor colors[], SkXfermode* xmode,
280 const uint16_t indices[], int indexCount,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000281 const SkPaint& paint) = 0;
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000282 /** The SkDevice passed will be an SkDevice which was returned by a call to
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000283 onCreateCompatibleDevice on this device with kSaveLayer_Usage.
284 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000285 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
286 const SkPaint&) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000287
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000288 /**
289 * On success (returns true), copy the device pixels into the bitmap.
290 * On failure, the bitmap parameter is left unchanged and false is
291 * returned.
292 *
293 * The device's pixels are converted to the bitmap's config. The only
294 * supported config is kARGB_8888_Config, though this is likely to be
295 * relaxed in the future. The meaning of config kARGB_8888_Config is
296 * modified by the enum param config8888. The default value interprets
297 * kARGB_8888_Config as SkPMColor
298 *
299 * If the bitmap has pixels already allocated, the device pixels will be
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000300 * written there. If not, bitmap->allocPixels() will be called
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000301 * automatically. If the bitmap is backed by a texture readPixels will
302 * fail.
303 *
304 * The actual pixels written is the intersection of the device's bounds,
305 * and the rectangle formed by the bitmap's width,height and the specified
306 * x,y. If bitmap pixels extend outside of that intersection, they will not
307 * be modified.
308 *
309 * Other failure conditions:
310 * * If the device is not a raster device (e.g. PDF) then readPixels will
311 * fail.
312 * * If bitmap is texture-backed then readPixels will fail. (This may be
313 * relaxed in the future.)
314 */
315 bool readPixels(SkBitmap* bitmap,
316 int x, int y,
317 SkCanvas::Config8888 config8888);
318
reed@google.com3636ed52011-01-25 23:50:57 +0000319 ///////////////////////////////////////////////////////////////////////////
320
junov@chromium.org1f9767c2012-02-07 16:27:57 +0000321 /** Update as needed the pixel value in the bitmap, so that the caller can
skia.committer@gmail.com772c4e62013-08-30 07:01:34 +0000322 access the pixels directly.
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000323 @return The device contents as a bitmap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000324 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000325 virtual const SkBitmap& onAccessBitmap() = 0;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000326
bsalomon@google.comc6980972011-11-02 19:57:21 +0000327 /**
328 * Implements readPixels API. The caller will ensure that:
329 * 1. bitmap has pixel config kARGB_8888_Config.
330 * 2. bitmap has pixels.
331 * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
332 * contained in the device bounds.
bsalomon@google.comc6980972011-11-02 19:57:21 +0000333 */
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000334 virtual bool onReadPixels(const SkBitmap& bitmap,
335 int x, int y,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000336 SkCanvas::Config8888 config8888) = 0;
reed@android.comf2b98d62010-12-20 18:26:13 +0000337
robertphillips@google.com07f81a52013-09-17 12:26:23 +0000338 /** Called when this device is installed into a Canvas. Balanced by a call
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000339 to unlockPixels() when the device is removed from a Canvas.
340 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000341 virtual void lockPixels() = 0;
342 virtual void unlockPixels() = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000343
reed@google.com76dd2772012-01-05 21:15:07 +0000344 /**
reed@google.comb55deeb2012-01-06 14:43:09 +0000345 * Returns true if the device allows processing of this imagefilter. If
346 * false is returned, then the filter is ignored. This may happen for
347 * some subclasses that do not support pixel manipulations after drawing
348 * has occurred (e.g. printing). The default implementation returns true.
349 */
commit-bot@chromium.orgae761f72014-02-05 22:32:02 +0000350 virtual bool allowImageFilter(const SkImageFilter*) = 0;
reed@google.comb55deeb2012-01-06 14:43:09 +0000351
352 /**
reed@google.com8926b162012-03-23 15:36:36 +0000353 * Override and return true for filters that the device can handle
354 * intrinsically. Doing so means that SkCanvas will pass-through this
355 * filter to drawSprite and drawDevice (and potentially filterImage).
356 * Returning false means the SkCanvas will have apply the filter itself,
357 * and just pass the resulting image to the device.
reed@google.com76dd2772012-01-05 21:15:07 +0000358 */
commit-bot@chromium.orgae761f72014-02-05 22:32:02 +0000359 virtual bool canHandleImageFilter(const SkImageFilter*) = 0;
reed@google.com8926b162012-03-23 15:36:36 +0000360
361 /**
362 * Related (but not required) to canHandleImageFilter, this method returns
363 * true if the device could apply the filter to the src bitmap and return
364 * the result (and updates offset as needed).
365 * If the device does not recognize or support this filter,
366 * it just returns false and leaves result and offset unchanged.
367 */
commit-bot@chromium.orgae761f72014-02-05 22:32:02 +0000368 virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000369 SkBitmap* result, SkIPoint* offset) = 0;
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000370
371 // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
372 // either is identical to kNative_Premul_Config8888. Otherwise, -1.
373 static const SkCanvas::Config8888 kPMColorAlias;
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000374
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +0000375protected:
reed@google.com76f10a32014-02-05 15:32:21 +0000376 // default impl returns NULL
377 virtual SkSurface* newSurface(const SkImageInfo&);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000378
379 // default impl returns NULL
380 virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes);
381
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +0000382 /**
383 * Leaky properties are those which the device should be applying but it isn't.
384 * These properties will be applied by the draw, when and as it can.
385 * If the device does handle a property, that property should be set to the identity value
386 * for that property, effectively making it non-leaky.
387 */
388 SkDeviceProperties fLeakyProperties;
389
reed@android.com8a1c16f2008-12-17 15:59:43 +0000390private:
reed@google.com6f8f2922011-03-04 22:27:10 +0000391 friend class SkCanvas;
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000392 friend struct DeviceCM; //for setMatrixClip
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000393 friend class SkDraw;
394 friend class SkDrawIter;
395 friend class SkDeviceFilteredPaint;
senorblanco@chromium.org9c397442012-09-27 21:57:45 +0000396 friend class SkDeviceImageFilterProxy;
reed@google.com76f10a32014-02-05 15:32:21 +0000397 friend class DeferredDevice; // for newSurface
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000398
reed@google.com97af1a62012-08-28 12:19:02 +0000399 friend class SkSurface_Raster;
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000400
reed@google.com97af1a62012-08-28 12:19:02 +0000401 // used to change the backend's pixels (and possibly config/rowbytes)
402 // but cannot change the width/height, so there should be no change to
403 // any clip information.
reed@google.comec3ca872013-11-13 16:02:18 +0000404 // TODO: move to SkBitmapDevice
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000405 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) = 0;
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000406
407 // just called by SkCanvas when built as a layer
408 void setOrigin(int x, int y) { fOrigin.set(x, y); }
409 // just called by SkCanvas for saveLayer
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000410 SkBaseDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
411 int width, int height,
412 bool isOpaque);
reed@google.com6f8f2922011-03-04 22:27:10 +0000413
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000414 /**
415 * Subclasses should override this to implement createCompatibleDevice.
416 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000417 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
418 int width, int height,
419 bool isOpaque,
420 Usage usage) = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000421
422 /** Causes any deferred drawing to the device to be completed.
423 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000424 virtual void flush() = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000425
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000426 SkIPoint fOrigin;
427 SkMetaData* fMetaData;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +0000428
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000429#ifdef SK_DEBUG
430 bool fAttachedToCanvas;
431#endif
432
433 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000434};
435
reed@android.com8a1c16f2008-12-17 15:59:43 +0000436#endif