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

Commit 3aff96fa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Delete renderengine::Surface"

parents 46a5c477 c956fa24
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ filegroup {
        "gl/GLExtensions.cpp",
        "gl/GLFramebuffer.cpp",
        "gl/GLImage.cpp",
        "gl/GLSurface.cpp",
        "gl/Program.cpp",
        "gl/ProgramCache.cpp",
    ],
+2 −36
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@
#include "GLExtensions.h"
#include "GLFramebuffer.h"
#include "GLImage.h"
#include "GLSurface.h"
#include "Program.h"
#include "ProgramCache.h"

@@ -423,10 +422,6 @@ std::unique_ptr<Framebuffer> GLES20RenderEngine::createFramebuffer() {
    return std::make_unique<GLFramebuffer>(*this);
}

std::unique_ptr<Surface> GLES20RenderEngine::createSurface() {
    return std::make_unique<GLSurface>(*this);
}

std::unique_ptr<Image> GLES20RenderEngine::createImage() {
    return std::make_unique<GLImage>(*this);
}
@@ -439,31 +434,6 @@ 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);
        }
        if (success) {
            mSurfaceHeight = glSurface.getHeight();
        }
    }

    return success;
}

void GLES20RenderEngine::resetCurrentSurface() {
    eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    mSurfaceHeight = 0;
}

base::unique_fd GLES20RenderEngine::flush() {
    if (!GLExtensions::getInstance().hasNativeFenceSync()) {
        return base::unique_fd();
@@ -577,7 +547,7 @@ void GLES20RenderEngine::fillRegionWithColor(const Region& region, float red, fl

void GLES20RenderEngine::setScissor(const Rect& region) {
    // Invert y-coordinate to map to GL-space.
    int32_t canvasHeight = mRenderToFbo ? mFboHeight : mSurfaceHeight;
    int32_t canvasHeight = mFboHeight;
    int32_t glBottom = canvasHeight - region.bottom;

    glScissor(region.left, glBottom, region.getWidth(), region.getHeight());
@@ -620,7 +590,6 @@ status_t GLES20RenderEngine::bindFrameBuffer(Framebuffer* framebuffer) {
    glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureName, 0);

    mRenderToFbo = true;
    mFboHeight = glFramebuffer->getBufferHeight();

    uint32_t glStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
@@ -632,7 +601,6 @@ status_t GLES20RenderEngine::bindFrameBuffer(Framebuffer* framebuffer) {
}

void GLES20RenderEngine::unbindFrameBuffer(Framebuffer* /* framebuffer */) {
    mRenderToFbo = false;
    mFboHeight = 0;

    // back to main framebuffer
@@ -661,9 +629,7 @@ void GLES20RenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect s
    int32_t r = sourceCrop.right;
    int32_t b = sourceCrop.bottom;
    int32_t t = sourceCrop.top;
    if (mRenderToFbo) {
    std::swap(t, b);
    }
    mat4 m = mat4::ortho(l, r, b, t, 0, 1);

    // Apply custom rotation to the projection.
+0 −6
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ class Texture;
namespace gl {

class GLImage;
class GLSurface;

class GLES20RenderEngine : public impl::RenderEngine {
public:
@@ -52,13 +51,10 @@ public:
    ~GLES20RenderEngine() override;

    std::unique_ptr<Framebuffer> createFramebuffer() override;
    std::unique_ptr<Surface> createSurface() override;
    std::unique_ptr<Image> createImage() override;

    void primeCache() const override;
    bool isCurrent() const override;
    bool setCurrentSurface(const Surface& surface) override;
    void resetCurrentSurface() override;
    base::unique_fd flush() override;
    bool finish() override;
    bool waitFence(base::unique_fd fenceFd) override;
@@ -147,8 +143,6 @@ private:
    mat4 mBt2020ToSrgb;
    mat4 mBt2020ToDisplayP3;

    bool mRenderToFbo = false;
    int32_t mSurfaceHeight = 0;
    int32_t mFboHeight = 0;

    // Current dataspace of layer being rendered
+0 −105
Original line number Diff line number Diff line
/*
 * 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.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "GLSurface.h"

#include <android/native_window.h>
#include <log/log.h>
#include <ui/PixelFormat.h>
#include "GLES20RenderEngine.h"

namespace android {
namespace renderengine {
namespace gl {

GLSurface::GLSurface(const GLES20RenderEngine& engine)
      : mEGLDisplay(engine.getEGLDisplay()), mEGLConfig(engine.getEGLConfig()) {
    // RE does not assume any config when EGL_KHR_no_config_context is supported
    if (mEGLConfig == EGL_NO_CONFIG_KHR) {
        mEGLConfig =
                GLES20RenderEngine::chooseEglConfig(mEGLDisplay, PIXEL_FORMAT_RGBA_8888, false);
    }
}

GLSurface::~GLSurface() {
    setNativeWindow(nullptr);
}

void GLSurface::setNativeWindow(ANativeWindow* window) {
    if (mEGLSurface != EGL_NO_SURFACE) {
        eglDestroySurface(mEGLDisplay, mEGLSurface);
        mEGLSurface = EGL_NO_SURFACE;
        mSurfaceWidth = 0;
        mSurfaceHeight = 0;
    }

    mWindow = window;
    if (mWindow) {
        mEGLSurface = eglCreateWindowSurface(mEGLDisplay, mEGLConfig, mWindow, nullptr);
        mSurfaceWidth = ANativeWindow_getWidth(window);
        mSurfaceHeight = ANativeWindow_getHeight(window);
    }
}

void GLSurface::swapBuffers() const {
    if (!eglSwapBuffers(mEGLDisplay, mEGLSurface)) {
        EGLint error = eglGetError();

        const char format[] = "eglSwapBuffers(%p, %p) failed with 0x%08x";
        if (mCritical || error == EGL_CONTEXT_LOST) {
            LOG_ALWAYS_FATAL(format, mEGLDisplay, mEGLSurface, error);
        } else {
            ALOGE(format, mEGLDisplay, mEGLSurface, error);
        }
    }
}

EGLint GLSurface::queryConfig(EGLint attrib) const {
    EGLint value;
    if (!eglGetConfigAttrib(mEGLDisplay, mEGLConfig, attrib, &value)) {
        value = 0;
    }

    return value;
}

int32_t GLSurface::queryRedSize() const {
    return queryConfig(EGL_RED_SIZE);
}

int32_t GLSurface::queryGreenSize() const {
    return queryConfig(EGL_GREEN_SIZE);
}

int32_t GLSurface::queryBlueSize() const {
    return queryConfig(EGL_BLUE_SIZE);
}

int32_t GLSurface::queryAlphaSize() const {
    return queryConfig(EGL_ALPHA_SIZE);
}

int32_t GLSurface::getWidth() const {
    return mSurfaceWidth;
}

int32_t GLSurface::getHeight() const {
    return mSurfaceHeight;
}

} // namespace gl
} // namespace renderengine
} // namespace android

libs/renderengine/gl/GLSurface.h

deleted100644 → 0
+0 −76
Original line number Diff line number Diff line
/*
 * 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.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <cstdint>

#include <EGL/egl.h>
#include <android-base/macros.h>
#include <renderengine/Surface.h>

struct ANativeWindow;

namespace android {
namespace renderengine {
namespace gl {

class GLES20RenderEngine;

class GLSurface final : public renderengine::Surface {
public:
    GLSurface(const GLES20RenderEngine& engine);
    ~GLSurface() override;

    // renderengine::Surface implementation
    void setCritical(bool enable) override { mCritical = enable; }
    void setAsync(bool enable) override { mAsync = enable; }

    void setNativeWindow(ANativeWindow* window) override;
    void swapBuffers() const override;

    int32_t queryRedSize() const override;
    int32_t queryGreenSize() const override;
    int32_t queryBlueSize() const override;
    int32_t queryAlphaSize() const override;

    bool getAsync() const { return mAsync; }
    EGLSurface getEGLSurface() const { return mEGLSurface; }

    int32_t getWidth() const override;
    int32_t getHeight() const override;

private:
    EGLint queryConfig(EGLint attrib) const;

    EGLDisplay mEGLDisplay;
    EGLConfig mEGLConfig;

    bool mCritical = false;
    bool mAsync = false;

    int32_t mSurfaceWidth = 0;
    int32_t mSurfaceHeight = 0;

    ANativeWindow* mWindow = nullptr;
    EGLSurface mEGLSurface = EGL_NO_SURFACE;

    DISALLOW_COPY_AND_ASSIGN(GLSurface);
};

} // namespace gl
} // namespace renderengine
} // namespace android
Loading