LayerDim.cpp revision bce26daaaf4ea245ccb09d75a378d294e518d945
1/* 2 * Copyright (C) 2007 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 <stdlib.h> 18#include <stdint.h> 19#include <sys/types.h> 20 21#include <utils/Errors.h> 22#include <utils/Log.h> 23 24#include <ui/GraphicBuffer.h> 25 26#include "LayerDim.h" 27#include "SurfaceFlinger.h" 28#include "DisplayHardware/DisplayHardware.h" 29 30namespace android { 31// --------------------------------------------------------------------------- 32 33LayerDim::LayerDim(SurfaceFlinger* flinger, DisplayID display, 34 const sp<Client>& client) 35 : LayerBaseClient(flinger, display, client) 36{ 37} 38 39LayerDim::~LayerDim() 40{ 41} 42 43void LayerDim::onDraw(const Region& clip) const 44{ 45 const State& s(drawingState()); 46 Region::const_iterator it = clip.begin(); 47 Region::const_iterator const end = clip.end(); 48 if (s.alpha>0 && (it != end)) { 49 const DisplayHardware& hw(graphicPlane(0).displayHardware()); 50 const GLfloat alpha = s.alpha/255.0f; 51 const uint32_t fbHeight = hw.getHeight(); 52 glDisable(GL_DITHER); 53 54 if (s.alpha == 0xFF) { 55 glDisable(GL_BLEND); 56 } else { 57 glEnable(GL_BLEND); 58 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 59 } 60 61 glColor4f(0, 0, 0, alpha); 62 63#if defined(GL_OES_EGL_image_external) 64 if (GLExtensions::getInstance().haveTextureExternal()) { 65 glDisable(GL_TEXTURE_EXTERNAL_OES); 66 } 67#endif 68 glDisable(GL_TEXTURE_2D); 69 70 glVertexPointer(2, GL_FLOAT, 0, mVertices); 71 72 while (it != end) { 73 const Rect& r = *it++; 74 const GLint sy = fbHeight - (r.top + r.height()); 75 glScissor(r.left, sy, r.width(), r.height()); 76 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 77 } 78 } 79 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 80} 81 82// --------------------------------------------------------------------------- 83 84}; // namespace android 85