2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_HWUI_LAYER_CACHE_H
18 #define ANDROID_HWUI_LAYER_CACHE_H
26 namespace uirenderer {
30 ///////////////////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////////////////
35 #define LAYER_LOGD(...) ALOGD(__VA_ARGS__)
37 #define LAYER_LOGD(...)
40 ///////////////////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////////////////////////
50 * Returns a layer large enough for the specified dimensions. If no suitable
51 * layer can be found, a new one is created and returned. If creating a new
52 * layer fails, NULL is returned.
54 * When a layer is obtained from the cache, it is removed and the total
55 * size of the cache goes down.
57 * @param width The desired width of the layer
58 * @param height The desired height of the layer
60 Layer* get(RenderState& renderState, const uint32_t width, const uint32_t height);
63 * Adds the layer to the cache. The layer will not be added if there is
64 * not enough space available. Adding a layer can cause other layers to
65 * be removed from the cache.
67 * @param layer The layer to add to the cache
69 * @return True if the layer was added, false otherwise.
71 bool put(Layer* layer);
73 * Clears the cache. This causes all layers to be deleted.
78 * Sets the maximum size of the cache in bytes.
80 void setMaxSize(uint32_t maxSize);
82 * Returns the maximum size of the cache in bytes.
84 uint32_t getMaxSize();
86 * Returns the current size of the cache in bytes.
93 * Prints out the content of the cache.
100 mLayer(nullptr), mWidth(0), mHeight(0) {
103 LayerEntry(const uint32_t layerWidth, const uint32_t layerHeight): mLayer(nullptr) {
104 mWidth = Layer::computeIdealWidth(layerWidth);
105 mHeight = Layer::computeIdealHeight(layerHeight);
108 LayerEntry(Layer* layer):
109 mLayer(layer), mWidth(layer->getWidth()), mHeight(layer->getHeight()) {
112 static int compare(const LayerEntry& lhs, const LayerEntry& rhs);
114 bool operator==(const LayerEntry& other) const {
115 return compare(*this, other) == 0;
118 bool operator!=(const LayerEntry& other) const {
119 return compare(*this, other) != 0;
122 bool operator<(const LayerEntry& other) const {
123 return LayerEntry::compare(*this, other) < 0;
129 }; // struct LayerEntry
131 void deleteLayer(Layer* layer);
133 std::multiset<LayerEntry> mCache;
137 }; // class LayerCache
139 }; // namespace uirenderer
140 }; // namespace android
142 #endif // ANDROID_HWUI_LAYER_CACHE_H