Skip to content

Commit

Permalink
Remove all uses of the fl_gc global variable. Towards a clean driver …
Browse files Browse the repository at this point in the history
…model.

fl_gc remains usable by the application as a hook into the system.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11189 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Feb 18, 2016
1 parent 6ce2701 commit f33b45f
Show file tree
Hide file tree
Showing 60 changed files with 762 additions and 727 deletions.
3 changes: 2 additions & 1 deletion FL/Fl_Device.H
Expand Up @@ -45,7 +45,8 @@ public:
static const char *class_id;
/**
Returns the name of the class of this object.
Use of the class_name() function is discouraged because it will be removed from future FLTK versions.
The class_name() function is deprecated.
The preferred procedure is to use the Fl_Graphics_Driver::has_feature() member function.
The class of an instance of an Fl_Device subclass can be checked with code such as:
\code
Expand Down
9 changes: 8 additions & 1 deletion FL/Fl_Graphics_Driver.H
Expand Up @@ -4,7 +4,7 @@
// Definition of classes Fl_Device, Fl_Graphics_Driver, Fl_Surface_Device, Fl_Display_Device
// for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2014 by Bill Spitzak and others.
// Copyright 2010-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand Down Expand Up @@ -84,9 +84,12 @@ typedef short COORD_T;
to support all FLTK drawing functions.
*/
class FL_EXPORT Fl_Graphics_Driver : public Fl_Device {
friend class Fl_Surface_Device;
friend class Fl_Pixmap;
friend class Fl_Bitmap;
friend class Fl_RGB_Image;
private:
void global_gc(void);
public:
// The following functions create the various graphics drivers that are required
// for core operations. They must be implemented as members of Fl_Graphics_Driver,
Expand Down Expand Up @@ -251,6 +254,10 @@ public:
virtual int draw_scaled(Fl_Image *img, int X, int Y, int W, int H);
virtual void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);

/** Sets the value of the driver-specific graphics context. */
virtual void set_gc(void*) {}
/** Returns the driver-specific graphics context, of NULL if there's none. */
virtual void *get_gc(void) {return NULL;}
protected:
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
virtual void transformed_vertex0(COORD_T x, COORD_T y);
Expand Down
3 changes: 1 addition & 2 deletions FL/Fl_Image_Surface.H
Expand Up @@ -3,7 +3,7 @@
//
// Draw-to-image code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2014 by Bill Spitzak and others.
// Copyright 1998-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand Down Expand Up @@ -61,7 +61,6 @@ private:
#else
Fl_Surface_Device *previous;
Window pre_window;
GC gc;
#endif
public:
static const char *class_id;
Expand Down
23 changes: 2 additions & 21 deletions FL/Fl_PostScript.H
Expand Up @@ -3,7 +3,7 @@
//
// Support for graphics output to PostScript file for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2011 by Bill Spitzak and others.
// Copyright 2010-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand Down Expand Up @@ -233,15 +233,6 @@ class Clip {
two variants of which are usable and allow to specify what page format and layout are desired.
*/
class FL_EXPORT Fl_PostScript_File_Device : public Fl_Paged_Device {
#ifdef __APPLE__ // PORTME: Fl_Surface_Driver ? - platform specifics for PostScript
CGContextRef gc;
#elif defined(WIN32)
// not needed
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: define storage for your graphics context in Fl_PostScript_File_Device if needed"
#else // X11
// not needed
#endif
protected:
Fl_PostScript_Graphics_Driver *driver();
public:
Expand All @@ -264,17 +255,7 @@ public:
void translate(int x, int y);
void untranslate(void);
int end_page (void);
void end_job(void);
#ifdef __APPLE__ // PORTME: Fl_Surface_Driver ? - platform specifics for PostScript
void set_current() { fl_gc = gc; Fl_Paged_Device::set_current(); }
#elif defined(WIN32)
// not needed
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: set access to your graphics context in Fl_PostScript_File_Device if needed"
#else // X11
// not needed
#endif

void end_job(void);
static const char *file_chooser_title;
};

Expand Down
3 changes: 0 additions & 3 deletions FL/Fl_Printer.H
Expand Up @@ -51,9 +51,6 @@
class Fl_System_Printer : public Fl_Paged_Device {
friend class Fl_Printer;
private:
/** \brief the printer's graphics context, if there's one, NULL otherwise */
void *gc;
void set_current(void);
#ifdef __APPLE__ // PORTME: Fl_Surface_Driver ? - platform printer driver
float scale_x;
float scale_y;
Expand Down
2 changes: 1 addition & 1 deletion FL/mac.H
Expand Up @@ -162,7 +162,7 @@ public:
void in_windowDidResize(bool); // sets whether window is performing windowDidResize
// Quartz additions:
CGContextRef gc; // graphics context (NULL when using QD)
static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
static void q_release_context(Fl_X *x=0); // free all resources associated with gc
// Cocoa additions
static NSOpenGLPixelFormat *mode_to_NSOpenGLPixelFormat(int mode, const int*); // computes NSOpenGLPixelFormat from Gl window's mode
static NSOpenGLContext* create_GLcontext_for_window(NSOpenGLPixelFormat *pixelformat, NSOpenGLContext *shared_ctx, Fl_Window *window);
Expand Down
14 changes: 8 additions & 6 deletions FL/win32.H
Expand Up @@ -3,7 +3,7 @@
//
// WIN32 header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2012 by Bill Spitzak and others.
// Copyright 1998-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand Down Expand Up @@ -132,15 +132,17 @@ extern FL_EXPORT HDC fl_makeDC(HBITMAP);
// off-screen pixmaps: create, destroy, draw into, copy to window
typedef HBITMAP Fl_Offscreen;
#define fl_create_offscreen(w, h) \
CreateCompatibleBitmap( (fl_gc ? fl_gc : fl_GetDC(0) ) , w, h)
CreateCompatibleBitmap( (fl_graphics_driver->get_gc() ? (HDC)fl_graphics_driver->get_gc() : fl_GetDC(0) ) , w, h)

# define fl_begin_offscreen(b) \
HDC _sgc=fl_gc; Window _sw=fl_window; \
Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); \
fl_gc=fl_makeDC(b); int _savedc = SaveDC(fl_gc); fl_window=(HWND)b; fl_push_no_clip()
void* _sgc=fl_graphics_driver->get_gc(); Window _sw=fl_window; \
Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); \
HDC _tmp_gc = fl_makeDC(b); int _savedc = SaveDC(_tmp_gc); \
Fl_Display_Device::display_device()->set_current(); \
fl_graphics_driver->set_gc(_tmp_gc); fl_window=(HWND)b; fl_push_no_clip()

# define fl_end_offscreen() \
fl_pop_clip(); RestoreDC(fl_gc, _savedc); DeleteDC(fl_gc); _ss->set_current(); fl_window=_sw; fl_gc = _sgc
fl_pop_clip(); RestoreDC((HDC)fl_graphics_driver->get_gc(), _savedc); DeleteDC((HDC)fl_graphics_driver->get_gc()); _ss->set_current(); fl_window=_sw; fl_graphics_driver->set_gc(_sgc);


FL_EXPORT void fl_copy_offscreen(int x,int y,int w,int h,HBITMAP pixmap,int srcx,int srcy);
Expand Down
9 changes: 5 additions & 4 deletions src/Fl.cxx
Expand Up @@ -3,7 +3,7 @@
//
// Main event handling code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2015 by Bill Spitzak and others.
// Copyright 1998-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand Down Expand Up @@ -60,6 +60,7 @@
#endif // DEBUG || DEBUG_WATCH

#ifdef WIN32
#include <FL/Fl_Graphics_Driver.H> // for fl_graphics_driver
#elif defined(__APPLE__) // PORTME: Fl_Screen_Driver - window driver and main loop
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: implement global variables for your platform here"
Expand Down Expand Up @@ -1618,10 +1619,10 @@ void Fl_Window::hide() {
// Send a message to myself so that I'll get out of the event loop...
PostMessage(ip->xid, WM_APP, 0, 0);
if (ip->private_dc) fl_release_dc(ip->xid, ip->private_dc);
if (ip->xid == fl_window && fl_gc) {
fl_release_dc(fl_window, fl_gc);
if (ip->xid == fl_window && fl_graphics_driver->get_gc()) {
fl_release_dc(fl_window, (HDC)fl_graphics_driver->get_gc());
fl_window = (HWND)-1;
fl_gc = 0;
fl_graphics_driver->set_gc(0);
# ifdef FLTK_USE_CAIRO
if (Fl::cairo_autolink_context()) Fl::cairo_make_current((Fl_Window*) 0);
# endif
Expand Down
16 changes: 7 additions & 9 deletions src/Fl_Copy_Surface.cxx
Expand Up @@ -49,15 +49,15 @@ Fl_GDI_Surface_::~Fl_GDI_Surface_() {
}

void Fl_GDI_Surface_::translate(int x, int y) {
GetWindowOrgEx(fl_gc, origins+depth);
SetWindowOrgEx(fl_gc, origins[depth].x - x, origins[depth].y - y, NULL);
GetWindowOrgEx((HDC)driver()->get_gc(), origins+depth);
SetWindowOrgEx((HDC)driver()->get_gc(), origins[depth].x - x, origins[depth].y - y, NULL);
if (depth < sizeof(origins)/sizeof(POINT)) depth++;
else Fl::warning("Fl_GDI_Surface_: translate stack overflow!");
}

void Fl_GDI_Surface_::untranslate() {
if (depth > 0) depth--;
SetWindowOrgEx(fl_gc, origins[depth].x, origins[depth].y, NULL);
SetWindowOrgEx((HDC)driver()->get_gc(), origins[depth].x, origins[depth].y, NULL);
}

const char *Fl_GDI_Surface_::class_id = "Fl_GDI_Surface_";
Expand All @@ -79,11 +79,10 @@ Fl_Copy_Surface::Fl_Copy_Surface(int w, int h) : Fl_Surface_Device(NULL)
helper = new Fl_Quartz_Surface_(width, height);
driver(helper->driver());
prepare_copy_pdf_and_tiff(w, h);
oldgc = fl_gc;
#elif defined(WIN32)
helper = new Fl_GDI_Surface_();
driver(helper->driver());
oldgc = fl_gc;
oldgc = (HDC)Fl_Surface_Device::surface()->driver()->get_gc();
// exact computation of factor from screen units to EnhMetaFile units (0.01 mm)
HDC hdc = GetDC(NULL);
int hmm = GetDeviceCaps(hdc, HORZSIZE);
Expand Down Expand Up @@ -122,10 +121,9 @@ Fl_Copy_Surface::~Fl_Copy_Surface()
{
#ifdef __APPLE__ // PORTME: Fl_Surface_Driver - platform copy surface
complete_copy_pdf_and_tiff();
fl_gc = oldgc;
delete (Fl_Quartz_Surface_*)helper;
#elif defined(WIN32)
if(oldgc == fl_gc) oldgc = NULL;
if (oldgc == (HDC)Fl_Surface_Device::surface()->driver()->get_gc()) oldgc = NULL;
HENHMETAFILE hmf = CloseEnhMetaFile (gc);
if ( hmf != NULL ) {
if ( OpenClipboard (NULL) ){
Expand All @@ -136,7 +134,7 @@ Fl_Copy_Surface::~Fl_Copy_Surface()
DeleteEnhMetaFile(hmf);
}
DeleteDC(gc);
fl_gc = oldgc;
Fl_Surface_Device::surface()->driver()->set_gc(oldgc);
delete (Fl_GDI_Surface_*)helper;
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: free resources in destructor of Fl_Copy_Surface"
Expand Down Expand Up @@ -166,7 +164,7 @@ void Fl_Copy_Surface::draw(Fl_Widget* widget, int delta_x, int delta_y)
void Fl_Copy_Surface::set_current()
{
#if defined(__APPLE__) || defined(WIN32) // PORTME: Fl_Surface_Driver - platform copy surface
fl_gc = gc;
driver()->set_gc(gc);
fl_window = (Window)1;
Fl_Surface_Device::set_current();
#elif defined(FL_PORTING)
Expand Down
5 changes: 3 additions & 2 deletions src/Fl_Device.cxx
Expand Up @@ -3,7 +3,7 @@
//
// implementation of Fl_Device class for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2012 by Bill Spitzak and others.
// Copyright 2010-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand Down Expand Up @@ -62,6 +62,7 @@ void Fl_Surface_Device::set_current(void)
{
fl_graphics_driver = _driver;
_surface = this;
_driver->global_gc();
}

Fl_Surface_Device* Fl_Surface_Device::_surface; // the current target surface of graphics operations
Expand All @@ -86,7 +87,7 @@ Fl_Surface_Device *Fl_Surface_Device::default_surface()
}


Fl_Display_Device *Fl_Display_Device::_display = Fl_Display_Device::display_device();
Fl_Display_Device *Fl_Display_Device::_display;


//
Expand Down
15 changes: 8 additions & 7 deletions src/Fl_Double_Window.cxx
Expand Up @@ -3,7 +3,7 @@
//
// Double-buffered window code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2012 by Bill Spitzak and others.
// Copyright 1998-2016 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand Down Expand Up @@ -176,14 +176,15 @@ void Fl_Double_Window::flush(int eraseoverlay) {
if (damage() & ~FL_DAMAGE_EXPOSE) {
fl_clip_region(myi->region); myi->region = 0;
#ifdef WIN32
HDC _sgc = fl_gc;
fl_gc = fl_makeDC(myi->other_xid);
int save = SaveDC(fl_gc);
void* _sgc = fl_graphics_driver->get_gc();
HDC gc = fl_makeDC(myi->other_xid);
fl_graphics_driver->set_gc(gc);
int save = SaveDC(gc);
fl_restore_clip(); // duplicate region into new gc
draw();
RestoreDC(fl_gc, save);
DeleteDC(fl_gc);
fl_gc = _sgc;
RestoreDC(gc, save);
DeleteDC(gc);
fl_graphics_driver->set_gc(_sgc);
//# if defined(FLTK_USE_CAIRO)
//if Fl::cairo_autolink_context() Fl::cairo_make_current(this); // capture gc changes automatically to update the cairo context adequately
//# endif
Expand Down

0 comments on commit f33b45f

Please sign in to comment.