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

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
« no previous file with comments | « include/core/SkBitmapDevice.h ('k') | include/core/SkDevice.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
187 * local RAM) return the address of those pixels, and if not null,
188 * return the ImageInfo and rowBytes. The returned address is only valid
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
181 * local RAM) return the const-address of those pixels, and if not null, 201 * local RAM) return the const-address of those pixels, and if not null,
182 * return the ImageInfo and rowBytes. The returned address is only valid 202 * 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 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);
(...skipping 972 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 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); 1204 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
1182 1205
1183 enum ClipEdgeStyle { 1206 enum ClipEdgeStyle {
1184 kHard_ClipEdgeStyle, 1207 kHard_ClipEdgeStyle,
1185 kSoft_ClipEdgeStyle 1208 kSoft_ClipEdgeStyle
1186 }; 1209 };
1187 1210
1188 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e dgeStyle); 1211 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e dgeStyle);
1189 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl e edgeStyle); 1212 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl e edgeStyle);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; } 1259 SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
1237 void setSurfaceBase(SkSurface_Base* sb) { 1260 void setSurfaceBase(SkSurface_Base* sb) {
1238 fSurfaceBase = sb; 1261 fSurfaceBase = sb;
1239 } 1262 }
1240 friend class SkSurface_Base; 1263 friend class SkSurface_Base;
1241 friend class SkSurface_Gpu; 1264 friend class SkSurface_Gpu;
1242 1265
1243 bool fDeviceCMDirty; // cleared by updateDeviceCMCache() 1266 bool fDeviceCMDirty; // cleared by updateDeviceCMCache()
1244 void updateDeviceCMCache(); 1267 void updateDeviceCMCache();
1245 1268
1246 friend class SkDrawIter; // needs setupDrawForLayerDevice() 1269 friend class SkDrawIter; // needs setupDrawForLayerDevice()
1247 friend class AutoDrawLooper; 1270 friend class AutoDrawLooper;
1248 friend class SkLua; // needs top layer size and offset 1271 friend class SkLua; // needs top layer size and offset
1272 friend class SkDeferredDevice; // needs getTopDevice()
1249 1273
1250 SkBaseDevice* createLayerDevice(const SkImageInfo&); 1274 SkBaseDevice* createLayerDevice(const SkImageInfo&);
1251 1275
1252 SkBaseDevice* init(SkBaseDevice*); 1276 SkBaseDevice* init(SkBaseDevice*);
1253 1277
1254 /** 1278 /**
1255 * DEPRECATED 1279 * DEPRECATED
1256 * 1280 *
1257 * Specify a device for this canvas to draw into. If it is not null, its 1281 * Specify a device for this canvas to draw into. If it is not null, its
1258 * reference count is incremented. If the canvas was already holding a 1282 * reference count is incremented. If the canvas was already holding a
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 bool asROBitmap(SkBitmap*) const; 1447 bool asROBitmap(SkBitmap*) const;
1424 1448
1425 private: 1449 private:
1426 SkBitmap fBitmap; // used if peekPixels() fails 1450 SkBitmap fBitmap; // used if peekPixels() fails
1427 const void* fAddr; // NULL on failure 1451 const void* fAddr; // NULL on failure
1428 SkImageInfo fInfo; 1452 SkImageInfo fInfo;
1429 size_t fRowBytes; 1453 size_t fRowBytes;
1430 }; 1454 };
1431 1455
1432 #endif 1456 #endif
OLDNEW
« no previous file with comments | « include/core/SkBitmapDevice.h ('k') | include/core/SkDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698