From f26b0f44e7db9af9e47a8a9bb0813a084a00d0a2 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sun, 4 Feb 2024 09:19:23 -0500 Subject: [PATCH] Add Target Dimensions vs. Image Dimensions. --- RemoteInput/EIOSTypes.hxx | 7 +- RemoteInput/Platform/NativeHooks_Darwin.cxx | 8 +- RemoteInput/Platform/NativeHooks_Linux.cxx | 8 +- RemoteInput/Platform/NativeHooks_Windows.cxx | 14 +-- RemoteInput/Plugin/ControlCenter.cxx | 102 +++++++++++++------ RemoteInput/Plugin/ControlCenter.hxx | 10 +- RemoteInput/Plugin/ImageData.cxx | 41 ++++++-- RemoteInput/Plugin/ImageData.hxx | 13 ++- 8 files changed, 141 insertions(+), 62 deletions(-) diff --git a/RemoteInput/EIOSTypes.hxx b/RemoteInput/EIOSTypes.hxx index 084cb03..e6053a0 100644 --- a/RemoteInput/EIOSTypes.hxx +++ b/RemoteInput/EIOSTypes.hxx @@ -21,6 +21,7 @@ enum class EIOSCommand: std::uint32_t COMMAND_NONE, KILL_APPLICATION, + GET_IMAGE_DIMENSIONS, GET_TARGET_DIMENSIONS, HAS_FOCUS, GAIN_FOCUS, @@ -80,8 +81,10 @@ typedef struct EIOSData { std::int32_t parent_process_id; std::int32_t parent_thread_id; - std::int32_t width; - std::int32_t height; + std::int32_t image_width; + std::int32_t image_height; + std::int32_t target_width; + std::int32_t target_height; bool debug_graphics; bool ui_scaling; ImageFormat image_format; diff --git a/RemoteInput/Platform/NativeHooks_Darwin.cxx b/RemoteInput/Platform/NativeHooks_Darwin.cxx index e05f31a..523bb70 100644 --- a/RemoteInput/Platform/NativeHooks_Darwin.cxx +++ b/RemoteInput/Platform/NativeHooks_Darwin.cxx @@ -161,7 +161,7 @@ void JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobject dstData, void* rasBase = reinterpret_cast(srcInfo.rasBase) + (srcInfo.scanStride * srcy) + (srcInfo.pixelStride * srcx); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); std::uint8_t* dest = control_center->get_image(); ImageFormat format = control_center->get_image_format(); @@ -250,7 +250,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb void* rasBase = reinterpret_cast(srcInfo.rasBase) + (srcInfo.scanStride * sy1) + (srcInfo.pixelStride * sx1); bool isRasterAligned = srcInfo.scanStride % srcInfo.pixelStride == 0; //!(srcInfo.scanStride & 0x03); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); std::uint8_t* dest = control_center->get_image(); ImageFormat format = control_center->get_image_format(); @@ -481,7 +481,7 @@ CGLError mCGLFlushDrawable(CGLContextObj ctx) noexcept if (can_render(-1, width, height)) { - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); //Render to Shared Memory std::uint8_t* dest = control_center->get_image(); @@ -535,7 +535,7 @@ CGLError mCGLFlushDrawable(CGLContextObj ctx) noexcept if (can_render(-1, width, height)) { - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); //Render to Shared Memory std::uint8_t* dest = control_center->get_image(); diff --git a/RemoteInput/Platform/NativeHooks_Linux.cxx b/RemoteInput/Platform/NativeHooks_Linux.cxx index 4756c53..0c42a62 100644 --- a/RemoteInput/Platform/NativeHooks_Linux.cxx +++ b/RemoteInput/Platform/NativeHooks_Linux.cxx @@ -152,7 +152,7 @@ void JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobject dstData, void* rasBase = reinterpret_cast(srcInfo.rasBase) + (srcInfo.scanStride * srcy) + (srcInfo.pixelStride * srcx); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); std::uint8_t* dest = control_center->get_image(); ImageFormat format = control_center->get_image_format(); @@ -241,7 +241,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb void* rasBase = reinterpret_cast(srcInfo.rasBase) + (srcInfo.scanStride * sy1) + (srcInfo.pixelStride * sx1); bool isRasterAligned = srcInfo.scanStride % srcInfo.pixelStride == 0; //!(srcInfo.scanStride & 0x03); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); std::uint8_t* dest = control_center->get_image(); ImageFormat format = control_center->get_image_format(); @@ -387,7 +387,7 @@ extern "C" [[gnu::visibility("default")]] Bool XShmPutImage(Display *display, Dr int stride = width * bytes_per_pixel; void *rasBase = reinterpret_cast(image->data) + (stride * src_y) + (bytes_per_pixel * src_x); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); //Render to Shared Memory std::uint8_t* dest = control_center->get_image(); @@ -533,7 +533,7 @@ extern "C" [[gnu::visibility("default")]] void glXSwapBuffers(Display* dpy, GLXD if (width >= 200 && height >= 200) { - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); //Render to Shared Memory std::uint8_t* dest = control_center->get_image(); diff --git a/RemoteInput/Platform/NativeHooks_Windows.cxx b/RemoteInput/Platform/NativeHooks_Windows.cxx index 5f478ce..d40644c 100644 --- a/RemoteInput/Platform/NativeHooks_Windows.cxx +++ b/RemoteInput/Platform/NativeHooks_Windows.cxx @@ -173,7 +173,7 @@ void __stdcall JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobjec void* rasBase = reinterpret_cast(srcInfo.rasBase) + (srcInfo.scanStride * srcy) + (srcInfo.pixelStride * srcx); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); std::uint8_t* dest = control_center->get_image(); ImageFormat format = control_center->get_image_format(); @@ -274,7 +274,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb void* rasBase = reinterpret_cast(srcInfo.rasBase) + (srcInfo.scanStride * sy1) + (srcInfo.pixelStride * sx1); bool isRasterAligned = srcInfo.scanStride % srcInfo.pixelStride == 0; //!(srcInfo.scanStride & 0x03); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); std::uint8_t* dest = control_center->get_image(); ImageFormat format = control_center->get_image_format(); @@ -464,7 +464,7 @@ void __stdcall JavaNativeGDIBlit(JNIEnv *env, jobject joSelf, jobject srcData, j void* rasBase = reinterpret_cast(srcInfo.rasBase) + (srcInfo.scanStride * srcy) + (srcInfo.pixelStride * srcx); bool isRasterAligned = !(srcInfo.scanStride & 0x03); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); std::uint8_t* dest = control_center->get_image(); ImageFormat format = control_center->get_image_format(); @@ -619,7 +619,7 @@ HRESULT __cdecl JavaDirectXCopyImageToIntArgbSurface(IDirect3DSurface9 *pSurface jint height = srcHeight; //Prepare for BackBuffer Rendering - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); ImageFormat format = control_center->get_image_format(); std::uint8_t* destImage = ptr_coord(control_center->get_image(), srcx, srcy, pDstInfo->pixelStride, pDstInfo->scanStride); std::uint8_t* debugImage = ptr_coord(control_center->get_debug_graphics() ? control_center->get_debug_image() : nullptr, srcx, srcy, pDstInfo->pixelStride, pDstInfo->scanStride); @@ -800,7 +800,7 @@ HRESULT __cdecl JavaDirectXCopyImageToIntXrgbSurface(SurfaceDataRasInfo *pSrcInf jint height = pSrcInfo->bounds.y2 - pSrcInfo->bounds.y1; //Prepare for BackBuffer Rendering - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); ImageFormat format = control_center->get_image_format(); std::uint8_t* destImage = ptr_coord(control_center->get_image(), srcx, srcy, pSrcInfo->pixelStride, pSrcInfo->scanStride); std::uint8_t* debugImage = ptr_coord(control_center->get_debug_graphics() ? control_center->get_debug_image() : nullptr, srcx, srcy, pSrcInfo->pixelStride, pSrcInfo->scanStride); @@ -1076,7 +1076,7 @@ void __stdcall mglDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenu int stride = width * bytes_per_pixel; void *rasBase = static_cast(const_cast(data)) + (stride * src_y) + (bytes_per_pixel * src_x); - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); //Render to Shared Memory std::uint8_t* dest = control_center->get_image(); @@ -1128,7 +1128,7 @@ BOOL __stdcall mSwapBuffers(HDC hdc) noexcept if (can_render(-1, width, height)) { - control_center->update_dimensions(width, height); + control_center->set_target_dimensions(width, height); //Check if extensions are supported //This check is needed for renderers that do not support pixel buffer objects or vertex buffer objects diff --git a/RemoteInput/Plugin/ControlCenter.cxx b/RemoteInput/Plugin/ControlCenter.cxx index 872cb7f..d109393 100644 --- a/RemoteInput/Plugin/ControlCenter.cxx +++ b/RemoteInput/Plugin/ControlCenter.cxx @@ -193,10 +193,17 @@ void ControlCenter::process_command() noexcept } break; + case EIOSCommand::GET_IMAGE_DIMENSIONS: + { + image_data.set_image_width(get_image_width()); + image_data.set_image_height(get_image_height()); + } + break; + case EIOSCommand::GET_TARGET_DIMENSIONS: { - image_data.set_width(get_width()); - image_data.set_height(get_height()); + image_data.set_target_width(get_target_width()); + image_data.set_target_height(get_target_height()); } break; @@ -891,15 +898,15 @@ bool ControlCenter::init_maps() noexcept memory_map = std::make_unique>(mapName, sizeof(ImageData), MemoryMapStream::open_mode::read); if (memory_map && memory_map->is_mapped()) { - int width = memory_map->data().width(); - int height = memory_map->data().height(); + int image_width = memory_map->data().image_width(); + int image_height = memory_map->data().image_height(); - if (width && height) + if (image_width && image_height) { - std::size_t image_size = width * height * 4 * sizeof(std::uint8_t); - std::size_t debug_size = width * height * 4 * sizeof(std::uint8_t); + std::size_t image_size = image_width * image_height * 4 * sizeof(std::uint8_t); + std::size_t debug_size = image_width * image_height * 4 * sizeof(std::uint8_t); std::size_t extra_size = (1024 * sizeof(std::int32_t)); - std::int32_t map_size = sizeof(EIOSData) + image_size + debug_size + extra_size; + std::size_t map_size = sizeof(EIOSData) + image_size + debug_size + extra_size; //Open only.. memory_map = std::make_unique>(mapName, map_size, MemoryMapStream::open_mode::read | MemoryMapStream::open_mode::write); @@ -909,21 +916,22 @@ bool ControlCenter::init_maps() noexcept return false; } - int width = 0; - int height = 0; - GetDesktopResolution(width, height); //TODO: Change to Target Window size.. + int image_width = 0; + int image_height = 0; + GetDesktopResolution(image_width, image_height); - std::size_t image_size = width * height * 4 * sizeof(std::uint8_t); - std::size_t debug_size = width * height * 4 * sizeof(std::uint8_t); + std::size_t image_size = image_width * image_height * 4 * sizeof(std::uint8_t); + std::size_t debug_size = image_width * image_height * 4 * sizeof(std::uint8_t); std::size_t extra_size = (1024 * sizeof(std::int32_t)); - std::int32_t map_size = sizeof(EIOSData) + image_size + debug_size + extra_size; + std::size_t map_size = sizeof(EIOSData) + image_size + debug_size + extra_size; //Create only.. memory_map = std::make_unique>(mapName, map_size, MemoryMapStream::open_mode::read | MemoryMapStream::open_mode::write | MemoryMapStream::open_mode::create); bool result = memory_map && memory_map->is_mapped(); if (result) { - update_dimensions(width, height); + set_image_dimensions(image_width, image_height); + set_target_dimensions(image_width, image_height); } return result; } @@ -1030,14 +1038,24 @@ std::int32_t ControlCenter::parent_thread_id() const noexcept return memory_map && memory_map->is_mapped() ? get_image_data()->parent_thread_id() : -1; } -std::int32_t ControlCenter::get_width() const noexcept +std::int32_t ControlCenter::get_image_width() const noexcept { - return memory_map && memory_map->is_mapped() ? get_image_data()->width() : -1; + return memory_map && memory_map->is_mapped() ? get_image_data()->image_width() : -1; } -std::int32_t ControlCenter::get_height() const noexcept +std::int32_t ControlCenter::get_image_height() const noexcept { - return memory_map && memory_map->is_mapped() ? get_image_data()->height() : -1; + return memory_map && memory_map->is_mapped() ? get_image_data()->image_height() : -1; +} + +std::int32_t ControlCenter::get_target_width() const noexcept +{ + return memory_map && memory_map->is_mapped() ? get_image_data()->target_width() : -1; +} + +std::int32_t ControlCenter::get_target_height() const noexcept +{ + return memory_map && memory_map->is_mapped() ? get_image_data()->target_height() : -1; } std::uint8_t* ControlCenter::get_image() const noexcept @@ -1048,8 +1066,8 @@ std::uint8_t* ControlCenter::get_image() const noexcept std::uint8_t* ControlCenter::get_debug_image() const noexcept { - std::uint8_t* image = get_image(); - return image ? image + (get_width() * get_height() * 4) : nullptr; + ImageData* image_data = get_image_data(); + return image_data ? image_data->debug_image_buffer() : nullptr; } bool ControlCenter::get_debug_graphics() const noexcept @@ -1204,7 +1222,17 @@ void ControlCenter::kill_process(std::int32_t pid) const noexcept }); } -void ControlCenter::update_dimensions(std::int32_t width, std::int32_t height) const noexcept +void ControlCenter::set_image_dimensions(std::int32_t width, std::int32_t height) const noexcept +{ + if (memory_map && memory_map->is_mapped()) + { + ImageData* image_data = get_image_data(); + image_data->set_image_width(width); + image_data->set_image_height(height); + } +} + +void ControlCenter::set_target_dimensions(std::int32_t width, std::int32_t height) const noexcept { if (memory_map && memory_map->is_mapped()) { @@ -1220,29 +1248,43 @@ void ControlCenter::update_dimensions(std::int32_t width, std::int32_t height) c if (w > 0 && h > 0) { - image_data->set_width(w); - image_data->set_height(h); + image_data->set_target_width(w); + image_data->set_target_height(h); } else { - image_data->set_width(width); - image_data->set_height(height); + image_data->set_target_width(width); + image_data->set_target_height(height); } } else { - image_data->set_width(width); - image_data->set_height(height); + image_data->set_target_width(width); + image_data->set_target_height(height); } } } +void ControlCenter::get_image_dimensions(std::int32_t* width, std::int32_t* height) const noexcept +{ + if (memory_map && memory_map->is_mapped()) + { + *width = get_image_width(); + *height = get_image_height(); + } + else + { + *width = -1; + *height = -1; + } +} + void ControlCenter::get_target_dimensions(std::int32_t* width, std::int32_t* height) const noexcept { if (memory_map && memory_map->is_mapped()) { - *width = get_width(); - *height = get_height(); + *width = get_target_width(); + *height = get_target_height(); } else { diff --git a/RemoteInput/Plugin/ControlCenter.hxx b/RemoteInput/Plugin/ControlCenter.hxx index f651be2..116d297 100644 --- a/RemoteInput/Plugin/ControlCenter.hxx +++ b/RemoteInput/Plugin/ControlCenter.hxx @@ -63,7 +63,8 @@ public: bool hasReflector() const noexcept; void set_parent_process_id(std::int32_t pid) const noexcept; void set_parent_thread_id(std::int32_t tid) const noexcept; - void update_dimensions(std::int32_t width, std::int32_t height) const noexcept; + void set_image_dimensions(std::int32_t width, std::int32_t height) const noexcept; + void set_target_dimensions(std::int32_t width, std::int32_t height) const noexcept; static void signal_sync(std::int32_t pid) noexcept; static void wait_for_sync(std::int32_t pid) noexcept; @@ -74,8 +75,10 @@ public: std::int32_t parent_process_id() const noexcept; std::int32_t parent_thread_id() const noexcept; - std::int32_t get_width() const noexcept; - std::int32_t get_height() const noexcept; + std::int32_t get_image_width() const noexcept; + std::int32_t get_image_height() const noexcept; + std::int32_t get_target_width() const noexcept; + std::int32_t get_target_height() const noexcept; std::uint8_t* get_image() const noexcept; std::uint8_t* get_debug_image() const noexcept; bool get_debug_graphics() const noexcept; @@ -90,6 +93,7 @@ public: void set_keyboard_input_enabled(bool enabled) const noexcept; bool is_mouse_input_enabled() const noexcept; void set_mouse_input_enabled(bool enabled) const noexcept; + void get_image_dimensions(std::int32_t* width, std::int32_t* height) const noexcept; void get_target_dimensions(std::int32_t* width, std::int32_t* height) const noexcept; ImageFormat get_image_format() const noexcept; void set_image_format(ImageFormat format) noexcept; diff --git a/RemoteInput/Plugin/ImageData.cxx b/RemoteInput/Plugin/ImageData.cxx index d3016c3..1096668 100644 --- a/RemoteInput/Plugin/ImageData.cxx +++ b/RemoteInput/Plugin/ImageData.cxx @@ -38,14 +38,24 @@ std::int32_t ImageData::parent_thread_id() const return image_data->parent_thread_id; } -std::int32_t ImageData::width() const +std::int32_t ImageData::image_width() const { - return image_data->width; + return image_data->image_width; } -std::int32_t ImageData::height() const +std::int32_t ImageData::image_height() const { - return image_data->height; + return image_data->image_height; +} + +std::int32_t ImageData::target_width() const +{ + return image_data->target_width; +} + +std::int32_t ImageData::target_height() const +{ + return image_data->target_height; } bool ImageData::debug_graphics() const @@ -78,14 +88,24 @@ void ImageData::set_parent_thread_id(std::int32_t tid) image_data->parent_thread_id = tid; } -void ImageData::set_width(std::int32_t width) +void ImageData::set_image_width(std::int32_t width) { - image_data->width = width; + image_data->image_width = width; } -void ImageData::set_height(std::int32_t height) +void ImageData::set_image_height(std::int32_t height) { - image_data->height = height; + image_data->image_height = height; +} + +void ImageData::set_target_width(std::int32_t width) +{ + image_data->target_width = width; +} + +void ImageData::set_target_height(std::int32_t height) +{ + image_data->target_height = height; } void ImageData::set_debug_graphics(bool debug_graphics) @@ -129,6 +149,11 @@ std::uint8_t* ImageData::image_buffer() const noexcept return reinterpret_cast(image_data.get()) + sizeof(EIOSData); } +std::uint8_t* ImageData::debug_image_buffer() const noexcept +{ + return image_buffer() + image_width() * image_height() * 4; +} + Stream& ImageData::data_stream() const noexcept { return *stream; diff --git a/RemoteInput/Plugin/ImageData.hxx b/RemoteInput/Plugin/ImageData.hxx index 1b54c50..6a51eaa 100644 --- a/RemoteInput/Plugin/ImageData.hxx +++ b/RemoteInput/Plugin/ImageData.hxx @@ -27,8 +27,10 @@ public: std::int32_t parent_process_id() const; std::int32_t parent_thread_id() const; - std::int32_t width() const; - std::int32_t height() const; + std::int32_t image_width() const; + std::int32_t image_height() const; + std::int32_t target_width() const; + std::int32_t target_height() const; bool debug_graphics() const; bool ui_scaling() const; ImageFormat image_format() const; @@ -36,8 +38,10 @@ public: void set_parent_process_id(std::int32_t pid); void set_parent_thread_id(std::int32_t tid); - void set_width(std::int32_t width); - void set_height(std::int32_t height); + void set_image_width(std::int32_t width); + void set_image_height(std::int32_t height); + void set_target_width(std::int32_t width); + void set_target_height(std::int32_t height); void set_debug_graphics(bool debug_graphics); void set_ui_scaling(bool ui_scaling); void set_image_format(ImageFormat format); @@ -46,6 +50,7 @@ public: void* data_buffer(std::ios_base::openmode mode) const noexcept; std::uint8_t* image_buffer() const noexcept; + std::uint8_t* debug_image_buffer() const noexcept; Stream& data_stream() const noexcept; };