blob: 62d0ce190aec1718e9472eb049d30765311d6d27 [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
35 #define PATCH_LOGD(...) LOGD(__VA_ARGS__)
36#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
83 PatchDescription(const PatchDescription& description):
84 bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight),
85 pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight),
86 xCount(description.xCount), yCount(description.yCount),
87 emptyCount(description.emptyCount), colorKey(description.colorKey) {
88 }
89
90 bool operator<(const PatchDescription& rhs) const {
91 LTE_FLOAT(bitmapWidth) {
92 LTE_FLOAT(bitmapHeight) {
93 LTE_FLOAT(pixelWidth) {
94 LTE_FLOAT(pixelHeight) {
95 LTE_INT(xCount) {
96 LTE_INT(yCount) {
97 LTE_INT(emptyCount) {
98 LTE_INT(colorKey) return false;
99 }
100 }
101 }
102 }
103 }
104 }
105 }
106 return false;
107 }
108
109 private:
110 float bitmapWidth;
111 float bitmapHeight;
112 float pixelWidth;
113 float pixelHeight;
114 uint32_t xCount;
115 uint32_t yCount;
116 int8_t emptyCount;
117 uint32_t colorKey;
118
119 }; // struct PatchDescription
120
Romain Guy2728f962010-10-08 18:36:15 -0700121 uint32_t mMaxEntries;
122 KeyedVector<PatchDescription, Patch*> mCache;
Romain Guy6f72beb2010-11-30 12:04:14 -0800123
Romain Guyf7f93552010-07-08 19:17:03 -0700124}; // class PatchCache
125
126}; // namespace uirenderer
127}; // namespace android
128
Romain Guy5b3b3522010-10-27 18:57:51 -0700129#endif // ANDROID_HWUI_PATCH_CACHE_H