source: trunk/src/openvg/qwindowsurface_vgegl.cpp@ 858

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

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

  • Property svn:eol-style set to native
File size: 23.3 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 QtOpenVG 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 "qwindowsurface_vgegl_p.h"
43#include "qpaintengine_vg_p.h"
44#include "qpixmapdata_vg_p.h"
45#include "qvgimagepool_p.h"
46#include "qvg_p.h"
47
48#if !defined(QT_NO_EGL)
49
50QT_BEGIN_NAMESPACE
51
52// Turn off "direct to window" rendering if EGL cannot support it.
53#if !defined(EGL_RENDER_BUFFER) || !defined(EGL_SINGLE_BUFFER)
54#if defined(QVG_DIRECT_TO_WINDOW)
55#undef QVG_DIRECT_TO_WINDOW
56#endif
57#endif
58
59// Determine if preserved window contents should be used.
60#if !defined(EGL_SWAP_BEHAVIOR) || !defined(EGL_BUFFER_PRESERVED)
61#if !defined(QVG_NO_PRESERVED_SWAP)
62#define QVG_NO_PRESERVED_SWAP 1
63#endif
64#endif
65
66VGImageFormat qt_vg_config_to_vg_format(QEglContext *context)
67{
68 return qt_vg_image_to_vg_format
69 (qt_vg_config_to_image_format(context));
70}
71
72QImage::Format qt_vg_config_to_image_format(QEglContext *context)
73{
74 EGLint red = context->configAttrib(EGL_RED_SIZE);
75 EGLint green = context->configAttrib(EGL_GREEN_SIZE);
76 EGLint blue = context->configAttrib(EGL_BLUE_SIZE);
77 EGLint alpha = context->configAttrib(EGL_ALPHA_SIZE);
78 QImage::Format argbFormat;
79#ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT
80 EGLint type = context->configAttrib(EGL_SURFACE_TYPE);
81 if ((type & EGL_VG_ALPHA_FORMAT_PRE_BIT) != 0)
82 argbFormat = QImage::Format_ARGB32_Premultiplied;
83 else
84 argbFormat = QImage::Format_ARGB32;
85#else
86 argbFormat = QImage::Format_ARGB32;
87#endif
88 if (red == 8 && green == 8 && blue == 8 && alpha == 8)
89 return argbFormat;
90 else if (red == 8 && green == 8 && blue == 8 && alpha == 0)
91 return QImage::Format_RGB32;
92 else if (red == 5 && green == 6 && blue == 5 && alpha == 0)
93 return QImage::Format_RGB16;
94 else if (red == 4 && green == 4 && blue == 4 && alpha == 4)
95 return QImage::Format_ARGB4444_Premultiplied;
96 else
97 return argbFormat; // XXX
98}
99
100#if !defined(QVG_NO_SINGLE_CONTEXT)
101
102class QVGSharedContext
103{
104public:
105 QVGSharedContext();
106 ~QVGSharedContext();
107
108 QEglContext *context;
109 int refCount;
110 int widgetRefCount;
111 QVGPaintEngine *engine;
112 EGLSurface surface;
113 QVGPixmapData *firstPixmap;
114};
115
116QVGSharedContext::QVGSharedContext()
117 : context(0)
118 , refCount(0)
119 , widgetRefCount(0)
120 , engine(0)
121 , surface(EGL_NO_SURFACE)
122 , firstPixmap(0)
123{
124}
125
126QVGSharedContext::~QVGSharedContext()
127{
128 // Don't accidentally destroy the QEglContext if the reference
129 // count falls to zero while deleting the paint engine.
130 ++refCount;
131
132 if (context)
133 context->makeCurrent(qt_vg_shared_surface());
134 delete engine;
135 if (context)
136 context->doneCurrent();
137 if (context && surface != EGL_NO_SURFACE)
138 context->destroySurface(surface);
139 delete context;
140}
141
142Q_GLOBAL_STATIC(QVGSharedContext, sharedContext);
143
144QVGPaintEngine *qt_vg_create_paint_engine(void)
145{
146 QVGSharedContext *shared = sharedContext();
147 if (!shared->engine)
148 shared->engine = new QVGPaintEngine();
149 return shared->engine;
150}
151
152void qt_vg_destroy_paint_engine(QVGPaintEngine *engine)
153{
154 Q_UNUSED(engine);
155}
156
157void qt_vg_register_pixmap(QVGPixmapData *pd)
158{
159 QVGSharedContext *shared = sharedContext();
160 pd->next = shared->firstPixmap;
161 pd->prev = 0;
162 if (shared->firstPixmap)
163 shared->firstPixmap->prev = pd;
164 shared->firstPixmap = pd;
165}
166
167void qt_vg_unregister_pixmap(QVGPixmapData *pd)
168{
169 if (pd->next)
170 pd->next->prev = pd->prev;
171 if (pd->prev) {
172 pd->prev->next = pd->next;
173 } else {
174 QVGSharedContext *shared = sharedContext();
175 if (shared)
176 shared->firstPixmap = pd->next;
177 }
178}
179