blob: 505798aec3a73653105f3b125adf401c23f0f418 [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 Guy2728f962010-10-08 18:36:15 -070020#include <utils/KeyedVector.h>
21
Romain Guy25dc3a72010-12-10 12:33:05 -080022#include "utils/Compare.h"
Romain Guyc15008e2010-11-10 11:59:15 -080023#include "Debug.h"
Romain Guyf7f93552010-07-08 19:17:03 -070024#include "Patch.h"
Romain Guyf7f93552010-07-08 19:17:03 -070025
26namespace android {
27namespace uirenderer {
28
29///////////////////////////////////////////////////////////////////////////////
30// Defines
31///////////////////////////////////////////////////////////////////////////////
32
33// Debug
Romain Guyf7f93552010-07-08 19:17:03 -070034#if DEBUG_PATCHES
Steve Block1afd5ba2011-12-20 16:23:08 +000035 #define PATCH_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyf7f93552010-07-08 19:17:03 -070036#else
37 #define PATCH_LOGD(...)
38#endif
39
40///////////////////////////////////////////////////////////////////////////////
41// Cache
42///////////////////////////////////////////////////////////////////////////////
43
Romain Guy2728f962010-10-08 18:36:15 -070044class PatchCache {
Romain Guyf7f93552010-07-08 19:17:03 -070045public:
Romain Guyfb8b7632010-08-23 21:05:08 -070046 PatchCache();
Romain Guyf7f93552010-07-08 19:17:03 -070047 PatchCache(uint32_t maxCapacity);
48 ~PatchCache();
49
Romain Guy2728f962010-10-08 18:36:15 -070050 Patch* get(const float bitmapWidth, const float bitmapHeight,
51 const float pixelWidth, const float pixelHeight,
Romain Guy4bb94202010-10-12 15:59:26 -070052 const int32_t* xDivs, const int32_t* yDivs, const uint32_t* colors,
53 const uint32_t width, const uint32_t height, const int8_t numColors);
Romain Guyf7f93552010-07-08 19:17:03 -070054 void clear();
55
Romain Guyc15008e2010-11-10 11:59:15 -080056 uint32_t getSize() const {
57 return mCache.size();
58 }
59
60 uint32_t getMaxSize() const {
61 return mMaxEntries;
62 }
63
Romain Guyf7f93552010-07-08 19:17:03 -070064private:
Romain Guy6f72beb2010-11-30 12:04:14 -080065 /**
66 * Description of a patch.
67 */
68 struct PatchDescription {
69 PatchDescription(): bitmapWidth(0), bitmapHeight(0), pixelWidth(0), pixelHeight(0),
70 xCount(0), yCount(0), emptyCount(0), colorKey(0) {
71 }
72
73 PatchDescription(const float bitmapWidth, const float bitmapHeight,
74 const float pixelWidth, const float pixelHeight,
75 const uint32_t xCount, const uint32_t yCount,
76 const int8_t emptyCount, const uint32_t colorKey):
77 bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight),
78 pixelWidth(pixelWidth), pixelHeight(pixelHeight),
79 xCount(xCount), yCount(yCount),
80 emptyCount(emptyCount), colorKey(colorKey) {
81 }
82
Romain Guy6f72beb2010-11-30 12:04:14 -080083 bool operator<(const PatchDescription& rhs) const {
84 LTE_FLOAT(bitmapWidth) {
85 LTE_FLOAT(bitmapHeight) {
86 LTE_FLOAT(pixelWidth) {
87 LTE_FLOAT(pixelHeight) {
88 LTE_INT(xCount) {
89 LTE_INT(yCount) {
90 LTE_INT(emptyCount) {
91 LTE_INT(colorKey) return false;
92 }
93 }
94 }
95 }
96 }
97 }
98 }
99 return false;
100 }
101
102 private:
103 float bitmapWidth;
104 float bitmapHeight;
105 float pixelWidth;
106 float pixelHeight;
107 uint32_t xCount;
108 uint32_t yCount;
109 int8_t emptyCount;
110 uint32_t colorKey;
111
112 }; // struct PatchDescription
113
Romain Guy2728f962010-10-08 18:36:15 -0700114 uint32_t mMaxEntries;
115 KeyedVector<PatchDescription, Patch*> mCache;
Romain Guy6f72beb2010-11-30 12:04:14 -0800116
Romain Guyf7f93552010-07-08 19:17:03 -0700117}; // class PatchCache
118
119}; // namespace uirenderer
120}; // namespace android
121
Romain Guy5b3b3522010-10-27 18:57:51 -0700122#endif // ANDROID_HWUI_PATCH_CACHE_H