Revision: 4504
http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4504&view=rev
Author: ossman_
Date: 2011-06-17 07:35:56 +0000 (Fri, 17 Jun 2011)
Log Message:
-----------
Implement optimised drawing operations for OS X. Didn't see any reduction in
CPU usage unfortunately, but at least we're now using the native pixel format
of our server which avoids a conversion on the server side.
Modified Paths:
--------------
trunk/vncviewer/CMakeLists.txt
trunk/vncviewer/Viewport.h
Added Paths:
-----------
trunk/vncviewer/OSXPixelBuffer.cxx
trunk/vncviewer/OSXPixelBuffer.h
Modified: trunk/vncviewer/CMakeLists.txt
===================================================================
--- trunk/vncviewer/CMakeLists.txt 2011-06-17 07:33:28 UTC (rev 4503)
+++ trunk/vncviewer/CMakeLists.txt 2011-06-17 07:35:56 UTC (rev 4504)
@@ -23,7 +23,9 @@
if(WIN32)
set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} Win32PixelBuffer.cxx)
-elseif(NOT APPLE)
+elseif(APPLE)
+ set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} OSXPixelBuffer.cxx)
+else()
set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} X11PixelBuffer.cxx)
endif()
Added: trunk/vncviewer/OSXPixelBuffer.cxx
===================================================================
--- trunk/vncviewer/OSXPixelBuffer.cxx (rev 0)
+++ trunk/vncviewer/OSXPixelBuffer.cxx 2011-06-17 07:35:56 UTC (rev 4504)
@@ -0,0 +1,104 @@
+/* Copyright 2011 Pierre Ossman <[email protected]> for Cendio AB
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#include <assert.h>
+
+#include <ApplicationServices/ApplicationServices.h>
+
+#include <FL/Fl_Window.H>
+#include <FL/x.H>
+
+#include <rfb/LogWriter.h>
+#include <rfb/Exception.h>
+
+#include "OSXPixelBuffer.h"
+
+using namespace rfb;
+
+static rfb::LogWriter vlog("PlatformPixelBuffer");
+
+PlatformPixelBuffer::PlatformPixelBuffer(int width, int height) :
+ ManagedPixelBuffer(rfb::PixelFormat(32, 24, false, true,
+ 255, 255, 255, 16, 8, 0),
+ width, height),
+ image(NULL)
+{
+ CGColorSpaceRef lut;
+ CGDataProviderRef provider;
+
+ lut = CGColorSpaceCreateDeviceRGB();
+ assert(lut);
+ provider = CGDataProviderCreateWithData(NULL, data, datasize, NULL);
+ assert(provider);
+
+ image = CGImageCreate(width, height, 8, 32, width*4, lut,
+ kCGImageAlphaNoneSkipFirst |
kCGBitmapByteOrder32Little,
+ provider, NULL, false, kCGRenderingIntentDefault);
+ assert(image);
+
+ CGDataProviderRelease(provider);
+ CGColorSpaceRelease(lut);
+}
+
+
+PlatformPixelBuffer::~PlatformPixelBuffer()
+{
+ CGImageRelease((CGImageRef)image);
+}
+
+
+void PlatformPixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int
h)
+{
+ CGRect rect;
+ CGContextRef gc;
+ CGAffineTransform at;
+
+ gc = (CGContextRef)fl_gc;
+
+ CGContextSaveGState(gc);
+
+ // We have to use clipping to partially display an image
+
+ rect.origin.x = x - 0.5;
+ rect.origin.y = y - 0.5;
+ rect.size.width = w;
+ rect.size.height = h;
+
+ CGContextClipToRect(gc, rect);
+
+ // Oh the hackiness that is OS X image handling...
+ // The CGContextDrawImage() routine magically flips the images and offsets
+ // them by 0.5,0.5 in order to compensate for OS X unfamiliar coordinate
+ // system. But this breaks horribly when you set up the CTM to get the
+ // more familiar top-down system (which FLTK does), meaning we have to
+ // reset the CTM back to the identity matrix and calculate new origin
+ // coordinates.
+
+ at = CGContextGetCTM(gc);
+ CGContextScaleCTM(gc, 1, -1);
+ CGContextTranslateCTM(gc, -at.tx, -at.ty);
+
+ rect.origin.x = x - src_x;
+ rect.origin.y = Fl_Window::current()->h() - (y - src_y);
+ rect.size.width = width();
+ rect.size.height = -height(); // Negative height does _not_ flip the image
+
+ CGContextDrawImage(gc, rect, (CGImageRef)image);
+
+ CGContextRestoreGState(gc);
+}
Added: trunk/vncviewer/OSXPixelBuffer.h
===================================================================
--- trunk/vncviewer/OSXPixelBuffer.h (rev 0)
+++ trunk/vncviewer/OSXPixelBuffer.h 2011-06-17 07:35:56 UTC (rev 4504)
@@ -0,0 +1,37 @@
+/* Copyright 2011 Pierre Ossman <[email protected]> for Cendio AB
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#ifndef __OSXPIXELBUFFER_H__
+#define __OSXPIXELBUFFER_H__
+
+#include <rfb/PixelBuffer.h>
+
+class PlatformPixelBuffer: public rfb::ManagedPixelBuffer {
+public:
+ PlatformPixelBuffer(int width, int height);
+ ~PlatformPixelBuffer();
+
+ void draw(int src_x, int src_y, int x, int y, int w, int h);
+
+protected:
+ // This is really a CGImageRerf, but Apple headers conflict with FLTK
+ void *image;
+};
+
+
+#endif
Modified: trunk/vncviewer/Viewport.h
===================================================================
--- trunk/vncviewer/Viewport.h 2011-06-17 07:33:28 UTC (rev 4503)
+++ trunk/vncviewer/Viewport.h 2011-06-17 07:35:56 UTC (rev 4504)
@@ -36,11 +36,16 @@
#if defined(WIN32)
#include "Win32PixelBuffer.h"
#elif defined(__APPLE__)
-#include "PlatformPixelBuffer.h"
+#include "OSXPixelBuffer.h"
#else
#include "X11PixelBuffer.h"
#endif
+// We also have a generic version of the above, using pure FLTK:
+//
+// #include "PlatformPixelBuffer.h"
+//
+
class CConn;
class Viewport : public Fl_Widget {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Tigervnc-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits