blob: b5503674490bd6512d7379c569443fc34f5d6ca0 [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>
Chet Haase5c13d892010-10-08 08:37:55 -070021#include <SkiaShader.h>
22#include <utils/KeyedVector.h>
23
24namespace android {
25namespace uirenderer {
26
27/**
28 * Type of Resource being cached
29 */
30enum ResourceType {
31 kBitmap,
Chet Haase5c13d892010-10-08 08:37:55 -070032 kShader,
33};
34
35class ResourceReference {
36public:
37
38 ResourceReference() { refCount = 0; recycled = false; destroyed = false;}
39 ResourceReference(ResourceType type) {
40 refCount = 0; recycled = false; destroyed = false; resourceType = type;
41 }
42
43 int refCount;
44 bool recycled;
45 bool destroyed;
46 ResourceType resourceType;
47};
48
49class ResourceCache {
50 KeyedVector<void *, ResourceReference *>* mCache;
51public:
52 ResourceCache();
53 ~ResourceCache();
54 void incrementRefcount(SkBitmap* resource);
Chet Haase5c13d892010-10-08 08:37:55 -070055 void incrementRefcount(SkiaShader* resource);
56 void incrementRefcount(const void* resource, ResourceType resourceType);
57 void decrementRefcount(void* resource);
58 void decrementRefcount(SkBitmap* resource);
59 void decrementRefcount(SkiaShader* resource);
60 void recycle(void* resource);
61 void recycle(SkBitmap* resource);
62 void destructor(SkBitmap* resource);
Chet Haase5c13d892010-10-08 08:37:55 -070063 void destructor(SkiaShader* resource);
64private:
65 void deleteResourceReference(void* resource, ResourceReference* ref);
66 void incrementRefcount(void* resource, ResourceType resourceType);
67 void logCache();
68};
69
70}; // namespace uirenderer
71}; // namespace android
72
73#endif // ANDROID_UI_RESOURCE_CACHE_H