Gnash  0.8.11dev
eglDevice.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
20 #ifndef __EGL_DEVICE_H__
21 #define __EGL_DEVICE_H__ 1
22 
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
26 
27 #include <memory>
28 
29 #ifdef HAVE_X11_X_H
30 #include "x11/X11Device.h"
31 #endif
32 #include "GnashDevice.h"
33 
34 #ifdef HAVE_EGL_EGL_H
35 # include <EGL/egl.h>
36 #else
37 # error "This file needs EGL, which is part of OpenGL-ES"
38 #endif
39 
40 #include "Point2d.h"
41 
42 namespace gnash {
43 
44 namespace renderer {
45 
46 struct eglVertex {
47  eglVertex(float x, float y)
48  : _x(x), _y(y) { }
49 
50  eglVertex(const point& p)
51  : _x(p.x), _y(p.y) { }
52  float _x;
53  float _y;
54 };
55 
56 class EGLDevice : public GnashDevice
57 {
58  public:
59  typedef enum {LOW, MEDIUM, HIGH} quality_e;
60  EGLDevice();
61  EGLDevice(int argc, char *argv[]);
63 
64  virtual ~EGLDevice();
65 
66  dtype_t getType() { return EGL; };
67 
68  // Initialize EGL Device layer
69  bool initDevice(int argc, char *argv[]);
70 
71  // Initialize EGL Window layer
73 
74  // Utility methods not in the base class
76  const char *getErrorString(int error);
77 
78  size_t getStride() {
79  return getDepth() * getWidth();
80  };
81 
82  // Accessors for the settings needed by higher level code.
83  // Surface accessors
84  size_t getWidth() {
85  return getWidth(_eglSurface);
86  };
87 
88  size_t getHeight() {
89  return getHeight(_eglSurface);
90  }
91 
92  EGLint getDepth() {
93  EGLint value;
94  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_DEPTH_SIZE, &value);
95  return value;
96  }
97 
98  int getRedSize() {
99  EGLint value;
100  if (_eglConfig && _eglDisplay) {
101  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_RED_SIZE, &value);
102  }
103  return static_cast<int>(value);
104  };
105  int getGreenSize() {
106  EGLint value;
107  if (_eglConfig && _eglDisplay) {
108  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_GREEN_SIZE, &value);
109  }
110  return static_cast<int>(value);
111  };
112  int getBlueSize() {
113  EGLint value;
114  if (_eglConfig && _eglDisplay) {
115  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_BLUE_SIZE, &value);
116  }
117  return static_cast<int>(value);
118  };
119 
121  EGLint value;
122  if (_eglSurface && _eglDisplay) {
123  eglQuerySurface(_eglDisplay, _eglSurface, EGL_RENDER_BUFFER, &value);
124  }
125  if (value == EGL_SINGLE_BUFFER) {
126  return true;
127  }
128  return false;
129  }
132  }
133 
134  int getID() {
135  return static_cast<int>(getSurfaceID());
136  }
137 
139 
140  bool isNativeRender() {
141  EGLint value;
142  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_RENDERABLE, &value);
143  return value;
144  }
145 
146  // Overload some of the base class methods to deal with Device specific
147  // data types.
148  bool bindClient(GnashDevice::rtype_t rtype);
149 
150  size_t getWidth(EGLSurface surface) {
151  EGLint value;
152  if (surface && _eglDisplay) {
153  eglQuerySurface(_eglDisplay, surface, EGL_WIDTH, &value);
154  }
155  return static_cast<size_t>(value);
156  };
157  size_t getHeight(EGLSurface surface) {
158  EGLint value;
159  if (surface && _eglDisplay) {
160  eglQuerySurface(_eglDisplay, surface, EGL_HEIGHT, &value);
161  }
162  return static_cast<size_t>(value);
163  }
164  bool isBufferDestroyed(EGLSurface surface) {
165  EGLint value;
166  eglQuerySurface(_eglDisplay, surface, EGL_SWAP_BEHAVIOR, &value);
167  if (value == EGL_BUFFER_DESTROYED) {
168  return true;
169  }
170  return false;
171  }
172 #ifdef BUILD_X11_DEVICE
173  EGLint getNativeVisual();
174 #endif
175 
177  bool checkEGLConfig(EGLConfig config);
178 
181  int queryEGLConfig(EGLDisplay display);
182 
183  // Debugging utilities
185  void printEGLConfig(EGLConfig config);
187  void printEGLContext(EGLContext context);
189  void printEGLSurface(EGLSurface surface);
190  void printEGLAttribs(const EGLint *attrib);
191 
192  // Create Pbuffers for offscreen rendering
193  EGLSurface createPbuffer(int width, int height);
194  EGLSurface createPbuffer(int width, int height, EGLClientBuffer buf, EGLenum type);
195  EGLSurface createPixmap(int width, int height, NativePixmapType buf);
196  size_t totalPbuffers() { return _pbuffers.size(); };
197  EGLSurface &operator[](int index) { if (!_pbuffers.empty()) { return _pbuffers[index]; }; };
198 
199  // Swapping Buffers makes the specified surface active on the display if
200  // EGL_RENDER_BUFFER is set to EGL_BACK_BUFFER. If it's set to
201  // EGL_SINGLE_BUFFER then this has no effect, as the display was drawn to
202  // directly.
203  // Swap to the default surface
204  bool swapBuffers() {
205  // GNASH_REPORT_FUNCTION;
206  if (!isSingleBuffered()) {
207  return eglSwapBuffers(_eglDisplay, _eglSurface);
208  }
209  return true;
210  }
211  bool copyPbuffers(size_t x) {
213  if (x < _pbuffers.size()) {
214  NativePixmapType pix;
215  if (!eglCopyBuffers(_eglDisplay, _pbuffers[x], pix)) {
216  log_error( "eglCopyBuffers() failed (error 0x%x)", eglGetError());
217  return false;
218  }
219  return true;
220  }
221  return false;
222  }
223  // Make one of the pbuffers the current one to draw into
225  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglSurface != EGL_NO_SURFACE)) {
226  if (!eglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext)) {
227  log_error( "eglMakeCurrent() failed (error 0x%x)", eglGetError());
228  return false;
229  }
230  }
231  return false;
232  }
233 
234  bool makePbufferCurrent(size_t x) {
235  if (x < _pbuffers.size()) {
236  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglContext != EGL_NO_CONTEXT)) {
237  if (!eglMakeCurrent(_eglDisplay, _pbuffers[x], _pbuffers[x], _eglContext)) {
238  log_error( "eglMakeCurrent() failed (error 0x%x)", eglGetError());
239  return false;
240  }
241  return true;
242  }
243  }
244  return false;
245  }
246 
247  size_t getVerticalRes() {
248  EGLint value = 0;
249  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglSurface != EGL_NO_SURFACE)) {
250  eglQuerySurface(_eglDisplay, _eglSurface, EGL_VERTICAL_RESOLUTION, &value);
251  }
252  return static_cast<size_t>(value);
253  }
254  size_t getHorzRes() {
255  EGLint value = 0;
256  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglSurface != EGL_NO_SURFACE)) {
257  eglQuerySurface(_eglDisplay, _eglSurface, EGL_HORIZONTAL_RESOLUTION, &value);
258  }
259  return static_cast<size_t>(value);
260  }
261  bool isBackBuffered() {
262  EGLint value;
263  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglSurface != EGL_NO_SURFACE)) {
264  eglQuerySurface(_eglDisplay, _eglSurface, EGL_RENDER_BUFFER, &value);
265  if (value == EGL_BACK_BUFFER) {
266  return true;
267  }
268  return false;
269  }
270  return false;
271  }
272 
273  bool isMultiSample() {
274  EGLint value;
275  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglSurface != EGL_NO_SURFACE)) {
276  eglQuerySurface(_eglDisplay, _eglSurface, EGL_MULTISAMPLE_RESOLVE, &value);
277  if (value == EGL_MULTISAMPLE_RESOLVE_BOX) {
278  return true;
279  }
280  return false;
281  }
282  return false;
283  }
284 
285  EGLint getSurfaceID() {
286  EGLint value = -1;
287  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglSurface != EGL_NO_SURFACE)) {
288  eglQuerySurface(_eglDisplay, _eglSurface, EGL_CONFIG_ID, &value);
289  }
290  return value;
291  }
292 
293  // Context accessors
294  EGLint getContextID() {
295  EGLint value = -1;
296  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglContext != EGL_NO_CONTEXT)) {
297  eglQueryContext(_eglDisplay, _eglContext, EGL_CONFIG_ID, &value);
298  }
299  return value;
300  }
302  EGLint value;
303  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglContext != EGL_NO_CONTEXT)) {
304  eglQueryContext(_eglDisplay, _eglContext, EGL_RENDER_BUFFER, &value);
305  if (value == EGL_SINGLE_BUFFER) {
306  return true;
307  }
308  return false;
309  }
310  return false;
311  }
313  EGLint value;
314  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglContext != EGL_NO_CONTEXT)) {
315  eglQueryContext(_eglDisplay, _eglContext, EGL_RENDER_BUFFER, &value);
316  if (value == EGL_BACK_BUFFER) {
317  return true;
318  }
319  return false;
320  }
321  return false;
322  }
323 
324  // Config accessors
325  EGLint getSamples() {
326  EGLint value = -1;
327  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglConfig != 0)) {
328  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_SAMPLES, &value);
329  }
330  return value;
331  }
332  EGLint getSampleBuffers() {
333  EGLint value = -1;
334  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglConfig != 0)) {
335  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_SAMPLE_BUFFERS, &value);
336  }
337  return value;
338  }
340  EGLint value = -1;
341  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglConfig != 0)) {
342  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_MAX_SWAP_INTERVAL, &value);
343  }
344  return value;
345  }
347  EGLint value = -1;
348  if ((_eglDisplay != EGL_NO_DISPLAY) && (_eglConfig != 0)) {
349  eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_MIN_SWAP_INTERVAL, &value);
350  }
351  return value;
352  }
353 
354  void setAttrib(int bpp);
355  static EGLint getRenderableTypes();
356 protected:
357  EGLConfig _eglConfig;
358  EGLContext _eglContext;
359  EGLSurface _eglSurface;
360  EGLDisplay _eglDisplay;
361  EGLNativeWindowType _nativeWindow;
362  EGLNativePixmapType _nativePixmap;
364  const EGLint *_attrib;
365  unsigned int _bpp;
366  std::vector<EGLSurface> _pbuffers;
367 };
368 
369 #define DUMP_CURRENT_SURFACE printEGLSurface(eglGetCurrentSurface(EGL_DRAW))
370 #define DUMP_CURRENT_CONTEXT printEGLContext(eglGetCurrentContext())
371 
372 } // namespace renderer
373 } // namespace gnash
374 
375 #endif // end of __EGL_DEVICE_H__
376 
377 // local Variables:
378 // mode: C++
379 // indent-tabs-mode: nil
380 // End:
gnash::renderer::EGLDevice::getType
dtype_t getType()
Definition: eglDevice.h:66
gnash::LogFile::getDefaultInstance
static LogFile & getDefaultInstance()
Definition: log.cpp:77
gnash::renderer::EGLDevice::_nativeWindow
EGLNativeWindowType _nativeWindow
Definition: eglDevice.h:361
pix
BitmapData_as::iterator pix
Definition: BitmapData_as.cpp:568
gnash::renderer::EGLDevice::isContextBackBuffered
bool isContextBackBuffered()
Definition: eglDevice.h:312
gnash::renderer::GnashDevice::native_window_t
long native_window_t
Definition: GnashDevice.h:43
gnash::renderer::EGLDevice::copyPbuffers
bool copyPbuffers(size_t x)
Definition: eglDevice.h:211
gnash::renderer::EGLDevice::operator[]
EGLSurface & operator[](int index)
Definition: eglDevice.h:197
gnash::renderer::EGLDevice::quality_e
quality_e
Definition: eglDevice.h:59
height
@ height
Definition: klash_part.cpp:329
gnash::renderer::EGLDevice::makePbufferCurrent
bool makePbufferCurrent(size_t x)
Definition: eglDevice.h:234
gnash::renderer::EGLDevice::getWidth
size_t getWidth(EGLSurface surface)
Definition: eglDevice.h:150
gnash::GnashException
Top-level gnash exception.
Definition: GnashException.h:31
gnash::renderer::EGLDevice::isSingleBuffered
bool isSingleBuffered()
Is this device single buffered.
Definition: eglDevice.h:120
gnash::renderer::EGLDevice::attachWindow
bool attachWindow(GnashDevice::native_window_t window)
Definition: eglDevice.cpp:376
gnash::renderer::EGLDevice::getSamples
EGLint getSamples()
Definition: eglDevice.h:325
dbglogfile
#define dbglogfile
Definition: gtkext.cpp:48
gnash::renderer::EGLDevice::getBlueSize
int getBlueSize()
Get the size of the Blue pixel.
Definition: eglDevice.h:112
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::renderer::EGLDevice::isBufferDestroyed
bool isBufferDestroyed()
Are buffers destroyed ?
Definition: eglDevice.h:130
y
std::int32_t y
Definition: BitmapData_as.cpp:435
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::renderer::EGLDevice::getWidth
size_t getWidth()
Get the width of the device.
Definition: eglDevice.h:84
configTemplates.h
gnash::renderer::EGLDevice::queryEGLConfig
int queryEGLConfig()
Query the system for all supported configs.
Definition: eglDevice.h:180
gnash::renderer::EGLDevice::bindClient
bool bindClient(GnashDevice::rtype_t rtype)
Definition: eglDevice.cpp:332
_
#define _(String)
Definition: log.h:44
Renderer.h
gnash::renderer::GnashDevice::dtype_t
dtype_t
The list of supported device types.
Definition: GnashDevice.h:48
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::renderer::EGLDevice::makePbufferCurrent
bool makePbufferCurrent()
Definition: eglDevice.h:224
gnash::renderer::EGLDevice::_nativePixmap
EGLNativePixmapType _nativePixmap
Definition: eglDevice.h:362
gnash::renderer::EGLDevice::getID
int getID()
Get the window ID handle.
Definition: eglDevice.h:134
gnash::renderer::EGLDevice::getContextID
EGLint getContextID()
Definition: eglDevice.h:294
gnash::renderer::EGLDevice::_eglSurface
EGLSurface _eglSurface
Definition: eglDevice.h:359
GNASH_REPORT_FUNCTION
#define GNASH_REPORT_FUNCTION
Definition: log.h:452
gnash::renderer::EGLDevice::~EGLDevice
virtual ~EGLDevice()
Definition: eglDevice.cpp:131
gnash::renderer::EGLDevice::_quality
quality_e _quality
Definition: eglDevice.h:363
gnash::renderer::GnashDevice::OPENVG
@ OPENVG
Definition: GnashDevice.h:46
gnash::renderer::GnashDevice::EGL
@ EGL
Definition: GnashDevice.h:48
gnash::renderer::EGLDevice::getRedSize
int getRedSize()
Get the size of the Red pixel.
Definition: eglDevice.h:98
gnash::renderer::eglVertex
Definition: eglDevice.h:46
gnash::renderer::EGLDevice::checkEGLConfig
bool checkEGLConfig(EGLConfig config)
Check the requested EGl configuration against the current one.
Definition: eglDevice.cpp:475
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::renderer::GnashDevice::OPENGLES1
@ OPENGLES1
Definition: GnashDevice.h:46
gnash::renderer::EGLDevice::totalPbuffers
size_t totalPbuffers()
Definition: eglDevice.h:196
gnash::renderer::EGLDevice::supportsRenderer
bool supportsRenderer(GnashDevice::rtype_t rtype)
Is the specified renderer supported by this hardware ?
Definition: eglDevice.cpp:293
gnash::renderer::eglVertex::_x
float _x
Definition: eglDevice.h:52
gnash::renderer::EGLDevice::isContextSingleBuffered
bool isContextSingleBuffered()
Definition: eglDevice.h:301
gnash::renderer::EGLDevice::getSurfaceID
EGLint getSurfaceID()
Definition: eglDevice.h:285
gnash::renderer::GnashDevice
Definition: GnashDevice.h:40
gnash::renderer::EGLDevice::_eglDisplay
EGLDisplay _eglDisplay
Definition: eglDevice.h:360
gnash::renderer::EGLDevice::getDepth
EGLint getDepth()
Get the depth of the device.
Definition: eglDevice.h:92
gnash::key::type
type
Definition: GnashKey.h:330
gnash::renderer::EGLDevice::setAttrib
void setAttrib(int bpp)
Definition: eglDevice.cpp:116
Point2d.h
gnash::renderer::EGLDevice::getHeight
size_t getHeight(EGLSurface surface)
Definition: eglDevice.h:157
gnash::renderer::EGLDevice::getVerticalRes
size_t getVerticalRes()
Definition: eglDevice.h:247
gnash::renderer::eglVertex::eglVertex
eglVertex(const point &p)
Definition: eglDevice.h:50
gnash::renderer::EGLDevice::_attrib
const EGLint * _attrib
Definition: eglDevice.h:364
gnash::renderer::EGLDevice::isMultiSample
bool isMultiSample()
Definition: eglDevice.h:273
gnash::renderer::EGLDevice::_eglContext
EGLContext _eglContext
Definition: eglDevice.h:358
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::renderer::EGLDevice::HIGH
@ HIGH
Definition: eglDevice.h:59
gnash::renderer::EGLDevice::getSampleBuffers
EGLint getSampleBuffers()
Definition: eglDevice.h:332
gnash::renderer::EGLDevice::LOW
@ LOW
Definition: eglDevice.h:59
eglDevice.h
gnash::renderer::EGLDevice::swapBuffers
bool swapBuffers()
Definition: eglDevice.h:204
gnash::renderer::EGLDevice::isNativeRender
bool isNativeRender()
Is this renderering natively.
Definition: eglDevice.h:140
gnash::renderer::eglVertex::eglVertex
eglVertex(float x, float y)
Definition: eglDevice.h:47
gnash::geometry::Point2d
2D Point class
Definition: Point2d.h:39
gnash::renderer::EGLDevice::EGLDevice
EGLDevice()
Definition: eglDevice.cpp:50
gnash::renderer::EGLDevice::_eglConfig
EGLConfig _eglConfig
Definition: eglDevice.h:357
log.h
gnash::renderer::GnashDevice::XORG
@ XORG
Definition: GnashDevice.h:46
gnash::renderer::EGLDevice::_pbuffers
std::vector< EGLSurface > _pbuffers
Definition: eglDevice.h:366
gnash::renderer::GnashDevice::VAAPI
@ VAAPI
Definition: GnashDevice.h:46
gnash::renderer::EGLDevice::initDevice
bool initDevice(int argc, char *argv[])
Definition: eglDevice.cpp:169
gnash::renderer::EGLDevice::getHorzRes
size_t getHorzRes()
Definition: eglDevice.h:254
gnash::renderer::EGLDevice::isBackBuffered
bool isBackBuffered()
Definition: eglDevice.h:261
X11Device.h
gnashconfig.h
gnash::renderer::EGLDevice::getStride
size_t getStride()
Query the system for all supported configs.
Definition: eglDevice.h:78
gnash::renderer::EGLDevice::createPixmap
EGLSurface createPixmap(int width, int height, NativePixmapType buf)
Definition: eglDevice.cpp:808
gnash::renderer::EGLDevice::getMaxSwapInterval
EGLint getMaxSwapInterval()
Definition: eglDevice.h:339
gnash::renderer::EGLDevice::printEGLSurface
void printEGLSurface()
Definition: eglDevice.h:188
gnash::renderer::EGLDevice
Definition: eglDevice.h:57
gnash::renderer::GnashDevice::OPENGLES2
@ OPENGLES2
Definition: GnashDevice.h:46
gnash::renderer::EGLDevice::printEGLContext
void printEGLContext()
Definition: eglDevice.h:186
gnash::config
struct lirc_config * config
Definition: lirc_ext.cpp:43
gnash::renderer::EGLDevice::createPbuffer
EGLSurface createPbuffer(int width, int height)
Definition: eglDevice.cpp:767
gnash::renderer::surface_attributes
const EGLint surface_attributes[]
Definition: configTemplates.h:183
gnash::renderer::EGLDevice::isBufferDestroyed
bool isBufferDestroyed(EGLSurface surface)
Definition: eglDevice.h:164
GnashDevice.h
gnash::renderer::EGLDevice::printEGLConfig
void printEGLConfig()
Definition: eglDevice.h:184
gnash::renderer::GnashDevice::rtype_t
rtype_t
The list of supported renders that use devices.
Definition: GnashDevice.h:46
gnash::renderer::EGLDevice::getGreenSize
int getGreenSize()
Get the size of the Green pixel.
Definition: eglDevice.h:105
width
@ width
Definition: klash_part.cpp:329
gnash::renderer::eglVertex::_y
float _y
Definition: eglDevice.h:53
GnashException.h
x
std::int32_t x
Definition: BitmapData_as.cpp:434
gnash::renderer::EGLDevice::getRenderableTypes
static EGLint getRenderableTypes()
Definition: eglDevice.cpp:830
gnash::renderer::EGLDevice::getMinSwapInterval
EGLint getMinSwapInterval()
Definition: eglDevice.h:346
gnash::renderer::EGLDevice::getHeight
size_t getHeight()
Get the Height of the device.
Definition: eglDevice.h:88
gnash::renderer::EGLDevice::_bpp
unsigned int _bpp
Definition: eglDevice.h:365
gnash::renderer::EGLDevice::MEDIUM
@ MEDIUM
Definition: eglDevice.h:59
gnash::renderer::EGLDevice::getErrorString
const char * getErrorString(int error)
Return a string with the error code as text, instead of a numeric value.
Definition: eglDevice.cpp:436
gnash::renderer::EGLDevice::printEGLAttribs
void printEGLAttribs(const EGLint *attrib)
Definition: eglDevice.cpp:581