Home | History | Annotate | Download | only in RenderEngine
      1 /*
      2  * Copyright (C) 2010 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 #include <stdint.h>
     18 #include <stdio.h>
     19 #include <stdlib.h>
     20 
     21 #include "GLExtensions.h"
     22 
     23 namespace android {
     24 // ---------------------------------------------------------------------------
     25 
     26 ANDROID_SINGLETON_STATIC_INSTANCE(GLExtensions)
     27 
     28 SortedVector<String8> GLExtensions::parseExtensionString(char const* extensions) {
     29     SortedVector<String8> list;
     30 
     31     char const* curr = extensions;
     32     char const* head = curr;
     33     do {
     34         head = strchr(curr, ' ');
     35         String8 s(curr, head ? head - curr : strlen(curr));
     36         if (s.length()) {
     37             list.add(s);
     38         }
     39         curr = head + 1;
     40     } while (head);
     41 
     42     return list;
     43 }
     44 
     45 void GLExtensions::initWithGLStrings(GLubyte const* vendor, GLubyte const* renderer,
     46                                      GLubyte const* version, GLubyte const* extensions) {
     47     mVendor = (char const*)vendor;
     48     mRenderer = (char const*)renderer;
     49     mVersion = (char const*)version;
     50     mExtensions = (char const*)extensions;
     51     mExtensionList = parseExtensionString(mExtensions);
     52 }
     53 
     54 bool GLExtensions::hasExtension(char const* extension) const {
     55     const String8 s(extension);
     56     return mExtensionList.indexOf(s) >= 0;
     57 }
     58 
     59 char const* GLExtensions::getVendor() const {
     60     return mVendor.string();
     61 }
     62 
     63 char const* GLExtensions::getRenderer() const {
     64     return mRenderer.string();
     65 }
     66 
     67 char const* GLExtensions::getVersion() const {
     68     return mVersion.string();
     69 }
     70 
     71 char const* GLExtensions::getExtensions() const {
     72     return mExtensions.string();
     73 }
     74 
     75 void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExtensions) {
     76     mEGLVersion = eglVersion;
     77     mEGLExtensions = eglExtensions;
     78     mEGLExtensionList = parseExtensionString(mEGLExtensions);
     79 
     80     // EGL_ANDROIDX_no_config_context is an experimental extension with no
     81     // written specification. It will be replaced by something more formal.
     82     // SurfaceFlinger is using it to allow a single EGLContext to render to
     83     // both a 16-bit primary display framebuffer and a 32-bit virtual display
     84     // framebuffer.
     85     //
     86     // EGL_KHR_no_config_context is official extension to allow creating a
     87     // context that works with any surface of a display.
     88     if (hasEGLExtension("EGL_ANDROIDX_no_config_context") ||
     89         hasEGLExtension("EGL_KHR_no_config_context")) {
     90         mHasNoConfigContext = true;
     91     }
     92 
     93     if (hasEGLExtension("EGL_ANDROID_native_fence_sync")) {
     94         mHasNativeFenceSync = true;
     95     }
     96     if (hasEGLExtension("EGL_KHR_fence_sync")) {
     97         mHasFenceSync = true;
     98     }
     99     if (hasEGLExtension("EGL_KHR_wait_sync")) {
    100         mHasWaitSync = true;
    101     }
    102 
    103     if (hasEGLExtension("EGL_ANDROID_image_crop")) {
    104         mHasImageCrop = true;
    105     }
    106     if (hasEGLExtension("EGL_EXT_protected_content")) {
    107         mHasProtectedContent = true;
    108     }
    109     if (hasEGLExtension("EGL_IMG_context_priority")) {
    110         mHasContextPriority = true;
    111     }
    112 }
    113 
    114 char const* GLExtensions::getEGLVersion() const {
    115     return mEGLVersion.string();
    116 }
    117 
    118 char const* GLExtensions::getEGLExtensions() const {
    119     return mEGLExtensions.string();
    120 }
    121 
    122 bool GLExtensions::hasEGLExtension(char const* extension) const {
    123     const String8 s(extension);
    124     return mEGLExtensionList.indexOf(s) >= 0;
    125 }
    126 
    127 // ---------------------------------------------------------------------------
    128 }; // namespace android
    129