The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 24 | #include <ui/GraphicBuffer.h> |
| 25 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include "LayerDim.h" |
| 27 | #include "SurfaceFlinger.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include "DisplayHardware/DisplayHardware.h" |
| 29 | |
| 30 | namespace android { |
| 31 | // --------------------------------------------------------------------------- |
| 32 | |
Mathias Agopian | 9cc8852 | 2009-06-18 18:48:39 -0700 | [diff] [blame] | 33 | bool LayerDim::sUseTexture; |
| 34 | GLuint LayerDim::sTexId; |
| 35 | EGLImageKHR LayerDim::sImage; |
| 36 | int32_t LayerDim::sWidth; |
| 37 | int32_t LayerDim::sHeight; |
| 38 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | // --------------------------------------------------------------------------- |
| 40 | |
| 41 | LayerDim::LayerDim(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 42 | const sp<Client>& client) |
| 43 | : LayerBaseClient(flinger, display, client) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | void LayerDim::initDimmer(SurfaceFlinger* flinger, uint32_t w, uint32_t h) |
| 48 | { |
Mathias Agopian | 9cc8852 | 2009-06-18 18:48:39 -0700 | [diff] [blame] | 49 | sTexId = -1; |
| 50 | sImage = EGL_NO_IMAGE_KHR; |
| 51 | sWidth = w; |
| 52 | sHeight = h; |
| 53 | sUseTexture = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | LayerDim::~LayerDim() |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void LayerDim::onDraw(const Region& clip) const |
| 61 | { |
| 62 | const State& s(drawingState()); |
Mathias Agopian | 6158b1b | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 63 | Region::const_iterator it = clip.begin(); |
| 64 | Region::const_iterator const end = clip.end(); |
| 65 | if (s.alpha>0 && (it != end)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 67 | const GLfloat alpha = s.alpha/255.0f; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 68 | const uint32_t fbHeight = hw.getHeight(); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 69 | glDisable(GL_DITHER); |
| 70 | glEnable(GL_BLEND); |
| 71 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 72 | glColor4f(0, 0, 0, alpha); |
| 73 | |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 74 | #if defined(GL_OES_texture_external) |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 75 | if (GLExtensions::getInstance().haveTextureExternal()) { |
| 76 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 77 | } |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 78 | #endif |
Mathias Agopian | c19ffcb | 2010-06-29 15:31:58 -0700 | [diff] [blame^] | 79 | glDisable(GL_TEXTURE_2D); |
Mathias Agopian | 9cc8852 | 2009-06-18 18:48:39 -0700 | [diff] [blame] | 80 | |
| 81 | GLshort w = sWidth; |
| 82 | GLshort h = sHeight; |
| 83 | const GLshort vertices[4][2] = { |
| 84 | { 0, 0 }, |
| 85 | { 0, h }, |
| 86 | { w, h }, |
| 87 | { w, 0 } |
| 88 | }; |
| 89 | glVertexPointer(2, GL_SHORT, 0, vertices); |
| 90 | |
Mathias Agopian | 6158b1b | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 91 | while (it != end) { |
| 92 | const Rect& r = *it++; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 93 | const GLint sy = fbHeight - (r.top + r.height()); |
| 94 | glScissor(r.left, sy, r.width(), r.height()); |
| 95 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | } |
| 97 | } |
Mathias Agopian | 9cc8852 | 2009-06-18 18:48:39 -0700 | [diff] [blame] | 98 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // --------------------------------------------------------------------------- |
| 102 | |
| 103 | }; // namespace android |