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>
|
2010-10-22 16:17:12 -07:00
|
|
|
#include <SkiaColorFilter.h>
|
2010-10-08 08:37:55 -07:00
|
|
|
#include <SkiaShader.h>
|
|
|
|
#include <utils/KeyedVector.h>
|
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
2012-09-14 15:31:25 -07:00
|
|
|
#include "Layer.h"
|
2010-10-08 08:37:55 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of Resource being cached
|
|
|
|
*/
|
|
|
|
enum ResourceType {
|
|
|
|
kBitmap,
|
|
|
|
kShader,
|
2010-10-22 16:17:12 -07:00
|
|
|
kColorFilter,
|
2011-02-04 12:50:55 -08:00
|
|
|
kPath,
|
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
2012-09-14 15:31:25 -07:00
|
|
|
kLayer
|
2010-10-08 08:37:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceReference {
|
|
|
|
public:
|
|
|
|
|
|
|
|
ResourceReference() { refCount = 0; recycled = false; destroyed = false;}
|
|
|
|
ResourceReference(ResourceType type) {
|
|
|
|
refCount = 0; recycled = false; destroyed = false; resourceType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
int refCount;
|
|
|
|
bool recycled;
|
|
|
|
bool destroyed;
|
|
|
|
ResourceType resourceType;
|
|
|
|
};
|
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
class ANDROID_API ResourceCache {
|
2010-10-08 08:37:55 -07:00
|
|
|
public:
|
|
|
|
ResourceCache();
|
|
|
|
~ResourceCache();
|
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();
|
|
|
|
|
2011-02-04 12:50:55 -08:00
|
|
|
void incrementRefcount(SkPath* resource);
|
2010-10-08 08:37:55 -07:00
|
|
|
void incrementRefcount(SkBitmap* resource);
|
|
|
|
void incrementRefcount(SkiaShader* resource);
|
2010-10-22 16:17:12 -07:00
|
|
|
void incrementRefcount(SkiaColorFilter* resource);
|
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
2012-09-14 15:31:25 -07:00
|
|
|
void incrementRefcount(Layer* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
|
|
|
void incrementRefcountLocked(SkPath* resource);
|
|
|
|
void incrementRefcountLocked(SkBitmap* resource);
|
|
|
|
void incrementRefcountLocked(SkiaShader* resource);
|
|
|
|
void incrementRefcountLocked(SkiaColorFilter* resource);
|
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
2012-09-14 15:31:25 -07:00
|
|
|
void incrementRefcountLocked(Layer* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
void decrementRefcount(SkBitmap* resource);
|
2011-02-04 12:50:55 -08:00
|
|
|
void decrementRefcount(SkPath* resource);
|
2010-10-08 08:37:55 -07:00
|
|
|
void decrementRefcount(SkiaShader* resource);
|
2010-10-22 16:17:12 -07:00
|
|
|
void decrementRefcount(SkiaColorFilter* resource);
|
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
2012-09-14 15:31:25 -07:00
|
|
|
void decrementRefcount(Layer* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
|
|
|
void decrementRefcountLocked(SkBitmap* resource);
|
|
|
|
void decrementRefcountLocked(SkPath* resource);
|
|
|
|
void decrementRefcountLocked(SkiaShader* resource);
|
|
|
|
void decrementRefcountLocked(SkiaColorFilter* resource);
|
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
2012-09-14 15:31:25 -07:00
|
|
|
void decrementRefcountLocked(Layer* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2011-02-04 12:50:55 -08:00
|
|
|
void destructor(SkPath* resource);
|
2010-10-08 08:37:55 -07:00
|
|
|
void destructor(SkBitmap* resource);
|
|
|
|
void destructor(SkiaShader* resource);
|
2010-10-22 16:17:12 -07:00
|
|
|
void destructor(SkiaColorFilter* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
|
|
|
void destructorLocked(SkPath* resource);
|
|
|
|
void destructorLocked(SkBitmap* resource);
|
|
|
|
void destructorLocked(SkiaShader* resource);
|
|
|
|
void destructorLocked(SkiaColorFilter* resource);
|
|
|
|
|
2012-10-22 15:07:26 -07:00
|
|
|
bool recycle(SkBitmap* resource);
|
|
|
|
bool recycleLocked(SkBitmap* resource);
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
private:
|
2012-09-23 17:46:45 -07:00
|
|
|
void deleteResourceReferenceLocked(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
|
|
|
|
|
|
|
KeyedVector<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
|