LayerDim.cpp revision 2f73af9212487c81d31d07227fa8a2f4abc77638
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}
40
41LayerDim::~LayerDim()
42{
43}
44
45void LayerDim::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const
46{
47    const State& s(drawingState());
48    if (s.alpha>0) {
49        const GLfloat alpha = s.alpha/255.0f;
50        const uint32_t fbHeight = hw->getHeight();
51        glDisable(GL_TEXTURE_EXTERNAL_OES);
52        glDisable(GL_TEXTURE_2D);
53
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
61        glColor4f(0, 0, 0, alpha);
62
63        LayerMesh mesh;
64        computeGeometry(hw, &mesh);
65
66        glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices());
67        glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount());
68
69        glDisable(GL_BLEND);
70        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
71    }
72}
73
74sp<ISurface> LayerDim::createSurface()
75{
76    class BSurface : public BnSurface, public LayerCleaner {
77        virtual sp<IGraphicBufferProducer> getSurfaceTexture() const { return 0; }
78    public:
79        BSurface(const sp<SurfaceFlinger>& flinger,
80                const sp<LayerBase>& layer)
81            : LayerCleaner(flinger, layer) { }
82    };
83    sp<ISurface> sur(new BSurface(mFlinger, this));
84    return sur;
85}
86
87bool LayerDim::isVisible() const {
88    const Layer::State& s(mDrawingState);
89    return !(s.flags & layer_state_t::eLayerHidden) && s.alpha;
90}
91
92
93// ---------------------------------------------------------------------------
94
95}; // namespace android
96