From 53070ba725c4b57b55b4c0aac2661fffeec3ec06 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 17 Mar 2010 13:58:35 +0000 Subject: Deleted class Fl_Gl_Printer that's no longer useful. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7284 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_Device.H | 2 +- FL/Fl_Gl_Printer.H | 6 +-- src/Fl_Gl_Device_Plugin.cxx | 111 +++++++++++++++++++++++++++++++++++++++++++ src/Fl_Gl_Printer.cxx | 113 -------------------------------------------- 4 files changed, 115 insertions(+), 117 deletions(-) create mode 100644 src/Fl_Gl_Device_Plugin.cxx delete mode 100644 src/Fl_Gl_Printer.cxx diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H index b2403f9b1..d4f9bfde1 100644 --- a/FL/Fl_Device.H +++ b/FL/Fl_Device.H @@ -203,7 +203,7 @@ public: }; #endif -/* +/** This plugin socket allows the integration of new device drivers for special window or screen types. It is currently used to provide an automated printing service for OpenGL windows, if linked with fltk_gl. diff --git a/FL/Fl_Gl_Printer.H b/FL/Fl_Gl_Printer.H index 66929c570..4fd3096c8 100644 --- a/FL/Fl_Gl_Printer.H +++ b/FL/Fl_Gl_Printer.H @@ -6,7 +6,7 @@ #include #include -/** +/* * @brief To print Fl_Gl_Window's. * Because Fl_Printer::print_widget() prints only the background of Fl_Gl_Window's, @@ -14,12 +14,12 @@ */ class Fl_Gl_Printer : public Fl_Printer { public: - /** + /* @brief The constructor. */ Fl_Gl_Printer(void) : Fl_Printer() {} - /** + /* @brief Prints an Fl_Gl_Window. * Under MSWindows, take care to move the print dialog window(s) out of the target OpenGL window(s) diff --git a/src/Fl_Gl_Device_Plugin.cxx b/src/Fl_Gl_Device_Plugin.cxx new file mode 100644 index 000000000..23cd84470 --- /dev/null +++ b/src/Fl_Gl_Device_Plugin.cxx @@ -0,0 +1,111 @@ +/* + * Fl_Gl_Device_Plugin.cxx + */ + +#include +#include +#include "Fl_Gl_Choice.H" +#include "FL/Fl.H" +#ifndef __APPLE__ +#include "FL/fl_draw.H" +#endif + +#if defined(__APPLE__) +static void imgProviderReleaseData (void *info, const void *data, size_t size) +{ + free((void *)data); +} +#endif + +static void print_gl_window(Fl_Virtual_Printer *printer, Fl_Gl_Window *glw, int x, int y) +{ +#ifdef WIN32 + HDC save_gc = fl_gc; + const int bytesperpixel = 3; +#elif defined(__APPLE__) + CGContextRef save_gc = fl_gc; + const int bytesperpixel = 4; +#else + _XGC *save_gc = fl_gc; + const int bytesperpixel = 3; +#endif + glw->redraw(); + fl_gc = NULL; + Fl::check(); + glw->make_current(); + // select front buffer as our source for pixel data + glReadBuffer(GL_FRONT); + // Read OpenGL context pixels directly. + // For extra safety, save & restore OpenGL states that are changed + glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); + glPixelStorei(GL_PACK_ALIGNMENT, 4); /* Force 4-byte alignment */ + glPixelStorei(GL_PACK_ROW_LENGTH, 0); + glPixelStorei(GL_PACK_SKIP_ROWS, 0); + glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + // Read a block of pixels from the frame buffer + int mByteWidth = glw->w() * bytesperpixel; + mByteWidth = (mByteWidth + 3) & ~3; // Align to 4 bytes + uchar *baseAddress = (uchar*)malloc(mByteWidth * glw->h()); + glReadPixels(0, 0, glw->w(), glw->h(), +#ifdef WIN32 + GL_RGB, GL_UNSIGNED_BYTE, +#elif defined(__APPLE__) + GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, +#else // FIXME Linux/Unix + GL_RGB, GL_UNSIGNED_BYTE, +#endif + baseAddress); + glPopClientAttrib(); + fl_gc = save_gc; +#if defined(__APPLE__) +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4 +#define kCGBitmapByteOrder32Big 0 +#define CGBitmapInfo CGImageAlphaInfo +#endif + CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB(); + CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, baseAddress, mByteWidth * glw->h(), imgProviderReleaseData); + CGImageRef image = CGImageCreate(glw->w(), glw->h(), 8, 8*bytesperpixel, mByteWidth, cSpace, +#if __BIG_ENDIAN__ + (CGBitmapInfo)(kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big) /* XRGB Big Endian */ +#else + kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little /* XRGB Little Endian */ +#endif + , provider, NULL, false, kCGRenderingIntentDefault); + if(image == NULL) return; + CGContextSaveGState(fl_gc); + int w, h; + printer->printable_rect(&w, &h); + CGContextTranslateCTM(fl_gc, 0, h); + CGContextScaleCTM(fl_gc, 1.0f, -1.0f); + CGRect rect = { { x, h - y - glw->h() }, { glw->w(), glw->h() } }; + Fl_X::q_begin_image(rect, 0, 0, glw->w(), glw->h()); + CGContextDrawImage(fl_gc, rect, image); + Fl_X::q_end_image(); + CGContextRestoreGState(fl_gc); + CGImageRelease(image); + CGColorSpaceRelease(cSpace); + CGDataProviderRelease(provider); +#else + fl_draw_image(baseAddress + (glw->h() - 1) * mByteWidth, x, y , glw->w(), glw->h(), bytesperpixel, - mByteWidth); + free(baseAddress); +#endif // __APPLE__ +} + +/** + This class will make sure that OpenGL printing is available if fltk_gl + was linked to the program. + */ +class Fl_Gl_Device_Plugin : public Fl_Device_Plugin { +public: + Fl_Gl_Device_Plugin() : Fl_Device_Plugin(name()) { } + virtual const char *name() { return "opengl.device.fltk.org"; } + virtual int print(Fl_Virtual_Printer *p, Fl_Widget *w, int x, int y) { + Fl_Gl_Window *glw = w->as_gl_window(); + if (!glw) return 0; + print_gl_window(p, glw, x, y); + return 1; + } +}; + +static Fl_Gl_Device_Plugin Gl_Device_Plugin; + diff --git a/src/Fl_Gl_Printer.cxx b/src/Fl_Gl_Printer.cxx deleted file mode 100644 index 46d8f011f..000000000 --- a/src/Fl_Gl_Printer.cxx +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Fl_Gl_Printer.cxx - */ - -#include "FL/Fl_Gl_Printer.H" -#include "Fl_Gl_Choice.H" -#include "FL/Fl.H" -#ifndef __APPLE__ -#include "FL/fl_draw.H" -#endif - -#if defined(__APPLE__) -static void imgProviderReleaseData (void *info, const void *data, size_t size) -{ - free((void *)data); -} -#endif - -void Fl_Gl_Printer::print_gl_window(Fl_Gl_Window *glw, int x, int y) -{ -#ifdef WIN32 - HDC save_gc = fl_gc; - const int bytesperpixel = 3; -#elif defined(__APPLE__) - CGContextRef save_gc = fl_gc; - const int bytesperpixel = 4; -#else - _XGC *save_gc = fl_gc; - const int bytesperpixel = 3; -#endif - glw->redraw(); - fl_gc = NULL; - Fl::check(); - glw->make_current(); - // select front buffer as our source for pixel data - glReadBuffer(GL_FRONT); - // Read OpenGL context pixels directly. - // For extra safety, save & restore OpenGL states that are changed - glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); - glPixelStorei(GL_PACK_ALIGNMENT, 4); /* Force 4-byte alignment */ - glPixelStorei(GL_PACK_ROW_LENGTH, 0); - glPixelStorei(GL_PACK_SKIP_ROWS, 0); - glPixelStorei(GL_PACK_SKIP_PIXELS, 0); - // Read a block of pixels from the frame buffer - int mByteWidth = glw->w() * bytesperpixel; - mByteWidth = (mByteWidth + 3) & ~3; // Align to 4 bytes - uchar *baseAddress = (uchar*)malloc(mByteWidth * glw->h()); - glReadPixels(0, 0, glw->w(), glw->h(), -#ifdef WIN32 - GL_RGB, GL_UNSIGNED_BYTE, -#elif defined(__APPLE__) - GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, -#else // FIXME Linux/Unix - GL_RGB, GL_UNSIGNED_BYTE, -#endif - baseAddress); - glPopClientAttrib(); - fl_gc = save_gc; -#if defined(__APPLE__) -#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4 -#define kCGBitmapByteOrder32Big 0 -#define CGBitmapInfo CGImageAlphaInfo -#endif - CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB(); - CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, baseAddress, mByteWidth * glw->h(), imgProviderReleaseData); - CGImageRef image = CGImageCreate(glw->w(), glw->h(), 8, 8*bytesperpixel, mByteWidth, cSpace, -#if __BIG_ENDIAN__ - (CGBitmapInfo)(kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big) /* XRGB Big Endian */ -#else - kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little /* XRGB Little Endian */ -#endif - , provider, NULL, false, kCGRenderingIntentDefault); - if(image == NULL) return; - CGContextSaveGState(fl_gc); - int w, h; - this->printable_rect(&w, &h); - CGContextTranslateCTM(fl_gc, 0, h); - CGContextScaleCTM(fl_gc, 1.0f, -1.0f); - CGRect rect = { { x, h - y - glw->h() }, { glw->w(), glw->h() } }; - Fl_X::q_begin_image(rect, 0, 0, glw->w(), glw->h()); - CGContextDrawImage(fl_gc, rect, image); - Fl_X::q_end_image(); - CGContextRestoreGState(fl_gc); - CGImageRelease(image); - CGColorSpaceRelease(cSpace); - CGDataProviderRelease(provider); -#else - fl_draw_image(baseAddress + (glw->h() - 1) * mByteWidth, x, y , glw->w(), glw->h(), bytesperpixel, - mByteWidth); - free(baseAddress); -#endif // __APPLE__ -} - -/* - This class will make sure that OpenGL printing is available if fltk_gl - was linked to the program. - */ -class Fl_Gl_Device_Plugin : public Fl_Device_Plugin { -public: - Fl_Gl_Device_Plugin() : Fl_Device_Plugin(name()) { } - virtual const char *name() { return "opengl.device.fltk.org"; } - virtual int print(Fl_Virtual_Printer *p, Fl_Widget *w, int x, int y) { - Fl_Gl_Window *glw = w->as_gl_window(); - if (!glw) return 0; - // FIXME: this is a dangerous cast! Remove Fl_Gl_Printer entirely and add - // FIXME: a static function (may be a friend of Fl_Printer). - Fl_Gl_Printer *glp = (Fl_Gl_Printer*)p; - glp->print_gl_window(glw, x, y); - return 1; - } -}; - -static Fl_Gl_Device_Plugin Gl_Device_Plugin; - -- cgit v1.2.3