Merge "Correctly initialize/refresh layers."

This commit is contained in:
Romain Guy
2010-09-22 22:52:40 -07:00
committed by Android (Google) Code Review
3 changed files with 16 additions and 7 deletions

View File

@@ -82,6 +82,10 @@ struct Layer {
* Indicates whether this layer should be blended.
*/
bool blend;
/**
* Indicates that this layer has never been used before.
*/
bool empty;
}; // struct Layer
}; // namespace uirenderer

View File

@@ -109,18 +109,16 @@ Layer* LayerCache::get(LayerSize& size) {
layer = new Layer;
layer->blend = true;
layer->empty = true;
glGenTextures(1, &layer->texture);
glBindTexture(GL_TEXTURE_2D, layer->texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width, size.height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
}
return layer;

View File

@@ -381,8 +381,15 @@ bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
// Copy the framebuffer into the layer
glBindTexture(GL_TEXTURE_2D, layer->texture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bounds.left, mHeight - bounds.bottom,
bounds.getWidth(), bounds.getHeight(), 0);
if (layer->empty) {
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bounds.left, mHeight - bounds.bottom,
bounds.getWidth(), bounds.getHeight(), 0);
layer->empty = false;
} else {
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bounds.left, mHeight - bounds.bottom,
bounds.getWidth(), bounds.getHeight());
}
if (flags & SkCanvas::kClipToLayer_SaveFlag) {
if (mSnapshot->clipTransformed(bounds)) setScissorFromClip();