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