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

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

Issue 1074983003: add SkPixmap and external locking to bitmaps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The Android Open Source Project 2 * Copyright 2008 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 SkPixelRef_DEFINED 8 #ifndef SkPixelRef_DEFINED
9 #define SkPixelRef_DEFINED 9 #define SkPixelRef_DEFINED
10 10
11 #include "SkAtomics.h" 11 #include "SkAtomics.h"
12 #include "SkBitmap.h" 12 #include "SkBitmap.h"
13 #include "SkFilterQuality.h"
13 #include "SkImageInfo.h" 14 #include "SkImageInfo.h"
14 #include "SkMutex.h" 15 #include "SkMutex.h"
16 #include "SkPixmap.h"
15 #include "SkRefCnt.h" 17 #include "SkRefCnt.h"
16 #include "SkSize.h" 18 #include "SkSize.h"
17 #include "SkString.h" 19 #include "SkString.h"
18 #include "SkTDArray.h" 20 #include "SkTDArray.h"
19 21
20 //#define xed
21
22 #ifdef SK_DEBUG 22 #ifdef SK_DEBUG
23 /** 23 /**
24 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref 24 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref
25 * subclasses to correctly handle lock/unlock pixels. For performance 25 * subclasses to correctly handle lock/unlock pixels. For performance
26 * reasons, simple malloc-based subclasses call setPreLocked() to skip 26 * reasons, simple malloc-based subclasses call setPreLocked() to skip
27 * the overhead of implementing these calls. 27 * the overhead of implementing these calls.
28 * 28 *
29 * This build-flag disables that optimization, to add in debugging our 29 * This build-flag disables that optimization, to add in debugging our
30 * call-sites, to ensure that they correctly balance their calls of 30 * call-sites, to ensure that they correctly balance their calls of
31 * lock and unlock. 31 * lock and unlock.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 * return a ref to its data. If the pixelRef 186 * return a ref to its data. If the pixelRef
187 * is uncompressed or otherwise does not have this form, return NULL. 187 * is uncompressed or otherwise does not have this form, return NULL.
188 * 188 *
189 * If non-null is returned, the caller is responsible for calling unref() 189 * If non-null is returned, the caller is responsible for calling unref()
190 * on the data when it is finished. 190 * on the data when it is finished.
191 */ 191 */
192 SkData* refEncodedData() { 192 SkData* refEncodedData() {
193 return this->onRefEncodedData(); 193 return this->onRefEncodedData();
194 } 194 }
195 195
196 struct LockRequest {
197 SkISize fSize;
198 SkFilterQuality fQuality;
199 };
200
201 struct LockResult {
202 void (*fUnlockProc)(void* ctx);
203 void* fUnlockContext;
204
205 SkColorTable* fCTable; // should be NULL unless colortype is kIndex8
206 const void* fPixels;
207 size_t fRowBytes;
208 SkISize fSize;
209
210 void unlock() {
211 if (fUnlockProc) {
212 fUnlockProc(fUnlockContext);
213 fUnlockProc = NULL; // can't unlock twice!
214 }
215 }
216 };
217
218 bool requestLock(const LockRequest&, LockResult*);
219
196 /** Are we really wrapping a texture instead of a bitmap? 220 /** Are we really wrapping a texture instead of a bitmap?
197 */ 221 */
198 virtual GrTexture* getTexture() { return NULL; } 222 virtual GrTexture* getTexture() { return NULL; }
199 223
200 /** 224 /**
201 * If any planes or rowBytes is NULL, this should output the sizes and retu rn true 225 * If any planes or rowBytes is NULL, this should output the sizes and retu rn true
202 * if it can efficiently return YUV planar data. If it cannot, it should re turn false. 226 * if it can efficiently return YUV planar data. If it cannot, it should re turn false.
203 * 227 *
204 * If all planes and rowBytes are not NULL, then it should copy the associa ted Y,U,V data 228 * If all planes and rowBytes are not NULL, then it should copy the associa ted Y,U,V data
205 * into those planes of memory supplied by the caller. It should validate t hat the sizes 229 * into those planes of memory supplied by the caller. It should validate t hat the sizes
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 /** 316 /**
293 * Returns the size (in bytes) of the internally allocated memory. 317 * Returns the size (in bytes) of the internally allocated memory.
294 * This should be implemented in all serializable SkPixelRef derived classe s. 318 * This should be implemented in all serializable SkPixelRef derived classe s.
295 * SkBitmap::fPixelRefOffset + SkBitmap::getSafeSize() should never overflo w this value, 319 * SkBitmap::fPixelRefOffset + SkBitmap::getSafeSize() should never overflo w this value,
296 * otherwise the rendering code may attempt to read memory out of bounds. 320 * otherwise the rendering code may attempt to read memory out of bounds.
297 * 321 *
298 * @return default impl returns 0. 322 * @return default impl returns 0.
299 */ 323 */
300 virtual size_t getAllocatedSizeInBytes() const; 324 virtual size_t getAllocatedSizeInBytes() const;
301 325
326 virtual bool onRequestLock(const LockRequest&, LockResult*);
327
302 /** Return the mutex associated with this pixelref. This value is assigned 328 /** Return the mutex associated with this pixelref. This value is assigned
303 in the constructor, and cannot change during the lifetime of the object. 329 in the constructor, and cannot change during the lifetime of the object.
304 */ 330 */
305 SkBaseMutex* mutex() const { return fMutex; } 331 SkBaseMutex* mutex() const { return fMutex; }
306 332
307 // only call from constructor. Flags this to always be locked, removing 333 // only call from constructor. Flags this to always be locked, removing
308 // the need to grab the mutex and call onLockPixels/onUnlockPixels. 334 // the need to grab the mutex and call onLockPixels/onUnlockPixels.
309 // Performance tweak to avoid those calls (esp. in multi-thread use case). 335 // Performance tweak to avoid those calls (esp. in multi-thread use case).
310 void setPreLocked(void*, size_t rowBytes, SkColorTable*); 336 void setPreLocked(void*, size_t rowBytes, SkColorTable*);
311 337
312 private: 338 private:
313 SkBaseMutex* fMutex; // must remain in scope for the life of this object 339 SkBaseMutex* fMutex; // must remain in scope for the life of this object
314 340
315 // mostly const. fInfo.fAlpahType can be changed at runtime. 341 // mostly const. fInfo.fAlpahType can be changed at runtime.
316 const SkImageInfo fInfo; 342 const SkImageInfo fInfo;
317 343
318 // LockRec is only valid if we're in a locked state (isLocked()) 344 // LockRec is only valid if we're in a locked state (isLocked())
319 LockRec fRec; 345 LockRec fRec;
320 int fLockCount; 346 int fLockCount;
321 347
348 bool lockPixelsInsideMutex(LockRec* rec);
349
322 // Bottom bit indicates the Gen ID is unique. 350 // Bottom bit indicates the Gen ID is unique.
323 bool genIDIsUnique() const { return SkToBool(fTaggedGenID.load() & 1); } 351 bool genIDIsUnique() const { return SkToBool(fTaggedGenID.load() & 1); }
324 mutable SkAtomic<uint32_t> fTaggedGenID; 352 mutable SkAtomic<uint32_t> fTaggedGenID;
325 353
326 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 354 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
327 const uint32_t fStableID; 355 const uint32_t fStableID;
328 #endif 356 #endif
329 357
330 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne d 358 SkTDArray<GenIDChangeListener*> fGenIDChangeListeners; // pointers are owne d
331 359
(...skipping 24 matching lines...) Expand all
356 /** 384 /**
357 * Allocate a new pixelref matching the specified ImageInfo, allocating 385 * Allocate a new pixelref matching the specified ImageInfo, allocating
358 * the memory for the pixels. If the ImageInfo requires a ColorTable, 386 * the memory for the pixels. If the ImageInfo requires a ColorTable,
359 * the pixelref will ref() the colortable. 387 * the pixelref will ref() the colortable.
360 * On failure return NULL. 388 * On failure return NULL.
361 */ 389 */
362 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable *) = 0; 390 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable *) = 0;
363 }; 391 };
364 392
365 #endif 393 #endif
OLDNEW
« no previous file with comments | « include/core/SkImageInfo.h ('k') | include/core/SkPixmap.h » ('j') | include/core/SkPixmap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698