blob: 654817d61bbe6fc762b124f3e614b5f699908c3c [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-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 Agopian6950e422009-10-05 17:07:12 -070024#include <ui/GraphicBuffer.h>
25
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026#include "LayerDim.h"
27#include "SurfaceFlinger.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028#include "DisplayHardware/DisplayHardware.h"
29
30namespace android {
31// ---------------------------------------------------------------------------
32
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033LayerDim::LayerDim(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopian593c05c2010-06-02 23:28:45 -070034 const sp<Client>& client)
35 : LayerBaseClient(flinger, display, client)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036{
37}
38
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039LayerDim::~LayerDim()
40{
41}
42
43void LayerDim::onDraw(const Region& clip) const
44{
45 const State& s(drawingState());
Mathias Agopian6158b1b2009-05-11 00:03:41 -070046 Region::const_iterator it = clip.begin();
47 Region::const_iterator const end = clip.end();
48 if (s.alpha>0 && (it != end)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian781953d2010-06-25 18:02:21 -070050 const GLfloat alpha = s.alpha/255.0f;
Mathias Agopian1473f462009-04-10 14:24:30 -070051 const uint32_t fbHeight = hw.getHeight();
Mathias Agopian1473f462009-04-10 14:24:30 -070052 glDisable(GL_DITHER);
Mathias Agopiand35c6662011-01-25 20:17:45 -080053
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
Mathias Agopian781953d2010-06-25 18:02:21 -070061 glColor4f(0, 0, 0, alpha);
62
Michael I. Golde20a56d2010-09-15 15:46:24 -070063#if defined(GL_OES_EGL_image_external)
Mathias Agopian781953d2010-06-25 18:02:21 -070064 if (GLExtensions::getInstance().haveTextureExternal()) {
65 glDisable(GL_TEXTURE_EXTERNAL_OES);
66 }
Mathias Agopianf8b4b442010-06-14 21:20:00 -070067#endif
Mathias Agopian6e138fb2011-02-02 16:03:19 -080068 glVertexPointer(2, GL_FLOAT, 0, mVertices);
Mathias Agopian9cc88522009-06-18 18:48:39 -070069
Mathias Agopian6158b1b2009-05-11 00:03:41 -070070 while (it != end) {
71 const Rect& r = *it++;
Mathias Agopian1473f462009-04-10 14:24:30 -070072 const GLint sy = fbHeight - (r.top + r.height());
73 glScissor(r.left, sy, r.width(), r.height());
74 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 }
76 }
Mathias Agopian9cc88522009-06-18 18:48:39 -070077 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078}
79
80// ---------------------------------------------------------------------------
81
82}; // namespace android