Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: include/core/SkCanvas.h

Issue 197433002: support direct writing to top layer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkCanvas_DEFINED 8 #ifndef SkCanvas_DEFINED
9 #define SkCanvas_DEFINED 9 #define SkCanvas_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 #include "SkBitmap.h" 12 #include "SkBitmap.h"
13 #include "SkDeque.h" 13 #include "SkDeque.h"
14 #include "SkClipStack.h" 14 #include "SkClipStack.h"
15 #include "SkPaint.h" 15 #include "SkPaint.h"
16 #include "SkRefCnt.h" 16 #include "SkRefCnt.h"
17 #include "SkPath.h" 17 #include "SkPath.h"
18 #include "SkRegion.h" 18 #include "SkRegion.h"
19 #include "SkXfermode.h" 19 #include "SkXfermode.h"
20 20
21 // if not defined, we always assume ClipToLayer for saveLayer() 21 // if not defined, we always assume ClipToLayer for saveLayer()
22 //#define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 22 //#define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
23 23
24 24
25 //#define SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG 25 //#define SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
26 //#define SK_SUPPORT_LEGACY_GETCLIPTYPE 26 //#define SK_SUPPORT_LEGACY_GETCLIPTYPE
27 //#define SK_SUPPORT_LEGACY_GETTOTALCLIP 27 //#define SK_SUPPORT_LEGACY_GETTOTALCLIP
28 //#define SK_SUPPORT_LEGACY_GETTOPDEVICE
28 29
29 class SkBounder; 30 class SkBounder;
30 class SkBaseDevice; 31 class SkBaseDevice;
31 class SkDraw; 32 class SkDraw;
32 class SkDrawFilter; 33 class SkDrawFilter;
33 class SkMetaData; 34 class SkMetaData;
34 class SkPicture; 35 class SkPicture;
35 class SkRRect; 36 class SkRRect;
36 class SkSurface; 37 class SkSurface;
37 class SkSurface_Base; 38 class SkSurface_Base;
38 class GrContext; 39 class GrContext;
40 class GrRenderTarget;
39 41
40 /** \class SkCanvas 42 /** \class SkCanvas
41 43
42 A Canvas encapsulates all of the state about drawing into a device (bitmap). 44 A Canvas encapsulates all of the state about drawing into a device (bitmap).
43 This includes a reference to the device itself, and a stack of matrix/clip 45 This includes a reference to the device itself, and a stack of matrix/clip
44 values. For any given draw call (e.g. drawRect), the geometry of the object 46 values. For any given draw call (e.g. drawRect), the geometry of the object
45 being drawn is transformed by the concatenation of all the matrices in the 47 being drawn is transformed by the concatenation of all the matrices in the
46 stack. The transformed geometry is clipped by the intersection of all of 48 stack. The transformed geometry is clipped by the intersection of all of
47 the clips in the stack. 49 the clips in the stack.
48 50
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 * installed. Note that this can change on other calls like save/restore, 154 * installed. Note that this can change on other calls like save/restore,
153 * so do not access this device after subsequent canvas calls. 155 * so do not access this device after subsequent canvas calls.
154 * The reference count of the device is not changed. 156 * The reference count of the device is not changed.
155 * 157 *
156 * @param updateMatrixClip If this is true, then before the device is 158 * @param updateMatrixClip If this is true, then before the device is
157 * returned, we ensure that its has been notified about the current 159 * returned, we ensure that its has been notified about the current
158 * matrix and clip. Note: this happens automatically when the device 160 * matrix and clip. Note: this happens automatically when the device
159 * is drawn to, but is optional here, as there is a small perf hit 161 * is drawn to, but is optional here, as there is a small perf hit
160 * sometimes. 162 * sometimes.
161 */ 163 */
164 #ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
165 private:
166 #endif
162 SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const; 167 SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
168 public:
163 169
164 /** 170 /**
165 * Create a new surface matching the specified info, one that attempts to 171 * Create a new surface matching the specified info, one that attempts to
166 * be maximally compatible when used with this canvas. 172 * be maximally compatible when used with this canvas.
167 */ 173 */
168 SkSurface* newSurface(const SkImageInfo&); 174 SkSurface* newSurface(const SkImageInfo&);
169 175
170 /** 176 /**
171 * Return the GPU context of the device that is associated with the canvas. 177 * Return the GPU context of the device that is associated with the canvas.
172 * For a canvas with non-GPU device, NULL is returned. 178 * For a canvas with non-GPU device, NULL is returned.
173 */ 179 */
174 GrContext* getGrContext(); 180 GrContext* getGrContext();
175 181
176 /////////////////////////////////////////////////////////////////////////// 182 ///////////////////////////////////////////////////////////////////////////
177 183
178 /** 184 /**
179 * If the canvas has pixels (and is not recording to a picture or other 185 * If the canvas has writable pixels in its top layer (and is not recording to a picture
180 * non-raster target) and has direct access to its pixels (i.e. they are in 186 * or other non-raster target) and has direct access to its pixels (i.e. th ey are in
181 * local RAM) return the const-address of those pixels, and if not null, 187 * local RAM) return the const-address of those pixels, and if not null,
bsalomon 2014/03/12 14:43:11 This comment should be updated to indicate that th
reed1 2014/03/12 15:31:59 Done.
182 * return the ImageInfo and rowBytes. The returned address is only valid 188 * return the ImageInfo and rowBytes. The returned address is only valid
183 * while the canvas object is in scope and unchanged. Any API calls made on 189 * while the canvas object is in scope and unchanged. Any API calls made on
190 * canvas (or its parent surface if any) will invalidate the
191 * returned address (and associated information).
192 *
193 * On failure, returns NULL and the info and rowBytes parameters are
194 * ignored.
195 */
196 void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes);
197
198 /**
199 * If the canvas has readable pixels in its base layer (and is not recordin g to a picture
200 * or other non-raster target) and has direct access to its pixels (i.e. th ey are in
201 * local RAM) return the const-address of those pixels, and if not null,
202 * return the ImageInfo and rowBytes. The returned address is only valid
203 * while the canvas object is in scope and unchanged. Any API calls made on
184 * canvas (or its parent surface if any) will invalidate the 204 * canvas (or its parent surface if any) will invalidate the
185 * returned address (and associated information). 205 * returned address (and associated information).
186 * 206 *
187 * On failure, returns NULL and the info and rowBytes parameters are 207 * On failure, returns NULL and the info and rowBytes parameters are
188 * ignored. 208 * ignored.
189 */ 209 */
190 const void* peekPixels(SkImageInfo* info, size_t* rowBytes); 210 const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
191 211
192 /** 212 /**
193 * This enum can be used with read/writePixels to perform a pixel ops to or 213 * This enum can be used with read/writePixels to perform a pixel ops to or
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 intptr_t fStorage[32]; 1183 intptr_t fStorage[32];
1164 class SkDrawIter* fImpl; // this points at fStorage 1184 class SkDrawIter* fImpl; // this points at fStorage
1165 SkPaint fDefaultPaint; 1185 SkPaint fDefaultPaint;
1166 bool fDone; 1186 bool fDone;
1167 }; 1187 };
1168 1188
1169 // don't call 1189 // don't call
1170 const SkRegion& internal_private_getTotalClip() const; 1190 const SkRegion& internal_private_getTotalClip() const;
1171 // don't call 1191 // don't call
1172 void internal_private_getTotalClipAsPath(SkPath*) const; 1192 void internal_private_getTotalClipAsPath(SkPath*) const;
1193 // don't call
1194 GrRenderTarget* internal_private_accessTopLayerRenderTarget();
1173 1195
1174 protected: 1196 protected:
1175 // default impl defers to getDevice()->newSurface(info) 1197 // default impl defers to getDevice()->newSurface(info)
1176 virtual SkSurface* onNewSurface(const SkImageInfo&); 1198 virtual SkSurface* onNewSurface(const SkImageInfo&);
1177 1199
1178 // default impl defers to its device 1200 // default impl defers to its device
1179 virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); 1201 virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes);
1202 virtual void* onAccessTopLayerPixels(SkImageInfo*, size_t* rowBytes);
1180 1203
1181 // Subclass save/restore notifiers. These are called *before* updating the c anvas state. 1204 // Subclass save/restore notifiers. These are called *before* updating the c anvas state.
1182 // Overriders should call the corresponding INHERITED method up the inherita nce chain. 1205 // Overriders should call the corresponding INHERITED method up the inherita nce chain.
1183 // For onSaveLayer(), returning false suppresses full layer allocation (and forces 1206 // For onSaveLayer(), returning false suppresses full layer allocation (and forces
1184 // the base impl to only perform a state save + bounds clip). 1207 // the base impl to only perform a state save + bounds clip).
1185 virtual void onSave(SaveFlags); 1208 virtual void onSave(SaveFlags);
1186 virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags); 1209 virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags);
1187 virtual void onRestore(); 1210 virtual void onRestore();
1188 1211
1189 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); 1212 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; } 1267 SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
1245 void setSurfaceBase(SkSurface_Base* sb) { 1268 void setSurfaceBase(SkSurface_Base* sb) {
1246 fSurfaceBase = sb; 1269 fSurfaceBase = sb;
1247 } 1270 }
1248 friend class SkSurface_Base; 1271 friend class SkSurface_Base;
1249 friend class SkSurface_Gpu; 1272 friend class SkSurface_Gpu;
1250 1273
1251 bool fDeviceCMDirty; // cleared by updateDeviceCMCache() 1274 bool fDeviceCMDirty; // cleared by updateDeviceCMCache()
1252 void updateDeviceCMCache(); 1275 void updateDeviceCMCache();
1253 1276
1254 friend class SkDrawIter; // needs setupDrawForLayerDevice() 1277 friend class SkDrawIter; // needs setupDrawForLayerDevice()
1255 friend class AutoDrawLooper; 1278 friend class AutoDrawLooper;
1256 friend class SkLua; // needs top layer size and offset 1279 friend class SkLua; // needs top layer size and offset
1280 friend class SkDeferredDevice; // needs getTopDevice()
1257 1281
1258 SkBaseDevice* createLayerDevice(const SkImageInfo&); 1282 SkBaseDevice* createLayerDevice(const SkImageInfo&);
1259 1283
1260 SkBaseDevice* init(SkBaseDevice*); 1284 SkBaseDevice* init(SkBaseDevice*);
1261 1285
1262 /** 1286 /**
1263 * DEPRECATED 1287 * DEPRECATED
1264 * 1288 *
1265 * Specify a device for this canvas to draw into. If it is not null, its 1289 * Specify a device for this canvas to draw into. If it is not null, its
1266 * reference count is incremented. If the canvas was already holding a 1290 * reference count is incremented. If the canvas was already holding a
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 bool asROBitmap(SkBitmap*) const; 1455 bool asROBitmap(SkBitmap*) const;
1432 1456
1433 private: 1457 private:
1434 SkBitmap fBitmap; // used if peekPixels() fails 1458 SkBitmap fBitmap; // used if peekPixels() fails
1435 const void* fAddr; // NULL on failure 1459 const void* fAddr; // NULL on failure
1436 SkImageInfo fInfo; 1460 SkImageInfo fInfo;
1437 size_t fRowBytes; 1461 size_t fRowBytes;
1438 }; 1462 };
1439 1463
1440 #endif 1464 #endif
OLDNEW
« no previous file with comments | « include/core/SkBitmapDevice.h ('k') | include/core/SkDevice.h » ('j') | src/core/SkCanvas.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698