summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2018-10-31 09:05:26 +0000
committerManolo Gouy <Manolo>2018-10-31 09:05:26 +0000
commit22bcc7b4cacee37be4e0559c84c848d1f6b1daf6 (patch)
treeed41ffe4ef1d3c9a8123900867bda631b147226b /src
parent9e2011375763cfeda1fd17c5c9f9467420f66f78 (diff)
Remove all dependency to libfltk_gl from Fl_cocoa.mm.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@13103 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Gl_Window.cxx2
-rw-r--r--src/Fl_Gl_Window_Driver.H2
-rw-r--r--src/Fl_cocoa.mm47
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx7
4 files changed, 36 insertions, 22 deletions
diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx
index 938a0dc5f..2248e1a84 100644
--- a/src/Fl_Gl_Window.cxx
+++ b/src/Fl_Gl_Window.cxx
@@ -594,7 +594,7 @@ void Fl_Cocoa_Gl_Window_Driver::swap_buffers() {
glRasterPos3f(pos[0], pos[1], pos[2]); // restore original glRasterPos
}
else
- flush_context();//aglSwapBuffers((AGLContext)context_);
+ flush_context(pWindow->context());//aglSwapBuffers((AGLContext)context_);
}
void Fl_Cocoa_Gl_Window_Driver::resize(int is_a_resize, int unused, int also) {
diff --git a/src/Fl_Gl_Window_Driver.H b/src/Fl_Gl_Window_Driver.H
index 88d2c14dc..9ac15b3ae 100644
--- a/src/Fl_Gl_Window_Driver.H
+++ b/src/Fl_Gl_Window_Driver.H
@@ -112,7 +112,6 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver {
virtual void swap_buffers();
virtual void resize(int is_a_resize, int w, int h);
virtual char swap_type();
- void flush_context();
virtual Fl_Gl_Choice *find(int m, const int *alistp);
virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0);
virtual void set_gl_context(Fl_Window* w, GLContext context);
@@ -124,6 +123,7 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver {
static NSOpenGLPixelFormat *mode_to_NSOpenGLPixelFormat(int mode, const int*); // uses Objective-c
static void GLcontext_update(NSOpenGLContext*); // uses Objective-c
static void GLcontext_release(NSOpenGLContext*); // uses Objective-c
+ static void flush_context(NSOpenGLContext*); // uses Objective-c
static void GLcontext_makecurrent(NSOpenGLContext*); // uses Objective-c
static void GL_cleardrawable(void); // uses Objective-c
virtual char *alpha_mask_for_string(const char *str, int n, int w, int h);
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index e0b787c10..e30b85943 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -530,6 +530,13 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
#endif
@end
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
+typedef union {
+ CGContextRef gc;
+ NSOpenGLContext *context;
+} bitmap_or_gl_context;
+#endif
+
@interface FLView : NSView <NSTextInput
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
, NSTextInputClient
@@ -547,7 +554,7 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
NSRange selectedRange;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
@public
- CGContextRef layer_gc;
+ bitmap_or_gl_context layer_data;
#endif
}
+ (void)prepareEtext:(NSString*)aString;
@@ -2163,16 +2170,16 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
Each layer-backed non-OpenGL window has a single FLView object which itself has an associated CALayer.
FLView implements displayLayer:. Consequently, FLView objects are drawn
by the displayLayer: method. An FLView manages also a member variable
- CGContextRef layer_gc, a bitmap context the size of the view (double on Retina).
+ CGContextRef layer_data.gc, a bitmap context the size of the view (double on Retina).
All Quartz drawings go to this bitmap. displayLayer: finishes by using an image copy
of the bitmap as the layer's contents. That step fills the window.
When resized or when the window flips between low/high resolution displays,
- FLView receives the viewFrameDidChange message which deletes the bitmap and zeros layer_gc.
+ FLView receives the viewFrameDidChange message which deletes the bitmap and zeros layer_data.gc.
This ensures the bitmap is recreated after the window was resized.
Each layer-backed OpenGL window has an associated FLViewGL object, derived from FLView.
FLViewGL objects are drawn by the displayLayer: method which calls drawRect:
- which draws the GL scene.
+ which draws the GL scene. Member variable layer_data.context contains the OpenGL context.
*/
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
@@ -2188,6 +2195,7 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
- (void)displayLayer:(CALayer *)layer;
- (void)drawRect:(NSRect)rect;
- (void)viewFrameDidChange;
+- (void)dealloc;
@end
@implementation FLViewGL
@@ -2202,12 +2210,12 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
if (d->wait_for_expose_value) {
// 1st drawing of GL window
[self did_view_resolution_change];
- [window->as_gl_window()->context() update]; // GL window is empty without this
+ [layer_data.context update]; // GL window may be empty without this
d->wait_for_expose_value = 0;
}
through_drawRect = YES;
window->clear_damage(FL_DAMAGE_ALL);
- window->as_gl_window()->flush();
+ d->Fl_Window_Driver::flush();
window->clear_damage();
through_drawRect = NO;
if (fl_mac_os_version < 101401) {
@@ -2216,6 +2224,10 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
fl_unlock_function();
}
-(void)viewFrameDidChange { ; }
+-(void)dealloc {
+ layer_data.context = NULL;
+ [super dealloc];
+}
@end
#endif //>= MAC_OS_X_VERSION_10_8
@@ -2237,7 +2249,7 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
rect.size.width/scale, rect.size.height/scale);
[self viewFrameDidChange];
}
- if (!layer_gc) { // runs when window is created, resized, changed screen resolution
+ if (!layer_data.gc) { // runs when window is created, resized, changed screen resolution
layer.bounds = NSRectToCGRect(rect);
d->wait_for_expose_value = 0;
[self did_view_resolution_change];
@@ -2245,7 +2257,7 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
rect.size.width *= 2; rect.size.height *= 2;
layer.contentsScale = 2.;
} else layer.contentsScale = 1.;
- layer_gc = prepare_bitmap_for_layer(rect.size.width, rect.size.height);
+ layer_data.gc = prepare_bitmap_for_layer(rect.size.width, rect.size.height);
Fl_X *i = Fl_X::i(window);
if ( i->region ) {
Fl_Graphics_Driver::default_driver().XDestroyRegion(i->region);
@@ -2259,7 +2271,7 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
Fl_Cocoa_Window_Driver::q_release_context();
through_drawRect = NO;
window->clear_damage();
- CGImageRef cgimg = CGBitmapContextCreateImage(layer_gc); // requires 10.4
+ CGImageRef cgimg = CGBitmapContextCreateImage(layer_data.gc); // requires 10.4
layer.contents = (id)cgimg;
CGImageRelease(cgimg);
}
@@ -2267,11 +2279,11 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
-(void)viewFrameDidChange
{
- CGContextRelease(layer_gc);
- layer_gc = NULL;
+ CGContextRelease(layer_data.gc);
+ layer_data.gc = NULL;
}
-(void)dealloc {
- CGContextRelease(layer_gc);
+ CGContextRelease(layer_data.gc);
[super dealloc];
}
#endif //>= MAC_OS_X_VERSION_10_8
@@ -2900,6 +2912,9 @@ NSOpenGLContext* Fl_Cocoa_Gl_Window_Driver::create_GLcontext_for_window(NSOpenGL
addr(view, @selector(setWantsBestResolutionOpenGLSurface:), YES);
}
[context setView:view];
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
+ if (views_use_CA) ((FLViewGL*)view)->layer_data.context = context;
+#endif
}
return context;
}
@@ -2909,9 +2924,9 @@ void Fl_Cocoa_Gl_Window_Driver::GLcontext_update(NSOpenGLContext* ctxt)
[ctxt update];
}
-void Fl_Cocoa_Gl_Window_Driver::flush_context()
+void Fl_Cocoa_Gl_Window_Driver::flush_context(NSOpenGLContext* ctxt)
{
- [pWindow->context() flushBuffer];
+ [ctxt flushBuffer];
}
void Fl_Cocoa_Gl_Window_Driver::GLcontext_release(NSOpenGLContext* ctxt)
@@ -3402,7 +3417,7 @@ void Fl_Cocoa_Window_Driver::make_current()
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
if (views_use_CA) {
- gc = ((FLView*)[fl_window contentView])->layer_gc;
+ gc = ((FLView*)[fl_window contentView])->layer_data.gc;
} else
#endif
{
@@ -4235,7 +4250,7 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep_layer(Fl_Window *win, int x, i
{ // capture window data for layer-based views because initWithFocusedViewRect: does not work for them
NSBitmapImageRep *bitmap = nil;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
- CGContextRef gc = ((FLView*)[fl_xid(win) contentView])->layer_gc;
+ CGContextRef gc = ((FLView*)[fl_xid(win) contentView])->layer_data.gc;
CGImageRef cgimg = CGBitmapContextCreateImage(gc); // requires 10.4
float s = Fl::screen_driver()->scale(0);
int resolution = Fl_Cocoa_Window_Driver::driver(win->top_window())->mapped_to_retina() ? 2 : 1;
diff --git a/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx b/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx
index f574c671c..a51788018 100644
--- a/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx
+++ b/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx
@@ -68,9 +68,8 @@ Fl_RGB_Image* Fl_OpenGL_Display_Device::capture_gl_rectangle(Fl_Gl_Window* glw,
if (factor != 1) {
w *= factor; h *= factor; x *= factor; y *= factor;
}
- Fl_Cocoa_Gl_Window_Driver *driver = (Fl_Cocoa_Gl_Window_Driver*)glw->gl_driver();
- driver->GLcontext_makecurrent(glw->context());
- driver->flush_context(); // to capture also the overlay and for directGL demo
+ Fl_Cocoa_Gl_Window_Driver::GLcontext_makecurrent(glw->context());
+ Fl_Cocoa_Gl_Window_Driver::flush_context(glw->context()); // to capture also the overlay and for directGL demo
// Read OpenGL context pixels directly.
// For extra safety, save & restore OpenGL states that are changed
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
@@ -88,7 +87,7 @@ Fl_RGB_Image* Fl_OpenGL_Display_Device::capture_gl_rectangle(Fl_Gl_Window* glw,
baseAddress = convert_BGRA_to_RGB(baseAddress, w, h, mByteWidth);
Fl_RGB_Image *img = new Fl_RGB_Image(baseAddress, w, h, 3, 3 * w);
img->alloc_array = 1;
- driver->flush_context();
+ Fl_Cocoa_Gl_Window_Driver::flush_context(glw->context());
return img;
}