summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2010-08-18 17:11:11 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-08-18 17:11:11 -0700
commit1b196022ece4305f7619a41a84fe49f792dfb1bc (patch)
tree99d22da85f311588b83a6311238184f65265a463 /libs
parentadec63015fd9bd05498572486f38f0436a1199ad (diff)
parent8b55f377655d13a445b08a0a8ed09b6e95c752b0 (diff)
downloadframeworks_base-1b196022ece4305f7619a41a84fe49f792dfb1bc.zip
frameworks_base-1b196022ece4305f7619a41a84fe49f792dfb1bc.tar.gz
frameworks_base-1b196022ece4305f7619a41a84fe49f792dfb1bc.tar.bz2
Merge "Fix drawing issues with layers."
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/OpenGLRenderer.cpp47
-rw-r--r--libs/hwui/Snapshot.h8
2 files changed, 41 insertions, 14 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 0a5ff57..3440687 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -41,7 +41,7 @@ namespace uirenderer {
#define DEFAULT_PATH_CACHE_SIZE 6.0f
#define DEFAULT_PATCH_CACHE_SIZE 100
#define DEFAULT_GRADIENT_CACHE_SIZE 0.5f
-#define DEFAULT_DROP_SHADOW_CACHE_SIZE 1.0f
+#define DEFAULT_DROP_SHADOW_CACHE_SIZE 2.0f
#define REQUIRED_TEXTURE_UNITS_COUNT 3
@@ -251,13 +251,13 @@ bool OpenGLRenderer::restoreSnapshot() {
mOrthoMatrix.load(current->orthoMatrix);
}
+ mSaveCount--;
+ mSnapshot = previous;
+
if (restoreLayer) {
composeLayer(current, previous);
}
- mSaveCount--;
- mSnapshot = previous;
-
if (restoreClip) {
setScissorFromClip();
}
@@ -287,7 +287,11 @@ int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
mode = SkXfermode::kSrcOver_Mode;
}
- createLayer(mSnapshot, left, top, right, bottom, alpha, mode, flags);
+ if (alpha > 0 && !mSnapshot->invisible) {
+ createLayer(mSnapshot, left, top, right, bottom, alpha, mode, flags);
+ } else {
+ mSnapshot->invisible = true;
+ }
return count;
}
@@ -295,7 +299,11 @@ int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
int alpha, int flags) {
int count = saveSnapshot();
- createLayer(mSnapshot, left, top, right, bottom, alpha, SkXfermode::kSrcOver_Mode, flags);
+ if (alpha > 0 && !mSnapshot->invisible) {
+ createLayer(mSnapshot, left, top, right, bottom, alpha, SkXfermode::kSrcOver_Mode, flags);
+ } else {
+ mSnapshot->invisible = true;
+ }
return count;
}
@@ -328,7 +336,6 @@ bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
snapshot->flags |= Snapshot::kFlagIsLayer;
snapshot->layer = layer;
snapshot->fbo = layer->fbo;
-
snapshot->transform.loadTranslate(-left, -top, 0.0f);
snapshot->setClip(0.0f, 0.0f, right - left, bottom - top);
snapshot->viewport.set(0.0f, 0.0f, right - left, bottom - top);
@@ -340,8 +347,7 @@ bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
// Change the ortho projection
glViewport(0, 0, right - left, bottom - top);
- // Don't flip the FBO, it will get flipped when drawing back to the framebuffer
- mOrthoMatrix.loadOrtho(0.0f, right - left, 0.0f, bottom - top, -1.0f, 1.0f);
+ mOrthoMatrix.loadOrtho(0.0f, right - left, bottom - top, 0.0f, -1.0f, 1.0f);
return true;
}
@@ -363,9 +369,14 @@ void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
Layer* layer = current->layer;
const Rect& rect = layer->layer;
+ // FBOs are already drawn with a top-left origin, don't flip the texture
+ resetDrawTextureTexCoords(0.0f, 1.0f, 1.0f, 0.0f);
+
drawTextureRect(rect.left, rect.top, rect.right, rect.bottom,
layer->texture, layer->alpha, layer->mode, layer->blend);
+ resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
+
LayerSize size(rect.getWidth(), rect.getHeight());
// Failing to add the layer to the cache should happen only if the
// layer is too large
@@ -422,6 +433,8 @@ const Rect& OpenGLRenderer::getClipBounds() {
}
bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
+ if (mSnapshot->invisible) return true;
+
Rect r(left, top, right, bottom);
mSnapshot->transform.mapRect(r);
return !mSnapshot->clipRect.intersects(r);
@@ -527,6 +540,7 @@ void OpenGLRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
}
void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
+ if (mSnapshot->invisible) return;
const Rect& clip = mSnapshot->clipRect;
drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode, true);
}
@@ -556,7 +570,8 @@ void OpenGLRenderer::drawRect(float left, float top, float right, float bottom,
void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
float x, float y, SkPaint* paint) {
- if (text == NULL || count == 0 || (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
+ if (mSnapshot->invisible || text == NULL || count == 0 ||
+ (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
return;
}
@@ -614,6 +629,8 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
}
void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
+ if (mSnapshot->invisible) return;
+
GLuint textureUnit = 0;
glActiveTexture(gTextureUnits[textureUnit]);
@@ -621,6 +638,13 @@ void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
if (!texture) return;
const AutoTexture autoCleanup(texture);
+ const float x = texture->left - texture->offset;
+ const float y = texture->top - texture->offset;
+
+ if (quickReject(x, y, x + texture->width, y + texture->height)) {
+ return;
+ }
+
int alpha;
SkXfermode::Mode mode;
getAlphaAndMode(paint, &alpha, &mode);
@@ -631,9 +655,6 @@ void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
- const float x = texture->left - texture->offset;
- const float y = texture->top - texture->offset;
-
setupTextureAlpha8(texture, textureUnit, x, y, r, g, b, a, mode, true, true);
// Draw the mesh
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index 21b2bef..97e7cae 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -42,7 +42,7 @@ namespace uirenderer {
*/
class Snapshot: public LightRefBase<Snapshot> {
public:
- Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0) { }
+ Snapshot(): invisible(false), flags(0), previous(NULL), layer(NULL), fbo(0) { }
/**
* Copies the specified snapshot. Only the transform and clip rectangle
@@ -54,6 +54,7 @@ public:
height(s->height),
transform(s->transform),
clipRect(s->clipRect),
+ invisible(s->invisible),
flags(0),
previous(s),
layer(NULL),
@@ -165,6 +166,11 @@ public:
Rect clipRect;
/**
+ * If true, the layer won't be rendered.
+ */
+ bool invisible;
+
+ /**
* Dirty flags.
*/
int flags;