source: trunk/src/opengl/qpixmapdata_x11gl_egl.cpp@ 624

Last change on this file since 624 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 8.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 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#include <private/qgl_p.h>
43#include <private/qegl_p.h>
44#include <private/qeglproperties_p.h>
45#include <private/qpaintengineex_opengl2_p.h>
46
47#include "qpixmapdata_x11gl_p.h"
48
49QT_BEGIN_NAMESPACE
50
51extern EGLConfig qt_chooseEGLConfigForPixmap(bool hasAlpha, bool readOnly); // in qgl_x11egl.cpp
52extern bool qt_createEGLSurfaceForPixmap(QPixmapData* pmd, bool readOnly); // in qgl_x11egl.cpp
53
54// On 16bpp systems, RGB & ARGB pixmaps are different bit-depths and therefore need
55// different contexts:
56static EGLContext qPixmapARGBSharedEglContext = EGL_NO_CONTEXT;
57static EGLContext qPixmapRGBSharedEglContext = EGL_NO_CONTEXT;
58
59bool QX11GLPixmapData::hasX11GLPixmaps()
60{
61 static bool checkedForX11Pixmaps = false;
62 static bool haveX11Pixmaps = false;
63
64 if (checkedForX11Pixmaps)
65 return haveX11Pixmaps;
66
67 checkedForX11Pixmaps = true;
68
69 QX11PixmapData *argbPixmapData = 0;
70 QX11PixmapData *rgbPixmapData = 0;
71 do {
72 if (qgetenv("QT_USE_X11GL_PIXMAPS").isEmpty())
73 break;
74
75 // Check we actually have EGL configs which support pixmaps
76 EGLConfig argbConfig = qt_chooseEGLConfigForPixmap(true, false);
77 EGLConfig rgbConfig = qt_chooseEGLConfigForPixmap(false, false);
78
79 if (argbConfig == 0 || rgbConfig == 0)
80 break;
81
82 // Create the shared contexts:
83 eglBindAPI(EGL_OPENGL_ES_API);
84 EGLint contextAttribs[] = {
85#if defined(QT_OPENGL_ES_2)
86 EGL_CONTEXT_CLIENT_VERSION, 2,
87#endif
88 EGL_NONE
89 };
90 qPixmapARGBSharedEglContext = eglCreateContext(QEglContext::defaultDisplay(0),
91 argbConfig, 0, contextAttribs);
92
93 if (argbConfig == rgbConfig) {
94 // If the configs are the same, we can re-use the same context.
95 qPixmapRGBSharedEglContext = qPixmapARGBSharedEglContext;
96 } else {
97 qPixmapRGBSharedEglContext = eglCreateContext(QEglContext::defaultDisplay(0),
98 rgbConfig, 0, contextAttribs);
99 }
100
101 argbPixmapData = new QX11PixmapData(QPixmapData::PixmapType);
102 argbPixmapData->resize(100, 100);
103 argbPixmapData->fill(Qt::transparent); // Force ARGB
104
105 if (!qt_createEGLSurfaceForPixmap(argbPixmapData, false))
106 break;
107
108 haveX11Pixmaps = eglMakeCurrent(QEglContext::defaultDisplay(0),
109 (EGLSurface)argbPixmapData->gl_surface,
110 (EGLSurface)argbPixmapData->gl_surface,
111 qPixmapARGBSharedEglContext);
112 if (!haveX11Pixmaps) {
113 EGLint err = eglGetError();
114 qWarning() << "Unable to make pixmap config current:" << err << QEglContext::errorString(err);