Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_RESOURCE_CACHE_H |
| 18 | #define ANDROID_HWUI_RESOURCE_CACHE_H |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 19 | |
| 20 | #include <SkBitmap.h> |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 21 | #include <SkiaColorFilter.h> |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 22 | #include <SkiaShader.h> |
| 23 | #include <utils/KeyedVector.h> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | /** |
| 29 | * Type of Resource being cached |
| 30 | */ |
| 31 | enum ResourceType { |
| 32 | kBitmap, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 33 | kShader, |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 34 | kColorFilter, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | class ResourceReference { |
| 38 | public: |
| 39 | |
| 40 | ResourceReference() { refCount = 0; recycled = false; destroyed = false;} |
| 41 | ResourceReference(ResourceType type) { |
| 42 | refCount = 0; recycled = false; destroyed = false; resourceType = type; |
| 43 | } |
| 44 | |
| 45 | int refCount; |
| 46 | bool recycled; |
| 47 | bool destroyed; |
| 48 | ResourceType resourceType; |
| 49 | }; |
| 50 | |
| 51 | class ResourceCache { |
| 52 | KeyedVector<void *, ResourceReference *>* mCache; |
| 53 | public: |
| 54 | ResourceCache(); |
| 55 | ~ResourceCache(); |
| 56 | void incrementRefcount(SkBitmap* resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 57 | void incrementRefcount(SkiaShader* resource); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 58 | void incrementRefcount(SkiaColorFilter* resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 59 | void incrementRefcount(const void* resource, ResourceType resourceType); |
| 60 | void decrementRefcount(void* resource); |
| 61 | void decrementRefcount(SkBitmap* resource); |
| 62 | void decrementRefcount(SkiaShader* resource); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 63 | void decrementRefcount(SkiaColorFilter* resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 64 | void recycle(void* resource); |
| 65 | void recycle(SkBitmap* resource); |
| 66 | void destructor(SkBitmap* resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 67 | void destructor(SkiaShader* resource); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 68 | void destructor(SkiaColorFilter* resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 69 | private: |
| 70 | void deleteResourceReference(void* resource, ResourceReference* ref); |
| 71 | void incrementRefcount(void* resource, ResourceType resourceType); |
| 72 | void logCache(); |
| 73 | }; |
| 74 | |
| 75 | }; // namespace uirenderer |
| 76 | }; // namespace android |
| 77 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 78 | #endif // ANDROID_HWUI_RESOURCE_CACHE_H |