The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 21 | #include <GLES/gl.h> |
| 22 | #include <GLES/glext.h> |
| 23 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <utils/Errors.h> |
| 25 | #include <utils/Log.h> |
| 26 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 27 | #include <ui/GraphicBuffer.h> |
| 28 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include "LayerDim.h" |
| 30 | #include "SurfaceFlinger.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 31 | #include "DisplayDevice.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | // --------------------------------------------------------------------------- |
| 35 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 36 | LayerDim::LayerDim(SurfaceFlinger* flinger, const sp<Client>& client) |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 37 | : Layer(flinger, client) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 40 | LayerDim::~LayerDim() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 43 | void LayerDim::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | { |
| 45 | const State& s(drawingState()); |
Mathias Agopian | f74e8e0 | 2012-04-16 03:14:05 -0700 | [diff] [blame] | 46 | if (s.alpha>0) { |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 47 | const GLfloat alpha = s.alpha/255.0f; |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 48 | const uint32_t fbHeight = hw->getHeight(); |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 49 | glDisable(GL_TEXTURE_EXTERNAL_OES); |
| 50 | glDisable(GL_TEXTURE_2D); |
Mathias Agopian | 0d15612 | 2011-01-25 20:17:45 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 59 | glColor4f(0, 0, 0, alpha); |
| 60 | |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 61 | LayerMesh mesh; |
| 62 | computeGeometry(hw, &mesh); |
| 63 | |
| 64 | glVertexPointer(2, GL_FLOAT, 0, mesh.getVertices()); |
| 65 | glDrawArrays(GL_TRIANGLE_FAN, 0, mesh.getVertexCount()); |
Mathias Agopian | 945ebbf | 2009-06-18 18:48:39 -0700 | [diff] [blame] | 66 | |
Mathias Agopian | c492e67 | 2011-10-18 14:49:27 -0700 | [diff] [blame] | 67 | glDisable(GL_BLEND); |
| 68 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Mathias Agopian | 2f73af9 | 2013-03-05 15:50:58 -0800 | [diff] [blame] | 72 | sp<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, |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 78 | const sp<Layer>& layer) |
Mathias Agopian | 2f73af9 | 2013-03-05 15:50:58 -0800 | [diff] [blame] | 79 | : LayerCleaner(flinger, layer) { } |
| 80 | }; |
| 81 | sp<ISurface> sur(new BSurface(mFlinger, this)); |
| 82 | return sur; |
| 83 | } |
| 84 | |
| 85 | bool LayerDim::isVisible() const { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 86 | const Layer::State& s(drawingState()); |
Mathias Agopian | 2f73af9 | 2013-03-05 15:50:58 -0800 | [diff] [blame] | 87 | return !(s.flags & layer_state_t::eLayerHidden) && s.alpha; |
| 88 | } |
| 89 | |
| 90 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | // --------------------------------------------------------------------------- |
| 92 | |
| 93 | }; // namespace android |