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

Commit 8cd3edfa authored by Greg Daniel's avatar Greg Daniel
Browse files

Break Layer class into Gl and Vulkan subclasses

Test: manual testing
Change-Id: Ibd2beed39de3ac6da7448e96496253cfe427dfbb
parent d14cafc2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ hwui_src_files := \
    FrameInfo.cpp \
    FrameInfoVisualizer.cpp \
    GammaFontRenderer.cpp \
    GlLayer.cpp \
    GlopBuilder.cpp \
    GpuMemoryTracker.cpp \
    GradientCache.cpp \
+5 −3
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#include "Caches.h"

#include "GammaFontRenderer.h"
#include "Layer.h"
#include "GlLayer.h"
#include "Properties.h"
#include "renderstate/RenderState.h"
#include "ShadowTessellator.h"
@@ -170,9 +170,11 @@ void Caches::dumpMemoryUsage(String8 &log) {
        for (std::set<Layer*>::iterator it = mRenderState->mActiveLayers.begin();
                it != mRenderState->mActiveLayers.end(); it++) {
            const Layer* layer = *it;
            log.appendFormat("    Layer size %dx%d; texid=%u refs=%d\n",
            LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::OpenGL);
            const GlLayer* glLayer = static_cast<const GlLayer*>(layer);
            log.appendFormat("    GlLayer size %dx%d; texid=%u refs=%d\n",
                    layer->getWidth(), layer->getHeight(),
                    layer->getTextureId(),
                    glLayer->getTextureId(),
                    layer->getStrongCount());
            memused += layer->getWidth() * layer->getHeight() * 4;
        }
+22 −7
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
#include "DeferredLayerUpdater.h"

#include "GlLayer.h"
#include "renderthread/EglManager.h"
#include "renderthread/RenderTask.h"
#include "utils/PaintUtils.h"
@@ -55,9 +56,12 @@ void DeferredLayerUpdater::apply() {
    mLayer->setAlpha(mAlpha, mMode);

    if (mSurfaceTexture.get()) {
        LOG_ALWAYS_FATAL_IF(mLayer->getApi() != Layer::Api::OpenGL,
                            "apply surfaceTexture with non GL backend %x, GL %x, VK %x",
                            mLayer->getApi(), Layer::Api::OpenGL, Layer::Api::Vulkan);
        if (mNeedsGLContextAttach) {
            mNeedsGLContextAttach = false;
            mSurfaceTexture->attachToContext(mLayer->getTextureId());
            mSurfaceTexture->attachToContext(static_cast<GlLayer*>(mLayer)->getTextureId());
        }
        if (mUpdateTexImage) {
            mUpdateTexImage = false;
@@ -71,6 +75,9 @@ void DeferredLayerUpdater::apply() {
}

void DeferredLayerUpdater::doUpdateTexImage() {
    LOG_ALWAYS_FATAL_IF(mLayer->getApi() != Layer::Api::OpenGL,
                        "doUpdateTexImage non GL backend %x, GL %x, VK %x",
                        mLayer->getApi(), Layer::Api::OpenGL, Layer::Api::Vulkan);
    if (mSurfaceTexture->updateTexImage() == NO_ERROR) {
        float transform[16];

@@ -112,28 +119,36 @@ void DeferredLayerUpdater::doUpdateTexImage() {

void DeferredLayerUpdater::updateLayer(bool forceFilter, GLenum renderTarget,
        const float* textureTransform) {
    LOG_ALWAYS_FATAL_IF(mLayer->getApi() != Layer::Api::OpenGL,
                        "updateLayer non GL backend %x, GL %x, VK %x",
                        mLayer->getApi(), Layer::Api::OpenGL, Layer::Api::Vulkan);

    mLayer->setBlend(mBlend);
    mLayer->setForceFilter(forceFilter);
    mLayer->setSize(mWidth, mHeight);
    mLayer->getTexTransform().load(textureTransform);

    if (renderTarget != mLayer->getRenderTarget()) {
        mLayer->setRenderTarget(renderTarget);
        mLayer->bindTexture();
        mLayer->setFilter(GL_NEAREST, false, true);
        mLayer->setWrap(GL_CLAMP_TO_EDGE, false, true);
    GlLayer* glLayer = static_cast<GlLayer*>(mLayer);
    if (renderTarget != glLayer->getRenderTarget()) {
        glLayer->setRenderTarget(renderTarget);
        glLayer->bindTexture();
        glLayer->setFilter(GL_NEAREST, false, true);
        glLayer->setWrap(GL_CLAMP_TO_EDGE, false, true);
    }
}

void DeferredLayerUpdater::detachSurfaceTexture() {
    if (mSurfaceTexture.get()) {
        LOG_ALWAYS_FATAL_IF(mLayer->getApi() != Layer::Api::OpenGL,
                            "detachSurfaceTexture with non GL backend %x, GL %x, VK %x",
                            mLayer->getApi(), Layer::Api::OpenGL, Layer::Api::Vulkan);
        status_t err = mSurfaceTexture->detachFromContext();
        if (err != 0) {
            // TODO: Elevate to fatal exception
            ALOGE("Failed to detach SurfaceTexture from context %d", err);
        }
        mSurfaceTexture = nullptr;
        mLayer->clearTexture();
        static_cast<GlLayer*>(mLayer)->clearTexture();
    }
}

+4 −1
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@
#include <SkMatrix.h>
#include <utils/StrongPointer.h>

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

#include "Layer.h"
#include "Rect.h"
#include "renderthread/RenderThread.h"
@@ -60,8 +63,8 @@ public:

    ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
        if (texture.get() != mSurfaceTexture.get()) {
            mNeedsGLContextAttach = needsAttach;
            mSurfaceTexture = texture;
            mNeedsGLContextAttach = needsAttach;

            GLenum target = texture->getCurrentTextureTarget();
            LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES,

libs/hwui/GlLayer.cpp

0 → 100644
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 "GlLayer.h"

#include "Caches.h"
#include "RenderNode.h"
#include "renderstate/RenderState.h"
#include "utils/TraceUtils.h"

#include <utils/Log.h>

#define ATRACE_LAYER_WORK(label) \
    ATRACE_FORMAT("%s HW Layer DisplayList %s %ux%u", \
            label, \
            (renderNode.get() != NULL) ? renderNode->getName() : "", \
            getWidth(), getHeight())

namespace android {
namespace uirenderer {

GlLayer::GlLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight)
        : Layer(renderState, Api::OpenGL)
        , caches(Caches::getInstance())
        , texture(caches) {
    texture.mWidth = layerWidth;
    texture.mHeight = layerHeight;
}

GlLayer::~GlLayer() {
    if (texture.mId) {
        texture.deleteTexture();
    }
}

void GlLayer::onGlContextLost() {
    texture.deleteTexture();
}

void GlLayer::bindTexture() const {
    if (texture.mId) {
        caches.textureState().bindTexture(texture.target(), texture.mId);
    }
}

void GlLayer::generateTexture() {
    if (!texture.mId) {
        glGenTextures(1, &texture.mId);
    }
}

void GlLayer::clearTexture() {
    // There's a rare possibility that Caches could have been destroyed already
    // since this method is queued up as a task.
    // Since this is a reset method, treat this as non-fatal.
    if (caches.isInitialized()) {
        caches.textureState().unbindTexture(texture.mId);
    }
    texture.mId = 0;
}

}; // namespace uirenderer
}; // namespace android
Loading