OLD | NEW |
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 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 private: | 181 private: |
182 const void* fPixels; | 182 const void* fPixels; |
183 SkColorTable* fCTable; | 183 SkColorTable* fCTable; |
184 size_t fRowBytes; | 184 size_t fRowBytes; |
185 SkImageInfo fInfo; | 185 SkImageInfo fInfo; |
186 }; | 186 }; |
187 | 187 |
188 ////////////////////////////////////////////////////////////////////////////////
///////////// | 188 ////////////////////////////////////////////////////////////////////////////////
///////////// |
189 | 189 |
| 190 class SK_API SkAutoPixmapStorage : public SkPixmap { |
| 191 public: |
| 192 SkAutoPixmapStorage(); |
| 193 ~SkAutoPixmapStorage(); |
| 194 |
| 195 /** |
| 196 * Try to allocate memory for the pixels needed to match the specified Info
. On success |
| 197 * return true and fill out the pixmap to point to that memory. The storage
will be freed |
| 198 * when this object is destroyed, or if another call to tryAlloc() or alloc
() is made. |
| 199 * |
| 200 * On failure, return false and reset() the pixmap to empty. |
| 201 */ |
| 202 bool tryAlloc(const SkImageInfo&); |
| 203 |
| 204 /** |
| 205 * Allocate memory for the pixels needed to match the specified Info and fi
ll out the pixmap |
| 206 * to point to that memory. The storage will be freed when this object is d
estroyed, |
| 207 * or if another call to tryAlloc() or alloc() is made. |
| 208 * |
| 209 * If the memory cannot be allocated, calls sk_throw(). |
| 210 */ |
| 211 void alloc(const SkImageInfo&); |
| 212 |
| 213 /** |
| 214 * Gets the size and optionally the rowBytes that would be allocated by SkAu
toPixmapStorage if |
| 215 * alloc/tryAlloc was called. |
| 216 */ |
| 217 static size_t AllocSize(const SkImageInfo& info, size_t* rowBytes); |
| 218 |
| 219 /** |
| 220 * Returns an SkData object wrapping the allocated pixels memory, and reset
s the pixmap. |
| 221 * If the storage hasn't been allocated, the result is NULL. |
| 222 */ |
| 223 const SkData* SK_WARN_UNUSED_RESULT detachPixelsAsData(); |
| 224 |
| 225 // We wrap these so we can clear our internal storage |
| 226 |
| 227 void reset() { |
| 228 this->freeStorage(); |
| 229 this->INHERITED::reset(); |
| 230 } |
| 231 void reset(const SkImageInfo& info, const void* addr, size_t rb, SkColorTabl
e* ctable = NULL) { |
| 232 this->freeStorage(); |
| 233 this->INHERITED::reset(info, addr, rb, ctable); |
| 234 } |
| 235 void reset(const SkImageInfo& info) { |
| 236 this->freeStorage(); |
| 237 this->INHERITED::reset(info); |
| 238 } |
| 239 bool SK_WARN_UNUSED_RESULT reset(const SkMask& mask) { |
| 240 this->freeStorage(); |
| 241 return this->INHERITED::reset(mask); |
| 242 } |
| 243 |
| 244 private: |
| 245 void* fStorage; |
| 246 |
| 247 void freeStorage() { |
| 248 sk_free(fStorage); |
| 249 fStorage = nullptr; |
| 250 } |
| 251 |
| 252 typedef SkPixmap INHERITED; |
| 253 }; |
| 254 |
190 ////////////////////////////////////////////////////////////////////////////////
///////////// | 255 ////////////////////////////////////////////////////////////////////////////////
///////////// |
191 | 256 |
192 class SK_API SkAutoPixmapUnlock : ::SkNoncopyable { | 257 class SK_API SkAutoPixmapUnlock : ::SkNoncopyable { |
193 public: | 258 public: |
194 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} | 259 SkAutoPixmapUnlock() : fUnlockProc(NULL), fIsLocked(false) {} |
195 SkAutoPixmapUnlock(const SkPixmap& pm, void (*unlock)(void*), void* ctx) | 260 SkAutoPixmapUnlock(const SkPixmap& pm, void (*unlock)(void*), void* ctx) |
196 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm), fIsLocked(true) | 261 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm), fIsLocked(true) |
197 {} | 262 {} |
198 ~SkAutoPixmapUnlock() { this->unlock(); } | 263 ~SkAutoPixmapUnlock() { this->unlock(); } |
199 | 264 |
(...skipping 29 matching lines...) Expand all Loading... |
229 private: | 294 private: |
230 void (*fUnlockProc)(void*); | 295 void (*fUnlockProc)(void*); |
231 void* fUnlockContext; | 296 void* fUnlockContext; |
232 SkPixmap fPixmap; | 297 SkPixmap fPixmap; |
233 bool fIsLocked; | 298 bool fIsLocked; |
234 | 299 |
235 friend class SkBitmap; | 300 friend class SkBitmap; |
236 }; | 301 }; |
237 | 302 |
238 #endif | 303 #endif |
OLD | NEW |