PatchCache.cpp revision 4aa90573bbf86db0d33a3a790c5dbd0d93b95cfe
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" 23#include "Properties.h" 24 25namespace android { 26namespace uirenderer { 27 28/////////////////////////////////////////////////////////////////////////////// 29// Constructors/destructor 30/////////////////////////////////////////////////////////////////////////////// 31 32PatchCache::PatchCache(): mCache(DEFAULT_PATCH_CACHE_SIZE) { 33} 34 35PatchCache::PatchCache(uint32_t maxEntries): mCache(maxEntries) { 36} 37 38PatchCache::~PatchCache() { 39 clear(); 40} 41 42/////////////////////////////////////////////////////////////////////////////// 43// Callbacks 44/////////////////////////////////////////////////////////////////////////////// 45 46void PatchCache::operator()(PatchDescription& description, Patch*& mesh) { 47 if (mesh) delete mesh; 48} 49 50/////////////////////////////////////////////////////////////////////////////// 51// Caching 52/////////////////////////////////////////////////////////////////////////////// 53 54void PatchCache::clear() { 55 mCache.setOnEntryRemovedListener(this); 56 mCache.clear(); 57 mCache.setOnEntryRemovedListener(NULL); 58} 59 60Patch* PatchCache::get(uint32_t width, uint32_t height) { 61 const PatchDescription description(width, height); 62 63 Patch* mesh = mCache.get(description); 64 if (!mesh) { 65 PATCH_LOGD("Creating new patch mesh, w=%d h=%d", width, height); 66 mesh = new Patch(width, height); 67 mCache.put(description, mesh); 68 } 69 70 return mesh; 71} 72 73}; // namespace uirenderer 74}; // namespace android 75