LayerDim.cpp revision 13127d8921356dff794250e04208c3ed60b3a3df
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 <GLES/gl.h>
22#include <GLES/glext.h>
23
24#include <utils/Errors.h>
25#include <utils/Log.h>
26
27#include <ui/GraphicBuffer.h>
28
29#include "LayerDim.h"
30#include "SurfaceFlinger.h"
31#include "DisplayDevice.h"
32
33namespace android {
34// ---------------------------------------------------------------------------
35
36LayerDim::LayerDim(SurfaceFlinger* flinger, const sp<Client>& client)
37    : Layer(flinger, client) {
38}
39
40LayerDim::~LayerDim() {
41}
42
43void LayerDim::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const
44{
45    const State& s(drawingState());
46    if (s.alpha>0) {
47        const GLfloat alpha = s.alpha/255.0f;
48        const uint32_t fbHeight = hw->getHeight();
49        glDisable(GL_TEXTURE_EXTERNAL_OES);
50        glDisable(GL_TEXTURE_2D);
51
52        if (s.alpha == 0xFF) {
53            glDisable(GL_BLEND);
54        } else {
55            glEnable(GL_BLEND);
56            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
57        }
58
59        glColor4f(0, 0, 0, alpha);
60
61        LayerMesh mesh;
62        computeGeometry(hw, &mesh);
63
64        glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
65        glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
66
67        glDisable(GL_BLEND);
68        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
69    }
70}
71
72sp<ISurface> LayerDim::createSurface()
73{
74    class BSurface : public BnSurface, public LayerCleaner {
75        virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { return 0; }
76    public:
77        BSurface(const sp<SurfaceFlinger>& flinger,
78                const sp<Layer>& layer)
79            : LayerCleaner(flinger, layer) { }
80    };
81    sp<ISurface> sur(new BSurface(mFlinger, this));
82    return sur;
83}
84
85bool LayerDim::isVisible() const {
86    const Layer::State& s(drawingState());
87    return !(s.flags & layer_state_t::eLayerHidden) && s.alpha;
88}
89
90
91// ---------------------------------------------------------------------------
92
93}; // namespace android
94