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 | |
| 17 | #include <SkPixelRef.h> |
| 18 | #include "ResourceCache.h" |
| 19 | #include "Caches.h" |
| 20 | |
| 21 | namespace android { |
| 22 | namespace uirenderer { |
| 23 | |
| 24 | /////////////////////////////////////////////////////////////////////////////// |
| 25 | // Resource cache |
| 26 | /////////////////////////////////////////////////////////////////////////////// |
| 27 | |
| 28 | void ResourceCache::logCache() { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 29 | ALOGD("ResourceCache: cacheReport:"); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 30 | for (size_t i = 0; i < mCache->size(); ++i) { |
| 31 | ResourceReference* ref = mCache->valueAt(i); |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 32 | ALOGD(" ResourceCache: mCache(%d): resource, ref = 0x%p, 0x%p", |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 33 | i, mCache->keyAt(i), mCache->valueAt(i)); |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 34 | ALOGD(" ResourceCache: mCache(%d): refCount, recycled, destroyed, type = %d, %d, %d, %d", |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 35 | i, ref->refCount, ref->recycled, ref->destroyed, ref->resourceType); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | ResourceCache::ResourceCache() { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 40 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 41 | mCache = new KeyedVector<void*, ResourceReference*>(); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | ResourceCache::~ResourceCache() { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 45 | Mutex::Autolock _l(mLock); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 46 | delete mCache; |
| 47 | } |
| 48 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 49 | void ResourceCache::lock() { |
| 50 | mLock.lock(); |
| 51 | } |
| 52 | |
| 53 | void ResourceCache::unlock() { |
| 54 | mLock.unlock(); |
| 55 | } |
| 56 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 57 | void ResourceCache::incrementRefcount(void* resource, ResourceType resourceType) { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 58 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 59 | incrementRefcountLocked(resource, resourceType); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void ResourceCache::incrementRefcount(SkBitmap* bitmapResource) { |
Derek Sollenberger | 6062c59 | 2011-02-22 13:55:04 -0500 | [diff] [blame] | 63 | SkSafeRef(bitmapResource->pixelRef()); |
| 64 | SkSafeRef(bitmapResource->getColorTable()); |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 65 | incrementRefcount((void*) bitmapResource, kBitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 68 | void ResourceCache::incrementRefcount(SkPath* pathResource) { |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 69 | incrementRefcount((void*) pathResource, kPath); |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 72 | void ResourceCache::incrementRefcount(SkiaShader* shaderResource) { |
Derek Sollenberger | 6062c59 | 2011-02-22 13:55:04 -0500 | [diff] [blame] | 73 | SkSafeRef(shaderResource->getSkShader()); |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 74 | incrementRefcount((void*) shaderResource, kShader); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 77 | void ResourceCache::incrementRefcount(SkiaColorFilter* filterResource) { |
Derek Sollenberger | 6062c59 | 2011-02-22 13:55:04 -0500 | [diff] [blame] | 78 | SkSafeRef(filterResource->getSkColorFilter()); |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 79 | incrementRefcount((void*) filterResource, kColorFilter); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 82 | void ResourceCache::incrementRefcount(Layer* layerResource) { |
| 83 | incrementRefcount((void*) layerResource, kLayer); |
| 84 | } |
| 85 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 86 | void ResourceCache::incrementRefcountLocked(void* resource, ResourceType resourceType) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 87 | ssize_t index = mCache->indexOfKey(resource); |
| 88 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 89 | if (ref == NULL || mCache->size() == 0) { |
| 90 | ref = new ResourceReference(resourceType); |
| 91 | mCache->add(resource, ref); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 92 | } |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 93 | ref->refCount++; |
| 94 | } |
| 95 | |
| 96 | void ResourceCache::incrementRefcountLocked(SkBitmap* bitmapResource) { |
| 97 | SkSafeRef(bitmapResource->pixelRef()); |
| 98 | SkSafeRef(bitmapResource->getColorTable()); |
| 99 | incrementRefcountLocked((void*) bitmapResource, kBitmap); |
| 100 | } |
| 101 | |
| 102 | void ResourceCache::incrementRefcountLocked(SkPath* pathResource) { |
| 103 | incrementRefcountLocked((void*) pathResource, kPath); |
| 104 | } |
| 105 | |
| 106 | void ResourceCache::incrementRefcountLocked(SkiaShader* shaderResource) { |
| 107 | SkSafeRef(shaderResource->getSkShader()); |
| 108 | incrementRefcountLocked((void*) shaderResource, kShader); |
| 109 | } |
| 110 | |
| 111 | void ResourceCache::incrementRefcountLocked(SkiaColorFilter* filterResource) { |
| 112 | SkSafeRef(filterResource->getSkColorFilter()); |
| 113 | incrementRefcountLocked((void*) filterResource, kColorFilter); |
| 114 | } |
| 115 | |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 116 | void ResourceCache::incrementRefcountLocked(Layer* layerResource) { |
| 117 | incrementRefcountLocked((void*) layerResource, kLayer); |
| 118 | } |
| 119 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 120 | void ResourceCache::decrementRefcount(void* resource) { |
| 121 | Mutex::Autolock _l(mLock); |
| 122 | decrementRefcountLocked(resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void ResourceCache::decrementRefcount(SkBitmap* bitmapResource) { |
Derek Sollenberger | 6062c59 | 2011-02-22 13:55:04 -0500 | [diff] [blame] | 126 | SkSafeUnref(bitmapResource->pixelRef()); |
| 127 | SkSafeUnref(bitmapResource->getColorTable()); |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 128 | decrementRefcount((void*) bitmapResource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 131 | void ResourceCache::decrementRefcount(SkPath* pathResource) { |
| 132 | decrementRefcount((void*) pathResource); |
| 133 | } |
| 134 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 135 | void ResourceCache::decrementRefcount(SkiaShader* shaderResource) { |
Derek Sollenberger | 6062c59 | 2011-02-22 13:55:04 -0500 | [diff] [blame] | 136 | SkSafeUnref(shaderResource->getSkShader()); |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 137 | decrementRefcount((void*) shaderResource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 140 | void ResourceCache::decrementRefcount(SkiaColorFilter* filterResource) { |
Derek Sollenberger | 6062c59 | 2011-02-22 13:55:04 -0500 | [diff] [blame] | 141 | SkSafeUnref(filterResource->getSkColorFilter()); |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 142 | decrementRefcount((void*) filterResource); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 145 | void ResourceCache::decrementRefcount(Layer* layerResource) { |
| 146 | decrementRefcount((void*) layerResource); |
| 147 | } |
| 148 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 149 | void ResourceCache::decrementRefcountLocked(void* resource) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 150 | ssize_t index = mCache->indexOfKey(resource); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 151 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 152 | if (ref == NULL) { |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 153 | // 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] | 154 | return; |
| 155 | } |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 156 | ref->refCount--; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 157 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 158 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 162 | void ResourceCache::decrementRefcountLocked(SkBitmap* bitmapResource) { |
| 163 | SkSafeUnref(bitmapResource->pixelRef()); |
| 164 | SkSafeUnref(bitmapResource->getColorTable()); |
| 165 | decrementRefcountLocked((void*) bitmapResource); |
| 166 | } |
| 167 | |
| 168 | void ResourceCache::decrementRefcountLocked(SkPath* pathResource) { |
| 169 | decrementRefcountLocked((void*) pathResource); |
| 170 | } |
| 171 | |
| 172 | void ResourceCache::decrementRefcountLocked(SkiaShader* shaderResource) { |
| 173 | SkSafeUnref(shaderResource->getSkShader()); |
| 174 | decrementRefcountLocked((void*) shaderResource); |
| 175 | } |
| 176 | |
| 177 | void ResourceCache::decrementRefcountLocked(SkiaColorFilter* filterResource) { |
| 178 | SkSafeUnref(filterResource->getSkColorFilter()); |
| 179 | decrementRefcountLocked((void*) filterResource); |
| 180 | } |
| 181 | |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 182 | void ResourceCache::decrementRefcountLocked(Layer* layerResource) { |
| 183 | decrementRefcountLocked((void*) layerResource); |
| 184 | } |
| 185 | |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 186 | void ResourceCache::destructor(SkPath* resource) { |
| 187 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 188 | destructorLocked(resource); |
| 189 | } |
| 190 | |
| 191 | void ResourceCache::destructorLocked(SkPath* resource) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 192 | ssize_t index = mCache->indexOfKey(resource); |
| 193 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 194 | if (ref == NULL) { |
| 195 | // If we're not tracking this resource, just delete it |
| 196 | if (Caches::hasInstance()) { |
| 197 | Caches::getInstance().pathCache.removeDeferred(resource); |
| 198 | } |
| 199 | delete resource; |
| 200 | return; |
| 201 | } |
| 202 | ref->destroyed = true; |
| 203 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 204 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 208 | void ResourceCache::destructor(SkBitmap* resource) { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 209 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 210 | destructorLocked(resource); |
| 211 | } |
| 212 | |
| 213 | void ResourceCache::destructorLocked(SkBitmap* resource) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 214 | ssize_t index = mCache->indexOfKey(resource); |
| 215 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 216 | if (ref == NULL) { |
| 217 | // If we're not tracking this resource, just delete it |
| 218 | if (Caches::hasInstance()) { |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 219 | Caches::getInstance().textureCache.removeDeferred(resource); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 220 | } |
| 221 | delete resource; |
| 222 | return; |
| 223 | } |
| 224 | ref->destroyed = true; |
| 225 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 226 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 230 | void ResourceCache::destructor(SkiaShader* resource) { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 231 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 232 | destructorLocked(resource); |
| 233 | } |
| 234 | |
| 235 | void ResourceCache::destructorLocked(SkiaShader* resource) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 236 | ssize_t index = mCache->indexOfKey(resource); |
| 237 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 238 | if (ref == NULL) { |
| 239 | // If we're not tracking this resource, just delete it |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 240 | delete resource; |
| 241 | return; |
| 242 | } |
| 243 | ref->destroyed = true; |
| 244 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 245 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 249 | void ResourceCache::destructor(SkiaColorFilter* resource) { |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 250 | Mutex::Autolock _l(mLock); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 251 | destructorLocked(resource); |
| 252 | } |
| 253 | |
| 254 | void ResourceCache::destructorLocked(SkiaColorFilter* resource) { |
Romain Guy | 8dcfd5e | 2012-07-20 11:36:03 -0700 | [diff] [blame] | 255 | ssize_t index = mCache->indexOfKey(resource); |
| 256 | ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 257 | if (ref == NULL) { |
| 258 | // If we're not tracking this resource, just delete it |
| 259 | delete resource; |
| 260 | return; |
| 261 | } |
| 262 | ref->destroyed = true; |
| 263 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 264 | deleteResourceReferenceLocked(resource, ref); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 268 | void ResourceCache::recycle(SkBitmap* resource) { |
| 269 | Mutex::Autolock _l(mLock); |
| 270 | recycleLocked(resource); |
| 271 | } |
| 272 | |
| 273 | void ResourceCache::recycleLocked(SkBitmap* resource) { |
| 274 | ssize_t index = mCache->indexOfKey(resource); |
| 275 | if (index < 0) { |
| 276 | // not tracking this resource; just recycle the pixel data |
| 277 | resource->setPixels(NULL, NULL); |
| 278 | return; |
| 279 | } |
| 280 | ResourceReference* ref = mCache->valueAt(index); |
| 281 | if (ref == NULL) { |
| 282 | // Should not get here - shouldn't get a call to recycle if we're not yet tracking it |
| 283 | return; |
| 284 | } |
| 285 | ref->recycled = true; |
| 286 | if (ref->refCount == 0) { |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 287 | deleteResourceReferenceLocked(resource, ref); |
Romain Guy | 58ecc20 | 2012-09-07 11:58:36 -0700 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
Chet Haase | e7d2295 | 2010-11-11 16:30:16 -0800 | [diff] [blame] | 291 | /** |
| 292 | * This method should only be called while the mLock mutex is held (that mutex is grabbed |
| 293 | * by the various destructor() and recycle() methods which call this method). |
| 294 | */ |
Romain Guy | 97dc917 | 2012-09-23 17:46:45 -0700 | [diff] [blame] | 295 | void ResourceCache::deleteResourceReferenceLocked(void* resource, ResourceReference* ref) { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 296 | if (ref->recycled && ref->resourceType == kBitmap) { |
| 297 | ((SkBitmap*) resource)->setPixels(NULL, NULL); |
| 298 | } |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 299 | if (ref->destroyed || ref->resourceType == kLayer) { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 300 | switch (ref->resourceType) { |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 301 | case kBitmap: { |
| 302 | SkBitmap* bitmap = (SkBitmap*) resource; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 303 | if (Caches::hasInstance()) { |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 304 | Caches::getInstance().textureCache.removeDeferred(bitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 305 | } |
| 306 | delete bitmap; |
| 307 | } |
| 308 | break; |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 309 | case kPath: { |
| 310 | SkPath* path = (SkPath*) resource; |
Chet Haase | 5a7e828 | 2011-02-04 12:50:55 -0800 | [diff] [blame] | 311 | if (Caches::hasInstance()) { |
| 312 | Caches::getInstance().pathCache.removeDeferred(path); |
| 313 | } |
| 314 | delete path; |
| 315 | } |
| 316 | break; |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 317 | case kShader: { |
| 318 | SkiaShader* shader = (SkiaShader*) resource; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 319 | delete shader; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 320 | } |
| 321 | break; |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 322 | case kColorFilter: { |
| 323 | SkiaColorFilter* filter = (SkiaColorFilter*) resource; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 324 | delete filter; |
| 325 | } |
| 326 | break; |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 327 | case kLayer: { |
Dave Burke | 56257af | 2012-09-25 20:30:09 -0700 | [diff] [blame] | 328 | Layer* layer = (Layer*) resource; |
Mathias Agopian | 54643d7 | 2012-09-25 21:30:22 -0700 | [diff] [blame^] | 329 | Caches::getInstance().deleteLayerDeferred(layer); |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 330 | } |
| 331 | break; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | mCache->removeItem(resource); |
| 335 | delete ref; |
| 336 | } |
| 337 | |
| 338 | }; // namespace uirenderer |
| 339 | }; // namespace android |