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( 31 #ifdef USE_HWC2 32 bool premultipliedAlpha, bool opaque, float alpha) { 33 #else 34 bool premultipliedAlpha, bool opaque, int alpha) { 35 #endif 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. 42 #ifdef USE_HWC2 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 } 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 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 63 #ifdef USE_HWC2 64 if (alpha < 1.0f || !opaque) { 65 #else 66 if (alpha < 0xFF || !opaque) { 67 #endif 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 // --------------------------------------------------------------------------- 79