Browse files

Add 16bpp patches

Change-Id: I7e3464caceba3dc538bf321e870947402f9086bf
  • Loading branch information...
1 parent e16e26d commit 1c3c82e406742ab2d7e4fdf2386834d40ad89fe0 @joaoventura committed Jan 30, 2013
View
5 patches/apply_patches.sh
@@ -44,3 +44,8 @@ applyPatch 0001-Fix-alignment-and-copy-size-for-legacy-QCOM-OMX.patch frameworks
# Remove Trebuchet wallpapers
applyPatch 0001-Trebuchet-Remove-wallpapers.patch packages_apps_Trebuchet packages/apps/Trebuchet
+# 16 bpp patches
+applyPatch 0001-Use-RGB565-surface-for-wallpaper.patch frameworks_base frameworks/base
+applyPatch 0001-Prefer-16bpp-formats-for-opaque-bitmaps.patch frameworks_base frameworks/base
+applyPatch 0001-Prefer-16bpp-surface-formats.patch frameworks_base frameworks/base
+
View
73 patches/frameworks_base/0001-Prefer-16bpp-formats-for-opaque-bitmaps.patch
@@ -0,0 +1,73 @@
+From 80a50ff1d84afad039d7b9b44ed9cbedf4512bc4 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jo=C3=A3o=20Ventura?= <joaojonesventura@gmail.com>
+Date: Wed, 30 Jan 2013 17:40:13 +0000
+Subject: [PATCH] Prefer 16bpp formats for opaque bitmaps
+
+Configure BitmapFactory to prefer RGB565, which will make it
+use that format for all opaque assets loaded by it with standard
+settings. Toggle dithering flag in strategic places and reenable
+16bpp drawing cache, to speed up software UI rendering.
+
+(Original author: Grigori Goronzy <greg@blackbox>)
+
+Change-Id: I292f77a4481e86964255d7b59c9407f5e99a8e08
+---
+ core/java/android/view/ViewRootImpl.java | 2 +-
+ graphics/java/android/graphics/Bitmap.java | 1 +
+ graphics/java/android/graphics/BitmapFactory.java | 6 +++---
+ 3 files changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
+index 6c982eb..9a02ca6 100644
+--- a/core/java/android/view/ViewRootImpl.java
++++ b/core/java/android/view/ViewRootImpl.java
+@@ -935,7 +935,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,
+ // We used to use the following condition to choose 32 bits drawing caches:
+ // PixelFormat.hasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888
+ // However, windows are now always 32 bits by default, so choose 32 bits
+- attachInfo.mUse32BitDrawingCache = true;
++ attachInfo.mUse32BitDrawingCache = PixelFormat.formatHasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888;
+ attachInfo.mHasWindowFocus = false;
+ attachInfo.mWindowVisibility = viewVisibility;
+ attachInfo.mRecomputeGlobalAttributes = false;
+diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
+index 380b3d8..4015544 100644
+--- a/graphics/java/android/graphics/Bitmap.java
++++ b/graphics/java/android/graphics/Bitmap.java
+@@ -555,6 +555,7 @@ public final class Bitmap implements Parcelable {
+ canvas.concat(m);
+
+ paint = new Paint();
++ paint.setDither(true);
+ paint.setFilterBitmap(filter);
+ if (transformed) {
+ paint.setAntiAlias(true);
+diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
+index 8d17561..6de8986 100644
+--- a/graphics/java/android/graphics/BitmapFactory.java
++++ b/graphics/java/android/graphics/BitmapFactory.java
+@@ -38,7 +38,7 @@ public class BitmapFactory {
+ * the same result from the decoder as if null were passed.
+ */
+ public Options() {
+- inDither = false;
++ inDither = true;
+ inScaled = true;
+ }
+
+@@ -98,10 +98,10 @@ public class BitmapFactory {
+ * system's screen depth, and characteristics of the original image such
+ * as if it has per-pixel alpha (requiring a config that also does).
+ *
+- * Image are loaded with the {@link Bitmap.Config#ARGB_8888} config by
++ * Image are loaded with the {@link Bitmap.Config#RGB_565} config by
+ * default.
+ */
+- public Bitmap.Config inPreferredConfig = Bitmap.Config.ARGB_8888;
++ public Bitmap.Config inPreferredConfig = Bitmap.Config.RGB_565;
+
+ /**
+ * If dither is true, the decoder will attempt to dither the decoded
+--
+1.7.10.4
+
View
69 patches/frameworks_base/0001-Prefer-16bpp-surface-formats.patch
@@ -0,0 +1,69 @@
+From f790f290a3de5d20918e8aa43bb493cfe552708d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jo=C3=A3o=20Ventura?= <joaojonesventura@gmail.com>
+Date: Wed, 30 Jan 2013 17:50:41 +0000
+Subject: [PATCH] Prefer 16bpp surface formats
+
+Adds a property to use RGB565 surface formats for the opaque
+surface default, enabled by default.
+
+(Original author: Grigori Goronzy <greg@blackbox>)
+
+Change-Id: Ia5aa00b9fcb197d25f7107a569103389a0337eb3
+---
+ services/surfaceflinger/SurfaceFlinger.cpp | 11 +++++++++--
+ services/surfaceflinger/SurfaceFlinger.h | 2 +-
+ 2 files changed, 10 insertions(+), 3 deletions(-)
+
+diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
+index ca4f155..34eca35 100644
+--- a/services/surfaceflinger/SurfaceFlinger.cpp
++++ b/services/surfaceflinger/SurfaceFlinger.cpp
+@@ -113,7 +113,8 @@ SurfaceFlinger::SurfaceFlinger()
+ #endif
+ mConsoleSignals(0),
+ mSecureFrameBuffer(0),
+- mUseDithering(false)
++ mUseDithering(false),
++ mPrefer16bpp(0)
+ {
+ init();
+ }
+@@ -137,6 +138,9 @@ void SurfaceFlinger::init()
+ property_get("persist.sys.use_dithering", value, "0");
+ mUseDithering = atoi(value) == 1;
+
++ property_get("persist.sys.prefer_16bpp", value, "1");
++ mPrefer16bpp = atoi(value);
++
+ if (mDebugDDMS) {
+ DdmConnection::start(getServiceName());
+ }
+@@ -1552,7 +1556,10 @@ sp<Layer> SurfaceFlinger::createNormalSurface(
+ #ifdef NO_RGBX_8888
+ format = PIXEL_FORMAT_RGB_565;
+ #else
+- format = PIXEL_FORMAT_RGBX_8888;
++ if (mPrefer16bpp)
++ format = PIXEL_FORMAT_RGB_565;
++ else
++ format = PIXEL_FORMAT_RGBX_8888;
+ #endif
+ break;
+ }
+diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
+index e6b465d..83c4f18 100644
+--- a/services/surfaceflinger/SurfaceFlinger.h
++++ b/services/surfaceflinger/SurfaceFlinger.h
+@@ -443,8 +443,8 @@ private:
+
+ // only written in the main thread, only read in other threads
+ volatile int32_t mSecureFrameBuffer;
+-
+ bool mUseDithering;
++ bool mPrefer16bpp;
+ };
+
+ // ---------------------------------------------------------------------------
+--
+1.7.10.4
+
View
79 patches/frameworks_base/0001-Use-RGB565-surface-for-wallpaper.patch
@@ -0,0 +1,79 @@
+From b9f2076ce646f73af55e4789a3d75dcae88c547d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jo=C3=A3o=20Ventura?= <joaojonesventura@gmail.com>
+Date: Wed, 30 Jan 2013 17:32:47 +0000
+Subject: [PATCH] Use RGB565 surface for wallpaper
+
+The framebuffer only uses 16bpp on most legacy devices anyway, so this
+does not result in worse quality. It saves a lot of GPU fillrate and
+memory, though.
+
+(Original author: Grigori Goronzy <greg@blackbox>)
+
+Change-Id: I0133dec0ee0e122248027b422ba13b03f55e57a9
+---
+ core/java/android/app/WallpaperManager.java | 4 ++--
+ core/java/android/service/wallpaper/WallpaperService.java | 2 +-
+ packages/SystemUI/src/com/android/systemui/ImageWallpaper.java | 5 ++++-
+ 3 files changed, 7 insertions(+), 4 deletions(-)
+
+diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
+index b1c1f30..dcd640c 100644
+--- a/core/java/android/app/WallpaperManager.java
++++ b/core/java/android/app/WallpaperManager.java
+@@ -350,7 +350,7 @@ public class WallpaperManager {
+ Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true);
+ if (bm != null) {
+ Drawable dr = new BitmapDrawable(mContext.getResources(), bm);
+- dr.setDither(false);
++ dr.setDither(true);
+ return dr;
+ }
+ return null;
+@@ -369,7 +369,7 @@ public class WallpaperManager {
+ Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false);
+ if (bm != null) {
+ Drawable dr = new BitmapDrawable(mContext.getResources(), bm);
+- dr.setDither(false);
++ dr.setDither(true);
+ return dr;
+ }
+ return null;
+diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java
+index 18167b6..c95363c 100644
+--- a/core/java/android/service/wallpaper/WallpaperService.java
++++ b/core/java/android/service/wallpaper/WallpaperService.java
+@@ -186,7 +186,7 @@ public abstract class WallpaperService extends Service {
+
+ final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {
+ {
+- mRequestedFormat = PixelFormat.RGBX_8888;
++ mRequestedFormat = PixelFormat.RGB_565;
+ }
+
+ @Override
+diff --git a/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
+index 724679f..fc46443 100644
+--- a/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
++++ b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
+@@ -23,6 +23,7 @@ import android.content.Context;
+ import android.content.Intent;
+ import android.graphics.Bitmap;
+ import android.graphics.Canvas;
++import android.graphics.Paint;
+ import android.graphics.Rect;
+ import android.graphics.Region.Op;
+ import android.opengl.GLUtils;
+@@ -372,7 +373,9 @@ public class ImageWallpaper extends WallpaperService {
+ c.restore();
+ }
+ if (mBackground != null) {
+- c.drawBitmap(mBackground, 0, 0, null);
++ Paint paint = new Paint();
++ paint.setDither(true);
++ c.drawBitmap(mBackground, 0, 0, paint);
+ }
+ } finally {
+ sh.unlockCanvasAndPost(c);
+--
+1.7.10.4
+

0 comments on commit 1c3c82e

Please sign in to comment.