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

Commit 781c53a8 authored by Craig Donner's avatar Craig Donner Committed by Android (Google) Code Review
Browse files

Merge "Setting consumer protected mode on from SurfaceTexture when in a protected context."

parents aed01e49 4bbb8504
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

#include <stdio.h>

#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

@@ -34,6 +36,8 @@

// ----------------------------------------------------------------------------

#define EGL_QCOM_PROTECTED_CONTENT 0x32E0

namespace android {

static const char* const OutOfResourcesException =
@@ -55,6 +59,28 @@ static int32_t createProcessUniqueId() {
    return android_atomic_inc(&globalCounter);
}

// Check whether the current EGL context is protected.
static bool isProtectedContext() {
    EGLDisplay dpy = eglGetCurrentDisplay();
    EGLContext ctx = eglGetCurrentContext();

    if (dpy == EGL_NO_DISPLAY) {
        ALOGE("isProtectedSurface: invalid current EGLDisplay");
        return false;
    }

    if (ctx == EGL_NO_CONTEXT) {
        ALOGE("isProtectedSurface: invalid current EGLContext");
        return false;
    }

    EGLint isProtected = EGL_FALSE;
    // TODO: Change the enum value below when an extension is ratified.
    eglQueryContext(dpy, ctx, EGL_QCOM_PROTECTED_CONTENT, &isProtected);

    return isProtected;
}

// ----------------------------------------------------------------------------

static void SurfaceTexture_setSurfaceTexture(JNIEnv* env, jobject thiz,
@@ -263,6 +289,11 @@ static void SurfaceTexture_init(JNIEnv* env, jobject thiz, jboolean isDetached,
            getpid(),
            createProcessUniqueId()));

    // If the current context is protected, inform the producer.
    if (isProtectedContext()) {
        consumer->setConsumerUsageBits(GRALLOC_USAGE_PROTECTED);
    }

    SurfaceTexture_setSurfaceTexture(env, thiz, surfaceTexture);
    SurfaceTexture_setProducer(env, thiz, producer);