Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62a2696c authored by Chris Craik's avatar Chris Craik Committed by Android Git Automerger
Browse files

am fbd2d949: am b6e41a08: am 0bb5c26b: Merge "Fix AssetAtlas usage in BitmapShaders" into mnc-dev

* commit 'fbd2d949':
  Fix AssetAtlas usage in BitmapShaders
parents 931d3cc9 fbd2d949
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -203,7 +203,13 @@ bool tryStoreBitmap(Caches& caches, const SkShader& shader, const Matrix4& model
        return false;
        return false;
    }
    }


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


    outData->bitmapSampler = (*textureUnit)++;
    outData->bitmapSampler = (*textureUnit)++;
+5 −5
Original line number Original line Diff line number Diff line
@@ -140,8 +140,8 @@ 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, AtlasUsageType atlasUsageType) {
    if (CC_LIKELY(mAssetAtlas)) {
    if (CC_LIKELY(mAssetAtlas != nullptr) && atlasUsageType == AtlasUsageType::Use) {
        AssetAtlas::Entry* entry = mAssetAtlas->getEntry(bitmap);
        AssetAtlas::Entry* entry = mAssetAtlas->getEntry(bitmap);
        if (CC_UNLIKELY(entry)) {
        if (CC_UNLIKELY(entry)) {
            return entry->texture;
            return entry->texture;
@@ -190,15 +190,15 @@ Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
}
}


bool TextureCache::prefetchAndMarkInUse(const SkBitmap* bitmap) {
bool TextureCache::prefetchAndMarkInUse(const SkBitmap* bitmap) {
    Texture* texture = getCachedTexture(bitmap);
    Texture* texture = getCachedTexture(bitmap, AtlasUsageType::Use);
    if (texture) {
    if (texture) {
        texture->isInUse = true;
        texture->isInUse = true;
    }
    }
    return texture;
    return texture;
}
}


Texture* TextureCache::get(const SkBitmap* bitmap) {
Texture* TextureCache::get(const SkBitmap* bitmap, AtlasUsageType atlasUsageType) {
    Texture* texture = getCachedTexture(bitmap);
    Texture* texture = getCachedTexture(bitmap, atlasUsageType);


    if (!texture) {
    if (!texture) {
        if (!canMakeTextureFromBitmap(bitmap)) {
        if (!canMakeTextureFromBitmap(bitmap)) {
+19 −4
Original line number Original line Diff line number Diff line
@@ -76,10 +76,20 @@ public:
    bool prefetchAndMarkInUse(const SkBitmap* bitmap);
    bool prefetchAndMarkInUse(const SkBitmap* bitmap);


    /**
    /**
     * Returns the texture associated with the specified bitmap. If the texture
     * Returns the texture associated with the specified bitmap from either within the cache, or
     * cannot be found in the cache, a new texture is generated.
     * the AssetAtlas. If the texture cannot be found in the cache, a new texture is generated.
     */
     */
    Texture* get(const SkBitmap* bitmap);
    Texture* get(const SkBitmap* bitmap) {
        return get(bitmap, AtlasUsageType::Use);
    }

    /**
     * Returns the texture associated with the specified bitmap. If the texture cannot be found in
     * the cache, a new texture is generated, even if it resides in the AssetAtlas.
     */
    Texture* getAndBypassAtlas(const SkBitmap* bitmap) {
        return get(bitmap, AtlasUsageType::Bypass);
    }


    /**
    /**
     * Removes the texture associated with the specified pixelRef. This is meant
     * Removes the texture associated with the specified pixelRef. This is meant
@@ -123,10 +133,15 @@ public:
    void setAssetAtlas(AssetAtlas* assetAtlas);
    void setAssetAtlas(AssetAtlas* assetAtlas);


private:
private:
    enum class AtlasUsageType {
        Use,
        Bypass,
    };


    bool canMakeTextureFromBitmap(const SkBitmap* bitmap);
    bool canMakeTextureFromBitmap(const SkBitmap* bitmap);


    Texture* getCachedTexture(const SkBitmap* bitmap);
    Texture* get(const SkBitmap* bitmap, AtlasUsageType atlasUsageType);
    Texture* getCachedTexture(const SkBitmap* bitmap, AtlasUsageType atlasUsageType);


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