summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorcon <qtc-committer@nokia.com>2011-04-05 08:58:53 (GMT)
committercon <qtc-committer@nokia.com>2011-04-05 09:01:52 (GMT)
commitfc36e189b7654692cdcfcd6098f3c22b15629cb1 (patch)
treefaf7338ac476381445a91e61aaad0c2ba011876d /src
parentf4d1db4ddb2339fdbf9d4c15a4eebcc1c55ad33a (diff)
downloadQt-fc36e189b7654692cdcfcd6098f3c22b15629cb1.zip
Qt-fc36e189b7654692cdcfcd6098f3c22b15629cb1.tar.gz
Qt-fc36e189b7654692cdcfcd6098f3c22b15629cb1.tar.bz2
Use OpenGL backend for proof of concept UIKit lighthouse plugin.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/plugins/platforms/uikit/examples/qmltest/qmltest.xcodeproj/project.pbxproj20
-rw-r--r--src/plugins/platforms/uikit/quikiteventloop.mm4
-rw-r--r--src/plugins/platforms/uikit/quikitwindow.h32
-rw-r--r--src/plugins/platforms/uikit/quikitwindow.mm226
-rw-r--r--src/plugins/platforms/uikit/quikitwindowsurface.h22
-rw-r--r--src/plugins/platforms/uikit/quikitwindowsurface.mm198
-rw-r--r--src/plugins/platforms/uikit/uikit.pro2
7 files changed, 303 insertions, 201 deletions
diff --git a/src/plugins/platforms/uikit/examples/qmltest/qmltest.xcodeproj/project.pbxproj b/src/plugins/platforms/uikit/examples/qmltest/qmltest.xcodeproj/project.pbxproj
index 84f0d3a..10bb20f 100755
--- a/src/plugins/platforms/uikit/examples/qmltest/qmltest.xcodeproj/project.pbxproj
+++ b/src/plugins/platforms/uikit/examples/qmltest/qmltest.xcodeproj/project.pbxproj
@@ -12,6 +12,12 @@
288765A50DF7441C002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765A40DF7441C002DB57D /* CoreGraphics.framework */; };
D316594E1338B29E00760B02 /* libQtXml_debug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D31659431338B21000760B02 /* libQtXml_debug.a */; };
D316594F1338B29E00760B02 /* libQtXmlPatterns_debug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D31659441338B21000760B02 /* libQtXmlPatterns_debug.a */; };
+ D35784241345D8C90046D202 /* libQtOpenGL_debug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D35784231345D8C90046D202 /* libQtOpenGL_debug.a */; };
+ D35784261345D9940046D202 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D35784251345D9940046D202 /* OpenGLES.framework */; };
+ D35784281345D9E00046D202 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D35784271345D9E00046D202 /* QuartzCore.framework */; };
+ D3578436134A09990046D202 /* libQtOpenGL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D3578435134A09990046D202 /* libQtOpenGL.a */; };
+ D3578439134A0AAE0046D202 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D35784251345D9940046D202 /* OpenGLES.framework */; };
+ D357843A134A0AB10046D202 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D35784271345D9E00046D202 /* QuartzCore.framework */; };
D3CAA7C813264AAD008BB877 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = D3CAA7C713264AAD008BB877 /* main.mm */; };
D3CAA7E613264EA6008BB877 /* moc_qmlapplicationviewer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D3CAA7E313264EA6008BB877 /* moc_qmlapplicationviewer.cpp */; };
D3CAA7E713264EA6008BB877 /* qmlapplicationviewer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D3CAA7E413264EA6008BB877 /* qmlapplicationviewer.cpp */; };
@@ -54,6 +60,10 @@
8D1107310486CEB800E47090 /* qmltest-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "qmltest-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
D31659431338B21000760B02 /* libQtXml_debug.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libQtXml_debug.a; path = "../../../../../../../qt-lighthouse-ios-simulator/lib/libQtXml_debug.a"; sourceTree = SOURCE_ROOT; };
D31659441338B21000760B02 /* libQtXmlPatterns_debug.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libQtXmlPatterns_debug.a; path = "../../../../../../../qt-lighthouse-ios-simulator/lib/libQtXmlPatterns_debug.a"; sourceTree = SOURCE_ROOT; };
+ D35784231345D8C90046D202 /* libQtOpenGL_debug.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libQtOpenGL_debug.a; path = "../../../../../../../qt-lighthouse-ios-simulator/lib/libQtOpenGL_debug.a"; sourceTree = "<group>"; };
+ D35784251345D9940046D202 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
+ D35784271345D9E00046D202 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+ D3578435134A09990046D202 /* libQtOpenGL.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libQtOpenGL.a; path = "../../../../../../../qt-lighthouse-ios-device/lib/libQtOpenGL.a"; sourceTree = "<group>"; };
D3CAA7C713264AAD008BB877 /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = "<group>"; };
D3CAA7E313264EA6008BB877 /* moc_qmlapplicationviewer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = moc_qmlapplicationviewer.cpp; path = qmlapplicationviewer/moc_qmlapplicationviewer.cpp; sourceTree = "<group>"; };
D3CAA7E413264EA6008BB877 /* qmlapplicationviewer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = qmlapplicationviewer.cpp; path = qmlapplicationviewer/qmlapplicationviewer.cpp; sourceTree = "<group>"; };
@@ -85,9 +95,11 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ D35784281345D9E00046D202 /* QuartzCore.framework in Frameworks */,
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */,
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
288765A50DF7441C002DB57D /* CoreGraphics.framework in Frameworks */,
+ D35784261345D9940046D202 /* OpenGLES.framework in Frameworks */,
D3CAA7FA13264F8A008BB877 /* libz.1.2.3.dylib in Frameworks */,
D3CAA81B13265056008BB877 /* libQtCore_debug.a in Frameworks */,
D3CAA81C13265056008BB877 /* libQtDeclarative_debug.a in Frameworks */,
@@ -98,6 +110,7 @@
D3CAA82813265220008BB877 /* libQtNetwork_debug.a in Frameworks */,
D316594E1338B29E00760B02 /* libQtXml_debug.a in Frameworks */,
D316594F1338B29E00760B02 /* libQtXmlPatterns_debug.a in Frameworks */,
+ D35784241345D8C90046D202 /* libQtOpenGL_debug.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -105,6 +118,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ D357843A134A0AB10046D202 /* QuartzCore.framework in Frameworks */,
+ D3578439134A0AAE0046D202 /* OpenGLES.framework in Frameworks */,
D3CAA7F013264F52008BB877 /* Foundation.framework in Frameworks */,
D3CAA7F113264F52008BB877 /* UIKit.framework in Frameworks */,
D3CAA7F213264F52008BB877 /* CoreGraphics.framework in Frameworks */,
@@ -118,6 +133,7 @@
D3D817B8132A2CFD00CDE422 /* libQtXml.a in Frameworks */,
D3D817B9132A2CFD00CDE422 /* libQtXmlPatterns.a in Frameworks */,
D3D817BB132A2D0E00CDE422 /* libquikit.a in Frameworks */,
+ D3578436134A09990046D202 /* libQtOpenGL.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -172,6 +188,8 @@
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */,
1D30AB110D05D00D00671497 /* Foundation.framework */,
288765A40DF7441C002DB57D /* CoreGraphics.framework */,
+ D35784251345D9940046D202 /* OpenGLES.framework */,
+ D35784271345D9E00046D202 /* QuartzCore.framework */,
D3CAA7F913264F8A008BB877 /* libz.1.2.3.dylib */,
);
name = Frameworks;
@@ -195,6 +213,7 @@
D3D817AB132A2CFD00CDE422 /* libQtDeclarative.a */,
D3D817AC132A2CFD00CDE422 /* libQtGui.a */,
D3D817AD132A2CFD00CDE422 /* libQtNetwork.a */,
+ D3578435134A09990046D202 /* libQtOpenGL.a */,
D3D817AE132A2CFD00CDE422 /* libQtScript.a */,
D3D817AF132A2CFD00CDE422 /* libQtSql.a */,
D3D817B0132A2CFD00CDE422 /* libQtXml.a */,
@@ -211,6 +230,7 @@
D3CAA81713265056008BB877 /* libQtDeclarative_debug.a */,
D3CAA81813265056008BB877 /* libQtGui_debug.a */,
D3CAA82713265220008BB877 /* libQtNetwork_debug.a */,
+ D35784231345D8C90046D202 /* libQtOpenGL_debug.a */,
D3CAA81913265056008BB877 /* libQtScript_debug.a */,
D3CAA81A13265056008BB877 /* libQtSql_debug.a */,
D31659431338B21000760B02 /* libQtXml_debug.a */,
diff --git a/src/plugins/platforms/uikit/quikiteventloop.mm b/src/plugins/platforms/uikit/quikiteventloop.mm
index 70757b1..d3afd86 100644
--- a/src/plugins/platforms/uikit/quikiteventloop.mm
+++ b/src/plugins/platforms/uikit/quikiteventloop.mm
@@ -78,10 +78,6 @@
}
QUIKitWindow *platformWindow = static_cast<QUIKitWindow *>(widget->platformWindow());
platformWindow->ensureNativeWindow();
- QUIKitWindowSurface *surface = static_cast<QUIKitWindowSurface*>(widget->windowSurface());
- UIView *view = surface->nativeView();
- [platformWindow->nativeWindow() addSubview:view];
- [platformWindow->nativeWindow() makeKeyAndVisible];
}
return YES;
}
diff --git a/src/plugins/platforms/uikit/quikitwindow.h b/src/plugins/platforms/uikit/quikitwindow.h
index d5a6690..f6d2c27 100644
--- a/src/plugins/platforms/uikit/quikitwindow.h
+++ b/src/plugins/platforms/uikit/quikitwindow.h
@@ -43,7 +43,33 @@
#define QUIKITWINDOW_H
#include <QPlatformWindow>
-#include <UIKit/UIKit.h>
+
+#import <UIKit/UIKit.h>
+#import <OpenGLES/ES1/gl.h>
+#import <OpenGLES/ES1/glext.h>
+#import <OpenGLES/EAGL.h>
+
+@interface EAGLView : UIView
+{
+ QPlatformWindow *mWindow;
+ EAGLContext *mContext;
+
+ GLint mFramebufferWidth;
+ GLint mFramebufferHeight;
+
+ GLuint mFramebuffer, mColorRenderbuffer, mDepthRenderbuffer;
+}
+
+- (void)setContext:(EAGLContext *)newContext;
+- (void)presentFramebuffer;
+- (void)deleteFramebuffer;
+- (void)createFramebuffer;
+- (void)makeCurrent;
+- (void)setWindow:(QPlatformWindow *)window;
+- (void)sendMouseEventForTouches:(NSSet *)touches withEvent:(UIEvent *)event fakeButtons:(Qt::MouseButtons)buttons;
+@end
+
+class EAGLPlatformContext;
QT_BEGIN_NAMESPACE
@@ -60,9 +86,13 @@ public:
UIWindow *ensureNativeWindow();
+ QPlatformGLContext *glContext() const;
+
private:
QUIKitScreen *mScreen;
UIWindow *mWindow;
+ EAGLView *mView;
+ mutable EAGLPlatformContext *mContext;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/uikit/quikitwindow.mm b/src/plugins/platforms/uikit/quikitwindow.mm
index ebdee06..aafbfa1 100644
--- a/src/plugins/platforms/uikit/quikitwindow.mm
+++ b/src/plugins/platforms/uikit/quikitwindow.mm
@@ -39,17 +39,221 @@
**
****************************************************************************/
+#import <QuartzCore/CAEAGLLayer.h>
+
#include "quikitwindow.h"
#include "quikitscreen.h"
#include <QtDebug>
+#include <QtGui/QPlatformGLContext>
+#include <QtGui/QWindowSystemInterface>
+
+#include <QtDebug>
+
+class EAGLPlatformContext : public QPlatformGLContext
+{
+public:
+ EAGLPlatformContext(EAGLView *view)
+ : mView(view)
+ {
+ mFormat.setWindowApi(QPlatformWindowFormat::OpenGL);
+ mFormat.setDepthBufferSize(24);
+ mFormat.setAccumBufferSize(0);
+ mFormat.setRedBufferSize(8);
+ mFormat.setGreenBufferSize(8);
+ mFormat.setBlueBufferSize(8);
+ mFormat.setAlphaBufferSize(8);
+ mFormat.setStencilBufferSize(8);
+ mFormat.setSampleBuffers(false);
+ mFormat.setSamples(1);
+// mFormat.setSwapInterval(?)
+ mFormat.setDoubleBuffer(true);
+ mFormat.setDepth(true);
+ mFormat.setRgba(true);
+ mFormat.setAlpha(true);
+ mFormat.setAccum(false);
+ mFormat.setStencil(true);
+ mFormat.setStereo(false);
+ mFormat.setDirectRendering(false);
+ mFormat.setUseDefaultSharedContext(false);
+
+ EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
+ [mView setContext:aContext];
+ }
+
+ ~EAGLPlatformContext() { }
+
+ void makeCurrent()
+ {
+ QPlatformGLContext::makeCurrent();
+ [mView makeCurrent];
+ }
+
+ void doneCurrent()
+ {
+ QPlatformGLContext::doneCurrent();
+ }
+
+ void swapBuffers()
+ {
+ [mView presentFramebuffer];
+ }
+
+ void* getProcAddress(const QString& ) { return 0; }
+
+ QPlatformWindowFormat platformWindowFormat() const
+ {
+ return mFormat;
+ }
+
+private:
+ EAGLView *mView;
+
+ QPlatformWindowFormat mFormat;
+};
+
+@implementation EAGLView
+
++ (Class)layerClass
+{
+ return [CAEAGLLayer class];
+}
+
+- (id)init
+{
+ if ((self = [super init])) {
+ CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
+ eaglLayer.opaque = TRUE;
+ eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking,
+ kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
+ nil];
+ }
+ return self;
+}
+
+- (void)setContext:(EAGLContext *)newContext
+{
+ if (mContext != newContext)
+ {
+ [self deleteFramebuffer];
+ [mContext release];
+ mContext = [newContext retain];
+ [EAGLContext setCurrentContext:nil];
+ }
+}
+
+- (void)presentFramebuffer
+{
+ if (mContext) {
+ [EAGLContext setCurrentContext:mContext];
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, mColorRenderbuffer);
+ [mContext presentRenderbuffer:GL_RENDERBUFFER_OES];
+ }
+}
+
+- (void)deleteFramebuffer
+{
+ if (mContext)
+ {
+ [EAGLContext setCurrentContext:mContext];
+ if (mFramebuffer) {
+ glDeleteFramebuffersOES(1, &mFramebuffer);
+ mFramebuffer = 0;
+ }
+ if (mColorRenderbuffer) {
+ glDeleteRenderbuffersOES(1, &mColorRenderbuffer);
+ mColorRenderbuffer = 0;
+ }
+ if (mDepthRenderbuffer) {
+ glDeleteRenderbuffersOES(1, &mDepthRenderbuffer);
+ mDepthRenderbuffer = 0;
+ }
+ }
+}
+
+- (void)createFramebuffer
+{
+ if (mContext && !mFramebuffer)
+ {
+ [EAGLContext setCurrentContext:mContext];
+ glGenFramebuffersOES(1, &mFramebuffer);
+ glBindFramebufferOES(GL_FRAMEBUFFER_OES, mFramebuffer);
+
+ glGenRenderbuffersOES(1, &mColorRenderbuffer);
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, mColorRenderbuffer);
+ [mContext renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer *)self.layer];
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &mFramebufferWidth);
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &mFramebufferHeight);
+ glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, mColorRenderbuffer);
+
+ glGenRenderbuffersOES(1, &mDepthRenderbuffer);
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, mDepthRenderbuffer);
+ glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH24_STENCIL8_OES, mFramebufferWidth, mFramebufferHeight);
+ glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, mDepthRenderbuffer);
+ glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, mDepthRenderbuffer);
+
+ if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
+ NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
+ }
+}
+
+- (void)makeCurrent
+{
+ if (mContext)
+ {
+ [EAGLContext setCurrentContext:mContext];
+ if (!mFramebuffer)
+ [self createFramebuffer];
+ glBindFramebufferOES(GL_FRAMEBUFFER_OES, mFramebuffer);
+ glViewport(0, 0, mFramebufferWidth, mFramebufferHeight);
+ }
+}
+
+- (void)setWindow:(QPlatformWindow *)window
+{
+ mWindow = window;
+}
+
+- (void)sendMouseEventForTouches:(NSSet *)touches withEvent:(UIEvent *)event fakeButtons:(Qt::MouseButtons)buttons
+{
+ UITouch *touch = [touches anyObject];
+ CGPoint locationInView = [touch locationInView:self];
+ QPoint p(locationInView.x, locationInView.y);
+ // TODO handle global touch point? for status bar?
+ QWindowSystemInterface::handleMouseEvent(mWindow->widget(), (ulong)(event.timestamp*1000),
+ p, p, buttons);
+}
+
+- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
+}
+
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
+}
+
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::NoButton];
+}
+
+- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::NoButton];
+}
+
+@end
QT_BEGIN_NAMESPACE
QUIKitWindow::QUIKitWindow(QWidget *tlw) :
QPlatformWindow(tlw),
- mWindow(nil)
+ mWindow(nil),
+ mContext(0)
{
mScreen = static_cast<QUIKitScreen *>(QPlatformScreen::platformScreenForWidget(tlw));
CGRect screenBounds = [mScreen->uiScreen() bounds];
@@ -60,6 +264,8 @@ QUIKitWindow::QUIKitWindow(QWidget *tlw) :
QUIKitWindow::~QUIKitWindow()
{
+ delete mContext; mContext = 0;
+ [mView release];
[mWindow release];
}
@@ -67,6 +273,8 @@ void QUIKitWindow::setGeometry(const QRect &rect)
{
if (mWindow) {
mWindow.frame = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
+ mView.frame = CGRectMake(0, 0, rect.width(), rect.height());
+ [mView deleteFramebuffer];
[mWindow setNeedsDisplay];
}
QPlatformWindow::setGeometry(rect);
@@ -75,15 +283,31 @@ void QUIKitWindow::setGeometry(const QRect &rect)
UIWindow *QUIKitWindow::ensureNativeWindow()
{
if (!mWindow) {
+ // window
CGRect screenBounds = [mScreen->uiScreen() bounds];
QRect geom = geometry();
CGRect frame = CGRectMake(geom.x(), geom.y(), geom.width(), geom.height());
mWindow = [[UIWindow alloc] initWithFrame:frame];
mWindow.screen = mScreen->uiScreen();
mWindow.frame = frame; // for some reason setting the screen resets frame.origin
+
+ // view
+ mView = [[EAGLView alloc] initWithFrame:CGRectMake(0, 0, geom.width(), geom.height())];
+ [mView setMultipleTouchEnabled:YES];
+ [mView setWindow:this];
+ [mWindow addSubview:mView];
[mWindow setNeedsDisplay];
+ [mWindow makeKeyAndVisible];
}
return mWindow;
}
+QPlatformGLContext *QUIKitWindow::glContext() const
+{
+ if (!mContext) {
+ mContext = new EAGLPlatformContext(mView);
+ }
+ return mContext;
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/uikit/quikitwindowsurface.h b/src/plugins/platforms/uikit/quikitwindowsurface.h
index 81f60f5..58ccb1b 100644
--- a/src/plugins/platforms/uikit/quikitwindowsurface.h
+++ b/src/plugins/platforms/uikit/quikitwindowsurface.h
@@ -43,23 +43,6 @@
#define QUIKITWINDOWSURFACE_H
#include <QtGui/QPlatformIntegration>
-#include <QtGui/QImage>
-#include <QtGui/QWindowSystemInterface>
-
-#include <UIKit/UIKit.h>
-
-@interface QImageView : UIView
-{
- CGImageRef m_cgImage;
- QWidget *m_widget;
-}
-
-- (void)setImage:(QImage *)image;
-- (void)setWidget:(QWidget *)widget;
-
-//- (QList<struct QWindowSystemInterface::TouchPoint>)touchPointsForTouches:(NSSet *)touches;
-- (void)sendMouseEventForTouches:(NSSet *)touches withEvent:(UIEvent *)event fakeButtons:(Qt::MouseButtons)buttons;
-@end
QT_BEGIN_NAMESPACE
@@ -70,12 +53,9 @@ public:
QPaintDevice *paintDevice();
void flush(QWidget *widget, const QRegion &region, const QPoint &offset);
- void resize (const QSize &size);
- UIView *nativeView() const { return mView; }
private:
- QImage *mImage;
- QImageView *mView;
+ QPaintDevice *mPaintDevice;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/uikit/quikitwindowsurface.mm b/src/plugins/platforms/uikit/quikitwindowsurface.mm
index 1274fca..dd188fb 100644
--- a/src/plugins/platforms/uikit/quikitwindowsurface.mm
+++ b/src/plugins/platforms/uikit/quikitwindowsurface.mm
@@ -42,201 +42,51 @@
#include "quikitwindowsurface.h"
#include "quikitwindow.h"
-#include <QtDebug>
-
-@implementation QImageView
-
-- (void)dealloc
-{
- CGImageRelease(m_cgImage);
- [super dealloc];
-}
-
-- (void)setImage:(QImage *)image
-{
- CGImageRelease(m_cgImage);
-
- const uchar *imageData = image->bits();
- int bitDepth = image->depth();
- int colorBufferSize = 8;
- int bytesPrLine = image->bytesPerLine();
- int width = image->width();
- int height = image->height();
-
- CGColorSpaceRef cgColourSpaceRef = CGColorSpaceCreateDeviceRGB();
-
- CGDataProviderRef cgDataProviderRef = CGDataProviderCreateWithData(
- NULL,
- imageData,
- image->byteCount(),
- NULL);
-
- m_cgImage = CGImageCreate(width,
- height,
- colorBufferSize,
- bitDepth,
- bytesPrLine,
- cgColourSpaceRef,
- kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little,
- cgDataProviderRef,
- NULL,
- false,
- kCGRenderingIntentDefault);
+#include <QtOpenGL/private/qgl_p.h>
+#include <QtOpenGL/private/qglpaintdevice_p.h>
- CGDataProviderRelease(cgDataProviderRef);
- CGColorSpaceRelease(cgColourSpaceRef);
-}
-
-- (void)setWidget:(QWidget *)widget
-{
- m_widget = widget;
-}
-
-- (void)drawRect:(CGRect)rect
-{
-
- if (!m_cgImage)
- return;
-
- CGContextRef cgContext = UIGraphicsGetCurrentContext();
- CGContextSaveGState( cgContext );
-
- int dy = rect.origin.y + CGRectGetMaxY(rect);
- CGContextTranslateCTM(cgContext, 0, dy);
- CGContextScaleCTM(cgContext, 1, -1);
- CGImageRef subImage = CGImageCreateWithImageInRect(m_cgImage, rect);
- CGContextDrawImage(cgContext,rect,subImage);
- CGImageRelease(subImage);
-
- CGContextRestoreGState(cgContext);
-}
-
-//- (QList<struct QWindowSystemInterface::TouchPoint>)touchPointsForTouches:(NSSet *)touches
-//{
-// NSEnumerator *enumerator = [touches objectEnumerator];
-// id touch;
-// int count = 0;
-// QList<struct QWindowSystemInterface::TouchPoint> result;
-// while ((touch = [enumerator nextObject])) {
-// CGPoint locationInView = [touch locationInView:self];
-// CGRect bounds = [self bounds];
-// struct QWindowSystemInterface::TouchPoint p;
-// p.id = count;
-// p.isPrimary = true;
-// p.normalPosition = QPointF(locationInView.x / bounds.size.width,
-// locationInView.y / bounds.size.height);
-// p.area = QRectF(locationInView.x, locationInView.y, 1, 1);
-// p.pressure = 1.;
-// switch ([touch phase]) {
-// case UITouchPhaseBegan:
-// p.state = Qt::TouchPointPressed;
-// break;
-// case UITouchPhaseMoved:
-// p.state = Qt::TouchPointMoved;
-// break;
-// case UITouchPhaseStationary:
-// p.state = Qt::TouchPointStationary;
-// break;
-// case UITouchPhaseEnded:
-// case UITouchPhaseCancelled:
-// p.state = Qt::TouchPointReleased;
-// break;
-// }
-// result << p;
-// qDebug() << p.id << ":" << p.normalPosition << p.area << p.state;
-// ++count;
-// }
-// qDebug() << result.size();
-// return result;
-//}
-
-- (void)sendMouseEventForTouches:(NSSet *)touches withEvent:(UIEvent *)event fakeButtons:(Qt::MouseButtons)buttons
-{
- UITouch *touch = [touches anyObject];
- CGPoint locationInView = [touch locationInView:self];
- QPoint p(locationInView.x, locationInView.y);
- // TODO handle global touch point? for status bar?
- QWindowSystemInterface::handleMouseEvent(m_widget, (ulong)(event.timestamp*1000),
- p, p, buttons);
-}
+#include <QtDebug>
-- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+class EAGLPaintDevice : public QGLPaintDevice
{
- //QWindowSystemInterface::handleTouchEvent(m_widget, (ulong)(event.timestamp*1000),
- // QEvent::TouchBegin, QTouchEvent::TouchScreen,
- // [self touchPointsForTouches:touches]);
- [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
-}
+public:
+ EAGLPaintDevice(QPlatformWindow *window)
+ :QGLPaintDevice(), mWindow(window)
+ {
+ }
-- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
-{
- //QWindowSystemInterface::handleTouchEvent(m_widget, (ulong)(event.timestamp*1000),
- // QEvent::TouchUpdate, QTouchEvent::TouchScreen,
- // [self touchPointsForTouches:touches]);
- [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
-}
+ int devType() const { return QInternal::OpenGL; }
+ QSize size() const { return mWindow->geometry().size(); }
+ QGLContext* context() const { return QGLContext::fromPlatformGLContext(mWindow->glContext()); }
-- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
-{
- //QWindowSystemInterface::handleTouchEvent(m_widget, (ulong)(event.timestamp*1000),
- // QEvent::TouchEnd, QTouchEvent::TouchScreen,
- // [self touchPointsForTouches:touches]);
- [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::NoButton];
-}
+ QPaintEngine *paintEngine() const { return qt_qgl_paint_engine(); }
-- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
-{
- //QWindowSystemInterface::handleTouchEvent(m_widget, (ulong)(event.timestamp*1000),
- // QEvent::TouchEnd, QTouchEvent::TouchScreen,
- // [self touchPointsForTouches:touches]);
- [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::NoButton];
-}
-
-@end
+ void beginPaint(){
+ QGLPaintDevice::beginPaint();
+ }
+private:
+ QPlatformWindow *mWindow;
+};
QT_BEGIN_NAMESPACE
QUIKitWindowSurface::QUIKitWindowSurface(QWidget *window)
- : QWindowSurface(window)
+ : QWindowSurface(window), mPaintDevice(new EAGLPaintDevice(window->platformWindow()))
{
- QUIKitWindow *platformWindow = static_cast<QUIKitWindow *>(window->platformWindow());
- Q_ASSERT(platformWindow);
- const QRect geo = window->geometry();
- mView = [[QImageView alloc] initWithFrame:CGRectMake(geo.x(),geo.y(),geo.width(),geo.height())];
- [mView setMultipleTouchEnabled:YES];
- [mView setWidget:window];
- mImage = new QImage(window->size(),QImage::Format_ARGB32_Premultiplied);
- [mView setImage:mImage];
- if (platformWindow->nativeWindow()) {
- [platformWindow->nativeWindow() addSubview:mView];
- [mView setNeedsDisplay];
- }
+ setPartialUpdateSupport(false);
}
QPaintDevice *QUIKitWindowSurface::paintDevice()
{
- return mImage;
+ return mPaintDevice;
}
void QUIKitWindowSurface::flush(QWidget *widget, const QRegion &region, const QPoint &offset)
{
Q_UNUSED(widget);
+ Q_UNUSED(region);
Q_UNUSED(offset);
-
- QRect geo = region.boundingRect();
- [mView setNeedsDisplayInRect:CGRectMake(geo.x(),geo.y(),geo.width(),geo.height())];
-}
-
-void QUIKitWindowSurface::resize (const QSize &size)
-{
- QWindowSurface::resize(size);
-
- delete mImage;
- mImage = new QImage(size,QImage::Format_ARGB32_Premultiplied);
- [mView setImage:mImage];
- const QRect geo = geometry();
- [mView setFrame:CGRectMake(geo.x(), geo.y(), size.width(), size.height())];
- [mView setNeedsDisplay];
+ widget->platformWindow()->glContext()->swapBuffers();
}
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/uikit/uikit.pro b/src/plugins/platforms/uikit/uikit.pro
index b73c334..1589ee9 100644
--- a/src/plugins/platforms/uikit/uikit.pro
+++ b/src/plugins/platforms/uikit/uikit.pro
@@ -2,6 +2,8 @@ TARGET = quikit
include(../../qpluginbase.pri)
QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms
+QT += opengl
+
OBJECTIVE_SOURCES = main.mm \
quikitintegration.mm \
quikitwindow.mm \