[Commits] SDL: Added SDL_RenderGetMetalLayer() and SDL_RenderGetMetalComma...

libsdl.org revision control commits-owner at libsdl.org
Fri Dec 8 14:30:13 PST 2017


details:   https://hg.libsdl.org/SDL/rev/4d97d8cdaa90
changeset: 11744:4d97d8cdaa90
user:      Sam Lantinga <slouken at libsdl.org>
date:      Fri Dec 08 14:30:10 2017 -0800
description:
Added SDL_RenderGetMetalLayer() and SDL_RenderGetMetalCommandEncoder()

diffstat:

 include/SDL_render.h                |  21 +++++++++++++++++++++
 src/dynapi/SDL_dynapi_overrides.h   |   2 ++
 src/dynapi/SDL_dynapi_procs.h       |   2 ++
 src/render/SDL_render.c             |  22 ++++++++++++++++++++++
 src/render/SDL_sysrender.h          |   3 +++
 src/render/metal/SDL_render_metal.m |  17 +++++++++++++++++
 6 files changed, 67 insertions(+), 0 deletions(-)

diffs (135 lines):

diff -r 3af68ade4d30 -r 4d97d8cdaa90 include/SDL_render.h
--- a/include/SDL_render.h	Fri Dec 08 13:20:20 2017 -0800
+++ b/include/SDL_render.h	Fri Dec 08 14:30:10 2017 -0800
@@ -898,6 +898,27 @@
  */
 extern DECLSPEC int SDLCALL SDL_GL_UnbindTexture(SDL_Texture *texture);
 
+/**
+ *  \brief Get the CAMetalLayer associated with the given Metal renderer
+ *
+ *  \param renderer The renderer to query
+ *
+ *  \return CAMetalLayer* on success, or NULL if the renderer isn't a Metal renderer
+ *
+ *  \sa SDL_RenderGetMetalCommandEncoder()
+ */
+extern DECLSPEC void *SDLCALL SDL_RenderGetMetalLayer(SDL_Renderer * renderer);
+
+/**
+ *  \brief Get the Metal command encoder for the current frame
+ *
+ *  \param renderer The renderer to query
+ *
+ *  \return id<MTLRenderCommandEncoder> on success, or NULL if the renderer isn't a Metal renderer
+ *
+ *  \sa SDL_RenderGetMetalLayer()
+ */
+extern DECLSPEC void *SDLCALL SDL_RenderGetMetalCommandEncoder(SDL_Renderer * renderer);
 
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
diff -r 3af68ade4d30 -r 4d97d8cdaa90 src/dynapi/SDL_dynapi_overrides.h
--- a/src/dynapi/SDL_dynapi_overrides.h	Fri Dec 08 13:20:20 2017 -0800
+++ b/src/dynapi/SDL_dynapi_overrides.h	Fri Dec 08 14:30:10 2017 -0800
@@ -663,3 +663,5 @@
 #define SDL_SetYUVConversionMode SDL_SetYUVConversionMode_REAL
 #define SDL_GetYUVConversionMode SDL_GetYUVConversionMode_REAL
 #define SDL_GetYUVConversionModeForResolution SDL_GetYUVConversionModeForResolution_REAL
+#define SDL_RenderGetMetalLayer SDL_RenderGetMetalLayer_REAL
+#define SDL_RenderGetMetalCommandEncoder SDL_RenderGetMetalCommandEncoder_REAL
diff -r 3af68ade4d30 -r 4d97d8cdaa90 src/dynapi/SDL_dynapi_procs.h
--- a/src/dynapi/SDL_dynapi_procs.h	Fri Dec 08 13:20:20 2017 -0800
+++ b/src/dynapi/SDL_dynapi_procs.h	Fri Dec 08 14:30:10 2017 -0800
@@ -697,3 +697,5 @@
 SDL_DYNAPI_PROC(void,SDL_SetYUVConversionMode,(SDL_YUV_CONVERSION_MODE a),(a),)
 SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionMode,(void),(),return)
 SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionModeForResolution,(int a, int b),(a,b),return)
+SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalLayer,(SDL_Renderer *a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalCommandEncoder,(SDL_Renderer *a),(a),return)
diff -r 3af68ade4d30 -r 4d97d8cdaa90 src/render/SDL_render.c
--- a/src/render/SDL_render.c	Fri Dec 08 13:20:20 2017 -0800
+++ b/src/render/SDL_render.c	Fri Dec 08 14:30:10 2017 -0800
@@ -2123,6 +2123,28 @@
     return SDL_Unsupported();
 }
 
+void *
+SDL_RenderGetMetalLayer(SDL_Renderer * renderer)
+{
+    CHECK_RENDERER_MAGIC(renderer, NULL);
+
+    if (renderer->GetMetalLayer) {
+        return renderer->GetMetalLayer(renderer);
+    }
+    return NULL;
+}
+
+void *
+SDL_RenderGetMetalCommandEncoder(SDL_Renderer * renderer)
+{
+    CHECK_RENDERER_MAGIC(renderer, NULL);
+
+    if (renderer->GetMetalCommandEncoder) {
+        return renderer->GetMetalCommandEncoder(renderer);
+    }
+    return NULL;
+}
+
 static SDL_BlendMode
 SDL_GetShortBlendMode(SDL_BlendMode blendMode)
 {
diff -r 3af68ade4d30 -r 4d97d8cdaa90 src/render/SDL_sysrender.h
--- a/src/render/SDL_sysrender.h	Fri Dec 08 13:20:20 2017 -0800
+++ b/src/render/SDL_sysrender.h	Fri Dec 08 14:30:10 2017 -0800
@@ -123,6 +123,9 @@
     int (*GL_BindTexture) (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
     int (*GL_UnbindTexture) (SDL_Renderer * renderer, SDL_Texture *texture);
 
+    void *(*GetMetalLayer) (SDL_Renderer * renderer);
+    void *(*GetMetalCommandEncoder) (SDL_Renderer * renderer);
+
     /* The current renderer info */
     SDL_RendererInfo info;
 
diff -r 3af68ade4d30 -r 4d97d8cdaa90 src/render/metal/SDL_render_metal.m
--- a/src/render/metal/SDL_render_metal.m	Fri Dec 08 13:20:20 2017 -0800
+++ b/src/render/metal/SDL_render_metal.m	Fri Dec 08 14:30:10 2017 -0800
@@ -81,6 +81,8 @@
 static void METAL_RenderPresent(SDL_Renderer * renderer);
 static void METAL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
 static void METAL_DestroyRenderer(SDL_Renderer * renderer);
+static void *METAL_GetMetalLayer(SDL_Renderer * renderer);
+static void *METAL_GetMetalCommandEncoder(SDL_Renderer * renderer);
 
 SDL_RenderDriver METAL_RenderDriver = {
     METAL_CreateRenderer,
@@ -328,6 +330,8 @@
     renderer->RenderPresent = METAL_RenderPresent;
     renderer->DestroyTexture = METAL_DestroyTexture;
     renderer->DestroyRenderer = METAL_DestroyRenderer;
+    renderer->GetMetalLayer = METAL_GetMetalLayer;
+    renderer->GetMetalCommandEncoder = METAL_GetMetalCommandEncoder;
 
     renderer->info = METAL_RenderDriver.info;
     renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
@@ -786,6 +790,19 @@
     SDL_free(renderer);
 }}
 
+void *METAL_GetMetalLayer(SDL_Renderer * renderer)
+{ @autoreleasepool {
+    METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+    return (__bridge void*)data.mtllayer;
+}}
+
+void *METAL_GetMetalCommandEncoder(SDL_Renderer * renderer)
+{ @autoreleasepool {
+    METAL_ActivateRenderer(renderer);
+    METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+    return (__bridge void*)data.mtlcmdencoder;
+}}
+
 #endif /* SDL_VIDEO_RENDER_METAL && !SDL_RENDER_DISABLED */
 
 /* vi: set ts=4 sw=4 expandtab: */


More information about the commits mailing list