blob: 0822cba4de35afc69a01afb9d18e8468c038bbda [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 Guyc15008e2010-11-10 11:59:15 -080022#include "Debug.h"
Romain Guyf7f93552010-07-08 19:17:03 -070023#include "Patch.h"
Romain Guyf7f93552010-07-08 19:17:03 -070024
25namespace android {
26namespace uirenderer {
27
28///////////////////////////////////////////////////////////////////////////////
29// Defines
30///////////////////////////////////////////////////////////////////////////////
31
32// Debug
Romain Guyf7f93552010-07-08 19:17:03 -070033#if DEBUG_PATCHES
Steve Block5baa3a62011-12-20 16:23:08 +000034 #define PATCH_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyf7f93552010-07-08 19:17:03 -070035#else
36 #define PATCH_LOGD(...)
37#endif
38
39///////////////////////////////////////////////////////////////////////////////
40// Cache
41///////////////////////////////////////////////////////////////////////////////
42
Romain Guy2728f962010-10-08 18:36:15 -070043class PatchCache {
Romain Guyf7f93552010-07-08 19:17:03 -070044public:
Romain Guyfb8b7632010-08-23 21:05:08 -070045 PatchCache();
Romain Guyf7f93552010-07-08 19:17:03 -070046 PatchCache(uint32_t maxCapacity);
47 ~PatchCache();
48
Romain Guy13ba0052013-02-15 12:47:26 -080049 Patch* get(const uint32_t bitmapWidth, const uint32_t bitmapHeight,
Romain Guy2728f962010-10-08 18:36:15 -070050 const float pixelWidth, const float pixelHeight,
Romain Guy4bb94202010-10-12 15:59:26 -070051 const int32_t* xDivs, const int32_t* yDivs, const uint32_t* colors,
52 const uint32_t width, const uint32_t height, const int8_t numColors);
Romain Guyf7f93552010-07-08 19:17:03 -070053 void clear();
54
Romain Guyc15008e2010-11-10 11:59:15 -080055 uint32_t getSize() const {
56 return mCache.size();
57 }
58
59 uint32_t getMaxSize() const {
60 return mMaxEntries;
61 }
62
Romain Guyf7f93552010-07-08 19:17:03 -070063private:
Romain Guy6f72beb2010-11-30 12:04:14 -080064 /**
65 * Description of a patch.
66 */
67 struct PatchDescription {
68 PatchDescription(): bitmapWidth(0), bitmapHeight(0), pixelWidth(0), pixelHeight(0),
69 xCount(0), yCount(0), emptyCount(0), colorKey(0) {
70 }
71
Romain Guy13ba0052013-02-15 12:47:26 -080072 PatchDescription(const uint32_t bitmapWidth, const uint32_t bitmapHeight,
Romain Guy6f72beb2010-11-30 12:04:14 -080073 const float pixelWidth, const float pixelHeight,
74 const uint32_t xCount, const uint32_t yCount,
75 const int8_t emptyCount, const uint32_t colorKey):
76 bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight),
77 pixelWidth(pixelWidth), pixelHeight(pixelHeight),
78 xCount(xCount), yCount(yCount),
79 emptyCount(emptyCount), colorKey(colorKey) {
80 }
81
Romain Guy13ba0052013-02-15 12:47:26 -080082 static int compare(const PatchDescription& lhs, const PatchDescription& rhs);
83
84 bool operator==(const PatchDescription& other) const {
85 return compare(*this, other) == 0;
86 }
87
88 bool operator!=(const PatchDescription& other) const {
89 return compare(*this, other) != 0;
90 }
91
92 friend inline int strictly_order_type(const PatchDescription& lhs,
93 const PatchDescription& rhs) {
94 return PatchDescription::compare(lhs, rhs) < 0;
95 }
96
97 friend inline int compare_type(const PatchDescription& lhs,
98 const PatchDescription& rhs) {
99 return PatchDescription::compare(lhs, rhs);
Romain Guy6f72beb2010-11-30 12:04:14 -0800100 }
101
102 private:
Romain Guy13ba0052013-02-15 12:47:26 -0800103 uint32_t bitmapWidth;
104 uint32_t bitmapHeight;
Romain Guy6f72beb2010-11-30 12:04:14 -0800105 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