首页 > 解决方案 > android ndk opengl creating protected context

问题描述

I am trying to create a protected context using opengl on android.

I am basing my code off of: https://github.com/googlesamples/android-ndk

Using the native activity as my base.

I have changed the EGL parameters to the following:

EGLint context_attribs[] = {
        EGL_CONTEXT_CLIENT_VERSION, 3,
        0x32C0, EGL_TRUE,
        EGL_NONE,
};
EGLint surface_attribs[] = {
        0x32C0, EGL_TRUE,
        EGL_NONE,
};

And things seem to work on most devices, but a few devices are giving strange behavior (phone crashes, or not displaying at all, even though they claim to support protected contexts). A good example is the s9 qualcomm edition runs fine, until anything appears on the screen (overlay, navbar slide down, or sliding the samsung side-bar) which will result in a phone reboot.

Is there something I may have missed with setting up the protected contexts?

According to the khronos docs: https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_protected_content.txt

0x32c0 is the correct number for protected content.

--------------EDIT--------------

I swapped 0x32c0 over to EGL_PROTECTED_CONTENT_EXT, and checked the extensions, and EGL_EXT_protected_content does exist. There are two devices I am working with that are having problems with this specifically (Samsung Galaxy s9+ qualcomm and Samsung Galaxy Tab S2). The S2 claims it supports the protected context, but then after using it, I get EGL_BAD_ALLOC. On the S9, everything runs fine, no errors, but the device will consistently crash on me after using it for a little.

标签: androidopengl-esandroid-ndkegl

解决方案


为什么使用 0x32C0 而不是令牌名称:EGL_PROTECTED_CONTENT_EXT?

您是否查询过扩展字符串“EGL_EXT_protected_content”在受支持的扩展中?这应该是你做的第一件事。

您是否尝试执行任何不允许的操作?可能导致崩溃。

从 eglCreateSurface 和 eglCreateContext 检查您的错误。EGL_BAD_ATTRIBUTE 表示不支持。


推荐阅读