Romain Guy | f7f9355 | 2010-07-08 19:17:03 -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 | #define LOG_TAG "OpenGLRenderer" |
| 18 | |
| 19 | #include <utils/Log.h> |
| 20 | #include <utils/ResourceTypes.h> |
| 21 | |
| 22 | #include "PatchCache.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame^] | 23 | #include "Properties.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | // Constructors/destructor |
| 30 | /////////////////////////////////////////////////////////////////////////////// |
| 31 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame^] | 32 | PatchCache::PatchCache(): mCache(DEFAULT_PATCH_CACHE_SIZE) { |
| 33 | } |
| 34 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 35 | PatchCache::PatchCache(uint32_t maxEntries): mCache(maxEntries) { |
| 36 | } |
| 37 | |
| 38 | PatchCache::~PatchCache() { |
| 39 | clear(); |
| 40 | } |
| 41 | |
| 42 | /////////////////////////////////////////////////////////////////////////////// |
| 43 | // Callbacks |
| 44 | /////////////////////////////////////////////////////////////////////////////// |
| 45 | |
| 46 | void PatchCache::operator()(PatchDescription& description, Patch*& mesh) { |
| 47 | if (mesh) delete mesh; |
| 48 | } |
| 49 | |
| 50 | /////////////////////////////////////////////////////////////////////////////// |
| 51 | // Caching |
| 52 | /////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | void PatchCache::clear() { |
| 55 | mCache.setOnEntryRemovedListener(this); |
| 56 | mCache.clear(); |
| 57 | mCache.setOnEntryRemovedListener(NULL); |
| 58 | } |
| 59 | |
| 60 | Patch* PatchCache::get(const Res_png_9patch* patch) { |
| 61 | const uint32_t width = patch->numXDivs; |
| 62 | const uint32_t height = patch->numYDivs; |
| 63 | const PatchDescription description(width, height); |
| 64 | |
| 65 | Patch* mesh = mCache.get(description); |
| 66 | if (!mesh) { |
| 67 | PATCH_LOGD("Creating new patch mesh, w=%d h=%d", width, height); |
| 68 | mesh = new Patch(width, height); |
| 69 | mCache.put(description, mesh); |
| 70 | } |
| 71 | |
| 72 | return mesh; |
| 73 | } |
| 74 | |
| 75 | }; // namespace uirenderer |
| 76 | }; // namespace android |