summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/uikit/quikitwindowsurface.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/uikit/quikitwindowsurface.mm')
-rw-r--r--src/plugins/platforms/uikit/quikitwindowsurface.mm196
1 files changed, 25 insertions, 171 deletions
diff --git a/src/plugins/platforms/uikit/quikitwindowsurface.mm b/src/plugins/platforms/uikit/quikitwindowsurface.mm
index 1274fca..bb7dcd7 100644
--- a/src/plugins/platforms/uikit/quikitwindowsurface.mm
+++ b/src/plugins/platforms/uikit/quikitwindowsurface.mm
@@ -42,201 +42,55 @@
#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);
-
- CGDataProviderRelease(cgDataProviderRef);
- CGColorSpaceRelease(cgColourSpaceRef);
-}
-
-- (void)setWidget:(QWidget *)widget
-{
- m_widget = widget;
-}
-
-- (void)drawRect:(CGRect)rect
-{
-
- if (!m_cgImage)
- return;
-
- CGContextRef cgContext = UIGraphicsGetCurrentContext();
- CGContextSaveGState( cgContext );
+#include <QtOpenGL/private/qgl_p.h>
+#include <QtOpenGL/private/qglpaintdevice_p.h>
- 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);
-}
-
-- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-{
- //QWindowSystemInterface::handleTouchEvent(m_widget, (ulong)(event.timestamp*1000),
- // QEvent::TouchBegin, QTouchEvent::TouchScreen,
- // [self touchPointsForTouches:touches]);
- [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
-}
+#include <QtDebug>
-- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+class EAGLPaintDevice : public QGLPaintDevice
{
- //QWindowSystemInterface::handleTouchEvent(m_widget, (ulong)(event.timestamp*1000),
- // QEvent::TouchUpdate, QTouchEvent::TouchScreen,
- // [self touchPointsForTouches:touches]);
- [self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::LeftButton];
-}
+public:
+ EAGLPaintDevice(QPlatformWindow *window)
+ :QGLPaintDevice(), mWindow(window)
+ {
+ }
-- (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];
-}
+ int devType() const { return QInternal::OpenGL; }
+ QSize size() const { return mWindow->geometry().size(); }
+ QGLContext* context() const { return QGLContext::fromPlatformGLContext(mWindow->glContext()); }
-- (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];
-}
+ QPaintEngine *paintEngine() const { return qt_qgl_paint_engine(); }
-@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];
- }
}
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())];
+ widget->platformWindow()->glContext()->swapBuffers();
}
-void QUIKitWindowSurface::resize (const QSize &size)
+QWindowSurface::WindowSurfaceFeatures QUIKitWindowSurface::features() const
{
- 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];
+ return PartialUpdates;
}
QT_END_NAMESPACE