Update with current status
[gnash.git] / libdevice / egl / eglDevice.cpp
blob5f9894a31c9f0a6fed03740259bea30f5bece69d
1 //
2 // Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifdef HAVE_CONFIG_H
19 #include "gnashconfig.h"
20 #endif
22 #include <iostream>
23 #include <cerrno>
24 #include <exception>
26 #include "log.h"
27 // #include "RunResources.h"
28 #include "Renderer.h"
29 #include "GnashException.h"
31 #ifdef HAVE_EGL_EGL_H
32 # include <EGL/egl.h>
33 #else
34 # error "This file needs EGL, which is part of OpenGL-ES"
35 #endif
37 //#include <GL/gl.h>
39 #include "eglDevice.h"
41 #include "configTemplates.h"
43 namespace gnash {
45 namespace renderer {
47 // The debug log used by all the gnash libraries.
48 static LogFile& dbglogfile = LogFile::getDefaultInstance();
50 EGLDevice::EGLDevice()
51 : _eglConfig(0),
52 _eglContext(EGL_NO_CONTEXT),
53 _eglSurface(EGL_NO_SURFACE),
54 _eglDisplay(EGL_NO_DISPLAY),
55 _quality(LOW),
56 _attrib(0),
57 #if BUILD_X11_DEVICE
58 _bpp(32)
59 #else
60 _bpp(16)
61 #endif
63 GNASH_REPORT_FUNCTION;
65 setAttrib(_bpp);
68 EGLDevice::EGLDevice(int argc, char *argv[])
69 : _eglConfig(0),
70 _eglContext(EGL_NO_CONTEXT),
71 _eglSurface(EGL_NO_SURFACE),
72 _eglDisplay(EGL_NO_DISPLAY),
73 _quality(LOW),
74 _attrib(0),
75 #if BUILD_X11_DEVICE
76 _bpp(32)
77 #else
78 _bpp(16)
79 #endif
81 GNASH_REPORT_FUNCTION;
83 setAttrib(_bpp);
85 if (!initDevice(argc, argv)) {
86 log_error(_("Couldn't initialize EGL device!"));
90 EGLDevice::EGLDevice(GnashDevice::rtype_t rtype)
91 : _eglConfig(0),
92 _eglContext(EGL_NO_CONTEXT),
93 _eglSurface(EGL_NO_SURFACE),
94 _eglDisplay(EGL_NO_DISPLAY),
95 _quality(LOW),
96 _attrib(0),
97 #if BUILD_X11_DEVICE
98 _bpp(32)
99 #else
100 _bpp(16)
101 #endif
103 GNASH_REPORT_FUNCTION;
105 setAttrib(_bpp);
107 if (!initDevice(0, 0)) {
108 log_error(_("Couldn't initialize EGL device!"));
110 if (!bindClient(rtype)) {
111 log_error(_("Couldn't bind client to type %d!"), rtype);
115 void
116 EGLDevice::setAttrib(int bpp)
118 switch (bpp) {
119 case 32:
120 _attrib = attrib32_low;
121 break;
122 case 16:
123 _attrib = attrib16_low;
124 break;
125 case 1:
126 _attrib = attrib1_list;
127 break;
131 EGLDevice::~EGLDevice()
133 // GNASH_REPORT_FUNCTION;
135 if (_eglDisplay != EGL_NO_DISPLAY) {
136 eglMakeCurrent(_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
138 std::vector<EGLSurface>::iterator it;
139 for (it = _pbuffers.begin(); it != _pbuffers.end(); ++it) {
140 eglDestroySurface(_eglDisplay, *it);
143 if (_eglContext != EGL_NO_CONTEXT)
144 eglDestroyContext(_eglDisplay, _eglContext);
146 if (_eglSurface != EGL_NO_SURFACE)
147 eglDestroySurface(_eglDisplay, _eglSurface);
149 eglTerminate(_eglDisplay);
153 /// @note: There are a few steps required to initialize an EGL
154 /// Device. This uses threee methods to do so, two are defaults from
155 /// the base class, one is an additional class that is EGL specific.
157 /// To start, initialize the device with the command line
158 /// arguments. These are ignored by EGL, but passed through here to
159 /// follow the way most other Devices need to be initialized.
161 /// Once initialized, EGL must be told which Client API to use, this
162 /// is either OpenVG, OpenGLES1, or OpenGLES2. To do this, we bind the
163 /// EGL device to the client API.
165 /// Once bound, the last step attaches the window surface of the
166 /// desktop or framebuffer to EGL. This is what binds EGL to the
167 /// desktop or framebuffer.
168 bool
169 EGLDevice::initDevice(int /* argc */, char **/*argv[] */)
171 // EGLDevice::rtype_t rtype;
173 dbglogfile.setVerbosity(2);
175 GNASH_REPORT_FUNCTION;
177 // step 1 - get an EGL display
178 // _eglDisplay = eglGetDisplay(XOpenDisplay(0));
179 _eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
180 if (EGL_NO_DISPLAY == _eglDisplay) {
181 log_error(_( "eglGetDisplay() failed (error 0x%x)"), eglGetError());
182 return false;
185 // This can be called multiple times safely
186 if (eglInitialize(_eglDisplay, 0, 0) != EGL_TRUE) {
187 log_error(_( "eglInitialize() failed (error %s)"),
188 getErrorString(eglGetError()));
189 return false;
192 // step2 - bind to the wanted client API
193 /// This is done by bindClient() later on
194 // bindClient(GnashDevice::OPENVG);
195 // queryEGLConfig(_eglDisplay);
197 log_debug(_("EGL_CLIENT_APIS = %s"), eglQueryString(_eglDisplay, EGL_CLIENT_APIS));
198 log_debug(_("EGL_EXTENSIONS = %s"), eglQueryString(_eglDisplay, EGL_EXTENSIONS));
199 log_debug(_("EGL_VERSION = %s, EGL_VENDOR = %s"),
200 eglQueryString(_eglDisplay, EGL_VERSION),
201 eglQueryString(_eglDisplay, EGL_VENDOR));
203 // step3 - find a suitable config
204 EGLint max_num_config = 0;
206 // Get the number of supported configurations
207 if ( EGL_FALSE == eglGetConfigs(_eglDisplay, 0, 0, &max_num_config) ) {
208 log_error(_("eglGetConfigs() failed to retrieve the number of configs (error %s)"),
209 getErrorString(eglGetError()));
210 return 0;
212 if(max_num_config <= 0) {
213 log_error(_( "No EGLconfigs found\n" ));
214 return 0;
216 log_debug(_("Max number of EGL Configs is %d"), max_num_config);
218 // The quality of the rendering is controlled by the number of samples
219 // and sample buffers as specified in the configuration. Higher quality
220 // settings force lower performance.
222 // eglChooseConfig() always returns EGL_SUCCESS, so we we just check the
223 // returned number of configurations to see if eglChooseConfig() actually
224 // found a workable configuration.
225 EGLint eglNumOfConfigs = 0;
226 switch (_quality) {
227 case EGLDevice::LOW:
228 eglChooseConfig(_eglDisplay, attrib32_low, &_eglConfig,
229 1, &eglNumOfConfigs);
230 if (eglNumOfConfigs) {
231 log_debug(_("Using the 32bpp, low quality configuration"));
232 } else {
233 log_error(_("eglChooseConfig(32-low) failed"));
234 eglChooseConfig(_eglDisplay, attrib16_low, &_eglConfig,
235 1, &eglNumOfConfigs);
236 if (eglNumOfConfigs) {
237 log_debug(_("Using the 16bpp, low quality configuration"));
238 } else {
239 log_error(_("eglChooseConfig(16-low) failed"));
240 return false;
243 break;
244 case EGLDevice::MEDIUM:
245 eglChooseConfig(_eglDisplay, attrib32_medium, &_eglConfig,
246 1, &eglNumOfConfigs);
247 if (eglNumOfConfigs) {
248 log_debug(_("Using the 32bpp, medium quality configuration"));
249 } else {
250 log_error(_("eglChooseConfig(32-medium) failed"));
251 eglChooseConfig(_eglDisplay, attrib16_medium, &_eglConfig,
252 1, &eglNumOfConfigs);
253 if (eglNumOfConfigs) {
254 log_debug(_("Using the 16bpp, medium quality configuration"));
255 } else {
256 log_error(_("eglChooseConfig(16-medium) failed"));
257 return false;
260 break;
261 case EGLDevice::HIGH:
262 eglChooseConfig(_eglDisplay, attrib32_high, &_eglConfig,
263 1, &eglNumOfConfigs);
264 if (eglNumOfConfigs) {
265 log_debug(_("Using the 32bpp, high quality configuration"));
266 } else {
267 log_error(_("eglChooseConfig(32-high) failed"));
268 eglChooseConfig(_eglDisplay, attrib16_high, &_eglConfig,
269 1, &eglNumOfConfigs);
270 if (eglNumOfConfigs) {
271 log_debug(_("Using the 16bpp, medium quality configuration"));
272 } else {
273 log_error(_("eglChooseConfig(16-high) failed"));
274 return false;
277 break;
278 default:
279 break;
282 if (!checkEGLConfig(_eglConfig)) {
283 log_error(_("EGL configuration doesn't match!"));
284 //return false;
285 } else {
286 printEGLConfig(_eglConfig);
289 return true;
292 bool
293 EGLDevice::supportsRenderer(rtype_t rtype)
295 GNASH_REPORT_FUNCTION;
297 if (_eglDisplay && _eglContext) {
298 EGLint value;
299 eglQueryContext(_eglDisplay, _eglContext, EGL_CONTEXT_CLIENT_TYPE, &value);
300 std::string str;
301 if ((value == EGL_OPENGL_ES_API) && (rtype == EGLDevice::OPENGLES2)) {
302 return true;
303 } else if ((value == EGL_OPENGL_ES_API) && (rtype == EGLDevice::OPENGLES1)) {
304 return true;
305 } else if ((value == EGL_OPENVG_API) && (rtype == EGLDevice::OPENVG)){
306 return true;
309 return false;
312 #ifdef BUILD_X11_DEVICE
313 EGLint
314 EGLDevice::getNativeVisual()
316 EGLint vid;
317 if (_eglDisplay && _eglConfig) {
318 if (!eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &vid)) {
319 log_error(_("eglGetConfigAttrib() failed (error %s)"),
320 getErrorString(eglGetError()));
321 return 0;
322 } else {
323 log_debug(_("EGL native visual is: %d"), vid);
327 return vid;
329 #endif
331 bool
332 EGLDevice::bindClient(rtype_t rtype)
334 GNASH_REPORT_FUNCTION;
336 switch (rtype) {
337 case GnashDevice::OPENGLES2:
339 log_debug(_("Initializing EGL for OpenGLES2"));
340 if(EGL_FALSE == eglBindAPI(EGL_OPENGL_ES_API)) {
341 log_error(_("eglBindAPI() failed to retrieve the number of configs (error %s)"),
342 getErrorString(eglGetError()));
343 return false;
345 break;
347 case GnashDevice::OPENGLES1:
349 log_debug(_("Initializing EGL for OpenGLES1"));
350 if(EGL_FALSE == eglBindAPI(EGL_OPENGL_ES_API)) {
351 log_error(_("eglBindAPI() failed to retrive the number of configs (error %s)"),
352 getErrorString(eglGetError()));
353 return false;
355 break;
357 case GnashDevice::OPENVG:
359 log_debug(_("Initializing EGL for OpenVG"));
360 if(EGL_FALSE == eglBindAPI(EGL_OPENVG_API)) {
361 log_error(_("eglBindAPI() failed to retrieve the number of configs (error %s)"),
362 getErrorString(eglGetError()));
363 return false;
365 break;
367 case GnashDevice::XORG:
368 case GnashDevice::VAAPI:
369 default:
370 break;
372 return true;
375 bool
376 EGLDevice::attachWindow(GnashDevice::native_window_t window)
378 GNASH_REPORT_FUNCTION;
380 if (!window) {
381 throw GnashException("bogus window handle!");
382 } else {
383 #ifdef EGL_NATIVE_WINDOW_INT
384 _nativeWindow = static_cast<EGLNativeWindowType>(window);
385 #else
386 _nativeWindow = reinterpret_cast<EGLNativeWindowType>(window);
387 #endif
390 if (_eglSurface != EGL_NO_SURFACE) {
391 eglDestroySurface(_eglDisplay, _eglSurface);
394 log_debug(_("Initializing EGL Surface"));
395 if (_eglDisplay && _eglConfig) {
396 _eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig,
397 _nativeWindow, surface_attributes);
400 if (EGL_NO_SURFACE == _eglSurface) {
401 log_error(_("eglCreateWindowSurface failed (error %s)"),
402 getErrorString(eglGetError()));
403 } else {
404 printEGLSurface(_eglSurface);
407 // step5 - create a context
408 _eglContext = eglCreateContext(_eglDisplay, _eglConfig, EGL_NO_CONTEXT, NULL);
409 if (EGL_NO_CONTEXT == _eglContext) {
410 // At least on Ubuntu 10.10, this returns a successful error string
411 // with LibeMesa's OpenVG 1.0 implementation. With OpenVG 1.1 on
412 // an ARM board, this works fine. Even the libMesa examples fail
413 // the same way.
414 boost::format fmt = boost::format(
415 _("eglCreateContext failed (error %s)")
416 ) % getErrorString(eglGetError());
417 throw GnashException(fmt.str());
418 } else {
419 printEGLContext(_eglContext);
422 // step6 - make the context and surface current
423 if (EGL_FALSE == eglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext)) {
424 // If for some reason we get a context, but can't make it current,
425 // nothing else will work anyway, so don't continue.
426 boost::format fmt = boost::format(
427 _("eglMakeCurrent failed (error %s)")
428 ) % getErrorString(eglGetError());
429 throw GnashException(fmt.str());
430 } // begin user code
432 return true;
435 const char *
436 EGLDevice::getErrorString(int error)
438 switch (error) {
439 case EGL_SUCCESS:
440 return "EGL_SUCCESS";
441 case EGL_NOT_INITIALIZED:
442 return "EGL_NOT_INITIALIZED";
443 case EGL_BAD_ACCESS:
444 return "EGL_BAD_ACCESS";
445 case EGL_BAD_ALLOC:
446 return "EGL_BAD_ALLOC";
447 case EGL_BAD_ATTRIBUTE:
448 return "EGL_BAD_ATTRIBUTE";
449 case EGL_BAD_CONFIG:
450 return "EGL_BAD_CONFIG";
451 case EGL_BAD_CONTEXT:
452 return "EGL_BAD_CONTEXT";
453 case EGL_BAD_CURRENT_SURFACE:
454 return "EGL_BAD_CURRENT_SURFACE";
455 case EGL_BAD_DISPLAY:
456 return "EGL_BAD_DISPLAY";
457 case EGL_BAD_MATCH:
458 return "EGL_BAD_MATCH";
459 case EGL_BAD_NATIVE_PIXMAP:
460 return "EGL_BAD_NATIVE_PIXMAP";
461 case EGL_BAD_NATIVE_WINDOW:
462 return "EGL_BAD_NATIVE_WINDOW";
463 case EGL_BAD_PARAMETER:
464 return "EGL_BAD_PARAMETER";
465 case EGL_BAD_SURFACE:
466 return "EGL_BAD_SURFACE";
467 case EGL_CONTEXT_LOST:
468 return "EGL_CONTEXT_LOST";
469 default:
470 return "unknown error code";
474 bool
475 EGLDevice::checkEGLConfig(EGLConfig config)
477 // GNASH_REPORT_FUNCTION;
479 // Use this to explicitly check that the EGL config has the expected color depths
480 EGLint value;
481 if (_bpp == 32) {
482 eglGetConfigAttrib(_eglDisplay, config, EGL_RED_SIZE, &value);
483 if (8 != value) {
484 return false;
486 eglGetConfigAttrib(_eglDisplay, config, EGL_GREEN_SIZE, &value);
487 if (8 != value) {
488 return false;
490 eglGetConfigAttrib(_eglDisplay, config, EGL_BLUE_SIZE, &value);
491 if (8 != value) {
492 return false;
494 eglGetConfigAttrib(_eglDisplay, config, EGL_ALPHA_SIZE, &value);
495 if (0 != value) {
496 return false;
498 eglGetConfigAttrib(_eglDisplay, config, EGL_SAMPLES, &value);
499 if (0 != value) {
500 return false;
502 } else if (_bpp == 16) {
503 eglGetConfigAttrib(_eglDisplay, config, EGL_RED_SIZE, &value);
504 if ( 5 != value ) {
505 return false;
507 eglGetConfigAttrib(_eglDisplay, config, EGL_GREEN_SIZE, &value);
508 if (6 != value) {
509 return false;
511 eglGetConfigAttrib(_eglDisplay, config, EGL_BLUE_SIZE, &value);
512 if (5 != value) {
513 return false;
515 eglGetConfigAttrib(_eglDisplay, config, EGL_ALPHA_SIZE, &value);
516 if (0 != value) {
517 return false;
519 eglGetConfigAttrib(_eglDisplay, config, EGL_SAMPLES, &value);
520 #ifdef RENDERER_GLES
521 if (4 != value) {
522 return false;
524 #endif
525 #ifdef RENDERER_OPENVG
526 if (0 != value) {
527 return false;
529 #endif
530 } else {
531 return false;
534 return true;
537 /// Query the system for all supported configs
539 EGLDevice::queryEGLConfig(EGLDisplay display)
541 GNASH_REPORT_FUNCTION;
542 EGLConfig *configs = 0;
543 EGLint max_num_config = 0;
545 // Get the number of supported configurations
546 if ( EGL_FALSE == eglGetConfigs(display, 0, 0, &max_num_config) ) {
547 log_error(_("eglGetConfigs() failed to retrieve the number of configs (error %s)"),
548 getErrorString(eglGetError()));
549 return 0;
551 if(max_num_config <= 0) {
552 log_error(_("No EGLconfigs found\n"));
553 return 0;
555 log_debug(_("Max number of EGL Configs is %d"), max_num_config);
557 configs = new EGLConfig[max_num_config];
558 if (0 == configs) {
559 log_error(_("Out of memory\n"));
560 return 0;
563 if ( EGL_FALSE == eglGetConfigs(display, configs, max_num_config, &max_num_config)) {
564 log_error(_("eglGetConfigs() failed to retrieve the configs (error %s)"),
565 getErrorString(eglGetError()));
566 return 0;
569 #if 0
570 // This prints out all the configurations, so it can be quite large
571 for (int i=0; i<max_num_config; i++ ) {
572 std::cerr << "Config[" << i << "] is:" << std::endl;
573 printEGLConfig(configs[i]);
575 #endif
577 return max_num_config;
580 void
581 EGLDevice::printEGLAttribs(const EGLint *attrib)
583 if (attrib) {
584 std::cout << "Printing EGL Attributes list" << std::endl;
585 int i = 0;
586 while (attrib[i] != EGL_NONE) {
587 switch (attrib[i]) {
588 case EGL_RED_SIZE:
589 std::cout << "\tRed: " << attrib[i+1];
590 break;
591 case EGL_GREEN_SIZE:
592 std::cout << ", Green: " << attrib[i+1];
593 break;
594 case EGL_BLUE_SIZE:
595 std::cout << ", Blue: " << attrib[i+1] << std::endl;
596 break;
597 case EGL_DEPTH_SIZE:
598 std::cout << ", Depth: " << attrib[i+1] << std::endl;
599 break;
600 case EGL_RENDERABLE_TYPE:
601 if (attrib[i+1] & EGL_OPENVG_BIT) {
602 std::cout << "\tOpenVG Renderable" << std::endl;
604 if (attrib[i+1] & EGL_OPENGL_ES_BIT) {
605 std::cout << "\tOpenGLES1 Renderable" << std::endl;
607 if (attrib[i+1] & EGL_OPENGL_ES2_BIT) {
608 std::cout << "\tOpenGLES2 Renderable" << std::endl;
610 break;
611 default:
612 break;
614 i+=2;
617 std::cout << "----------------------------------" << std::endl;
620 void
621 EGLDevice::printEGLConfig(EGLConfig config)
623 EGLint red, blue, green;
624 EGLint value;
625 eglGetConfigAttrib(_eglDisplay, config, EGL_RED_SIZE, &red);
626 eglGetConfigAttrib(_eglDisplay, config, EGL_GREEN_SIZE, &green);
627 eglGetConfigAttrib(_eglDisplay, config, EGL_BLUE_SIZE, &blue);
628 std::cout << "\tConfig has RED = " << red << ", GREEN = " << green
629 << ", BLUE = " << blue << std::endl;
631 eglGetConfigAttrib(_eglDisplay, config, EGL_BUFFER_SIZE, &value);
632 std::cout << "\tEGL_BUFFER_SIZE is " << value << std::endl;
633 eglGetConfigAttrib(_eglDisplay, config, EGL_ALPHA_SIZE, &value);
634 std::cout << "\tEGL_ALPHA_SIZE is " << value << std::endl;
635 eglGetConfigAttrib(_eglDisplay, config, EGL_ALPHA_MASK_SIZE, &value);
636 std::cout << "\tEGL_ALPHA_MASK_SIZE is " << value << std::endl;
637 eglGetConfigAttrib(_eglDisplay, config, EGL_STENCIL_SIZE, &value);
638 std::cout << "\tEGL_STENCIL_SIZE is " << value << std::endl;
639 eglGetConfigAttrib(_eglDisplay, config, EGL_SAMPLES, &value);
640 std::cout << "\tEGL_SAMPLES is " << value << std::endl;
641 eglGetConfigAttrib(_eglDisplay, config, EGL_DEPTH_SIZE, &value);
642 std::cout << "\tEGL_DEPTH_SIZE is " << value << std::endl;
643 eglGetConfigAttrib(_eglDisplay, config, EGL_MAX_SWAP_INTERVAL, &value);
644 std::cout << "\tEGL_MAX_SWAP_INTERVAL is " << value << std::endl;
645 eglGetConfigAttrib(_eglDisplay, config, EGL_MIN_SWAP_INTERVAL, &value);
646 std::cout << "\tEGL_MIN_SWAP_INTERVAL is " << value << std::endl;
647 eglGetConfigAttrib(_eglDisplay, config, EGL_NATIVE_RENDERABLE, &value);
648 std::string val = (value)? "true" : "false";
649 std::cout << "\tEGL_NATIVE_RENDERABLE is " << val << std::endl;
650 eglGetConfigAttrib(_eglDisplay, config, EGL_SAMPLE_BUFFERS, &value);
651 std::cout << "\tEGL_SAMPLE_BUFFERS is " << value << std::endl;
652 eglGetConfigAttrib(_eglDisplay, config, EGL_RENDERABLE_TYPE, &value);
653 if (value > 0) {
654 std::string str;
655 if (value & EGL_OPENGL_ES2_BIT) {
656 str += " OpenGL-ES 2.0";
658 if (value & EGL_OPENGL_ES_BIT) {
659 str += " OpenGL-ES 1.1";
661 if (value & EGL_OPENVG_BIT) {
662 str += " OpenVG";
664 if (value & EGL_OPENGL_BIT) {
665 str += " OpenGL";
667 std::cout <<"\tEGL_RENDERABLE_TYPE = " << str << std::endl;
668 } else {
669 std::cout <<"\tEGL_RENDERABLE_TYPE (default)" << std::endl;
671 eglGetConfigAttrib(_eglDisplay, config, EGL_SURFACE_TYPE, &value);
672 if (value > 0) {
673 std::string str;
674 if (value & EGL_WINDOW_BIT) {
675 str += " Window";
677 if (value & EGL_PIXMAP_BIT) {
678 str += " Pixmap";
680 if (value & EGL_PBUFFER_BIT) {
681 str += " Pbuffer";
683 std::cout <<"\tEGL_SURFACE_TYPE = " << str << std::endl;
684 } else {
685 std::cout <<"\tEGL_SURFACE_TYPE (default)" << std::endl;
688 eglGetConfigAttrib(_eglDisplay, config, EGL_CONFIG_CAVEAT, &value);
689 if (value > 0) {
690 std::string str;
691 if (value & EGL_NONE) {
692 str += " EGL_NONE";
694 if (value & EGL_SLOW_CONFIG) {
695 str += " EGL_SLOW_CONFIG";
697 if (value & EGL_NON_CONFORMANT_CONFIG) {
698 str += " EGL_NON_CONFORMANT_CONFIG";
700 std::cout <<"\tEGL_CONFIG_CAVEAT = " << str << std::endl;
701 } else {
702 std::cout <<"\tEGL_CONFIG_CAVEAT (default)" << std::endl;
705 #ifdef BUILD_X11_DEVICE
706 eglGetConfigAttrib(_eglDisplay, config, EGL_NATIVE_VISUAL_ID, &value);
707 std::cout << "\tX11 Visual is: " << value << std::endl;
708 #endif
710 eglGetConfigAttrib(_eglDisplay, config, EGL_BIND_TO_TEXTURE_RGB, &value);
711 val = (value)? "true" : "false";
712 std::cout << "\tEGL_BIND_TO_TEXTURE_RGB is " << val << std::endl;
714 eglGetConfigAttrib(_eglDisplay, config, EGL_BIND_TO_TEXTURE_RGBA, &value);
715 val = (value)? "true" : "false";
716 std::cout << "\tEGL_BIND_TO_TEXTURE_RGBA is " << val << std::endl;
720 void
721 EGLDevice::printEGLContext(EGLContext context)
723 EGLint value;
724 eglQueryContext(_eglDisplay, context, EGL_CONFIG_ID, &value);
725 std::cout << "Context EGL_CONFIG_ID is " << value << std::endl;
726 eglQueryContext(_eglDisplay, context, EGL_CONTEXT_CLIENT_TYPE, &value);
727 std::cout << "\tEGL_CONTEXT_CLIENT_TYPE is "
728 << std::string((value == EGL_OPENVG_API)
729 ? "EGL_OPENVG_API" : "EGL_OPENGL_ES_API") << std::endl;
730 // eglQueryContext(_eglDisplay, context, EGL_CONTEXT_CLIENT_VERSION, &value);
731 // log_debug("EGL_CONTEXT_CLIENT_VERSION is %d", value);
732 eglQueryContext(_eglDisplay, context, EGL_RENDER_BUFFER, &value);
733 std::cout << "\tEGL_RENDER_BUFFER is " << std::string((value == EGL_BACK_BUFFER)
734 ? "EGL_BACK_BUFFER" : "EGL_SINGLE_BUFFER") << std::endl;
737 void
738 EGLDevice::printEGLSurface(EGLSurface surface)
740 EGLint value;
741 eglQuerySurface(_eglDisplay, surface, EGL_CONFIG_ID, &value);
742 std::cout << "Surface EGL_CONFIG_ID is " << value << std::endl;
743 eglQuerySurface(_eglDisplay, surface, EGL_HEIGHT, &value);
744 std::cout << "\tEGL_HEIGHT is " << value<< std::endl;
745 eglQuerySurface(_eglDisplay, surface, EGL_WIDTH, &value);
746 std::cout << "\tEGL_WIDTH is " << value << std::endl;
747 eglQuerySurface(_eglDisplay, surface, EGL_RENDER_BUFFER, &value);
748 std::cout << "\tEGL_RENDER_BUFFER is " << std::string((value == EGL_BACK_BUFFER)
749 ? "EGL_BACK_BUFFER" : "EGL_SINGLE_BUFFER") << std::endl;
750 eglQuerySurface(_eglDisplay, surface, EGL_VERTICAL_RESOLUTION, &value);
751 std::cout << "\tEGL_VERTICAL_RESOLUTION is " << value << std::endl;
752 eglQuerySurface(_eglDisplay, surface, EGL_HORIZONTAL_RESOLUTION, &value);
753 std::cout << "\tEGL_HORIZONTAL_RESOLUTION is " << value << std::endl;
754 eglQuerySurface(_eglDisplay, surface, EGL_SWAP_BEHAVIOR, &value);
755 std::cout << "\tEGL_SWAP_BEHAVIOR is "
756 << std::string((value == EGL_BUFFER_DESTROYED)
757 ? "EGL_BUFFER_DESTROYED" : "EGL_BUFFER_PRESERVED") << std::endl;
758 eglQuerySurface(_eglDisplay, surface, EGL_MULTISAMPLE_RESOLVE, &value);
759 std::cout << "\tEGL_MULTISAMPLE_RESOLVE is "
760 << std::string((value == EGL_MULTISAMPLE_RESOLVE_BOX)
761 ? "EGL_MULTISAMPLE_RESOLVE_BOX" : "EGL_MULTISAMPLE_RESOLVE_DEFAULT") << std::endl;
764 // EGL WIDTH, EGL HEIGHT, EGL LARGEST PBUFFER, EGL TEXTURE FORMAT,
765 // EGL TEXTURE TARGET, EGL MIPMAP TEXTURE, EGL COLORSPACE, and EGL ALPHA FORMAT.
766 EGLSurface
767 EGLDevice::createPbuffer(int width, int height)
769 const EGLint attribs[] = {
770 EGL_WIDTH, width,
771 EGL_HEIGHT, height,
772 EGL_NONE
775 EGLSurface pbuf = eglCreatePbufferSurface(_eglDisplay, _eglConfig, attribs);
776 if (pbuf == EGL_NO_SURFACE) {
777 log_error(_( "eglCreatePbufferSurface() failed (error 0x%x)"), eglGetError());
778 return EGL_NO_SURFACE;
781 _pbuffers.push_back(pbuf);
783 return pbuf;
785 EGLSurface
786 EGLDevice::createPbuffer(int width, int height, EGLClientBuffer buf, EGLenum type)
788 const EGLint attribs[] = {
789 EGL_WIDTH, width,
790 EGL_HEIGHT, height,
791 EGL_NONE
794 EGLSurface pbuf = eglCreatePbufferFromClientBuffer(_eglDisplay, type, buf,
795 _eglConfig, attribs);
796 if (pbuf == EGL_NO_SURFACE) {
797 log_error(_("eglCreatePbufferFromClientBuffer() failed (error 0x%x)"),
798 eglGetError());
799 return EGL_NO_SURFACE;
802 _pbuffers.push_back(pbuf);
804 return pbuf;
807 EGLSurface
808 EGLDevice::createPixmap(int width, int height, NativePixmapType buf)
810 const EGLint attribs[] = {
811 EGL_WIDTH, width,
812 EGL_HEIGHT, height,
813 EGL_NONE
816 EGLSurface pbuf = eglCreatePixmapSurface(_eglDisplay, _eglConfig, buf, attribs);
817 if (pbuf == EGL_NO_SURFACE) {
818 log_error(_("eglCreatePbufferFromClientBuffer() failed (error 0x%x)"),
819 eglGetError());
820 return EGL_NO_SURFACE;
823 _pbuffers.push_back(pbuf);
825 return pbuf;
828 // Set the bitmask for the configured renderable types.
829 EGLint
830 EGLDevice::getRenderableTypes()
832 EGLint type = 0;
833 #ifdef RENDERER_GLES1
834 type = type | EGL_OPENGL_ES_BIT;
835 #endif
836 #ifdef RENDERER_GLES2
837 type = type | EGL_OPENGL_ES2_BIT;
838 #endif
839 #ifdef RENDERER_OPENVG
840 type = type | EGL_OPENVG_BIT;
841 #endif
842 return type;
847 } // namespace renderer
848 } // namespace gnash
850 // local Variables:
851 // mode: C++
852 // indent-tabs-mode: nil
853 // End: