Bug 1258470 - Part 6: Update LayerView in response to Tab.SELECTED from outside omg.gfx. draft
authorNick Alexander <nalexander@mozilla.com>
Thu, 23 Jun 2016 15:01:53 -0700
changeset 380998 1c69c10d3f5f6015ecb7cdb6dfe26e555276cad1
parent 380997 309b70ce9ddb237667e9011007ac1e90c97aab27
child 380999 bbdf1277e792b27926ad3917a5c476be61c2fa50
push id21383
push usernalexander@mozilla.com
push dateFri, 24 Jun 2016 00:16:43 +0000
bugs1258470
milestone50.0a1
Bug 1258470 - Part 6: Update LayerView in response to Tab.SELECTED from outside omg.gfx. MozReview-Commit-ID: 7qD2gdiyQkh
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/gfx/LayerRenderer.java
mobile/android/base/java/org/mozilla/gecko/gfx/LayerView.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -279,36 +279,46 @@ public abstract class GeckoApp
     public FormAssistPopup getFormAssistPopup() {
         return mFormAssistPopup;
     }
 
     @Override
     public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
         // When a tab is closed, it is always unselected first.
         // When a tab is unselected, another tab is always selected first.
+        final LayerView layerView = mLayerView;
+
         switch (msg) {
             case UNSELECTED:
                 hidePlugins(tab);
                 break;
 
             case LOCATION_CHANGE:
                 // We only care about location change for the selected tab.
                 if (!Tabs.getInstance().isSelectedTab(tab))
                     break;
                 // Fall through...
             case SELECTED:
                 invalidateOptionsMenu();
                 if (mFormAssistPopup != null)
                     mFormAssistPopup.hide();
+
+                // Sets the background of the newly selected tab. This background color
+                // gets cleared in endDrawing(). This function runs on the UI thread,
+                // but other code that touches the paint state is run on the compositor
+                // thread, so this may need to be changed if any problems appear.
+                if (layerView != null) {
+                    layerView.setSurfaceBackgroundColor(tab.getBackgroundColor());
+                    layerView.setPaintState(LayerView.PAINT_START);
+                }
                 break;
 
             case LOADED:
                 // Sync up the layer view and the tab if the tab is
                 // currently displayed.
-                LayerView layerView = mLayerView;
                 if (layerView != null && Tabs.getInstance().isSelectedTab(tab))
                     layerView.setBackgroundColor(tab.getBackgroundColor());
                 break;
 
             case DESKTOP_MODE_CHANGE:
                 if (Tabs.getInstance().isSelectedTab(tab))
                     invalidateOptionsMenu();
                 break;
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/LayerRenderer.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/LayerRenderer.java
@@ -1,18 +1,16 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.gfx;
 
 import org.mozilla.gecko.GeckoAppShell;
-import org.mozilla.gecko.Tab;
-import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.gfx.Layer.RenderContext;
 import org.mozilla.gecko.mozglue.DirectBufferAllocator;
 
 import android.graphics.Color;
 import android.graphics.RectF;
 import android.opengl.GLES20;
 import android.util.Log;
 
@@ -27,17 +25,17 @@ import java.util.concurrent.CopyOnWriteA
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.microedition.khronos.egl.EGLConfig;
 
 /**
  * The layer renderer implements the rendering logic for a layer view.
  */
-public class LayerRenderer implements Tabs.OnTabsChangedListener {
+public class LayerRenderer {
     private static final String LOGTAG = "GeckoLayerRenderer";
     private static final String PROFTAG = "GeckoLayerRendererProf";
 
     private static final int NANOS_PER_SECOND = 1000000000;
 
     private static final int MAX_SCROLL_SPEED_TO_REQUEST_ZOOM_RENDER = 5;
 
     private final LayerView mView;
@@ -114,27 +112,25 @@ public class LayerRenderer implements Ta
         "}\n";
 
     public LayerRenderer(LayerView view) {
         mView = view;
 
         mTasks = new CopyOnWriteArrayList<RenderTask>();
         mLastFrameTime = System.nanoTime();
 
-        Tabs.registerOnTabsChangedListener(this);
         mZoomedViewListeners = new ArrayList<LayerView.ZoomedViewListener>();
     }
 
     public void destroy() {
         if (mCoordByteBuffer != null) {
             DirectBufferAllocator.free(mCoordByteBuffer);
             mCoordByteBuffer = null;
             mCoordBuffer = null;
         }
-        Tabs.unregisterOnTabsChangedListener(this);
         mZoomedViewListeners.clear();
     }
 
     void onSurfaceCreated(EGLConfig config) {
         checkMonitoringEnabled();
         createDefaultProgram();
         activateDefaultProgram();
     }
@@ -485,30 +481,16 @@ public class LayerRenderer implements Ta
                     }
                 });
                 mView.setPaintState(LayerView.PAINT_AFTER_FIRST);
             }
             mLastFrameTime = mFrameStartTime;
         }
     }
 
-    @Override
-    public void onTabChanged(final Tab tab, Tabs.TabEvents msg, String data) {
-        // Sets the background of the newly selected tab. This background color
-        // gets cleared in endDrawing(). This function runs on the UI thread,
-        // but other code that touches the paint state is run on the compositor
-        // thread, so this may need to be changed if any problems appear.
-        if (msg == Tabs.TabEvents.SELECTED) {
-            if (mView != null) {
-                mView.setSurfaceBackgroundColor(tab.getBackgroundColor());
-                mView.setPaintState(LayerView.PAINT_START);
-            }
-        }
-    }
-
     public void updateZoomedView(final ByteBuffer data) {
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
                 for (LayerView.ZoomedViewListener listener : mZoomedViewListeners) {
                     data.position(0);
                     listener.updateView(data);
                 }
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/LayerView.java
@@ -352,17 +352,17 @@ public class LayerView extends ScrollVie
     }
 
     @Override
     public void setBackgroundColor(int newColor) {
         mBackgroundColor = newColor;
         requestRender();
     }
 
-    void setSurfaceBackgroundColor(int newColor) {
+    public void setSurfaceBackgroundColor(int newColor) {
         if (mSurfaceView != null) {
             mSurfaceView.setBackgroundColor(newColor);
         }
     }
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
         if (AppConstants.MOZ_ANDROID_APZ && !mLayerClient.isGeckoReady()) {