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 | |
| 17 | class SkBitmapCache { |
| 18 | public: |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 19 | /** |
piotaixr | 8159146 | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 20 | * Use this allocator for bitmaps, so they can use ashmem when available. |
| 21 | * Returns NULL if the ResourceCache has not been initialized with a DiscardableFactory. |
reed | 14b6aba | 2014-08-29 10:25:26 -0700 | [diff] [blame] | 22 | */ |
| 23 | static SkBitmap::Allocator* GetAllocator(); |
| 24 | |
| 25 | /** |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 26 | * Search based on the src bitmap and inverse scales in X and Y. If found, returns true and |
| 27 | * result will be set to the matching bitmap with its pixels already locked. |
| 28 | */ |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame^] | 29 | static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result, |
| 30 | SkResourceCache* localCache = NULL); |
piotaixr | 8159146 | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 31 | |
reed | 14b6aba | 2014-08-29 10:25:26 -0700 | [diff] [blame] | 32 | /* |
| 33 | * result must be marked isImmutable() |
| 34 | */ |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 35 | static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame^] | 36 | const SkBitmap& result, SkResourceCache* localCache = NULL); |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 37 | |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 38 | /** |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 39 | * Search based on the bitmap's genID and subset. If found, returns true and |
| 40 | * result will be set to the matching bitmap with its pixels already locked. |
| 41 | */ |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame^] | 42 | static bool Find(uint32_t genID, const SkIRect& subset, SkBitmap* result, |
| 43 | SkResourceCache* localCache = NULL); |
piotaixr | 42b0dfe | 2014-09-03 11:33:13 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * The width and the height of the provided subset must be the same as the result bitmap ones. |
| 47 | * result must be marked isImmutable() |
| 48 | */ |
reed | 30ad530 | 2014-09-16 10:39:55 -0700 | [diff] [blame^] | 49 | static bool Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result, |
| 50 | SkResourceCache* localCache = NULL); |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | class SkMipMapCache { |
| 54 | public: |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 55 | static const SkMipMap* FindAndRef(const SkBitmap& src); |
| 56 | static void Add(const SkBitmap& src, const SkMipMap* result); |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | #endif |