blob: 1829b89dbfc0256999f46dd811e646f3fbf160f1 [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
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_PATCH_CACHE_H
18#define ANDROID_HWUI_PATCH_CACHE_H
Romain Guyf7f93552010-07-08 19:17:03 -070019
Romain Guy3b748a42013-04-17 18:54:38 -070020#include <GLES2/gl2.h>
Romain Guy2728f962010-10-08 18:36:15 -070021
Romain Guy3b748a42013-04-17 18:54:38 -070022#include <utils/LruCache.h>
23
24#include <androidfw/ResourceTypes.h>
25
26#include "AssetAtlas.h"
Romain Guyc15008e2010-11-10 11:59:15 -080027#include "Debug.h"
Romain Guyf7f93552010-07-08 19:17:03 -070028#include "Patch.h"
Romain Guyf7f93552010-07-08 19:17:03 -070029
30namespace android {
31namespace uirenderer {
32
33///////////////////////////////////////////////////////////////////////////////
34// Defines
35///////////////////////////////////////////////////////////////////////////////
36
37// Debug
Romain Guyf7f93552010-07-08 19:17:03 -070038#if DEBUG_PATCHES
Steve Block5baa3a62011-12-20 16:23:08 +000039 #define PATCH_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyf7f93552010-07-08 19:17:03 -070040#else
41 #define PATCH_LOGD(...)
42#endif
43
44///////////////////////////////////////////////////////////////////////////////
45// Cache
46///////////////////////////////////////////////////////////////////////////////
47
Romain Guy3b748a42013-04-17 18:54:38 -070048class Caches;
49
Romain Guy2728f962010-10-08 18:36:15 -070050class PatchCache {
Romain Guyf7f93552010-07-08 19:17:03 -070051public:
Romain Guyfb8b7632010-08-23 21:05:08 -070052 PatchCache();
Romain Guyf7f93552010-07-08 19:17:03 -070053 ~PatchCache();
Romain Guy3b748a42013-04-17 18:54:38 -070054 void init(Caches& caches);
Romain Guyf7f93552010-07-08 19:17:03 -070055
Romain Guy3b748a42013-04-17 18:54:38 -070056 const Patch* get(const AssetAtlas::Entry* entry,
57 const uint32_t bitmapWidth, const uint32_t bitmapHeight,
58 const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch);
Romain Guyf7f93552010-07-08 19:17:03 -070059 void clear();
60
Romain Guyc15008e2010-11-10 11:59:15 -080061 uint32_t getSize() const {
Romain Guy3b748a42013-04-17 18:54:38 -070062 return mSize;
Romain Guyc15008e2010-11-10 11:59:15 -080063 }
64
65 uint32_t getMaxSize() const {
Romain Guy3b748a42013-04-17 18:54:38 -070066 return mMaxSize;
67 }
68
69 GLuint getMeshBuffer() const {
70 return mMeshBuffer;
Romain Guyc15008e2010-11-10 11:59:15 -080071 }
72
Romain Guy4c2547f2013-06-11 16:19:24 -070073 uint32_t getGenerationId() const {
74 return mGenerationId;
75 }
76
Romain Guyf7f93552010-07-08 19:17:03 -070077private:
Romain Guy3b748a42013-04-17 18:54:38 -070078 void clearCache();
Romain Guy4c2547f2013-06-11 16:19:24 -070079 void createVertexBuffer();
Romain Guy3b748a42013-04-17 18:54:38 -070080
Romain Guy6f72beb2010-11-30 12:04:14 -080081 struct PatchDescription {
Romain Guy3b748a42013-04-17 18:54:38 -070082 PatchDescription(): mPatch(NULL), mBitmapWidth(0), mBitmapHeight(0),
83 mPixelWidth(0), mPixelHeight(0) {
Romain Guy6f72beb2010-11-30 12:04:14 -080084 }
85
Romain Guy13ba0052013-02-15 12:47:26 -080086 PatchDescription(const uint32_t bitmapWidth, const uint32_t bitmapHeight,
Romain Guy3b748a42013-04-17 18:54:38 -070087 const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch):
88 mPatch(patch), mBitmapWidth(bitmapWidth), mBitmapHeight(bitmapHeight),
89 mPixelWidth(pixelWidth), mPixelHeight(pixelHeight) {
Romain Guy6f72beb2010-11-30 12:04:14 -080090 }
91
Romain Guy3b748a42013-04-17 18:54:38 -070092 hash_t hash() const;
93
Romain Guy13ba0052013-02-15 12:47:26 -080094 static int compare(const PatchDescription& lhs, const PatchDescription& rhs);
95
96 bool operator==(const PatchDescription& other) const {
97 return compare(*this, other) == 0;
98 }
99
100 bool operator!=(const PatchDescription& other) const {
101 return compare(*this, other) != 0;
102 }
103
104 friend inline int strictly_order_type(const PatchDescription& lhs,
105 const PatchDescription& rhs) {
106 return PatchDescription::compare(lhs, rhs) < 0;
107 }
108
109 friend inline int compare_type(const PatchDescription& lhs,
110 const PatchDescription& rhs) {
111 return PatchDescription::compare(lhs, rhs);
Romain Guy6f72beb2010-11-30 12:04:14 -0800112 }
113
Romain Guy3b748a42013-04-17 18:54:38 -0700114 friend inline hash_t hash_type(const PatchDescription& entry) {
115 return entry.hash();
116 }
117
Romain Guy6f72beb2010-11-30 12:04:14 -0800118 private:
Romain Guy3b748a42013-04-17 18:54:38 -0700119 const Res_png_9patch* mPatch;
120 uint32_t mBitmapWidth;
121 uint32_t mBitmapHeight;
122 float mPixelWidth;
123 float mPixelHeight;
Romain Guy6f72beb2010-11-30 12:04:14 -0800124
125 }; // struct PatchDescription
126
Romain Guy3b748a42013-04-17 18:54:38 -0700127 uint32_t mMaxSize;
128 uint32_t mSize;
Romain Guy6f72beb2010-11-30 12:04:14 -0800129
Romain Guy4c2547f2013-06-11 16:19:24 -0700130 LruCache<PatchDescription, Patch*> mCache;
131
Romain Guy3b748a42013-04-17 18:54:38 -0700132 GLuint mMeshBuffer;
Romain Guy7d9b1b32013-05-28 14:25:09 -0700133
Romain Guy4c2547f2013-06-11 16:19:24 -0700134 uint32_t mGenerationId;
Romain Guyf7f93552010-07-08 19:17:03 -0700135}; // class PatchCache
136
137}; // namespace uirenderer
138}; // namespace android
139
Romain Guy5b3b3522010-10-27 18:57:51 -0700140#endif // ANDROID_HWUI_PATCH_CACHE_H