2010-10-08 08:37:55 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#ifndef ANDROID_HWUI_RESOURCE_CACHE_H
|
|
|
|
#define ANDROID_HWUI_RESOURCE_CACHE_H
|
2010-10-08 08:37:55 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
#include <cutils/compiler.h>
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
#include <SkBitmap.h>
|
2014-12-04 15:20:29 -05:00
|
|
|
#include <SkPixelRef.h>
|
2013-06-26 15:45:41 -07:00
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
#include <utils/KeyedVector.h>
|
2014-11-06 09:45:10 -08:00
|
|
|
#include <utils/Singleton.h>
|
2013-06-26 15:45:41 -07:00
|
|
|
|
|
|
|
#include <androidfw/ResourceTypes.h>
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2014-10-15 15:46:42 -04:00
|
|
|
class Layer;
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
/**
|
|
|
|
* Type of Resource being cached
|
|
|
|
*/
|
|
|
|
enum ResourceType {
|
2013-06-26 15:45:41 -07:00
|
|
|
kNinePatch,
|
2010-10-08 08:37:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceReference {
|
|
|
|
public:
|
|
|
|
|
|
|
|
ResourceReference(ResourceType type) {
|
2014-12-04 15:20:29 -05:00
|
|
|
refCount = 0; destroyed = false; resourceType = type;
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int refCount;
|
|
|
|
bool destroyed;
|
|
|
|
ResourceType resourceType;
|
|
|
|
};
|
|
|
|
|
2014-11-06 09:45:10 -08:00
|
|
|
class ANDROID_API ResourceCache: public Singleton<ResourceCache> {
|
2010-10-08 08:37:55 -07:00
|
|
|
ResourceCache();
|
|
|
|
~ResourceCache();
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2014-11-06 09:45:10 -08:00
|
|
|
friend class Singleton<ResourceCache>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
/**
|
|
|
|
* When using these two methods, make sure to only invoke the *Locked()
|
|
|
|
* variants of increment/decrementRefcount(), recyle() and destructor()
|
|
|
|
*/
|
|
|
|
void lock();
|
|
|
|
void unlock();
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void incrementRefcount(const Res_png_9patch* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void decrementRefcount(const Res_png_9patch* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void decrementRefcountLocked(const Res_png_9patch* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2013-06-26 15:45:41 -07:00
|
|
|
void destructor(Res_png_9patch* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2013-06-26 15:45:41 -07:00
|
|
|
void destructorLocked(Res_png_9patch* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
private:
|
2014-01-02 17:13:34 -08:00
|
|
|
void deleteResourceReferenceLocked(const void* resource, ResourceReference* ref);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void incrementRefcount(void* resource, ResourceType resourceType);
|
2012-09-07 11:58:36 -07:00
|
|
|
void incrementRefcountLocked(void* resource, ResourceType resourceType);
|
|
|
|
|
|
|
|
void decrementRefcount(void* resource);
|
|
|
|
void decrementRefcountLocked(void* resource);
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void logCache();
|
2010-11-11 16:30:16 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to increment, decrement, and destroy. Incrementing is generally accessed on the UI
|
|
|
|
* thread, but destroying resources may be called from the GC thread, the finalizer thread,
|
|
|
|
* or a reference queue finalization thread.
|
|
|
|
*/
|
|
|
|
mutable Mutex mLock;
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
KeyedVector<const void*, ResourceReference*>* mCache;
|
2010-10-08 08:37:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif // ANDROID_HWUI_RESOURCE_CACHE_H
|