| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 SkBitmapCache_DEFINED | 8 #ifndef SkBitmapCache_DEFINED |
| 9 #define SkBitmapCache_DEFINED | 9 #define SkBitmapCache_DEFINED |
| 10 | 10 |
| 11 #include "SkScalar.h" | 11 #include "SkScalar.h" |
| 12 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 13 | 13 |
| 14 class SkImage; |
| 14 class SkResourceCache; | 15 class SkResourceCache; |
| 15 class SkMipMap; | 16 class SkMipMap; |
| 16 | 17 |
| 17 uint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID); | 18 uint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID); |
| 18 | 19 |
| 19 void SkNotifyBitmapGenIDIsStale(uint32_t bitmapGenID); | 20 void SkNotifyBitmapGenIDIsStale(uint32_t bitmapGenID); |
| 20 | 21 |
| 22 struct SkBitmapCacheDesc { |
| 23 uint32_t fImageID; |
| 24 int32_t fWidth; |
| 25 int32_t fHeight; |
| 26 SkIRect fBounds; |
| 27 |
| 28 static SkBitmapCacheDesc Make(const SkBitmap&, int width, int height); |
| 29 static SkBitmapCacheDesc Make(const SkBitmap&); |
| 30 static SkBitmapCacheDesc Make(const SkImage*, int width, int height); |
| 31 static SkBitmapCacheDesc Make(const SkImage*); |
| 32 }; |
| 33 |
| 21 class SkBitmapCache { | 34 class SkBitmapCache { |
| 22 public: | 35 public: |
| 23 /** | 36 /** |
| 24 * Use this allocator for bitmaps, so they can use ashmem when available. | 37 * Use this allocator for bitmaps, so they can use ashmem when available. |
| 25 * Returns nullptr if the ResourceCache has not been initialized with a Disc
ardableFactory. | 38 * Returns nullptr if the ResourceCache has not been initialized with a Disc
ardableFactory. |
| 26 */ | 39 */ |
| 27 static SkBitmap::Allocator* GetAllocator(); | 40 static SkBitmap::Allocator* GetAllocator(); |
| 28 | 41 |
| 29 /** | 42 /** |
| 30 * Search based on the src bitmap and scaled width/height. If found, return
s true and | 43 * Search based on the desc. If found, returns true and |
| 31 * result will be set to the matching bitmap with its pixels already locked
. | 44 * result will be set to the matching bitmap with its pixels already locked
. |
| 32 */ | 45 */ |
| 33 static bool FindWH(const SkBitmap& src, int width, int height, SkBitmap* res
ult, | 46 static bool FindWH(const SkBitmapCacheDesc&, SkBitmap* result, |
| 34 SkResourceCache* localCache = nullptr); | 47 SkResourceCache* localCache = nullptr); |
| 35 | 48 |
| 36 /* | 49 /* |
| 37 * result must be marked isImmutable() | 50 * result must be marked isImmutable() |
| 38 */ | 51 */ |
| 39 static void AddWH(const SkBitmap& src, int width, int height, const SkBitmap
& result, | 52 static bool AddWH(const SkBitmapCacheDesc&, const SkBitmap& result, |
| 40 SkResourceCache* localCache = nullptr); | 53 SkResourceCache* localCache = nullptr); |
| 41 | 54 |
| 42 /** | 55 /** |
| 43 * Search based on the bitmap's genID and subset. If found, returns true an
d | 56 * Search based on the bitmap's genID and subset. If found, returns true an
d |
| 44 * result will be set to the matching bitmap with its pixels already locked
. | 57 * result will be set to the matching bitmap with its pixels already locked
. |
| 45 */ | 58 */ |
| 46 static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result, | 59 static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result, |
| 47 SkResourceCache* localCache = nullptr); | 60 SkResourceCache* localCache = nullptr); |
| 48 | 61 |
| 49 /** | 62 /** |
| 50 * The width and the height of the provided subset must be the same as the r
esult bitmap ones. | 63 * The width and the height of the provided subset must be the same as the r
esult bitmap ones. |
| 51 * result must be marked isImmutable() | 64 * result must be marked isImmutable() |
| 52 */ | 65 */ |
| 53 static bool Add(SkPixelRef*, const SkIRect& subset, const SkBitmap& result, | 66 static bool Add(SkPixelRef*, const SkIRect& subset, const SkBitmap& result, |
| 54 SkResourceCache* localCache = nullptr); | 67 SkResourceCache* localCache = nullptr); |
| 55 | 68 |
| 56 static bool Find(uint32_t genID, SkBitmap* result, SkResourceCache* localCac
he = nullptr); | 69 static bool Find(uint32_t genID, SkBitmap* result, SkResourceCache* localCac
he = nullptr); |
| 57 // todo: eliminate the need to specify ID, since it should == the bitmap's | 70 // todo: eliminate the need to specify ID, since it should == the bitmap's |
| 58 static void Add(uint32_t genID, const SkBitmap&, SkResourceCache* localCache
= nullptr); | 71 static void Add(uint32_t genID, const SkBitmap&, SkResourceCache* localCache
= nullptr); |
| 59 }; | 72 }; |
| 60 | 73 |
| 61 class SkMipMapCache { | 74 class SkMipMapCache { |
| 62 public: | 75 public: |
| 63 static const SkMipMap* FindAndRef(const SkBitmap& src, SkResourceCache* loca
lCache = nullptr); | 76 static const SkMipMap* FindAndRef(const SkBitmapCacheDesc&, |
| 77 SkResourceCache* localCache = nullptr); |
| 64 static const SkMipMap* AddAndRef(const SkBitmap& src, SkResourceCache* local
Cache = nullptr); | 78 static const SkMipMap* AddAndRef(const SkBitmap& src, SkResourceCache* local
Cache = nullptr); |
| 65 }; | 79 }; |
| 66 | 80 |
| 67 #endif | 81 #endif |
| OLD | NEW |