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

Commit 05279df2 authored by Alec Mouri's avatar Alec Mouri Committed by Android (Google) Code Review
Browse files

Merge "Clean up Renderengine caching semantics"

parents c086504b b5c4f351
Loading
Loading
Loading
Loading
+14 −43
Original line number Original line Diff line number Diff line
@@ -626,23 +626,14 @@ void GLESRenderEngine::bindExternalTextureImage(uint32_t texName, const Image& i
}
}


status_t GLESRenderEngine::bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer,
status_t GLESRenderEngine::bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer,
                                                     sp<Fence> bufferFence, bool readCache) {
                                                     sp<Fence> bufferFence) {
    return bindExternalTextureBuffer(texName, buffer, bufferFence, readCache,
                                     /*persistCache=*/false);
}

status_t GLESRenderEngine::bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer,
                                                     sp<Fence> bufferFence, bool readCache,
                                                     bool persistCache) {
    ATRACE_CALL();
    ATRACE_CALL();
    if (readCache) {
    auto cachedImage = mImageCache.find(buffer->getId());
    auto cachedImage = mImageCache.find(buffer->getId());


    if (cachedImage != mImageCache.end()) {
    if (cachedImage != mImageCache.end()) {
        bindExternalTextureImage(texName, *cachedImage->second);
        bindExternalTextureImage(texName, *cachedImage->second);
        return NO_ERROR;
        return NO_ERROR;
    }
    }
    }


    std::unique_ptr<Image> newImage = createImage();
    std::unique_ptr<Image> newImage = createImage();


@@ -678,35 +669,19 @@ status_t GLESRenderEngine::bindExternalTextureBuffer(uint32_t texName, sp<Graphi
            }
            }
        }
        }
    }
    }

    // We don't always want to persist to the cache, e.g. on older devices we
    // might bind for synchronization purposes, but that might leak if we never
    // call drawLayers again, so it's just better to recreate the image again
    // if needed when we draw.
    if (persistCache) {
    mImageCache.insert(std::make_pair(buffer->getId(), std::move(newImage)));
    mImageCache.insert(std::make_pair(buffer->getId(), std::move(newImage)));
    }


    return NO_ERROR;
    return NO_ERROR;
}
}


void GLESRenderEngine::evictImages(const std::vector<LayerSettings>& layers) {
void GLESRenderEngine::unbindExternalTextureBuffer(uint64_t bufferId) {
    ATRACE_CALL();
    const auto& cachedImage = mImageCache.find(bufferId);
    // destroy old image references that we're not going to draw with.
    if (cachedImage != mImageCache.end()) {
    std::unordered_set<uint64_t> bufIds;
        ALOGV("Destroying image for buffer: %" PRIu64, bufferId);
    for (auto layer : layers) {
        mImageCache.erase(bufferId);
        if (layer.source.buffer.buffer != nullptr) {
        return;
            bufIds.emplace(layer.source.buffer.buffer->getId());
        }
    }

    for (auto it = mImageCache.begin(); it != mImageCache.end();) {
        if (bufIds.count(it->first) == 0) {
            it = mImageCache.erase(it);
        } else {
            it++;
        }
    }
    }
    ALOGV("Failed to find image for buffer: %" PRIu64, bufferId);
}
}


FloatRect GLESRenderEngine::setupLayerCropping(const LayerSettings& layer, Mesh& mesh) {
FloatRect GLESRenderEngine::setupLayerCropping(const LayerSettings& layer, Mesh& mesh) {
@@ -844,8 +819,6 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display,
        return fbo.getStatus();
        return fbo.getStatus();
    }
    }


    evictImages(layers);

    // clear the entire buffer, sometimes when we reuse buffers we'd persist
    // clear the entire buffer, sometimes when we reuse buffers we'd persist
    // ghost images otherwise.
    // ghost images otherwise.
    // we also require a full transparent framebuffer for overlays. This is
    // we also require a full transparent framebuffer for overlays. This is
@@ -888,10 +861,8 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display,
            isOpaque = layer.source.buffer.isOpaque;
            isOpaque = layer.source.buffer.isOpaque;


            sp<GraphicBuffer> gBuf = layer.source.buffer.buffer;
            sp<GraphicBuffer> gBuf = layer.source.buffer.buffer;

            bool readCache = layer.source.buffer.cacheHint == Buffer::CachingHint::USE_CACHE;
            bindExternalTextureBuffer(layer.source.buffer.textureName, gBuf,
            bindExternalTextureBuffer(layer.source.buffer.textureName, gBuf,
                                      layer.source.buffer.fence, readCache, /*persistCache=*/true);
                                      layer.source.buffer.fence);


            usePremultipliedAlpha = layer.source.buffer.usePremultipliedAlpha;
            usePremultipliedAlpha = layer.source.buffer.usePremultipliedAlpha;
            Texture texture(Texture::TEXTURE_EXTERNAL, layer.source.buffer.textureName);
            Texture texture(Texture::TEXTURE_EXTERNAL, layer.source.buffer.textureName);
+2 −4
Original line number Original line Diff line number Diff line
@@ -74,8 +74,8 @@ public:
    void genTextures(size_t count, uint32_t* names) override;
    void genTextures(size_t count, uint32_t* names) override;
    void deleteTextures(size_t count, uint32_t const* names) override;
    void deleteTextures(size_t count, uint32_t const* names) override;
    void bindExternalTextureImage(uint32_t texName, const Image& image) override;
    void bindExternalTextureImage(uint32_t texName, const Image& image) override;
    status_t bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer, sp<Fence> fence,
    status_t bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer, sp<Fence> fence);
                                       bool readCache);
    void unbindExternalTextureBuffer(uint64_t bufferId);
    status_t bindFrameBuffer(Framebuffer* framebuffer) override;
    status_t bindFrameBuffer(Framebuffer* framebuffer) override;
    void unbindFrameBuffer(Framebuffer* framebuffer) override;
    void unbindFrameBuffer(Framebuffer* framebuffer) override;
    void checkErrors() const override;
    void checkErrors() const override;
@@ -143,8 +143,6 @@ private:
    // Defines the viewport, and sets the projection matrix to the projection
    // Defines the viewport, and sets the projection matrix to the projection
    // defined by the clip.
    // defined by the clip.
    void setViewportAndProjection(Rect viewport, Rect clip);
    void setViewportAndProjection(Rect viewport, Rect clip);
    status_t bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer, sp<Fence> fence,
                                       bool readCache, bool persistCache);
    // Evicts stale images from the buffer cache.
    // Evicts stale images from the buffer cache.
    void evictImages(const std::vector<LayerSettings>& layers);
    void evictImages(const std::vector<LayerSettings>& layers);
    // Computes the cropping window for the layer and sets up cropping
    // Computes the cropping window for the layer and sets up cropping
+0 −13
Original line number Original line Diff line number Diff line
@@ -32,16 +32,6 @@ namespace renderengine {


// Metadata describing the input buffer to render from.
// Metadata describing the input buffer to render from.
struct Buffer {
struct Buffer {
    // Hint for whether to use the Image cache or not.
    // If NO_CACHE is specified, then upload the contents of the GraphicBuffer
    // to the GPU, without checking against any implementation defined cache.
    // If USE_CACHE is specified, then check against an implementation defined
    // cache first. If there is an Image cached for the given GraphicBuffer id,
    // then use that instead of the provided buffer contents. If there is no
    // cached image or the RenderEngine implementation does not support caching,
    // then use the GraphicBuffer contents.
    enum class CachingHint { NO_CACHE, USE_CACHE };

    // Buffer containing the image that we will render.
    // Buffer containing the image that we will render.
    // If buffer == nullptr, then the rest of the fields in this struct will be
    // If buffer == nullptr, then the rest of the fields in this struct will be
    // ignored.
    // ignored.
@@ -50,9 +40,6 @@ struct Buffer {
    // Fence that will fire when the buffer is ready to be bound.
    // Fence that will fire when the buffer is ready to be bound.
    sp<Fence> fence = nullptr;
    sp<Fence> fence = nullptr;


    // Caching hint to use when uploading buffer contents.
    CachingHint cacheHint = CachingHint::NO_CACHE;

    // Texture identifier to bind the external texture to.
    // Texture identifier to bind the external texture to.
    // TODO(alecmouri): This is GL-specific...make the type backend-agnostic.
    // TODO(alecmouri): This is GL-specific...make the type backend-agnostic.
    uint32_t textureName = 0;
    uint32_t textureName = 0;
+5 −1
Original line number Original line Diff line number Diff line
@@ -110,7 +110,11 @@ public:
    virtual void deleteTextures(size_t count, uint32_t const* names) = 0;
    virtual void deleteTextures(size_t count, uint32_t const* names) = 0;
    virtual void bindExternalTextureImage(uint32_t texName, const Image& image) = 0;
    virtual void bindExternalTextureImage(uint32_t texName, const Image& image) = 0;
    virtual status_t bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer,
    virtual status_t bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer,
                                               sp<Fence> fence, bool cleanCache) = 0;
                                               sp<Fence> fence) = 0;
    // Removes internal resources referenced by the bufferId. This method should be
    // invoked when the caller will no longer hold a reference to a GraphicBuffer
    // and needs to clean up its resources.
    virtual void unbindExternalTextureBuffer(uint64_t bufferId) = 0;
    // When binding a native buffer, it must be done before setViewportAndProjection
    // When binding a native buffer, it must be done before setViewportAndProjection
    // Returns NO_ERROR when binds successfully, NO_MEMORY when there's no memory for allocation.
    // Returns NO_ERROR when binds successfully, NO_MEMORY when there's no memory for allocation.
    virtual status_t bindFrameBuffer(Framebuffer* framebuffer) = 0;
    virtual status_t bindFrameBuffer(Framebuffer* framebuffer) = 0;
+2 −1
Original line number Original line Diff line number Diff line
@@ -53,7 +53,8 @@ public:
    MOCK_METHOD2(genTextures, void(size_t, uint32_t*));
    MOCK_METHOD2(genTextures, void(size_t, uint32_t*));
    MOCK_METHOD2(deleteTextures, void(size_t, uint32_t const*));
    MOCK_METHOD2(deleteTextures, void(size_t, uint32_t const*));
    MOCK_METHOD2(bindExternalTextureImage, void(uint32_t, const renderengine::Image&));
    MOCK_METHOD2(bindExternalTextureImage, void(uint32_t, const renderengine::Image&));
    MOCK_METHOD4(bindExternalTextureBuffer, status_t(uint32_t, sp<GraphicBuffer>, sp<Fence>, bool));
    MOCK_METHOD3(bindExternalTextureBuffer, status_t(uint32_t, sp<GraphicBuffer>, sp<Fence>));
    MOCK_METHOD1(unbindExternalTextureBuffer, void(uint64_t));
    MOCK_CONST_METHOD0(checkErrors, void());
    MOCK_CONST_METHOD0(checkErrors, void());
    MOCK_METHOD4(setViewportAndProjection,
    MOCK_METHOD4(setViewportAndProjection,
                 void(size_t, size_t, Rect, ui::Transform::orientation_flags));
                 void(size_t, size_t, Rect, ui::Transform::orientation_flags));
Loading