source: trunk/src/opengl/qgl_symbian.cpp@ 1028

Last change on this file since 1028 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 10.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtOpenGL module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42
43#include "qgl.h"
44#include <coemain.h>
45#include <coecntrl.h>
46#include <w32std.h>
47#include <private/qpixmap_s60_p.h>
48#include <private/qimagepixmapcleanuphooks_p.h>
49#include <private/qgl_p.h>
50#include <private/qpaintengine_opengl_p.h>
51#include <private/qwidget_p.h> // to access QWExtra
52#include "qgl_egl_p.h"
53#include "qcolormap.h"
54#include <QDebug>
55
56QT_BEGIN_NAMESPACE
57
58// Turn off "direct to window" rendering if EGL cannot support it.
59#if !defined(EGL_RENDER_BUFFER) || !defined(EGL_SINGLE_BUFFER)
60#if defined(QGL_DIRECT_TO_WINDOW)
61#undef QGL_DIRECT_TO_WINDOW
62#endif
63#endif
64
65// Determine if preserved window contents should be used.
66#if !defined(EGL_SWAP_BEHAVIOR) || !defined(EGL_BUFFER_PRESERVED)
67#if !defined(QGL_NO_PRESERVED_SWAP)
68#define QGL_NO_PRESERVED_SWAP 1
69#endif
70#endif
71
72/*
73 QGLTemporaryContext implementation
74*/
75
76
77class QGLTemporaryContextPrivate
78{
79public:
80 bool initialized;
81 RWindow *window;
82 EGLContext context;
83 EGLSurface surface;
84 EGLDisplay display;
85};
86
87QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
88 : d(new QGLTemporaryContextPrivate)
89{
90 d->initialized = false;
91 d->window = 0;
92 d->context = 0;
93 d->surface = 0;
94
95 d->display = d->display = QEgl::display();
96
97 EGLConfig config;
98 int numConfigs = 0;
99 EGLint attribs[] = {
100 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
101#ifdef QT_OPENGL_ES_2
102 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
103#endif
104 EGL_NONE
105 };
106
107 eglChooseConfig(d->display, attribs, &config, 1, &numConfigs);
108 if (!numConfigs) {
109 qWarning("QGLTemporaryContext: No EGL configurations available.");
110 return;
111 }
112
113 d->window = new RWindow(CCoeEnv::Static()->WsSession());
114 d->window->Construct(CCoeEnv::Static()->RootWin(),(uint)this);
115
116 d->surface = eglCreateWindowSurface(d->display, config, (EGLNativeWindowType) d->window, NULL);
117
118 if (d->surface == EGL_NO_SURFACE) {
119 qWarning("QGLTemporaryContext: Error creating EGL surface.");
120 delete d->window;
121 d->window = 0;
122 return;
123 }
124
125 EGLint contextAttribs[] = {
126#ifdef QT_OPENGL_ES_2
127 EGL_CONTEXT_CLIENT_VERSION, 2,
128#endif
129 EGL_NONE
130 };
131 d->context = eglCreateContext(d->display, config, 0, contextAttribs);
132 if (d->context != EGL_NO_CONTEXT
133 && eglMakeCurrent(d->display, d->surface, d->surface, d->context))
134 {
135 d->initialized = true;
136 } else {
137 qWarning("QGLTemporaryContext: Error creating EGL context.");
138 d->window = 0;
139 return;
140 }
141}
142
143QGLTemporaryContext::~QGLTemporaryContext()
144{
145 if (d->initialized) {
146 eglMakeCurrent(d->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);