(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
This commit is contained in:
parent
f8bd5f3046
commit
8711cf8be9
@ -70,14 +70,12 @@ class FL_EXPORT Fl_Image_Surface : public Fl_Widget_Surface {
|
||||
friend void fl_end_offscreen(void);
|
||||
friend void fl_delete_offscreen(Fl_Offscreen ctx);
|
||||
private:
|
||||
class Helper;
|
||||
Helper *platform_surface;
|
||||
class Fl_Image_Surface_Driver *platform_surface;
|
||||
protected:
|
||||
void translate(int x, int y);
|
||||
void untranslate();
|
||||
public:
|
||||
Fl_Image_Surface(int w, int h, int high_res = 0);
|
||||
Fl_Image_Surface(Fl_Offscreen off, int w, int h);
|
||||
Fl_Image_Surface(int w, int h, int high_res = 0, Fl_Offscreen off = 0);
|
||||
~Fl_Image_Surface();
|
||||
void set_current();
|
||||
void end_current();
|
||||
@ -90,6 +88,24 @@ public:
|
||||
Fl_Offscreen offscreen();
|
||||
};
|
||||
|
||||
|
||||
class Fl_Image_Surface_Driver : public Fl_Widget_Surface {
|
||||
friend class Fl_Image_Surface;
|
||||
protected:
|
||||
int width;
|
||||
int height;
|
||||
Fl_Offscreen offscreen;
|
||||
Fl_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Widget_Surface(NULL), width(w), height(h), offscreen(off) {}
|
||||
virtual ~Fl_Image_Surface_Driver() {}
|
||||
virtual void set_current() {}
|
||||
virtual void translate(int x, int y) {}
|
||||
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() {}
|
||||
static Fl_Image_Surface_Driver *newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen off);
|
||||
};
|
||||
|
||||
#endif // Fl_Image_Surface_H
|
||||
|
||||
//
|
||||
|
@ -17,40 +17,13 @@
|
||||
//
|
||||
|
||||
#include <FL/Fl_Image_Surface.H>
|
||||
#include "config_lib.h"
|
||||
|
||||
|
||||
#ifdef FL_CFG_GFX_QUARTZ
|
||||
#include <src/drivers/Quartz/Fl_Quartz_Image_Surface.H>
|
||||
|
||||
#elif defined(FL_CFG_GFX_GDI)
|
||||
#include <src/drivers/GDI/Fl_GDI_Image_Surface.H>
|
||||
|
||||
#elif defined(USE_SDL)
|
||||
#include <src/drivers/PicoSDL/Fl_PicoSDL_Image_Surface.H>
|
||||
|
||||
#elif defined(FL_PORTING) || defined(USE_SDL)
|
||||
# pragma message "FL_PORTING: implement class Fl_Image_Surface::Helper for your platform"
|
||||
|
||||
class Fl_Image_Surface::Helper : public Fl_Widget_Surface { // class model
|
||||
friend class Fl_Image_Surface;
|
||||
public:
|
||||
Fl_Offscreen offscreen;
|
||||
int width;
|
||||
int height;
|
||||
Helper(int w, int h, int high_res) : Fl_Widget_Surface(NULL), width(w), height(h) {} // to implement
|
||||
~Helper() {} // to implement
|
||||
void set_current(){} // to implement
|
||||
void translate(int x, int y) {} // to implement
|
||||
void untranslate() {} // to implement
|
||||
Fl_RGB_Image *image() {} // to implement
|
||||
void end_current() {} // to implement
|
||||
int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;}
|
||||
};
|
||||
|
||||
#elif defined(FL_CFG_GFX_XLIB)
|
||||
#include <src/drivers/Xlib/Fl_Xlib_Image_Surface.H>
|
||||
|
||||
#if defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: implement class Fl_XXX_Image_Surface_Driver for your platform"
|
||||
Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -60,26 +33,16 @@ public:
|
||||
which is useful to draw it later on a high resolution display (e.g., retina display).
|
||||
This is implemented for the Mac OS platform only.
|
||||
If \p highres is non-zero, use Fl_Image_Surface::highres_image() to get the image data.
|
||||
\param pixmap is used internally by FLTK; applications just use its default value.
|
||||
\version 1.3.4 (1.3.3 without the highres parameter)
|
||||
*/
|
||||
Fl_Image_Surface::Fl_Image_Surface(int w, int h, int high_res) : Fl_Widget_Surface(NULL) {
|
||||
platform_surface = new Helper(w, h, high_res);
|
||||
Fl_Image_Surface::Fl_Image_Surface(int w, int h, int high_res, Fl_Offscreen pixmap) : Fl_Widget_Surface(NULL) {
|
||||
platform_surface = Fl_Image_Surface_Driver::newImageSurfaceDriver(w, h, high_res, pixmap);
|
||||
driver(platform_surface->driver());
|
||||
}
|
||||
|
||||
/** Special constructor that is effective on the Xlib platform only.
|
||||
*/
|
||||
Fl_Image_Surface::Fl_Image_Surface(Fl_Offscreen pixmap, int w, int h) : Fl_Widget_Surface(NULL) {
|
||||
#ifdef FL_CFG_GFX_XLIB
|
||||
platform_surface = new Helper(pixmap, w, h);
|
||||
#else
|
||||
platform_surface = new Helper(w, h, 0);
|
||||
#endif
|
||||
driver(platform_surface->driver());
|
||||
}
|
||||
|
||||
/** The destructor.
|
||||
*/
|
||||
/** The destructor. */
|
||||
Fl_Image_Surface::~Fl_Image_Surface() { delete platform_surface; }
|
||||
|
||||
void Fl_Image_Surface::origin(int x, int y) {platform_surface->origin(x, y);}
|
||||
@ -99,6 +62,7 @@ Fl_Offscreen Fl_Image_Surface::offscreen() {return platform_surface->offscreen;}
|
||||
|
||||
int Fl_Image_Surface::printable_rect(int *w, int *h) {return platform_surface->printable_rect(w, h);}
|
||||
|
||||
|
||||
/** Returns an image made of all drawings sent to the Fl_Image_Surface object.
|
||||
The returned object contains its own copy of the RGB data.
|
||||
The caller is responsible for deleting the image.
|
||||
@ -115,7 +79,7 @@ Fl_Shared_Image* Fl_Image_Surface::highres_image()
|
||||
{
|
||||
Fl_Shared_Image *s_img = Fl_Shared_Image::get(platform_surface->image());
|
||||
int width, height;
|
||||
printable_rect(&width, &height);
|
||||
platform_surface->printable_rect(&width, &height);
|
||||
s_img->scale(width, height);
|
||||
return s_img;
|
||||
}
|
||||
@ -133,7 +97,7 @@ Fl_Offscreen Fl_Image_Surface::get_offscreen_before_delete() {
|
||||
static Fl_Image_Surface **offscreen_api_surface = NULL;
|
||||
static int count_offscreens = 0;
|
||||
|
||||
static int find_slot(void) { // return an available slot to memorize an Fl_Image_Surface::Helper object
|
||||
static int find_slot(void) { // return an available slot to memorize an Fl_Image_Surface object
|
||||
static int max = 0;
|
||||
for (int num = 0; num < count_offscreens; num++) {
|
||||
if (!offscreen_api_surface[num]) return num;
|
||||
|
@ -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::Helper::Helper(int w, int h, int high_res) : Fl_Widget_Surface(NULL), width(w), height(h) {
|
||||
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_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);
|
||||
|
@ -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::Helper::Helper(int w, int h, int high_res) : Fl_Widget_Surface(NULL), width(w), height(h) {
|
||||
|
||||
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_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();
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
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_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;
|
||||
fl_open_display();
|
||||
offscreen = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, fl_visual->depth);
|
||||
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_Offscreen pixmap, int w, int h) : Fl_Widget_Surface(NULL) {
|
||||
width = w;
|
||||
height = h;
|
||||
previous = 0;
|
||||
offscreen = pixmap;
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user