blob: a7c0ccef89f844886b9bfdba2aaf08d535338667 [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
60Patch* 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