Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -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 | |
| 17 | #include <GLES/gl.h> |
| 18 | |
| 19 | #include <cutils/compiler.h> |
| 20 | |
| 21 | #include "GLES10RenderEngine.h" |
| 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | // --------------------------------------------------------------------------- |
| 26 | |
| 27 | GLES10RenderEngine::~GLES10RenderEngine() { |
| 28 | } |
| 29 | |
| 30 | void GLES10RenderEngine::setupLayerBlending( |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 31 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 32 | bool premultipliedAlpha, bool opaque, float alpha) { |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 33 | #else |
| 34 | bool premultipliedAlpha, bool opaque, int alpha) { |
| 35 | #endif |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 36 | // OpenGL ES 1.0 doesn't support texture combiners. |
| 37 | // This path doesn't properly handle opaque layers that have non-opaque |
| 38 | // alpha values. The alpha channel will be copied into the framebuffer or |
| 39 | // screenshot, so if the framebuffer or screenshot is blended on top of |
| 40 | // something else, whatever is below the window will incorrectly show |
| 41 | // through. |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 42 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 43 | if (CC_UNLIKELY(alpha < 1.0f)) { |
| 44 | if (premultipliedAlpha) { |
| 45 | glColor4f(alpha, alpha, alpha, alpha); |
| 46 | } else { |
| 47 | glColor4f(1.0f, 1.0f, 1.0f, alpha); |
| 48 | } |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 49 | #else |
| 50 | if (CC_UNLIKELY(alpha < 0xFF)) { |
| 51 | GLfloat floatAlpha = alpha * (1.0f / 255.0f); |
| 52 | if (premultipliedAlpha) { |
| 53 | glColor4f(floatAlpha, floatAlpha, floatAlpha, floatAlpha); |
| 54 | } else { |
| 55 | glColor4f(1.0f, 1.0f, 1.0f, floatAlpha); |
| 56 | } |
| 57 | #endif |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 58 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
| 59 | } else { |
| 60 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 61 | } |
| 62 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 63 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 64 | if (alpha < 1.0f || !opaque) { |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 65 | #else |
| 66 | if (alpha < 0xFF || !opaque) { |
| 67 | #endif |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 68 | glEnable(GL_BLEND); |
| 69 | glBlendFunc(premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA, |
| 70 | GL_ONE_MINUS_SRC_ALPHA); |
| 71 | } else { |
| 72 | glDisable(GL_BLEND); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // --------------------------------------------------------------------------- |
| 77 | }; // namespace android |
| 78 | // --------------------------------------------------------------------------- |