iOS: Implement QPlatformOpenGLContext
The iOS platform GL context is an EAGLContext, which is wrapped by the new class QIOSContext. The class takes care of makeCurrent() and swapBuffers(), but defers framebuffer management to the corresponding QIOSWindow. At the moment only a single framebuffer is created, and changing the geometry of the QWindow does not trigger any sort of invalidation of the buffers. The implementation assumes OpenGL ES2.x support. Though strictly speaking we could support ES1 for QtGui, it serves little purpose as Qt Quick 2 requires ES2. This patch also disabled touch event synthesization until we have figured out where we will maintain the connection to UIWindow. QPlatformOpenGLContext::getProcAddress() for getting extensions is implemented by using dlsym() to look up the symbol. This should not present any issues for App Store deployment, like dlopen() would. Change-Id: I166f800f3ecc0d180133c590465371ac1642b0ec Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
This commit is contained in:
parent
ac8d906a3a
commit
3c4f48f9e2
@ -13,14 +13,16 @@ OBJECTIVE_SOURCES = main.mm \
|
||||
qiosscreen.mm \
|
||||
qioseventdispatcher.mm \
|
||||
qiosbackingstore.mm \
|
||||
qiosapplicationdelegate.mm
|
||||
qiosapplicationdelegate.mm \
|
||||
qioscontext.mm
|
||||
|
||||
HEADERS = qiosintegration.h \
|
||||
qioswindow.h \
|
||||
qiosscreen.h \
|
||||
qioseventdispatcher.h \
|
||||
qiosbackingstore.h \
|
||||
qiosapplicationdelegate.h
|
||||
qiosapplicationdelegate.h \
|
||||
qioscontext.h
|
||||
|
||||
#HEADERS = qiossoftwareinputhandler.h
|
||||
|
||||
|
@ -133,6 +133,7 @@ void QIOSBackingStore::resize(const QSize &size, const QRegion &staticContents)
|
||||
{
|
||||
Q_UNUSED(size);
|
||||
Q_UNUSED(staticContents);
|
||||
|
||||
qDebug() << __FUNCTION__ << "not implemented";
|
||||
}
|
||||
|
||||
|
76
src/plugins/platforms/ios/qioscontext.h
Normal file
76
src/plugins/platforms/ios/qioscontext.h
Normal file
@ -0,0 +1,76 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QIOSCONTEXT_H
|
||||
#define QIOSCONTEXT_H
|
||||
|
||||
#include <qpa/qplatformopenglcontext.h>
|
||||
|
||||
@class EAGLContext;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QIOSContext : public QPlatformOpenGLContext
|
||||
{
|
||||
public:
|
||||
QIOSContext(QOpenGLContext *context);
|
||||
~QIOSContext();
|
||||
|
||||
QSurfaceFormat format() const;
|
||||
|
||||
void swapBuffers(QPlatformSurface *surface);
|
||||
|
||||
bool makeCurrent(QPlatformSurface *surface);
|
||||
void doneCurrent();
|
||||
|
||||
GLuint defaultFramebufferObject(QPlatformSurface *) const;
|
||||
QFunctionPointer getProcAddress(const QByteArray &procName);
|
||||
|
||||
EAGLContext *nativeContext() const;
|
||||
|
||||
private:
|
||||
EAGLContext *m_eaglContext;
|
||||
QSurfaceFormat m_format;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QIOSCONTEXT_H
|
124
src/plugins/platforms/ios/qioscontext.mm
Normal file
124
src/plugins/platforms/ios/qioscontext.mm
Normal file
@ -0,0 +1,124 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qioscontext.h"
|
||||
#include "qioswindow.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <QtGui/QOpenGlContext>
|
||||
|
||||
#import <OpenGLES/EAGL.h>
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
|
||||
QIOSContext::QIOSContext(QOpenGLContext *context)
|
||||
: QPlatformOpenGLContext()
|
||||
, m_eaglContext([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2])
|
||||
{
|
||||
// Start out with the requested format
|
||||
QSurfaceFormat format = context->format();
|
||||
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
format.setMajorVersion(2);
|
||||
format.setMinorVersion(0);
|
||||
|
||||
// Even though iOS internally double-buffers its rendering, we
|
||||
// report single-buffered here since the buffer remains unchanged
|
||||
// when swapping unlesss you manually clear it yourself.
|
||||
format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
|
||||
|
||||
m_format = format;
|
||||
}
|
||||
|
||||
QIOSContext::~QIOSContext()
|
||||
{
|
||||
[m_eaglContext release];
|
||||
}
|
||||
|
||||
QSurfaceFormat QIOSContext::format() const
|
||||
{
|
||||
return m_format;
|
||||
}
|
||||
|
||||
bool QIOSContext::makeCurrent(QPlatformSurface *surface)
|
||||
{
|
||||
Q_ASSERT(surface && surface->surface()->surfaceType() == QSurface::OpenGLSurface);
|
||||
|
||||
[EAGLContext setCurrentContext:m_eaglContext];
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject(surface));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QIOSContext::doneCurrent()
|
||||
{
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
}
|
||||
|
||||
void QIOSContext::swapBuffers(QPlatformSurface *surface)
|
||||
{
|
||||
Q_ASSERT(surface && surface->surface()->surfaceType() == QSurface::OpenGLSurface);
|
||||
|
||||
[EAGLContext setCurrentContext:m_eaglContext];
|
||||
|
||||
GLint renderbuffer;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject(surface));
|
||||
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &renderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
||||
|
||||
[m_eaglContext presentRenderbuffer:GL_RENDERBUFFER];
|
||||
}
|
||||
|
||||
GLuint QIOSContext::defaultFramebufferObject(QPlatformSurface *surface) const
|
||||
{
|
||||
return static_cast<QIOSWindow *>(surface)->framebufferObject(*const_cast<const QIOSContext*>(this));
|
||||
}
|
||||
|
||||
QFunctionPointer QIOSContext::getProcAddress(const QByteArray& functionName)
|
||||
{
|
||||
return reinterpret_cast<QFunctionPointer>(dlsym(RTLD_NEXT, functionName.constData()));
|
||||
}
|
||||
|
||||
EAGLContext *QIOSContext::nativeContext() const
|
||||
{
|
||||
return m_eaglContext;
|
||||
}
|
@ -57,6 +57,8 @@ public:
|
||||
QPlatformWindow *createPlatformWindow(QWindow *window) const;
|
||||
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
|
||||
|
||||
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;
|
||||
|
||||
QPlatformFontDatabase *fontDatabase() const;
|
||||
|
||||
QAbstractEventDispatcher *guiThreadEventDispatcher() const;
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "qiosbackingstore.h"
|
||||
#include "qiosscreen.h"
|
||||
#include "qioseventdispatcher.h"
|
||||
#include "qioscontext.h"
|
||||
|
||||
#include <QtPlatformSupport/private/qcoretextfontdatabase_p.h>
|
||||
|
||||
@ -65,21 +66,31 @@ QIOSIntegration::~QIOSIntegration()
|
||||
QPlatformPixmap *QIOSIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
|
||||
{
|
||||
Q_UNUSED(type);
|
||||
|
||||
qDebug() << __FUNCTION__ << "not yet implemented";
|
||||
return 0;
|
||||
//return new QRasterPixmapData(type);
|
||||
}
|
||||
|
||||
QPlatformWindow *QIOSIntegration::createPlatformWindow(QWindow *window) const
|
||||
{
|
||||
qDebug() << __FUNCTION__ << "Creating platform window";
|
||||
return new QIOSWindow(window);
|
||||
}
|
||||
|
||||
QPlatformBackingStore *QIOSIntegration::createPlatformBackingStore(QWindow *window) const
|
||||
{
|
||||
qDebug() << __FUNCTION__ << "Creating platform backingstore";
|
||||
return new QIOSBackingStore(window);
|
||||
}
|
||||
|
||||
// Used when the QWindow's surface type is set by the client to QSurface::OpenGLSurface
|
||||
QPlatformOpenGLContext *QIOSIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
qDebug() << __FUNCTION__ << "Creating platform opengl context";
|
||||
return new QIOSContext(context);
|
||||
}
|
||||
|
||||
QAbstractEventDispatcher *QIOSIntegration::guiThreadEventDispatcher() const
|
||||
{
|
||||
return new QIOSEventDispatcher();
|
||||
|
@ -1,38 +1,38 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
@ -45,24 +45,11 @@
|
||||
#include <qpa/qplatformwindow.h>
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
#import <OpenGLES/ES1/glext.h>
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
#import <OpenGLES/EAGL.h>
|
||||
|
||||
class QIOSContext;
|
||||
|
||||
@interface EAGLView : UIView <UIKeyInput>
|
||||
{
|
||||
QPlatformWindow *m_window;
|
||||
EAGLContext *m_context;
|
||||
|
||||
GLint m_framebufferWidth;
|
||||
GLint m_framebufferHeight;
|
||||
|
||||
GLuint m_framebuffer, m_colorRenderbuffer, m_depthRenderbuffer;
|
||||
|
||||
id delegate;
|
||||
// ------- Text Input ----------
|
||||
UITextAutocapitalizationType autocapitalizationType;
|
||||
UITextAutocorrectionType autocorrectionType;
|
||||
BOOL enablesReturnKeyAutomatically;
|
||||
@ -72,19 +59,8 @@
|
||||
BOOL secureTextEntry;
|
||||
}
|
||||
|
||||
- (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;
|
||||
|
||||
@property (readonly,getter=fbo) GLint fbo;
|
||||
@property (nonatomic, assign) id delegate;
|
||||
|
||||
// ------- Text Input ----------
|
||||
|
||||
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
|
||||
@property(nonatomic) UITextAutocorrectionType autocorrectionType;
|
||||
@property(nonatomic) BOOL enablesReturnKeyAutomatically;
|
||||
@ -95,39 +71,22 @@
|
||||
|
||||
@end
|
||||
|
||||
@protocol EAGLViewDelegate
|
||||
- (void)eaglView:(EAGLView *)view usesFramebuffer:(GLuint)buffer;
|
||||
@end
|
||||
|
||||
class EAGLPlatformContext;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QIOSScreen;
|
||||
|
||||
class QIOSWindow : public QPlatformWindow
|
||||
{
|
||||
public:
|
||||
explicit QIOSWindow(QWindow *window);
|
||||
~QIOSWindow();
|
||||
|
||||
UIWindow *nativeWindow() const { return m_window; }
|
||||
EAGLView *nativeView() const { return m_view; }
|
||||
void setGeometry(const QRect &rect);
|
||||
|
||||
UIWindow *ensureNativeWindow();
|
||||
GLuint framebufferObject(const QIOSContext &context) const;
|
||||
|
||||
QPlatformOpenGLContext *glContext() const;
|
||||
EAGLView *nativeView() const { return m_view; }
|
||||
|
||||
QIOSScreen *platformScreen() const { return m_screen; }
|
||||
|
||||
void updateGeometryAndOrientation();
|
||||
private:
|
||||
QIOSScreen *m_screen;
|
||||
UIWindow *m_window;
|
||||
CGRect m_frame;
|
||||
EAGLView *m_view;
|
||||
mutable EAGLPlatformContext *m_context;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -1,152 +1,57 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
|
||||
#include "qioswindow.h"
|
||||
|
||||
#include "qioscontext.h"
|
||||
#include "qiosscreen.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <qpa/qplatformopenglcontext.h>
|
||||
#include <qpa/qwindowsysteminterface.h>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
static GLint stencilBits()
|
||||
{
|
||||
static GLint bits;
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
glGetIntegerv(GL_STENCIL_BITS, &bits);
|
||||
initialized = true;
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
/*
|
||||
static GLint depthBits()
|
||||
{
|
||||
// we can choose between GL_DEPTH24_STENCIL8_OES and GL_DEPTH_COMPONENT16
|
||||
return stencilBits() > 0 ? 24 : 16;
|
||||
}
|
||||
*/
|
||||
|
||||
class EAGLPlatformContext : public QPlatformOpenGLContext
|
||||
{
|
||||
public:
|
||||
EAGLPlatformContext(EAGLView *view)
|
||||
: m_view(view)
|
||||
{
|
||||
/*
|
||||
mFormat.setWindowApi(QPlatformWindowFormat::OpenGL);
|
||||
mFormat.setDepthBufferSize(depthBits());
|
||||
mFormat.setAccumBufferSize(0);
|
||||
mFormat.setRedBufferSize(8);
|
||||
mFormat.setGreenBufferSize(8);
|
||||
mFormat.setBlueBufferSize(8);
|
||||
mFormat.setAlphaBufferSize(8);
|
||||
mFormat.setStencilBufferSize(stencilBits());
|
||||
mFormat.setSamples(0);
|
||||
mFormat.setSampleBuffers(false);
|
||||
mFormat.setDoubleBuffer(true);
|
||||
mFormat.setDepth(true);
|
||||
mFormat.setRgba(true);
|
||||
mFormat.setAlpha(true);
|
||||
mFormat.setAccum(false);
|
||||
mFormat.setStencil(stencilBits() > 0);
|
||||
mFormat.setStereo(false);
|
||||
mFormat.setDirectRendering(false);
|
||||
*/
|
||||
|
||||
#if defined(QT_OPENGL_ES_2)
|
||||
EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
#else
|
||||
EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
|
||||
#endif
|
||||
[m_view setContext:aContext];
|
||||
}
|
||||
|
||||
~EAGLPlatformContext() { }
|
||||
|
||||
bool makeCurrent(QPlatformSurface *surface)
|
||||
{
|
||||
Q_UNUSED(surface);
|
||||
qDebug() << __FUNCTION__ << "not implemented";
|
||||
//QPlatformOpenGLContext::makeCurrent();
|
||||
//[m_view makeCurrent];
|
||||
return false;
|
||||
}
|
||||
|
||||
void doneCurrent()
|
||||
{
|
||||
qDebug() << __FUNCTION__ << "not implemented";
|
||||
//QPlatformOpenGLContext::doneCurrent();
|
||||
}
|
||||
|
||||
void swapBuffers(QPlatformSurface *surface)
|
||||
{
|
||||
Q_UNUSED(surface);
|
||||
qDebug() << __FUNCTION__ << "not implemented";
|
||||
//[m_view presentFramebuffer];
|
||||
}
|
||||
|
||||
QFunctionPointer getProcAddress(const QByteArray& ) { return 0; }
|
||||
|
||||
QSurfaceFormat format() const
|
||||
{
|
||||
return mFormat;
|
||||
}
|
||||
|
||||
private:
|
||||
EAGLView *m_view;
|
||||
|
||||
QSurfaceFormat mFormat;
|
||||
};
|
||||
|
||||
@implementation EAGLView
|
||||
|
||||
@synthesize delegate;
|
||||
|
||||
+ (Class)layerClass
|
||||
{
|
||||
return [CAEAGLLayer class];
|
||||
@ -155,12 +60,14 @@ private:
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if ((self = [super initWithFrame:frame])) {
|
||||
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
||||
// Set up EAGL layer
|
||||
CAEAGLLayer *eaglLayer = static_cast<CAEAGLLayer *>(self.layer);
|
||||
eaglLayer.opaque = TRUE;
|
||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking,
|
||||
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
|
||||
nil];
|
||||
[NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking,
|
||||
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
|
||||
|
||||
// Set up text input
|
||||
autocapitalizationType = UITextAutocapitalizationTypeNone;
|
||||
autocorrectionType = UITextAutocorrectionTypeNo;
|
||||
enablesReturnKeyAutomatically = NO;
|
||||
@ -169,113 +76,28 @@ private:
|
||||
returnKeyType = UIReturnKeyDone;
|
||||
secureTextEntry = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setContext:(EAGLContext *)newContext
|
||||
{
|
||||
if (m_context != newContext)
|
||||
{
|
||||
[self deleteFramebuffer];
|
||||
[m_context release];
|
||||
m_context = [newContext retain];
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)presentFramebuffer
|
||||
{
|
||||
if (m_context) {
|
||||
[EAGLContext setCurrentContext:m_context];
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_colorRenderbuffer);
|
||||
[m_context presentRenderbuffer:GL_RENDERBUFFER];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deleteFramebuffer
|
||||
{
|
||||
if (m_context)
|
||||
{
|
||||
[EAGLContext setCurrentContext:m_context];
|
||||
if (m_framebuffer) {
|
||||
glDeleteFramebuffers(1, &m_framebuffer);
|
||||
m_framebuffer = 0;
|
||||
}
|
||||
if (m_colorRenderbuffer) {
|
||||
glDeleteRenderbuffers(1, &m_colorRenderbuffer);
|
||||
m_colorRenderbuffer = 0;
|
||||
}
|
||||
if (m_depthRenderbuffer) {
|
||||
glDeleteRenderbuffers(1, &m_depthRenderbuffer);
|
||||
m_depthRenderbuffer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)createFramebuffer
|
||||
{
|
||||
if (m_context && !m_framebuffer)
|
||||
{
|
||||
[EAGLContext setCurrentContext:m_context];
|
||||
glGenFramebuffers(1, &m_framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
|
||||
|
||||
glGenRenderbuffers(1, &m_colorRenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_colorRenderbuffer);
|
||||
[m_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &m_framebufferWidth);
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &m_framebufferHeight);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRenderbuffer);
|
||||
|
||||
glGenRenderbuffers(1, &m_depthRenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_depthRenderbuffer);
|
||||
if (stencilBits() > 0) {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, m_framebufferWidth, m_framebufferHeight);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthRenderbuffer);
|
||||
} else {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_framebufferWidth, m_framebufferHeight);
|
||||
}
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRenderbuffer);
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
||||
if (delegate && [delegate respondsToSelector:@selector(eaglView:usesFramebuffer:)]) {
|
||||
[delegate eaglView:self usesFramebuffer:m_framebuffer];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)makeCurrent
|
||||
{
|
||||
if (m_context)
|
||||
{
|
||||
[EAGLContext setCurrentContext:m_context];
|
||||
if (!m_framebuffer)
|
||||
[self createFramebuffer];
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
|
||||
glViewport(0, 0, m_framebufferWidth, m_framebufferHeight);
|
||||
}
|
||||
}
|
||||
|
||||
- (GLint)fbo
|
||||
{
|
||||
return m_framebuffer;
|
||||
}
|
||||
|
||||
- (void)setWindow:(QPlatformWindow *)window
|
||||
{
|
||||
m_window = window;
|
||||
}
|
||||
|
||||
- (void)sendMouseEventForTouches:(NSSet *)touches withEvent:(UIEvent *)event fakeButtons:(Qt::MouseButtons)buttons
|
||||
{
|
||||
Q_UNUSED(touches);
|
||||
Q_UNUSED(event);
|
||||
Q_UNUSED(buttons);
|
||||
|
||||
// FIXME: Reintroduce relation to UIWindow
|
||||
qDebug() << __FUNCTION__ << "not implemented";
|
||||
|
||||
#if 0
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint locationInView = [touch locationInView:self];
|
||||
CGFloat scaleFactor = [self contentScaleFactor];
|
||||
QPoint p(locationInView.x * scaleFactor, locationInView.y * scaleFactor);
|
||||
|
||||
// TODO handle global touch point? for status bar?
|
||||
QWindowSystemInterface::handleMouseEvent(m_window->window(), (ulong)(event.timestamp*1000),
|
||||
p, p, buttons);
|
||||
QWindowSystemInterface::handleMouseEvent(m_window->window(), (ulong)(event.timestamp*1000), p, p, buttons);
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
@ -298,8 +120,6 @@ private:
|
||||
[self sendMouseEventForTouches:touches withEvent:event fakeButtons:Qt::NoButton];
|
||||
}
|
||||
|
||||
// ------- Text Input ----------
|
||||
|
||||
@synthesize autocapitalizationType;
|
||||
@synthesize autocorrectionType;
|
||||
@synthesize enablesReturnKeyAutomatically;
|
||||
@ -343,107 +163,79 @@ private:
|
||||
|
||||
@end
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QIOSWindow::QIOSWindow(QWindow *window) :
|
||||
QPlatformWindow(window),
|
||||
m_window(nil),
|
||||
m_context(0)
|
||||
QIOSWindow::QIOSWindow(QWindow *window)
|
||||
: QPlatformWindow(window)
|
||||
, m_view([[EAGLView alloc] init])
|
||||
{
|
||||
m_screen = static_cast<QIOSScreen *>(QPlatformScreen::platformScreenForWindow(window));
|
||||
m_view = [[EAGLView alloc] init];
|
||||
}
|
||||
|
||||
QIOSWindow::~QIOSWindow()
|
||||
{
|
||||
delete m_context; m_context = 0;
|
||||
[m_view release];
|
||||
[m_window release];
|
||||
}
|
||||
|
||||
void QIOSWindow::setGeometry(const QRect &rect)
|
||||
{
|
||||
// Not supported. Only a single "full screen" window is supported
|
||||
QPlatformWindow::setGeometry(rect);
|
||||
|
||||
qDebug() << __FUNCTION__ << "not implemented";
|
||||
}
|
||||
|
||||
UIWindow *QIOSWindow::ensureNativeWindow()
|
||||
GLuint QIOSWindow::framebufferObject(const QIOSContext &context) const
|
||||
{
|
||||
if (!m_window) {
|
||||
m_window = [[UIWindow alloc] init];
|
||||
updateGeometryAndOrientation();
|
||||
// window
|
||||
m_window.screen = m_screen->uiScreen();
|
||||
// for some reason setting the screen resets frame.origin, so we need to set the frame afterwards
|
||||
m_window.frame = m_frame;
|
||||
static GLuint framebuffer = 0;
|
||||
|
||||
// view
|
||||
[m_view deleteFramebuffer];
|
||||
m_view.frame = CGRectMake(0, 0, m_window.bounds.size.width, m_window.bounds.size.height); // fill
|
||||
[m_view setContentScaleFactor:[m_window.screen scale]];
|
||||
[m_view setMultipleTouchEnabled:YES];
|
||||
[m_view setWindow:this];
|
||||
[m_window addSubview:m_view];
|
||||
[m_window setNeedsDisplay];
|
||||
[m_window makeKeyAndVisible];
|
||||
}
|
||||
return m_window;
|
||||
}
|
||||
// FIXME: Cache context and recreate framebuffer if window
|
||||
// is used with a different context then last time.
|
||||
|
||||
void QIOSWindow::updateGeometryAndOrientation()
|
||||
{
|
||||
if (!m_window)
|
||||
return;
|
||||
m_frame = [m_screen->uiScreen() applicationFrame];
|
||||
CGRect screen = [m_screen->uiScreen() bounds];
|
||||
QRect geom;
|
||||
CGFloat angle = 0;
|
||||
switch ([[UIApplication sharedApplication] statusBarOrientation]) {
|
||||
case UIInterfaceOrientationPortrait:
|
||||
geom = QRect(m_frame.origin.x, m_frame.origin.y, m_frame.size.width, m_frame.size.height);
|
||||
break;
|
||||
case UIInterfaceOrientationPortraitUpsideDown:
|
||||
geom = QRect(screen.size.width - m_frame.origin.x - m_frame.size.width,
|
||||
screen.size.height - m_frame.origin.y - m_frame.size.height,
|
||||
m_frame.size.width,
|
||||
m_frame.size.height);
|
||||
angle = M_PI;
|
||||
break;
|
||||
case UIInterfaceOrientationLandscapeLeft:
|
||||
geom = QRect(screen.size.height - m_frame.origin.y - m_frame.size.height,
|
||||
m_frame.origin.x,
|
||||
m_frame.size.height,
|
||||
m_frame.size.width);
|
||||
angle = -M_PI/2.;
|
||||
break;
|
||||
case UIInterfaceOrientationLandscapeRight:
|
||||
geom = QRect(m_frame.origin.y,
|
||||
screen.size.width - m_frame.origin.x - m_frame.size.width,
|
||||
m_frame.size.height,
|
||||
m_frame.size.width);
|
||||
angle = +M_PI/2.;
|
||||
break;
|
||||
if (!framebuffer) {
|
||||
EAGLContext* eaglContext = context.nativeContext();
|
||||
|
||||
[EAGLContext setCurrentContext:eaglContext];
|
||||
|
||||
// Create the framebuffer and bind it
|
||||
glGenFramebuffers(1, &framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
|
||||
GLint width;
|
||||
GLint height;
|
||||
|
||||
// Create a color renderbuffer, allocate storage for it,
|
||||
// and attach it to the framebuffer’s color attachment point.
|
||||
GLuint colorRenderbuffer;
|
||||
glGenRenderbuffers(1, &colorRenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
|
||||
[eaglContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:static_cast<CAEAGLLayer *>(m_view.layer)];
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width);
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
|
||||
|
||||
QSurfaceFormat requestedFormat = context.format();
|
||||
if (requestedFormat.depthBufferSize() > 0 || requestedFormat.stencilBufferSize() > 0) {
|
||||
// Create a depth or depth/stencil renderbuffer, allocate storage for it,
|
||||
// and attach it to the framebuffer’s depth attachment point.
|
||||
GLuint depthRenderbuffer;
|
||||
glGenRenderbuffers(1, &depthRenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
|
||||
|
||||
// FIXME: Support more fine grained control over depth/stencil buffer sizes
|
||||
if (requestedFormat.stencilBufferSize() > 0) {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
|
||||
} else {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
|
||||
}
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
|
||||
}
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
||||
}
|
||||
|
||||
CGFloat scale = [m_screen->uiScreen() scale];
|
||||
geom = QRect(geom.x() * scale, geom.y() * scale,
|
||||
geom.width() * scale, geom.height() * scale);
|
||||
|
||||
if (angle != 0) {
|
||||
[m_view layer].transform = CATransform3DMakeRotation(angle, 0, 0, 1.);
|
||||
} else {
|
||||
[m_view layer].transform = CATransform3DIdentity;
|
||||
}
|
||||
[m_view setNeedsDisplay];
|
||||
window()->setGeometry(geom);
|
||||
}
|
||||
|
||||
QPlatformOpenGLContext *QIOSWindow::glContext() const
|
||||
{
|
||||
if (!m_context) {
|
||||
m_context = new EAGLPlatformContext(m_view);
|
||||
}
|
||||
return m_context;
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user