Skip to content

Commit 0bb5c26

Browse files
ChrisCraikAndroid (Google) Code Review
authored andcommitted
Merge "Fix AssetAtlas usage in BitmapShaders" into mnc-dev
2 parents 57ee4b8 + 6ad690e commit 0bb5c26

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

libs/hwui/SkiaShader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@ bool tryStoreBitmap(Caches& caches, const SkShader& shader, const Matrix4& model
203203
return false;
204204
}
205205

206-
outData->bitmapTexture = caches.textureCache.get(&bitmap);
206+
/*
207+
* Bypass the AssetAtlas, since those textures:
208+
* 1) require UV mapping, which isn't implemented in matrix computation below
209+
* 2) can't handle REPEAT simply
210+
* 3) are safe to upload here (outside of sync stage), since they're static
211+
*/
212+
outData->bitmapTexture = caches.textureCache.getAndBypassAtlas(&bitmap);
207213
if (!outData->bitmapTexture) return false;
208214

209215
outData->bitmapSampler = (*textureUnit)++;

libs/hwui/TextureCache.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) {
140140

141141
// Returns a prepared Texture* that either is already in the cache or can fit
142142
// in the cache (and is thus added to the cache)
143-
Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
144-
if (CC_LIKELY(mAssetAtlas)) {
143+
Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap, AtlasUsageType atlasUsageType) {
144+
if (CC_LIKELY(mAssetAtlas != nullptr) && atlasUsageType == AtlasUsageType::Use) {
145145
AssetAtlas::Entry* entry = mAssetAtlas->getEntry(bitmap);
146146
if (CC_UNLIKELY(entry)) {
147147
return entry->texture;
@@ -190,15 +190,15 @@ Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
190190
}
191191

192192
bool TextureCache::prefetchAndMarkInUse(const SkBitmap* bitmap) {
193-
Texture* texture = getCachedTexture(bitmap);
193+
Texture* texture = getCachedTexture(bitmap, AtlasUsageType::Use);
194194
if (texture) {
195195
texture->isInUse = true;
196196
}
197197
return texture;
198198
}
199199

200-
Texture* TextureCache::get(const SkBitmap* bitmap) {
201-
Texture* texture = getCachedTexture(bitmap);
200+
Texture* TextureCache::get(const SkBitmap* bitmap, AtlasUsageType atlasUsageType) {
201+
Texture* texture = getCachedTexture(bitmap, atlasUsageType);
202202

203203
if (!texture) {
204204
if (!canMakeTextureFromBitmap(bitmap)) {

libs/hwui/TextureCache.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,20 @@ class TextureCache : public OnEntryRemoved<uint32_t, Texture*> {
7676
bool prefetchAndMarkInUse(const SkBitmap* bitmap);
7777

7878
/**
79-
* Returns the texture associated with the specified bitmap. If the texture
80-
* cannot be found in the cache, a new texture is generated.
79+
* Returns the texture associated with the specified bitmap from either within the cache, or
80+
* the AssetAtlas. If the texture cannot be found in the cache, a new texture is generated.
8181
*/
82-
Texture* get(const SkBitmap* bitmap);
82+
Texture* get(const SkBitmap* bitmap) {
83+
return get(bitmap, AtlasUsageType::Use);
84+
}
85+
86+
/**
87+
* Returns the texture associated with the specified bitmap. If the texture cannot be found in
88+
* the cache, a new texture is generated, even if it resides in the AssetAtlas.
89+
*/
90+
Texture* getAndBypassAtlas(const SkBitmap* bitmap) {
91+
return get(bitmap, AtlasUsageType::Bypass);
92+
}
8393

8494
/**
8595
* Removes the texture associated with the specified pixelRef. This is meant
@@ -123,10 +133,15 @@ class TextureCache : public OnEntryRemoved<uint32_t, Texture*> {
123133
void setAssetAtlas(AssetAtlas* assetAtlas);
124134

125135
private:
136+
enum class AtlasUsageType {
137+
Use,
138+
Bypass,
139+
};
126140

127141
bool canMakeTextureFromBitmap(const SkBitmap* bitmap);
128142

129-
Texture* getCachedTexture(const SkBitmap* bitmap);
143+
Texture* get(const SkBitmap* bitmap, AtlasUsageType atlasUsageType);
144+
Texture* getCachedTexture(const SkBitmap* bitmap, AtlasUsageType atlasUsageType);
130145

131146
/**
132147
* Generates the texture from a bitmap into the specified texture structure.

0 commit comments

Comments
 (0)