diff options
| author | Manolo Gouy <Manolo> | 2016-03-19 16:48:33 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-03-19 16:48:33 +0000 |
| commit | 8711cf8be9035e5bc5e2e487012fa50d24e65748 (patch) | |
| tree | 08694c4ba7e3628eb00fb40d398d5f622fe6ad6e /src/drivers | |
| parent | f8bd5f304681258e4f9cf16784782fefa7e378f8 (diff) | |
(hopefully) Final driver-based rewriting of the Fl_Image_Surface class.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11371 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Image_Surface.cxx | 48 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx | 67 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Image_Surface.cxx | 52 |
4 files changed, 111 insertions, 58 deletions
diff --git a/src/drivers/GDI/Fl_GDI_Image_Surface.cxx b/src/drivers/GDI/Fl_GDI_Image_Surface.cxx index 3e3d1f55b..9039c4f5a 100644 --- a/src/drivers/GDI/Fl_GDI_Image_Surface.cxx +++ b/src/drivers/GDI/Fl_GDI_Image_Surface.cxx @@ -16,28 +16,52 @@ // http://www.fltk.org/str.php // -#include <FL/fl_draw.H> #include "../../config_lib.h" - #ifdef FL_CFG_GFX_GDI #include "Fl_GDI_Graphics_Driver.H" -#include "Fl_GDI_Image_Surface.H" +#include <FL/Fl_Image_Surface.H> +#include <FL/fl_draw.H> +#include <windows.h> + +class Fl_GDI_Image_Surface_Driver : public Fl_Image_Surface_Driver { + friend class Fl_Image_Surface; +public: + Fl_Surface_Device *previous; + Window pre_window; + HDC _sgc; + int _savedc; + Fl_GDI_Image_Surface_Driver(int w, int h, int high_res); + ~Fl_GDI_Image_Surface_Driver(); + void set_current(); + 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) +{ + return new Fl_GDI_Image_Surface_Driver(w, h, high_res); +} -Fl_Image_Surface::Helper::Helper(int w, int h, int high_res) : Fl_Widget_Surface(NULL), width(w), height(h) { +Fl_GDI_Image_Surface_Driver::Fl_GDI_Image_Surface_Driver(int w, int h, int high_res) : Fl_Image_Surface_Driver(w, h, high_res, 0) { previous = 0; offscreen = CreateCompatibleBitmap( (fl_graphics_driver->gc() ? (HDC)fl_graphics_driver->gc() : fl_GetDC(0) ) , w, h); driver(new Fl_Translated_GDI_Graphics_Driver); _sgc = NULL; } -Fl_Image_Surface::Helper::~Helper() { + +Fl_GDI_Image_Surface_Driver::~Fl_GDI_Image_Surface_Driver() { if (offscreen) DeleteObject(offscreen); } -void Fl_Image_Surface::Helper::set_current() { + +void Fl_GDI_Image_Surface_Driver::set_current() { pre_window = fl_window; if (!previous) previous = Fl_Surface_Device::surface(); if (!_sgc) _sgc = (HDC)previous->driver()->gc(); @@ -49,15 +73,18 @@ void Fl_Image_Surface::Helper::set_current() { fl_push_no_clip(); } -void Fl_Image_Surface::Helper::translate(int x, int y) { + +void Fl_GDI_Image_Surface_Driver::translate(int x, int y) { ((Fl_Translated_GDI_Graphics_Driver*)driver())->translate_all(x, y); } -void Fl_Image_Surface::Helper::untranslate() { + +void Fl_GDI_Image_Surface_Driver::untranslate() { ((Fl_Translated_GDI_Graphics_Driver*)driver())->untranslate_all(); } -Fl_RGB_Image* Fl_Image_Surface::Helper::image() + +Fl_RGB_Image* Fl_GDI_Image_Surface_Driver::image() { unsigned char *data; data = fl_read_image(NULL, 0, 0, width, height, 0); @@ -68,7 +95,8 @@ Fl_RGB_Image* Fl_Image_Surface::Helper::image() return image; } -void Fl_Image_Surface::Helper::end_current() + +void Fl_GDI_Image_Surface_Driver::end_current() { HDC gc = (HDC)driver()->gc(); RestoreDC(gc, _savedc); diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx index c2b6eb534..0914eda90 100644 --- a/src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface.cxx @@ -16,19 +16,37 @@ // http://www.fltk.org/str.php // -#include <FL/fl_draw.H> - #include "../../config_lib.h" - #ifdef FL_CFG_GFX_QUARTZ +#include <FL/fl_draw.H> +#include <FL/Fl_Image_Surface.H> #include "Fl_Quartz_Graphics_Driver.H" -#include "Fl_Quartz_Image_Surface.H" - #include <ApplicationServices/ApplicationServices.h> +class Fl_Quartz_Image_Surface_Driver : public Fl_Image_Surface_Driver { + friend class Fl_Image_Surface; +public: + Fl_Surface_Device *previous; + Window pre_window; + int was_high; + Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res); + ~Fl_Quartz_Image_Surface_Driver(); + void set_current(); + 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) +{ + return new Fl_Quartz_Image_Surface_Driver(w, h, high_res); +} -Fl_Image_Surface::Helper::Helper(int w, int h, int high_res) : Fl_Widget_Surface(NULL), width(w), height(h) { + +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; @@ -48,15 +66,15 @@ Fl_Image_Surface::Helper::Helper(int w, int h, int high_res) : Fl_Widget_Surface CGContextFillRect(offscreen, CGRectMake(0,0,w,h)); } -Fl_Image_Surface::Helper::~Helper() { +Fl_Quartz_Image_Surface_Driver::~Fl_Quartz_Image_Surface_Driver() { if (offscreen) { - void *data = CGBitmapContextGetData((CGContextRef)offscreen); + void *data = CGBitmapContextGetData(offscreen); free(data); CGContextRelease((CGContextRef)offscreen); } } -void Fl_Image_Surface::Helper::set_current() { +void Fl_Quartz_Image_Surface_Driver::set_current() { pre_window = fl_window; if (!previous) previous = Fl_Surface_Device::surface(); driver()->gc(offscreen); @@ -66,34 +84,31 @@ void Fl_Image_Surface::Helper::set_current() { Fl_X::set_high_resolution( CGBitmapContextGetWidth(offscreen) > width ); } -void Fl_Image_Surface::Helper::translate(int x, int y) { - CGContextRef gc = (CGContextRef)driver()->gc(); - CGContextRestoreGState(gc); - CGContextSaveGState(gc); - CGContextTranslateCTM(gc, x, -y); - CGContextSaveGState(gc); - CGContextTranslateCTM(gc, 0, height); - CGContextScaleCTM(gc, 1.0f, -1.0f); +void Fl_Quartz_Image_Surface_Driver::translate(int x, int y) { + CGContextRestoreGState(offscreen); + CGContextSaveGState(offscreen); + CGContextTranslateCTM(offscreen, x, -y); + CGContextSaveGState(offscreen); + CGContextTranslateCTM(offscreen, 0, height); + CGContextScaleCTM(offscreen, 1.0f, -1.0f); } -void Fl_Image_Surface::Helper::untranslate() { - CGContextRestoreGState((CGContextRef)driver()->gc()); +void Fl_Quartz_Image_Surface_Driver::untranslate() { + CGContextRestoreGState(offscreen); } -Fl_RGB_Image* Fl_Image_Surface::Helper::image() +Fl_RGB_Image* Fl_Quartz_Image_Surface_Driver::image() { - unsigned char *data; - int W = width, H = height; CGContextFlush(offscreen); - W = CGBitmapContextGetWidth(offscreen); - H = CGBitmapContextGetHeight(offscreen); - data = fl_read_image(NULL, 0, 0, W, H, 0); + int W = CGBitmapContextGetWidth(offscreen); + int H = CGBitmapContextGetHeight(offscreen); + unsigned char *data = fl_read_image(NULL, 0, 0, W, H, 0); Fl_RGB_Image *image = new Fl_RGB_Image(data, W, H); image->alloc_array = 1; return image; } -void Fl_Image_Surface::Helper::end_current() +void Fl_Quartz_Image_Surface_Driver::end_current() { Fl_X::set_high_resolution(was_high); previous->Fl_Surface_Device::set_current(); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx index d466153cc..4e89df5bd 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx @@ -720,7 +720,7 @@ void Fl_Xlib_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, in surface = new Fl_Image_Surface(img->w(), img->h()); } else if (depth == 4 && fl_can_do_alpha_blending()) { Fl_Offscreen pixmap = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), img->w(), img->h(), 32); - surface = new Fl_Image_Surface(pixmap, img->w(), img->h()); + surface = new Fl_Image_Surface(img->w(), img->h(), 0, pixmap); depth |= FL_IMAGE_WITH_ALPHA; } if (surface) { diff --git a/src/drivers/Xlib/Fl_Xlib_Image_Surface.cxx b/src/drivers/Xlib/Fl_Xlib_Image_Surface.cxx index 2f04259b1..0367a34f0 100644 --- a/src/drivers/Xlib/Fl_Xlib_Image_Surface.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Image_Surface.cxx @@ -20,34 +20,45 @@ #include "../../config_lib.h" - #ifdef FL_CFG_GFX_XLIB #include "Fl_Xlib_Graphics_Driver.H" -#include "Fl_Xlib_Image_Surface.H" +#include <FL/Fl_Image_Surface.H> #include "Fl_Translated_Xlib_Graphics_Driver.H" -Fl_Image_Surface::Helper::Helper(int w, int h, int high_res) : Fl_Widget_Surface(NULL) { - width = w; - height = h; - previous = 0; - fl_open_display(); - offscreen = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, fl_visual->depth); - driver(new Fl_Translated_Xlib_Graphics_Driver()); +class Fl_Xlib_Image_Surface_Driver : public Fl_Image_Surface_Driver { + friend class Fl_Image_Surface; +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); + ~Fl_Xlib_Image_Surface_Driver(); + void set_current(); + 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) +{ + return new Fl_Xlib_Image_Surface_Driver(w, h, high_res, off); } -Fl_Image_Surface::Helper::Helper(Fl_Offscreen pixmap, int w, int h) : Fl_Widget_Surface(NULL) { - width = w; - height = h; +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; - offscreen = pixmap; + if (!off) { + fl_open_display(); + offscreen = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, fl_visual->depth); + } driver(new Fl_Translated_Xlib_Graphics_Driver()); } -Fl_Image_Surface::Helper::~Helper() { +Fl_Xlib_Image_Surface_Driver::~Fl_Xlib_Image_Surface_Driver() { if (offscreen) XFreePixmap(fl_display, offscreen); } -void Fl_Image_Surface::Helper::set_current() { +void Fl_Xlib_Image_Surface_Driver::set_current() { pre_window = fl_window; if (!previous) previous = Fl_Surface_Device::surface(); fl_window = offscreen; @@ -55,25 +66,24 @@ void Fl_Image_Surface::Helper::set_current() { fl_push_no_clip(); } -void Fl_Image_Surface::Helper::translate(int x, int y) { +void Fl_Xlib_Image_Surface_Driver::translate(int x, int y) { ((Fl_Translated_Xlib_Graphics_Driver*)driver())->translate_all(x, y); } -void Fl_Image_Surface::Helper::untranslate() { +void Fl_Xlib_Image_Surface_Driver::untranslate() { ((Fl_Translated_Xlib_Graphics_Driver*)driver())->untranslate_all(); } -Fl_RGB_Image* Fl_Image_Surface::Helper::image() +Fl_RGB_Image* Fl_Xlib_Image_Surface_Driver::image() { - unsigned char *data; - data = fl_read_image(NULL, 0, 0, width, height, 0); + 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_Image_Surface::Helper::end_current() +void Fl_Xlib_Image_Surface_Driver::end_current() { fl_pop_clip(); previous->Fl_Surface_Device::set_current(); |
