Skip to content

Commit

Permalink
Add Target Dimensions vs. Image Dimensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Feb 4, 2024
1 parent 6f3c1b7 commit f26b0f4
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 62 deletions.
7 changes: 5 additions & 2 deletions RemoteInput/EIOSTypes.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class EIOSCommand: std::uint32_t
COMMAND_NONE,
KILL_APPLICATION,

GET_IMAGE_DIMENSIONS,
GET_TARGET_DIMENSIONS,
HAS_FOCUS,
GAIN_FOCUS,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions RemoteInput/Platform/NativeHooks_Darwin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobject dstData,

void* rasBase = reinterpret_cast<std::uint8_t*>(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();

Expand Down Expand Up @@ -250,7 +250,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb
void* rasBase = reinterpret_cast<std::uint8_t*>(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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions RemoteInput/Platform/NativeHooks_Linux.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobject dstData,

void* rasBase = reinterpret_cast<std::uint8_t*>(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();

Expand Down Expand Up @@ -241,7 +241,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb
void* rasBase = reinterpret_cast<std::uint8_t*>(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();

Expand Down Expand Up @@ -387,7 +387,7 @@ extern "C" [[gnu::visibility("default")]] Bool XShmPutImage(Display *display, Dr
int stride = width * bytes_per_pixel;
void *rasBase = reinterpret_cast<std::uint8_t*>(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();
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions RemoteInput/Platform/NativeHooks_Windows.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void __stdcall JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobjec

void* rasBase = reinterpret_cast<std::uint8_t*>(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();

Expand Down Expand Up @@ -274,7 +274,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb
void* rasBase = reinterpret_cast<std::uint8_t*>(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();

Expand Down Expand Up @@ -464,7 +464,7 @@ void __stdcall JavaNativeGDIBlit(JNIEnv *env, jobject joSelf, jobject srcData, j
void* rasBase = reinterpret_cast<std::uint8_t*>(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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1076,7 +1076,7 @@ void __stdcall mglDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenu
int stride = width * bytes_per_pixel;
void *rasBase = static_cast<std::uint8_t*>(const_cast<void*>(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();
Expand Down Expand Up @@ -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
Expand Down
102 changes: 72 additions & 30 deletions RemoteInput/Plugin/ControlCenter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -891,15 +898,15 @@ bool ControlCenter::init_maps() noexcept
memory_map = std::make_unique<MemoryMapStream<ImageData>>(mapName, sizeof(ImageData), MemoryMapStream<ImageData>::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<MemoryMapStream<ImageData>>(mapName, map_size, MemoryMapStream<ImageData>::open_mode::read | MemoryMapStream<ImageData>::open_mode::write);
Expand All @@ -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<MemoryMapStream<ImageData>>(mapName, map_size, MemoryMapStream<ImageData>::open_mode::read | MemoryMapStream<ImageData>::open_mode::write | MemoryMapStream<ImageData>::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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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())
{
Expand All @@ -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
{
Expand Down
10 changes: 7 additions & 3 deletions RemoteInput/Plugin/ControlCenter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit f26b0f4

Please sign in to comment.