2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/Log.h>
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "LayerDim.h"
|
|
|
|
#include "SurfaceFlinger.h"
|
|
|
|
#include "DisplayHardware/DisplayHardware.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-06-19 01:48:39 +00:00
|
|
|
bool LayerDim::sUseTexture;
|
|
|
|
GLuint LayerDim::sTexId;
|
|
|
|
EGLImageKHR LayerDim::sImage;
|
|
|
|
int32_t LayerDim::sWidth;
|
|
|
|
int32_t LayerDim::sHeight;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
LayerDim::LayerDim(SurfaceFlinger* flinger, DisplayID display,
|
2010-06-03 06:28:45 +00:00
|
|
|
const sp<Client>& client)
|
|
|
|
: LayerBaseClient(flinger, display, client)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerDim::initDimmer(SurfaceFlinger* flinger, uint32_t w, uint32_t h)
|
|
|
|
{
|
2009-06-19 01:48:39 +00:00
|
|
|
sTexId = -1;
|
|
|
|
sImage = EGL_NO_IMAGE_KHR;
|
|
|
|
sWidth = w;
|
|
|
|
sHeight = h;
|
|
|
|
sUseTexture = false;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LayerDim::~LayerDim()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerDim::onDraw(const Region& clip) const
|
|
|
|
{
|
|
|
|
const State& s(drawingState());
|
2009-05-11 07:03:41 +00:00
|
|
|
Region::const_iterator it = clip.begin();
|
|
|
|
Region::const_iterator const end = clip.end();
|
|
|
|
if (s.alpha>0 && (it != end)) {
|
2009-03-04 03:31:44 +00:00
|
|
|
const DisplayHardware& hw(graphicPlane(0).displayHardware());
|
2010-06-26 01:02:21 +00:00
|
|
|
const GLfloat alpha = s.alpha/255.0f;
|
2009-04-10 21:24:30 +00:00
|
|
|
const uint32_t fbHeight = hw.getHeight();
|
|
|
|
glDisable(GL_DITHER);
|
2011-03-10 00:13:31 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2010-06-26 01:02:21 +00:00
|
|
|
glColor4f(0, 0, 0, alpha);
|
|
|
|
|
2010-09-15 22:46:24 +00:00
|
|
|
#if defined(GL_OES_EGL_image_external)
|
2010-06-26 01:02:21 +00:00
|
|
|
if (GLExtensions::getInstance().haveTextureExternal()) {
|
|
|
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
|
|
|
}
|
2010-06-15 04:20:00 +00:00
|
|
|
#endif
|
2010-06-29 22:31:58 +00:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
2009-06-19 01:48:39 +00:00
|
|
|
|
|
|
|
GLshort w = sWidth;
|
|
|
|
GLshort h = sHeight;
|
|
|
|
const GLshort vertices[4][2] = {
|
|
|
|
{ 0, 0 },
|
|
|
|
{ 0, h },
|
|
|
|
{ w, h },
|
|
|
|
{ w, 0 }
|
|
|
|
};
|
|
|
|
glVertexPointer(2, GL_SHORT, 0, vertices);
|
|
|
|
|
2009-05-11 07:03:41 +00:00
|
|
|
while (it != end) {
|
|
|
|
const Rect& r = *it++;
|
2009-04-10 21:24:30 +00:00
|
|
|
const GLint sy = fbHeight - (r.top + r.height());
|
|
|
|
glScissor(r.left, sy, r.width(), r.height());
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-19 01:48:39 +00:00
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|