summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Diego Perez <diegoperez@google.com> 2015-04-22 09:51:54 +0100
committer Diego Perez <diegoperez@google.com> 2015-05-07 00:39:39 +0000
commit8ab069f3aed15c7e5de32ff52a3b4710218f9895 (patch)
tree19f5ebc08550ac56345f9e6230bdf24dc4aa0708
parentf3cb4ba213a0fa4d1c184c430a2eaac7e27ccf6f (diff)
Fix GcSnapshot drawInLayer when clipping is used.
GcSnapshot only allocates an image for tinting that is the size of the current clipping area. When drawing to that image, the wrong coordinate system was used since now we are dealing with only the clipping rect we need to translate -clipX, -clipY the drawing so it's painted at 0,0 of the new BufferedImage. Change-Id: Id8639d5ea9bef36ac07743df332161d6eadc6a81
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java15
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java
index c34f9b51a349..a39eb4d45ca5 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java
@@ -616,6 +616,8 @@ public class GcSnapshot {
return;
}
+ int x = 0;
+ int y = 0;
int width;
int height;
Rectangle clipBounds = originalGraphics.getClipBounds();
@@ -626,6 +628,8 @@ public class GcSnapshot {
}
// If we have clipBounds available, use them as they will always be
// smaller than the full layer size.
+ x = clipBounds.x;
+ y = clipBounds.y;
width = clipBounds.width;
height = clipBounds.height;
} else {
@@ -646,13 +650,20 @@ public class GcSnapshot {
true /*compositeOnly*/, forceMode);
try {
// The main draw operation.
+ // We translate the operation to take into account that the rendering does not
+ // know about the clipping area.
+ imageGraphics.translate(-x, -y);
drawable.draw(imageGraphics, paint);
// Apply the color filter.
+ // Restore the original coordinates system and apply the filter only to the
+ // clipped area.
+ imageGraphics.translate(x, y);
filter.applyFilter(imageGraphics, width, height);
- // Draw the tinted image on the main layer.
- configuredGraphics.drawImage(image, 0, 0, null);
+ // Draw the tinted image on the main layer using as start point the clipping
+ // upper left coordinates.
+ configuredGraphics.drawImage(image, x, y, null);
layer.change();
} finally {
// dispose Graphics2D objects