Extensions.cpp revision 8762e332e3797fb41929a1c6069207f4906ca329
1/*
2 * Copyright (C) 2013 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 "Extensions.h"
18
19#include "Debug.h"
20#include "Properties.h"
21#include "utils/StringUtils.h"
22
23#include <GLES2/gl2.h>
24#include <GLES2/gl2ext.h>
25
26#include <utils/Log.h>
27
28namespace android {
29namespace uirenderer {
30
31// Debug
32#if DEBUG_EXTENSIONS
33    #define EXT_LOGD(...) ALOGD(__VA_ARGS__)
34#else
35    #define EXT_LOGD(...)
36#endif
37
38
39Extensions::Extensions() {
40    auto extensions = StringUtils::split((const char*) glGetString(GL_EXTENSIONS));
41    mHasNPot = extensions.has("GL_OES_texture_npot");
42    mHasFramebufferFetch = extensions.has("GL_NV_shader_framebuffer_fetch");
43    mHasDiscardFramebuffer = extensions.has("GL_EXT_discard_framebuffer");
44    mHasDebugMarker = extensions.has("GL_EXT_debug_marker");
45    mHas1BitStencil = extensions.has("GL_OES_stencil1");
46    mHas4BitStencil = extensions.has("GL_OES_stencil4");
47    mHasUnpackSubImage = extensions.has("GL_EXT_unpack_subimage");
48
49#ifdef ANDROID_ENABLE_LINEAR_BLENDING
50    mHasSRGB = mVersionMajor >= 3 || extensions.has("GL_EXT_sRGB");
51    mHasSRGBWriteControl = extensions.has("GL_EXT_sRGB_write_control");
52
53    // If linear blending is enabled, the device must have (ES3.0 or EXT_sRGB)
54    // and EXT_sRGB_write_control
55    LOG_ALWAYS_FATAL_IF(!mHasSRGB, "Linear blending requires ES 3.0 or EXT_sRGB");
56    LOG_ALWAYS_FATAL_IF(!mHasSRGBWriteControl, "Linear blending requires EXT_sRGB_write_control");
57#else
58    mHasSRGB = false;
59    mHasSRGBWriteControl = false;
60#endif
61
62    const char* version = (const char*) glGetString(GL_VERSION);
63
64    // Section 6.1.5 of the OpenGL ES specification indicates the GL version
65    // string strictly follows this format:
66    //
67    // OpenGL<space>ES<space><version number><space><vendor-specific information>
68    //
69    // In addition section 6.1.5 describes the version number thusly:
70    //
71    // "The version number is either of the form major number.minor number or
72    // major number.minor number.release number, where the numbers all have one
73    // or more digits. The release number and vendor specific information are
74    // optional."
75
76    if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) {
77        // If we cannot parse the version number, assume OpenGL ES 2.0
78        mVersionMajor = 2;
79        mVersionMinor = 0;
80    }
81}
82
83}; // namespace uirenderer
84}; // namespace android
85