PatchCache.h revision 5baa3a62a97544669fba6d65a11c07f252e654dd
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
17#ifndef ANDROID_HWUI_PATCH_CACHE_H
18#define ANDROID_HWUI_PATCH_CACHE_H
19
20#include <utils/KeyedVector.h>
21
22#include "utils/Compare.h"
23#include "Debug.h"
24#include "Patch.h"
25
26namespace android {
27namespace uirenderer {
28
29///////////////////////////////////////////////////////////////////////////////
30// Defines
31///////////////////////////////////////////////////////////////////////////////
32
33// Debug
34#if DEBUG_PATCHES
35    #define PATCH_LOGD(...) ALOGD(__VA_ARGS__)
36#else
37    #define PATCH_LOGD(...)
38#endif
39
40///////////////////////////////////////////////////////////////////////////////
41// Cache
42///////////////////////////////////////////////////////////////////////////////
43
44class PatchCache {
45public:
46    PatchCache();
47    PatchCache(uint32_t maxCapacity);
48    ~PatchCache();
49
50    Patch* get(const float bitmapWidth, const float bitmapHeight,
51            const float pixelWidth, const float pixelHeight,
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);
54    void clear();
55
56    uint32_t getSize() const {
57        return mCache.size();
58    }
59
60    uint32_t getMaxSize() const {
61        return mMaxEntries;
62    }
63
64private:
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
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
114    uint32_t mMaxEntries;
115    KeyedVector<PatchDescription, Patch*> mCache;
116
117}; // class PatchCache
118
119}; // namespace uirenderer
120}; // namespace android
121
122#endif // ANDROID_HWUI_PATCH_CACHE_H
123