Loading libs/renderengine/gl/GLESRenderEngine.cpp +38 −8 Original line number Diff line number Diff line Loading @@ -449,6 +449,7 @@ bool GLESRenderEngine::isCurrent() const { } base::unique_fd GLESRenderEngine::flush() { ATRACE_CALL(); if (!GLExtensions::getInstance().hasNativeFenceSync()) { return base::unique_fd(); } Loading Loading @@ -479,6 +480,7 @@ base::unique_fd GLESRenderEngine::flush() { } bool GLESRenderEngine::finish() { ATRACE_CALL(); if (!GLExtensions::getInstance().hasFenceSync()) { ALOGW("no synchronization support"); return false; Loading Loading @@ -544,6 +546,8 @@ bool GLESRenderEngine::waitFence(base::unique_fd fenceFd) { } void GLESRenderEngine::clearWithColor(float red, float green, float blue, float alpha) { ATRACE_CALL(); glDisable(GL_BLEND); glClearColor(red, green, blue, alpha); glClear(GL_COLOR_BUFFER_BIT); } Loading Loading @@ -594,6 +598,7 @@ void GLESRenderEngine::deleteTextures(size_t count, uint32_t const* names) { } void GLESRenderEngine::bindExternalTextureImage(uint32_t texName, const Image& image) { ATRACE_CALL(); const GLImage& glImage = static_cast<const GLImage&>(image); const GLenum target = GL_TEXTURE_EXTERNAL_OES; Loading @@ -607,9 +612,16 @@ void GLESRenderEngine::bindExternalTextureImage(uint32_t texName, const Image& i } } status_t GLESRenderEngine::bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer, sp<Fence> bufferFence, bool readCache) { 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(); if (readCache) { auto cachedImage = mImageCache.find(buffer->getId()); Loading Loading @@ -655,7 +667,7 @@ 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 purpoeses, but that might leak if we never // 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) { Loading Loading @@ -703,6 +715,7 @@ FloatRect GLESRenderEngine::setupLayerCropping(const LayerSettings& layer, Mesh& } status_t GLESRenderEngine::bindFrameBuffer(Framebuffer* framebuffer) { ATRACE_CALL(); GLFramebuffer* glFramebuffer = static_cast<GLFramebuffer*>(framebuffer); EGLImageKHR eglImage = glFramebuffer->getEGLImage(); uint32_t textureName = glFramebuffer->getTextureName(); Loading Loading @@ -770,6 +783,7 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, const std::vector<LayerSettings>& layers, ANativeWindowBuffer* const buffer, base::unique_fd* drawFence) { ATRACE_CALL(); if (layers.empty()) { ALOGV("Drawing empty layer stack"); return NO_ERROR; Loading @@ -786,6 +800,13 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, evictImages(layers); // clear the entire buffer, sometimes when we reuse buffers we'd persist // ghost images otherwise. // we also require a full transparent framebuffer for overlays. This is // probably not quite efficient on all GPUs, since we could filter out // opaque layers. clearWithColor(0.0, 0.0, 0.0, 0.0); setViewportAndProjection(display.physicalDisplay, display.clip); setOutputDataSpace(display.outputDataspace); Loading @@ -794,6 +815,7 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, mat4 projectionMatrix = mState.projectionMatrix * display.globalTransform; mState.projectionMatrix = projectionMatrix; if (!display.clearRegion.isEmpty()) { glDisable(GL_BLEND); fillRegionWithColor(display.clearRegion, 0.0, 0.0, 0.0, 1.0); } Loading @@ -813,9 +835,11 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, bool usePremultipliedAlpha = true; bool disableTexture = true; bool isOpaque = false; if (layer.source.buffer.buffer != nullptr) { disableTexture = false; isOpaque = layer.source.buffer.isOpaque; sp<GraphicBuffer> gBuf = layer.source.buffer.buffer; Loading @@ -825,17 +849,19 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, usePremultipliedAlpha = layer.source.buffer.usePremultipliedAlpha; Texture texture(Texture::TEXTURE_EXTERNAL, layer.source.buffer.textureName); texture.setMatrix(layer.source.buffer.textureTransform.asArray()); mat4 texMatrix = layer.source.buffer.textureTransform; texture.setMatrix(texMatrix.asArray()); texture.setFiltering(layer.source.buffer.useTextureFiltering); texture.setDimensions(gBuf->getWidth(), gBuf->getHeight()); setSourceY410BT2020(layer.source.buffer.isY410BT2020); renderengine::Mesh::VertexArray<vec2> texCoords(mesh.getTexCoordArray<vec2>()); texCoords[0] = vec2(0.0, 1.0); texCoords[1] = vec2(0.0, 0.0); texCoords[2] = vec2(1.0, 0.0); texCoords[3] = vec2(1.0, 1.0); texCoords[0] = vec2(0.0, 0.0); texCoords[1] = vec2(0.0, 1.0); texCoords[2] = vec2(1.0, 1.0); texCoords[3] = vec2(1.0, 0.0); setupLayerTexturing(texture); } Loading @@ -843,8 +869,11 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, const half4 color = half4(solidColor.r, solidColor.g, solidColor.b, layer.alpha); // Buffer sources will have a black solid color ignored in the shader, // so in that scenario the solid color passed here is arbitrary. setupLayerBlending(usePremultipliedAlpha, layer.source.buffer.isOpaque, disableTexture, color, layer.geometry.roundedCornersRadius); setupLayerBlending(usePremultipliedAlpha, isOpaque, disableTexture, color, layer.geometry.roundedCornersRadius); if (layer.disableBlending) { glDisable(GL_BLEND); } setSourceDataSpace(layer.sourceDataspace); drawMesh(mesh); Loading Loading @@ -903,6 +932,7 @@ void GLESRenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect sou } void GLESRenderEngine::setViewportAndProjection(Rect viewport, Rect clip) { ATRACE_CALL(); mVpWidth = viewport.getWidth(); mVpHeight = viewport.getHeight(); Loading libs/renderengine/gl/GLESRenderEngine.h +5 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,8 @@ public: void genTextures(size_t count, uint32_t* names) override; void deleteTextures(size_t count, uint32_t const* names) override; void bindExternalTextureImage(uint32_t texName, const Image& image) override; status_t bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer, sp<Fence> fence, bool readCache); status_t bindFrameBuffer(Framebuffer* framebuffer) override; void unbindFrameBuffer(Framebuffer* framebuffer) override; void checkErrors() const override; Loading Loading @@ -184,6 +186,9 @@ private: const bool mUseColorManagement = false; // Cache of GL images that we'll store per GraphicBuffer ID // TODO: Layer should call back on destruction instead to clean this up, // as it has better system utilization at the potential expense of a // more complicated interface. std::unordered_map<uint64_t, std::unique_ptr<Image>> mImageCache; class FlushTracer { Loading libs/renderengine/gl/GLFramebuffer.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ * limitations under the License. */ #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include "GLFramebuffer.h" #include <GLES/gl.h> Loading @@ -21,6 +23,7 @@ #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> #include <nativebase/nativebase.h> #include <utils/Trace.h> #include "GLESRenderEngine.h" namespace android { Loading @@ -40,6 +43,7 @@ GLFramebuffer::~GLFramebuffer() { } bool GLFramebuffer::setNativeWindowBuffer(ANativeWindowBuffer* nativeBuffer, bool isProtected) { ATRACE_CALL(); if (mEGLImage != EGL_NO_IMAGE_KHR) { eglDestroyImageKHR(mEGLDisplay, mEGLImage); mEGLImage = EGL_NO_IMAGE_KHR; Loading libs/renderengine/gl/GLImage.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -14,11 +14,14 @@ * limitations under the License. */ #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include "GLImage.h" #include <vector> #include <log/log.h> #include <utils/Trace.h> #include "GLESRenderEngine.h" #include "GLExtensions.h" Loading Loading @@ -50,6 +53,7 @@ GLImage::~GLImage() { } bool GLImage::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) { ATRACE_CALL(); if (mEGLImage != EGL_NO_IMAGE_KHR) { if (!eglDestroyImageKHR(mEGLDisplay, mEGLImage)) { ALOGE("failed to destroy image: %#x", eglGetError()); Loading libs/renderengine/include/renderengine/LayerSettings.h +3 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,9 @@ struct LayerSettings { // Additional layer-specific color transform to be applied before the global // transform. mat4 colorTransform = mat4(); // True if blending will be forced to be disabled. bool disableBlending = false; }; } // namespace renderengine Loading Loading
libs/renderengine/gl/GLESRenderEngine.cpp +38 −8 Original line number Diff line number Diff line Loading @@ -449,6 +449,7 @@ bool GLESRenderEngine::isCurrent() const { } base::unique_fd GLESRenderEngine::flush() { ATRACE_CALL(); if (!GLExtensions::getInstance().hasNativeFenceSync()) { return base::unique_fd(); } Loading Loading @@ -479,6 +480,7 @@ base::unique_fd GLESRenderEngine::flush() { } bool GLESRenderEngine::finish() { ATRACE_CALL(); if (!GLExtensions::getInstance().hasFenceSync()) { ALOGW("no synchronization support"); return false; Loading Loading @@ -544,6 +546,8 @@ bool GLESRenderEngine::waitFence(base::unique_fd fenceFd) { } void GLESRenderEngine::clearWithColor(float red, float green, float blue, float alpha) { ATRACE_CALL(); glDisable(GL_BLEND); glClearColor(red, green, blue, alpha); glClear(GL_COLOR_BUFFER_BIT); } Loading Loading @@ -594,6 +598,7 @@ void GLESRenderEngine::deleteTextures(size_t count, uint32_t const* names) { } void GLESRenderEngine::bindExternalTextureImage(uint32_t texName, const Image& image) { ATRACE_CALL(); const GLImage& glImage = static_cast<const GLImage&>(image); const GLenum target = GL_TEXTURE_EXTERNAL_OES; Loading @@ -607,9 +612,16 @@ void GLESRenderEngine::bindExternalTextureImage(uint32_t texName, const Image& i } } status_t GLESRenderEngine::bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer, sp<Fence> bufferFence, bool readCache) { 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(); if (readCache) { auto cachedImage = mImageCache.find(buffer->getId()); Loading Loading @@ -655,7 +667,7 @@ 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 purpoeses, but that might leak if we never // 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) { Loading Loading @@ -703,6 +715,7 @@ FloatRect GLESRenderEngine::setupLayerCropping(const LayerSettings& layer, Mesh& } status_t GLESRenderEngine::bindFrameBuffer(Framebuffer* framebuffer) { ATRACE_CALL(); GLFramebuffer* glFramebuffer = static_cast<GLFramebuffer*>(framebuffer); EGLImageKHR eglImage = glFramebuffer->getEGLImage(); uint32_t textureName = glFramebuffer->getTextureName(); Loading Loading @@ -770,6 +783,7 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, const std::vector<LayerSettings>& layers, ANativeWindowBuffer* const buffer, base::unique_fd* drawFence) { ATRACE_CALL(); if (layers.empty()) { ALOGV("Drawing empty layer stack"); return NO_ERROR; Loading @@ -786,6 +800,13 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, evictImages(layers); // clear the entire buffer, sometimes when we reuse buffers we'd persist // ghost images otherwise. // we also require a full transparent framebuffer for overlays. This is // probably not quite efficient on all GPUs, since we could filter out // opaque layers. clearWithColor(0.0, 0.0, 0.0, 0.0); setViewportAndProjection(display.physicalDisplay, display.clip); setOutputDataSpace(display.outputDataspace); Loading @@ -794,6 +815,7 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, mat4 projectionMatrix = mState.projectionMatrix * display.globalTransform; mState.projectionMatrix = projectionMatrix; if (!display.clearRegion.isEmpty()) { glDisable(GL_BLEND); fillRegionWithColor(display.clearRegion, 0.0, 0.0, 0.0, 1.0); } Loading @@ -813,9 +835,11 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, bool usePremultipliedAlpha = true; bool disableTexture = true; bool isOpaque = false; if (layer.source.buffer.buffer != nullptr) { disableTexture = false; isOpaque = layer.source.buffer.isOpaque; sp<GraphicBuffer> gBuf = layer.source.buffer.buffer; Loading @@ -825,17 +849,19 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, usePremultipliedAlpha = layer.source.buffer.usePremultipliedAlpha; Texture texture(Texture::TEXTURE_EXTERNAL, layer.source.buffer.textureName); texture.setMatrix(layer.source.buffer.textureTransform.asArray()); mat4 texMatrix = layer.source.buffer.textureTransform; texture.setMatrix(texMatrix.asArray()); texture.setFiltering(layer.source.buffer.useTextureFiltering); texture.setDimensions(gBuf->getWidth(), gBuf->getHeight()); setSourceY410BT2020(layer.source.buffer.isY410BT2020); renderengine::Mesh::VertexArray<vec2> texCoords(mesh.getTexCoordArray<vec2>()); texCoords[0] = vec2(0.0, 1.0); texCoords[1] = vec2(0.0, 0.0); texCoords[2] = vec2(1.0, 0.0); texCoords[3] = vec2(1.0, 1.0); texCoords[0] = vec2(0.0, 0.0); texCoords[1] = vec2(0.0, 1.0); texCoords[2] = vec2(1.0, 1.0); texCoords[3] = vec2(1.0, 0.0); setupLayerTexturing(texture); } Loading @@ -843,8 +869,11 @@ status_t GLESRenderEngine::drawLayers(const DisplaySettings& display, const half4 color = half4(solidColor.r, solidColor.g, solidColor.b, layer.alpha); // Buffer sources will have a black solid color ignored in the shader, // so in that scenario the solid color passed here is arbitrary. setupLayerBlending(usePremultipliedAlpha, layer.source.buffer.isOpaque, disableTexture, color, layer.geometry.roundedCornersRadius); setupLayerBlending(usePremultipliedAlpha, isOpaque, disableTexture, color, layer.geometry.roundedCornersRadius); if (layer.disableBlending) { glDisable(GL_BLEND); } setSourceDataSpace(layer.sourceDataspace); drawMesh(mesh); Loading Loading @@ -903,6 +932,7 @@ void GLESRenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect sou } void GLESRenderEngine::setViewportAndProjection(Rect viewport, Rect clip) { ATRACE_CALL(); mVpWidth = viewport.getWidth(); mVpHeight = viewport.getHeight(); Loading
libs/renderengine/gl/GLESRenderEngine.h +5 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,8 @@ public: void genTextures(size_t count, uint32_t* names) override; void deleteTextures(size_t count, uint32_t const* names) override; void bindExternalTextureImage(uint32_t texName, const Image& image) override; status_t bindExternalTextureBuffer(uint32_t texName, sp<GraphicBuffer> buffer, sp<Fence> fence, bool readCache); status_t bindFrameBuffer(Framebuffer* framebuffer) override; void unbindFrameBuffer(Framebuffer* framebuffer) override; void checkErrors() const override; Loading Loading @@ -184,6 +186,9 @@ private: const bool mUseColorManagement = false; // Cache of GL images that we'll store per GraphicBuffer ID // TODO: Layer should call back on destruction instead to clean this up, // as it has better system utilization at the potential expense of a // more complicated interface. std::unordered_map<uint64_t, std::unique_ptr<Image>> mImageCache; class FlushTracer { Loading
libs/renderengine/gl/GLFramebuffer.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ * limitations under the License. */ #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include "GLFramebuffer.h" #include <GLES/gl.h> Loading @@ -21,6 +23,7 @@ #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> #include <nativebase/nativebase.h> #include <utils/Trace.h> #include "GLESRenderEngine.h" namespace android { Loading @@ -40,6 +43,7 @@ GLFramebuffer::~GLFramebuffer() { } bool GLFramebuffer::setNativeWindowBuffer(ANativeWindowBuffer* nativeBuffer, bool isProtected) { ATRACE_CALL(); if (mEGLImage != EGL_NO_IMAGE_KHR) { eglDestroyImageKHR(mEGLDisplay, mEGLImage); mEGLImage = EGL_NO_IMAGE_KHR; Loading
libs/renderengine/gl/GLImage.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -14,11 +14,14 @@ * limitations under the License. */ #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include "GLImage.h" #include <vector> #include <log/log.h> #include <utils/Trace.h> #include "GLESRenderEngine.h" #include "GLExtensions.h" Loading Loading @@ -50,6 +53,7 @@ GLImage::~GLImage() { } bool GLImage::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) { ATRACE_CALL(); if (mEGLImage != EGL_NO_IMAGE_KHR) { if (!eglDestroyImageKHR(mEGLDisplay, mEGLImage)) { ALOGE("failed to destroy image: %#x", eglGetError()); Loading
libs/renderengine/include/renderengine/LayerSettings.h +3 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,9 @@ struct LayerSettings { // Additional layer-specific color transform to be applied before the global // transform. mat4 colorTransform = mat4(); // True if blending will be forced to be disabled. bool disableBlending = false; }; } // namespace renderengine Loading