blob: cda27188fe105ac8255dcb2440732a90e7022ab8 [file] [log] [blame]
Chet Haase5c13d892010-10-08 08:37:55 -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
17#ifndef ANDROID_UI_RESOURCE_CACHE_H
18#define ANDROID_UI_RESOURCE_CACHE_H
19
20#include <SkBitmap.h>
21#include <SkMatrix.h>
22#include <SkPaint.h>
23#include <SkiaShader.h>
24#include <utils/KeyedVector.h>
25
26namespace android {
27namespace uirenderer {
28
29/**
30 * Type of Resource being cached
31 */
32enum ResourceType {
33 kBitmap,
34 kMatrix,
35 kPaint,
36 kShader,
37};
38
39class ResourceReference {
40public:
41
42 ResourceReference() { refCount = 0; recycled = false; destroyed = false;}
43 ResourceReference(ResourceType type) {
44 refCount = 0; recycled = false; destroyed = false; resourceType = type;
45 }
46
47 int refCount;
48 bool recycled;
49 bool destroyed;
50 ResourceType resourceType;
51};
52
53class ResourceCache {
54 KeyedVector<void *, ResourceReference *>* mCache;
55public:
56 ResourceCache();
57 ~ResourceCache();
58 void incrementRefcount(SkBitmap* resource);
59 void incrementRefcount(SkMatrix* resource);
60 void incrementRefcount(SkPaint* resource);
61 void incrementRefcount(SkiaShader* resource);
62 void incrementRefcount(const void* resource, ResourceType resourceType);
63 void decrementRefcount(void* resource);
64 void decrementRefcount(SkBitmap* resource);
65 void decrementRefcount(SkiaShader* resource);
66 void recycle(void* resource);
67 void recycle(SkBitmap* resource);
68 void destructor(SkBitmap* resource);
69 void destructor(SkMatrix* resource);
70 void destructor(SkPaint* resource);
71 void destructor(SkiaShader* resource);
72private:
73 void deleteResourceReference(void* resource, ResourceReference* ref);
74 void incrementRefcount(void* resource, ResourceType resourceType);
75 void logCache();
76};
77
78}; // namespace uirenderer
79}; // namespace android
80
81#endif // ANDROID_UI_RESOURCE_CACHE_H