Leave the Metal view active on the window when recreating the Metal renderer

Fixes https://github.com/libsdl-org/SDL/issues/5140

Also move the metal tag definition to SDL_syswm.h so it can be used by applications
This commit is contained in:
Sam Lantinga
2022-01-07 12:37:28 -08:00
parent 88ac517df0
commit 4b38d4c96b
6 changed files with 55 additions and 10 deletions

View File

@@ -39,7 +39,6 @@
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
#define METALVIEW_TAG 255
@interface SDL_cocoametalview : NSView

View File

@@ -31,6 +31,8 @@
#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_METAL)
#include "SDL_events.h"
#include "SDL_syswm.h"
static int SDLCALL
SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
@@ -103,7 +105,7 @@ SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
- (NSInteger)tag
{
return METALVIEW_TAG;
return SDL_METALVIEW_TAG;
}
- (void)updateDrawableSize
@@ -173,7 +175,7 @@ Cocoa_Metal_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
{ @autoreleasepool {
SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
NSView *contentView = data->sdlContentView;
SDL_cocoametalview* metalview = [contentView viewWithTag:METALVIEW_TAG];
SDL_cocoametalview* metalview = [contentView viewWithTag:SDL_METALVIEW_TAG];
if (metalview) {
CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;
SDL_assert(layer != NULL);