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

Commit d3b13cbb authored by Chia-I Wu's avatar Chia-I Wu
Browse files

renderengine: move away from "new"

Replace "new" by either of std::vector or std::make_unique.

Bug: 115738279
Test: boots
Change-Id: I45704b34d668198ece741894829d752035dafff6
parent 56d7b0a7
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 {
+8 −9
Original line number Diff line number Diff line
@@ -116,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;
}

+0 −2
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;
}
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public:
    enum { position = 0, texCoords = 1 };

    Program(const ProgramCache::Key& needs, const char* vertex, const char* fragment);
    ~Program();
    ~Program() = default;

    /* whether this object is usable */
    bool isValid() const;
+3 −8
Original line number Diff line number Diff line
@@ -77,10 +77,6 @@ Formatter& dedent(Formatter& f) {
    return f;
}

ProgramCache::ProgramCache() {}

ProgramCache::~ProgramCache() {}

void ProgramCache::primeCache(bool useColorManagement) {
    uint32_t shaderCount = 0;
    uint32_t keyMask = Key::BLEND_MASK | Key::OPACITY_MASK | Key::ALPHA_MASK | Key::TEXTURE_MASK;
@@ -646,7 +642,7 @@ String8 ProgramCache::generateFragmentShader(const Key& needs) {
    return fs.getString();
}

Program* ProgramCache::generateProgram(const Key& needs) {
std::unique_ptr<Program> ProgramCache::generateProgram(const Key& needs) {
    ATRACE_CALL();

    // vertex shader
@@ -655,8 +651,7 @@ Program* ProgramCache::generateProgram(const Key& needs) {
    // fragment shader
    String8 fs = generateFragmentShader(needs);

    Program* program = new Program(needs, vs.string(), fs.string());
    return program;
    return std::make_unique<Program>(needs, vs.string(), fs.string());
}

void ProgramCache::useProgram(const Description& description) {
@@ -676,7 +671,7 @@ void ProgramCache::useProgram(const Description& description) {
    }

    // here we have a suitable program for this description
    Program* program = it->second;
    std::unique_ptr<Program>& program = it->second;
    if (program->isValid()) {
        program->use();
        program->setUniforms(description);
Loading