Bug 1288834 - Remove ZOOMEDVIEW event from GeckoEvent; r=snorp
authorJim Chen <nchen@mozilla.com>
Thu, 04 Aug 2016 09:15:17 -0400
changeset 308192 32966f97f82e60c65372de3a2ee7bb11d3c1cb10
parent 308191 4c7c02cdc1b9e3f04059f3054ed8711529a364fe
child 308193 9a90e9fe5bf1c99dc1f049b259155c5f89e5e26d
push idunknown
push userunknown
push dateunknown
reviewerssnorp
bugs1288834
milestone51.0a1
Bug 1288834 - Remove ZOOMEDVIEW event from GeckoEvent; r=snorp Remove the now-obsolete ZOOMEDVIEW event from GeckoEvent, and the associated code in nsAppShell and AndroidBridge.
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEvent.java
widget/android/AndroidBridge.cpp
widget/android/AndroidBridge.h
widget/android/AndroidJavaWrappers.cpp
widget/android/AndroidJavaWrappers.h
widget/android/nsAppShell.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEvent.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEvent.java
@@ -70,18 +70,17 @@ public class GeckoEvent {
         CALL_OBSERVER(33),
         REMOVE_OBSERVER(34),
         TELEMETRY_HISTOGRAM_ADD(37),
         TELEMETRY_UI_SESSION_START(42),
         TELEMETRY_UI_SESSION_STOP(43),
         TELEMETRY_UI_EVENT(44),
         GAMEPAD_ADDREMOVE(45),
         GAMEPAD_DATA(46),
-        LONG_PRESS(47),
-        ZOOMEDVIEW(48);
+        LONG_PRESS(47);
 
         public final int value;
 
         private NativeGeckoEvent(int value) {
             this.value = value;
         }
     }
 
@@ -113,18 +112,16 @@ public class GeckoEvent {
 
     private int mMetaState;
     private int mFlags;
     private int mCount;
     private String mCharacters;
     private String mCharactersExtra;
     private String mData;
 
-    private ByteBuffer mBuffer;
-
     private int mWidth;
     private int mHeight;
 
     private int mID;
     private int mGamepadButton;
     private boolean mGamepadButtonPressed;
     private float mGamepadButtonValue;
     private float[] mGamepadValues;
@@ -327,27 +324,16 @@ public class GeckoEvent {
           .append(", \"y\" : ").append(metrics.viewportRectTop)
           .append(", \"zoom\" : ").append(metrics.zoomFactor)
           .append(", \"displayPort\" :").append(displayPort.toJSON())
           .append('}');
         event.mCharactersExtra = sb.toString();
         return event;
     }
 
-    public static GeckoEvent createZoomedViewEvent(int tabId, int x, int y, int bufw, int bufh, float scaleFactor, ByteBuffer buffer) {
-        GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.ZOOMEDVIEW);
-        event.mPoints = new Point[2];
-        event.mPoints[0] = new Point(x, y);
-        event.mPoints[1] = new Point(bufw, bufh);
-        event.mX = (double) scaleFactor;
-        event.mMetaState = tabId;
-        event.mBuffer = buffer;
-        return event;
-    }
-
     public static GeckoEvent createCallObserverEvent(String observerKey, String topic, String data) {
         GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.CALL_OBSERVER);
         event.mCharacters = observerKey;
         event.mCharactersExtra = topic;
         event.mData = data;
         return event;
     }
 
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -1655,100 +1655,16 @@ AndroidBridge::GetFrameNameJavaProfiling
 
     if (!jstrSampleName)
         return false;
 
     aResult = jstrSampleName->ToCString();
     return true;
 }
 
-static float
-GetScaleFactor(nsPresContext* aPresContext) {
-    nsIPresShell* presShell = aPresContext->PresShell();
-    LayoutDeviceToLayerScale cumulativeResolution(presShell->GetCumulativeResolution());
-    return cumulativeResolution.scale;
-}
-
-nsresult
-AndroidBridge::CaptureZoomedView(mozIDOMWindowProxy *window, nsIntRect zoomedViewRect, ByteBuffer::Param buffer,
-                                  float zoomFactor) {
-    nsresult rv;
-
-    if (!buffer)
-        return NS_ERROR_FAILURE;
-
-    nsCOMPtr <nsIDOMWindowUtils> utils = do_GetInterface(window);
-    if (!utils)
-        return NS_ERROR_FAILURE;
-
-    JNIEnv* const env = jni::GetGeckoThreadEnv();
-
-    AutoLocalJNIFrame jniFrame(env, 0);
-
-    if (!window) {
-        return NS_ERROR_FAILURE;
-    }
-
-    nsCOMPtr<nsPIDOMWindowOuter> win = nsPIDOMWindowOuter::From(window);
-    RefPtr<nsPresContext> presContext;
-    nsIDocShell* docshell = win->GetDocShell();
-
-    if (docshell) {
-        docshell->GetPresContext(getter_AddRefs(presContext));
-    }
-
-    if (!presContext) {
-        return NS_ERROR_FAILURE;
-    }
-    nsCOMPtr <nsIPresShell> presShell = presContext->PresShell();
-
-    float scaleFactor = GetScaleFactor(presContext) ;
-
-    nscolor bgColor = NS_RGB(255, 255, 255);
-    uint32_t renderDocFlags = (nsIPresShell::RENDER_IGNORE_VIEWPORT_SCROLLING | nsIPresShell::RENDER_DOCUMENT_RELATIVE);
-    nsRect r(presContext->DevPixelsToAppUnits(zoomedViewRect.x / scaleFactor),
-             presContext->DevPixelsToAppUnits(zoomedViewRect.y / scaleFactor ),
-             presContext->DevPixelsToAppUnits(zoomedViewRect.width / scaleFactor ),
-             presContext->DevPixelsToAppUnits(zoomedViewRect.height / scaleFactor ));
-
-    bool is24bit = (GetScreenDepth() == 24);
-    SurfaceFormat format = is24bit ? SurfaceFormat::B8G8R8X8 : SurfaceFormat::R5G6B5_UINT16;
-    gfxImageFormat iFormat = gfx::SurfaceFormatToImageFormat(format);
-    uint32_t stride = gfxASurface::FormatStrideForWidth(iFormat, zoomedViewRect.width);
-
-    uint8_t* data = static_cast<uint8_t*>(buffer->Address());
-    if (!data) {
-        return NS_ERROR_FAILURE;
-    }
-
-    MOZ_ASSERT (gfxPlatform::GetPlatform()->SupportsAzureContentForType(BackendType::CAIRO),
-              "Need BackendType::CAIRO support");
-    RefPtr < DrawTarget > dt = Factory::CreateDrawTargetForData(
-        BackendType::CAIRO, data, IntSize(zoomedViewRect.width, zoomedViewRect.height), stride,
-        format);
-    if (!dt || !dt->IsValid()) {
-        ALOG_BRIDGE("Error creating DrawTarget");
-        return NS_ERROR_FAILURE;
-    }
-    RefPtr<gfxContext> context = gfxContext::CreateOrNull(dt);
-    MOZ_ASSERT(context); // already checked the draw target above
-    context->SetMatrix(context->CurrentMatrix().Scale(zoomFactor, zoomFactor));
-
-    rv = presShell->RenderDocument(r, renderDocFlags, bgColor, context);
-
-    if (is24bit) {
-        gfxUtils::ConvertBGRAtoRGBA(data, stride * zoomedViewRect.height);
-    }
-
-    LayerView::UpdateZoomedView(buffer);
-
-    NS_ENSURE_SUCCESS(rv, rv);
-    return NS_OK;
-}
-
 void
 AndroidBridge::GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort)
 {
 
     ALOG_BRIDGE("Enter: %s", __PRETTY_FUNCTION__);
     if (!mLayerClient) {
         ALOG_BRIDGE("Exceptional Exit: %s", __PRETTY_FUNCTION__);
         return;
--- a/widget/android/AndroidBridge.h
+++ b/widget/android/AndroidBridge.h
@@ -142,17 +142,16 @@ public:
     static AndroidBridge *Bridge() {
         return sBridge;
     }
 
     /* These are all implemented in Java */
     bool GetThreadNameJavaProfiling(uint32_t aThreadId, nsCString & aResult);
     bool GetFrameNameJavaProfiling(uint32_t aThreadId, uint32_t aSampleId, uint32_t aFrameId, nsCString & aResult);
 
-    nsresult CaptureZoomedView(mozIDOMWindowProxy *window, nsIntRect zoomedViewRect, jni::ByteBuffer::Param buffer, float zoomFactor);
     void GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort);
     void ContentDocumentChanged();
     bool IsContentDocumentDisplayed();
 
     bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const LayerRect& aDisplayPort, float aDisplayResolution, bool aDrawingCritical,
                                    mozilla::ParentLayerPoint& aScrollOffset, mozilla::CSSToParentLayerScale& aZoom);
 
     void SetLayerClient(java::GeckoLayerClient::Param jobj);
--- a/widget/android/AndroidJavaWrappers.cpp
+++ b/widget/android/AndroidJavaWrappers.cpp
@@ -34,17 +34,16 @@ jfieldID AndroidGeckoEvent::jRectField =
 
 jfieldID AndroidGeckoEvent::jCharactersField = 0;
 jfieldID AndroidGeckoEvent::jCharactersExtraField = 0;
 jfieldID AndroidGeckoEvent::jDataField = 0;
 jfieldID AndroidGeckoEvent::jMetaStateField = 0;
 jfieldID AndroidGeckoEvent::jFlagsField = 0;
 jfieldID AndroidGeckoEvent::jCountField = 0;
 jfieldID AndroidGeckoEvent::jPointerIndexField = 0;
-jfieldID AndroidGeckoEvent::jByteBufferField = 0;
 jfieldID AndroidGeckoEvent::jWidthField = 0;
 jfieldID AndroidGeckoEvent::jHeightField = 0;
 jfieldID AndroidGeckoEvent::jIDField = 0;
 jfieldID AndroidGeckoEvent::jGamepadButtonField = 0;
 jfieldID AndroidGeckoEvent::jGamepadButtonPressedField = 0;
 jfieldID AndroidGeckoEvent::jGamepadButtonValueField = 0;
 jfieldID AndroidGeckoEvent::jGamepadValuesField = 0;
 
@@ -102,17 +101,16 @@ AndroidGeckoEvent::InitGeckoEventClass(J
 
     jCharactersField = geckoEvent.getField("mCharacters", "Ljava/lang/String;");
     jCharactersExtraField = geckoEvent.getField("mCharactersExtra", "Ljava/lang/String;");
     jDataField = geckoEvent.getField("mData", "Ljava/lang/String;");
     jMetaStateField = geckoEvent.getField("mMetaState", "I");
     jFlagsField = geckoEvent.getField("mFlags", "I");
     jCountField = geckoEvent.getField("mCount", "I");
     jPointerIndexField = geckoEvent.getField("mPointerIndex", "I");
-    jByteBufferField = geckoEvent.getField("mBuffer", "Ljava/nio/ByteBuffer;");
     jWidthField = geckoEvent.getField("mWidth", "I");
     jHeightField = geckoEvent.getField("mHeight", "I");
     jIDField = geckoEvent.getField("mID", "I");
     jGamepadButtonField = geckoEvent.getField("mGamepadButton", "I");
     jGamepadButtonPressedField = geckoEvent.getField("mGamepadButtonPressed", "Z");
     jGamepadButtonValueField = geckoEvent.getField("mGamepadButtonValue", "F");
     jGamepadValuesField = geckoEvent.getField("mGamepadValues", "[F");
 }
@@ -305,24 +303,16 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jo
             break;
 
         case VIEWPORT: {
             ReadCharactersField(jenv);
             ReadCharactersExtraField(jenv);
             break;
         }
 
-        case ZOOMEDVIEW: {
-            mX = jenv->GetDoubleField(jobj, jXField);
-            mMetaState = jenv->GetIntField(jobj, jMetaStateField);
-            ReadPointArray(mPoints, jenv, jPoints, 2);
-            mByteBuffer = new RefCountedJavaObject(jenv, jenv->GetObjectField(jobj, jByteBufferField));
-            break;
-        }
-
         case CALL_OBSERVER: {
             ReadCharactersField(jenv);
             ReadCharactersExtraField(jenv);
             ReadDataField(jenv);
             break;
         }
 
         case REMOVE_OBSERVER: {
--- a/widget/android/AndroidJavaWrappers.h
+++ b/widget/android/AndroidJavaWrappers.h
@@ -468,17 +468,16 @@ public:
     Modifiers DOMModifiers() const;
     bool IsAltPressed() const { return (mMetaState & AMETA_ALT_MASK) != 0; }
     bool IsShiftPressed() const { return (mMetaState & AMETA_SHIFT_MASK) != 0; }
     bool IsCtrlPressed() const { return (mMetaState & AMETA_CTRL_MASK) != 0; }
     bool IsMetaPressed() const { return (mMetaState & AMETA_META_MASK) != 0; }
     int Flags() { return mFlags; }
     int Count() { return mCount; }
     int PointerIndex() { return mPointerIndex; }
-    RefCountedJavaObject* ByteBuffer() { return mByteBuffer; }
     int Width() { return mWidth; }
     int Height() { return mHeight; }
     int ID() { return mID; }
     int GamepadButton() { return mGamepadButton; }
     bool GamepadButtonPressed() { return mGamepadButtonPressed; }
     float GamepadButtonValue() { return mGamepadButtonValue; }
     const nsTArray<float>& GamepadValues() { return mGamepadValues; }
     int RequestId() { return mCount; } // for convenience
@@ -503,17 +502,16 @@ protected:
     nsTArray<float> mPressures;
     nsTArray<int> mToolTypes;
     nsIntRect mRect;
     int mFlags, mMetaState;
     int mCount;
     double mX, mY, mZ, mW;
     int mPointerIndex;
     nsString mCharacters, mCharactersExtra, mData;
-    RefPtr<RefCountedJavaObject> mByteBuffer;
     int mWidth, mHeight;
     int mID;
     int mGamepadButton;
     bool mGamepadButtonPressed;
     float mGamepadButtonValue;
     nsTArray<float> mGamepadValues;
     nsCOMPtr<nsIObserver> mObserver;
     MultiTouchInput mApzInput;
@@ -562,18 +560,16 @@ protected:
     static jfieldID jCharactersField;
     static jfieldID jCharactersExtraField;
     static jfieldID jDataField;
     static jfieldID jMetaStateField;
     static jfieldID jFlagsField;
     static jfieldID jCountField;
     static jfieldID jPointerIndexField;
 
-    static jfieldID jByteBufferField;
-
     static jfieldID jWidthField;
     static jfieldID jHeightField;
 
     static jfieldID jIDField;
     static jfieldID jGamepadButtonField;
     static jfieldID jGamepadButtonPressedField;
     static jfieldID jGamepadButtonValueField;
     static jfieldID jGamepadValuesField;
@@ -590,17 +586,16 @@ public:
         TELEMETRY_HISTOGRAM_ADD = 37,
         ADD_OBSERVER = 38,
         TELEMETRY_UI_SESSION_START = 42,
         TELEMETRY_UI_SESSION_STOP = 43,
         TELEMETRY_UI_EVENT = 44,
         GAMEPAD_ADDREMOVE = 45,
         GAMEPAD_DATA = 46,
         LONG_PRESS = 47,
-        ZOOMEDVIEW = 48,
         dummy_java_enum_list_end
     };
 
     enum {
         ACTION_GAMEPAD_ADDED = 1,
         ACTION_GAMEPAD_REMOVED = 2
     };
 
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -651,43 +651,16 @@ nsAppShell::PostEvent(AndroidGeckoEvent*
 void
 nsAppShell::LegacyGeckoEvent::Run()
 {
     const mozilla::UniquePtr<AndroidGeckoEvent>& curEvent = ae;
 
     EVLOG("nsAppShell: event %p %d", (void*)curEvent.get(), curEvent->Type());
 
     switch (curEvent->Type()) {
-    case AndroidGeckoEvent::ZOOMEDVIEW: {
-        if (!nsAppShell::Get()->mBrowserApp)
-            break;
-        int32_t tabId = curEvent->MetaState();
-        const nsTArray<nsIntPoint>& points = curEvent->Points();
-        float scaleFactor = (float) curEvent->X();
-        RefPtr<RefCountedJavaObject> javaBuffer = curEvent->ByteBuffer();
-        const auto& mBuffer = jni::ByteBuffer::Ref::From(javaBuffer->GetObject());
-
-        nsCOMPtr<mozIDOMWindowProxy> domWindow;
-        nsCOMPtr<nsIBrowserTab> tab;
-        nsAppShell::Get()->mBrowserApp->GetBrowserTab(tabId, getter_AddRefs(tab));
-        if (!tab) {
-            NS_ERROR("Can't find tab!");
-            break;
-        }
-        tab->GetWindow(getter_AddRefs(domWindow));
-        if (!domWindow) {
-            NS_ERROR("Can't find dom window!");
-            break;
-        }
-        NS_ASSERTION(points.Length() == 2, "ZoomedView event does not have enough coordinates");
-        nsIntRect r(points[0].x, points[0].y, points[1].x, points[1].y);
-        AndroidBridge::Bridge()->CaptureZoomedView(domWindow, r, mBuffer, scaleFactor);
-        break;
-    }
-
     case AndroidGeckoEvent::VIEWPORT: {
         if (curEvent->Characters().Length() == 0)
             break;
 
         nsCOMPtr<nsIObserverService> obsServ =
             mozilla::services::GetObserverService();
 
         const NS_ConvertUTF16toUTF8 topic(curEvent->Characters());