blob: f2cf5485a09f19371af983ed0e3e167d91b6f466 [file] [log] [blame]
Romain Guyf7f93552010-07-08 19:17:03 -07001/*
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 Guyfb8b7632010-08-23 21:05:08 -070023#include "Properties.h"
Romain Guyf7f93552010-07-08 19:17:03 -070024
25namespace android {
26namespace uirenderer {
27
28///////////////////////////////////////////////////////////////////////////////
29// Constructors/destructor
30///////////////////////////////////////////////////////////////////////////////
31
Romain Guyfb8b7632010-08-23 21:05:08 -070032PatchCache::PatchCache(): mCache(DEFAULT_PATCH_CACHE_SIZE) {
33}
34
Romain Guyf7f93552010-07-08 19:17:03 -070035PatchCache::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
Romain Guy4aa90572010-09-26 18:40:37 -070060Patch* PatchCache::get(uint32_t width, uint32_t height) {
Romain Guyf7f93552010-07-08 19:17:03 -070061 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