am eb2dcc79
: Merge "Don\'t preload textures for AssetAtlas" into lmp-mr1-dev
automerge: e4a6ed9
* commit 'e4a6ed9d6d8721c9fad018b0d43dfe7daf4b24e7':
Don't preload textures for AssetAtlas
This commit is contained in:
@ -36,39 +36,37 @@ void AssetAtlas::init(sp<GraphicBuffer> buffer, int64_t* map, int count) {
|
|||||||
ATRACE_NAME("AssetAtlas::init");
|
ATRACE_NAME("AssetAtlas::init");
|
||||||
|
|
||||||
mImage = new Image(buffer);
|
mImage = new Image(buffer);
|
||||||
|
|
||||||
if (mImage->getTexture()) {
|
if (mImage->getTexture()) {
|
||||||
|
if (!mTexture) {
|
||||||
Caches& caches = Caches::getInstance();
|
Caches& caches = Caches::getInstance();
|
||||||
|
|
||||||
mTexture = new Texture(caches);
|
mTexture = new Texture(caches);
|
||||||
mTexture->id = mImage->getTexture();
|
|
||||||
mTexture->width = buffer->getWidth();
|
mTexture->width = buffer->getWidth();
|
||||||
mTexture->height = buffer->getHeight();
|
mTexture->height = buffer->getHeight();
|
||||||
|
|
||||||
createEntries(caches, map, count);
|
createEntries(caches, map, count);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ALOGW("Could not create atlas image");
|
ALOGW("Could not create atlas image");
|
||||||
|
|
||||||
delete mImage;
|
delete mImage;
|
||||||
mImage = NULL;
|
mImage = NULL;
|
||||||
mTexture = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mGenerationId++;
|
updateTextureId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetAtlas::terminate() {
|
void AssetAtlas::terminate() {
|
||||||
if (mImage) {
|
if (mImage) {
|
||||||
delete mImage;
|
delete mImage;
|
||||||
mImage = NULL;
|
mImage = NULL;
|
||||||
|
updateTextureId();
|
||||||
delete mTexture;
|
|
||||||
mTexture = NULL;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < mEntries.size(); i++) {
|
|
||||||
delete mEntries.valueAt(i);
|
|
||||||
}
|
}
|
||||||
mEntries.clear();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AssetAtlas::updateTextureId() {
|
||||||
|
mTexture->id = mImage ? mImage->getTexture() : 0;
|
||||||
|
for (size_t i = 0; i < mEntries.size(); i++) {
|
||||||
|
AssetAtlas::Entry* entry = mEntries.valueAt(i);
|
||||||
|
entry->texture->id = mTexture->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +131,6 @@ void AssetAtlas::createEntries(Caches& caches, int64_t* map, int count) {
|
|||||||
y / height, (y + bitmap->height()) / height);
|
y / height, (y + bitmap->height()) / height);
|
||||||
|
|
||||||
Texture* texture = new DelegateTexture(caches, mTexture);
|
Texture* texture = new DelegateTexture(caches, mTexture);
|
||||||
texture->id = mTexture->id;
|
|
||||||
texture->blend = !bitmap->isOpaque();
|
texture->blend = !bitmap->isOpaque();
|
||||||
texture->width = bitmap->width();
|
texture->width = bitmap->width();
|
||||||
texture->height = bitmap->height();
|
texture->height = bitmap->height();
|
||||||
|
@ -106,7 +106,7 @@ public:
|
|||||||
friend class AssetAtlas;
|
friend class AssetAtlas;
|
||||||
};
|
};
|
||||||
|
|
||||||
AssetAtlas(): mTexture(NULL), mImage(NULL), mGenerationId(0),
|
AssetAtlas(): mTexture(NULL), mImage(NULL),
|
||||||
mBlendKey(true), mOpaqueKey(false) { }
|
mBlendKey(true), mOpaqueKey(false) { }
|
||||||
~AssetAtlas() { terminate(); }
|
~AssetAtlas() { terminate(); }
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ public:
|
|||||||
* After calling this method, the width, height
|
* After calling this method, the width, height
|
||||||
* and texture are set to 0.
|
* and texture are set to 0.
|
||||||
*/
|
*/
|
||||||
ANDROID_API void terminate();
|
void terminate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the width of this atlas in pixels.
|
* Returns the width of this atlas in pixels.
|
||||||
@ -168,21 +168,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
Texture* getEntryTexture(const SkBitmap* bitmap) const;
|
Texture* getEntryTexture(const SkBitmap* bitmap) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current generation id of the atlas.
|
|
||||||
*/
|
|
||||||
uint32_t getGenerationId() const {
|
|
||||||
return mGenerationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createEntries(Caches& caches, int64_t* map, int count);
|
void createEntries(Caches& caches, int64_t* map, int count);
|
||||||
|
void updateTextureId();
|
||||||
|
|
||||||
Texture* mTexture;
|
Texture* mTexture;
|
||||||
Image* mImage;
|
Image* mImage;
|
||||||
|
|
||||||
uint32_t mGenerationId;
|
|
||||||
|
|
||||||
const bool mBlendKey;
|
const bool mBlendKey;
|
||||||
const bool mOpaqueKey;
|
const bool mOpaqueKey;
|
||||||
|
|
||||||
|
@ -237,8 +237,6 @@ void Caches::terminate() {
|
|||||||
programCache.clear();
|
programCache.clear();
|
||||||
currentProgram = NULL;
|
currentProgram = NULL;
|
||||||
|
|
||||||
assetAtlas.terminate();
|
|
||||||
|
|
||||||
patchCache.clear();
|
patchCache.clear();
|
||||||
|
|
||||||
clearGarbage();
|
clearGarbage();
|
||||||
|
@ -348,8 +348,6 @@ public:
|
|||||||
Dither dither;
|
Dither dither;
|
||||||
Stencil stencil;
|
Stencil stencil;
|
||||||
|
|
||||||
AssetAtlas assetAtlas;
|
|
||||||
|
|
||||||
bool gpuPixelBuffersEnabled;
|
bool gpuPixelBuffersEnabled;
|
||||||
|
|
||||||
// Debug methods
|
// Debug methods
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "AssetAtlas.h"
|
#include "AssetAtlas.h"
|
||||||
#include "DeferredDisplayList.h"
|
#include "DeferredDisplayList.h"
|
||||||
#include "DisplayListRenderer.h"
|
#include "DisplayListRenderer.h"
|
||||||
|
#include "RenderState.h"
|
||||||
#include "UvMapper.h"
|
#include "UvMapper.h"
|
||||||
#include "utils/LinearAllocator.h"
|
#include "utils/LinearAllocator.h"
|
||||||
|
|
||||||
@ -647,24 +648,17 @@ public:
|
|||||||
DrawBitmapOp(const SkBitmap* bitmap, const SkPaint* paint)
|
DrawBitmapOp(const SkBitmap* bitmap, const SkPaint* paint)
|
||||||
: DrawBoundedOp(0, 0, bitmap->width(), bitmap->height(), paint)
|
: DrawBoundedOp(0, 0, bitmap->width(), bitmap->height(), paint)
|
||||||
, mBitmap(bitmap)
|
, mBitmap(bitmap)
|
||||||
, mAtlas(Caches::getInstance().assetAtlas) {
|
, mEntryValid(false), mEntry(NULL) {
|
||||||
mEntry = mAtlas.getEntry(bitmap);
|
|
||||||
if (mEntry) {
|
|
||||||
mEntryGenerationId = mAtlas.getGenerationId();
|
|
||||||
mUvMapper = mEntry->uvMapper;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
|
virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
|
||||||
return renderer.drawBitmap(mBitmap, getPaint(renderer));
|
return renderer.drawBitmap(mBitmap, getPaint(renderer));
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetAtlas::Entry* getAtlasEntry() {
|
AssetAtlas::Entry* getAtlasEntry(OpenGLRenderer& renderer) {
|
||||||
// The atlas entry is stale, let's get a new one
|
if (!mEntryValid) {
|
||||||
if (mEntry && mEntryGenerationId != mAtlas.getGenerationId()) {
|
mEntryValid = true;
|
||||||
mEntryGenerationId = mAtlas.getGenerationId();
|
mEntry = renderer.renderState().assetAtlas().getEntry(mBitmap);
|
||||||
mEntry = mAtlas.getEntry(mBitmap);
|
|
||||||
mUvMapper = mEntry->uvMapper;
|
|
||||||
}
|
}
|
||||||
return mEntry;
|
return mEntry;
|
||||||
}
|
}
|
||||||
@ -700,7 +694,7 @@ public:
|
|||||||
pureTranslate &= state.mMatrix.isPureTranslate();
|
pureTranslate &= state.mMatrix.isPureTranslate();
|
||||||
|
|
||||||
Rect texCoords(0, 0, 1, 1);
|
Rect texCoords(0, 0, 1, 1);
|
||||||
((DrawBitmapOp*) ops[i].op)->mUvMapper.map(texCoords);
|
((DrawBitmapOp*) ops[i].op)->uvMap(renderer, texCoords);
|
||||||
|
|
||||||
SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, top);
|
SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, top);
|
||||||
SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top);
|
SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top);
|
||||||
@ -729,7 +723,7 @@ public:
|
|||||||
virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
|
virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
|
||||||
const DeferredDisplayState& state) {
|
const DeferredDisplayState& state) {
|
||||||
deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
|
deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
|
||||||
deferInfo.mergeId = getAtlasEntry() ?
|
deferInfo.mergeId = getAtlasEntry(renderer) ?
|
||||||
(mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap;
|
(mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap;
|
||||||
|
|
||||||
// Don't merge non-simply transformed or neg scale ops, SET_TEXTURE doesn't handle rotation
|
// Don't merge non-simply transformed or neg scale ops, SET_TEXTURE doesn't handle rotation
|
||||||
@ -742,13 +736,17 @@ public:
|
|||||||
(mBitmap->colorType() != kAlpha_8_SkColorType);
|
(mBitmap->colorType() != kAlpha_8_SkColorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uvMap(OpenGLRenderer& renderer, Rect& texCoords) {
|
||||||
|
if (getAtlasEntry(renderer)) {
|
||||||
|
mEntry->uvMapper.map(texCoords);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const SkBitmap* bitmap() { return mBitmap; }
|
const SkBitmap* bitmap() { return mBitmap; }
|
||||||
protected:
|
protected:
|
||||||
const SkBitmap* mBitmap;
|
const SkBitmap* mBitmap;
|
||||||
const AssetAtlas& mAtlas;
|
bool mEntryValid;
|
||||||
uint32_t mEntryGenerationId;
|
|
||||||
AssetAtlas::Entry* mEntry;
|
AssetAtlas::Entry* mEntry;
|
||||||
UvMapper mUvMapper;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawBitmapRectOp : public DrawBoundedOp {
|
class DrawBitmapRectOp : public DrawBoundedOp {
|
||||||
@ -841,18 +839,13 @@ public:
|
|||||||
float left, float top, float right, float bottom, const SkPaint* paint)
|
float left, float top, float right, float bottom, const SkPaint* paint)
|
||||||
: DrawBoundedOp(left, top, right, bottom, paint),
|
: DrawBoundedOp(left, top, right, bottom, paint),
|
||||||
mBitmap(bitmap), mPatch(patch), mGenerationId(0), mMesh(NULL),
|
mBitmap(bitmap), mPatch(patch), mGenerationId(0), mMesh(NULL),
|
||||||
mAtlas(Caches::getInstance().assetAtlas) {
|
mEntryValid(false), mEntry(NULL) {
|
||||||
mEntry = mAtlas.getEntry(bitmap);
|
|
||||||
if (mEntry) {
|
|
||||||
mEntryGenerationId = mAtlas.getGenerationId();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AssetAtlas::Entry* getAtlasEntry() {
|
AssetAtlas::Entry* getAtlasEntry(OpenGLRenderer& renderer) {
|
||||||
// The atlas entry is stale, let's get a new one
|
if (!mEntryValid) {
|
||||||
if (mEntry && mEntryGenerationId != mAtlas.getGenerationId()) {
|
mEntryValid = true;
|
||||||
mEntryGenerationId = mAtlas.getGenerationId();
|
mEntry = renderer.renderState().assetAtlas().getEntry(mBitmap);
|
||||||
mEntry = mAtlas.getEntry(mBitmap);
|
|
||||||
}
|
}
|
||||||
return mEntry;
|
return mEntry;
|
||||||
}
|
}
|
||||||
@ -860,7 +853,7 @@ public:
|
|||||||
const Patch* getMesh(OpenGLRenderer& renderer) {
|
const Patch* getMesh(OpenGLRenderer& renderer) {
|
||||||
if (!mMesh || renderer.getCaches().patchCache.getGenerationId() != mGenerationId) {
|
if (!mMesh || renderer.getCaches().patchCache.getGenerationId() != mGenerationId) {
|
||||||
PatchCache& cache = renderer.getCaches().patchCache;
|
PatchCache& cache = renderer.getCaches().patchCache;
|
||||||
mMesh = cache.get(getAtlasEntry(), mBitmap->width(), mBitmap->height(),
|
mMesh = cache.get(getAtlasEntry(renderer), mBitmap->width(), mBitmap->height(),
|
||||||
mLocalBounds.getWidth(), mLocalBounds.getHeight(), mPatch);
|
mLocalBounds.getWidth(), mLocalBounds.getHeight(), mPatch);
|
||||||
mGenerationId = cache.getGenerationId();
|
mGenerationId = cache.getGenerationId();
|
||||||
}
|
}
|
||||||
@ -942,14 +935,14 @@ public:
|
|||||||
indexCount += opMesh->indexCount;
|
indexCount += opMesh->indexCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return renderer.drawPatches(mBitmap, getAtlasEntry(),
|
return renderer.drawPatches(mBitmap, getAtlasEntry(renderer),
|
||||||
&vertices[0], indexCount, getPaint(renderer));
|
&vertices[0], indexCount, getPaint(renderer));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
|
virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
|
||||||
// We're not calling the public variant of drawPatch() here
|
// We're not calling the public variant of drawPatch() here
|
||||||
// This method won't perform the quickReject() since we've already done it at this point
|
// This method won't perform the quickReject() since we've already done it at this point
|
||||||
return renderer.drawPatch(mBitmap, getMesh(renderer), getAtlasEntry(),
|
return renderer.drawPatch(mBitmap, getMesh(renderer), getAtlasEntry(renderer),
|
||||||
mLocalBounds.left, mLocalBounds.top, mLocalBounds.right, mLocalBounds.bottom,
|
mLocalBounds.left, mLocalBounds.top, mLocalBounds.right, mLocalBounds.bottom,
|
||||||
getPaint(renderer));
|
getPaint(renderer));
|
||||||
}
|
}
|
||||||
@ -964,7 +957,7 @@ public:
|
|||||||
virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
|
virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
|
||||||
const DeferredDisplayState& state) {
|
const DeferredDisplayState& state) {
|
||||||
deferInfo.batchId = DeferredDisplayList::kOpBatch_Patch;
|
deferInfo.batchId = DeferredDisplayList::kOpBatch_Patch;
|
||||||
deferInfo.mergeId = getAtlasEntry() ? (mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap;
|
deferInfo.mergeId = getAtlasEntry(renderer) ? (mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap;
|
||||||
deferInfo.mergeable = state.mMatrix.isPureTranslate() &&
|
deferInfo.mergeable = state.mMatrix.isPureTranslate() &&
|
||||||
OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode;
|
OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode;
|
||||||
deferInfo.opaqueOverBounds = isOpaqueOverBounds(state) && mBitmap->isOpaque();
|
deferInfo.opaqueOverBounds = isOpaqueOverBounds(state) && mBitmap->isOpaque();
|
||||||
@ -977,8 +970,7 @@ private:
|
|||||||
uint32_t mGenerationId;
|
uint32_t mGenerationId;
|
||||||
const Patch* mMesh;
|
const Patch* mMesh;
|
||||||
|
|
||||||
const AssetAtlas& mAtlas;
|
bool mEntryValid;
|
||||||
uint32_t mEntryGenerationId;
|
|
||||||
AssetAtlas::Entry* mEntry;
|
AssetAtlas::Entry* mEntry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2057,7 +2057,7 @@ status_t OpenGLRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
mCaches.activeTexture(0);
|
mCaches.activeTexture(0);
|
||||||
Texture* texture = mCaches.assetAtlas.getEntryTexture(bitmap);
|
Texture* texture = mRenderState.assetAtlas().getEntryTexture(bitmap);
|
||||||
const UvMapper& mapper(getMapper(texture));
|
const UvMapper& mapper(getMapper(texture));
|
||||||
|
|
||||||
for (int32_t y = 0; y < meshHeight; y++) {
|
for (int32_t y = 0; y < meshHeight; y++) {
|
||||||
@ -2240,7 +2240,7 @@ status_t OpenGLRenderer::drawPatch(const SkBitmap* bitmap, const Res_png_9patch*
|
|||||||
return DrawGlInfo::kStatusDone;
|
return DrawGlInfo::kStatusDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetAtlas::Entry* entry = mCaches.assetAtlas.getEntry(bitmap);
|
AssetAtlas::Entry* entry = mRenderState.assetAtlas().getEntry(bitmap);
|
||||||
const Patch* mesh = mCaches.patchCache.get(entry, bitmap->width(), bitmap->height(),
|
const Patch* mesh = mCaches.patchCache.get(entry, bitmap->width(), bitmap->height(),
|
||||||
right - left, bottom - top, patch);
|
right - left, bottom - top, patch);
|
||||||
|
|
||||||
@ -3036,7 +3036,7 @@ const SkPaint* OpenGLRenderer::filterPaint(const SkPaint* paint) {
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Texture* OpenGLRenderer::getTexture(const SkBitmap* bitmap) {
|
Texture* OpenGLRenderer::getTexture(const SkBitmap* bitmap) {
|
||||||
Texture* texture = mCaches.assetAtlas.getEntryTexture(bitmap);
|
Texture* texture = mRenderState.assetAtlas().getEntryTexture(bitmap);
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
return mCaches.textureCache.get(bitmap);
|
return mCaches.textureCache.get(bitmap);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ void RenderState::onGLContextCreated() {
|
|||||||
mCaches = &Caches::getInstance();
|
mCaches = &Caches::getInstance();
|
||||||
mCaches->init();
|
mCaches->init();
|
||||||
mCaches->setRenderState(this);
|
mCaches->setRenderState(this);
|
||||||
|
mCaches->textureCache.setAssetAtlas(&mAssetAtlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderState::onGLContextDestroyed() {
|
void RenderState::onGLContextDestroyed() {
|
||||||
@ -72,6 +73,7 @@ void RenderState::onGLContextDestroyed() {
|
|||||||
LOG_ALWAYS_FATAL("%d layers have survived gl context destruction", size);
|
LOG_ALWAYS_FATAL("%d layers have survived gl context destruction", size);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
mAssetAtlas.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderState::setViewport(GLsizei width, GLsizei height) {
|
void RenderState::setViewport(GLsizei width, GLsizei height) {
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <private/hwui/DrawGlInfo.h>
|
#include <private/hwui/DrawGlInfo.h>
|
||||||
|
|
||||||
|
#include "AssetAtlas.h"
|
||||||
#include "Caches.h"
|
#include "Caches.h"
|
||||||
#include "utils/Macros.h"
|
#include "utils/Macros.h"
|
||||||
|
|
||||||
@ -73,6 +74,8 @@ public:
|
|||||||
// more thinking...
|
// more thinking...
|
||||||
void postDecStrong(VirtualLightRefBase* object);
|
void postDecStrong(VirtualLightRefBase* object);
|
||||||
|
|
||||||
|
AssetAtlas& assetAtlas() { return mAssetAtlas; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class renderthread::RenderThread;
|
friend class renderthread::RenderThread;
|
||||||
friend class Caches;
|
friend class Caches;
|
||||||
@ -86,6 +89,7 @@ private:
|
|||||||
|
|
||||||
renderthread::RenderThread& mRenderThread;
|
renderthread::RenderThread& mRenderThread;
|
||||||
Caches* mCaches;
|
Caches* mCaches;
|
||||||
|
AssetAtlas mAssetAtlas;
|
||||||
std::set<const Layer*> mActiveLayers;
|
std::set<const Layer*> mActiveLayers;
|
||||||
std::set<renderthread::CanvasContext*> mRegisteredContexts;
|
std::set<renderthread::CanvasContext*> mRegisteredContexts;
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <utils/Mutex.h>
|
#include <utils/Mutex.h>
|
||||||
|
|
||||||
|
#include "AssetAtlas.h"
|
||||||
#include "Caches.h"
|
#include "Caches.h"
|
||||||
#include "TextureCache.h"
|
#include "TextureCache.h"
|
||||||
#include "Properties.h"
|
#include "Properties.h"
|
||||||
@ -39,7 +40,7 @@ namespace uirenderer {
|
|||||||
TextureCache::TextureCache():
|
TextureCache::TextureCache():
|
||||||
mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity),
|
mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity),
|
||||||
mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
|
mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
|
||||||
mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) {
|
mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE), mAssetAtlas(0) {
|
||||||
char property[PROPERTY_VALUE_MAX];
|
char property[PROPERTY_VALUE_MAX];
|
||||||
if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
|
if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
|
||||||
INIT_LOGD(" Setting texture cache size to %sMB", property);
|
INIT_LOGD(" Setting texture cache size to %sMB", property);
|
||||||
@ -62,7 +63,7 @@ TextureCache::TextureCache():
|
|||||||
|
|
||||||
TextureCache::TextureCache(uint32_t maxByteSize):
|
TextureCache::TextureCache(uint32_t maxByteSize):
|
||||||
mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity),
|
mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity),
|
||||||
mSize(0), mMaxSize(maxByteSize) {
|
mSize(0), mMaxSize(maxByteSize), mAssetAtlas(0) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +125,10 @@ void TextureCache::operator()(uint32_t&, Texture*& texture) {
|
|||||||
// Caching
|
// Caching
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void TextureCache::setAssetAtlas(AssetAtlas* assetAtlas) {
|
||||||
|
mAssetAtlas = assetAtlas;
|
||||||
|
}
|
||||||
|
|
||||||
void TextureCache::resetMarkInUse() {
|
void TextureCache::resetMarkInUse() {
|
||||||
LruCache<uint32_t, Texture*>::Iterator iter(mCache);
|
LruCache<uint32_t, Texture*>::Iterator iter(mCache);
|
||||||
while (iter.next()) {
|
while (iter.next()) {
|
||||||
@ -143,6 +148,13 @@ bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) {
|
|||||||
// Returns a prepared Texture* that either is already in the cache or can fit
|
// Returns a prepared Texture* that either is already in the cache or can fit
|
||||||
// in the cache (and is thus added to the cache)
|
// in the cache (and is thus added to the cache)
|
||||||
Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
|
Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
|
||||||
|
if (CC_LIKELY(mAssetAtlas)) {
|
||||||
|
AssetAtlas::Entry* entry = mAssetAtlas->getEntry(bitmap);
|
||||||
|
if (CC_UNLIKELY(entry)) {
|
||||||
|
return entry->texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Texture* texture = mCache.get(bitmap->pixelRef()->getStableID());
|
Texture* texture = mCache.get(bitmap->pixelRef()->getStableID());
|
||||||
|
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
|
@ -44,6 +44,8 @@ namespace uirenderer {
|
|||||||
// Classes
|
// Classes
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class AssetAtlas;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple LRU texture cache. The cache has a maximum size expressed in bytes.
|
* A simple LRU texture cache. The cache has a maximum size expressed in bytes.
|
||||||
* Any texture added to the cache causing the cache to grow beyond the maximum
|
* Any texture added to the cache causing the cache to grow beyond the maximum
|
||||||
@ -123,6 +125,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setFlushRate(float flushRate);
|
void setFlushRate(float flushRate);
|
||||||
|
|
||||||
|
void setAssetAtlas(AssetAtlas* assetAtlas);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool canMakeTextureFromBitmap(const SkBitmap* bitmap);
|
bool canMakeTextureFromBitmap(const SkBitmap* bitmap);
|
||||||
@ -155,6 +159,8 @@ private:
|
|||||||
|
|
||||||
Vector<uint32_t> mGarbage;
|
Vector<uint32_t> mGarbage;
|
||||||
mutable Mutex mLock;
|
mutable Mutex mLock;
|
||||||
|
|
||||||
|
AssetAtlas* mAssetAtlas;
|
||||||
}; // class TextureCache
|
}; // class TextureCache
|
||||||
|
|
||||||
}; // namespace uirenderer
|
}; // namespace uirenderer
|
||||||
|
@ -175,7 +175,8 @@ void EglManager::setTextureAtlas(const sp<GraphicBuffer>& buffer,
|
|||||||
|
|
||||||
void EglManager::initAtlas() {
|
void EglManager::initAtlas() {
|
||||||
if (mAtlasBuffer.get()) {
|
if (mAtlasBuffer.get()) {
|
||||||
Caches::getInstance().assetAtlas.init(mAtlasBuffer, mAtlasMap, mAtlasMapSize);
|
mRenderThread.renderState().assetAtlas().init(mAtlasBuffer,
|
||||||
|
mAtlasMap, mAtlasMapSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user