summaryrefslogtreecommitdiff
path: root/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2016-02-09 21:54:38 +0000
committerMatthias Melcher <fltk@matthiasm.com>2016-02-09 21:54:38 +0000
commit94f0278d4771c816f3303efd2e8fa10fc6c41b7a (patch)
treed60ad09f2f45e2d972541fe19a5a7d26bb3a1ddf /src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
parent7a0fe79f99ea90106b035047cb37148b4f3809fc (diff)
Porting efforts, minimal Android stuff, cleanup.
- Moving code around for Fl_Double_Window, but not yet happy - Tested CMake for Android cross compilation. Very happy! git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11142 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx')
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
index f2d68eaa1..a8ed4185e 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
@@ -42,6 +42,118 @@ Fl_Offscreen Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(int w, int h
return (Fl_Offscreen)ctx;
}
+char Fl_Quartz_Graphics_Driver::can_do_alpha_blending() {
+ return 1;
+}
+
+static void bmProviderRelease (void *src, const void *data, size_t size) {
+ CFIndex count = CFGetRetainCount(src);
+ CFRelease(src);
+ if(count == 1) free((void*)data);
+}
+
+void Fl_Quartz_Graphics_Driver::copy_offscreen(int x,int y,int w,int h,Fl_Offscreen osrc,int srcx,int srcy) {
+ CGContextRef src = (CGContextRef)osrc;
+ void *data = CGBitmapContextGetData(src);
+ int sw = CGBitmapContextGetWidth(src);
+ int sh = CGBitmapContextGetHeight(src);
+ CGImageAlphaInfo alpha = CGBitmapContextGetAlphaInfo(src);
+ CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
+ // when output goes to a Quartz printercontext, release of the bitmap must be
+ // delayed after the end of the print page
+ CFRetain(src);
+ CGDataProviderRef src_bytes = CGDataProviderCreateWithData( src, data, sw*sh*4, bmProviderRelease);
+ CGImageRef img = CGImageCreate( sw, sh, 8, 4*8, 4*sw, lut, alpha,
+ src_bytes, 0L, false, kCGRenderingIntentDefault);
+ // fl_push_clip();
+ CGRect rect = CGRectMake(x, y, w, h);
+ Fl_X::q_begin_image(rect, srcx, srcy, sw, sh);
+ CGContextDrawImage(fl_gc, rect, img);
+ Fl_X::q_end_image();
+ CGImageRelease(img);
+ CGColorSpaceRelease(lut);
+ CGDataProviderRelease(src_bytes);
+}
+
+/** \addtogroup fl_drawings
+ @{
+ */
+
+// FIXME: driver system
+/**
+ Creation of an offscreen graphics buffer.
+ \param w,h width and height in pixels of the buffer.
+ \return the created graphics buffer.
+ */
+Fl_Offscreen fl_create_offscreen(int w, int h) {
+ void *data = calloc(w*h,4);
+ CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
+ CGContextRef ctx = CGBitmapContextCreate(
+ data, w, h, 8, w*4, lut, kCGImageAlphaNoneSkipLast);
+ CGColorSpaceRelease(lut);
+ return (Fl_Offscreen)ctx;
+}
+
+// FIXME: driver system
+/** Deletion of an offscreen graphics buffer.
+ \param ctx the buffer to be deleted.
+ */
+void fl_delete_offscreen(Fl_Offscreen ctx) {
+ if (!ctx) return;
+ void *data = CGBitmapContextGetData((CGContextRef)ctx);
+ CFIndex count = CFGetRetainCount(ctx);
+ CGContextRelease((CGContextRef)ctx);
+ if(count == 1) free(data);
+}
+
+// FIXME: driver system
+const int stack_max = 16;
+static int stack_ix = 0;
+static CGContextRef stack_gc[stack_max];
+static Window stack_window[stack_max];
+static Fl_Surface_Device *_ss;
+
+// FIXME: driver system
+/** Send all subsequent drawing commands to this offscreen buffer.
+ \param ctx the offscreen buffer.
+ */
+void fl_begin_offscreen(Fl_Offscreen ctx) {
+ _ss = Fl_Surface_Device::surface();
+ Fl_Display_Device::display_device()->set_current();
+ if (stack_ix<stack_max) {
+ stack_gc[stack_ix] = fl_gc;
+ stack_window[stack_ix] = fl_window;
+ } else
+ fprintf(stderr, "FLTK CGContext Stack overflow error\n");
+ stack_ix++;
+
+ fl_gc = (CGContextRef)ctx;
+ fl_window = 0;
+ CGContextSaveGState(fl_gc);
+ fl_graphics_driver->push_no_clip();
+}
+
+// FIXME: driver system
+/** Quit sending drawing commands to the current offscreen buffer.
+ */
+void fl_end_offscreen() {
+ fl_graphics_driver->pop_clip();
+ CGContextRestoreGState(fl_gc); // matches CGContextSaveGState in fl_begin_offscreen()
+ CGContextFlush(fl_gc);
+ if (stack_ix>0)
+ stack_ix--;
+ else
+ fprintf(stderr, "FLTK CGContext Stack underflow error\n");
+ if (stack_ix<stack_max) {
+ fl_gc = stack_gc[stack_ix];
+ fl_window = stack_window[stack_ix];
+ }
+ _ss->set_current();
+}
+
+/** @} */
+
+
//
// End of "$Id$".