| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2009 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 |  | 
|  | 18 | #define LOG_TAG "EGLUtils" | 
|  | 19 |  | 
| Mathias Agopian | 8c12c7a | 2009-08-07 16:37:21 -0700 | [diff] [blame] | 20 | #include <cutils/log.h> | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 21 | #include <utils/Errors.h> | 
|  | 22 |  | 
|  | 23 | #include <ui/EGLUtils.h> | 
|  | 24 |  | 
|  | 25 | #include <EGL/egl.h> | 
|  | 26 |  | 
|  | 27 | #include <private/ui/android_natives_priv.h> | 
|  | 28 |  | 
|  | 29 | // ---------------------------------------------------------------------------- | 
|  | 30 | namespace android { | 
|  | 31 | // ---------------------------------------------------------------------------- | 
|  | 32 |  | 
| Mathias Agopian | 8c12c7a | 2009-08-07 16:37:21 -0700 | [diff] [blame] | 33 | const char *EGLUtils::strerror(EGLint err) | 
|  | 34 | { | 
|  | 35 | switch (err){ | 
|  | 36 | case EGL_SUCCESS:           return "EGL_SUCCESS"; | 
|  | 37 | case EGL_NOT_INITIALIZED:   return "EGL_NOT_INITIALIZED"; | 
|  | 38 | case EGL_BAD_ACCESS:        return "EGL_BAD_ACCESS"; | 
|  | 39 | case EGL_BAD_ALLOC:         return "EGL_BAD_ALLOC"; | 
|  | 40 | case EGL_BAD_ATTRIBUTE:     return "EGL_BAD_ATTRIBUTE"; | 
|  | 41 | case EGL_BAD_CONFIG:        return "EGL_BAD_CONFIG"; | 
|  | 42 | case EGL_BAD_CONTEXT:       return "EGL_BAD_CONTEXT"; | 
|  | 43 | case EGL_BAD_CURRENT_SURFACE: return "EGL_BAD_CURRENT_SURFACE"; | 
|  | 44 | case EGL_BAD_DISPLAY:       return "EGL_BAD_DISPLAY"; | 
|  | 45 | case EGL_BAD_MATCH:         return "EGL_BAD_MATCH"; | 
|  | 46 | case EGL_BAD_NATIVE_PIXMAP: return "EGL_BAD_NATIVE_PIXMAP"; | 
|  | 47 | case EGL_BAD_NATIVE_WINDOW: return "EGL_BAD_NATIVE_WINDOW"; | 
|  | 48 | case EGL_BAD_PARAMETER:     return "EGL_BAD_PARAMETER"; | 
|  | 49 | case EGL_BAD_SURFACE:       return "EGL_BAD_SURFACE"; | 
|  | 50 | case EGL_CONTEXT_LOST:      return "EGL_CONTEXT_LOST"; | 
|  | 51 | default: return "UNKNOWN"; | 
|  | 52 | } | 
|  | 53 | } | 
|  | 54 |  | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 55 | status_t EGLUtils::selectConfigForPixelFormat( | 
|  | 56 | EGLDisplay dpy, | 
|  | 57 | EGLint const* attrs, | 
|  | 58 | PixelFormat format, | 
|  | 59 | EGLConfig* outConfig) | 
|  | 60 | { | 
|  | 61 | EGLint numConfigs = -1, n=0; | 
|  | 62 |  | 
| Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 63 | if (!attrs) | 
|  | 64 | return BAD_VALUE; | 
|  | 65 |  | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 66 | if (outConfig == NULL) | 
|  | 67 | return BAD_VALUE; | 
|  | 68 |  | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 69 | // Get all the "potential match" configs... | 
|  | 70 | if (eglGetConfigs(dpy, NULL, 0, &numConfigs) == EGL_FALSE) | 
|  | 71 | return BAD_VALUE; | 
|  | 72 |  | 
|  | 73 | EGLConfig* const configs = (EGLConfig*)malloc(sizeof(EGLConfig)*numConfigs); | 
|  | 74 | if (eglChooseConfig(dpy, attrs, configs, numConfigs, &n) == EGL_FALSE) { | 
|  | 75 | free(configs); | 
|  | 76 | return BAD_VALUE; | 
|  | 77 | } | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 78 |  | 
| Mathias Agopian | b97603d | 2009-08-06 17:14:10 -0700 | [diff] [blame] | 79 | int i; | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 80 | EGLConfig config = NULL; | 
| Mathias Agopian | b97603d | 2009-08-06 17:14:10 -0700 | [diff] [blame] | 81 | for (i=0 ; i<n ; i++) { | 
| Mathias Agopian | d5ea3db | 2011-01-16 17:57:20 -0800 | [diff] [blame] | 82 | EGLint nativeVisualId = 0; | 
|  | 83 | eglGetConfigAttrib(dpy, configs[i], EGL_NATIVE_VISUAL_ID, &nativeVisualId); | 
|  | 84 | if (nativeVisualId>0 && format == nativeVisualId) { | 
|  | 85 | config = configs[i]; | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 86 | break; | 
|  | 87 | } | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | free(configs); | 
|  | 91 |  | 
| Mathias Agopian | b97603d | 2009-08-06 17:14:10 -0700 | [diff] [blame] | 92 | if (i<n) { | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 93 | *outConfig = config; | 
|  | 94 | return NO_ERROR; | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | return NAME_NOT_FOUND; | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | status_t EGLUtils::selectConfigForNativeWindow( | 
|  | 101 | EGLDisplay dpy, | 
|  | 102 | EGLint const* attrs, | 
|  | 103 | EGLNativeWindowType window, | 
|  | 104 | EGLConfig* outConfig) | 
|  | 105 | { | 
|  | 106 | int err; | 
|  | 107 | int format; | 
| Mathias Agopian | 42db9dc | 2009-08-06 20:46:44 -0700 | [diff] [blame] | 108 |  | 
|  | 109 | if (!window) | 
|  | 110 | return BAD_VALUE; | 
|  | 111 |  | 
| Mathias Agopian | 6cf50a7 | 2009-08-06 16:05:39 -0700 | [diff] [blame] | 112 | if ((err = window->query(window, NATIVE_WINDOW_FORMAT, &format)) < 0) { | 
|  | 113 | return err; | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | return selectConfigForPixelFormat(dpy, attrs, format, outConfig); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | // ---------------------------------------------------------------------------- | 
|  | 120 | }; // namespace android | 
|  | 121 | // ---------------------------------------------------------------------------- |