summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Device.cxx42
-rw-r--r--src/Fl_Gl_Window.cxx5
-rw-r--r--src/Fl_Image_Surface.cxx14
-rw-r--r--src/Fl_win32.cxx5
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx5
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx3
-rw-r--r--src/drivers/X11/Fl_X11_Window_Driver.cxx5
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx23
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx5
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx3
10 files changed, 54 insertions, 56 deletions
diff --git a/src/Fl_Device.cxx b/src/Fl_Device.cxx
index 2726eaca8..bec74b93e 100644
--- a/src/Fl_Device.cxx
+++ b/src/Fl_Device.cxx
@@ -42,23 +42,18 @@
|
+- Fl_..._Graphics_Driver: platform specific graphics driver
-TODO:
- Window Device to handle creation of surfaces and manage events
- System Device to handle file system acces, standard dialogs, etc.
-
*/
-Fl_Surface_Device *Fl_Surface_Device::pre_surface_ = NULL;
-
-/** \brief Make this surface the current drawing surface.
- This surface will receive all future graphics requests. */
+/** Make this surface the current drawing surface.
+ This surface will receive all future graphics requests.
+ \p Starting from FLTK 1.4.0, another convenient API to set/unset the current drawing surface
+ is Fl_Surface_Device::push_current( ) / Fl_Surface_Device::pop_current().*/
void Fl_Surface_Device::set_current(void)
{
- if (pre_surface_) pre_surface_->end_current_();
+ if (surface_) surface_->end_current_();
fl_graphics_driver = pGraphicsDriver;
surface_ = this;
pGraphicsDriver->global_gc();
- pre_surface_ = this;
}
Fl_Surface_Device* Fl_Surface_Device::surface_; // the current target surface of graphics operations
@@ -66,7 +61,7 @@ Fl_Surface_Device* Fl_Surface_Device::surface_; // the current target surface of
Fl_Surface_Device::~Fl_Surface_Device()
{
- if (pre_surface_ == this) pre_surface_ = NULL;
+ if (surface_ == this) surface_ = NULL;
}
@@ -88,6 +83,31 @@ Fl_Surface_Device *Fl_Surface_Device::default_surface()
return Fl_Display_Device::display_device();
}
+static int surface_stack_height = 0;
+static Fl_Surface_Device *surface_stack[16];
+
+/** Pushes \p new_current on top of the stack of current drawing surfaces, and makes it current.
+ \p new_current will receive all future graphics requests.
+ \version 1.4.0 */
+void Fl_Surface_Device::push_current(Fl_Surface_Device *new_current)
+{
+ if (surface_stack_height < sizeof(surface_stack)/sizeof(void*)) {
+ surface_stack[surface_stack_height++] = surface();
+ } else {
+ fprintf(stderr, "FLTK Fl_Surface_Device::push_current Stack overflow error\n");
+ }
+ new_current->set_current();
+}
+
+/** Removes the top element from the current drawing surface stack, and makes the new top element current.
+ \return A pointer to the new current drawing surface.
+ \version 1.4.0 */
+Fl_Surface_Device *Fl_Surface_Device::pop_current()
+{
+ if (surface_stack_height > 0) surface_stack[--surface_stack_height]->set_current();
+ return surface_;
+}
+
//
// End of "$Id$".
//
diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx
index 7564f1a3a..f59b69244 100644
--- a/src/Fl_Gl_Window.cxx
+++ b/src/Fl_Gl_Window.cxx
@@ -359,8 +359,7 @@ void Fl_Gl_Window::draw_overlay() {}
*/
void Fl_Gl_Window::draw() {
#ifdef FL_CFG_GFX_OPENGL
- Fl_Surface_Device *prev_device = Fl_Surface_Device::surface();
- Fl_OpenGL_Display_Device::display_device()->set_current();
+ Fl_Surface_Device::push_current( Fl_OpenGL_Display_Device::display_device() );
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glPushMatrix();
@@ -375,7 +374,7 @@ void Fl_Gl_Window::draw() {
glPopMatrix();
glPushAttrib(GL_ENABLE_BIT);
- prev_device->set_current();
+ Fl_Surface_Device::pop_current();
#else
Fl::fatal("Fl_Gl_Window::draw() *must* be overriden. Please refer to the documentation.");
#endif
diff --git a/src/Fl_Image_Surface.cxx b/src/Fl_Image_Surface.cxx
index 0dd2f6ff7..c925931ac 100644
--- a/src/Fl_Image_Surface.cxx
+++ b/src/Fl_Image_Surface.cxx
@@ -146,21 +146,13 @@ void fl_delete_offscreen(Fl_Offscreen ctx) {
}
}
-static Fl_Surface_Device* stack_surface[16];
-static unsigned stack_height = 0;
-
/** Send all subsequent drawing commands to this offscreen buffer.
\param ctx the offscreen buffer.
*/
void fl_begin_offscreen(Fl_Offscreen ctx) {
for (int i = 0; i < count_offscreens; i++) {
if (offscreen_api_surface[i] && offscreen_api_surface[i]->offscreen() == ctx) {
- if (stack_height < sizeof(stack_surface)/sizeof(void*)) {
- stack_surface[stack_height++] = Fl_Surface_Device::surface();
- } else {
- fprintf(stderr, "FLTK fl_begin_offscreen Stack overflow error\n");
- }
- offscreen_api_surface[i]->set_current();
+ Fl_Surface_Device::push_current(offscreen_api_surface[i]);
return;
}
}
@@ -169,9 +161,7 @@ void fl_begin_offscreen(Fl_Offscreen ctx) {
/** Quit sending drawing commands to the current offscreen buffer.
*/
void fl_end_offscreen() {
- if (stack_height > 0) {
- stack_surface[--stack_height]->set_current();
- }
+ Fl_Surface_Device::pop_current();
}
/** @} */
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index 3b981ae4b..df6238366 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -2392,9 +2392,8 @@ void Fl_WinAPI_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top
float scaling = 1;
RECT r = border_width_title_bar_height(wsides, hbottom, bt, &scaling);
int htop = bt + hbottom;
- Fl_Surface_Device *previous = Fl_Surface_Device::surface();
Window save_win = fl_window;
- Fl_Display_Device::display_device()->set_current();
+ Fl_Surface_Device::push_current( Fl_Display_Device::display_device() );
pWindow->show();
Fl::check();
void* save_gc = fl_graphics_driver->gc();
@@ -2417,7 +2416,7 @@ void Fl_WinAPI_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top
ReleaseDC(NULL, (HDC)fl_graphics_driver->gc());
fl_window = save_win;
fl_graphics_driver->gc(save_gc);
- previous->set_current();
+ Fl_Surface_Device::pop_current();
}
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
index ca3d74734..00d96ea42 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
@@ -251,12 +251,11 @@ static void pmProviderRelease (void *ctxt, const void *data, size_t size) {
}
fl_uintptr_t Fl_Quartz_Graphics_Driver::cache(Fl_Pixmap *img, int w, int h, const char *const*data) {
- Fl_Surface_Device *old = Fl_Surface_Device::surface();
Fl_Image_Surface *surf = new Fl_Image_Surface(w, h);
- surf->set_current();
+ Fl_Surface_Device::push_current(surf);
fl_draw_pixmap(data, 0, 0, FL_BLACK);
CGContextRef src = surf->get_offscreen_before_delete();
- old->set_current();
+ Fl_Surface_Device::pop_current();
delete surf;
void *cgdata = CGBitmapContextGetData(src);
int sw = CGBitmapContextGetWidth(src);
diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
index 1a2e3de5e..cb22904aa 100644
--- a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
@@ -29,7 +29,6 @@ class Fl_Quartz_Image_Surface_Driver : public Fl_Image_Surface_Driver {
friend class Fl_Image_Surface;
virtual void end_current_();
public:
- Fl_Surface_Device *previous;
Window pre_window;
Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res);
~Fl_Quartz_Image_Surface_Driver();
@@ -47,7 +46,6 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i
Fl_Quartz_Image_Surface_Driver::Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res) : Fl_Image_Surface_Driver(w, h, high_res, 0) {
- previous = 0;
int W = high_res ? 2*w : w;
int H = high_res ? 2*h : h;
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
@@ -77,7 +75,6 @@ Fl_Quartz_Image_Surface_Driver::~Fl_Quartz_Image_Surface_Driver() {
void Fl_Quartz_Image_Surface_Driver::set_current() {
pre_window = fl_window;
- if (!previous) previous = Fl_Surface_Device::surface();
driver()->gc(offscreen);
fl_window = 0;
Fl_Surface_Device::set_current();
diff --git a/src/drivers/X11/Fl_X11_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Window_Driver.cxx
index 6fc76e325..0f16c7812 100644
--- a/src/drivers/X11/Fl_X11_Window_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_Window_Driver.cxx
@@ -387,8 +387,7 @@ void Fl_X11_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top, F
top = left = bottom = right = NULL;
if (pWindow->decorated_h() == h()) return;
Window from = fl_window;
- Fl_Surface_Device *previous = Fl_Surface_Device::surface();
- Fl_Display_Device::display_device()->set_current();
+ Fl_Surface_Device::push_current( Fl_Display_Device::display_device() );
pWindow->show();
Fl::check();
pWindow->make_current();
@@ -421,7 +420,7 @@ void Fl_X11_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top, F
}
}
fl_window = from;
- previous->Fl_Surface_Device::set_current();
+ Fl_Surface_Device::pop_current();
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
index c439ddf94..156bd87d3 100644
--- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
@@ -28,10 +28,10 @@
class Fl_Xlib_Copy_Surface_Driver : public Fl_Copy_Surface_Driver {
friend class Fl_Copy_Surface_Driver;
+ virtual void end_current_();
protected:
Fl_Offscreen xid;
Window oldwindow;
- Fl_Surface_Device *_ss;
Fl_Xlib_Copy_Surface_Driver(int w, int h);
~Fl_Xlib_Copy_Surface_Driver();
void set_current();
@@ -51,26 +51,22 @@ Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int
Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy_Surface_Driver(w, h) {
driver(new Fl_Translated_Xlib_Graphics_Driver());
- Fl::first_window()->make_current();
- oldwindow = fl_xid(Fl::first_window());
+ oldwindow = fl_window;
xid = fl_create_offscreen(w,h);
- _ss = NULL;
- Fl_Surface_Device *present_surface = Fl_Surface_Device::surface();
- Fl_Surface_Device::set_current();
- fl_push_no_clip();
+ driver()->push_no_clip();
fl_window = xid;
driver()->color(FL_WHITE);
driver()->rectf(0, 0, w, h);
- present_surface->set_current();
fl_window = oldwindow;
}
Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() {
- fl_pop_clip();
+ driver()->pop_clip();
+ bool need_push = (Fl_Surface_Device::surface() != this);
+ if (need_push) Fl_Surface_Device::push_current(this);
unsigned char *data = fl_read_image(NULL,0,0,width,height,0);
- fl_window = oldwindow;
- _ss->set_current();
+ if (need_push) Fl_Surface_Device::pop_current();
Fl_X11_Screen_Driver::copy_image(data, width, height, 1);
delete[] data;
fl_delete_offscreen(xid);
@@ -79,11 +75,14 @@ Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() {
void Fl_Xlib_Copy_Surface_Driver::set_current() {
+ oldwindow = fl_window;
fl_window = xid;
- if (!_ss) _ss = Fl_Surface_Device::surface();
Fl_Surface_Device::set_current();
}
+void Fl_Xlib_Copy_Surface_Driver::end_current_() {
+ fl_window = oldwindow;
+}
void Fl_Xlib_Copy_Surface_Driver::translate(int x, int y) {
((Fl_Translated_Xlib_Graphics_Driver*)driver())->translate_all(x, y);
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
index 7ecb5471e..96f8b0685 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
@@ -714,10 +714,9 @@ void Fl_Xlib_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, in
depth |= FL_IMAGE_WITH_ALPHA;
}
if (surface) {
- Fl_Surface_Device *old_surf = Fl_Surface_Device::surface();
- surface->set_current();
+ Fl_Surface_Device::push_current(surface);
fl_draw_image(img->array, 0, 0, img->w(), img->h(), depth, img->ld());
- old_surf->set_current();
+ Fl_Surface_Device::pop_current();
*Fl_Graphics_Driver::id(img) = surface->get_offscreen_before_delete();
delete surface;
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
index 022a94066..4ec2bd25d 100644
--- a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
@@ -29,7 +29,6 @@ class Fl_Xlib_Image_Surface_Driver : public Fl_Image_Surface_Driver {
friend class Fl_Image_Surface;
virtual void end_current_();
public:
- Fl_Surface_Device *previous;
Window pre_window;
int was_high;
Fl_Xlib_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off);
@@ -46,7 +45,6 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i
}
Fl_Xlib_Image_Surface_Driver::Fl_Xlib_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Image_Surface_Driver(w, h, high_res, off) {
- previous = 0;
if (!off) {
fl_open_display();
offscreen = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, fl_visual->depth);
@@ -61,7 +59,6 @@ Fl_Xlib_Image_Surface_Driver::~Fl_Xlib_Image_Surface_Driver() {
void Fl_Xlib_Image_Surface_Driver::set_current() {
pre_window = fl_window;
- if (!previous) previous = Fl_Surface_Device::surface();
Fl_Surface_Device::set_current();
fl_window = offscreen;
fl_push_no_clip();