summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2025-02-08 17:19:07 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2025-02-08 17:19:07 +0100
commit81a5736006d64d749f9694268dd180ae80ec3d9d (patch)
tree43ac0ef7d51f55aa89a3a3583b57f312523158de /src/drivers
parent9afb35f3a68e71fd2afbb77123eb0fde1835b409 (diff)
Make Fl_Cocoa_Gl_Window_Driver::capture_gl_rectangle() return a depth-4 image
This change allows to capture the rounded corners of a top-level GL window. Also, rename Fl_Cocoa_Window_Driver::capture_decorated_window_10_5() from capture_decorated_window_10_6() because this function uses CGWindowListCreateImageFromArray() available from macOS 10.5.
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm20
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H2
2 files changed, 7 insertions, 15 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm
index ad309ee55..fd846f1c8 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm
+++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm
@@ -453,7 +453,7 @@ static uchar *convert_BGRA_to_RGB(uchar *baseAddress, int w, int h, int mByteWid
}
-static Fl_RGB_Image *cgimage_to_rgb3(CGImageRef img) {
+static Fl_RGB_Image *cgimage_to_rgb4(CGImageRef img) {
int w = (int)CGImageGetWidth(img);
int h = (int)CGImageGetHeight(img);
CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
@@ -463,15 +463,7 @@ static Fl_RGB_Image *cgimage_to_rgb3(CGImageRef img) {
CGColorSpaceRelease(cspace);
CGContextDrawImage(auxgc, CGRectMake(0, 0, w, h), img);
CGContextRelease(auxgc);
- uchar *rgb3 = new uchar[3 * w * h]; // transform RGBA pixel array into RGB array
- uchar *p = rgba, *q = rgb3, *last = rgba + 4 * w * h;
- while ( p < last) {
- memcpy(q, p, 3);
- p += 4;
- q += 3;
- }
- delete[] rgba;
- Fl_RGB_Image *rgb = new Fl_RGB_Image(rgb3, w, h, 3);
+ Fl_RGB_Image *rgb = new Fl_RGB_Image(rgba, w, h, 4);
rgb->alloc_array = 1;
return rgb;
}
@@ -484,16 +476,16 @@ Fl_RGB_Image* Fl_Cocoa_Gl_Window_Driver::capture_gl_rectangle(int x, int y, int
if (factor != 1) {
w *= factor; h *= factor; x *= factor; y *= factor;
}
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if (fl_mac_os_version >= 100600) {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+ if (fl_mac_os_version >= 100500) {
NSWindow *nswin = (NSWindow*)fl_mac_xid(pWindow);
- CGImageRef img_full = Fl_Cocoa_Window_Driver::capture_decorated_window_10_6(nswin);
+ CGImageRef img_full = Fl_Cocoa_Window_Driver::capture_decorated_window_10_5(nswin);
int bt = [nswin frame].size.height - [[nswin contentView] frame].size.height;
bt *= (factor / Fl_Graphics_Driver::default_driver().scale());
CGRect cgr = CGRectMake(x, y + bt, w, h); // add vertical offset to bypass titlebar
CGImageRef cgimg = CGImageCreateWithImageInRect(img_full, cgr); // 10.4
CGImageRelease(img_full);
- Fl_RGB_Image *rgb = cgimage_to_rgb3(cgimg);
+ Fl_RGB_Image *rgb = cgimage_to_rgb4(cgimg);
CGImageRelease(cgimg);
return rgb;
}
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
index c4d4e31da..4fa1a7491 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
+++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
@@ -97,7 +97,7 @@ public:
NSCursor *cursor;
static void q_release_context(Fl_Cocoa_Window_Driver *x = 0); // free all resources associated with gc
static void clip_to_rounded_corners(CGContextRef gc, int w, int h);
- static CGImageRef capture_decorated_window_10_6(NSWindow *nswin);
+ static CGImageRef capture_decorated_window_10_5(NSWindow *nswin);
void set_key_window();
bool mapped_to_retina(); // is window mapped to retina display?
void mapped_to_retina(bool); // sets whether window is mapped to retina display