blob: dc67e160fabf8c2da5644f8d917fdf480be4b45c [file] [log] [blame]
Romain Guy7fbcc042010-08-04 15:40:07 -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_PATH_CACHE_H
18#define ANDROID_HWUI_PATH_CACHE_H
Romain Guy7fbcc042010-08-04 15:40:07 -070019
Romain Guyfe48f652010-11-11 15:36:56 -080020#include <utils/Vector.h>
21
Romain Guyc15008e2010-11-10 11:59:15 -080022#include "Debug.h"
Romain Guyff26a0c2011-01-20 11:35:46 -080023#include "ShapeCache.h"
24
Romain Guy4bb94202010-10-12 15:59:26 -070025#include "utils/Compare.h"
Romain Guy7fbcc042010-08-04 15:40:07 -070026
27namespace android {
28namespace uirenderer {
29
Romain Guy9e108412010-11-09 14:35:20 -080030///////////////////////////////////////////////////////////////////////////////
Romain Guy9e108412010-11-09 14:35:20 -080031// Classes
32///////////////////////////////////////////////////////////////////////////////
33
Romain Guyff26a0c2011-01-20 11:35:46 -080034struct PathCacheEntry: public ShapeCacheEntry {
35 PathCacheEntry(SkPath* path, SkPaint* paint):
36 ShapeCacheEntry(ShapeCacheEntry::kShapePath, paint) {
37 this->path = path;
38 }
39
40 PathCacheEntry(): ShapeCacheEntry() {
Romain Guy7fbcc042010-08-04 15:40:07 -070041 path = NULL;
Romain Guy7fbcc042010-08-04 15:40:07 -070042 }
43
44 PathCacheEntry(const PathCacheEntry& entry):
Romain Guyff26a0c2011-01-20 11:35:46 -080045 ShapeCacheEntry(entry) {
46 path = entry.path;
Romain Guy7fbcc042010-08-04 15:40:07 -070047 }
48
Romain Guyff26a0c2011-01-20 11:35:46 -080049 bool lessThan(const ShapeCacheEntry& r) const {
50 const PathCacheEntry& rhs = (const PathCacheEntry&) r;
Romain Guy2665b852010-10-18 15:11:50 -070051 LTE_INT(path) {
Romain Guyff26a0c2011-01-20 11:35:46 -080052 return false;
Romain Guy4bb94202010-10-12 15:59:26 -070053 }
54 return false;
Romain Guy7fbcc042010-08-04 15:40:07 -070055 }
Romain Guy7fbcc042010-08-04 15:40:07 -070056
Romain Guyff26a0c2011-01-20 11:35:46 -080057 SkPath* path;
58}; // PathCacheEntry
Romain Guy7fbcc042010-08-04 15:40:07 -070059
60/**
61 * A simple LRU path cache. The cache has a maximum size expressed in bytes.
62 * Any texture added to the cache causing the cache to grow beyond the maximum
63 * allowed size will also cause the oldest texture to be kicked out.
64 */
Romain Guyff26a0c2011-01-20 11:35:46 -080065class PathCache: public ShapeCache<PathCacheEntry> {
Romain Guy7fbcc042010-08-04 15:40:07 -070066public:
Romain Guyfb8b7632010-08-23 21:05:08 -070067 PathCache();
Romain Guy7fbcc042010-08-04 15:40:07 -070068
69 /**
70 * Returns the texture associated with the specified path. If the texture
71 * cannot be found in the cache, a new texture is generated.
72 */
73 PathTexture* get(SkPath* path, SkPaint* paint);
74 /**
Romain Guya2341a92010-09-08 18:04:33 -070075 * Removes an entry.
76 */
77 void remove(SkPath* path);
Romain Guyfe48f652010-11-11 15:36:56 -080078 /**
79 * Removes the specified path. This is meant to be called from threads
80 * that are not the EGL context thread.
81 */
82 void removeDeferred(SkPath* path);
83 /**
84 * Process deferred removals.
85 */
86 void clearGarbage();
Romain Guy7fbcc042010-08-04 15:40:07 -070087
Romain Guy7fbcc042010-08-04 15:40:07 -070088private:
Romain Guyfe48f652010-11-11 15:36:56 -080089 Vector<SkPath*> mGarbage;
Romain Guya2341a92010-09-08 18:04:33 -070090 mutable Mutex mLock;
Romain Guy7fbcc042010-08-04 15:40:07 -070091}; // class PathCache
92
93}; // namespace uirenderer
94}; // namespace android
95
Romain Guy5b3b3522010-10-27 18:57:51 -070096#endif // ANDROID_HWUI_PATH_CACHE_H