| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <EGL/egl.h> | |
| 6 #include <EGL/eglext.h> | |
| 7 #include <gdk/gdkx.h> | |
| 8 #include <gtk/gtk.h> | |
| 9 | |
| 10 extern "C" { | |
| 11 #if defined(GLES2_CONFORM_SUPPORT_ONLY) | |
| 12 #include "gpu/gles2_conform_support/gtf/gtf_stubs.h" | |
| 13 #else | |
| 14 #include "third_party/gles2_conform/GTF_ES/glsl/GTF/Source/eglNative.h" | |
| 15 #endif | |
| 16 } | |
| 17 | |
| 18 | |
| 19 GTFbool GTFNativeCreateDisplay(EGLNativeDisplayType *pNativeDisplay) { | |
| 20 int argc = 0; | |
| 21 char **argv = NULL; | |
| 22 gtk_init(&argc, &argv); | |
| 23 *pNativeDisplay = GDK_DISPLAY();; | |
| 24 return *pNativeDisplay ? GTFtrue : GTFfalse; | |
| 25 } | |
| 26 | |
| 27 void GTFNativeDestroyDisplay(EGLNativeDisplayType nativeDisplay) { | |
| 28 gtk_exit(0); | |
| 29 } | |
| 30 | |
| 31 GTFbool GTFNativeCreateWindow(EGLNativeDisplayType nativeDisplay, | |
| 32 EGLDisplay eglDisplay, EGLConfig eglConfig, | |
| 33 const char* title, int width, int height, | |
| 34 EGLNativeWindowType *pNativeWindow) { | |
| 35 #ifdef CHROMEOS_GLES2_CONFORMANCE | |
| 36 // Due to the behavior of ChromeOS window manager, which always resize the | |
| 37 // top level window etc, we had to create a popup window. | |
| 38 GtkWidget* hwnd = gtk_window_new(GTK_WINDOW_POPUP); | |
| 39 #else | |
| 40 GtkWidget* hwnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 41 #endif | |
| 42 | |
| 43 gtk_window_set_title(GTK_WINDOW(hwnd), title); | |
| 44 gtk_window_set_default_size(GTK_WINDOW(hwnd), width, height); | |
| 45 gtk_widget_set_double_buffered(hwnd, FALSE); | |
| 46 gtk_widget_set_app_paintable(hwnd, TRUE); | |
| 47 | |
| 48 // We had to enter gtk main loop to realize the window on ChromeOS. | |
| 49 gtk_widget_show_now(hwnd); | |
| 50 | |
| 51 *pNativeWindow = GDK_WINDOW_XWINDOW(hwnd->window); | |
| 52 | |
| 53 return GTFtrue; | |
| 54 } | |
| 55 | |
| 56 void GTFNativeDestroyWindow(EGLNativeDisplayType nativeDisplay, | |
| 57 EGLNativeWindowType nativeWindow) { | |
| 58 GdkWindow* window = gdk_window_lookup(nativeWindow); | |
| 59 gpointer widget = NULL; | |
| 60 gdk_window_get_user_data(window, &widget); | |
| 61 gtk_widget_destroy(GTK_WIDGET(widget)); | |
| 62 } | |
| 63 | |
| 64 EGLImageKHR GTFCreateEGLImage(int width, int height, | |
| 65 GLenum format, GLenum type) { | |
| 66 PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr_; | |
| 67 egl_create_image_khr_ = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC> | |
| 68 (eglGetProcAddress("eglCreateImageKHR")); | |
| 69 | |
| 70 static const EGLint attrib[] = { | |
| 71 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, | |
| 72 EGL_GL_TEXTURE_LEVEL_KHR, 0, | |
| 73 EGL_NONE | |
| 74 }; | |
| 75 | |
| 76 if (format != GL_RGBA && format != GL_RGB) | |
| 77 return static_cast<EGLImageKHR>(NULL); | |
| 78 | |
| 79 if (type != GL_UNSIGNED_BYTE) | |
| 80 return static_cast<EGLImageKHR>(NULL); | |
| 81 | |
| 82 GLuint texture; | |
| 83 glGenTextures(1, &texture); | |
| 84 glBindTexture(GL_TEXTURE_2D, texture); | |
| 85 glTexImage2D(GL_TEXTURE_2D, | |
| 86 0, | |
| 87 format, | |
| 88 width, | |
| 89 height, | |
| 90 0, | |
| 91 format, | |
| 92 type, | |
| 93 NULL); | |
| 94 | |
| 95 // Disable mip-maps because we do not require it. | |
| 96 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 97 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 98 | |
| 99 if(glGetError() != GL_NO_ERROR) | |
| 100 return static_cast<EGLImageKHR>(NULL); | |
| 101 | |
| 102 EGLImageKHR egl_image = | |
| 103 egl_create_image_khr_(eglGetCurrentDisplay(), | |
| 104 eglGetCurrentContext(), | |
| 105 EGL_GL_TEXTURE_2D_KHR, | |
| 106 reinterpret_cast<EGLClientBuffer>(texture), | |
| 107 attrib); | |
| 108 | |
| 109 if (eglGetError() == EGL_SUCCESS) | |
| 110 return egl_image; | |
| 111 else | |
| 112 return static_cast<EGLImageKHR>(NULL); | |
| 113 } | |
| 114 | |
| 115 void GTFDestroyEGLImage(EGLImageKHR image) { | |
| 116 PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr_; | |
| 117 egl_destroy_image_khr_ = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC> | |
| 118 (eglGetProcAddress("eglDestroyImageKHR")); | |
| 119 | |
| 120 egl_destroy_image_khr_(eglGetCurrentDisplay(), image); | |
| 121 } | |
| OLD | NEW |