reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkBitmapCache_DEFINED |
| 9 | #define SkBitmapCache_DEFINED |
| 10 | |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 11 | #include "SkScalar.h" |
reed | 14b6aba | 2014-08-29 10:25:26 -0700 | [diff] [blame] | 12 | #include "SkBitmap.h" |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 13 | |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 14 | class SkResourceCache; |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 15 | class SkMipMap; |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 16 | |
reed | 7eeba25 | 2015-02-24 13:54:23 -0800 | [diff] [blame] | 17 | uint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID); |
| 18 | |
| 19 | void SkNotifyBitmapGenIDIsStale(uint32_t bitmapGenID); |
| 20 | |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 21 | class SkBitmapCache { |
| 22 | public: |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 23 | /** |
piotaixr | 8159146 | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 24 | * Use this allocator for bitmaps, so they can use ashmem when available. |
| 25 | * Returns NULL if the ResourceCache has not been initialized with a DiscardableFactory. |
reed | 14b6aba | 2014-08-29 10:25:26 -0700 | [diff] [blame] | 26 | */ |
| 27 | static SkBitmap::Allocator* GetAllocator(); |
| 28 | |
| 29 | /** |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 30 | * Search based on the src bitmap and inverse scales in X and Y. If found, returns true and |
| 31 | * result will be set to the matching bitmap with its pixels already locked. |
| 32 | */ |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 33 | static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result, |
| 34 | SkResourceCache* localCache = NULL); |
piotaixr | 8159146 | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 35 | |
reed | 14b6aba | 2014-08-29 10:25:26 -0700 | [diff] [blame] | 36 | /* |
| 37 | * result must be marked isImmutable() |
| 38 | */ |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 39 | static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 40 | const SkBitmap& result, SkResourceCache* localCache = NULL); |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 41 | |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 42 | /** |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 43 | * Search based on the bitmap's genID and subset. If found, returns true and |
| 44 | * result will be set to the matching bitmap with its pixels already locked. |
| 45 | */ |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 46 | static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result, |
| 47 | SkResourceCache* localCache = NULL); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * The width and the height of the provided subset must be the same as the result bitmap ones. |
| 51 | * result must be marked isImmutable() |
| 52 | */ |
reed | 83787d0 | 2015-02-25 07:17:11 -0800 | [diff] [blame^] | 53 | static bool Add(SkPixelRef*, const SkIRect& subset, const SkBitmap& result, |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame] | 54 | SkResourceCache* localCache = NULL); |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | class SkMipMapCache { |
| 58 | public: |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 59 | static const SkMipMap* FindAndRef(const SkBitmap& src, SkResourceCache* localCache = NULL); |
| 60 | static const SkMipMap* AddAndRef(const SkBitmap& src, SkResourceCache* localCache = NULL); |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #endif |