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

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

Issue 163823002: Revert of 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
85 /////////////////////////////////////////////////////////////////////////// 79 ///////////////////////////////////////////////////////////////////////////
86 80
87 /** 81 /**
88 * Trigger the immediate execution of all pending draw operations. 82 * Trigger the immediate execution of all pending draw operations.
89 */ 83 */
90 void flush(); 84 void flush();
91 85
92 /** 86 /**
93 * DEPRECATED: call imageInfo() instead.
94 * Return the width/height of the underlying device. The current drawable 87 * Return the width/height of the underlying device. The current drawable
95 * area may be small (due to clipping or saveLayer). For a canvas with 88 * area may be small (due to clipping or saveLayer). For a canvas with
96 * no device, 0,0 will be returned. 89 * no device, 0,0 will be returned.
97 */ 90 */
98 SkISize getDeviceSize() const; 91 SkISize getDeviceSize() const;
99 92
100 /** 93 /** Return the canvas' device object, which may be null. The device holds
101 * DEPRECATED. 94 the bitmap of the pixels that the canvas draws into. The reference count
102 * Return the canvas' device object, which may be null. The device holds 95 of the returned device is not changed by this call.
103 * the bitmap of the pixels that the canvas draws into. The reference count 96 */
104 * of the returned device is not changed by this call.
105 */
106 SkBaseDevice* getDevice() const; 97 SkBaseDevice* getDevice() const;
107 98
108 /** 99 /**
109 * saveLayer() can create another device (which is later drawn onto 100 * saveLayer() can create another device (which is later drawn onto
110 * the previous device). getTopDevice() returns the top-most device current 101 * the previous device). getTopDevice() returns the top-most device current
111 * installed. Note that this can change on other calls like save/restore, 102 * installed. Note that this can change on other calls like save/restore,
112 * so do not access this device after subsequent canvas calls. 103 * so do not access this device after subsequent canvas calls.
113 * The reference count of the device is not changed. 104 * The reference count of the device is not changed.
114 * 105 *
115 * @param updateMatrixClip If this is true, then before the device is 106 * @param updateMatrixClip If this is true, then before the device is
(...skipping 12 matching lines...) Expand all
128 119
129 /** 120 /**
130 * Return the GPU context of the device that is associated with the canvas. 121 * Return the GPU context of the device that is associated with the canvas.
131 * For a canvas with non-GPU device, NULL is returned. 122 * For a canvas with non-GPU device, NULL is returned.
132 */ 123 */
133 GrContext* getGrContext(); 124 GrContext* getGrContext();
134 125
135 /////////////////////////////////////////////////////////////////////////// 126 ///////////////////////////////////////////////////////////////////////////
136 127
137 /** 128 /**
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 /**
152 * This enum can be used with read/writePixels to perform a pixel ops to or 129 * This enum can be used with read/writePixels to perform a pixel ops to or
153 * from an 8888 config other than Skia's native config (SkPMColor). There 130 * from an 8888 config other than Skia's native config (SkPMColor). There
154 * are three byte orders supported: native, BGRA, and RGBA. Each has a 131 * are three byte orders supported: native, BGRA, and RGBA. Each has a
155 * premultiplied and unpremultiplied variant. 132 * premultiplied and unpremultiplied variant.
156 * 133 *
157 * Components of a 8888 pixel can be packed/unpacked from a 32bit word using 134 * Components of a 8888 pixel can be packed/unpacked from a 32bit word using
158 * either byte offsets or shift values. Byte offsets are endian-invariant 135 * either byte offsets or shift values. Byte offsets are endian-invariant
159 * while shifts are not. BGRA and RGBA configs are defined by byte 136 * while shifts are not. BGRA and RGBA configs are defined by byte
160 * orderings. The native config is defined by shift values (SK_A32_SHIFT, 137 * orderings. The native config is defined by shift values (SK_A32_SHIFT,
161 * ..., SK_B32_SHIFT). 138 * ..., SK_B32_SHIFT).
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 intptr_t fStorage[32]; 1012 intptr_t fStorage[32];
1036 class SkDrawIter* fImpl; // this points at fStorage 1013 class SkDrawIter* fImpl; // this points at fStorage
1037 SkPaint fDefaultPaint; 1014 SkPaint fDefaultPaint;
1038 bool fDone; 1015 bool fDone;
1039 }; 1016 };
1040 1017
1041 protected: 1018 protected:
1042 // default impl defers to getDevice()->newSurface(info) 1019 // default impl defers to getDevice()->newSurface(info)
1043 virtual SkSurface* onNewSurface(const SkImageInfo&); 1020 virtual SkSurface* onNewSurface(const SkImageInfo&);
1044 1021
1045 // default impl defers to its device
1046 virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes);
1047
1048 // Returns the canvas to be used by DrawIter. Default implementation 1022 // Returns the canvas to be used by DrawIter. Default implementation
1049 // returns this. Subclasses that encapsulate an indirect canvas may 1023 // returns this. Subclasses that encapsulate an indirect canvas may
1050 // need to overload this method. The impl must keep track of this, as it 1024 // need to overload this method. The impl must keep track of this, as it
1051 // is not released or deleted by the caller. 1025 // is not released or deleted by the caller.
1052 virtual SkCanvas* canvasForDrawIter(); 1026 virtual SkCanvas* canvasForDrawIter();
1053 1027
1054 // Clip rectangle bounds. Called internally by saveLayer. 1028 // Clip rectangle bounds. Called internally by saveLayer.
1055 // returns false if the entire rectangle is entirely clipped out 1029 // returns false if the entire rectangle is entirely clipped out
1056 // If non-NULL, The imageFilter parameter will be used to expand the clip 1030 // If non-NULL, The imageFilter parameter will be used to expand the clip
1057 // and offscreen bounds for any margin required by the filter DAG. 1031 // and offscreen bounds for any margin required by the filter DAG.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 if (NULL != fCanvas) { 1199 if (NULL != fCanvas) {
1226 fCanvas->endCommentGroup(); 1200 fCanvas->endCommentGroup();
1227 } 1201 }
1228 } 1202 }
1229 1203
1230 private: 1204 private:
1231 SkCanvas* fCanvas; 1205 SkCanvas* fCanvas;
1232 }; 1206 };
1233 #define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock) 1207 #define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock)
1234 1208
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
1278 #endif 1209 #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