OLD | NEW |
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 "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkDynamicAnnotations.h" | 12 #include "SkDynamicAnnotations.h" |
13 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
14 #include "SkString.h" | 14 #include "SkString.h" |
15 #include "SkFlattenable.h" | |
16 #include "SkImageInfo.h" | 15 #include "SkImageInfo.h" |
17 #include "SkTDArray.h" | 16 #include "SkTDArray.h" |
18 | 17 |
19 //#define xed | 18 //#define xed |
20 | 19 |
21 #ifdef SK_DEBUG | 20 #ifdef SK_DEBUG |
22 /** | 21 /** |
23 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref | 22 * Defining SK_IGNORE_PIXELREF_SETPRELOCKED will force all pixelref |
24 * subclasses to correctly handle lock/unlock pixels. For performance | 23 * subclasses to correctly handle lock/unlock pixels. For performance |
25 * reasons, simple malloc-based subclasses call setPreLocked() to skip | 24 * reasons, simple malloc-based subclasses call setPreLocked() to skip |
26 * the overhead of implementing these calls. | 25 * the overhead of implementing these calls. |
27 * | 26 * |
28 * This build-flag disables that optimization, to add in debugging our | 27 * This build-flag disables that optimization, to add in debugging our |
29 * call-sites, to ensure that they correctly balance their calls of | 28 * call-sites, to ensure that they correctly balance their calls of |
30 * lock and unlock. | 29 * lock and unlock. |
31 */ | 30 */ |
32 // #define SK_IGNORE_PIXELREF_SETPRELOCKED | 31 // #define SK_IGNORE_PIXELREF_SETPRELOCKED |
33 #endif | 32 #endif |
34 | 33 |
35 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE | |
36 // we only support unflattening, not flattening | |
37 #define SK_PIXELREF_BASECLASS SkFlattenable | |
38 #else | |
39 #define SK_PIXELREF_BASECLASS SkRefCnt | |
40 #endif | |
41 | |
42 class SkColorTable; | 34 class SkColorTable; |
43 class SkData; | 35 class SkData; |
44 struct SkIRect; | 36 struct SkIRect; |
45 class SkMutex; | 37 class SkMutex; |
46 | 38 |
47 class GrTexture; | 39 class GrTexture; |
48 | 40 |
49 /** \class SkPixelRef | 41 /** \class SkPixelRef |
50 | 42 |
51 This class is the smart container for pixel memory, and is used with | 43 This class is the smart container for pixel memory, and is used with |
52 SkBitmap. A pixelref is installed into a bitmap, and then the bitmap can | 44 SkBitmap. A pixelref is installed into a bitmap, and then the bitmap can |
53 access the actual pixel memory by calling lockPixels/unlockPixels. | 45 access the actual pixel memory by calling lockPixels/unlockPixels. |
54 | 46 |
55 This class can be shared/accessed between multiple threads. | 47 This class can be shared/accessed between multiple threads. |
56 */ | 48 */ |
57 class SK_API SkPixelRef : public SK_PIXELREF_BASECLASS { | 49 class SK_API SkPixelRef : public SkRefCnt { |
58 public: | 50 public: |
59 SK_DECLARE_INST_COUNT(SkPixelRef) | 51 SK_DECLARE_INST_COUNT(SkPixelRef) |
60 | 52 |
61 explicit SkPixelRef(const SkImageInfo&); | 53 explicit SkPixelRef(const SkImageInfo&); |
62 SkPixelRef(const SkImageInfo&, SkBaseMutex* mutex); | 54 SkPixelRef(const SkImageInfo&, SkBaseMutex* mutex); |
63 virtual ~SkPixelRef(); | 55 virtual ~SkPixelRef(); |
64 | 56 |
65 const SkImageInfo& info() const { | 57 const SkImageInfo& info() const { |
66 return fInfo; | 58 return fInfo; |
67 } | 59 } |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 virtual void globalRef(void* data=NULL); | 243 virtual void globalRef(void* data=NULL); |
252 | 244 |
253 /** | 245 /** |
254 * Release a "global" ref on this object. | 246 * Release a "global" ref on this object. |
255 * The default implementation just calls unref(), but subclasses can overri
de | 247 * The default implementation just calls unref(), but subclasses can overri
de |
256 * this method to implement additional behavior. | 248 * this method to implement additional behavior. |
257 */ | 249 */ |
258 virtual void globalUnref(); | 250 virtual void globalUnref(); |
259 #endif | 251 #endif |
260 | 252 |
261 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE | |
262 SK_DEFINE_FLATTENABLE_TYPE(SkPixelRef) | |
263 #endif | |
264 | |
265 // Register a listener that may be called the next time our generation ID ch
anges. | 253 // Register a listener that may be called the next time our generation ID ch
anges. |
266 // | 254 // |
267 // We'll only call the listener if we're confident that we are the only SkPi
xelRef with this | 255 // We'll only call the listener if we're confident that we are the only SkPi
xelRef with this |
268 // generation ID. If our generation ID changes and we decide not to call th
e listener, we'll | 256 // generation ID. If our generation ID changes and we decide not to call th
e listener, we'll |
269 // never call it: you must add a new listener for each generation ID change.
We also won't call | 257 // never call it: you must add a new listener for each generation ID change.
We also won't call |
270 // the listener when we're certain no one knows what our generation ID is. | 258 // the listener when we're certain no one knows what our generation ID is. |
271 // | 259 // |
272 // This can be used to invalidate caches keyed by SkPixelRef generation ID. | 260 // This can be used to invalidate caches keyed by SkPixelRef generation ID. |
273 struct GenIDChangeListener { | 261 struct GenIDChangeListener { |
274 virtual ~GenIDChangeListener() {} | 262 virtual ~GenIDChangeListener() {} |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 void needsNewGenID(); | 353 void needsNewGenID(); |
366 void callGenIDChangeListeners(); | 354 void callGenIDChangeListeners(); |
367 | 355 |
368 void setMutex(SkBaseMutex* mutex); | 356 void setMutex(SkBaseMutex* mutex); |
369 | 357 |
370 // When copying a bitmap to another with the same shape and config, we can s
afely | 358 // When copying a bitmap to another with the same shape and config, we can s
afely |
371 // clone the pixelref generation ID too, which makes them equivalent under c
aching. | 359 // clone the pixelref generation ID too, which makes them equivalent under c
aching. |
372 friend class SkBitmap; // only for cloneGenID | 360 friend class SkBitmap; // only for cloneGenID |
373 void cloneGenID(const SkPixelRef&); | 361 void cloneGenID(const SkPixelRef&); |
374 | 362 |
375 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE | 363 typedef SkRefCnt INHERITED; |
376 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE { sk_throw(); } | |
377 #endif | |
378 | |
379 typedef SK_PIXELREF_BASECLASS INHERITED; | |
380 }; | 364 }; |
381 | 365 |
382 class SkPixelRefFactory : public SkRefCnt { | 366 class SkPixelRefFactory : public SkRefCnt { |
383 public: | 367 public: |
384 /** | 368 /** |
385 * Allocate a new pixelref matching the specified ImageInfo, allocating | 369 * Allocate a new pixelref matching the specified ImageInfo, allocating |
386 * the memory for the pixels. If the ImageInfo requires a ColorTable, | 370 * the memory for the pixels. If the ImageInfo requires a ColorTable, |
387 * the pixelref will ref() the colortable. | 371 * the pixelref will ref() the colortable. |
388 * On failure return NULL. | 372 * On failure return NULL. |
389 */ | 373 */ |
390 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; | 374 virtual SkPixelRef* create(const SkImageInfo&, size_t rowBytes, SkColorTable
*) = 0; |
391 }; | 375 }; |
392 | 376 |
393 #endif | 377 #endif |
OLD | NEW |