blob: 0919e82a003b035fd2a64dc6e21330b0b61ba4bc [file] [log] [blame]
Romain Guy3bbacf22013-02-06 16:51:04 -08001/*
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
Chris Craik117bdbc2015-02-05 10:12:38 -080017#include "Extensions.h"
18
19#include "Debug.h"
20#include "Properties.h"
Chris Craik6e6646c2015-09-14 15:54:12 -070021#include "utils/StringUtils.h"
Romain Guye9bc11f2013-05-23 12:47:26 -070022
Romain Guyefb4b062017-02-27 11:00:04 -080023#include <cutils/compiler.h>
24
John Reck6b507802015-11-03 10:09:59 -080025#include <GLES2/gl2.h>
Chris Craik117bdbc2015-02-05 10:12:38 -080026#include <GLES2/gl2ext.h>
Romain Guy253f2c22016-09-28 17:34:42 -070027
Romain Guye9bc11f2013-05-23 12:47:26 -070028#include <utils/Log.h>
29
Romain Guy3bbacf22013-02-06 16:51:04 -080030namespace android {
Romain Guy3bbacf22013-02-06 16:51:04 -080031namespace uirenderer {
32
John Reck15401532015-11-16 10:40:31 -080033Extensions::Extensions() {
Stan Iliev7475d0f2017-10-31 11:47:54 -040034 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) {
35 //Extensions class is used only by OpenGL and SkiaGL pipelines
Stan Ilievd56d2182017-10-18 13:12:32 -040036 //The code below will crash for SkiaVulkan, because OpenGL is not initialized
37 //TODO: instantiate Extensions class only for OpenGL pipeline
Stan Iliev7475d0f2017-10-31 11:47:54 -040038 //TODO: remove the only usage of Extensions by SkiaGL in SkiaOpenGLReadback::copyImageInto
Stan Ilievd56d2182017-10-18 13:12:32 -040039 return;
40 }
Romain Guyb136c852016-12-01 09:50:49 -080041 const char* version = (const char*) glGetString(GL_VERSION);
42
43 // Section 6.1.5 of the OpenGL ES specification indicates the GL version
44 // string strictly follows this format:
45 //
46 // OpenGL<space>ES<space><version number><space><vendor-specific information>
47 //
48 // In addition section 6.1.5 describes the version number thusly:
49 //
50 // "The version number is either of the form major number.minor number or
51 // major number.minor number.release number, where the numbers all have one
52 // or more digits. The release number and vendor specific information are
53 // optional."
54
55 if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) {
56 // If we cannot parse the version number, assume OpenGL ES 2.0
57 mVersionMajor = 2;
58 mVersionMinor = 0;
59 }
60
John Reck704bed02015-11-05 09:22:17 -080061 auto extensions = StringUtils::split((const char*) glGetString(GL_EXTENSIONS));
Chris Craik6e6646c2015-09-14 15:54:12 -070062 mHasNPot = extensions.has("GL_OES_texture_npot");
63 mHasFramebufferFetch = extensions.has("GL_NV_shader_framebuffer_fetch");
64 mHasDiscardFramebuffer = extensions.has("GL_EXT_discard_framebuffer");
65 mHasDebugMarker = extensions.has("GL_EXT_debug_marker");
66 mHas1BitStencil = extensions.has("GL_OES_stencil1");
67 mHas4BitStencil = extensions.has("GL_OES_stencil4");
68 mHasUnpackSubImage = extensions.has("GL_EXT_unpack_subimage");
Romain Guy8472ac62017-11-01 09:50:28 -070069 mHasRenderableFloatTexture = extensions.has("GL_OES_texture_half_float");
Romain Guy8762e332016-10-12 12:14:07 -070070
Romain Guy8762e332016-10-12 12:14:07 -070071 mHasSRGB = mVersionMajor >= 3 || extensions.has("GL_EXT_sRGB");
Romain Guy253f2c22016-09-28 17:34:42 -070072 mHasSRGBWriteControl = extensions.has("GL_EXT_sRGB_write_control");
73
Romain Guyefb4b062017-02-27 11:00:04 -080074#ifdef ANDROID_ENABLE_LINEAR_BLENDING
Romain Guy8762e332016-10-12 12:14:07 -070075 // If linear blending is enabled, the device must have (ES3.0 or EXT_sRGB)
76 // and EXT_sRGB_write_control
77 LOG_ALWAYS_FATAL_IF(!mHasSRGB, "Linear blending requires ES 3.0 or EXT_sRGB");
78 LOG_ALWAYS_FATAL_IF(!mHasSRGBWriteControl, "Linear blending requires EXT_sRGB_write_control");
Romain Guyefb4b062017-02-27 11:00:04 -080079
80 mHasLinearBlending = true;
Romain Guy8762e332016-10-12 12:14:07 -070081#else
Romain Guyefb4b062017-02-27 11:00:04 -080082 mHasLinearBlending = false;
Romain Guy253f2c22016-09-28 17:34:42 -070083#endif
Romain Guy3bbacf22013-02-06 16:51:04 -080084}
85
Romain Guy3bbacf22013-02-06 16:51:04 -080086}; // namespace uirenderer
87}; // namespace android