blob: 530dad05d72ceb80c993b2e28d8379ee0f773033 [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 Guyf7f93552010-07-08 19:17:03 -070073private:
Romain Guy3b748a42013-04-17 18:54:38 -070074 void clearCache();
75
Romain Guy6f72beb2010-11-30 12:04:14 -080076 struct PatchDescription {
Romain Guy3b748a42013-04-17 18:54:38 -070077 PatchDescription(): mPatch(NULL), mBitmapWidth(0), mBitmapHeight(0),
78 mPixelWidth(0), mPixelHeight(0) {
Romain Guy6f72beb2010-11-30 12:04:14 -080079 }
80
Romain Guy13ba0052013-02-15 12:47:26 -080081 PatchDescription(const uint32_t bitmapWidth, const uint32_t bitmapHeight,
Romain Guy3b748a42013-04-17 18:54:38 -070082 const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch):
83 mPatch(patch), mBitmapWidth(bitmapWidth), mBitmapHeight(bitmapHeight),
84 mPixelWidth(pixelWidth), mPixelHeight(pixelHeight) {
Romain Guy6f72beb2010-11-30 12:04:14 -080085 }
86
Romain Guy3b748a42013-04-17 18:54:38 -070087 hash_t hash() const;
88
Romain Guy13ba0052013-02-15 12:47:26 -080089 static int compare(const PatchDescription& lhs, const PatchDescription& rhs);
90
91 bool operator==(const PatchDescription& other) const {
92 return compare(*this, other) == 0;
93 }
94
95 bool operator!=(const PatchDescription& other) const {
96 return compare(*this, other) != 0;
97 }
98
99 friend inline int strictly_order_type(const PatchDescription& lhs,
100 const PatchDescription& rhs) {
101 return PatchDescription::compare(lhs, rhs) < 0;
102 }
103
104 friend inline int compare_type(const PatchDescription& lhs,
105 const PatchDescription& rhs) {
106 return PatchDescription::compare(lhs, rhs);
Romain Guy6f72beb2010-11-30 12:04:14 -0800107 }
108
Romain Guy3b748a42013-04-17 18:54:38 -0700109 friend inline hash_t hash_type(const PatchDescription& entry) {
110 return entry.hash();
111 }
112
Romain Guy6f72beb2010-11-30 12:04:14 -0800113 private:
Romain Guy3b748a42013-04-17 18:54:38 -0700114 const Res_png_9patch* mPatch;
115 uint32_t mBitmapWidth;
116 uint32_t mBitmapHeight;
117 float mPixelWidth;
118 float mPixelHeight;
Romain Guy6f72beb2010-11-30 12:04:14 -0800119
120 }; // struct PatchDescription
121
Romain Guy3b748a42013-04-17 18:54:38 -0700122 uint32_t mMaxSize;
123 uint32_t mSize;
Romain Guy6f72beb2010-11-30 12:04:14 -0800124
Romain Guy3b748a42013-04-17 18:54:38 -0700125 GLuint mMeshBuffer;
Romain Guy7d9b1b32013-05-28 14:25:09 -0700126
127 LruCache<PatchDescription, Patch*> mCache;
Romain Guyf7f93552010-07-08 19:17:03 -0700128}; // class PatchCache
129
130}; // namespace uirenderer
131}; // namespace android
132
Romain Guy5b3b3522010-10-27 18:57:51 -0700133#endif // ANDROID_HWUI_PATCH_CACHE_H