Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
| 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "RenderEngine" |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 20 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 21 | |
| 22 | #include <GLES2/gl2.h> |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 23 | #include <GLES2/gl2ext.h> |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 24 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 25 | #include <ui/ColorSpace.h> |
| 26 | #include <ui/DebugUtils.h> |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 27 | #include <ui/Rect.h> |
| 28 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 29 | #include <utils/String8.h> |
| 30 | #include <utils/Trace.h> |
| 31 | |
| 32 | #include <cutils/compiler.h> |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 33 | #include <gui/ISurfaceComposer.h> |
| 34 | #include <math.h> |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 35 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 36 | #include "Description.h" |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 37 | #include "GLES20RenderEngine.h" |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 38 | #include "Mesh.h" |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 39 | #include "Program.h" |
| 40 | #include "ProgramCache.h" |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 41 | #include "Texture.h" |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 42 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 43 | #include <fstream> |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 44 | #include <sstream> |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 45 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 46 | // --------------------------------------------------------------------------- |
| 47 | bool checkGlError(const char* op, int lineNumber) { |
| 48 | bool errorFound = false; |
| 49 | GLint error = glGetError(); |
| 50 | while (error != GL_NO_ERROR) { |
| 51 | errorFound = true; |
| 52 | error = glGetError(); |
| 53 | ALOGV("after %s() (line # %d) glError (0x%x)\n", op, lineNumber, error); |
| 54 | } |
| 55 | return errorFound; |
| 56 | } |
| 57 | |
Courtney Goeltzenleuchter | 4f20f9c | 2017-04-06 08:18:34 -0600 | [diff] [blame] | 58 | static constexpr bool outputDebugPPMs = false; |
| 59 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 60 | void writePPM(const char* basename, GLuint width, GLuint height) { |
| 61 | ALOGV("writePPM #%s: %d x %d", basename, width, height); |
| 62 | |
| 63 | std::vector<GLubyte> pixels(width * height * 4); |
| 64 | std::vector<GLubyte> outBuffer(width * height * 3); |
| 65 | |
| 66 | // TODO(courtneygo): We can now have float formats, need |
| 67 | // to remove this code or update to support. |
| 68 | // Make returned pixels fit in uint32_t, one byte per component |
| 69 | glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); |
| 70 | if (checkGlError(__FUNCTION__, __LINE__)) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | std::string filename(basename); |
| 75 | filename.append(".ppm"); |
| 76 | std::ofstream file(filename.c_str(), std::ios::binary); |
| 77 | if (!file.is_open()) { |
| 78 | ALOGE("Unable to open file: %s", filename.c_str()); |
| 79 | ALOGE("You may need to do: \"adb shell setenforce 0\" to enable " |
| 80 | "surfaceflinger to write debug images"); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | file << "P6\n"; |
| 85 | file << width << "\n"; |
| 86 | file << height << "\n"; |
| 87 | file << 255 << "\n"; |
| 88 | |
| 89 | auto ptr = reinterpret_cast<char*>(pixels.data()); |
| 90 | auto outPtr = reinterpret_cast<char*>(outBuffer.data()); |
| 91 | for (int y = height - 1; y >= 0; y--) { |
| 92 | char* data = ptr + y * width * sizeof(uint32_t); |
| 93 | |
| 94 | for (GLuint x = 0; x < width; x++) { |
| 95 | // Only copy R, G and B components |
| 96 | outPtr[0] = data[0]; |
| 97 | outPtr[1] = data[1]; |
| 98 | outPtr[2] = data[2]; |
| 99 | data += sizeof(uint32_t); |
| 100 | outPtr += 3; |
| 101 | } |
| 102 | } |
| 103 | file.write(reinterpret_cast<char*>(outBuffer.data()), outBuffer.size()); |
| 104 | } |
| 105 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 106 | // --------------------------------------------------------------------------- |
| 107 | namespace android { |
| 108 | // --------------------------------------------------------------------------- |
| 109 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 110 | GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags) |
| 111 | : mVpWidth(0), mVpHeight(0), mPlatformHasWideColor((featureFlags & WIDE_COLOR_SUPPORT) != 0) { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 112 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); |
| 113 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); |
| 114 | |
| 115 | glPixelStorei(GL_UNPACK_ALIGNMENT, 4); |
| 116 | glPixelStorei(GL_PACK_ALIGNMENT, 4); |
| 117 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 118 | const uint16_t protTexData[] = {0}; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 119 | glGenTextures(1, &mProtectedTexName); |
| 120 | glBindTexture(GL_TEXTURE_2D, mProtectedTexName); |
| 121 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 122 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 123 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 124 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 125 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, protTexData); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 126 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 127 | // mColorBlindnessCorrection = M; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 128 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 129 | if (mPlatformHasWideColor) { |
| 130 | // Compute sRGB to DisplayP3 color transform |
| 131 | // NOTE: For now, we are limiting wide-color support to |
| 132 | // Display-P3 only. |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 133 | mat3 srgbToP3 = |
| 134 | ColorSpaceConnector(ColorSpace::sRGB(), ColorSpace::DisplayP3()).getTransform(); |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 135 | |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 136 | // color transform needs to be expanded to 4x4 to be what the shader wants |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 137 | // mat has an initializer that expands mat3 to mat4, but |
| 138 | // not an assignment operator |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 139 | mat4 gamutTransform(srgbToP3); |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 140 | mSrgbToDisplayP3 = gamutTransform; |
| 141 | } |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 144 | GLES20RenderEngine::~GLES20RenderEngine() {} |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 145 | |
| 146 | size_t GLES20RenderEngine::getMaxTextureSize() const { |
| 147 | return mMaxTextureSize; |
| 148 | } |
| 149 | |
| 150 | size_t GLES20RenderEngine::getMaxViewportDims() const { |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 151 | return mMaxViewportDims[0] < mMaxViewportDims[1] ? mMaxViewportDims[0] : mMaxViewportDims[1]; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 154 | void GLES20RenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, |
| 155 | size_t hwh, bool yswap, |
| 156 | Transform::orientation_flags rotation) { |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 157 | size_t l = sourceCrop.left; |
| 158 | size_t r = sourceCrop.right; |
| 159 | |
| 160 | // In GL, (0, 0) is the bottom-left corner, so flip y coordinates |
| 161 | size_t t = hwh - sourceCrop.top; |
| 162 | size_t b = hwh - sourceCrop.bottom; |
| 163 | |
Mathias Agopian | a8c386f | 2013-08-26 20:42:07 -0700 | [diff] [blame] | 164 | mat4 m; |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 165 | if (yswap) { |
| 166 | m = mat4::ortho(l, r, t, b, 0, 1); |
| 167 | } else { |
| 168 | m = mat4::ortho(l, r, b, t, 0, 1); |
| 169 | } |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 170 | |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 171 | // Apply custom rotation to the projection. |
| 172 | float rot90InRadians = 2.0f * static_cast<float>(M_PI) / 4.0f; |
| 173 | switch (rotation) { |
| 174 | case Transform::ROT_0: |
| 175 | break; |
| 176 | case Transform::ROT_90: |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 177 | m = mat4::rotate(rot90InRadians, vec3(0, 0, 1)) * m; |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 178 | break; |
| 179 | case Transform::ROT_180: |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 180 | m = mat4::rotate(rot90InRadians * 2.0f, vec3(0, 0, 1)) * m; |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 181 | break; |
| 182 | case Transform::ROT_270: |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 183 | m = mat4::rotate(rot90InRadians * 3.0f, vec3(0, 0, 1)) * m; |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 184 | break; |
| 185 | default: |
| 186 | break; |
| 187 | } |
| 188 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 189 | glViewport(0, 0, vpw, vph); |
| 190 | mState.setProjectionMatrix(m); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 191 | mVpWidth = vpw; |
| 192 | mVpHeight = vph; |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 195 | void GLES20RenderEngine::setupLayerBlending(bool premultipliedAlpha, bool opaque, |
| 196 | bool disableTexture, const half4& color) { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 197 | mState.setPremultipliedAlpha(premultipliedAlpha); |
| 198 | mState.setOpaque(opaque); |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 199 | mState.setColor(color); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 200 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 201 | if (disableTexture) { |
| 202 | mState.disableTexture(); |
| 203 | } |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 204 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 205 | if (color.a < 1.0f || !opaque) { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 206 | glEnable(GL_BLEND); |
| 207 | glBlendFunc(premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 208 | } else { |
| 209 | glDisable(GL_BLEND); |
| 210 | } |
| 211 | } |
| 212 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 213 | void GLES20RenderEngine::setColorMode(android_color_mode mode) { |
| 214 | ALOGV("setColorMode: %s (0x%x)", decodeColorMode(mode).c_str(), mode); |
| 215 | |
| 216 | if (mColorMode == mode) return; |
| 217 | |
| 218 | if (!mPlatformHasWideColor || !mDisplayHasWideColor || mode == HAL_COLOR_MODE_SRGB || |
| 219 | mode == HAL_COLOR_MODE_NATIVE) { |
| 220 | // We are returning back to our default color_mode |
| 221 | mUseWideColor = false; |
| 222 | mWideColorFrameCount = 0; |
| 223 | } else { |
| 224 | mUseWideColor = true; |
| 225 | } |
| 226 | |
| 227 | mColorMode = mode; |
| 228 | } |
| 229 | |
| 230 | void GLES20RenderEngine::setSourceDataSpace(android_dataspace source) { |
| 231 | if (source == HAL_DATASPACE_UNKNOWN) { |
| 232 | // Treat UNKNOWN as SRGB |
| 233 | source = HAL_DATASPACE_V0_SRGB; |
| 234 | } |
| 235 | mDataSpace = source; |
| 236 | } |
| 237 | |
| 238 | void GLES20RenderEngine::setWideColor(bool hasWideColor) { |
| 239 | ALOGV("setWideColor: %s", hasWideColor ? "true" : "false"); |
| 240 | mDisplayHasWideColor = hasWideColor; |
| 241 | } |
| 242 | |
| 243 | bool GLES20RenderEngine::usesWideColor() { |
| 244 | return mUseWideColor; |
| 245 | } |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 246 | |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 247 | void GLES20RenderEngine::setupLayerTexturing(const Texture& texture) { |
| 248 | GLuint target = texture.getTextureTarget(); |
| 249 | glBindTexture(target, texture.getTextureName()); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 250 | GLenum filter = GL_NEAREST; |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 251 | if (texture.getFiltering()) { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 252 | filter = GL_LINEAR; |
| 253 | } |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 254 | glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 255 | glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 256 | glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter); |
| 257 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 258 | |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 259 | mState.setTexture(texture); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void GLES20RenderEngine::setupLayerBlackedOut() { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 263 | glBindTexture(GL_TEXTURE_2D, mProtectedTexName); |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 264 | Texture texture(Texture::TEXTURE_2D, mProtectedTexName); |
| 265 | texture.setDimensions(1, 1); // FIXME: we should get that from somewhere |
| 266 | mState.setTexture(texture); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Dan Stoza | f008799 | 2014-10-20 15:46:09 -0700 | [diff] [blame] | 269 | mat4 GLES20RenderEngine::setupColorTransform(const mat4& colorTransform) { |
| 270 | mat4 oldTransform = mState.getColorMatrix(); |
| 271 | mState.setColorMatrix(colorTransform); |
| 272 | return oldTransform; |
| 273 | } |
| 274 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 275 | void GLES20RenderEngine::disableTexturing() { |
| 276 | mState.disableTexture(); |
| 277 | } |
| 278 | |
| 279 | void GLES20RenderEngine::disableBlending() { |
| 280 | glDisable(GL_BLEND); |
| 281 | } |
| 282 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 283 | void GLES20RenderEngine::bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, |
| 284 | uint32_t* fbName, uint32_t* status) { |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 285 | GLuint tname, name; |
| 286 | // turn our EGLImage into a texture |
| 287 | glGenTextures(1, &tname); |
| 288 | glBindTexture(GL_TEXTURE_2D, tname); |
| 289 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image); |
| 290 | |
| 291 | // create a Framebuffer Object to render into |
| 292 | glGenFramebuffers(1, &name); |
| 293 | glBindFramebuffer(GL_FRAMEBUFFER, name); |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 294 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tname, 0); |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 295 | |
| 296 | *status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 297 | *texName = tname; |
| 298 | *fbName = name; |
| 299 | } |
| 300 | |
| 301 | void GLES20RenderEngine::unbindFramebuffer(uint32_t texName, uint32_t fbName) { |
| 302 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 303 | glDeleteFramebuffers(1, &fbName); |
| 304 | glDeleteTextures(1, &texName); |
| 305 | } |
| 306 | |
Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 307 | void GLES20RenderEngine::setupFillWithColor(float r, float g, float b, float a) { |
Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 308 | mState.setPremultipliedAlpha(true); |
| 309 | mState.setOpaque(false); |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 310 | mState.setColor(half4(r, g, b, a)); |
Mathias Agopian | 19733a3 | 2013-08-28 18:13:56 -0700 | [diff] [blame] | 311 | mState.disableTexture(); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 312 | glDisable(GL_BLEND); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void GLES20RenderEngine::drawMesh(const Mesh& mesh) { |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 316 | if (mesh.getTexCoordsSize()) { |
| 317 | glEnableVertexAttribArray(Program::texCoords); |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 318 | glVertexAttribPointer(Program::texCoords, mesh.getTexCoordsSize(), GL_FLOAT, GL_FALSE, |
| 319 | mesh.getByteStride(), mesh.getTexCoords()); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame^] | 322 | glVertexAttribPointer(Program::position, mesh.getVertexSize(), GL_FLOAT, GL_FALSE, |
| 323 | mesh.getByteStride(), mesh.getPositions()); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 324 | |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 325 | if (usesWideColor()) { |
| 326 | Description wideColorState = mState; |
| 327 | if (mDataSpace != HAL_DATASPACE_DISPLAY_P3) { |
| 328 | wideColorState.setColorMatrix(mState.getColorMatrix() * mSrgbToDisplayP3); |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 329 | wideColorState.setWideGamut(true); |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 330 | ALOGV("drawMesh: gamut transform applied"); |
| 331 | } |
| 332 | ProgramCache::getInstance().useProgram(wideColorState); |
| 333 | |
| 334 | glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount()); |
| 335 | |
| 336 | if (outputDebugPPMs) { |
| 337 | std::ostringstream out; |
| 338 | out << "/data/texture_out" << mWideColorFrameCount++; |
| 339 | writePPM(out.str().c_str(), mVpWidth, mVpHeight); |
| 340 | } |
| 341 | } else { |
| 342 | ProgramCache::getInstance().useProgram(mState); |
| 343 | |
| 344 | glDrawArrays(mesh.getPrimitive(), 0, mesh.getVertexCount()); |
| 345 | } |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 346 | |
| 347 | if (mesh.getTexCoordsSize()) { |
| 348 | glDisableVertexAttribArray(Program::texCoords); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | void GLES20RenderEngine::dump(String8& result) { |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 353 | RenderEngine::dump(result); |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 354 | if (usesWideColor()) { |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 355 | result.append("Wide-color: On\n"); |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 356 | } else { |
Courtney Goeltzenleuchter | f3b2de1 | 2017-03-27 12:18:12 -0600 | [diff] [blame] | 357 | result.append("Wide-color: Off\n"); |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 358 | } |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | // --------------------------------------------------------------------------- |
| 362 | }; // namespace android |
| 363 | // --------------------------------------------------------------------------- |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 364 | |
| 365 | #if defined(__gl_h_) |
| 366 | #error "don't include gl/gl.h in this file" |
| 367 | #endif |