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

Bug: 22775237
Bug: 22855417

Change-Id: I9608ba08b28b02f3df1cc334fdc22d645831f1f6
This commit is contained in:
Craig Donner
2016-01-12 10:22:39 -08:00
parent eb12d19417
commit 4bbb8504a7

View File

@@ -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);