Remove Fl_Image_Surface::end_current() to be called after usage of the drawing surface.
This ensures API compatibility with FLTK 1.3 where Fl_Surface_Device->set_current() is used to change the current drawing surface. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12125 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
4755ace9e9
commit
5bb4e853c7
@ -83,7 +83,6 @@ protected:
|
||||
virtual void untranslate() {}
|
||||
int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;}
|
||||
virtual Fl_RGB_Image *image() {return NULL;}
|
||||
virtual void end_current() {}
|
||||
/** Each platform implements this function its own way.
|
||||
It returns an object implementing all virtual functions
|
||||
of class Fl_Copy_Surface_Driver for the plaform.
|
||||
|
@ -52,13 +52,17 @@ class Fl_Widget;
|
||||
</ol>
|
||||
*/
|
||||
class FL_EXPORT Fl_Surface_Device {
|
||||
/** \brief The graphics driver in use by this surface. */
|
||||
/** The graphics driver in use by this surface. */
|
||||
Fl_Graphics_Driver *pGraphicsDriver;
|
||||
static Fl_Surface_Device *_surface; // the surface that currently receives graphics output
|
||||
static Fl_Surface_Device *default_surface(); // create surface if none exists yet
|
||||
static Fl_Surface_Device *pre_surface_;
|
||||
// Some drawing surfaces (e.g., Fl_XXX_Image_Surface_Driver) need to re-implement this.
|
||||
// Gets called each time a surface ceases to be the current drawing surface.
|
||||
virtual void end_current_() {}
|
||||
protected:
|
||||
/** \brief Constructor that sets the graphics driver to use for the created surface. */
|
||||
Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {pGraphicsDriver = graphics_driver; };
|
||||
/** Constructor that sets the graphics driver to use for the created surface. */
|
||||
Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {pGraphicsDriver = graphics_driver; }
|
||||
public:
|
||||
virtual void set_current(void);
|
||||
/** \brief Sets the graphics driver of this drawing surface. */
|
||||
|
@ -77,7 +77,6 @@ public:
|
||||
Fl_Image_Surface(int w, int h, int high_res = 0, Fl_Offscreen off = 0);
|
||||
~Fl_Image_Surface();
|
||||
void set_current();
|
||||
void end_current();
|
||||
Fl_RGB_Image *image();
|
||||
Fl_Shared_Image *highres_image();
|
||||
void origin(int *x, int *y);
|
||||
@ -106,7 +105,6 @@ protected:
|
||||
virtual void untranslate() {}
|
||||
int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;}
|
||||
virtual Fl_RGB_Image *image() {return NULL;}
|
||||
virtual void end_current() {}
|
||||
/** Each platform implements this function its own way.
|
||||
It returns an object implementing all virtual functions
|
||||
of class Fl_Image_Surface_Driver for the plaform.
|
||||
|
@ -48,14 +48,17 @@ TODO:
|
||||
|
||||
*/
|
||||
|
||||
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. */
|
||||
void Fl_Surface_Device::set_current(void)
|
||||
{
|
||||
if (pre_surface_) pre_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
|
||||
@ -63,6 +66,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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,9 +55,6 @@ void Fl_Image_Surface::set_current() {
|
||||
if (platform_surface) platform_surface->set_current();
|
||||
}
|
||||
|
||||
/** Stop sending graphics commands to the surface */
|
||||
void Fl_Image_Surface::end_current() {platform_surface->end_current();}
|
||||
|
||||
void Fl_Image_Surface::translate(int x, int y) {
|
||||
if (platform_surface) platform_surface->translate(x, y);
|
||||
}
|
||||
@ -149,7 +146,7 @@ void fl_delete_offscreen(Fl_Offscreen ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
static int stack_current_offscreen[16];
|
||||
static Fl_Surface_Device* stack_surface[16];
|
||||
static unsigned stack_height = 0;
|
||||
|
||||
/** Send all subsequent drawing commands to this offscreen buffer.
|
||||
@ -158,12 +155,12 @@ static unsigned stack_height = 0;
|
||||
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) {
|
||||
offscreen_api_surface[i]->set_current();
|
||||
if (stack_height < sizeof(stack_current_offscreen)/sizeof(int)) {
|
||||
stack_current_offscreen[stack_height++] = i;
|
||||
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();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -173,8 +170,7 @@ void fl_begin_offscreen(Fl_Offscreen ctx) {
|
||||
*/
|
||||
void fl_end_offscreen() {
|
||||
if (stack_height > 0) {
|
||||
int i = stack_current_offscreen[--stack_height];
|
||||
offscreen_api_surface[i]->end_current();
|
||||
stack_surface[--stack_height]->set_current();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2417,7 +2417,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->Fl_Surface_Device::set_current();
|
||||
previous->set_current();
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
class Fl_GDI_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;
|
||||
@ -39,7 +40,6 @@ public:
|
||||
void translate(int x, int y);
|
||||
void untranslate();
|
||||
Fl_RGB_Image *image();
|
||||
void end_current();
|
||||
};
|
||||
|
||||
|
||||
@ -90,7 +90,6 @@ Fl_RGB_Image* Fl_GDI_Image_Surface_Driver::image()
|
||||
{
|
||||
unsigned char *data;
|
||||
data = fl_read_image(NULL, 0, 0, width, height, 0);
|
||||
end_current();
|
||||
previous->driver()->gc(_sgc);
|
||||
Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height);
|
||||
image->alloc_array = 1;
|
||||
@ -98,13 +97,12 @@ Fl_RGB_Image* Fl_GDI_Image_Surface_Driver::image()
|
||||
}
|
||||
|
||||
|
||||
void Fl_GDI_Image_Surface_Driver::end_current()
|
||||
void Fl_GDI_Image_Surface_Driver::end_current_()
|
||||
{
|
||||
HDC gc = (HDC)driver()->gc();
|
||||
RestoreDC(gc, _savedc);
|
||||
DeleteDC(gc);
|
||||
fl_pop_clip();
|
||||
previous->Fl_Surface_Device::set_current();
|
||||
fl_window = pre_window;
|
||||
}
|
||||
|
||||
|
@ -251,11 +251,12 @@ 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_draw_pixmap(data, 0, 0, FL_BLACK);
|
||||
CGContextRef src = surf->get_offscreen_before_delete();
|
||||
surf->end_current();
|
||||
old->set_current();
|
||||
delete surf;
|
||||
void *cgdata = CGBitmapContextGetData(src);
|
||||
int sw = CGBitmapContextGetWidth(src);
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
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;
|
||||
@ -36,7 +37,6 @@ public:
|
||||
void translate(int x, int y);
|
||||
void untranslate();
|
||||
Fl_RGB_Image *image();
|
||||
void end_current();
|
||||
};
|
||||
|
||||
|
||||
@ -108,9 +108,8 @@ Fl_RGB_Image* Fl_Quartz_Image_Surface_Driver::image()
|
||||
return image;
|
||||
}
|
||||
|
||||
void Fl_Quartz_Image_Surface_Driver::end_current()
|
||||
void Fl_Quartz_Image_Surface_Driver::end_current_()
|
||||
{
|
||||
previous->Fl_Surface_Device::set_current();
|
||||
fl_window = pre_window;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy
|
||||
_ss = NULL;
|
||||
Fl_Surface_Device *present_surface = Fl_Surface_Device::surface();
|
||||
Fl_Surface_Device::set_current();
|
||||
fl_push_no_clip();
|
||||
fl_window = xid;
|
||||
driver()->color(FL_WHITE);
|
||||
driver()->rectf(0, 0, w, h);
|
||||
@ -81,7 +82,6 @@ void Fl_Xlib_Copy_Surface_Driver::set_current() {
|
||||
fl_window = xid;
|
||||
if (!_ss) _ss = Fl_Surface_Device::surface();
|
||||
Fl_Surface_Device::set_current();
|
||||
fl_push_no_clip();
|
||||
}
|
||||
|
||||
|
||||
|
@ -714,9 +714,10 @@ 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_draw_image(img->array, 0, 0, img->w(), img->h(), depth, img->ld());
|
||||
surface->end_current();
|
||||
old_surf->set_current();
|
||||
*Fl_Graphics_Driver::id(img) = surface->get_offscreen_before_delete();
|
||||
delete surface;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
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;
|
||||
@ -37,7 +38,6 @@ public:
|
||||
void translate(int x, int y);
|
||||
void untranslate();
|
||||
Fl_RGB_Image *image();
|
||||
void end_current();
|
||||
};
|
||||
|
||||
Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen off)
|
||||
@ -62,8 +62,8 @@ 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_window = offscreen;
|
||||
Fl_Surface_Device::set_current();
|
||||
fl_window = offscreen;
|
||||
fl_push_no_clip();
|
||||
}
|
||||
|
||||
@ -78,16 +78,14 @@ void Fl_Xlib_Image_Surface_Driver::untranslate() {
|
||||
Fl_RGB_Image* Fl_Xlib_Image_Surface_Driver::image()
|
||||
{
|
||||
unsigned char *data = fl_read_image(NULL, 0, 0, width, height, 0);
|
||||
end_current();
|
||||
Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height);
|
||||
image->alloc_array = 1;
|
||||
return image;
|
||||
}
|
||||
|
||||
void Fl_Xlib_Image_Surface_Driver::end_current()
|
||||
void Fl_Xlib_Image_Surface_Driver::end_current_()
|
||||
{
|
||||
fl_pop_clip();
|
||||
previous->Fl_Surface_Device::set_current();
|
||||
fl_window = pre_window;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user