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

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

Merge "Refactor ANGLE Platform support"

parents b17611d4 75ce4779
Loading
Loading
Loading
Loading
+73 −20
Original line number Original line Diff line number Diff line
@@ -16,28 +16,29 @@


#if defined(__ANDROID__)
#if defined(__ANDROID__)


#include <cutils/properties.h>
#include "Loader.h"
#include "egl_angle_platform.h"
#include "egl_angle_platform.h"
#include <time.h>


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <EGL/Platform.h>
#pragma GCC diagnostic pop

#include <android/dlext.h>
#include <dlfcn.h>
#include <graphicsenv/GraphicsEnv.h>
#include <time.h>
#include <log/log.h>
#include <log/log.h>


namespace angle {
namespace angle {


GetDisplayPlatformFunc AnglePlatformImpl::angleGetDisplayPlatform = nullptr;
static GetDisplayPlatformFunc angleGetDisplayPlatform = nullptr;
ResetDisplayPlatformFunc AnglePlatformImpl::angleResetDisplayPlatform = nullptr;
static ResetDisplayPlatformFunc angleResetDisplayPlatform = nullptr;
// Initialize start time
time_t AnglePlatformImpl::startTime = time(nullptr);


void AnglePlatformImpl::assignAnglePlatformMethods(PlatformMethods* platformMethods) {
static time_t startTime = time(nullptr);
    platformMethods->addTraceEvent = addTraceEvent;
    platformMethods->getTraceCategoryEnabledFlag = getTraceCategoryEnabledFlag;
    platformMethods->monotonicallyIncreasingTime = monotonicallyIncreasingTime;
    platformMethods->logError = logError;
    platformMethods->logWarning = logWarning;
    platformMethods->logInfo = logInfo;
}


const unsigned char* AnglePlatformImpl::getTraceCategoryEnabledFlag(PlatformMethods* /*platform*/,
static const unsigned char* getTraceCategoryEnabledFlag(PlatformMethods* /*platform*/,
                                                        const char* /*categoryName*/) {
                                                        const char* /*categoryName*/) {
    // Returning ptr to 'g' (non-zero) to ALWAYS enable tracing initially.
    // Returning ptr to 'g' (non-zero) to ALWAYS enable tracing initially.
    // This ptr is what will be passed into "category_group_enabled" of addTraceEvent
    // This ptr is what will be passed into "category_group_enabled" of addTraceEvent
@@ -45,23 +46,23 @@ const unsigned char* AnglePlatformImpl::getTraceCategoryEnabledFlag(PlatformMeth
    return &traceEnabled;
    return &traceEnabled;
}
}


double AnglePlatformImpl::monotonicallyIncreasingTime(PlatformMethods* /*platform*/) {
static double monotonicallyIncreasingTime(PlatformMethods* /*platform*/) {
    return difftime(time(nullptr), startTime);
    return difftime(time(nullptr), startTime);
}
}


void AnglePlatformImpl::logError(PlatformMethods* /*platform*/, const char* errorMessage) {
static void logError(PlatformMethods* /*platform*/, const char* errorMessage) {
    ALOGE("ANGLE Error:%s", errorMessage);
    ALOGE("ANGLE Error:%s", errorMessage);
}
}


void AnglePlatformImpl::logWarning(PlatformMethods* /*platform*/, const char* warningMessage) {
static void logWarning(PlatformMethods* /*platform*/, const char* warningMessage) {
    ALOGW("ANGLE Warn:%s", warningMessage);
    ALOGW("ANGLE Warn:%s", warningMessage);
}
}


void AnglePlatformImpl::logInfo(PlatformMethods* /*platform*/, const char* infoMessage) {
static void logInfo(PlatformMethods* /*platform*/, const char* infoMessage) {
    ALOGD("ANGLE Info:%s", infoMessage);
    ALOGD("ANGLE Info:%s", infoMessage);
}
}


TraceEventHandle AnglePlatformImpl::addTraceEvent(
static TraceEventHandle addTraceEvent(
        PlatformMethods* /**platform*/, char phase, const unsigned char* /*category_group_enabled*/,
        PlatformMethods* /**platform*/, char phase, const unsigned char* /*category_group_enabled*/,
        const char* name, unsigned long long /*id*/, double /*timestamp*/, int /*num_args*/,
        const char* name, unsigned long long /*id*/, double /*timestamp*/, int /*num_args*/,
        const char** /*arg_names*/, const unsigned char* /*arg_types*/,
        const char** /*arg_names*/, const unsigned char* /*arg_types*/,
@@ -88,6 +89,58 @@ TraceEventHandle AnglePlatformImpl::addTraceEvent(
    return result;
    return result;
}
}


static void assignAnglePlatformMethods(PlatformMethods* platformMethods) {
    platformMethods->addTraceEvent = addTraceEvent;
    platformMethods->getTraceCategoryEnabledFlag = getTraceCategoryEnabledFlag;
    platformMethods->monotonicallyIncreasingTime = monotonicallyIncreasingTime;
    platformMethods->logError = logError;
    platformMethods->logWarning = logWarning;
    platformMethods->logInfo = logInfo;
}

// Initialize function ptrs for ANGLE PlatformMethods struct, used for systrace
bool initializeAnglePlatform(EGLDisplay dpy) {
    // Since we're inside libEGL, use dlsym to lookup fptr for ANGLEGetDisplayPlatform
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
    const android_dlextinfo dlextinfo = {
            .flags = ANDROID_DLEXT_USE_NAMESPACE,
            .library_namespace = ns,
    };
    void* so = android_dlopen_ext("libEGL_angle.so", RTLD_LOCAL | RTLD_NOW, &dlextinfo);
    angleGetDisplayPlatform =
            reinterpret_cast<GetDisplayPlatformFunc>(dlsym(so, "ANGLEGetDisplayPlatform"));

    if (!angleGetDisplayPlatform) {
        ALOGE("dlsym lookup of ANGLEGetDisplayPlatform in libEGL_angle failed!");
        return false;
    }

    angleResetDisplayPlatform =
            reinterpret_cast<ResetDisplayPlatformFunc>(
                    eglGetProcAddress("ANGLEResetDisplayPlatform"));

    PlatformMethods* platformMethods = nullptr;
    if (!((angleGetDisplayPlatform)(dpy, g_PlatformMethodNames,
                                                              g_NumPlatformMethods, nullptr,
                                                              &platformMethods))) {
        ALOGE("ANGLEGetDisplayPlatform call failed!");
        return false;
    }
    if (platformMethods) {
        assignAnglePlatformMethods(platformMethods);
    } else {
        ALOGE("In initializeAnglePlatform() platformMethods struct ptr is NULL. Not assigning "
              "tracing function ptrs!");
    }
    return true;
}

void resetAnglePlatform(EGLDisplay dpy) {
    if (angleResetDisplayPlatform) {
        angleResetDisplayPlatform(dpy);
    }
}

}; // namespace angle
}; // namespace angle


#endif // __ANDROID__
#endif // __ANDROID__
+3 −28
Original line number Original line Diff line number Diff line
@@ -18,40 +18,15 @@


#if defined(__ANDROID__)
#if defined(__ANDROID__)


#pragma GCC diagnostic push
#include "egldefs.h"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <EGL/Platform.h>
#pragma GCC diagnostic pop


#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#define ATRACE_TAG ATRACE_TAG_GRAPHICS

#include "egl_trace.h"
#include "egl_trace.h"


namespace angle {
namespace angle {


class AnglePlatformImpl {
bool initializeAnglePlatform(EGLDisplay dpy);
public:
void resetAnglePlatform(EGLDisplay dpy);
    static void assignAnglePlatformMethods(PlatformMethods* platformMethods);
    static GetDisplayPlatformFunc angleGetDisplayPlatform;
    static ResetDisplayPlatformFunc angleResetDisplayPlatform;

private:
    static time_t startTime;
    static const unsigned char* getTraceCategoryEnabledFlag(PlatformMethods* /*platform*/,
                                                            const char* /*categoryName*/);
    static double monotonicallyIncreasingTime(PlatformMethods* /*platform*/);
    static void logError(PlatformMethods* /*platform*/, const char* errorMessage);
    static void logWarning(PlatformMethods* /*platform*/, const char* warningMessage);
    static void logInfo(PlatformMethods* /*platform*/, const char* infoMessage);
    static TraceEventHandle addTraceEvent(PlatformMethods* /**platform*/, char phase,
                                          const unsigned char* /*category_group_enabled*/,
                                          const char* name, unsigned long long /*id*/,
                                          double /*timestamp*/, int /*num_args*/,
                                          const char** /*arg_names*/,
                                          const unsigned char* /*arg_types*/,
                                          const unsigned long long* /*arg_values*/,
                                          unsigned char /*flags*/);
};


}; // namespace angle
}; // namespace angle


+3 −40
Original line number Original line Diff line number Diff line
@@ -164,43 +164,6 @@ static bool addAnglePlatformAttributes(egl_connection_t* const cnx,
    return true;
    return true;
}
}


// Initialize function ptrs for ANGLE PlatformMethods struct, used for systrace
bool initializeAnglePlatform(EGLDisplay dpy) {
    // Since we're inside libEGL, use dlsym to lookup fptr for ANGLEGetDisplayPlatform
    android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
    const android_dlextinfo dlextinfo = {
            .flags = ANDROID_DLEXT_USE_NAMESPACE,
            .library_namespace = ns,
    };
    void* so = android_dlopen_ext("libEGL_angle.so", RTLD_LOCAL | RTLD_NOW, &dlextinfo);
    angle::AnglePlatformImpl::angleGetDisplayPlatform =
            reinterpret_cast<angle::GetDisplayPlatformFunc>(dlsym(so, "ANGLEGetDisplayPlatform"));

    if (!angle::AnglePlatformImpl::angleGetDisplayPlatform) {
        ALOGE("dlsym lookup of ANGLEGetDisplayPlatform in libEGL_angle failed!");
        return false;
    }

    angle::AnglePlatformImpl::angleResetDisplayPlatform =
            reinterpret_cast<angle::ResetDisplayPlatformFunc>(
                    eglGetProcAddress("ANGLEResetDisplayPlatform"));

    angle::PlatformMethods* platformMethods = nullptr;
    if (!((angle::AnglePlatformImpl::angleGetDisplayPlatform)(dpy, angle::g_PlatformMethodNames,
                                                              angle::g_NumPlatformMethods, nullptr,
                                                              &platformMethods))) {
        ALOGE("ANGLEGetDisplayPlatform call failed!");
        return false;
    }
    if (platformMethods) {
        angle::AnglePlatformImpl::assignAnglePlatformMethods(platformMethods);
    } else {
        ALOGE("In initializeAnglePlatform() platformMethods struct ptr is NULL. Not assigning "
              "tracing function ptrs!");
    }
    return true;
}

static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx,
static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx,
                                          const EGLAttrib* attrib_list, EGLint* error) {
                                          const EGLAttrib* attrib_list, EGLint* error) {
    EGLDisplay dpy = EGL_NO_DISPLAY;
    EGLDisplay dpy = EGL_NO_DISPLAY;
@@ -228,7 +191,7 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn
        if (dpy == EGL_NO_DISPLAY) {
        if (dpy == EGL_NO_DISPLAY) {
            ALOGE("eglGetPlatformDisplay failed!");
            ALOGE("eglGetPlatformDisplay failed!");
        } else {
        } else {
            if (!initializeAnglePlatform(dpy)) {
            if (!angle::initializeAnglePlatform(dpy)) {
                ALOGE("initializeAnglePlatform failed!");
                ALOGE("initializeAnglePlatform failed!");
            }
            }
        }
        }
@@ -505,8 +468,8 @@ EGLBoolean egl_display_t::terminate() {
        egl_connection_t* const cnx = &gEGLImpl;
        egl_connection_t* const cnx = &gEGLImpl;
        if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
        if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
            // If we're using ANGLE reset any custom DisplayPlatform
            // If we're using ANGLE reset any custom DisplayPlatform
            if (cnx->useAngle && angle::AnglePlatformImpl::angleResetDisplayPlatform) {
            if (cnx->useAngle) {
                (angle::AnglePlatformImpl::angleResetDisplayPlatform)(disp.dpy);
                angle::resetAnglePlatform(disp.dpy);
            }
            }
            if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {
            if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {
                ALOGW("eglTerminate(%p) failed (%s)", disp.dpy,
                ALOGW("eglTerminate(%p) failed (%s)", disp.dpy,