Bug 793771 - Use drawing cache on the tabs pane sliding on pre-ICS phone (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Mon, 15 Oct 2012 16:18:30 +0100
changeset 110293 1a3fae956dd782839400125555a0fafc5fb4d77f
parent 110292 49b130f753d3837eb460d296be14499c9966a603
child 110294 64bf0d8480a55d9adebdab86d2da017684270622
push id23680
push useremorley@mozilla.com
push dateTue, 16 Oct 2012 08:09:24 +0000
treeherdermozilla-central@8f145599e4bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs793771
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 793771 - Use drawing cache on the tabs pane sliding on pre-ICS phone (r=mfinkle)
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoApp.java
mobile/android/base/PropertyAnimator.java
mobile/android/base/gfx/LayerView.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -547,23 +547,27 @@ abstract public class BrowserApp extends
     public void onPropertyAnimationStart() {
         mBrowserToolbar.updateTabs(true);
 
         // Although the tabs panel is not animating per se, it will be re-drawn several
         // times while the main/gecko layout slides to left/top. Adding a hardware layer
         // here considerably improves the frame rate of the animation.
         if (Build.VERSION.SDK_INT >= 11)
             mTabsPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
+        else
+            mTabsPanel.setDrawingCacheEnabled(true);
     }
 
     @Override
     public void onPropertyAnimationEnd() {
         // Destroy the hardware layer used during the animation
         if (Build.VERSION.SDK_INT >= 11)
             mTabsPanel.setLayerType(View.LAYER_TYPE_NONE, null);
+        else
+            mTabsPanel.setDrawingCacheEnabled(false);
 
         if (hasTabsSideBar() && mTabsPanel.isShown()) {
             boolean usingTextureView = mLayerView.shouldUseTextureView();
 
             int leftMargin = (usingTextureView ? 0 : mTabsPanel.getWidth());
             int rightMargin = (usingTextureView ? mTabsPanel.getWidth() : 0);
             ((LinearLayout.LayoutParams) mGeckoLayout.getLayoutParams()).setMargins(leftMargin, 0, rightMargin, 0);
 
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2598,16 +2598,24 @@ abstract public class GeckoApp
         }
 
         @Override
         public boolean onTouchEvent(MotionEvent event) {
             if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onTouch(this, event))
                 return true;
             return super.onTouchEvent(event);
         }
+
+        @Override
+        public void setDrawingCacheEnabled(boolean enabled) {
+            // Instead of setting drawing cache in the view itself, we simply
+            // enable drawing caching on its children. This is mainly used in
+            // animations (see PropertyAnimator)
+            super.setChildrenDrawnWithCacheEnabled(enabled);
+        }
     }
 
     public boolean linkerExtract() {
         return false;
     }
 
     private class FullScreenHolder extends FrameLayout {
 
--- a/mobile/android/base/PropertyAnimator.java
+++ b/mobile/android/base/PropertyAnimator.java
@@ -117,34 +117,39 @@ public class PropertyAnimator implements
                 element.from = element.proxy.getScrollY();
             else if (element.property == Property.SCROLL_X)
                 element.from = element.proxy.getScrollX();
             else if (element.property == Property.HEIGHT)
                 element.from = element.proxy.getHeight();
 
             if (shouldEnableHardwareLayer(element))
                 element.view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
+            else
+                element.view.setDrawingCacheEnabled(true);
         }
 
         if (mDuration != 0) {
             mFramePoster.postFirstAnimationFrame();
 
             if (mListener != null)
                 mListener.onPropertyAnimationStart();
         }
     }
 
     public void stop() {
         mFramePoster.cancelAnimationFrame();
 
         // Make sure to snap to the end position.
         for (ElementHolder element : mElementsList) { 
             invalidate(element, element.to);
+
             if (shouldEnableHardwareLayer(element))
                 element.view.setLayerType(View.LAYER_TYPE_NONE, null);
+            else
+                element.view.setDrawingCacheEnabled(false);
         }
 
         mElementsList.clear();
 
         if (mListener != null) {
             mListener.onPropertyAnimationEnd();
             mListener = null;
         }
--- a/mobile/android/base/gfx/LayerView.java
+++ b/mobile/android/base/gfx/LayerView.java
@@ -101,16 +101,20 @@ public class LayerView extends FrameLayo
         // initializeView() is called on the initialization phase of GeckoApp,
         // which is late enough to detect hardware acceleration properly.
         if (shouldUseTextureView()) {
             mTextureView = new TextureView(getContext());
             mTextureView.setSurfaceTextureListener(new SurfaceTextureListener());
             mTextureView.setBackgroundColor(Color.WHITE);
             addView(mTextureView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
         } else {
+            // This will stop PropertyAnimator from creating a drawing cache (i.e. a bitmap)
+            // from a SurfaceView, which is just not possible (the bitmap will be transparent).
+            setWillNotCacheDrawing(false);
+
             mSurfaceView = new SurfaceView(getContext());
             mSurfaceView.setBackgroundColor(Color.WHITE);
             addView(mSurfaceView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
 
             SurfaceHolder holder = mSurfaceView.getHolder();
             holder.addCallback(new SurfaceListener());
             holder.setFormat(PixelFormat.RGB_565);
         }