Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -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_PATH_CACHE_H |
| 18 | #define ANDROID_HWUI_PATH_CACHE_H |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 19 | |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 20 | #include <utils/Vector.h> |
| 21 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 22 | #include "Debug.h" |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 23 | #include "ShapeCache.h" |
| 24 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 25 | #include "utils/Compare.h" |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
Romain Guy | 9e10841 | 2010-11-09 14:35:20 -0800 | [diff] [blame] | 30 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 9e10841 | 2010-11-09 14:35:20 -0800 | [diff] [blame] | 31 | // Classes |
| 32 | /////////////////////////////////////////////////////////////////////////////// |
| 33 | |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 34 | struct PathCacheEntry: public ShapeCacheEntry { |
| 35 | PathCacheEntry(SkPath* path, SkPaint* paint): |
| 36 | ShapeCacheEntry(ShapeCacheEntry::kShapePath, paint) { |
| 37 | this->path = path; |
| 38 | } |
| 39 | |
| 40 | PathCacheEntry(): ShapeCacheEntry() { |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 41 | path = NULL; |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 44 | bool lessThan(const ShapeCacheEntry& r) const { |
| 45 | const PathCacheEntry& rhs = (const PathCacheEntry&) r; |
Romain Guy | 2665b85 | 2010-10-18 15:11:50 -0700 | [diff] [blame] | 46 | LTE_INT(path) { |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 47 | return false; |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 48 | } |
| 49 | return false; |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 50 | } |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 51 | |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 52 | SkPath* path; |
Romain Guy | b29cfbf | 2011-03-18 16:24:19 -0700 | [diff] [blame] | 53 | |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 54 | }; // PathCacheEntry |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * A simple LRU path cache. The cache has a maximum size expressed in bytes. |
| 58 | * Any texture added to the cache causing the cache to grow beyond the maximum |
| 59 | * allowed size will also cause the oldest texture to be kicked out. |
| 60 | */ |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 61 | class PathCache: public ShapeCache<PathCacheEntry> { |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 62 | public: |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 63 | PathCache(); |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Returns the texture associated with the specified path. If the texture |
| 67 | * cannot be found in the cache, a new texture is generated. |
| 68 | */ |
| 69 | PathTexture* get(SkPath* path, SkPaint* paint); |
| 70 | /** |
Romain Guy | a2341a9 | 2010-09-08 18:04:33 -0700 | [diff] [blame] | 71 | * Removes an entry. |
| 72 | */ |
| 73 | void remove(SkPath* path); |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 74 | /** |
| 75 | * Removes the specified path. This is meant to be called from threads |
| 76 | * that are not the EGL context thread. |
| 77 | */ |
| 78 | void removeDeferred(SkPath* path); |
| 79 | /** |
| 80 | * Process deferred removals. |
| 81 | */ |
| 82 | void clearGarbage(); |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 83 | |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 84 | private: |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 85 | Vector<SkPath*> mGarbage; |
Romain Guy | a2341a9 | 2010-09-08 18:04:33 -0700 | [diff] [blame] | 86 | mutable Mutex mLock; |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 87 | }; // class PathCache |
| 88 | |
| 89 | }; // namespace uirenderer |
| 90 | }; // namespace android |
| 91 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 92 | #endif // ANDROID_HWUI_PATH_CACHE_H |