blob: f2519c4e028016087ebef4321ae38598e2fea568 [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
24#include "LayerDim.h"
25#include "SurfaceFlinger.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026#include "DisplayHardware/DisplayHardware.h"
27
28namespace android {
29// ---------------------------------------------------------------------------
30
31const uint32_t LayerDim::typeInfo = LayerBaseClient::typeInfo | 0x10;
32const char* const LayerDim::typeID = "LayerDim";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34// ---------------------------------------------------------------------------
35
36LayerDim::LayerDim(SurfaceFlinger* flinger, DisplayID display,
37 Client* client, int32_t i)
38 : LayerBaseClient(flinger, display, client, i)
39{
40}
41
42void LayerDim::initDimmer(SurfaceFlinger* flinger, uint32_t w, uint32_t h)
43{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044}
45
46LayerDim::~LayerDim()
47{
48}
49
50void LayerDim::onDraw(const Region& clip) const
51{
Mathias Agopian1473f462009-04-10 14:24:30 -070052 // FIXME: on some h/w (like msm7K, it will be faster to use a texture)
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 const State& s(drawingState());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 Region::iterator iterator(clip);
56 if (s.alpha>0 && iterator) {
57 const DisplayHardware& hw(graphicPlane(0).displayHardware());
Mathias Agopian1473f462009-04-10 14:24:30 -070058 const GGLfixed alpha = (s.alpha << 16)/255;
59 const uint32_t fbHeight = hw.getHeight();
60 glDisable(GL_TEXTURE_2D);
61 glDisable(GL_DITHER);
62 glEnable(GL_BLEND);
63 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
64 glColor4x(0, 0, 0, alpha);
65 glVertexPointer(2, GL_FIXED, 0, mVertices);
66 Rect r;
67 while (iterator.iterate(&r)) {
68 const GLint sy = fbHeight - (r.top + r.height());
69 glScissor(r.left, sy, r.width(), r.height());
70 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 }
72 }
73}
74
75// ---------------------------------------------------------------------------
76
77}; // namespace android