From 1f2b35fef2d09effc2f7f2016a65adc82f828bac Mon Sep 17 00:00:00 2001 From: kanjitalk755 Date: Wed, 12 Aug 2020 11:39:58 +0900 Subject: [PATCH] reserve framebuffer --- BasiliskII/src/CrossPlatform/vm_alloc.cpp | 11 ++++++++++- BasiliskII/src/CrossPlatform/vm_alloc.h | 2 ++ BasiliskII/src/SDL/video_sdl2.cpp | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/BasiliskII/src/CrossPlatform/vm_alloc.cpp b/BasiliskII/src/CrossPlatform/vm_alloc.cpp index 005cb727..cc51bd29 100755 --- a/BasiliskII/src/CrossPlatform/vm_alloc.cpp +++ b/BasiliskII/src/CrossPlatform/vm_alloc.cpp @@ -222,6 +222,13 @@ void vm_exit(void) #endif } +static void *reserved_buf; +static const size_t RESERVED_SIZE = 64 * 1024 * 1024; // for 5K Retina + +void *vm_acquire_reserved(size_t size) { + return reserved_buf && size <= RESERVED_SIZE ? reserved_buf : VM_MAP_FAILED; +} + /* Allocate zero-filled memory of SIZE bytes. The mapping is private and default protection bits are read / write. The return value is the actual mapping address chosen or VM_MAP_FAILED for errors. */ @@ -243,11 +250,13 @@ void * vm_acquire(size_t size, int options) #if defined(HAVE_MACH_VM) // vm_allocate() returns a zero-filled memory region - kern_return_t ret_code = vm_allocate(mach_task_self(), (vm_address_t *)&addr, size, TRUE); + kern_return_t ret_code = vm_allocate(mach_task_self(), (vm_address_t *)&addr, reserved_buf ? size : size + RESERVED_SIZE, TRUE); if (ret_code != KERN_SUCCESS) { errno = vm_error(ret_code); return VM_MAP_FAILED; } + if (!reserved_buf) + reserved_buf = (char *)addr + size; #elif defined(HAVE_MMAP_VM) int fd = zero_fd; int the_map_flags = translate_map_flags(options) | map_flags; diff --git a/BasiliskII/src/CrossPlatform/vm_alloc.h b/BasiliskII/src/CrossPlatform/vm_alloc.h index c44e853b..bc5aba97 100644 --- a/BasiliskII/src/CrossPlatform/vm_alloc.h +++ b/BasiliskII/src/CrossPlatform/vm_alloc.h @@ -99,6 +99,8 @@ extern void vm_exit(void); extern void * vm_acquire(size_t size, int options = VM_MAP_DEFAULT); +extern void * vm_acquire_reserved(size_t size); + /* Allocate zero-filled memory at exactly ADDR (which must be page-aligned). Returns 0 if successful, -1 on errors. */ diff --git a/BasiliskII/src/SDL/video_sdl2.cpp b/BasiliskII/src/SDL/video_sdl2.cpp index a17921a6..2dc0a3ca 100644 --- a/BasiliskII/src/SDL/video_sdl2.cpp +++ b/BasiliskII/src/SDL/video_sdl2.cpp @@ -215,6 +215,9 @@ extern void SysMountFirstFloppy(void); static void *vm_acquire_framebuffer(uint32 size) { +#ifdef HAVE_MACH_VM + return vm_acquire_reserved(size); +#else // always try to reallocate framebuffer at the same address static void *fb = VM_MAP_FAILED; if (fb != VM_MAP_FAILED) { @@ -228,11 +231,12 @@ static void *vm_acquire_framebuffer(uint32 size) if (fb == VM_MAP_FAILED) fb = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT); return fb; +#endif } static inline void vm_release_framebuffer(void *fb, uint32 size) { - vm_release(fb, size); +// vm_release(fb, size); } static inline int get_customized_color_depth(int default_depth)