Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_PATCH_CACHE_H |
| 18 | #define ANDROID_HWUI_PATCH_CACHE_H |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 19 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 20 | #include <utils/KeyedVector.h> |
| 21 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 22 | #include "Debug.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 23 | #include "Patch.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | // Defines |
| 30 | /////////////////////////////////////////////////////////////////////////////// |
| 31 | |
| 32 | // Debug |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 33 | #if DEBUG_PATCHES |
| 34 | #define PATCH_LOGD(...) LOGD(__VA_ARGS__) |
| 35 | #else |
| 36 | #define PATCH_LOGD(...) |
| 37 | #endif |
| 38 | |
| 39 | /////////////////////////////////////////////////////////////////////////////// |
| 40 | // Cache |
| 41 | /////////////////////////////////////////////////////////////////////////////// |
| 42 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 43 | class PatchCache { |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 44 | public: |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 45 | PatchCache(); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 46 | PatchCache(uint32_t maxCapacity); |
| 47 | ~PatchCache(); |
| 48 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 49 | Patch* get(const float bitmapWidth, const float bitmapHeight, |
| 50 | const float pixelWidth, const float pixelHeight, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 51 | 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 Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 53 | void clear(); |
| 54 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 55 | uint32_t getSize() const { |
| 56 | return mCache.size(); |
| 57 | } |
| 58 | |
| 59 | uint32_t getMaxSize() const { |
| 60 | return mMaxEntries; |
| 61 | } |
| 62 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 63 | private: |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame^] | 64 | /** |
| 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 | |
| 72 | PatchDescription(const float bitmapWidth, const float bitmapHeight, |
| 73 | 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 | |
| 82 | PatchDescription(const PatchDescription& description): |
| 83 | bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight), |
| 84 | pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight), |
| 85 | xCount(description.xCount), yCount(description.yCount), |
| 86 | emptyCount(description.emptyCount), colorKey(description.colorKey) { |
| 87 | } |
| 88 | |
| 89 | bool operator<(const PatchDescription& rhs) const { |
| 90 | LTE_FLOAT(bitmapWidth) { |
| 91 | LTE_FLOAT(bitmapHeight) { |
| 92 | LTE_FLOAT(pixelWidth) { |
| 93 | LTE_FLOAT(pixelHeight) { |
| 94 | LTE_INT(xCount) { |
| 95 | LTE_INT(yCount) { |
| 96 | LTE_INT(emptyCount) { |
| 97 | LTE_INT(colorKey) return false; |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | float bitmapWidth; |
| 110 | float bitmapHeight; |
| 111 | float pixelWidth; |
| 112 | float pixelHeight; |
| 113 | uint32_t xCount; |
| 114 | uint32_t yCount; |
| 115 | int8_t emptyCount; |
| 116 | uint32_t colorKey; |
| 117 | |
| 118 | }; // struct PatchDescription |
| 119 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 120 | uint32_t mMaxEntries; |
| 121 | KeyedVector<PatchDescription, Patch*> mCache; |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame^] | 122 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 123 | }; // class PatchCache |
| 124 | |
| 125 | }; // namespace uirenderer |
| 126 | }; // namespace android |
| 127 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 128 | #endif // ANDROID_HWUI_PATCH_CACHE_H |