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

Commit 8fd2a4ec authored by Chia-I Wu's avatar Chia-I Wu Committed by Android (Google) Code Review
Browse files

Merge changes I45704b34,I28428e32,Iaba7b766,Icfe01188

* changes:
  renderengine: move away from "new"
  renderengine: use std::unordered_map in ProgramCache
  renderengine: remove hasExtension from GLExtensions
  renderengine: remove unused Program::dumpShader
parents c8e212ed d3b13cbb
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ Mesh::Mesh(Primitive primitive, size_t vertexCount, size_t vertexSize, size_t te
        mTexCoordsSize(texCoordSize),
        mPrimitive(primitive) {
    if (vertexCount == 0) {
        mVertices = new float[1];
        mVertices.resize(1);
        mVertices[0] = 0.0f;
        mStride = 0;
        return;
@@ -40,7 +40,7 @@ Mesh::Mesh(Primitive primitive, size_t vertexCount, size_t vertexSize, size_t te
    // will be equal to stride as long as stride * vertexCount doesn't overflow.
    if ((stride < vertexSize) || (remainder != stride)) {
        ALOGE("Overflow in Mesh(..., %zu, %zu, %zu)", vertexCount, vertexSize, texCoordSize);
        mVertices = new float[1];
        mVertices.resize(1);
        mVertices[0] = 0.0f;
        mVertexCount = 0;
        mVertexSize = 0;
@@ -49,30 +49,26 @@ Mesh::Mesh(Primitive primitive, size_t vertexCount, size_t vertexSize, size_t te
        return;
    }

    mVertices = new float[stride * vertexCount];
    mVertices.resize(stride * vertexCount);
    mStride = stride;
}

Mesh::~Mesh() {
    delete[] mVertices;
}

Mesh::Primitive Mesh::getPrimitive() const {
    return mPrimitive;
}

float const* Mesh::getPositions() const {
    return mVertices;
    return mVertices.data();
}
float* Mesh::getPositions() {
    return mVertices;
    return mVertices.data();
}

float const* Mesh::getTexCoords() const {
    return mVertices + mVertexSize;
    return mVertices.data() + mVertexSize;
}
float* Mesh::getTexCoords() {
    return mVertices + mVertexSize;
    return mVertices.data() + mVertexSize;
}

size_t Mesh::getVertexCount() const {
+13 −9
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <ui/DebugUtils.h>
#include <ui/Rect.h>
#include <ui/Region.h>
#include <utils/KeyedVector.h>
#include <utils/String8.h>
#include <utils/Trace.h>
#include "GLExtensions.h"
@@ -115,28 +116,27 @@ static status_t selectConfigForAttribute(EGLDisplay dpy, EGLint const* attrs, EG
                                         EGLint wanted, EGLConfig* outConfig) {
    EGLint numConfigs = -1, n = 0;
    eglGetConfigs(dpy, nullptr, 0, &numConfigs);
    EGLConfig* const configs = new EGLConfig[numConfigs];
    eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
    std::vector<EGLConfig> configs(numConfigs, EGL_NO_CONFIG_KHR);
    eglChooseConfig(dpy, attrs, configs.data(), configs.size(), &n);
    configs.resize(n);

    if (n) {
    if (!configs.empty()) {
        if (attribute != EGL_NONE) {
            for (int i = 0; i < n; i++) {
            for (EGLConfig config : configs) {
                EGLint value = 0;
                eglGetConfigAttrib(dpy, configs[i], attribute, &value);
                eglGetConfigAttrib(dpy, config, attribute, &value);
                if (wanted == value) {
                    *outConfig = configs[i];
                    delete[] configs;
                    *outConfig = config;
                    return NO_ERROR;
                }
            }
        } else {
            // just pick the first one
            *outConfig = configs[0];
            delete[] configs;
            return NO_ERROR;
        }
    }
    delete[] configs;

    return NAME_NOT_FOUND;
}

@@ -883,6 +883,10 @@ void GLES20RenderEngine::dump(String8& result) {
    result.appendFormat("GLES: %s, %s, %s\n", extensions.getVendor(), extensions.getRenderer(),
                        extensions.getVersion());
    result.appendFormat("%s\n", extensions.getExtensions());

    result.appendFormat("RenderEngine program cache size: %zu\n",
                        ProgramCache::getInstance().getSize());

    result.appendFormat("RenderEngine last dataspace conversion: (%s) to (%s)\n",
                        dataspaceDetails(static_cast<android_dataspace>(mDataSpace)).c_str(),
                        dataspaceDetails(static_cast<android_dataspace>(mOutputDataSpace)).c_str());
+36 −35
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

#include "GLExtensions.h"

#include <string>
#include <unordered_set>

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -26,35 +29,37 @@ namespace android {
namespace renderengine {
namespace gl {

SortedVector<String8> GLExtensions::parseExtensionString(char const* extensions) {
    SortedVector<String8> list;
namespace {

class ExtensionSet {
public:
    ExtensionSet(const char* extensions) {
        char const* curr = extensions;
        char const* head = curr;
        do {
            head = strchr(curr, ' ');
        String8 s(curr, head ? head - curr : strlen(curr));
        if (s.length()) {
            list.add(s);
            size_t len = head ? head - curr : strlen(curr);
            if (len > 0) {
                mExtensions.emplace(curr, len);
            }
            curr = head + 1;
        } while (head);

    return list;
    }

    bool hasExtension(const char* extension) const { return mExtensions.count(extension) > 0; }

private:
    std::unordered_set<std::string> mExtensions;
};

} // anonymous namespace

void GLExtensions::initWithGLStrings(GLubyte const* vendor, GLubyte const* renderer,
                                     GLubyte const* version, GLubyte const* extensions) {
    mVendor = (char const*)vendor;
    mRenderer = (char const*)renderer;
    mVersion = (char const*)version;
    mExtensions = (char const*)extensions;
    mExtensionList = parseExtensionString(mExtensions);
}

bool GLExtensions::hasExtension(char const* extension) const {
    const String8 s(extension);
    return mExtensionList.indexOf(s) >= 0;
}

char const* GLExtensions::getVendor() const {
@@ -76,7 +81,8 @@ char const* GLExtensions::getExtensions() const {
void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExtensions) {
    mEGLVersion = eglVersion;
    mEGLExtensions = eglExtensions;
    mEGLExtensionList = parseExtensionString(mEGLExtensions);

    ExtensionSet extensionSet(eglExtensions);

    // EGL_ANDROIDX_no_config_context is an experimental extension with no
    // written specification. It will be replaced by something more formal.
@@ -86,24 +92,24 @@ void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExt
    //
    // EGL_KHR_no_config_context is official extension to allow creating a
    // context that works with any surface of a display.
    if (hasEGLExtension("EGL_ANDROIDX_no_config_context") ||
        hasEGLExtension("EGL_KHR_no_config_context")) {
    if (extensionSet.hasExtension("EGL_ANDROIDX_no_config_context") ||
        extensionSet.hasExtension("EGL_KHR_no_config_context")) {
        mHasNoConfigContext = true;
    }

    if (hasEGLExtension("EGL_ANDROID_native_fence_sync")) {
    if (extensionSet.hasExtension("EGL_ANDROID_native_fence_sync")) {
        mHasNativeFenceSync = true;
    }
    if (hasEGLExtension("EGL_KHR_fence_sync")) {
    if (extensionSet.hasExtension("EGL_KHR_fence_sync")) {
        mHasFenceSync = true;
    }
    if (hasEGLExtension("EGL_KHR_wait_sync")) {
    if (extensionSet.hasExtension("EGL_KHR_wait_sync")) {
        mHasWaitSync = true;
    }
    if (hasEGLExtension("EGL_EXT_protected_content")) {
    if (extensionSet.hasExtension("EGL_EXT_protected_content")) {
        mHasProtectedContent = true;
    }
    if (hasEGLExtension("EGL_IMG_context_priority")) {
    if (extensionSet.hasExtension("EGL_IMG_context_priority")) {
        mHasContextPriority = true;
    }
}
@@ -116,11 +122,6 @@ char const* GLExtensions::getEGLExtensions() const {
    return mEGLExtensions.string();
}

bool GLExtensions::hasEGLExtension(char const* extension) const {
    const String8 s(extension);
    return mEGLExtensionList.indexOf(s) >= 0;
}

}  // namespace gl
}  // namespace renderengine
}  // namespace android
+0 −7
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <utils/Singleton.h>
#include <utils/SortedVector.h>
#include <utils/String8.h>

namespace android {
@@ -46,13 +45,9 @@ class GLExtensions : public Singleton<GLExtensions> {
    String8 mRenderer;
    String8 mVersion;
    String8 mExtensions;
    SortedVector<String8> mExtensionList;

    String8 mEGLVersion;
    String8 mEGLExtensions;
    SortedVector<String8> mEGLExtensionList;

    static SortedVector<String8> parseExtensionString(char const* extensions);

    GLExtensions(const GLExtensions&);
    GLExtensions& operator=(const GLExtensions&);
@@ -74,12 +69,10 @@ public:
    char const* getRenderer() const;
    char const* getVersion() const;
    char const* getExtensions() const;
    bool hasExtension(char const* extension) const;

    void initWithEGLStrings(char const* eglVersion, char const* eglExtensions);
    char const* getEGLVersion() const;
    char const* getEGLExtensions() const;
    bool hasEGLExtension(char const* extension) const;
};

}  // namespace gl
+0 −13
Original line number Diff line number Diff line
@@ -74,8 +74,6 @@ Program::Program(const ProgramCache::Key& /*needs*/, const char* vertex, const c
    }
}

Program::~Program() {}

bool Program::isValid() const {
    return mInitialized;
}
@@ -112,17 +110,6 @@ GLuint Program::buildShader(const char* source, GLenum type) {
    return shader;
}

String8& Program::dumpShader(String8& result, GLenum /*type*/) {
    GLuint shader = GL_FRAGMENT_SHADER ? mFragmentShader : mVertexShader;
    GLint l;
    glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &l);
    char* src = new char[l];
    glGetShaderSource(shader, l, nullptr, src);
    result.append(src);
    delete[] src;
    return result;
}

void Program::setUniforms(const Description& desc) {
    // TODO: we should have a mechanism here to not always reset uniforms that
    // didn't change for this program.
Loading