From e8f4d7deab2c183604ea5a2344a1e2d7ff4f823a Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 14 Jan 2010 18:45:04 -0800 Subject: ADT/Layoutlib: improved gradient drawing for perf. Change-Id: I79b909d7787e4442e7cfdf196de1ac0c077da7f8 --- .../bridge/src/android/graphics/LinearGradient.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tools/layoutlib/bridge/src') diff --git a/tools/layoutlib/bridge/src/android/graphics/LinearGradient.java b/tools/layoutlib/bridge/src/android/graphics/LinearGradient.java index bd152a2..38ffed3 100644 --- a/tools/layoutlib/bridge/src/android/graphics/LinearGradient.java +++ b/tools/layoutlib/bridge/src/android/graphics/LinearGradient.java @@ -196,12 +196,15 @@ public class LinearGradient extends Shader { public Raster getRaster(int x, int y, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + int[] data = new int[w*h]; + if (mDx == 0) { // vertical gradient // compute first column and copy to all other columns + int index = 0; for (int iy = 0 ; iy < h ; iy++) { int color = getColor(iy + y, mY0, mDy); for (int ix = 0 ; ix < w ; ix++) { - image.setRGB(ix, iy, color); + data[index++] = color; } } } else if (mDy == 0) { // horizontal @@ -212,16 +215,19 @@ public class LinearGradient extends Shader { } for (int iy = 0 ; iy < h ; iy++) { - image.setRGB(0, iy, w, 1 /*h*/, line, 0 /* offset*/, w /*scansize*/); + System.arraycopy(line, 0, data, iy*w, line.length); } } else { + int index = 0; for (int iy = 0 ; iy < h ; iy++) { for (int ix = 0 ; ix < w ; ix++) { - image.setRGB(ix, iy, getColor(ix + x, iy + y)); + data[index++] = getColor(ix + x, iy + y); } } } + image.setRGB(0 /*startX*/, 0 /*startY*/, w, h, data, 0 /*offset*/, w /*scansize*/); + return image.getRaster(); } } -- cgit v1.1