reuse existing mask layer

This commit is contained in:
Jesús A. Álvarez 2019-11-05 21:35:03 +01:00
parent f81ca7897a
commit f995962795
3 changed files with 20 additions and 15 deletions

View File

@ -71,9 +71,11 @@ void make_window_transparent(SDL_Window * window)
NSWindow *cocoaWindow = wmInfo.info.cocoa.window;
NSView *sdlView = cocoaWindow.contentView;
sdlView.layer.backgroundColor = [NSColor clearColor].CGColor;
CALayer *maskLayer = [CAShapeLayer layer];
sdlView.layer.mask = [maskLayer retain];
SDL_SetWindowData(window, "maskLayer", maskLayer);
if (SDL_GetWindowData(window, "maskLayer") == NULL) {
CALayer *maskLayer = [CAShapeLayer layer];
sdlView.layer.mask = maskLayer;
SDL_SetWindowData(window, "maskLayer", maskLayer);
}
cocoaWindow.backgroundColor = [NSColor clearColor];
cocoaWindow.hasShadow = NO;
cocoaWindow.opaque = NO;

View File

@ -13,6 +13,9 @@
#include "prefs.h"
#include <vector>
extern void make_window_transparent(SDL_Window * window);
extern void update_sdl_video(SDL_Surface *s, int numrects, SDL_Rect *rects);
/*
* Rootless mode support
*/
@ -340,13 +343,23 @@ void update_display_mask(SDL_Window *window, int w, int h) {
printf("low_mem_map at 0x%x\n", low_mem_map);
}
std::vector<SDL_Rect> mask_rects;
if (display_mask.w != w || display_mask.h != h) {
// new mask
free(display_mask.pixels);
display_mask.pixels = (uint8_t*)calloc(1, w*h*2);
display_mask.cursorMask = &display_mask.pixels[display_mask.w * display_mask.h];
display_mask.pixels = (uint8_t*)calloc(2, w*h);
display_mask.w = w;
display_mask.h = h;
display_mask.cursorMask = &display_mask.pixels[display_mask.w * display_mask.h];
// update whole screen
make_window_transparent(window);
SDL_Rect rect = {.x = 0, .y = 0, .w = w, .h = h};
update_sdl_video(NULL, 1, &rect);
mask_rects.push_back(rect);
memset(display_mask.pixels, 0xff, 2 * display_mask.w * display_mask.h);
return;
}
// clear all
@ -358,7 +371,6 @@ void update_display_mask(SDL_Window *window, int w, int h) {
MaskRegion(deskPortVisRgn, false);
bool has_front_process = false;
std::vector<SDL_Rect> mask_rects;
M68kRegisters r;
uint32 rootLayerPtr = 0;
@ -418,8 +430,6 @@ void apply_display_mask(SDL_Surface * host_surface, SDL_Rect update_rect) {
return;
}
//printf("apply video mask (%d,%d->%dx%d)\n", (int)update_rect.x, (int)update_rect.y, (int)update_rect.w, (int)update_rect.h);
if (host_surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
printf("Invalid host surface\n");
return;

View File

@ -66,7 +66,6 @@
#include "vm_alloc.h"
#ifdef VIDEO_ROOTLESS
extern void make_window_transparent(SDL_Window * window);
extern void update_display_mask(SDL_Window * window, int w, int h);
extern void apply_display_mask(SDL_Surface * host_surface, SDL_Rect update_rect);
extern bool cursor_point_opaque(void);
@ -757,12 +756,6 @@ static SDL_Surface * init_sdl_video(int width, int height, int bpp, Uint32 flags
}
}
if (flags & SDL_WINDOW_FULLSCREEN) SDL_SetWindowGrab(sdl_window, SDL_TRUE);
#ifdef VIDEO_ROOTLESS
if (PrefsFindBool("rootless")) {
make_window_transparent(sdl_window);
}
#endif
// Some SDL events (regarding some native-window events), need processing
// as they are generated. SDL2 has a facility, SDL_AddEventWatch(), which