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

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

Issue 163603003: add peekPixels to SkCanvas and SkSurface (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 /** Construct a canvas with the specified bitmap to draw into. 70 /** Construct a canvas with the specified bitmap to draw into.
71 @param bitmap Specifies a bitmap for the canvas to draw into. Its 71 @param bitmap Specifies a bitmap for the canvas to draw into. Its
72 structure are copied to the canvas. 72 structure are copied to the canvas.
73 */ 73 */
74 explicit SkCanvas(const SkBitmap& bitmap); 74 explicit SkCanvas(const SkBitmap& bitmap);
75 virtual ~SkCanvas(); 75 virtual ~SkCanvas();
76 76
77 SkMetaData& getMetaData(); 77 SkMetaData& getMetaData();
78 78
79 /**
80 * Return ImageInfo for this canvas. If the canvas is not backed by pixels
81 * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
82 */
83 SkImageInfo imageInfo() const;
84
79 /////////////////////////////////////////////////////////////////////////// 85 ///////////////////////////////////////////////////////////////////////////
80 86
81 /** 87 /**
82 * Trigger the immediate execution of all pending draw operations. 88 * Trigger the immediate execution of all pending draw operations.
83 */ 89 */
84 void flush(); 90 void flush();
85 91
86 /** 92 /**
93 * DEPRECATED: call imageInfo() instead.
87 * Return the width/height of the underlying device. The current drawable 94 * Return the width/height of the underlying device. The current drawable
88 * area may be small (due to clipping or saveLayer). For a canvas with 95 * area may be small (due to clipping or saveLayer). For a canvas with
89 * no device, 0,0 will be returned. 96 * no device, 0,0 will be returned.
90 */ 97 */
91 SkISize getDeviceSize() const; 98 SkISize getDeviceSize() const;
92 99
93 /** Return the canvas' device object, which may be null. The device holds 100 /**
94 the bitmap of the pixels that the canvas draws into. The reference count 101 * DEPRECATED.
95 of the returned device is not changed by this call. 102 * Return the canvas' device object, which may be null. The device holds
96 */ 103 * the bitmap of the pixels that the canvas draws into. The reference count
104 * of the returned device is not changed by this call.
105 */
97 SkBaseDevice* getDevice() const; 106 SkBaseDevice* getDevice() const;
98 107
99 /** 108 /**
100 * saveLayer() can create another device (which is later drawn onto 109 * saveLayer() can create another device (which is later drawn onto
101 * the previous device). getTopDevice() returns the top-most device current 110 * the previous device). getTopDevice() returns the top-most device current
102 * installed. Note that this can change on other calls like save/restore, 111 * installed. Note that this can change on other calls like save/restore,
103 * so do not access this device after subsequent canvas calls. 112 * so do not access this device after subsequent canvas calls.
104 * The reference count of the device is not changed. 113 * The reference count of the device is not changed.
105 * 114 *
106 * @param updateMatrixClip If this is true, then before the device is 115 * @param updateMatrixClip If this is true, then before the device is
(...skipping 12 matching lines...) Expand all
119 128
120 /** 129 /**
121 * Return the GPU context of the device that is associated with the canvas. 130 * Return the GPU context of the device that is associated with the canvas.
122 * For a canvas with non-GPU device, NULL is returned. 131 * For a canvas with non-GPU device, NULL is returned.
123 */ 132 */
124 GrContext* getGrContext(); 133 GrContext* getGrContext();
125 134
126 /////////////////////////////////////////////////////////////////////////// 135 ///////////////////////////////////////////////////////////////////////////
127 136
128 /** 137 /**
138 * If the canvas has pixels (and is not recording to a picture or other
139 * non-raster target) and has direct access to its pixels (i.e. they are in
140 * local RAM) return the const-address of those pixels, and if not null,
141 * return the ImageInfo and rowBytes. The returned address is only valid
142 * while the canvas object is in scope and unchanged. Any API calls made on
143 * canvas (or its parent surface if any) will invalidate the
144 * returned address (and associated information).
145 *
146 * On failure, returns NULL and the info and rowBytes parameters are
147 * ignored.
148 */
149 const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
150
151 /**
129 * This enum can be used with read/writePixels to perform a pixel ops to or 152 * This enum can be used with read/writePixels to perform a pixel ops to or
130 * from an 8888 config other than Skia's native config (SkPMColor). There 153 * from an 8888 config other than Skia's native config (SkPMColor). There
131 * are three byte orders supported: native, BGRA, and RGBA. Each has a 154 * are three byte orders supported: native, BGRA, and RGBA. Each has a
132 * premultiplied and unpremultiplied variant. 155 * premultiplied and unpremultiplied variant.
133 * 156 *
134 * Components of a 8888 pixel can be packed/unpacked from a 32bit word using 157 * Components of a 8888 pixel can be packed/unpacked from a 32bit word using
135 * either byte offsets or shift values. Byte offsets are endian-invariant 158 * either byte offsets or shift values. Byte offsets are endian-invariant
136 * while shifts are not. BGRA and RGBA configs are defined by byte 159 * while shifts are not. BGRA and RGBA configs are defined by byte
137 * orderings. The native config is defined by shift values (SK_A32_SHIFT, 160 * orderings. The native config is defined by shift values (SK_A32_SHIFT,
138 * ..., SK_B32_SHIFT). 161 * ..., SK_B32_SHIFT).
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 intptr_t fStorage[32]; 1035 intptr_t fStorage[32];
1013 class SkDrawIter* fImpl; // this points at fStorage 1036 class SkDrawIter* fImpl; // this points at fStorage
1014 SkPaint fDefaultPaint; 1037 SkPaint fDefaultPaint;
1015 bool fDone; 1038 bool fDone;
1016 }; 1039 };
1017 1040
1018 protected: 1041 protected:
1019 // default impl defers to getDevice()->newSurface(info) 1042 // default impl defers to getDevice()->newSurface(info)
1020 virtual SkSurface* onNewSurface(const SkImageInfo&); 1043 virtual SkSurface* onNewSurface(const SkImageInfo&);
1021 1044
1045 // default impl defers to its device
1046 virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes);
1047
1022 // Returns the canvas to be used by DrawIter. Default implementation 1048 // Returns the canvas to be used by DrawIter. Default implementation
1023 // returns this. Subclasses that encapsulate an indirect canvas may 1049 // returns this. Subclasses that encapsulate an indirect canvas may
1024 // need to overload this method. The impl must keep track of this, as it 1050 // need to overload this method. The impl must keep track of this, as it
1025 // is not released or deleted by the caller. 1051 // is not released or deleted by the caller.
1026 virtual SkCanvas* canvasForDrawIter(); 1052 virtual SkCanvas* canvasForDrawIter();
1027 1053
1028 // Clip rectangle bounds. Called internally by saveLayer. 1054 // Clip rectangle bounds. Called internally by saveLayer.
1029 // returns false if the entire rectangle is entirely clipped out 1055 // returns false if the entire rectangle is entirely clipped out
1030 // If non-NULL, The imageFilter parameter will be used to expand the clip 1056 // If non-NULL, The imageFilter parameter will be used to expand the clip
1031 // and offscreen bounds for any margin required by the filter DAG. 1057 // and offscreen bounds for any margin required by the filter DAG.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 if (NULL != fCanvas) { 1225 if (NULL != fCanvas) {
1200 fCanvas->endCommentGroup(); 1226 fCanvas->endCommentGroup();
1201 } 1227 }
1202 } 1228 }
1203 1229
1204 private: 1230 private:
1205 SkCanvas* fCanvas; 1231 SkCanvas* fCanvas;
1206 }; 1232 };
1207 #define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock) 1233 #define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock)
1208 1234
1235 /**
1236 * If the caller wants read-only access to the pixels in a canvas, it can just
1237 * call canvas->peekPixels(), since that is the fastest way to "peek" at the
1238 * pixels on a raster-backed canvas.
1239 *
1240 * If the canvas has pixels, but they are not readily available to the CPU
1241 * (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will
1242 * succeed (though be slower, since it will return a copy of the pixels).
1243 *
1244 * SkAutoROCanvasPixels encapsulates these two techniques, trying first to call
1245 * peekPixels() (for performance), but if that fails, calling readPixels() and
1246 * storing the copy locally.
1247 *
1248 * The caller must respect the restrictions associated with peekPixels(), since
1249 * that may have been called: The returned information is invalidated if...
1250 * - any API is called on the canvas (or its parent surface if present)
1251 * - the canvas goes out of scope
1252 */
1253 class SkAutoROCanvasPixels : SkNoncopyable {
1254 public:
1255 SkAutoROCanvasPixels(SkCanvas* canvas);
1256
1257 // returns NULL on failure
1258 const void* addr() const { return fAddr; }
1259
1260 // undefined if addr() == NULL
1261 size_t rowBytes() const { return fRowBytes; }
1262
1263 // undefined if addr() == NULL
1264 const SkImageInfo& info() const { return fInfo; }
1265
1266 // helper that, if returns true, installs the pixels into the bitmap. Note
1267 // that the bitmap may reference the address returned by peekPixels(), so
1268 // the caller must respect the restrictions associated with peekPixels().
1269 bool asROBitmap(SkBitmap*) const;
1270
1271 private:
1272 SkBitmap fBitmap; // used if peekPixels() fails
1273 const void* fAddr; // NULL on failure
1274 SkImageInfo fInfo;
1275 size_t fRowBytes;
1276 };
1277
1209 #endif 1278 #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