minor SurfaceFlinger code cleanup and remove unnecessary tests

This commit is contained in:
Mathias Agopian
2009-09-24 14:57:26 -07:00
parent 2ddccd1649
commit f2d28b7485
5 changed files with 68 additions and 80 deletions

View File

@ -160,7 +160,7 @@ void DisplayHardware::init(uint32_t dpy)
if (mNativeWindow->isUpdateOnDemand()) {
mFlags |= UPDATE_ON_DEMAND;
mFlags |= PARTIAL_UPDATES;
}
if (eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &dummy) == EGL_TRUE) {
@ -174,9 +174,9 @@ void DisplayHardware::init(uint32_t dpy)
surface = eglCreateWindowSurface(display, config, mNativeWindow.get(), NULL);
if (mFlags & UPDATE_ON_DEMAND) {
// if we have update on demand, we definitely don't need to
// preserve the backbuffer, which is usually costly.
if (mFlags & PARTIAL_UPDATES) {
// if we have partial updates, we definitely don't need to
// preserve the backbuffer, which may be costly.
eglSurfaceAttrib(display, surface,
EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED);
}
@ -199,9 +199,9 @@ void DisplayHardware::init(uint32_t dpy)
mFlags |= SWAP_RECTANGLE;
}
}
// when we have the choice between UPDATE_ON_DEMAND and SWAP_RECTANGLE
// choose UPDATE_ON_DEMAND, which is more efficient
if (mFlags & UPDATE_ON_DEMAND)
// when we have the choice between PARTIAL_UPDATES and SWAP_RECTANGLE
// choose PARTIAL_UPDATES, which should be more efficient
if (mFlags & PARTIAL_UPDATES)
mFlags &= ~SWAP_RECTANGLE;
#endif
@ -317,7 +317,7 @@ void DisplayHardware::flip(const Region& dirty) const
}
#endif
if (mFlags & UPDATE_ON_DEMAND) {
if (mFlags & PARTIAL_UPDATES) {
mNativeWindow->setUpdateRectangle(dirty.getBounds());
}

View File

@ -48,7 +48,7 @@ public:
NPOT_EXTENSION = 0x00000100,
DRAW_TEXTURE_EXTENSION = 0x00000200,
BUFFER_PRESERVED = 0x00010000,
UPDATE_ON_DEMAND = 0x00020000, // video driver feature
PARTIAL_UPDATES = 0x00020000, // video driver feature
SLOW_CONFIG = 0x00040000, // software
SWAP_RECTANGLE = 0x00080000,
};

View File

@ -223,14 +223,12 @@ void Layer::onDraw(const Region& clip) const
mFrontBufferIndex : 0;
GLuint textureName = mTextures[index].name;
if (UNLIKELY(textureName == -1LU)) {
//LOGW("Layer %p doesn't have a texture", this);
// the texture has not been created yet, this Layer has
// in fact never been drawn into. this happens frequently with
// SurfaceView.
clearWithOpenGL(clip);
return;
}
drawWithOpenGL(clip, mTextures[index]);
}

View File

@ -363,15 +363,13 @@ void LayerBase::clearWithOpenGL(const Region& clip, GLclampx red,
Region::const_iterator it = clip.begin();
Region::const_iterator const end = clip.end();
if (it != end) {
glEnable(GL_SCISSOR_TEST);
glVertexPointer(2, GL_FIXED, 0, mVertices);
while (it != end) {
const Rect& r = *it++;
const GLint sy = fbHeight - (r.top + r.height());
glScissor(r.left, sy, r.width(), r.height());
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glEnable(GL_SCISSOR_TEST);
glVertexPointer(2, GL_FIXED, 0, mVertices);
while (it != end) {
const Rect& r = *it++;
const GLint sy = fbHeight - (r.top + r.height());
glScissor(r.left, sy, r.width(), r.height());
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
}
@ -427,71 +425,63 @@ void LayerBase::drawWithOpenGL(const Region& clip, const Texture& texture) const
}
}
Region::const_iterator it = clip.begin();
Region::const_iterator const end = clip.end();
if (UNLIKELY(transformed()
|| !(mFlags & DisplayHardware::DRAW_TEXTURE_EXTENSION) ))
{
//StopWatch watch("GL transformed");
Region::const_iterator it = clip.begin();
Region::const_iterator const end = clip.end();
if (it != end) {
const GLfixed texCoords[4][2] = {
{ 0, 0 },
{ 0, 0x10000 },
{ 0x10000, 0x10000 },
{ 0x10000, 0 }
};
const GLfixed texCoords[4][2] = {
{ 0, 0 },
{ 0, 0x10000 },
{ 0x10000, 0x10000 },
{ 0x10000, 0 }
};
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
// the texture's source is rotated
if (texture.transform == HAL_TRANSFORM_ROT_90) {
// TODO: handle the other orientations
glTranslatef(0, 1, 0);
glRotatef(-90, 0, 0, 1);
}
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
if (!(mFlags & (DisplayHardware::NPOT_EXTENSION |
DisplayHardware::DIRECT_TEXTURE))) {
// find the smallest power-of-two that will accommodate our surface
GLuint tw = 1 << (31 - clz(width));
GLuint th = 1 << (31 - clz(height));
if (tw < width) tw <<= 1;
if (th < height) th <<= 1;
// this divide should be relatively fast because it's
// a power-of-two (optimized path in libgcc)
GLfloat ws = GLfloat(width) /tw;
GLfloat hs = GLfloat(height)/th;
glScalef(ws, hs, 1.0f);
}
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FIXED, 0, mVertices);
glTexCoordPointer(2, GL_FIXED, 0, texCoords);
while (it != end) {
const Rect& r = *it++;
const GLint sy = fbHeight - (r.top + r.height());
glScissor(r.left, sy, r.width(), r.height());
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// the texture's source is rotated
if (texture.transform == HAL_TRANSFORM_ROT_90) {
// TODO: handle the other orientations
glTranslatef(0, 1, 0);
glRotatef(-90, 0, 0, 1);
}
if (!(mFlags & (DisplayHardware::NPOT_EXTENSION |
DisplayHardware::DIRECT_TEXTURE))) {
// find the smallest power-of-two that will accommodate our surface
GLuint tw = 1 << (31 - clz(width));
GLuint th = 1 << (31 - clz(height));
if (tw < width) tw <<= 1;
if (th < height) th <<= 1;
GLfloat ws = GLfloat(width) /tw;
GLfloat hs = GLfloat(height)/th;
glScalef(ws, hs, 1.0f);
}
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FIXED, 0, mVertices);
glTexCoordPointer(2, GL_FIXED, 0, texCoords);
while (it != end) {
const Rect& r = *it++;
const GLint sy = fbHeight - (r.top + r.height());
glScissor(r.left, sy, r.width(), r.height());
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
} else {
Region::const_iterator it = clip.begin();
Region::const_iterator const end = clip.end();
if (it != end) {
GLint crop[4] = { 0, height, width, -height };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
int x = tx();
int y = ty();
y = fbHeight - (y + height);
while (it != end) {
const Rect& r = *it++;
const GLint sy = fbHeight - (r.top + r.height());
glScissor(r.left, sy, r.width(), r.height());
glDrawTexiOES(x, y, 0, width, height);
}
GLint crop[4] = { 0, height, width, -height };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
int x = tx();
int y = ty();
y = fbHeight - (y + height);
while (it != end) {
const Rect& r = *it++;
const GLint sy = fbHeight - (r.top + r.height());
glScissor(r.left, sy, r.width(), r.height());
glDrawTexiOES(x, y, 0, width, height);
}
}
}

View File

@ -859,10 +859,10 @@ void SurfaceFlinger::handleRepaint()
// is costly and usually involves copying the whole update back.
}
} else {
if (flags & DisplayHardware::UPDATE_ON_DEMAND) {
if (flags & DisplayHardware::PARTIAL_UPDATES) {
// We need to redraw the rectangle that will be updated
// (pushed to the framebuffer).
// This is needed because UPDATE_ON_DEMAND only takes one
// This is needed because PARTIAL_UPDATES only takes one
// rectangle instead of a region (see DisplayHardware::flip())
mDirtyRegion.set(mInvalidRegion.bounds());
} else {
@ -920,7 +920,7 @@ void SurfaceFlinger::debugFlashRegions()
if (!((flags & DisplayHardware::SWAP_RECTANGLE) ||
(flags & DisplayHardware::BUFFER_PRESERVED))) {
const Region repaint((flags & DisplayHardware::UPDATE_ON_DEMAND) ?
const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ?
mDirtyRegion.bounds() : hw.bounds());
composeSurfaces(repaint);
}