Skip to content

Commit f26b0f4

Browse files
committed
Add Target Dimensions vs. Image Dimensions.
1 parent 6f3c1b7 commit f26b0f4

8 files changed

+141
-62
lines changed

RemoteInput/EIOSTypes.hxx

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum class EIOSCommand: std::uint32_t
2121
COMMAND_NONE,
2222
KILL_APPLICATION,
2323

24+
GET_IMAGE_DIMENSIONS,
2425
GET_TARGET_DIMENSIONS,
2526
HAS_FOCUS,
2627
GAIN_FOCUS,
@@ -80,8 +81,10 @@ typedef struct EIOSData
8081
{
8182
std::int32_t parent_process_id;
8283
std::int32_t parent_thread_id;
83-
std::int32_t width;
84-
std::int32_t height;
84+
std::int32_t image_width;
85+
std::int32_t image_height;
86+
std::int32_t target_width;
87+
std::int32_t target_height;
8588
bool debug_graphics;
8689
bool ui_scaling;
8790
ImageFormat image_format;

RemoteInput/Platform/NativeHooks_Darwin.cxx

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobject dstData,
161161

162162
void* rasBase = reinterpret_cast<std::uint8_t*>(srcInfo.rasBase) + (srcInfo.scanStride * srcy) + (srcInfo.pixelStride * srcx);
163163

164-
control_center->update_dimensions(width, height);
164+
control_center->set_target_dimensions(width, height);
165165
std::uint8_t* dest = control_center->get_image();
166166
ImageFormat format = control_center->get_image_format();
167167

@@ -250,7 +250,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb
250250
void* rasBase = reinterpret_cast<std::uint8_t*>(srcInfo.rasBase) + (srcInfo.scanStride * sy1) + (srcInfo.pixelStride * sx1);
251251
bool isRasterAligned = srcInfo.scanStride % srcInfo.pixelStride == 0; //!(srcInfo.scanStride & 0x03);
252252

253-
control_center->update_dimensions(width, height);
253+
control_center->set_target_dimensions(width, height);
254254
std::uint8_t* dest = control_center->get_image();
255255
ImageFormat format = control_center->get_image_format();
256256

@@ -481,7 +481,7 @@ CGLError mCGLFlushDrawable(CGLContextObj ctx) noexcept
481481

482482
if (can_render(-1, width, height))
483483
{
484-
control_center->update_dimensions(width, height);
484+
control_center->set_target_dimensions(width, height);
485485

486486
//Render to Shared Memory
487487
std::uint8_t* dest = control_center->get_image();
@@ -535,7 +535,7 @@ CGLError mCGLFlushDrawable(CGLContextObj ctx) noexcept
535535

536536
if (can_render(-1, width, height))
537537
{
538-
control_center->update_dimensions(width, height);
538+
control_center->set_target_dimensions(width, height);
539539

540540
//Render to Shared Memory
541541
std::uint8_t* dest = control_center->get_image();

RemoteInput/Platform/NativeHooks_Linux.cxx

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobject dstData,
152152

153153
void* rasBase = reinterpret_cast<std::uint8_t*>(srcInfo.rasBase) + (srcInfo.scanStride * srcy) + (srcInfo.pixelStride * srcx);
154154

155-
control_center->update_dimensions(width, height);
155+
control_center->set_target_dimensions(width, height);
156156
std::uint8_t* dest = control_center->get_image();
157157
ImageFormat format = control_center->get_image_format();
158158

@@ -241,7 +241,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb
241241
void* rasBase = reinterpret_cast<std::uint8_t*>(srcInfo.rasBase) + (srcInfo.scanStride * sy1) + (srcInfo.pixelStride * sx1);
242242
bool isRasterAligned = srcInfo.scanStride % srcInfo.pixelStride == 0; //!(srcInfo.scanStride & 0x03);
243243

244-
control_center->update_dimensions(width, height);
244+
control_center->set_target_dimensions(width, height);
245245
std::uint8_t* dest = control_center->get_image();
246246
ImageFormat format = control_center->get_image_format();
247247

@@ -387,7 +387,7 @@ extern "C" [[gnu::visibility("default")]] Bool XShmPutImage(Display *display, Dr
387387
int stride = width * bytes_per_pixel;
388388
void *rasBase = reinterpret_cast<std::uint8_t*>(image->data) + (stride * src_y) + (bytes_per_pixel * src_x);
389389

390-
control_center->update_dimensions(width, height);
390+
control_center->set_target_dimensions(width, height);
391391

392392
//Render to Shared Memory
393393
std::uint8_t* dest = control_center->get_image();
@@ -533,7 +533,7 @@ extern "C" [[gnu::visibility("default")]] void glXSwapBuffers(Display* dpy, GLXD
533533

534534
if (width >= 200 && height >= 200)
535535
{
536-
control_center->update_dimensions(width, height);
536+
control_center->set_target_dimensions(width, height);
537537

538538
//Render to Shared Memory
539539
std::uint8_t* dest = control_center->get_image();

RemoteInput/Platform/NativeHooks_Windows.cxx

+7-7
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void __stdcall JavaNativeBlit(JNIEnv *env, jobject self, jobject srcData, jobjec
173173

174174
void* rasBase = reinterpret_cast<std::uint8_t*>(srcInfo.rasBase) + (srcInfo.scanStride * srcy) + (srcInfo.pixelStride * srcx);
175175

176-
control_center->update_dimensions(width, height);
176+
control_center->set_target_dimensions(width, height);
177177
std::uint8_t* dest = control_center->get_image();
178178
ImageFormat format = control_center->get_image_format();
179179

@@ -274,7 +274,7 @@ void JavaNativeOGLBlit(JNIEnv *env, void *oglc, jlong pSrcOps, jlong pDstOps, jb
274274
void* rasBase = reinterpret_cast<std::uint8_t*>(srcInfo.rasBase) + (srcInfo.scanStride * sy1) + (srcInfo.pixelStride * sx1);
275275
bool isRasterAligned = srcInfo.scanStride % srcInfo.pixelStride == 0; //!(srcInfo.scanStride & 0x03);
276276

277-
control_center->update_dimensions(width, height);
277+
control_center->set_target_dimensions(width, height);
278278
std::uint8_t* dest = control_center->get_image();
279279
ImageFormat format = control_center->get_image_format();
280280

@@ -464,7 +464,7 @@ void __stdcall JavaNativeGDIBlit(JNIEnv *env, jobject joSelf, jobject srcData, j
464464
void* rasBase = reinterpret_cast<std::uint8_t*>(srcInfo.rasBase) + (srcInfo.scanStride * srcy) + (srcInfo.pixelStride * srcx);
465465
bool isRasterAligned = !(srcInfo.scanStride & 0x03);
466466

467-
control_center->update_dimensions(width, height);
467+
control_center->set_target_dimensions(width, height);
468468
std::uint8_t* dest = control_center->get_image();
469469
ImageFormat format = control_center->get_image_format();
470470

@@ -619,7 +619,7 @@ HRESULT __cdecl JavaDirectXCopyImageToIntArgbSurface(IDirect3DSurface9 *pSurface
619619
jint height = srcHeight;
620620

621621
//Prepare for BackBuffer Rendering
622-
control_center->update_dimensions(width, height);
622+
control_center->set_target_dimensions(width, height);
623623
ImageFormat format = control_center->get_image_format();
624624
std::uint8_t* destImage = ptr_coord(control_center->get_image(), srcx, srcy, pDstInfo->pixelStride, pDstInfo->scanStride);
625625
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
800800
jint height = pSrcInfo->bounds.y2 - pSrcInfo->bounds.y1;
801801

802802
//Prepare for BackBuffer Rendering
803-
control_center->update_dimensions(width, height);
803+
control_center->set_target_dimensions(width, height);
804804
ImageFormat format = control_center->get_image_format();
805805
std::uint8_t* destImage = ptr_coord(control_center->get_image(), srcx, srcy, pSrcInfo->pixelStride, pSrcInfo->scanStride);
806806
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
10761076
int stride = width * bytes_per_pixel;
10771077
void *rasBase = static_cast<std::uint8_t*>(const_cast<void*>(data)) + (stride * src_y) + (bytes_per_pixel * src_x);
10781078

1079-
control_center->update_dimensions(width, height);
1079+
control_center->set_target_dimensions(width, height);
10801080

10811081
//Render to Shared Memory
10821082
std::uint8_t* dest = control_center->get_image();
@@ -1128,7 +1128,7 @@ BOOL __stdcall mSwapBuffers(HDC hdc) noexcept
11281128

11291129
if (can_render(-1, width, height))
11301130
{
1131-
control_center->update_dimensions(width, height);
1131+
control_center->set_target_dimensions(width, height);
11321132

11331133
//Check if extensions are supported
11341134
//This check is needed for renderers that do not support pixel buffer objects or vertex buffer objects

RemoteInput/Plugin/ControlCenter.cxx

+72-30
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,17 @@ void ControlCenter::process_command() noexcept
193193
}
194194
break;
195195

196+
case EIOSCommand::GET_IMAGE_DIMENSIONS:
197+
{
198+
image_data.set_image_width(get_image_width());
199+
image_data.set_image_height(get_image_height());
200+
}
201+
break;
202+
196203
case EIOSCommand::GET_TARGET_DIMENSIONS:
197204
{
198-
image_data.set_width(get_width());
199-
image_data.set_height(get_height());
205+
image_data.set_target_width(get_target_width());
206+
image_data.set_target_height(get_target_height());
200207
}
201208
break;
202209

@@ -891,15 +898,15 @@ bool ControlCenter::init_maps() noexcept
891898
memory_map = std::make_unique<MemoryMapStream<ImageData>>(mapName, sizeof(ImageData), MemoryMapStream<ImageData>::open_mode::read);
892899
if (memory_map && memory_map->is_mapped())
893900
{
894-
int width = memory_map->data().width();
895-
int height = memory_map->data().height();
901+
int image_width = memory_map->data().image_width();
902+
int image_height = memory_map->data().image_height();
896903

897-
if (width && height)
904+
if (image_width && image_height)
898905
{
899-
std::size_t image_size = width * height * 4 * sizeof(std::uint8_t);
900-
std::size_t debug_size = width * height * 4 * sizeof(std::uint8_t);
906+
std::size_t image_size = image_width * image_height * 4 * sizeof(std::uint8_t);
907+
std::size_t debug_size = image_width * image_height * 4 * sizeof(std::uint8_t);
901908
std::size_t extra_size = (1024 * sizeof(std::int32_t));
902-
std::int32_t map_size = sizeof(EIOSData) + image_size + debug_size + extra_size;
909+
std::size_t map_size = sizeof(EIOSData) + image_size + debug_size + extra_size;
903910

904911
//Open only..
905912
memory_map = std::make_unique<MemoryMapStream<ImageData>>(mapName, map_size, MemoryMapStream<ImageData>::open_mode::read | MemoryMapStream<ImageData>::open_mode::write);
@@ -909,21 +916,22 @@ bool ControlCenter::init_maps() noexcept
909916
return false;
910917
}
911918

912-
int width = 0;
913-
int height = 0;
914-
GetDesktopResolution(width, height); //TODO: Change to Target Window size..
919+
int image_width = 0;
920+
int image_height = 0;
921+
GetDesktopResolution(image_width, image_height);
915922

916-
std::size_t image_size = width * height * 4 * sizeof(std::uint8_t);
917-
std::size_t debug_size = width * height * 4 * sizeof(std::uint8_t);
923+
std::size_t image_size = image_width * image_height * 4 * sizeof(std::uint8_t);
924+
std::size_t debug_size = image_width * image_height * 4 * sizeof(std::uint8_t);
918925
std::size_t extra_size = (1024 * sizeof(std::int32_t));
919-
std::int32_t map_size = sizeof(EIOSData) + image_size + debug_size + extra_size;
926+
std::size_t map_size = sizeof(EIOSData) + image_size + debug_size + extra_size;
920927

921928
//Create only..
922929
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);
923930
bool result = memory_map && memory_map->is_mapped();
924931
if (result)
925932
{
926-
update_dimensions(width, height);
933+
set_image_dimensions(image_width, image_height);
934+
set_target_dimensions(image_width, image_height);
927935
}
928936
return result;
929937
}
@@ -1030,14 +1038,24 @@ std::int32_t ControlCenter::parent_thread_id() const noexcept
10301038
return memory_map && memory_map->is_mapped() ? get_image_data()->parent_thread_id() : -1;
10311039
}
10321040

1033-
std::int32_t ControlCenter::get_width() const noexcept
1041+
std::int32_t ControlCenter::get_image_width() const noexcept
10341042
{
1035-
return memory_map && memory_map->is_mapped() ? get_image_data()->width() : -1;
1043+
return memory_map && memory_map->is_mapped() ? get_image_data()->image_width() : -1;
10361044
}
10371045

1038-
std::int32_t ControlCenter::get_height() const noexcept
1046+
std::int32_t ControlCenter::get_image_height() const noexcept
10391047
{
1040-
return memory_map && memory_map->is_mapped() ? get_image_data()->height() : -1;
1048+
return memory_map && memory_map->is_mapped() ? get_image_data()->image_height() : -1;
1049+
}
1050+
1051+
std::int32_t ControlCenter::get_target_width() const noexcept
1052+
{
1053+
return memory_map && memory_map->is_mapped() ? get_image_data()->target_width() : -1;
1054+
}
1055+
1056+
std::int32_t ControlCenter::get_target_height() const noexcept
1057+
{
1058+
return memory_map && memory_map->is_mapped() ? get_image_data()->target_height() : -1;
10411059
}
10421060

10431061
std::uint8_t* ControlCenter::get_image() const noexcept
@@ -1048,8 +1066,8 @@ std::uint8_t* ControlCenter::get_image() const noexcept
10481066

10491067
std::uint8_t* ControlCenter::get_debug_image() const noexcept
10501068
{
1051-
std::uint8_t* image = get_image();
1052-
return image ? image + (get_width() * get_height() * 4) : nullptr;
1069+
ImageData* image_data = get_image_data();
1070+
return image_data ? image_data->debug_image_buffer() : nullptr;
10531071
}
10541072

10551073
bool ControlCenter::get_debug_graphics() const noexcept
@@ -1204,7 +1222,17 @@ void ControlCenter::kill_process(std::int32_t pid) const noexcept
12041222
});
12051223
}
12061224

1207-
void ControlCenter::update_dimensions(std::int32_t width, std::int32_t height) const noexcept
1225+
void ControlCenter::set_image_dimensions(std::int32_t width, std::int32_t height) const noexcept
1226+
{
1227+
if (memory_map && memory_map->is_mapped())
1228+
{
1229+
ImageData* image_data = get_image_data();
1230+
image_data->set_image_width(width);
1231+
image_data->set_image_height(height);
1232+
}
1233+
}
1234+
1235+
void ControlCenter::set_target_dimensions(std::int32_t width, std::int32_t height) const noexcept
12081236
{
12091237
if (memory_map && memory_map->is_mapped())
12101238
{
@@ -1220,29 +1248,43 @@ void ControlCenter::update_dimensions(std::int32_t width, std::int32_t height) c
12201248

12211249
if (w > 0 && h > 0)
12221250
{
1223-
image_data->set_width(w);
1224-
image_data->set_height(h);
1251+
image_data->set_target_width(w);
1252+
image_data->set_target_height(h);
12251253
}
12261254
else
12271255
{
1228-
image_data->set_width(width);
1229-
image_data->set_height(height);
1256+
image_data->set_target_width(width);
1257+
image_data->set_target_height(height);
12301258
}
12311259
}
12321260
else
12331261
{
1234-
image_data->set_width(width);
1235-
image_data->set_height(height);
1262+
image_data->set_target_width(width);
1263+
image_data->set_target_height(height);
12361264
}
12371265
}
12381266
}
12391267

1268+
void ControlCenter::get_image_dimensions(std::int32_t* width, std::int32_t* height) const noexcept
1269+
{
1270+
if (memory_map && memory_map->is_mapped())
1271+
{
1272+
*width = get_image_width();
1273+
*height = get_image_height();
1274+
}
1275+
else
1276+
{
1277+
*width = -1;
1278+
*height = -1;
1279+
}
1280+
}
1281+
12401282
void ControlCenter::get_target_dimensions(std::int32_t* width, std::int32_t* height) const noexcept
12411283
{
12421284
if (memory_map && memory_map->is_mapped())
12431285
{
1244-
*width = get_width();
1245-
*height = get_height();
1286+
*width = get_target_width();
1287+
*height = get_target_height();
12461288
}
12471289
else
12481290
{

RemoteInput/Plugin/ControlCenter.hxx

+7-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public:
6363
bool hasReflector() const noexcept;
6464
void set_parent_process_id(std::int32_t pid) const noexcept;
6565
void set_parent_thread_id(std::int32_t tid) const noexcept;
66-
void update_dimensions(std::int32_t width, std::int32_t height) const noexcept;
66+
void set_image_dimensions(std::int32_t width, std::int32_t height) const noexcept;
67+
void set_target_dimensions(std::int32_t width, std::int32_t height) const noexcept;
6768

6869
static void signal_sync(std::int32_t pid) noexcept;
6970
static void wait_for_sync(std::int32_t pid) noexcept;
@@ -74,8 +75,10 @@ public:
7475

7576
std::int32_t parent_process_id() const noexcept;
7677
std::int32_t parent_thread_id() const noexcept;
77-
std::int32_t get_width() const noexcept;
78-
std::int32_t get_height() const noexcept;
78+
std::int32_t get_image_width() const noexcept;
79+
std::int32_t get_image_height() const noexcept;
80+
std::int32_t get_target_width() const noexcept;
81+
std::int32_t get_target_height() const noexcept;
7982
std::uint8_t* get_image() const noexcept;
8083
std::uint8_t* get_debug_image() const noexcept;
8184
bool get_debug_graphics() const noexcept;
@@ -90,6 +93,7 @@ public:
9093
void set_keyboard_input_enabled(bool enabled) const noexcept;
9194
bool is_mouse_input_enabled() const noexcept;
9295
void set_mouse_input_enabled(bool enabled) const noexcept;
96+
void get_image_dimensions(std::int32_t* width, std::int32_t* height) const noexcept;
9397
void get_target_dimensions(std::int32_t* width, std::int32_t* height) const noexcept;
9498
ImageFormat get_image_format() const noexcept;
9599
void set_image_format(ImageFormat format) noexcept;

0 commit comments

Comments
 (0)