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

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

Issue 1662353002: Add SkAutoPixmapStorage::detachPixelsAsData() (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: detachPixelsAsData Created 4 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
« no previous file with comments | « no previous file | src/core/SkPixmap.cpp » ('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 2015 Google Inc. 2 * Copyright 2015 Google Inc.
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 SkPixmap_DEFINED 8 #ifndef SkPixmap_DEFINED
9 #define SkPixmap_DEFINED 9 #define SkPixmap_DEFINED
10 10
11 #include "SkColor.h" 11 #include "SkColor.h"
12 #include "SkFilterQuality.h" 12 #include "SkFilterQuality.h"
13 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
14 14
15 class SkColorTable; 15 class SkColorTable;
16 class SkData;
16 struct SkMask; 17 struct SkMask;
17 18
18 /** 19 /**
19 * Pairs SkImageInfo with actual pixels and rowbytes. This class does not try t o manage the 20 * Pairs SkImageInfo with actual pixels and rowbytes. This class does not try t o manage the
20 * lifetime of the pixel memory (nor the colortable if provided). 21 * lifetime of the pixel memory (nor the colortable if provided).
21 */ 22 */
22 class SK_API SkPixmap { 23 class SK_API SkPixmap {
23 public: 24 public:
24 SkPixmap() 25 SkPixmap()
25 : fPixels(NULL), fCTable(NULL), fRowBytes(0), fInfo(SkImageInfo::MakeUnk nown(0, 0)) 26 : fPixels(NULL), fCTable(NULL), fRowBytes(0), fInfo(SkImageInfo::MakeUnk nown(0, 0))
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 178
178 /** 179 /**
179 * Allocate memory for the pixels needed to match the specified Info and fi ll out the pixmap 180 * Allocate memory for the pixels needed to match the specified Info and fi ll out the pixmap
180 * to point to that memory. The storage will be freed when this object is d estroyed, 181 * to point to that memory. The storage will be freed when this object is d estroyed,
181 * or if another call to tryAlloc() or alloc() is made. 182 * or if another call to tryAlloc() or alloc() is made.
182 * 183 *
183 * If the memory cannot be allocated, calls sk_throw(). 184 * If the memory cannot be allocated, calls sk_throw().
184 */ 185 */
185 void alloc(const SkImageInfo&); 186 void alloc(const SkImageInfo&);
186 187
188 /**
189 * Returns an SkData object wrapping the allocated pixels memory, and reset s the pixmap.
190 * If the storage hasn't been allocated, the result is NULL.
191 */
192 const SkData* SK_WARN_UNUSED_RESULT detachPixelsAsData();
193
187 // We wrap these so we can clear our internal storage 194 // We wrap these so we can clear our internal storage
188 195
189 void reset() { 196 void reset() {
190 this->freeStorage(); 197 this->freeStorage();
191 this->INHERITED::reset(); 198 this->INHERITED::reset();
192 } 199 }
193 void reset(const SkImageInfo& info, const void* addr, size_t rb, SkColorTabl e* ctable = NULL) { 200 void reset(const SkImageInfo& info, const void* addr, size_t rb, SkColorTabl e* ctable = NULL) {
194 this->freeStorage(); 201 this->freeStorage();
195 this->INHERITED::reset(info, addr, rb, ctable); 202 this->INHERITED::reset(info, addr, rb, ctable);
196 } 203 }
197 void reset(const SkImageInfo& info) { 204 void reset(const SkImageInfo& info) {
198 this->freeStorage(); 205 this->freeStorage();
199 this->INHERITED::reset(info); 206 this->INHERITED::reset(info);
200 } 207 }
201 bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask) { 208 bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask) {
202 this->freeStorage(); 209 this->freeStorage();
203 return this->INHERITED::reset(mask); 210 return this->INHERITED::reset(mask);
204 } 211 }
205 212
206 private: 213 private:
207 void* fStorage; 214 void* fStorage;
208 215
209 void freeStorage() { 216 void freeStorage() {
210 sk_free(fStorage); 217 sk_free(fStorage);
211 fStorage = NULL; 218 fStorage = nullptr;
212 } 219 }
213 220
214 typedef SkPixmap INHERITED; 221 typedef SkPixmap INHERITED;
215 }; 222 };
216 223
217 //////////////////////////////////////////////////////////////////////////////// ///////////// 224 //////////////////////////////////////////////////////////////////////////////// /////////////
218 225
219 class SK_API SkAutoPixmapUnlock : ::SkNoncopyable { 226 class SK_API SkAutoPixmapUnlock : ::SkNoncopyable {
220 public: 227 public:
221 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} 228 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {}
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 private: 263 private:
257 void (*fUnlockProc)(void*); 264 void (*fUnlockProc)(void*);
258 void* fUnlockContext; 265 void* fUnlockContext;
259 SkPixmap fPixmap; 266 SkPixmap fPixmap;
260 bool fIsLocked; 267 bool fIsLocked;
261 268
262 friend class SkBitmap; 269 friend class SkBitmap;
263 }; 270 };
264 271
265 #endif 272 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPixmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698