From 9de1263842607abe69d2dba07a81cc50e1fa6035 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Mon, 14 Dec 2020 12:15:11 +0200 Subject: [PATCH] egl: Add EGL_EXT_protected_content support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lionel Landwerlin Reviewed-by: Tapani Pälli Part-of: --- include/GL/internal/dri_interface.h | 11 ++++++++++- src/egl/drivers/dri2/egl_dri2.c | 8 ++++++++ src/egl/main/eglapi.c | 1 + src/egl/main/eglcontext.c | 15 +++++++++++++++ src/egl/main/eglcontext.h | 1 + src/egl/main/egldisplay.h | 1 + src/egl/main/eglimage.c | 3 ++- src/egl/main/eglimage.h | 2 +- src/egl/main/eglsurface.c | 6 ++++-- src/gallium/frontends/dri/dri_util.c | 7 +++++++ src/gallium/frontends/dri/dri_util.h | 4 ++++ 11 files changed, 54 insertions(+), 5 deletions(-) diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h index f29f62833b9..d680abda671 100644 --- a/include/GL/internal/dri_interface.h +++ b/include/GL/internal/dri_interface.h @@ -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; diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 362271a7d1a..cba764bb97b 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -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; diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index e20c03a6eac..97aab222de2 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -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); diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index e7b4cd073f2..63b65cc174b 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -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"); } diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h index cbdefa3432f..8fb6eeb70fc 100644 --- a/src/egl/main/eglcontext.h +++ b/src/egl/main/eglcontext.h @@ -63,6 +63,7 @@ struct _egl_context EGLint ContextPriority; EGLBoolean NoError; EGLint ReleaseBehavior; + EGLBoolean Protected; /* EGL_EXT_protected_content */ }; diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index b99fddc526c..28c2b299608 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -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; diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c index 64bf7f2bfe9..997855f48c0 100644 --- a/src/egl/main/eglimage.c +++ b/src/egl/main/eglimage.c @@ -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; diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h index 3da3d68027c..02ad3b8ef10 100644 --- a/src/egl/main/eglimage.h +++ b/src/egl/main/eglimage.h @@ -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; }; diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index ae356e8d87b..eb920ea9658 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -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; diff --git a/src/gallium/frontends/dri/dri_util.c b/src/gallium/frontends/dri/dri_util.c index ab010e60e0c..ed102450ecf 100644 --- a/src/gallium/frontends/dri/dri_util.c +++ b/src/gallium/frontends/dri/dri_util.c @@ -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. diff --git a/src/gallium/frontends/dri/dri_util.h b/src/gallium/frontends/dri/dri_util.h index af1a29be577..6e6bd76fba7 100644 --- a/src/gallium/frontends/dri/dri_util.h +++ b/src/gallium/frontends/dri/dri_util.h @@ -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.