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 | 25dc3a7 | 2010-12-10 12:33:05 -0800 | [diff] [blame] | 22 | #include "utils/Compare.h" |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 23 | #include "Debug.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 24 | #include "Patch.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | |
| 29 | /////////////////////////////////////////////////////////////////////////////// |
| 30 | // Defines |
| 31 | /////////////////////////////////////////////////////////////////////////////// |
| 32 | |
| 33 | // Debug |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 34 | #if DEBUG_PATCHES |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame^] | 35 | #define PATCH_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 36 | #else |
| 37 | #define PATCH_LOGD(...) |
| 38 | #endif |
| 39 | |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | // Cache |
| 42 | /////////////////////////////////////////////////////////////////////////////// |
| 43 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 44 | class PatchCache { |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 45 | public: |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 46 | PatchCache(); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 47 | PatchCache(uint32_t maxCapacity); |
| 48 | ~PatchCache(); |
| 49 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 50 | Patch* get(const float bitmapWidth, const float bitmapHeight, |
| 51 | const float pixelWidth, const float pixelHeight, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 52 | 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 Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 54 | void clear(); |
| 55 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 56 | uint32_t getSize() const { |
| 57 | return mCache.size(); |
| 58 | } |
| 59 | |
| 60 | uint32_t getMaxSize() const { |
| 61 | return mMaxEntries; |
| 62 | } |
| 63 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 64 | private: |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 65 | /** |
| 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 Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 83 | 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 Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 114 | uint32_t mMaxEntries; |
| 115 | KeyedVector<PatchDescription, Patch*> mCache; |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 116 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 117 | }; // class PatchCache |
| 118 | |
| 119 | }; // namespace uirenderer |
| 120 | }; // namespace android |
| 121 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 122 | #endif // ANDROID_HWUI_PATCH_CACHE_H |