Qt 4.8
qxlibintegration.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qxlibintegration.h"
43 #include "qxlibwindowsurface.h"
44 #include <QtGui/private/qpixmap_raster_p.h>
45 #include <QtCore/qdebug.h>
46 
47 #include "qxlibwindow.h"
49 #include "qxlibscreen.h"
50 #include "qxlibclipboard.h"
51 #include "qxlibdisplay.h"
52 #include "qxlibnativeinterface.h"
53 
54 #if !defined(QT_NO_OPENGL)
55 #if !defined(QT_OPENGL_ES_2)
56 #include <GL/glx.h>
57 #else
58 #include <EGL/egl.h>
59 #endif
60 #include <private/qwindowsurface_gl_p.h>
61 #include <private/qpixmapdata_gl_p.h>
62 #endif //QT_NO_OPENGL
63 
65 
67  : mUseOpenGL(useOpenGL)
68  , mFontDb(new QGenericUnixFontDatabase())
69  , mClipboard(0)
70  , mNativeInterface(new QXlibNativeInterface)
71 {
74 }
75 
77 {
78  switch (cap) {
79  case ThreadedPixmaps: return true;
80  case OpenGL: return hasOpenGL();
81  default: return QPlatformIntegration::hasCapability(cap);
82  }
83 }
84 
86 {
87 #ifndef QT_NO_OPENGL
88  if (mUseOpenGL)
89  return new QGLPixmapData(type);
90 #endif
91  return new QRasterPixmapData(type);
92 }
93 
95 {
96 #ifndef QT_NO_OPENGL
97  if (mUseOpenGL)
98  return new QGLWindowSurface(widget);
99 #endif
100  return new QXlibWindowSurface(widget);
101 }
102 
103 
105 {
106  return new QXlibWindow(widget);
107 }
108 
109 
110 
111 QPixmap QXlibIntegration::grabWindow(WId window, int x, int y, int width, int height) const
112 {
113  QImage image;
114  QWidget *widget = QWidget::find(window);
115  if (widget) {
117  image = screen->grabWindow(window,x,y,width,height);
118  } else {
119  for (int i = 0; i < mScreens.size(); i++) {
120  QXlibScreen *screen = static_cast<QXlibScreen *>(mScreens[i]);
121  if (screen->rootWindow() == window) {
122  image = screen->grabWindow(window,x,y,width,height);
123  }
124  }
125  }
126  return QPixmap::fromImage(image);
127 }
128 
130 {
131  return mFontDb;
132 }
133 
135 {
136  //Use lazy init since clipboard needs QTestliteScreen
137  if (!mClipboard) {
138  QXlibIntegration *that = const_cast<QXlibIntegration *>(this);
140  }
141  return mClipboard;
142 }
143 
145 {
146  return mNativeInterface;
147 }
148 
150 {
151 #if !defined(QT_NO_OPENGL)
152 #if !defined(QT_OPENGL_ES_2)
153  QXlibScreen *screen = static_cast<QXlibScreen *>(mScreens.at(0));
154  return glXQueryExtension(screen->display()->nativeDisplay(), 0, 0) != 0;
155 #else
156  static bool eglHasbeenInitialized = false;
157  static bool wasEglInitialized = false;
158  if (!eglHasbeenInitialized) {
159  eglHasbeenInitialized = true;
160  QXlibScreen *screen = static_cast<QXlibScreen *>(mScreens.at(0));
161  EGLint major, minor;
162  eglBindAPI(EGL_OPENGL_ES_API);
163  EGLDisplay disp = eglGetDisplay(screen->display()->nativeDisplay());
164  wasEglInitialized = eglInitialize(disp,&major,&minor);
165  screen->setEglDisplay(disp);
166  }
167  return wasEglInitialized;
168 #endif
169 #endif
170  return false;
171 }
172 
QPlatformNativeInterface * nativeInterface() const
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
unsigned long WId
Definition: qwindowdefs.h:119
int type
Definition: qmetatype.cpp:239
QPixmapData * createPixmapData(QPixmapData::PixelType type) const
Factory function for QPixmapData.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
QXlibScreen * mPrimaryScreen
Window rootWindow()
QPixmap grabWindow(WId window, int x, int y, int width, int height) const
This function is called when Qt needs to be able to grab the content of a window. ...
QPlatformWindow * createPlatformWindow(QWidget *widget, WId winId) const
Factory function for QPlatformWindow.
QPlatformFontDatabase * mFontDb
Display * nativeDisplay() const
QImage grabWindow(Window window, int x, int y, int w, int h)
virtual bool hasCapability(Capability cap) const
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QPlatformClipboard * mClipboard
QPlatformNativeInterface * mNativeInterface
QList< QPlatformScreen * > mScreens
The QPlatformWindow class provides an abstraction for top-level windows.
static QXlibScreen * testLiteScreenForWidget(QWidget *widget)
NSWindow * window
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QPlatformFontDatabase * fontDatabase() const
Accessor for the platform integrations fontdatabase.
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QWindowSurface class provides the drawing area for top-level windows.
QPlatformClipboard * clipboard() const
Accessor for the platform integrations clipboard.
QXlibIntegration(bool useOpenGL=false)
defined(QT_OPENGL_ES_2)
bool hasCapability(Capability cap) const
QWindowSurface * createWindowSurface(QWidget *widget, WId winId) const
Factory function for QWindowSurface.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool hasOpenGL() const
The QPlatformFontDatabase class makes it possible to customize how fonts are discovered and how they ...
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QXlibDisplay * display() const