DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2535
Version: 1.3-feature


Here is a patch that convert all matrix transformation variables from
static non reentrant to Fl_Graphics_Driver members/methods reentrant.

With it a kind of multitask is possible because switch betwen graphics
driver will not interfere with each other and will output to the correct
current device.


Link: http://www.fltk.org/str.php?L2535
Version: 1.3-feature
Index: FL/Fl_Device.H
===================================================================
--- FL/Fl_Device.H      (revision 8292)
+++ FL/Fl_Device.H      (working copy)
@@ -33,6 +33,7 @@
 #ifndef Fl_Device_H
 #define Fl_Device_H
 
+#include <FL/x.H>
 #include <FL/Fl_Plugin.H>
 #include <FL/Fl_Image.H>
 #include <FL/Fl_Bitmap.H>
@@ -59,6 +60,27 @@
  */
 typedef void (*Fl_Draw_Image_Cb)(void* data,int x,int y,int w,uchar* buf);
 
+#define REGION_STACK_SIZE 10
+#define REGION_STACK_MAX (REGION_STACK_SIZE - 1)
+
+#define MATRIX_STACK_SIZE 32
+#define MATRIX_STACK_MAX (MATRIX_STACK_SIZE - 1)
+struct matrix {double a, b, c, d, x, y;};
+
+// typedef what the x,y fields in a point are:
+#ifdef WIN32
+typedef int COORD_T;
+#  define XPOINT XPoint
+#elif defined(__APPLE_QUARTZ__)
+typedef float COORD_T;
+typedef struct { float x; float y; } QPoint;
+#  define XPOINT QPoint
+extern float fl_quartz_line_width_;
+#else
+typedef short COORD_T;
+#  define XPOINT XPoint
+#endif
+
 /**
  \brief All graphical output devices and all graphics systems.
  */
@@ -104,6 +126,7 @@
   friend class Fl_Pixmap;
   friend class Fl_Bitmap;
   friend class Fl_RGB_Image;
+  //friend class Fl_Pdf_Graphics_Driver;
   friend class Fl_PostScript_Graphics_Driver;
   friend void fl_rect(int x, int y, int w, int h);
   friend void fl_rectf(int x, int y, int w, int h);
@@ -156,7 +179,7 @@
   friend FL_EXPORT void fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, 
int X,int Y,int W,int H, int D);
   
   /** \brief The constructor. */
-  Fl_Graphics_Driver() {};
+  Fl_Graphics_Driver();
   /** \brief see fl_rect(int x, int y, int w, int h). */
   virtual void rect(int x, int y, int w, int h);
   /** \brief see fl_rectf(int x, int y, int w, int h). */
@@ -247,6 +270,28 @@
   virtual void push_no_clip();
   /** \brief see fl_pop_clip(). */
   virtual void pop_clip();
+  
+  virtual void fl_transformed_vertex0(COORD_T x, COORD_T y);
+  void fixloop();
+  
+  public:
+  virtual void fl_push_matrix();
+  virtual void fl_pop_matrix();
+  virtual void fl_scale(double x, double y);
+  virtual void fl_scale(double x);
+  virtual void fl_translate(double x, double y);
+  virtual void fl_rotate(double d);
+  virtual void fl_mult_matrix(double a, double b, double c, double d, double 
x, double y);
+  virtual double fl_transform_x(double x, double y);
+  virtual double fl_transform_y(double x, double y);
+  virtual double fl_transform_dx(double x, double y);
+  virtual double fl_transform_dy(double x, double y);
+  
+  virtual Fl_Region fl_clip_region();
+  virtual void fl_clip_region(Fl_Region r);
+  virtual void fl_restore_clip();
+  
+  protected:
   // Images
   /** \brief see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int 
D, int L). */
   virtual   void draw_image(const uchar* buf, int X,int Y,int W,int H, int 
D=3, int L=0) = 0;
@@ -278,6 +323,27 @@
     
 public:
   static const char *class_id;
+  matrix stack[MATRIX_STACK_SIZE];
+  int sptr;
+  matrix * fl_matrix;
+  matrix m;
+  
+  XPOINT *p;
+  int p_size;
+  int n;
+  int what;
+  enum {LINE, LOOP, POLYGON, POINT_};
+  
+  int gap_;
+#if defined(WIN32)
+  int counts[20];
+  int numcount;
+#endif  
+  
+  Fl_Region rstack[REGION_STACK_SIZE];
+  int rstackptr;
+  int fl_clip_state_number;
+    
   /** \brief The destructor */
   virtual ~Fl_Graphics_Driver() {};
 };
Index: FL/fl_draw.H
===================================================================
--- FL/fl_draw.H        (revision 8292)
+++ FL/fl_draw.H        (working copy)
@@ -133,18 +133,18 @@
 inline int fl_clip_box(int x , int y, int w, int h, int& X, int& Y, int& W, 
int& H) 
   {return fl_graphics_driver->clip_box(x,y,w,h,X,Y,W,H); }
 /** Undoes any clobbering of clip done by your program */
-extern void fl_restore_clip();
+inline void fl_restore_clip() { fl_graphics_driver->fl_restore_clip(); };
 /**
  Replaces the top of the clipping stack with a clipping region of any shape.
  
  Fl_Region is an operating system specific type.
  \param[in] r clipping region
  */
-FL_EXPORT void fl_clip_region(Fl_Region r);
+inline void fl_clip_region(Fl_Region r) { 
fl_graphics_driver->fl_clip_region(r); };
 /**
  returns the current clipping region.
  */
-extern Fl_Region fl_clip_region();
+inline Fl_Region fl_clip_region() { return 
fl_graphics_driver->fl_clip_region(); };
   
 
 // points:
@@ -326,13 +326,14 @@
 FL_EXPORT void fl_chord(int x, int y, int w, int h, double a1, double a2); // 
nyi
 
 // scalable drawing code (code in fl_vertex.C and fl_arc.C):
-FL_EXPORT void fl_push_matrix();
-FL_EXPORT void fl_pop_matrix();
-FL_EXPORT void fl_scale(double x, double y);
-FL_EXPORT void fl_scale(double x);
-FL_EXPORT void fl_translate(double x, double y);
-FL_EXPORT void fl_rotate(double d);
-FL_EXPORT void fl_mult_matrix(double a, double b, double c, double d, double 
x,double y);
+inline void fl_push_matrix() { fl_graphics_driver->fl_push_matrix(); };
+inline void fl_pop_matrix() { fl_graphics_driver->fl_pop_matrix(); };
+inline void fl_scale(double x, double y) { fl_graphics_driver->fl_scale(x, y); 
};
+inline void fl_scale(double x) { fl_graphics_driver->fl_scale(x); };
+inline void fl_translate(double x, double y) { 
fl_graphics_driver->fl_translate(x, y); };
+inline void fl_rotate(double d) { fl_graphics_driver->fl_rotate(d); };
+inline void fl_mult_matrix(double a, double b, double c, double d, double 
x,double y) 
+       { fl_graphics_driver->fl_mult_matrix(a, b, c, d, x, y); };
 /**
  Starts drawing a list of points. Points are added to the list with fl_vertex()
  */
@@ -424,10 +425,10 @@
  */
 inline void fl_end_complex_polygon() 
{fl_graphics_driver->end_complex_polygon(); }
 // get and use transformed positions:
-FL_EXPORT double fl_transform_x(double x, double y);
-FL_EXPORT double fl_transform_y(double x, double y);
-FL_EXPORT double fl_transform_dx(double x, double y);
-FL_EXPORT double fl_transform_dy(double x, double y);
+inline double fl_transform_x(double x, double y) {return 
fl_graphics_driver->fl_transform_x(x, y); };
+inline double fl_transform_y(double x, double y) {return 
fl_graphics_driver->fl_transform_y(x, y); };
+inline double fl_transform_dx(double x, double y) {return 
fl_graphics_driver->fl_transform_dx(x, y); };
+inline double fl_transform_dy(double x, double y) {return 
fl_graphics_driver->fl_transform_dy(x, y); };
 /**
  Adds coordinate pair to the vertex list without further transformations.
  \param[in] xf,yf transformed coordinate
Index: FL/Fl_Printer.H
===================================================================
--- FL/Fl_Printer.H     (revision 8292)
+++ FL/Fl_Printer.H     (working copy)
@@ -53,11 +53,10 @@
  Use Fl_Printer instead that is cross-platform and has the same API.
  */
 class Fl_System_Printer : public Fl_Paged_Device {
-  friend class Fl_Printer;
 private:
+    friend class Fl_Printer;
   /** \brief the printer's graphics context, if there's one, NULL otherwise */
-  void *gc; 
-  void set_current(void);
+  void *gc;
 #ifdef __APPLE__
   float scale_x;
   float scale_y;
@@ -78,6 +77,7 @@
   /** \brief The constructor */
   Fl_System_Printer(void);
 public:
+  void set_current();
   static const char *class_id;
   int start_job(int pagecount, int *frompage = NULL, int *topage = NULL);
   int start_page (void);
@@ -110,6 +110,7 @@
   /** \brief The constructor */
   Fl_PostScript_Printer(void) {class_name(class_id);};
 public:
+  void set_current();
   static const char *class_id;
   int start_job(int pages, int *firstpage = NULL, int *lastpage = NULL);
 };
Index: FL/win32.H
===================================================================
--- FL/win32.H  (revision 8292)
+++ FL/win32.H  (working copy)
@@ -37,7 +37,7 @@
 #include <windows.h>
 typedef HRGN Fl_Region;
 typedef HWND Window;
-
+#define FL_LIBRARY 1
 // this part is included only when compiling the FLTK library or if requested 
explicitly
 #if defined(FL_LIBRARY) || defined(FL_INTERNALS) 
 
Index: src/Fl_Device.cxx
===================================================================
--- src/Fl_Device.cxx   (revision 8292)
+++ src/Fl_Device.cxx   (working copy)
@@ -51,6 +51,16 @@
   fl_surface = this;
 }
 
+static matrix m0 = {1, 0, 0, 1, 0, 0};
+
+Fl_Graphics_Driver::Fl_Graphics_Driver() {
+       sptr=0; rstackptr=0; 
+       fl_clip_state_number=0;
+       m = m0; 
+       fl_matrix = &m; 
+       p = (XPOINT *)0;
+};
+
 //
 // End of "$Id$".
 //
Index: src/Fl_PostScript.cxx
===================================================================
--- src/Fl_PostScript.cxx       (revision 8292)
+++ src/Fl_PostScript.cxx       (working copy)
@@ -1115,9 +1115,6 @@
   delete [] out;
 }
 
-struct matrix {double a, b, c, d, x, y;};
-extern matrix * fl_matrix;
-
 void Fl_PostScript_Graphics_Driver::concat(){
   fprintf(output,"[%g %g %g %g %g %g] CT\n", fl_matrix->a , fl_matrix->b , 
fl_matrix->c , fl_matrix->d , fl_matrix->x , fl_matrix->y);
 }
Index: src/fl_rect.cxx
===================================================================
--- src/fl_rect.cxx     (revision 8292)
+++ src/fl_rect.cxx     (working copy)
@@ -507,12 +507,6 @@
 
 ////////////////////////////////////////////////////////////////
 
-#define STACK_SIZE 10
-#define STACK_MAX (STACK_SIZE - 1)
-static Fl_Region rstack[STACK_SIZE];
-static int rstackptr=0;
-int fl_clip_state_number=0; // used by gl_begin.cxx to update GL clip
-
 #if !defined(WIN32) && !defined(__APPLE__)
 // Missing X call: (is this the fastest way to init a 1-rectangle region?)
 // MSWindows equivalent exists, implemented inline in win32.H
@@ -526,7 +520,7 @@
 }
 #endif
 
-void fl_restore_clip() {
+void Fl_Graphics_Driver::fl_restore_clip() {
   fl_clip_state_number++;
   Fl_Region r = rstack[rstackptr];
 #if defined(USE_X11)
@@ -554,14 +548,14 @@
 #endif
 }
 
-void fl_clip_region(Fl_Region r) {
+void Fl_Graphics_Driver::fl_clip_region(Fl_Region r) {
   Fl_Region oldr = rstack[rstackptr];
   if (oldr) XDestroyRegion(oldr);
   rstack[rstackptr] = r;
   fl_restore_clip();
 }
 
-Fl_Region fl_clip_region() {
+Fl_Region Fl_Graphics_Driver::fl_clip_region() {
   return rstack[rstackptr];
 }
 
@@ -596,14 +590,14 @@
 # error unsupported platform
 #endif
   }
-  if (rstackptr < STACK_MAX) rstack[++rstackptr] = r;
+  if (rstackptr < REGION_STACK_MAX) rstack[++rstackptr] = r;
   else Fl::warning("fl_push_clip: clip stack overflow!\n");
   fl_restore_clip();
 }
 
 // make there be no clip (used by fl_begin_offscreen() only!)
 void Fl_Graphics_Driver::push_no_clip() {
-  if (rstackptr < STACK_MAX) rstack[++rstackptr] = 0;
+  if (rstackptr < REGION_STACK_MAX) rstack[++rstackptr] = 0;
   else Fl::warning("fl_push_no_clip: clip stack overflow!\n");
   fl_restore_clip();
 }
Index: src/fl_vertex.cxx
===================================================================
--- src/fl_vertex.cxx   (revision 8292)
+++ src/fl_vertex.cxx   (working copy)
@@ -44,20 +44,12 @@
 #include <FL/math.h>
 #include <stdlib.h>
 
-struct matrix {double a, b, c, d, x, y;};
-
-static matrix m = {1, 0, 0, 1, 0, 0};
-
-static matrix stack[32];
-matrix * fl_matrix = &m;
-static int sptr = 0;
-
 /**
   Saves the current transformation matrix on the stack. 
   The maximum depth of the stack is 4.
 */
-void fl_push_matrix() {
-  if (sptr==32)
+void Fl_Graphics_Driver::fl_push_matrix() {
+  if (sptr==MATRIX_STACK_SIZE)
     Fl::error("fl_push_matrix(): matrix stack overflow.");
   else
     stack[sptr++] = m;
@@ -66,7 +58,7 @@
 /**
   Restores the current transformation matrix from the stack.
 */
-void fl_pop_matrix() {
+void Fl_Graphics_Driver::fl_pop_matrix() {
   if (sptr==0)
     Fl::error("fl_pop_matrix(): matrix stack underflow.");
   else 
@@ -79,7 +71,7 @@
   \param[in] a,b,c,d,x,y transformation matrix elements such that
              <tt> X' = aX + cY + x </tt> and <tt> Y' = bX +dY + y </tt>
 */
-void fl_mult_matrix(double a, double b, double c, double d, double x, double 
y) {
+void Fl_Graphics_Driver::fl_mult_matrix(double a, double b, double c, double 
d, double x, double y) {
   matrix o;
   o.a = a*m.a + b*m.c;
   o.b = a*m.b + b*m.d;
@@ -94,25 +86,25 @@
   Concatenates scaling transformation onto the current one.
   \param[in] x,y scale factors in x-direction and y-direction
 */
-void fl_scale(double x,double y) {fl_mult_matrix(x,0,0,y,0,0);}
+void Fl_Graphics_Driver::fl_scale(double x,double y) 
{fl_mult_matrix(x,0,0,y,0,0);}
 
 /**
   Concatenates scaling transformation onto the current one.
   \param[in] x scale factor in both x-direction and y-direction
 */
-void fl_scale(double x) {fl_mult_matrix(x,0,0,x,0,0);}
+void Fl_Graphics_Driver::fl_scale(double x) {fl_mult_matrix(x,0,0,x,0,0);}
 
 /**
   Concatenates translation transformation onto the current one.
   \param[in] x,y translation factor in x-direction and y-direction
 */
-void fl_translate(double x,double y) {fl_mult_matrix(1,0,0,1,x,y);}
+void Fl_Graphics_Driver::fl_translate(double x,double y) 
{fl_mult_matrix(1,0,0,1,x,y);}
 
 /**
   Concatenates rotation transformation onto the current one.
   \param[in] d - rotation angle, counter-clockwise in degrees (not radians)
 */
-void fl_rotate(double d) {
+void Fl_Graphics_Driver::fl_rotate(double d) {
   if (d) {
     double s, c;
     if (d == 0) {s = 0; c = 1;}
@@ -124,27 +116,6 @@
   }
 }
 
-// typedef what the x,y fields in a point are:
-#ifdef WIN32
-typedef int COORD_T;
-#  define XPOINT XPoint
-#elif defined(__APPLE_QUARTZ__)
-typedef float COORD_T;
-typedef struct { float x; float y; } QPoint;
-#  define XPOINT QPoint
-extern float fl_quartz_line_width_;
-#else
-typedef short COORD_T;
-#  define XPOINT XPoint
-#endif
-
-static XPOINT *p = (XPOINT *)0;
-
-static int p_size;
-static int n;
-static int what;
-enum {LINE, LOOP, POLYGON, POINT_};
-
 void Fl_Graphics_Driver::begin_points() {n = 0; what = POINT_;}
 
 void Fl_Graphics_Driver::begin_line() {n = 0; what = LINE;}
@@ -157,27 +128,27 @@
   Transforms coordinate using the current transformation matrix.
   \param[in] x,y coordinate
 */
-double fl_transform_x(double x, double y) {return x*m.a + y*m.c + m.x;}
+double Fl_Graphics_Driver::fl_transform_x(double x, double y) {return x*m.a + 
y*m.c + m.x;}
 
 /**
   Transform coordinate using the current transformation matrix.
   \param[in] x,y coordinate
 */
-double fl_transform_y(double x, double y) {return x*m.b + y*m.d + m.y;}
+double Fl_Graphics_Driver::fl_transform_y(double x, double y) {return x*m.b + 
y*m.d + m.y;}
 
 /**
   Transforms distance using current transformation matrix.
   \param[in] x,y coordinate
 */
-double fl_transform_dx(double x, double y) {return x*m.a + y*m.c;}
+double Fl_Graphics_Driver::fl_transform_dx(double x, double y) {return x*m.a + 
y*m.c;}
 
 /**
   Transforms distance using current transformation matrix.
   \param[in] x,y coordinate
 */
-double fl_transform_dy(double x, double y) {return x*m.b + y*m.d;}
+double Fl_Graphics_Driver::fl_transform_dy(double x, double y) {return x*m.b + 
y*m.d;}
 
-static void fl_transformed_vertex(COORD_T x, COORD_T y) {
+void Fl_Graphics_Driver::fl_transformed_vertex0(COORD_T x, COORD_T y) {
   if (!n || x != p[n-1].x || y != p[n-1].y) {
     if (n >= p_size) {
       p_size = p ? 2*p_size : 16;
@@ -191,14 +162,14 @@
 
 void Fl_Graphics_Driver::transformed_vertex(double xf, double yf) {
 #ifdef __APPLE_QUARTZ__
-  fl_transformed_vertex(COORD_T(xf), COORD_T(yf));
+  fl_transformed_vertex0(COORD_T(xf), COORD_T(yf));
 #else
-  fl_transformed_vertex(COORD_T(rint(xf)), COORD_T(rint(yf)));
+  fl_transformed_vertex0(COORD_T(rint(xf)), COORD_T(rint(yf)));
 #endif
 }
 
 void Fl_Graphics_Driver::vertex(double x,double y) {
-  fl_transformed_vertex(x*m.a + y*m.c + m.x, x*m.b + y*m.d + m.y);
+  fl_transformed_vertex0(x*m.a + y*m.c + m.x, x*m.b + y*m.d + m.y);
 }
 
 void Fl_Graphics_Driver::end_points() {
@@ -241,7 +212,7 @@
 #endif
 }
 
-static void fixloop() {  // remove equal points from closed path
+void Fl_Graphics_Driver::fixloop() {  // remove equal points from closed path
   while (n>2 && p[n-1].x == p[0].x && p[n-1].y == p[0].y) n--;
 }
 
@@ -278,12 +249,6 @@
 #endif
 }
 
-static int gap_;
-#if defined(WIN32)
-static int counts[20];
-static int numcount;
-#endif
-
 void Fl_Graphics_Driver::begin_complex_polygon() {
   fl_begin_polygon();
   gap_ = 0;
Index: src/gl_start.cxx
===================================================================
--- src/gl_start.cxx    (revision 8292)
+++ src/gl_start.cxx    (working copy)
@@ -46,8 +46,6 @@
 #include <FL/fl_draw.H>
 #include "Fl_Gl_Choice.H"
 
-extern int fl_clip_state_number; // in fl_rect.cxx
-
 static GLContext context;
 static int clip_state_number=-1;
 static int pw, ph;
@@ -89,8 +87,8 @@
     glOrtho(0, pw, 0, ph, -1, 1);
     glDrawBuffer(GL_FRONT);
   }
-  if (clip_state_number != fl_clip_state_number) {
-    clip_state_number = fl_clip_state_number;
+  if (clip_state_number != fl_graphics_driver->fl_clip_state_number) {
+    clip_state_number = fl_graphics_driver->fl_clip_state_number;
     int x, y, w, h;
     if (fl_clip_box(0, 0, Fl_Window::current()->w(), Fl_Window::current()->h(),
                    x, y, w, h)) {
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to