egl: Add EGL_EXT_protected_content support
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 14 Dec 2020 10:15:11 +0000 (12:15 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 27 Oct 2022 10:53:18 +0000 (10:53 +0000)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8092>

include/GL/internal/dri_interface.h
src/egl/drivers/dri2/egl_dri2.c
src/egl/main/eglapi.c
src/egl/main/eglcontext.c
src/egl/main/eglcontext.h
src/egl/main/egldisplay.h
src/egl/main/eglimage.c
src/egl/main/eglimage.h
src/egl/main/eglsurface.c
src/gallium/frontends/dri/dri_util.c
src/gallium/frontends/dri/dri_util.h

index f29f628..d680abd 100644 (file)
@@ -1090,7 +1090,14 @@ struct __DRIdri2LoaderExtensionRec {
 
 #define __DRI_CTX_ATTRIB_NO_ERROR               6
 
-#define __DRI_CTX_NUM_ATTRIBS                   7
+/**
+ * \requires __DRI2_RENDER_HAS_PROTECTED_CONTEXT.
+ *
+ */
+#define __DRI_CTX_ATTRIB_PROTECTED              7
+
+
+#define __DRI_CTX_NUM_ATTRIBS                   8
 
 /**
  * \name Reasons that __DRIdri2Extension::createContextAttribs might fail
@@ -1894,6 +1901,8 @@ typedef struct __DRIDriverVtableExtensionRec {
 #define __DRI2_RENDERER_PREFER_BACK_BUFFER_REUSE              0x000f
 #define __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT                  0x0010
 
+#define __DRI2_RENDERER_HAS_PROTECTED_CONTEXT                 0x0020
+
 typedef struct __DRI2rendererQueryExtensionRec __DRI2rendererQueryExtension;
 struct __DRI2rendererQueryExtensionRec {
    __DRIextension base;
index 362271a..cba764b 100644 (file)
@@ -1027,6 +1027,9 @@ dri2_setup_screen(_EGLDisplay *disp)
    disp->Extensions.EXT_protected_surface =
       dri2_renderer_query_integer(dri2_dpy,
                                   __DRI2_RENDERER_HAS_PROTECTED_SURFACE);
+   disp->Extensions.EXT_protected_content =
+      dri2_renderer_query_integer(dri2_dpy,
+                                  __DRI2_RENDERER_HAS_PROTECTED_CONTEXT);
 }
 
 void
@@ -1480,6 +1483,11 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx,
       ctx_attribs[pos++] = true;
    }
 
+   if (dri2_ctx->base.Protected) {
+      ctx_attribs[pos++] = __DRI_CTX_ATTRIB_PROTECTED;
+      ctx_attribs[pos++] = true;
+   }
+
    *num_attribs = pos;
 
    return true;
index e20c03a..97aab22 100644 (file)
@@ -563,6 +563,7 @@ _eglCreateExtensionsString(_EGLDisplay *disp)
    _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
    _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
    _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers);
+   _EGL_CHECK_EXTENSION(EXT_protected_content);
    _EGL_CHECK_EXTENSION(EXT_protected_surface);
    _EGL_CHECK_EXTENSION(EXT_present_opaque);
    _EGL_CHECK_EXTENSION(EXT_surface_CTA861_3_metadata);
index e7b4cd0..63b65cc 100644 (file)
@@ -407,6 +407,14 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
          }
          break;
 
+      case EGL_PROTECTED_CONTENT_EXT:
+         if (!disp->Extensions.EXT_protected_content) {
+            err = EGL_BAD_ATTRIBUTE;
+            break;
+         }
+         ctx->Protected = val == EGL_TRUE;
+         break;
+
       default:
          err = EGL_BAD_ATTRIBUTE;
          break;
@@ -673,6 +681,8 @@ _eglQueryContextRenderBuffer(_EGLContext *ctx)
 EGLBoolean
 _eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value)
 {
+   _EGLDisplay *disp = c->Resource.Display;
+
    if (!value)
       return _eglError(EGL_BAD_PARAMETER, "eglQueryContext");
 
@@ -699,6 +709,11 @@ _eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value)
    case EGL_CONTEXT_PRIORITY_LEVEL_IMG:
       *value = c->ContextPriority;
       break;
+   case EGL_PROTECTED_CONTENT_EXT:
+      if (!disp->Extensions.EXT_protected_content)
+         return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext");
+      *value = c->Protected;
+      break;
    default:
       return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext");
    }
index cbdefa3..8fb6eeb 100644 (file)
@@ -63,6 +63,7 @@ struct _egl_context
    EGLint ContextPriority;
    EGLBoolean NoError;
    EGLint ReleaseBehavior;
+   EGLBoolean Protected; /* EGL_EXT_protected_content */
 };
 
 
index b99fddc..28c2b29 100644 (file)
@@ -112,6 +112,7 @@ struct _egl_extensions
    EGLBoolean EXT_image_dma_buf_import;
    EGLBoolean EXT_image_dma_buf_import_modifiers;
    EGLBoolean EXT_pixel_format_float;
+   EGLBoolean EXT_protected_content;
    EGLBoolean EXT_protected_surface;
    EGLBoolean EXT_present_opaque;
    EGLBoolean EXT_surface_CTA861_3_metadata;
index 64bf7f2..997855f 100644 (file)
@@ -59,7 +59,8 @@ _eglParseKHRImageAttribs(_EGLImageAttribs *attrs, _EGLDisplay *disp,
       attrs->GLTextureZOffset = val;
       break;
    case EGL_PROTECTED_CONTENT_EXT:
-      if (!disp->Extensions.EXT_protected_surface)
+      if (!disp->Extensions.EXT_protected_content &&
+          !disp->Extensions.EXT_protected_surface)
          return EGL_BAD_PARAMETER;
 
       attrs->ProtectedContent = val;
index 3da3d68..02ad3b8 100644 (file)
@@ -78,7 +78,7 @@ struct _egl_image_attribs
    struct _egl_image_attrib_int DMABufChromaHorizontalSiting;
    struct _egl_image_attrib_int DMABufChromaVerticalSiting;
 
-   /* EGL_EXT_protected_surface */
+   /* EGL_EXT_protected_content || EGL_EXT_protected_surface */
    EGLBoolean ProtectedContent;
 };
 
index ae356e8..eb920ea 100644 (file)
@@ -319,7 +319,8 @@ _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list)
          surf->MipmapTexture = !!val;
          break;
       case EGL_PROTECTED_CONTENT_EXT:
-         if (!disp->Extensions.EXT_protected_surface) {
+         if (!disp->Extensions.EXT_protected_content &&
+             !disp->Extensions.EXT_protected_surface) {
             err = EGL_BAD_ATTRIBUTE;
             break;
          }
@@ -607,7 +608,8 @@ _eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surface,
       *value = surface->HdrMetadata.max_fall;
       break;
    case EGL_PROTECTED_CONTENT_EXT:
-      if (!disp->Extensions.EXT_protected_surface)
+      if (!disp->Extensions.EXT_protected_content &&
+          !disp->Extensions.EXT_protected_surface)
          return _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface");
       *value = surface->ProtectedContent;
       break;
index ab010e6..ed10245 100644 (file)
@@ -534,6 +534,13 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
                   ~__DRIVER_CONTEXT_ATTRIB_NO_ERROR;
             }
             break;
+        case __DRI_CTX_ATTRIB_PROTECTED:
+           if (attribs[i * 2 + 1]) {
+              ctx_config.attribute_mask |= __DRIVER_CONTEXT_ATTRIB_PROTECTED;
+           } else {
+              ctx_config.attribute_mask &= ~__DRIVER_CONTEXT_ATTRIB_PROTECTED;
+           }
+           break;
         default:
             /* We can't create a context that satisfies the requirements of an
              * attribute that we don't understand.  Return failure.
index af1a29b..6e6bd76 100644 (file)
@@ -107,12 +107,16 @@ struct __DriverContextConfig {
 
     /* Only valid if __DRIVER_CONTEXT_ATTRIB_NO_ERROR is set */
     int no_error;
+
+    /* Only valid if __DRIVER_CONTEXT_ATTRIB_PROTECTED is set */
+    int protected_context;
 };
 
 #define __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY   (1 << 0)
 #define __DRIVER_CONTEXT_ATTRIB_PRIORITY         (1 << 1)
 #define __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR (1 << 2)
 #define __DRIVER_CONTEXT_ATTRIB_NO_ERROR         (1 << 3)
+#define __DRIVER_CONTEXT_ATTRIB_PROTECTED        (1 << 4)
 
 /**
  * Driver callback functions.