Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

eglscreen.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included
  12. * in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  18. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. /*
  22. * Stolen from eglgears
  23. *
  24. * Creates a surface and show that on the first screen
  25. */
  26. #define EGL_EGLEXT_PROTOTYPES
  27. #include <assert.h>
  28. #include <math.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <GL/gl.h>
  33. #include <EGL/egl.h>
  34. #include <EGL/eglext.h>
  35. #define MAX_CONFIGS 10
  36. #define MAX_MODES 100
  37. int
  38. main(int argc, char *argv[])
  39. {
  40. int maj, min;
  41. EGLSurface screen_surf;
  42. EGLConfig configs[MAX_CONFIGS];
  43. EGLint numConfigs, i;
  44. EGLBoolean b;
  45. EGLDisplay d;
  46. EGLint screenAttribs[10];
  47. EGLModeMESA mode[MAX_MODES];
  48. EGLScreenMESA screen;
  49. EGLint count, chosenMode;
  50. EGLint width = 0, height = 0;
  51. d = eglGetDisplay((EGLNativeDisplayType)"!EGL_i915");
  52. assert(d);
  53. if (!eglInitialize(d, &maj, &min)) {
  54. printf("eglscreen: eglInitialize failed\n");
  55. exit(1);
  56. }
  57. printf("eglscreen: EGL version = %d.%d\n", maj, min);
  58. printf("eglscreen: EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
  59. /* XXX use ChooseConfig */
  60. eglGetConfigs(d, configs, MAX_CONFIGS, &numConfigs);
  61. eglGetScreensMESA(d, &screen, 1, &count);
  62. if (!eglGetModesMESA(d, screen, mode, MAX_MODES, &count) || count == 0) {
  63. printf("eglscreen: eglGetModesMESA failed!\n");
  64. return 0;
  65. }
  66. /* Print list of modes, and find the one to use */
  67. printf("eglscreen: Found %d modes:\n", count);
  68. for (i = 0; i < count; i++) {
  69. EGLint w, h;
  70. eglGetModeAttribMESA(d, mode[i], EGL_WIDTH, &w);
  71. eglGetModeAttribMESA(d, mode[i], EGL_HEIGHT, &h);
  72. printf("%3d: %d x %d\n", i, w, h);
  73. if (w > width && h > height) {
  74. width = w;
  75. height = h;
  76. chosenMode = i;
  77. }
  78. }
  79. printf("eglscreen: Using screen mode/size %d: %d x %d\n", chosenMode, width, height);
  80. /* build up screenAttribs array */
  81. i = 0;
  82. screenAttribs[i++] = EGL_WIDTH;
  83. screenAttribs[i++] = width;
  84. screenAttribs[i++] = EGL_HEIGHT;
  85. screenAttribs[i++] = height;
  86. screenAttribs[i++] = EGL_NONE;
  87. screen_surf = eglCreateScreenSurfaceMESA(d, configs[0], screenAttribs);
  88. if (screen_surf == EGL_NO_SURFACE) {
  89. printf("eglscreen: Failed to create screen surface\n");
  90. return 0;
  91. }
  92. b = eglShowScreenSurfaceMESA(d, screen, screen_surf, mode[chosenMode]);
  93. if (!b) {
  94. printf("eglscreen: Show surface failed\n");
  95. return 0;
  96. }
  97. eglDestroySurface(d, screen_surf);
  98. eglTerminate(d);
  99. return 0;
  100. }