blob: 11f8feb1ff69f5b87a9b1d5e6f96e51c5a891e89 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Projectedbf3b62009-03-03 19:31:44 -080017#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 Agopian3330b202009-10-05 17:07:12 -070024#include <ui/GraphicBuffer.h>
25
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026#include "LayerDim.h"
27#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include "DisplayHardware/DisplayHardware.h"
29
30namespace android {
31// ---------------------------------------------------------------------------
32
Mathias Agopian945ebbf2009-06-18 18:48:39 -070033bool LayerDim::sUseTexture;
34GLuint LayerDim::sTexId;
35EGLImageKHR LayerDim::sImage;
36int32_t LayerDim::sWidth;
37int32_t LayerDim::sHeight;
38
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039// ---------------------------------------------------------------------------
40
41LayerDim::LayerDim(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian96f08192010-06-02 23:28:45 -070042 const sp<Client>& client)
43 : LayerBaseClient(flinger, display, client)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044{
45}
46
47void LayerDim::initDimmer(SurfaceFlinger* flinger, uint32_t w, uint32_t h)
48{
Mathias Agopian945ebbf2009-06-18 18:48:39 -070049 sTexId = -1;
50 sImage = EGL_NO_IMAGE_KHR;
51 sWidth = w;
52 sHeight = h;
53 sUseTexture = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054}
55
56LayerDim::~LayerDim()
57{
58}
59
60void LayerDim::onDraw(const Region& clip) const
61{
62 const State& s(drawingState());
Mathias Agopian20f68782009-05-11 00:03:41 -070063 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 Projectedbf3b62009-03-03 19:31:44 -080066 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian1f7bec62010-06-25 18:02:21 -070067 const GLfloat alpha = s.alpha/255.0f;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070068 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian076b1cc2009-04-10 14:24:30 -070069 glDisable(GL_DITHER);
Mathias Agopian0d156122011-01-25 20:17:45 -080070
71 if (s.alpha == 0xFF) {
72 glDisable(GL_BLEND);
73 } else {
74 glEnable(GL_BLEND);
75 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
76 }
77
Mathias Agopian1f7bec62010-06-25 18:02:21 -070078 glColor4f(0, 0, 0, alpha);
79
Michael I. Gold7f198b62010-09-15 15:46:24 -070080#if defined(GL_OES_EGL_image_external)
Mathias Agopian1f7bec62010-06-25 18:02:21 -070081 if (GLExtensions::getInstance().haveTextureExternal()) {
82 glDisable(GL_TEXTURE_EXTERNAL_OES);
83 }
Mathias Agopian0a917752010-06-14 21:20:00 -070084#endif
Mathias Agopian5d8f41c2010-06-29 15:31:58 -070085 glDisable(GL_TEXTURE_2D);
Mathias Agopian945ebbf2009-06-18 18:48:39 -070086
87 GLshort w = sWidth;
88 GLshort h = sHeight;
89 const GLshort vertices[4][2] = {
90 { 0, 0 },
91 { 0, h },
92 { w, h },
93 { w, 0 }
94 };
95 glVertexPointer(2, GL_SHORT, 0, vertices);
96
Mathias Agopian20f68782009-05-11 00:03:41 -070097 while (it != end) {
98 const Rect& r = *it++;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070099 const GLint sy = fbHeight - (r.top + r.height());
100 glScissor(r.left, sy, r.width(), r.height());
101 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 }
103 }
Mathias Agopian945ebbf2009-06-18 18:48:39 -0700104 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105}
106
107// ---------------------------------------------------------------------------
108
109}; // namespace android