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 | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 20 | #include <GLES2/gl2.h> |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 21 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 22 | #include <utils/LruCache.h> |
| 23 | |
| 24 | #include <androidfw/ResourceTypes.h> |
| 25 | |
| 26 | #include "AssetAtlas.h" |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 27 | #include "Debug.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 28 | #include "Patch.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | |
| 33 | /////////////////////////////////////////////////////////////////////////////// |
| 34 | // Defines |
| 35 | /////////////////////////////////////////////////////////////////////////////// |
| 36 | |
| 37 | // Debug |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 38 | #if DEBUG_PATCHES |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 39 | #define PATCH_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 40 | #else |
| 41 | #define PATCH_LOGD(...) |
| 42 | #endif |
| 43 | |
| 44 | /////////////////////////////////////////////////////////////////////////////// |
| 45 | // Cache |
| 46 | /////////////////////////////////////////////////////////////////////////////// |
| 47 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 48 | class Caches; |
| 49 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 50 | class PatchCache { |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 51 | public: |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 52 | PatchCache(); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 53 | ~PatchCache(); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 54 | void init(Caches& caches); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 55 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 56 | const Patch* get(const AssetAtlas::Entry* entry, |
| 57 | const uint32_t bitmapWidth, const uint32_t bitmapHeight, |
| 58 | const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 59 | void clear(); |
| 60 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 61 | uint32_t getSize() const { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 62 | return mSize; |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | uint32_t getMaxSize() const { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 66 | return mMaxSize; |
| 67 | } |
| 68 | |
| 69 | GLuint getMeshBuffer() const { |
| 70 | return mMeshBuffer; |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 73 | uint32_t getGenerationId() const { |
| 74 | return mGenerationId; |
| 75 | } |
| 76 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 77 | private: |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 78 | void clearCache(); |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 79 | void createVertexBuffer(); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 80 | |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 81 | struct PatchDescription { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 82 | PatchDescription(): mPatch(NULL), mBitmapWidth(0), mBitmapHeight(0), |
| 83 | mPixelWidth(0), mPixelHeight(0) { |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Romain Guy | 13ba005 | 2013-02-15 12:47:26 -0800 | [diff] [blame] | 86 | PatchDescription(const uint32_t bitmapWidth, const uint32_t bitmapHeight, |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 87 | const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch): |
| 88 | mPatch(patch), mBitmapWidth(bitmapWidth), mBitmapHeight(bitmapHeight), |
| 89 | mPixelWidth(pixelWidth), mPixelHeight(pixelHeight) { |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 92 | hash_t hash() const; |
| 93 | |
Romain Guy | 13ba005 | 2013-02-15 12:47:26 -0800 | [diff] [blame] | 94 | static int compare(const PatchDescription& lhs, const PatchDescription& rhs); |
| 95 | |
| 96 | bool operator==(const PatchDescription& other) const { |
| 97 | return compare(*this, other) == 0; |
| 98 | } |
| 99 | |
| 100 | bool operator!=(const PatchDescription& other) const { |
| 101 | return compare(*this, other) != 0; |
| 102 | } |
| 103 | |
| 104 | friend inline int strictly_order_type(const PatchDescription& lhs, |
| 105 | const PatchDescription& rhs) { |
| 106 | return PatchDescription::compare(lhs, rhs) < 0; |
| 107 | } |
| 108 | |
| 109 | friend inline int compare_type(const PatchDescription& lhs, |
| 110 | const PatchDescription& rhs) { |
| 111 | return PatchDescription::compare(lhs, rhs); |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 114 | friend inline hash_t hash_type(const PatchDescription& entry) { |
| 115 | return entry.hash(); |
| 116 | } |
| 117 | |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 118 | private: |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 119 | const Res_png_9patch* mPatch; |
| 120 | uint32_t mBitmapWidth; |
| 121 | uint32_t mBitmapHeight; |
| 122 | float mPixelWidth; |
| 123 | float mPixelHeight; |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 124 | |
| 125 | }; // struct PatchDescription |
| 126 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 127 | uint32_t mMaxSize; |
| 128 | uint32_t mSize; |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 129 | |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 130 | LruCache<PatchDescription, Patch*> mCache; |
| 131 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 132 | GLuint mMeshBuffer; |
Romain Guy | 7d9b1b3 | 2013-05-28 14:25:09 -0700 | [diff] [blame] | 133 | |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 134 | uint32_t mGenerationId; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 135 | }; // class PatchCache |
| 136 | |
| 137 | }; // namespace uirenderer |
| 138 | }; // namespace android |
| 139 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 140 | #endif // ANDROID_HWUI_PATCH_CACHE_H |