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