blob: 8a219d7053b0cd662fcb6fa03ba64b908be199f1 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkDevice_DEFINED
9#define SkDevice_DEFINED
10
11#include "SkRefCnt.h"
12#include "SkBitmap.h"
13#include "SkCanvas.h"
14#include "SkColor.h"
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +000015#include "SkImageFilter.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000016
reed@google.com46799cd2011-02-22 20:56:26 +000017class SkClipStack;
reed@android.com8a1c16f2008-12-17 15:59:43 +000018class SkDraw;
fmalita024f9962015-03-03 19:08:17 -080019class SkDrawFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000020struct SkIRect;
21class SkMatrix;
reed@google.coma7d94852011-03-30 21:23:07 +000022class SkMetaData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000023class SkRegion;
reede010f1c2014-09-17 10:49:38 -070024struct SkDeviceProperties;
commit-bot@chromium.orgb8d00db2013-06-26 19:18:23 +000025class GrRenderTarget;
bsalomon@google.comd9f826c2011-07-18 15:25:04 +000026
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000027class SK_API SkBaseDevice : public SkRefCnt {
reed@android.com8a1c16f2008-12-17 15:59:43 +000028public:
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000029 SK_DECLARE_INST_COUNT(SkBaseDevice)
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000030
reed@google.comaf951c92011-06-16 19:10:39 +000031 /**
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000032 * Construct a new device.
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000034 SkBaseDevice();
reedb2db8982014-11-13 12:41:02 -080035 explicit SkBaseDevice(const SkDeviceProperties&);
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000036 virtual ~SkBaseDevice();
reed@android.com8a1c16f2008-12-17 15:59:43 +000037
bungeman@google.com88edf1e2011-08-08 19:41:56 +000038 SkMetaData& getMetaData();
39
reed@google.comd51bfa02011-08-30 15:56:11 +000040 /**
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000041 * Return ImageInfo for this device. If the canvas is not backed by pixels
42 * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
43 */
44 virtual SkImageInfo imageInfo() const;
45
46 /**
reed@google.comd51bfa02011-08-30 15:56:11 +000047 * Return the bounds of the device in the coordinate space of the root
48 * canvas. The root device will have its top-left at 0,0, but other devices
49 * such as those associated with saveLayer may have a non-zero origin.
50 */
reed@google.comec3ca872013-11-13 16:02:18 +000051 void getGlobalBounds(SkIRect* bounds) const {
52 SkASSERT(bounds);
53 const SkIPoint& origin = this->getOrigin();
54 bounds->setXYWH(origin.x(), origin.y(), this->width(), this->height());
55 }
skia.committer@gmail.com73a5d532013-11-14 07:02:31 +000056
reed78e27682014-11-19 08:04:34 -080057 SkIRect getGlobalBounds() const {
58 SkIRect bounds;
59 this->getGlobalBounds(&bounds);
60 return bounds;
61 }
62
reedf252f642014-06-14 04:24:56 -070063 int width() const {
64 return this->imageInfo().width();
65 }
reed620fc602014-07-07 13:51:48 -070066
reedf252f642014-06-14 04:24:56 -070067 int height() const {
68 return this->imageInfo().height();
69 }
reed620fc602014-07-07 13:51:48 -070070
reedf252f642014-06-14 04:24:56 -070071 bool isOpaque() const {
72 return this->imageInfo().isOpaque();
73 }
skia.committer@gmail.com772c4e62013-08-30 07:01:34 +000074
reed@android.com8a1c16f2008-12-17 15:59:43 +000075 /** Return the bitmap associated with this device. Call this each time you need
76 to access the bitmap, as it notifies the subclass to perform any flushing
77 etc. before you examine the pixels.
78 @param changePixels set to true if the caller plans to change the pixels
79 @return the device's bitmap
80 */
81 const SkBitmap& accessBitmap(bool changePixels);
82
commit-bot@chromium.org4ef54f82014-03-17 17:03:18 +000083 bool writePixels(const SkImageInfo&, const void*, size_t rowBytes, int x, int y);
reed@android.com8a1c16f2008-12-17 15:59:43 +000084
reed@google.com9c135db2014-03-12 18:28:35 +000085 void* accessPixels(SkImageInfo* info, size_t* rowBytes);
86
bsalomon@google.comd9f826c2011-07-18 15:25:04 +000087 /**
88 * Return the device's associated gpu render target, or NULL.
reed@android.comf2b98d62010-12-20 18:26:13 +000089 */
reed89443ab2014-06-27 11:34:19 -070090 virtual GrRenderTarget* accessRenderTarget() { return NULL; }
reed@android.comf2b98d62010-12-20 18:26:13 +000091
bungeman@google.com88edf1e2011-08-08 19:41:56 +000092
93 /**
94 * Return the device's origin: its offset in device coordinates from
95 * the default origin in its canvas' matrix/clip
96 */
97 const SkIPoint& getOrigin() const { return fOrigin; }
98
rmistry@google.comfbfcd562012-08-23 18:09:54 +000099 /**
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000100 * onAttachToCanvas is invoked whenever a device is installed in a canvas
101 * (i.e., setDevice, saveLayer (for the new device created by the save),
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000102 * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000103 * devices to prepare for drawing (e.g., locking their pixels, etc.)
104 */
sugoi@google.come0e385c2013-03-11 18:50:03 +0000105 virtual void onAttachToCanvas(SkCanvas*) {
bsalomon@google.com405d0f42012-08-29 21:26:13 +0000106 SkASSERT(!fAttachedToCanvas);
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000107 this->lockPixels();
108#ifdef SK_DEBUG
109 fAttachedToCanvas = true;
110#endif
111 };
112
113 /**
114 * onDetachFromCanvas notifies a device that it will no longer be drawn to.
115 * It gives the device a chance to clean up (e.g., unlock its pixels). It
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000116 * is invoked from setDevice (for the displaced device), restore and
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000117 * possibly from SkCanvas' dtor.
118 */
119 virtual void onDetachFromCanvas() {
bsalomon@google.com405d0f42012-08-29 21:26:13 +0000120 SkASSERT(fAttachedToCanvas);
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000121 this->unlockPixels();
122#ifdef SK_DEBUG
123 fAttachedToCanvas = false;
124#endif
125 };
126
caryclark@google.comd53f7c22012-01-05 17:05:05 +0000127protected:
reed76033be2015-03-14 10:54:31 -0700128 enum TileUsage {
129 kPossible_TileUsage, //!< the created device may be drawn tiled
130 kNever_TileUsage, //!< the created device will never be drawn tiled
caryclark@google.comd53f7c22012-01-05 17:05:05 +0000131 };
132
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000133 struct TextFlags {
reed3375c802014-09-16 12:27:55 -0700134 uint32_t fFlags; // SkPaint::getFlags()
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000135 };
136
fmalita112e7e22014-11-13 14:05:58 -0800137 /**
138 * Returns the text-related flags, possibly modified based on the state of the
139 * device (e.g. support for LCD).
140 */
141 uint32_t filterTextFlags(const SkPaint&) const;
142
reedb2db8982014-11-13 12:41:02 -0800143 virtual bool onShouldDisableLCD(const SkPaint&) const { return false; }
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000144
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000145 /**
bsalomon@google.coma6926b12012-10-10 15:25:50 +0000146 *
147 * DEPRECATED: This will be removed in a future change. Device subclasses
148 * should use the matrix and clip from the SkDraw passed to draw functions.
149 *
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000150 * Called with the correct matrix and clip before this device is drawn
151 * to using those settings. If your subclass overrides this, be sure to
152 * call through to the base class as well.
153 *
154 * The clipstack is another view of the clip. It records the actual
155 * geometry that went into building the region. It is present for devices
156 * that want to parse it, but is not required: the region is a complete
157 * picture of the current clip. (i.e. if you regionize all of the geometry
158 * in the clipstack, you will arrive at an equivalent region to the one
159 * passed in).
bsalomon@google.coma6926b12012-10-10 15:25:50 +0000160 */
161 virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000162 const SkClipStack&) {};
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000163
reed@android.com8a1c16f2008-12-17 15:59:43 +0000164 /** These are called inside the per-device-layer loop for each draw call.
165 When these are called, we have already applied any saveLayer operations,
166 and are handling any looping from the paint, and any effects from the
167 DrawFilter.
168 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000169 virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000170 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000171 const SkPoint[], const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000172 virtual void drawRect(const SkDraw&, const SkRect& r,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000173 const SkPaint& paint) = 0;
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000174 virtual void drawOval(const SkDraw&, const SkRect& oval,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000175 const SkPaint& paint) = 0;
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000176 virtual void drawRRect(const SkDraw&, const SkRRect& rr,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000177 const SkPaint& paint) = 0;
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000178
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +0000179 // Default impl calls drawPath()
180 virtual void drawDRRect(const SkDraw&, const SkRRect& outer,
181 const SkRRect& inner, const SkPaint&);
182
reed@google.com7ff8d812011-03-25 15:08:16 +0000183 /**
184 * If pathIsMutable, then the implementation is allowed to cast path to a
185 * non-const pointer and modify it in place (as an optimization). Canvas
186 * may do this to implement helpers such as drawOval, by placing a temp
187 * path on the stack to hold the representation of the oval.
188 *
189 * If prePathMatrix is not null, it should logically be applied before any
190 * stroking or other effects. If there are no effects on the paint that
191 * affect the geometry/rasterization, then the pre matrix can just be
192 * pre-concated with the current matrix.
193 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000194 virtual void drawPath(const SkDraw&, const SkPath& path,
reed@android.comf2b98d62010-12-20 18:26:13 +0000195 const SkPaint& paint,
196 const SkMatrix* prePathMatrix = NULL,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000197 bool pathIsMutable = false) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000198 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000199 const SkMatrix& matrix, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000200 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000201 int x, int y, const SkPaint& paint) = 0;
reed@google.com33535f32012-09-25 15:37:50 +0000202
203 /**
204 * The default impl. will create a bitmap-shader from the bitmap,
205 * and call drawRect with it.
206 */
207 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
208 const SkRect* srcOrNull, const SkRect& dst,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000209 const SkPaint& paint,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000210 SkCanvas::DrawBitmapRectFlags flags) = 0;
reed@google.com33535f32012-09-25 15:37:50 +0000211
bungeman@google.com52c748b2011-08-22 21:30:43 +0000212 /**
213 * Does not handle text decoration.
214 * Decorations (underline and stike-thru) will be handled by SkCanvas.
215 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000216 virtual void drawText(const SkDraw&, const void* text, size_t len,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000217 SkScalar x, SkScalar y, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000218 virtual void drawPosText(const SkDraw&, const void* text, size_t len,
fmalita05c4a432014-09-29 06:29:53 -0700219 const SkScalar pos[], int scalarsPerPos,
220 const SkPoint& offset, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000221 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
222 const SkPoint verts[], const SkPoint texs[],
223 const SkColor colors[], SkXfermode* xmode,
224 const uint16_t indices[], int indexCount,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000225 const SkPaint& paint) = 0;
fmalitaaa1b9122014-08-28 14:32:24 -0700226 // default implementation unrolls the blob runs.
227 virtual void drawTextBlob(const SkDraw&, const SkTextBlob*, SkScalar x, SkScalar y,
fmalita024f9962015-03-03 19:08:17 -0800228 const SkPaint& paint, SkDrawFilter* drawFilter);
dandovecfff212014-08-04 10:02:00 -0700229 // default implementation calls drawVertices
dandovb3c9d1c2014-08-12 08:34:29 -0700230 virtual void drawPatch(const SkDraw&, const SkPoint cubics[12], const SkColor colors[4],
231 const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000232 /** The SkDevice passed will be an SkDevice which was returned by a call to
reed76033be2015-03-14 10:54:31 -0700233 onCreateDevice on this device with kNeverTile_TileExpectation.
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000234 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000235 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
236 const SkPaint&) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000237
reedf87fe782015-02-17 10:33:54 -0800238 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, const SkPath&,
239 const SkMatrix*, const SkPaint&);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000240 bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y);
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000241
reed@google.com3636ed52011-01-25 23:50:57 +0000242 ///////////////////////////////////////////////////////////////////////////
243
junov@chromium.org1f9767c2012-02-07 16:27:57 +0000244 /** Update as needed the pixel value in the bitmap, so that the caller can
skia.committer@gmail.com772c4e62013-08-30 07:01:34 +0000245 access the pixels directly.
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000246 @return The device contents as a bitmap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000247 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000248 virtual const SkBitmap& onAccessBitmap() = 0;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000249
robertphillips@google.com07f81a52013-09-17 12:26:23 +0000250 /** Called when this device is installed into a Canvas. Balanced by a call
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000251 to unlockPixels() when the device is removed from a Canvas.
252 */
reed89443ab2014-06-27 11:34:19 -0700253 virtual void lockPixels() {}
254 virtual void unlockPixels() {}
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000255
reed@google.com76dd2772012-01-05 21:15:07 +0000256 /**
reed@google.com8926b162012-03-23 15:36:36 +0000257 * Override and return true for filters that the device can handle
258 * intrinsically. Doing so means that SkCanvas will pass-through this
259 * filter to drawSprite and drawDevice (and potentially filterImage).
260 * Returning false means the SkCanvas will have apply the filter itself,
261 * and just pass the resulting image to the device.
reed@google.com76dd2772012-01-05 21:15:07 +0000262 */
reed89443ab2014-06-27 11:34:19 -0700263 virtual bool canHandleImageFilter(const SkImageFilter*) { return false; }
reed@google.com8926b162012-03-23 15:36:36 +0000264
265 /**
266 * Related (but not required) to canHandleImageFilter, this method returns
267 * true if the device could apply the filter to the src bitmap and return
268 * the result (and updates offset as needed).
269 * If the device does not recognize or support this filter,
270 * it just returns false and leaves result and offset unchanged.
271 */
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +0000272 virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
djsollenc87dd2c2014-11-14 11:11:46 -0800273 const SkImageFilter::Context&,
274 SkBitmap* /*result*/, SkIPoint* /*offset*/) {
reed89443ab2014-06-27 11:34:19 -0700275 return false;
276 }
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000277
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +0000278protected:
reed@google.com76f10a32014-02-05 15:32:21 +0000279 // default impl returns NULL
reed4a8126e2014-09-22 07:29:03 -0700280 virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&);
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000281
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000282 // default impl returns NULL
283 virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes);
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +0000284
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +0000285 /**
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000286 * The caller is responsible for "pre-clipping" the dst. The impl can assume that the dst
287 * image at the specified x,y offset will fit within the device's bounds.
288 *
289 * This is explicitly asserted in readPixels(), the public way to call this.
290 */
291 virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y);
commit-bot@chromium.org2cccf832014-03-12 03:04:08 +0000292
293 /**
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000294 * The caller is responsible for "pre-clipping" the src. The impl can assume that the src
295 * image at the specified x,y offset will fit within the device's bounds.
296 *
297 * This is explicitly asserted in writePixelsDirect(), the public way to call this.
298 */
299 virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y);
300
301 /**
reed@google.com9c135db2014-03-12 18:28:35 +0000302 * Default impl returns NULL.
303 */
304 virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes);
305
306 /**
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +0000307 * Leaky properties are those which the device should be applying but it isn't.
308 * These properties will be applied by the draw, when and as it can.
309 * If the device does handle a property, that property should be set to the identity value
310 * for that property, effectively making it non-leaky.
311 */
reede010f1c2014-09-17 10:49:38 -0700312 const SkDeviceProperties& getLeakyProperties() const {
313 return *fLeakyProperties;
314 }
commit-bot@chromium.org8128d8c2013-12-19 16:12:25 +0000315
commit-bot@chromium.org145d1c02014-03-16 19:46:36 +0000316 /**
317 * PRIVATE / EXPERIMENTAL -- do not call
commit-bot@chromium.org145d1c02014-03-16 19:46:36 +0000318 * This entry point gives the backend an opportunity to take over the rendering
319 * of 'picture'. If optimization data is available (due to an earlier
320 * 'optimize' call) this entry point should make use of it and return true
321 * if all rendering has been done. If false is returned, SkCanvas will
skia.committer@gmail.comeb849e52014-03-17 03:02:17 +0000322 * perform its own rendering pass. It is acceptable for the backend
commit-bot@chromium.org145d1c02014-03-16 19:46:36 +0000323 * to perform some device-specific warm up tasks and then let SkCanvas
324 * perform the main rendering loop (by return false from here).
325 */
reedd5fa1a42014-08-09 11:08:05 -0700326 virtual bool EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const SkMatrix*,
327 const SkPaint*);
commit-bot@chromium.org145d1c02014-03-16 19:46:36 +0000328
fmalita6987dca2014-11-13 08:33:37 -0800329 struct CreateInfo {
reed76033be2015-03-14 10:54:31 -0700330 static SkPixelGeometry AdjustGeometry(const SkImageInfo&, TileUsage, SkPixelGeometry);
fmalita6987dca2014-11-13 08:33:37 -0800331
reed76033be2015-03-14 10:54:31 -0700332 // The constructor may change the pixel geometry based on other parameters.
halcanary00b7e5e2015-04-15 13:05:18 -0700333 CreateInfo(const SkImageInfo& info,
334 TileUsage tileUsage,
335 SkPixelGeometry geo,
336 bool forImageFilter = false)
reedb2db8982014-11-13 12:41:02 -0800337 : fInfo(info)
reed76033be2015-03-14 10:54:31 -0700338 , fTileUsage(tileUsage)
339 , fPixelGeometry(AdjustGeometry(info, tileUsage, geo))
halcanary00b7e5e2015-04-15 13:05:18 -0700340 , fForImageFilter(forImageFilter) {}
reedb2db8982014-11-13 12:41:02 -0800341
reed76033be2015-03-14 10:54:31 -0700342 const SkImageInfo fInfo;
343 const TileUsage fTileUsage;
344 const SkPixelGeometry fPixelGeometry;
halcanary00b7e5e2015-04-15 13:05:18 -0700345 const bool fForImageFilter;
fmalita6987dca2014-11-13 08:33:37 -0800346 };
reedb2db8982014-11-13 12:41:02 -0800347
reed76033be2015-03-14 10:54:31 -0700348 /**
349 * Create a new device based on CreateInfo. If the paint is not null, then it represents a
350 * preview of how the new device will be composed with its creator device (this).
reed61f501f2015-04-29 08:34:00 -0700351 *
352 * The subclass may be handed this device in drawDevice(), so it must always return
353 * a device that it knows how to draw, and that it knows how to identify if it is not of the
354 * same subclass (since drawDevice is passed a SkBaseDevice*). If the subclass cannot fulfill
355 * that contract (e.g. PDF cannot support some settings on the paint) it should return NULL,
356 * and the caller may then decide to explicitly create a bitmapdevice, knowing that later
357 * it could not call drawDevice with it (but it could call drawSprite or drawBitmap).
reed76033be2015-03-14 10:54:31 -0700358 */
reed57a48a72015-03-14 04:30:21 -0700359 virtual SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) {
360 return NULL;
361 }
362
reedb2db8982014-11-13 12:41:02 -0800363 virtual void initForRootLayer(SkPixelGeometry geo);
364
reed@android.com8a1c16f2008-12-17 15:59:43 +0000365private:
reed@google.com6f8f2922011-03-04 22:27:10 +0000366 friend class SkCanvas;
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000367 friend struct DeviceCM; //for setMatrixClip
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000368 friend class SkDraw;
369 friend class SkDrawIter;
370 friend class SkDeviceFilteredPaint;
senorblanco@chromium.org9c397442012-09-27 21:57:45 +0000371 friend class SkDeviceImageFilterProxy;
reed@google.com9c135db2014-03-12 18:28:35 +0000372 friend class SkDeferredDevice; // for newSurface
reed78e27682014-11-19 08:04:34 -0800373 friend class SkNoPixelsBitmapDevice;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000374
reed@google.com97af1a62012-08-28 12:19:02 +0000375 friend class SkSurface_Raster;
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000376
reed@google.com97af1a62012-08-28 12:19:02 +0000377 // used to change the backend's pixels (and possibly config/rowbytes)
378 // but cannot change the width/height, so there should be no change to
379 // any clip information.
reed@google.comec3ca872013-11-13 16:02:18 +0000380 // TODO: move to SkBitmapDevice
reed89443ab2014-06-27 11:34:19 -0700381 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) {}
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000382
reedd9544982014-09-09 18:46:22 -0700383 virtual bool forceConservativeRasterClip() const { return false; }
384
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000385 // just called by SkCanvas when built as a layer
386 void setOrigin(int x, int y) { fOrigin.set(x, y); }
reed@google.com6f8f2922011-03-04 22:27:10 +0000387
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000388 /** Causes any deferred drawing to the device to be completed.
389 */
reed89443ab2014-06-27 11:34:19 -0700390 virtual void flush() {}
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000391
senorblancobe129b22014-08-08 07:14:35 -0700392 virtual SkImageFilter::Cache* getImageFilterCache() { return NULL; }
senorblanco55b6d8b2014-07-30 11:26:46 -0700393
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000394 SkIPoint fOrigin;
395 SkMetaData* fMetaData;
reede010f1c2014-09-17 10:49:38 -0700396 SkDeviceProperties* fLeakyProperties; // will always exist.
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +0000397
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000398#ifdef SK_DEBUG
399 bool fAttachedToCanvas;
400#endif
401
402 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000403};
404
reed@android.com8a1c16f2008-12-17 15:59:43 +0000405#endif