From 0a0d87e5db133ce769da654d6ed9a5fbe2ac75f9 Mon Sep 17 00:00:00 2001 From: Erwin Pannecoucke Date: Sat, 29 Dec 2012 12:29:30 +0100 Subject: [PATCH] Trebuchet: port wallpaper hack Normally the wallpaper is drawn by the system in a separate window. This means that the wallpaper can often be drawn out of sync with the launcher. This hack gets the wallpaper bitmap and draws it manually (in sync with the rest of the launcher). This increases performance greatly. This is a port from the cm-10.1 branch http://review.cyanogenmod.org/#/c/27326/3 --- patches/ApplyPatches.sh | 15 + ...t_0001-Trebuchet-port-wallpaper-hack.patch | 307 ++++++++++++++++++ 2 files changed, 322 insertions(+) create mode 100644 patches/packages_apps_Trebuchet_0001-Trebuchet-port-wallpaper-hack.patch diff --git a/patches/ApplyPatches.sh b/patches/ApplyPatches.sh index 1a24852..48e4936 100644 --- a/patches/ApplyPatches.sh +++ b/patches/ApplyPatches.sh @@ -1 +1,16 @@ #!/bin/sh +echo "removing old patches..." +rm ../../../../packages/apps/Trebuchet/*.patch + +echo +echo "Copying files..." +cp packages_apps_Trebuchet* ../../../../packages/apps/Trebuchet/ +echo + +echo "cd packages/apps/Trebuchet" +cd ../../../../packages/apps/Trebuchet/ +echo "apply patch" +git am *.patch +echo + +cd ../../../ diff --git a/patches/packages_apps_Trebuchet_0001-Trebuchet-port-wallpaper-hack.patch b/patches/packages_apps_Trebuchet_0001-Trebuchet-port-wallpaper-hack.patch new file mode 100644 index 0000000..582e661 --- /dev/null +++ b/patches/packages_apps_Trebuchet_0001-Trebuchet-port-wallpaper-hack.patch @@ -0,0 +1,307 @@ +From 500ee5e5918f337385b37ca4314f4a264a524087 Mon Sep 17 00:00:00 2001 +From: Erwin Pannecoucke +Date: Sat, 29 Dec 2012 12:20:24 +0100 +Subject: [PATCH] Trebuchet: port wallpaper hack + +Normally the wallpaper is drawn by the system in a separate window. +This means that the wallpaper can often be drawn out of sync with +the launcher. This hack gets the wallpaper bitmap and draws it +manually (in sync with the rest of the launcher). This increases +performance greatly. + +This is a port from the cm-10.1 branch +http://review.cyanogenmod.org/#/c/27326/3 + +Change-Id: I10d8586b011f205b36c8604f993256cb23045663 +--- + res/layout-port/launcher.xml | 26 ++++--- + res/values/strings.xml | 2 + + res/xml/preferences.xml | 4 ++ + src/com/cyanogenmod/trebuchet/Launcher.java | 12 +++- + src/com/cyanogenmod/trebuchet/Workspace.java | 75 ++++++++++++++++++-- + .../trebuchet/preference/PreferencesProvider.java | 4 ++ + 6 files changed, 102 insertions(+), 21 deletions(-) + +diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml +index fd3a843..80cc763 100644 +--- a/res/layout-port/launcher.xml ++++ b/res/layout-port/launcher.xml +@@ -22,9 +22,18 @@ + android:layout_width="match_parent" + android:layout_height="match_parent"> + +- +- ++ ++ ++ + +- +- +- + + Fade the side pages when scrolling homescreens + Scroll wallpaper + Scroll wallpaper when scrolling homescreens ++Wallpaper quick render ++ Use wallpaper hack that increases smoothness on static image wallpapers + Indicator + Show page indicator + Show current page indicator at the bottom of the screen +diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml +index 1bbc9ac..0351d47 100644 +--- a/res/xml/preferences.xml ++++ b/res/xml/preferences.xml +@@ -84,6 +84,10 @@ + android:title="@string/preferences_interface_homescreen_scrolling_scroll_wallpaper_title" + android:summary="@string/preferences_interface_homescreen_scrolling_scroll_wallpaper_summary" + android:defaultValue="true" /> ++ + + +diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java +index 9283243..50e4260 100644 +--- a/src/com/cyanogenmod/trebuchet/Launcher.java ++++ b/src/com/cyanogenmod/trebuchet/Launcher.java +@@ -263,6 +263,8 @@ public final class Launcher extends Activity + private boolean mHideIconLabels; + private boolean mAutoRotate; + ++ private boolean mWallpaperVisible; ++ + private Runnable mBuildLayersRunnable = new Runnable() { + public void run() { + if (mWorkspace != null) { +@@ -1093,6 +1095,8 @@ public final class Launcher extends Activity + } else if (Intent.ACTION_USER_PRESENT.equals(action)) { + mUserPresent = true; + updateRunning(); ++ } else if (Intent.ACTION_SET_WALLPAPER.equals(action)) { ++ mWorkspace.checkWallpaper(); + } + } + }; +@@ -1105,6 +1109,7 @@ public final class Launcher extends Activity + final IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_SCREEN_OFF); + filter.addAction(Intent.ACTION_USER_PRESENT); ++ filter.addAction(Intent.ACTION_SET_WALLPAPER); + registerReceiver(mReceiver, filter); + + mAttached = true; +@@ -2282,8 +2287,13 @@ public final class Launcher extends Activity + view.setPivotY(view.getHeight() / 2.0f); + } + ++ void setWallpaperVisibility(boolean visible) { ++ mWallpaperVisible = visible; ++ updateWallpaperVisibility(visible); ++ } ++ + void updateWallpaperVisibility(boolean visible) { +- int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; ++ int wpflags = visible && mWallpaperVisible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; + int curflags = getWindow().getAttributes().flags + & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; + if (wpflags != curflags) { +diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java +index 5a03a2f..e7763e7 100644 +--- a/src/com/cyanogenmod/trebuchet/Workspace.java ++++ b/src/com/cyanogenmod/trebuchet/Workspace.java +@@ -49,6 +49,7 @@ import android.graphics.PorterDuff; + import android.graphics.Rect; + import android.graphics.RectF; + import android.graphics.Region.Op; ++import android.graphics.drawable.BitmapDrawable; + import android.graphics.drawable.Drawable; + import android.os.IBinder; + import android.os.Parcelable; +@@ -118,8 +119,14 @@ public class Workspace extends PagedView + private float mWallpaperScrollRatio = 1.0f; + + private final WallpaperManager mWallpaperManager; ++ private boolean mWallpaperHack; ++ private Bitmap mWallpaperBitmap; ++ private float mWallpaperScrollX; ++ private float mWallpaperScrollY; ++ private int[] mWallpaperOffsets = new int[2]; ++ private Paint mPaint = new Paint(); + private IBinder mWindowToken; +- private static final float WALLPAPER_SCREENS_SPAN = 2f; ++ private static final float DEFAULT_WALLPAPER_SCREENS_SPAN = 2f; + + /** + * CellInfo for the cell that is currently being dragged +@@ -343,12 +350,14 @@ public class Workspace extends PagedView + res.getString(R.string.config_workspaceDefaultTransitionEffect)); + mFadeInAdjacentScreens = PreferencesProvider.Interface.Homescreen.Scrolling.getFadeInAdjacentScreens(context, + res.getBoolean(R.bool.config_workspaceDefualtFadeInAdjacentScreens)); ++ mWallpaperHack = PreferencesProvider.Interface.Homescreen.Scrolling.getWallpaperHack(context); + mShowScrollingIndicator = PreferencesProvider.Interface.Homescreen.Indicator.getShowScrollingIndicator(context); + mFadeScrollingIndicator = PreferencesProvider.Interface.Homescreen.Indicator.getFadeScrollingIndicator(context); + mShowDockDivider = PreferencesProvider.Interface.Homescreen.Indicator.getShowDockDivider(context); + + mLauncher = (Launcher) context; + initWorkspace(); ++ checkWallpaper(); + + // Disable multitouch across the workspace/all apps/customize tray + setMotionEventSplittingEnabled(true); +@@ -519,6 +528,21 @@ public class Workspace extends PagedView + } + } + ++ protected void checkWallpaper() { ++ if (mWallpaperHack) { ++ if (mWallpaperBitmap != null) { ++ mWallpaperBitmap = null; ++ } ++ if (mWallpaperManager.getWallpaperInfo() == null) { ++ Drawable wallpaper = mWallpaperManager.getDrawable(); ++ if (wallpaper instanceof BitmapDrawable) { ++ mWallpaperBitmap = ((BitmapDrawable) wallpaper).getBitmap(); ++ } ++ } ++ } ++ mLauncher.setWallpaperVisibility(mWallpaperBitmap == null); ++ } ++ + @Override + protected void onViewAdded(View child) { + super.onViewAdded(child); +@@ -887,7 +911,7 @@ public class Workspace extends PagedView + mWallpaperWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim)); + mWallpaperHeight = maxDim; + } else { +- mWallpaperWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim); ++ mWallpaperWidth = Math.max((int) (minDim * DEFAULT_WALLPAPER_SCREENS_SPAN), maxDim); + mWallpaperHeight = maxDim; + } + new Thread("setWallpaperDimension") { +@@ -948,9 +972,13 @@ public class Workspace extends PagedView + } + + private void centerWallpaperOffset() { +- mWallpaperManager.setWallpaperOffsetSteps(0.5f, 0); +- mWallpaperManager.setWallpaperOffsets(getWindowToken(), 0.5f, 0); +- } ++ if (mWallpaperHack) { ++ mWallpaperScrollX = 0.5f; ++ } else if (mWindowToken != null) { ++ mWallpaperManager.setWallpaperOffsetSteps(0.5f, 0); ++ mWallpaperManager.setWallpaperOffsets(getWindowToken(), 0.5f, 0); ++ } ++ } + + public void updateWallpaperOffsetImmediately() { + mUpdateWallpaperOffsetImmediately = true; +@@ -968,7 +996,10 @@ public class Workspace extends PagedView + updateNow = keepUpdating = mWallpaperOffset.computeScrollOffset(); + } + if (updateNow) { +- if (mWindowToken != null) { ++ if (mWallpaperHack) { ++ mWallpaperScrollX = mWallpaperOffset.getCurrX(); ++ mWallpaperScrollY = mWallpaperOffset.getCurrY(); ++ } else if (mWindowToken != null) { + mWallpaperManager.setWallpaperOffsets(mWindowToken, + mWallpaperOffset.getCurrX(), mWallpaperOffset.getCurrY()); + } +@@ -1549,12 +1580,44 @@ public class Workspace extends PagedView + } + } + ++ protected void onSizeChanged (int w, int h, int oldw, int oldh) { ++ super.onSizeChanged(w, h, oldw, oldh); ++ ++ getLocationOnScreen(mWallpaperOffsets); 1429 ++ } ++ + @Override + protected void onDraw(Canvas canvas) { + if (mScrollWallpaper) { + updateWallpaperOffsets(); + } + ++ // Draw the wallpaper if necessary ++ if (mWallpaperHack && mWallpaperBitmap != null) { ++ float x = getScrollX(); ++ float y = getScrollY(); ++ ++ int width = getWidth(); ++ int height = getHeight(); ++ int wallpaperWidth = mWallpaperBitmap.getWidth(); ++ int wallpaperHeight = mWallpaperBitmap.getHeight(); ++ ++ if (width + mWallpaperOffsets[0] > wallpaperWidth) { ++ // Wallpaper is smaller than screen ++ x += (width - wallpaperWidth) / 2; ++ } else { ++ x -= mWallpaperScrollX * (wallpaperWidth - width) + mWallpaperOffsets[0]; ++ } ++ if (height + mWallpaperOffsets[1] > wallpaperHeight) { ++ // Wallpaper is smaller than screen ++ y += (height - wallpaperHeight) / 2; ++ } else { ++ y -= mWallpaperScrollY * (wallpaperHeight - height) + mWallpaperOffsets[1]; ++ } ++ ++ canvas.drawBitmap(mWallpaperBitmap, x, y, mPaint); ++ } ++ + // Draw the background gradient if necessary + if (mBackground != null && mBackgroundAlpha > 0.0f && mDrawBackground) { + int alpha = (int) (mBackgroundAlpha * 255); +diff --git a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java +index 2b68ffd..61f05bd 100644 +--- a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java ++++ b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java +@@ -83,6 +83,10 @@ public final class PreferencesProvider { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + return preferences.getBoolean("ui_homescreen_scrolling_scroll_wallpaper", true); + } ++ public static boolean getWallpaperHack(Context context) { ++ final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); ++ return preferences.getBoolean("ui_homescreen_scrolling_wallpaper_hack", true); ++ } + public static Workspace.TransitionEffect getTransitionEffect(Context context, String def) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + return Workspace.TransitionEffect.valueOf( +-- +1.7.9.5 +