Loading services/surfaceflinger/RenderEngine/Android.bp +2 −2 Original line number Diff line number Diff line Loading @@ -41,10 +41,8 @@ filegroup { name: "librenderengine_sources", srcs: [ "Description.cpp", "Image.cpp", "Mesh.cpp", "RenderEngine.cpp", "Surface.cpp", "Texture.cpp", ], } Loading @@ -54,6 +52,8 @@ filegroup { srcs: [ "gl/GLES20RenderEngine.cpp", "gl/GLExtensions.cpp", "gl/GLImage.cpp", "gl/GLSurface.cpp", "gl/Program.cpp", "gl/ProgramCache.cpp", ], Loading services/surfaceflinger/RenderEngine/RenderEngine.cpp +0 −59 Original line number Diff line number Diff line Loading @@ -184,42 +184,6 @@ bool RenderEngine::useWaitSync() const { return SyncFeatures::getInstance().useWaitSync(); } bool RenderEngine::isCurrent() const { return mEGLDisplay == eglGetCurrentDisplay() && mEGLContext == eglGetCurrentContext(); } std::unique_ptr<renderengine::Surface> RenderEngine::createSurface() { return std::make_unique<Surface>(*this); } std::unique_ptr<renderengine::Image> RenderEngine::createImage() { return std::make_unique<Image>(*this); } bool RenderEngine::setCurrentSurface(const android::renderengine::Surface& surface) { // Note: renderengine::Surface is an abstract interface. This implementation only ever // creates renderengine::impl::Surface's, so it is safe to just cast to the actual // type. return setCurrentSurface(static_cast<const android::renderengine::impl::Surface&>(surface)); } bool RenderEngine::setCurrentSurface(const android::renderengine::impl::Surface& surface) { bool success = true; EGLSurface eglSurface = surface.getEGLSurface(); if (eglSurface != eglGetCurrentSurface(EGL_DRAW)) { success = eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext) == EGL_TRUE; if (success && surface.getAsync()) { eglSwapInterval(mEGLDisplay, 0); } } return success; } void RenderEngine::resetCurrentSurface() { eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } base::unique_fd RenderEngine::flush() { if (!GLExtensions::getInstance().hasNativeFenceSync()) { return base::unique_fd(); Loading Loading @@ -375,24 +339,6 @@ void RenderEngine::deleteTextures(size_t count, uint32_t const* names) { glDeleteTextures(count, names); } void RenderEngine::bindExternalTextureImage(uint32_t texName, const android::renderengine::Image& image) { // Note: renderengine::Image is an abstract interface. This implementation only ever // creates renderengine::impl::Image's, so it is safe to just cast to the actual type. return bindExternalTextureImage(texName, static_cast<const android::renderengine::impl::Image&>(image)); } void RenderEngine::bindExternalTextureImage(uint32_t texName, const android::renderengine::impl::Image& image) { const GLenum target = GL_TEXTURE_EXTERNAL_OES; glBindTexture(target, texName); if (image.getEGLImage() != EGL_NO_IMAGE_KHR) { glEGLImageTargetTexture2DOES(target, static_cast<GLeglImageOES>(image.getEGLImage())); } } void RenderEngine::readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) { glReadPixels(l, b, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); } Loading Loading @@ -597,11 +543,6 @@ EGLConfig RenderEngine::chooseEglConfig(EGLDisplay display, int format, bool log return config; } void RenderEngine::primeCache() const { ProgramCache::getInstance().primeCache(mFeatureFlags & USE_COLOR_MANAGEMENT); } } // namespace impl } // namespace renderengine } // namespace android services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp +54 −8 Original line number Diff line number Diff line Loading @@ -36,6 +36,9 @@ #include <ui/Rect.h> #include <utils/String8.h> #include <utils/Trace.h> #include "GLExtensions.h" #include "GLImage.h" #include "GLSurface.h" #include "Program.h" #include "ProgramCache.h" Loading Loading @@ -151,12 +154,51 @@ GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags) GLES20RenderEngine::~GLES20RenderEngine() {} size_t GLES20RenderEngine::getMaxTextureSize() const { return mMaxTextureSize; std::unique_ptr<Surface> GLES20RenderEngine::createSurface() { return std::make_unique<GLSurface>(*this); } size_t GLES20RenderEngine::getMaxViewportDims() const { return mMaxViewportDims[0] < mMaxViewportDims[1] ? mMaxViewportDims[0] : mMaxViewportDims[1]; std::unique_ptr<Image> GLES20RenderEngine::createImage() { return std::make_unique<GLImage>(*this); } void GLES20RenderEngine::primeCache() const { ProgramCache::getInstance().primeCache(mFeatureFlags & USE_COLOR_MANAGEMENT); } bool GLES20RenderEngine::isCurrent() const { return mEGLDisplay == eglGetCurrentDisplay() && mEGLContext == eglGetCurrentContext(); } bool GLES20RenderEngine::setCurrentSurface(const Surface& surface) { // Surface is an abstract interface. GLES20RenderEngine only ever // creates GLSurface's, so it is safe to just cast to the actual // type. bool success = true; const GLSurface& glSurface = static_cast<const GLSurface&>(surface); EGLSurface eglSurface = glSurface.getEGLSurface(); if (eglSurface != eglGetCurrentSurface(EGL_DRAW)) { success = eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext) == EGL_TRUE; if (success && glSurface.getAsync()) { eglSwapInterval(mEGLDisplay, 0); } } return success; } void GLES20RenderEngine::resetCurrentSurface() { eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } void GLES20RenderEngine::bindExternalTextureImage(uint32_t texName, const Image& image) { const GLImage& glImage = static_cast<const GLImage&>(image); const GLenum target = GL_TEXTURE_EXTERNAL_OES; glBindTexture(target, texName); if (glImage.getEGLImage() != EGL_NO_IMAGE_KHR) { glEGLImageTargetTexture2DOES(target, static_cast<GLeglImageOES>(glImage.getEGLImage())); } } void GLES20RenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, Loading Loading @@ -425,6 +467,14 @@ void GLES20RenderEngine::drawMesh(const Mesh& mesh) { } } size_t GLES20RenderEngine::getMaxTextureSize() const { return mMaxTextureSize; } size_t GLES20RenderEngine::getMaxViewportDims() const { return mMaxViewportDims[0] < mMaxViewportDims[1] ? mMaxViewportDims[0] : mMaxViewportDims[1]; } void GLES20RenderEngine::dump(String8& result) { RenderEngine::dump(result); result.appendFormat("RenderEngine last dataspace conversion: (%s) to (%s)\n", Loading Loading @@ -462,7 +512,3 @@ bool GLES20RenderEngine::needsXYZTransformMatrix() const { } // namespace gl } // namespace renderengine } // namespace android #if defined(__gl_h_) #error "don't include gl/gl.h in this file" #endif services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h +15 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ class Texture; namespace gl { class GLImage; class GLSurface; class GLES20RenderEngine : public impl::RenderEngine { GLuint mProtectedTexName; GLint mMaxViewportDims[2]; Loading @@ -60,6 +63,18 @@ public: GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag virtual ~GLES20RenderEngine(); std::unique_ptr<renderengine::Surface> createSurface() override; std::unique_ptr<renderengine::Image> createImage() override; void primeCache() const override; bool isCurrent() const; bool setCurrentSurface(const Surface& surface) override; void resetCurrentSurface() override; void bindExternalTextureImage(uint32_t texName, const renderengine::Image& image) override; protected: virtual void dump(String8& result); virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh, Loading services/surfaceflinger/RenderEngine/Image.cpp→services/surfaceflinger/RenderEngine/gl/GLImage.cpp +14 −17 Original line number Diff line number Diff line /* * Copyright 2017 The Android Open Source Project * Copyright 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -14,26 +14,17 @@ * limitations under the License. */ #include <renderengine/Image.h> #include "GLImage.h" #include <vector> #include <log/log.h> #include <renderengine/RenderEngine.h> #include "gl/GLExtensions.h" #include "GLExtensions.h" #include "GLES20RenderEngine.h" namespace android { namespace renderengine { Image::~Image() = default; namespace impl { Image::Image(const RenderEngine& engine) : mEGLDisplay(engine.getEGLDisplay()) {} Image::~Image() { setNativeWindowBuffer(nullptr, false); } namespace gl { static std::vector<EGLint> buildAttributeList(bool isProtected) { std::vector<EGLint> attrs; Loading @@ -42,7 +33,7 @@ static std::vector<EGLint> buildAttributeList(bool isProtected) { attrs.push_back(EGL_IMAGE_PRESERVED_KHR); attrs.push_back(EGL_TRUE); if (isProtected && gl::GLExtensions::getInstance().hasProtectedContent()) { if (isProtected && GLExtensions::getInstance().hasProtectedContent()) { attrs.push_back(EGL_PROTECTED_CONTENT_EXT); attrs.push_back(EGL_TRUE); } Loading @@ -52,7 +43,13 @@ static std::vector<EGLint> buildAttributeList(bool isProtected) { return attrs; } bool Image::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) { GLImage::GLImage(const GLES20RenderEngine& engine) : mEGLDisplay(engine.getEGLDisplay()) {} GLImage::~GLImage() { setNativeWindowBuffer(nullptr, false); } bool GLImage::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) { if (mEGLImage != EGL_NO_IMAGE_KHR) { if (!eglDestroyImageKHR(mEGLDisplay, mEGLImage)) { ALOGE("failed to destroy image: %#x", eglGetError()); Loading @@ -73,6 +70,6 @@ bool Image::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) return true; } } // namespace impl } // namespace gl } // namespace renderengine } // namespace android Loading
services/surfaceflinger/RenderEngine/Android.bp +2 −2 Original line number Diff line number Diff line Loading @@ -41,10 +41,8 @@ filegroup { name: "librenderengine_sources", srcs: [ "Description.cpp", "Image.cpp", "Mesh.cpp", "RenderEngine.cpp", "Surface.cpp", "Texture.cpp", ], } Loading @@ -54,6 +52,8 @@ filegroup { srcs: [ "gl/GLES20RenderEngine.cpp", "gl/GLExtensions.cpp", "gl/GLImage.cpp", "gl/GLSurface.cpp", "gl/Program.cpp", "gl/ProgramCache.cpp", ], Loading
services/surfaceflinger/RenderEngine/RenderEngine.cpp +0 −59 Original line number Diff line number Diff line Loading @@ -184,42 +184,6 @@ bool RenderEngine::useWaitSync() const { return SyncFeatures::getInstance().useWaitSync(); } bool RenderEngine::isCurrent() const { return mEGLDisplay == eglGetCurrentDisplay() && mEGLContext == eglGetCurrentContext(); } std::unique_ptr<renderengine::Surface> RenderEngine::createSurface() { return std::make_unique<Surface>(*this); } std::unique_ptr<renderengine::Image> RenderEngine::createImage() { return std::make_unique<Image>(*this); } bool RenderEngine::setCurrentSurface(const android::renderengine::Surface& surface) { // Note: renderengine::Surface is an abstract interface. This implementation only ever // creates renderengine::impl::Surface's, so it is safe to just cast to the actual // type. return setCurrentSurface(static_cast<const android::renderengine::impl::Surface&>(surface)); } bool RenderEngine::setCurrentSurface(const android::renderengine::impl::Surface& surface) { bool success = true; EGLSurface eglSurface = surface.getEGLSurface(); if (eglSurface != eglGetCurrentSurface(EGL_DRAW)) { success = eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext) == EGL_TRUE; if (success && surface.getAsync()) { eglSwapInterval(mEGLDisplay, 0); } } return success; } void RenderEngine::resetCurrentSurface() { eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } base::unique_fd RenderEngine::flush() { if (!GLExtensions::getInstance().hasNativeFenceSync()) { return base::unique_fd(); Loading Loading @@ -375,24 +339,6 @@ void RenderEngine::deleteTextures(size_t count, uint32_t const* names) { glDeleteTextures(count, names); } void RenderEngine::bindExternalTextureImage(uint32_t texName, const android::renderengine::Image& image) { // Note: renderengine::Image is an abstract interface. This implementation only ever // creates renderengine::impl::Image's, so it is safe to just cast to the actual type. return bindExternalTextureImage(texName, static_cast<const android::renderengine::impl::Image&>(image)); } void RenderEngine::bindExternalTextureImage(uint32_t texName, const android::renderengine::impl::Image& image) { const GLenum target = GL_TEXTURE_EXTERNAL_OES; glBindTexture(target, texName); if (image.getEGLImage() != EGL_NO_IMAGE_KHR) { glEGLImageTargetTexture2DOES(target, static_cast<GLeglImageOES>(image.getEGLImage())); } } void RenderEngine::readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) { glReadPixels(l, b, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); } Loading Loading @@ -597,11 +543,6 @@ EGLConfig RenderEngine::chooseEglConfig(EGLDisplay display, int format, bool log return config; } void RenderEngine::primeCache() const { ProgramCache::getInstance().primeCache(mFeatureFlags & USE_COLOR_MANAGEMENT); } } // namespace impl } // namespace renderengine } // namespace android
services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp +54 −8 Original line number Diff line number Diff line Loading @@ -36,6 +36,9 @@ #include <ui/Rect.h> #include <utils/String8.h> #include <utils/Trace.h> #include "GLExtensions.h" #include "GLImage.h" #include "GLSurface.h" #include "Program.h" #include "ProgramCache.h" Loading Loading @@ -151,12 +154,51 @@ GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags) GLES20RenderEngine::~GLES20RenderEngine() {} size_t GLES20RenderEngine::getMaxTextureSize() const { return mMaxTextureSize; std::unique_ptr<Surface> GLES20RenderEngine::createSurface() { return std::make_unique<GLSurface>(*this); } size_t GLES20RenderEngine::getMaxViewportDims() const { return mMaxViewportDims[0] < mMaxViewportDims[1] ? mMaxViewportDims[0] : mMaxViewportDims[1]; std::unique_ptr<Image> GLES20RenderEngine::createImage() { return std::make_unique<GLImage>(*this); } void GLES20RenderEngine::primeCache() const { ProgramCache::getInstance().primeCache(mFeatureFlags & USE_COLOR_MANAGEMENT); } bool GLES20RenderEngine::isCurrent() const { return mEGLDisplay == eglGetCurrentDisplay() && mEGLContext == eglGetCurrentContext(); } bool GLES20RenderEngine::setCurrentSurface(const Surface& surface) { // Surface is an abstract interface. GLES20RenderEngine only ever // creates GLSurface's, so it is safe to just cast to the actual // type. bool success = true; const GLSurface& glSurface = static_cast<const GLSurface&>(surface); EGLSurface eglSurface = glSurface.getEGLSurface(); if (eglSurface != eglGetCurrentSurface(EGL_DRAW)) { success = eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext) == EGL_TRUE; if (success && glSurface.getAsync()) { eglSwapInterval(mEGLDisplay, 0); } } return success; } void GLES20RenderEngine::resetCurrentSurface() { eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } void GLES20RenderEngine::bindExternalTextureImage(uint32_t texName, const Image& image) { const GLImage& glImage = static_cast<const GLImage&>(image); const GLenum target = GL_TEXTURE_EXTERNAL_OES; glBindTexture(target, texName); if (glImage.getEGLImage() != EGL_NO_IMAGE_KHR) { glEGLImageTargetTexture2DOES(target, static_cast<GLeglImageOES>(glImage.getEGLImage())); } } void GLES20RenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, Loading Loading @@ -425,6 +467,14 @@ void GLES20RenderEngine::drawMesh(const Mesh& mesh) { } } size_t GLES20RenderEngine::getMaxTextureSize() const { return mMaxTextureSize; } size_t GLES20RenderEngine::getMaxViewportDims() const { return mMaxViewportDims[0] < mMaxViewportDims[1] ? mMaxViewportDims[0] : mMaxViewportDims[1]; } void GLES20RenderEngine::dump(String8& result) { RenderEngine::dump(result); result.appendFormat("RenderEngine last dataspace conversion: (%s) to (%s)\n", Loading Loading @@ -462,7 +512,3 @@ bool GLES20RenderEngine::needsXYZTransformMatrix() const { } // namespace gl } // namespace renderengine } // namespace android #if defined(__gl_h_) #error "don't include gl/gl.h in this file" #endif
services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h +15 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ class Texture; namespace gl { class GLImage; class GLSurface; class GLES20RenderEngine : public impl::RenderEngine { GLuint mProtectedTexName; GLint mMaxViewportDims[2]; Loading @@ -60,6 +63,18 @@ public: GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag virtual ~GLES20RenderEngine(); std::unique_ptr<renderengine::Surface> createSurface() override; std::unique_ptr<renderengine::Image> createImage() override; void primeCache() const override; bool isCurrent() const; bool setCurrentSurface(const Surface& surface) override; void resetCurrentSurface() override; void bindExternalTextureImage(uint32_t texName, const renderengine::Image& image) override; protected: virtual void dump(String8& result); virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh, Loading
services/surfaceflinger/RenderEngine/Image.cpp→services/surfaceflinger/RenderEngine/gl/GLImage.cpp +14 −17 Original line number Diff line number Diff line /* * Copyright 2017 The Android Open Source Project * Copyright 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -14,26 +14,17 @@ * limitations under the License. */ #include <renderengine/Image.h> #include "GLImage.h" #include <vector> #include <log/log.h> #include <renderengine/RenderEngine.h> #include "gl/GLExtensions.h" #include "GLExtensions.h" #include "GLES20RenderEngine.h" namespace android { namespace renderengine { Image::~Image() = default; namespace impl { Image::Image(const RenderEngine& engine) : mEGLDisplay(engine.getEGLDisplay()) {} Image::~Image() { setNativeWindowBuffer(nullptr, false); } namespace gl { static std::vector<EGLint> buildAttributeList(bool isProtected) { std::vector<EGLint> attrs; Loading @@ -42,7 +33,7 @@ static std::vector<EGLint> buildAttributeList(bool isProtected) { attrs.push_back(EGL_IMAGE_PRESERVED_KHR); attrs.push_back(EGL_TRUE); if (isProtected && gl::GLExtensions::getInstance().hasProtectedContent()) { if (isProtected && GLExtensions::getInstance().hasProtectedContent()) { attrs.push_back(EGL_PROTECTED_CONTENT_EXT); attrs.push_back(EGL_TRUE); } Loading @@ -52,7 +43,13 @@ static std::vector<EGLint> buildAttributeList(bool isProtected) { return attrs; } bool Image::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) { GLImage::GLImage(const GLES20RenderEngine& engine) : mEGLDisplay(engine.getEGLDisplay()) {} GLImage::~GLImage() { setNativeWindowBuffer(nullptr, false); } bool GLImage::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) { if (mEGLImage != EGL_NO_IMAGE_KHR) { if (!eglDestroyImageKHR(mEGLDisplay, mEGLImage)) { ALOGE("failed to destroy image: %#x", eglGetError()); Loading @@ -73,6 +70,6 @@ bool Image::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) return true; } } // namespace impl } // namespace gl } // namespace renderengine } // namespace android