Fix INVALID_OPERATION error with layers rendering.
This change is a workaround for a driver bug that causes an INVALID_OPERATION
to be thrown on every glCopyTexSubImage() call. This change also adds a new
test for gradients local matrices.
Change-Id: I41b7437481026702d0a3a9677f099b4557c0a84e
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h
index 60523db..a0cc5d6 100644
--- a/libs/hwui/Layer.h
+++ b/libs/hwui/Layer.h
@@ -44,7 +44,7 @@
uint32_t id;
bool operator<(const LayerSize& rhs) const {
- if (id != 0 && rhs.id != 0) {
+ if (id != 0 && rhs.id != 0 && id != rhs.id) {
return id < rhs.id;
}
if (width == rhs.width) {
@@ -54,7 +54,7 @@
}
bool operator==(const LayerSize& rhs) const {
- return width == rhs.width && height == rhs.height;
+ return id == rhs.id && width == rhs.width && height == rhs.height;
}
}; // struct LayerSize
@@ -83,7 +83,7 @@
*/
bool blend;
/**
- * Indicates that this layer has never been used before.
+ * Indicates whether this layer has been used already.
*/
bool empty;
}; // struct Layer
diff --git a/libs/hwui/LayerCache.cpp b/libs/hwui/LayerCache.cpp
index 2770868..8c70cf9 100644
--- a/libs/hwui/LayerCache.cpp
+++ b/libs/hwui/LayerCache.cpp
@@ -114,6 +114,8 @@
glGenTextures(1, &layer->texture);
glBindTexture(GL_TEXTURE_2D, layer->texture);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 23de3a5..0810fb8 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -366,6 +366,8 @@
return false;
}
+ glActiveTexture(GL_TEXTURE0);
+
LayerSize size(bounds.getWidth(), bounds.getHeight());
Layer* layer = mCaches.layerCache.get(size);
if (!layer) {
@@ -383,17 +385,22 @@
// Copy the framebuffer into the layer
glBindTexture(GL_TEXTURE_2D, layer->texture);
- 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());
- }
+ // TODO: Workaround for b/3054204
+ glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bounds.left, mHeight - bounds.bottom,
+ bounds.getWidth(), bounds.getHeight(), 0);
- if (flags & SkCanvas::kClipToLayer_SaveFlag) {
- if (mSnapshot->clipTransformed(bounds)) setScissorFromClip();
+ // TODO: Waiting for b/3054204 to be fixed
+// 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 && mSnapshot->clipTransformed(bounds)) {
+ setScissorFromClip();
}
// Enqueue the buffer coordinates to clear the corresponding region later