Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 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 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 17 | #include "Extensions.h" |
| 18 | |
| 19 | #include "Debug.h" |
| 20 | #include "Properties.h" |
Chris Craik | 6e6646c | 2015-09-14 15:54:12 -0700 | [diff] [blame] | 21 | #include "utils/StringUtils.h" |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 22 | |
Romain Guy | efb4b06 | 2017-02-27 11:00:04 -0800 | [diff] [blame] | 23 | #include <cutils/compiler.h> |
| 24 | |
John Reck | 6b50780 | 2015-11-03 10:09:59 -0800 | [diff] [blame] | 25 | #include <GLES2/gl2.h> |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 26 | #include <GLES2/gl2ext.h> |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 27 | |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 28 | #include <utils/Log.h> |
| 29 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 30 | namespace android { |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 31 | namespace uirenderer { |
| 32 | |
John Reck | 1540153 | 2015-11-16 10:40:31 -0800 | [diff] [blame] | 33 | Extensions::Extensions() { |
Stan Iliev | f1f3c38 | 2017-11-09 12:17:35 -0500 | [diff] [blame] | 34 | if (Properties::isSkiaEnabled()) { |
Stan Iliev | d56d218 | 2017-10-18 13:12:32 -0400 | [diff] [blame] | 35 | return; |
| 36 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 37 | const char* version = (const char*)glGetString(GL_VERSION); |
Romain Guy | b136c85 | 2016-12-01 09:50:49 -0800 | [diff] [blame] | 38 | |
| 39 | // Section 6.1.5 of the OpenGL ES specification indicates the GL version |
| 40 | // string strictly follows this format: |
| 41 | // |
| 42 | // OpenGL<space>ES<space><version number><space><vendor-specific information> |
| 43 | // |
| 44 | // In addition section 6.1.5 describes the version number thusly: |
| 45 | // |
| 46 | // "The version number is either of the form major number.minor number or |
| 47 | // major number.minor number.release number, where the numbers all have one |
| 48 | // or more digits. The release number and vendor specific information are |
| 49 | // optional." |
| 50 | |
| 51 | if (sscanf(version, "OpenGL ES %d.%d", &mVersionMajor, &mVersionMinor) != 2) { |
| 52 | // If we cannot parse the version number, assume OpenGL ES 2.0 |
| 53 | mVersionMajor = 2; |
| 54 | mVersionMinor = 0; |
| 55 | } |
| 56 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 57 | auto extensions = StringUtils::split((const char*)glGetString(GL_EXTENSIONS)); |
Chris Craik | 6e6646c | 2015-09-14 15:54:12 -0700 | [diff] [blame] | 58 | mHasNPot = extensions.has("GL_OES_texture_npot"); |
| 59 | mHasFramebufferFetch = extensions.has("GL_NV_shader_framebuffer_fetch"); |
| 60 | mHasDiscardFramebuffer = extensions.has("GL_EXT_discard_framebuffer"); |
| 61 | mHasDebugMarker = extensions.has("GL_EXT_debug_marker"); |
| 62 | mHas1BitStencil = extensions.has("GL_OES_stencil1"); |
| 63 | mHas4BitStencil = extensions.has("GL_OES_stencil4"); |
| 64 | mHasUnpackSubImage = extensions.has("GL_EXT_unpack_subimage"); |
Romain Guy | 8472ac6 | 2017-11-01 09:50:28 -0700 | [diff] [blame] | 65 | mHasRenderableFloatTexture = extensions.has("GL_OES_texture_half_float"); |
Romain Guy | 8762e33 | 2016-10-12 12:14:07 -0700 | [diff] [blame] | 66 | |
Romain Guy | 8762e33 | 2016-10-12 12:14:07 -0700 | [diff] [blame] | 67 | mHasSRGB = mVersionMajor >= 3 || extensions.has("GL_EXT_sRGB"); |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 68 | mHasSRGBWriteControl = extensions.has("GL_EXT_sRGB_write_control"); |
| 69 | |
Romain Guy | efb4b06 | 2017-02-27 11:00:04 -0800 | [diff] [blame] | 70 | #ifdef ANDROID_ENABLE_LINEAR_BLENDING |
Romain Guy | 8762e33 | 2016-10-12 12:14:07 -0700 | [diff] [blame] | 71 | // If linear blending is enabled, the device must have (ES3.0 or EXT_sRGB) |
| 72 | // and EXT_sRGB_write_control |
| 73 | LOG_ALWAYS_FATAL_IF(!mHasSRGB, "Linear blending requires ES 3.0 or EXT_sRGB"); |
| 74 | LOG_ALWAYS_FATAL_IF(!mHasSRGBWriteControl, "Linear blending requires EXT_sRGB_write_control"); |
Romain Guy | efb4b06 | 2017-02-27 11:00:04 -0800 | [diff] [blame] | 75 | |
| 76 | mHasLinearBlending = true; |
Romain Guy | 8762e33 | 2016-10-12 12:14:07 -0700 | [diff] [blame] | 77 | #else |
Romain Guy | efb4b06 | 2017-02-27 11:00:04 -0800 | [diff] [blame] | 78 | mHasLinearBlending = false; |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 79 | #endif |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 80 | } |
| 81 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 82 | }; // namespace uirenderer |
| 83 | }; // namespace android |