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 | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 17 | #define LOG_TAG "OpenGLRenderer" |
| 18 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 19 | #include <SkPixelRef.h> |
| 20 | #include "ResourceCache.h" |
| 21 | #include "Caches.h" |
| 22 | |
| 23 | namespace android { |
John Reck | a35778c7 | 2014-11-06 09:45:10 -0800 | [diff] [blame] | 24 | |
| 25 | #ifdef USE_OPENGL_RENDERER |
| 26 | using namespace uirenderer; |
| 27 | ANDROID_SINGLETON_STATIC_INSTANCE(ResourceCache); |
| 28 | #endif |
| 29 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 30 | namespace uirenderer { |
| 31 | |
| 32 | /////////////////////////////////////////////////////////////////////////////// |
| 33 | // Resource cache |
| 34 | /////////////////////////////////////////////////////////////////////////////// |
| 35 | |
| 36 | void ResourceCache::logCache() { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 37 | ALOGD("ResourceCache: cacheReport:"); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 38 | for (size_t i = 0; i < mCache->size(); ++i) { |
| 39 | ResourceReference* ref = mCache->valueAt(i); |
Ashok Bhat | f5df700 | 2014-03-25 20:51:35 +0000 | [diff] [blame] | 40 | ALOGD(" ResourceCache: mCache(%zu): resource, ref = 0x%p, 0x%p", |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 41 | i, mCache->keyAt(i), mCache->valueAt(i)); |
Ashok Bhat | f5df700 | 2014-03-25 20:51:35 +0000 | [diff] [blame] | 42 | ALOGD(" ResourceCache: mCache(%zu): refCount, recycled, destroyed, type = %d, %d, %d, %d", |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 43 | i, ref->refCount, ref->recycled, ref->destroyed, ref->resourceType); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | ResourceCache::ResourceCache() { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 48 | Mutex::Autolock _l(mLock); |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 49 | mCache = new KeyedVector<const void*, ResourceReference*>(); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | ResourceCache::~ResourceCache() { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 53 | Mutex::Autolock _l(mLock); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 54 | delete mCache; |
| 55 | } |
| 56 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 57 | void ResourceCache::lock() { |
| 58 | mLock.lock(); |
| 59 | } |
| 60 | |
| 61 | void ResourceCache::unlock() { |
| 62 | mLock.unlock(); |
| 63 | } |
| 64 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 65 | void ResourceCache::incrementRefcount(void* resource, ResourceType resourceType) { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 66 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 67 | incrementRefcountLocked(resource, resourceType); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 70 | void ResourceCache::incrementRefcount(const SkBitmap* bitmapResource) { |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 71 | incrementRefcount((void*) bitmapResource, kBitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 74 | void ResourceCache::incrementRefcount(const SkPath* pathResource) { |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 75 | incrementRefcount((void*) pathResource, kPath); |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 78 | void ResourceCache::incrementRefcount(const Res_png_9patch* patchResource) { |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 79 | incrementRefcount((void*) patchResource, kNinePatch); |
| 80 | } |
| 81 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 82 | void ResourceCache::incrementRefcountLocked(void* resource, ResourceType resourceType) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 83 | ssize_t index = mCache->indexOfKey(resource); |
| 84 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 85 | if (ref == NULL || mCache->size() == 0) { |
| 86 | ref = new ResourceReference(resourceType); |
| 87 | mCache->add(resource, ref); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 88 | } |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 89 | ref->refCount++; |
| 90 | } |
| 91 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 92 | void ResourceCache::incrementRefcountLocked(const SkBitmap* bitmapResource) { |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 93 | incrementRefcountLocked((void*) bitmapResource, kBitmap); |
| 94 | } |
| 95 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 96 | void ResourceCache::incrementRefcountLocked(const SkPath* pathResource) { |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 97 | incrementRefcountLocked((void*) pathResource, kPath); |
| 98 | } |
| 99 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 100 | void ResourceCache::incrementRefcountLocked(const Res_png_9patch* patchResource) { |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 101 | incrementRefcountLocked((void*) patchResource, kNinePatch); |
| 102 | } |
| 103 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 104 | void ResourceCache::decrementRefcount(void* resource) { |
| 105 | Mutex::Autolock _l(mLock); |
| 106 | decrementRefcountLocked(resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 109 | void ResourceCache::decrementRefcount(const SkBitmap* bitmapResource) { |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 110 | decrementRefcount((void*) bitmapResource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 113 | void ResourceCache::decrementRefcount(const SkPath* pathResource) { |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 114 | decrementRefcount((void*) pathResource); |
| 115 | } |
| 116 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 117 | void ResourceCache::decrementRefcount(const Res_png_9patch* patchResource) { |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 118 | decrementRefcount((void*) patchResource); |
| 119 | } |
| 120 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 121 | void ResourceCache::decrementRefcountLocked(void* resource) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 122 | ssize_t index = mCache->indexOfKey(resource); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 123 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 124 | if (ref == NULL) { |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 125 | // Should not get here - shouldn't get a call to decrement if we're not yet tracking it |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 126 | return; |
| 127 | } |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 128 | ref->refCount--; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 129 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 130 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 134 | void ResourceCache::decrementRefcountLocked(const SkBitmap* bitmapResource) { |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 135 | decrementRefcountLocked((void*) bitmapResource); |
| 136 | } |
| 137 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 138 | void ResourceCache::decrementRefcountLocked(const SkPath* pathResource) { |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 139 | decrementRefcountLocked((void*) pathResource); |
| 140 | } |
| 141 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 142 | void ResourceCache::decrementRefcountLocked(const Res_png_9patch* patchResource) { |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 143 | decrementRefcountLocked((void*) patchResource); |
| 144 | } |
| 145 | |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 146 | void ResourceCache::destructor(SkPath* resource) { |
| 147 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 148 | destructorLocked(resource); |
| 149 | } |
| 150 | |
| 151 | void ResourceCache::destructorLocked(SkPath* resource) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 152 | ssize_t index = mCache->indexOfKey(resource); |
| 153 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 154 | if (ref == NULL) { |
| 155 | // If we're not tracking this resource, just delete it |
| 156 | if (Caches::hasInstance()) { |
| 157 | Caches::getInstance().pathCache.removeDeferred(resource); |
Sangkyu Lee | 36fad8f | 2014-01-09 14:11:57 +0900 | [diff] [blame] | 158 | } else { |
| 159 | delete resource; |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 160 | } |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 161 | return; |
| 162 | } |
| 163 | ref->destroyed = true; |
| 164 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 165 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 169 | void ResourceCache::destructor(const SkBitmap* resource) { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 170 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 171 | destructorLocked(resource); |
| 172 | } |
| 173 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 174 | void ResourceCache::destructorLocked(const SkBitmap* resource) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 175 | ssize_t index = mCache->indexOfKey(resource); |
| 176 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 177 | if (ref == NULL) { |
| 178 | // If we're not tracking this resource, just delete it |
| 179 | if (Caches::hasInstance()) { |
John Reck | 71d08a0 | 2014-11-24 15:21:28 -0800 | [diff] [blame] | 180 | Caches::getInstance().textureCache.releaseTexture(resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 181 | } |
John Reck | 71d08a0 | 2014-11-24 15:21:28 -0800 | [diff] [blame] | 182 | delete resource; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 183 | return; |
| 184 | } |
| 185 | ref->destroyed = true; |
| 186 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 187 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 191 | void ResourceCache::destructor(Res_png_9patch* resource) { |
| 192 | Mutex::Autolock _l(mLock); |
| 193 | destructorLocked(resource); |
| 194 | } |
| 195 | |
| 196 | void ResourceCache::destructorLocked(Res_png_9patch* resource) { |
| 197 | ssize_t index = mCache->indexOfKey(resource); |
| 198 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
| 199 | if (ref == NULL) { |
Sangkyu Lee | 36fad8f | 2014-01-09 14:11:57 +0900 | [diff] [blame] | 200 | // If we're not tracking this resource, just delete it |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 201 | if (Caches::hasInstance()) { |
| 202 | Caches::getInstance().patchCache.removeDeferred(resource); |
Sangkyu Lee | 36fad8f | 2014-01-09 14:11:57 +0900 | [diff] [blame] | 203 | } else { |
| 204 | // A Res_png_9patch is actually an array of byte that's larger |
| 205 | // than sizeof(Res_png_9patch). It must be freed as an array. |
| 206 | delete[] (int8_t*) resource; |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 207 | } |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 208 | return; |
| 209 | } |
| 210 | ref->destroyed = true; |
| 211 | if (ref->refCount == 0) { |
| 212 | deleteResourceReferenceLocked(resource, ref); |
| 213 | } |
| 214 | } |
| 215 | |
Chet Haase | 547e665 | 2012-10-22 15:07:26 -0700 | [diff] [blame] | 216 | /** |
| 217 | * Return value indicates whether resource was actually recycled, which happens when RefCnt |
| 218 | * reaches 0. |
| 219 | */ |
| 220 | bool ResourceCache::recycle(SkBitmap* resource) { |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 221 | Mutex::Autolock _l(mLock); |
Chet Haase | 547e665 | 2012-10-22 15:07:26 -0700 | [diff] [blame] | 222 | return recycleLocked(resource); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Chet Haase | 547e665 | 2012-10-22 15:07:26 -0700 | [diff] [blame] | 225 | /** |
| 226 | * Return value indicates whether resource was actually recycled, which happens when RefCnt |
| 227 | * reaches 0. |
| 228 | */ |
| 229 | bool ResourceCache::recycleLocked(SkBitmap* resource) { |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 230 | ssize_t index = mCache->indexOfKey(resource); |
| 231 | if (index < 0) { |
John Reck | 71d08a0 | 2014-11-24 15:21:28 -0800 | [diff] [blame] | 232 | if (Caches::hasInstance()) { |
| 233 | Caches::getInstance().textureCache.releaseTexture(resource); |
| 234 | } |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 235 | // not tracking this resource; just recycle the pixel data |
| 236 | resource->setPixels(NULL, NULL); |
Chet Haase | 547e665 | 2012-10-22 15:07:26 -0700 | [diff] [blame] | 237 | return true; |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 238 | } |
| 239 | ResourceReference* ref = mCache->valueAt(index); |
| 240 | if (ref == NULL) { |
| 241 | // Should not get here - shouldn't get a call to recycle if we're not yet tracking it |
Chet Haase | 547e665 | 2012-10-22 15:07:26 -0700 | [diff] [blame] | 242 | return true; |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 243 | } |
| 244 | ref->recycled = true; |
| 245 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 246 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | 547e665 | 2012-10-22 15:07:26 -0700 | [diff] [blame] | 247 | return true; |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 248 | } |
Chet Haase | 547e665 | 2012-10-22 15:07:26 -0700 | [diff] [blame] | 249 | // Still referring to resource, don't recycle yet |
| 250 | return false; |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 253 | /** |
| 254 | * This method should only be called while the mLock mutex is held (that mutex is grabbed |
| 255 | * by the various destructor() and recycle() methods which call this method). |
| 256 | */ |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 257 | void ResourceCache::deleteResourceReferenceLocked(const void* resource, ResourceReference* ref) { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 258 | if (ref->recycled && ref->resourceType == kBitmap) { |
John Reck | 71d08a0 | 2014-11-24 15:21:28 -0800 | [diff] [blame] | 259 | SkBitmap* bitmap = (SkBitmap*) resource; |
| 260 | if (Caches::hasInstance()) { |
| 261 | Caches::getInstance().textureCache.releaseTexture(bitmap); |
| 262 | } |
| 263 | bitmap->setPixels(NULL, NULL); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 264 | } |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 265 | if (ref->destroyed) { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 266 | switch (ref->resourceType) { |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 267 | case kBitmap: { |
| 268 | SkBitmap* bitmap = (SkBitmap*) resource; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 269 | if (Caches::hasInstance()) { |
John Reck | 71d08a0 | 2014-11-24 15:21:28 -0800 | [diff] [blame] | 270 | Caches::getInstance().textureCache.releaseTexture(bitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 271 | } |
John Reck | 71d08a0 | 2014-11-24 15:21:28 -0800 | [diff] [blame] | 272 | delete bitmap; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 273 | } |
| 274 | break; |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 275 | case kPath: { |
| 276 | SkPath* path = (SkPath*) resource; |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 277 | if (Caches::hasInstance()) { |
| 278 | Caches::getInstance().pathCache.removeDeferred(path); |
Sangkyu Lee | 36fad8f | 2014-01-09 14:11:57 +0900 | [diff] [blame] | 279 | } else { |
| 280 | delete path; |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 281 | } |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 282 | } |
| 283 | break; |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 284 | case kNinePatch: { |
| 285 | if (Caches::hasInstance()) { |
| 286 | Caches::getInstance().patchCache.removeDeferred((Res_png_9patch*) resource); |
Sangkyu Lee | 36fad8f | 2014-01-09 14:11:57 +0900 | [diff] [blame] | 287 | } else { |
| 288 | // A Res_png_9patch is actually an array of byte that's larger |
| 289 | // than sizeof(Res_png_9patch). It must be freed as an array. |
| 290 | int8_t* patch = (int8_t*) resource; |
| 291 | delete[] patch; |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 292 | } |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 293 | } |
| 294 | break; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | mCache->removeItem(resource); |
| 298 | delete ref; |
| 299 | } |
| 300 | |
| 301 | }; // namespace uirenderer |
| 302 | }; // namespace android |