Bug 1252877 Part 3: Remove plugin capture code from child. r=jimm
authorBob Owen <bobowencode@gmail.com>
Mon, 18 Jul 2016 09:54:02 +0100
changeset 330449 499de859b4b9923dc421d7a168c5e5846100431b
parent 330448 4010b27b7c25d9e2c844240464b4998f66d0e4af
child 330450 b1c3f87e64f3c447464b87329e81e87a75ab89ae
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1252877
milestone50.0a1
Bug 1252877 Part 3: Remove plugin capture code from child. r=jimm
dom/plugins/ipc/PluginInstanceParent.cpp
dom/plugins/ipc/PluginInstanceParent.h
--- a/dom/plugins/ipc/PluginInstanceParent.cpp
+++ b/dom/plugins/ipc/PluginInstanceParent.cpp
@@ -56,36 +56,28 @@
 #include <windowsx.h>
 #include "gfxWindowsPlatform.h"
 #include "mozilla/plugins/PluginSurfaceParent.h"
 #include "nsClassHashtable.h"
 #include "nsHashKeys.h"
 #include "nsIWidget.h"
 #include "nsPluginNativeWindow.h"
 #include "PluginQuirks.h"
-#include "nsWindowsHelpers.h"
 extern const wchar_t* kFlashFullscreenClass;
 #elif defined(MOZ_WIDGET_GTK)
 #include "mozilla/dom/ContentChild.h"
 #include <gdk/gdk.h>
 #elif defined(XP_MACOSX)
 #include <ApplicationServices/ApplicationServices.h>
 #endif // defined(XP_MACOSX)
 
 using namespace mozilla::plugins;
 using namespace mozilla::layers;
 using namespace mozilla::gl;
 
-#if defined(XP_WIN)
-// Delays associated with attempting an e10s window capture for scrolling.
-const int kScrollCaptureDelayMs = 100;
-const int kInitScrollCaptureDelayMs = 1000;
-const uint32_t kScrollCaptureFillColor = 0xFFa0a0a0; // gray
-#endif
-
 void
 StreamNotifyParent::ActorDestroy(ActorDestroyReason aWhy)
 {
   // Implement me! Bug 1005162
 }
 
 bool
 StreamNotifyParent::RecvRedirectNotifyResponse(const bool& allow)
@@ -138,20 +130,16 @@ PluginInstanceParent::PluginInstancePare
     , mPluginWndProc(nullptr)
     , mNestedEventState(false)
 #endif // defined(XP_WIN)
 #if defined(XP_MACOSX)
     , mShWidth(0)
     , mShHeight(0)
     , mShColorSpace(nullptr)
 #endif
-#if defined(XP_WIN)
-    , mValidFirstCapture(false)
-    , mIsScrolling(false)
-#endif
 {
 #if defined(OS_WIN)
     if (!sPluginInstanceList) {
         sPluginInstanceList = new nsClassHashtable<nsVoidPtrHashKey, PluginInstanceParent>();
     }
 #endif
 }
 
@@ -166,19 +154,16 @@ PluginInstanceParent::~PluginInstancePar
 #endif
 #if defined(MOZ_WIDGET_COCOA)
     if (mShWidth != 0 && mShHeight != 0) {
         DeallocShmem(mShSurface);
     }
     if (mShColorSpace)
         ::CGColorSpaceRelease(mShColorSpace);
 #endif
-#if defined(XP_WIN)
-    CancelScheduledScrollCapture();
-#endif
 }
 
 bool
 PluginInstanceParent::InitMetadata(const nsACString& aMimeType,
                                    const nsACString& aSrcAttribute)
 {
     if (aSrcAttribute.IsEmpty()) {
         return false;
@@ -443,22 +428,16 @@ bool
 PluginInstanceParent::AnswerNPN_SetValue_NPPVpluginWindow(
     const bool& windowed, NPError* result)
 {
     // Yes, we are passing a boolean as a void*.  We have to cast to intptr_t
     // first to avoid gcc warnings about casting to a pointer from a
     // non-pointer-sized integer.
     *result = mNPNIface->setvalue(mNPP, NPPVpluginWindowBool,
                                   (void*)(intptr_t)windowed);
-
-#if defined(XP_WIN)
-    if (windowed) {
-        ScheduleScrollCapture(kScrollCaptureDelayMs);
-    }
-#endif
     return true;
 }
 
 bool
 PluginInstanceParent::AnswerNPN_SetValue_NPPVpluginTransparent(
     const bool& transparent, NPError* result)
 {
     *result = mNPNIface->setvalue(mNPP, NPPVpluginTransparentBool,
@@ -1202,181 +1181,16 @@ PluginInstanceParent::EndUpdateBackgroun
 #endif
 
     Unused << SendUpdateBackground(BackgroundDescriptor(), aRect);
 
     return NS_OK;
 }
 
 #if defined(XP_WIN)
-//#define CAPTURE_LOG(...) printf_stderr("CAPTURE [%X]: ", this);printf_stderr(__VA_ARGS__);printf_stderr("\n");
-#define CAPTURE_LOG(...)
-
-void
-PluginInstanceParent::ScheduleScrollCapture(int aTimeout)
-{
-    if (mCaptureRefreshTask) {
-        return;
-    }
-    CAPTURE_LOG("delayed scroll capture requested.");
-    mCaptureRefreshTask =
-        NewNonOwningCancelableRunnableMethod(this, &PluginInstanceParent::ScheduledUpdateScrollCaptureCallback);
-    RefPtr<Runnable> addrefedTask = mCaptureRefreshTask;
-    MessageLoop::current()->PostDelayedTask(addrefedTask.forget(),
-                                            kScrollCaptureDelayMs);
-}
-
-void
-PluginInstanceParent::ScheduledUpdateScrollCaptureCallback()
-{
-    CAPTURE_LOG("taking delayed scrollcapture.");
-    mCaptureRefreshTask = nullptr;
-    bool retrigger = false;
-    UpdateScrollCapture(retrigger);
-    if (retrigger) {
-        // reset the async request
-        ScheduleScrollCapture(kScrollCaptureDelayMs);
-    }
-}
-
-void
-PluginInstanceParent::CancelScheduledScrollCapture()
-{
-    CAPTURE_LOG("delayed scroll capture cancelled.");
-    if (mCaptureRefreshTask) {
-        mCaptureRefreshTask->Cancel();
-        mCaptureRefreshTask = nullptr;
-    }
-}
-
-bool
-PluginInstanceParent::UpdateScrollCapture(bool& aRequestNewCapture)
-{
-    aRequestNewCapture = false;
-    if (!::IsWindow(mChildPluginHWND)) {
-        CAPTURE_LOG("invalid window");
-        aRequestNewCapture = true;
-        return false;
-    }
-
-    nsAutoHDC windowDC(::GetDC(mChildPluginHWND));
-    if (!windowDC) {
-        CAPTURE_LOG("no windowdc");
-        aRequestNewCapture = true;
-        return false;
-    }
-
-    RECT bounds = {0};
-    ::GetWindowRect(mChildPluginHWND, &bounds);
-    if ((bounds.left == bounds.right && bounds.top == bounds.bottom) ||
-        mWindowSize.IsEmpty()) {
-        CAPTURE_LOG("empty bounds");
-        // Lots of null window plugins in content, don't capture.
-        return false;
-    }
-
-    // If we need to init mScrollCapture do so, also reset it if the size of the
-    // plugin window changes.
-    if (!mScrollCapture || mScrollCapture->GetSize() != mWindowSize) {
-        mValidFirstCapture = false;
-        mScrollCapture =
-            gfxPlatform::GetPlatform()->CreateOffscreenSurface(mWindowSize,
-                                                               SurfaceFormat::X8R8G8B8_UINT32);
-    }
-
-    // Check clipping, we don't want to capture windows that are clipped by
-    // the viewport.
-    RECT clip = {0};
-    int rgnType = ::GetWindowRgnBox(mPluginHWND, &clip);
-    bool clipCorrect = !clip.left && !clip.top &&
-                       clip.right == mWindowSize.width &&
-                       clip.bottom == mWindowSize.height;
-
-    bool isVisible = ::IsWindowVisible(mChildPluginHWND);
-
-    CAPTURE_LOG("validcap=%d visible=%d region=%d clip=%d:%dx%dx%dx%d",
-                mValidFirstCapture, isVisible, rgnType, clipCorrect,
-                clip.left, clip.top, clip.right, clip.bottom);
-
-    // We have a good capture and can't update so keep using the existing
-    // capture image. Otherwise fall through so we paint the fill color to
-    // the layer.
-    if (mValidFirstCapture && (!isVisible || !clipCorrect)) {
-        return true;
-    }
-
-    // On Windows we'll need a native bitmap for BitBlt.
-    RefPtr<gfxWindowsSurface> nativeScrollCapture;
-
-    // Copy the plugin window if it's visible and there's no clipping, otherwise
-    // use a default fill color.
-    if (isVisible && clipCorrect) {
-        CAPTURE_LOG("capturing window");
-        nativeScrollCapture =
-            new gfxWindowsSurface(mWindowSize, SurfaceFormat::X8R8G8B8_UINT32);
-        if (!::BitBlt(nativeScrollCapture->GetDC(), 0, 0, mWindowSize.width,
-                      mWindowSize.height, windowDC, 0, 0, SRCCOPY)) {
-            CAPTURE_LOG("blt failure??");
-            return false;
-        }
-        ::GdiFlush();
-        mValidFirstCapture = true;
-    }
-
-    IntSize targetSize = mScrollCapture->GetSize();
-
-    if (targetSize.IsEmpty()) {
-        return false;
-    }
-
-    RefPtr<gfx::DrawTarget> dt =
-        gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(mScrollCapture,
-                                                               targetSize);
-
-    if (nativeScrollCapture) {
-        // Copy the native capture image over to a remotable gfx surface.
-        RefPtr<gfx::SourceSurface> sourceSurface =
-            gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr,
-                                                                   nativeScrollCapture);
-        dt->CopySurface(sourceSurface,
-                        IntRect(0, 0, targetSize.width, targetSize.height),
-                        IntPoint());
-    } else {
-        CAPTURE_LOG("using fill color");
-        dt->FillRect(gfx::Rect(0, 0, targetSize.width, targetSize.height),
-                     gfx::ColorPattern(gfx::Color::FromABGR(kScrollCaptureFillColor)),
-                     gfx::DrawOptions(1.f, CompositionOp::OP_SOURCE));
-        aRequestNewCapture = true;
-    }
-    dt->Flush();
-
-    // Get a source for mScrollCapture and load it into the image container.
-    RefPtr<gfx::SourceSurface> cachedSource =
-        gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt,
-                                                               mScrollCapture);
-    RefPtr<SourceSurfaceImage> image =
-        new SourceSurfaceImage(cachedSource->GetSize(), cachedSource);
-
-    ImageContainer::NonOwningImage holder(image);
-    holder.mFrameID = ++mFrameID;
-
-    AutoTArray<ImageContainer::NonOwningImage,1> imageList;
-    imageList.AppendElement(holder);
-
-    // inits mImageContainer
-    ImageContainer *container = GetImageContainer();
-    container->SetCurrentImages(imageList);
-
-    // Invalidate our area in the page so the image gets flushed.
-    NPRect nprect = {0, 0, targetSize.width, targetSize.height};
-    RecvNPN_InvalidateRect(nprect);
-
-    return true;
-}
-
 nsresult
 PluginInstanceParent::SetScrollCaptureId(uint64_t aScrollCaptureId)
 {
   if (aScrollCaptureId == ImageContainer::sInvalidAsyncContainerId) {
     return NS_ERROR_FAILURE;
   }
 
   mImageContainer = new ImageContainer(aScrollCaptureId);
@@ -1394,27 +1208,16 @@ PluginInstanceParent::GetScrollCaptureCo
   container.forget(aContainer);
 
   return NS_OK;
 }
 
 nsresult
 PluginInstanceParent::UpdateScrollState(bool aIsScrolling)
 {
-  bool scrollStateChanged = (mIsScrolling != aIsScrolling);
-  mIsScrolling = aIsScrolling;
-  if (scrollStateChanged && !aIsScrolling) {
-      // At the end of a dom scroll operation capturing now will attempt to
-      // capture a window that is still hidden due to the current scroll
-      // operation. (The browser process will update visibility after layer
-      // updates get pushed over.) So we delay our attempt for a bit. This
-      // shouldn't hurt our chances of capturing with APZ scroll since the
-      // delay is short.
-      ScheduleScrollCapture(kScrollCaptureDelayMs);
-  }
   return NS_OK;
 }
 #endif // XP_WIN
 
 PluginAsyncSurrogate*
 PluginInstanceParent::GetAsyncSurrogate()
 {
     return mSurrogate;
@@ -1561,19 +1364,16 @@ PluginInstanceParent::NPP_SetWindow(cons
     window.x = aWindow->x;
     window.y = aWindow->y;
     window.width = aWindow->width;
     window.height = aWindow->height;
     window.clipRect = aWindow->clipRect; // MacOS specific
     window.type = aWindow->type;
 #endif
 
-    mWindowSize.width = window.width;
-    mWindowSize.height = window.height;
-
 #if defined(XP_MACOSX)
     double floatScaleFactor = 1.0;
     mNPNIface->getvalue(mNPP, NPNVcontentsScaleFactor, &floatScaleFactor);
     int scaleFactor = ceil(floatScaleFactor);
     window.contentsScaleFactor = floatScaleFactor;
 
     if (mShWidth != window.width * scaleFactor || mShHeight != window.height * scaleFactor) {
         if (mDrawingModel == NPDrawingModelCoreAnimation ||
@@ -1608,22 +1408,16 @@ PluginInstanceParent::NPP_SetWindow(cons
     window.colormap = ws_info->colormap;
 #endif
 
     if (!CallNPP_SetWindow(window)) {
         return NPERR_GENERIC_ERROR;
     }
 
     RecordDrawingModel();
-
-#if defined(XP_WIN)
-    if (!mCaptureRefreshTask) {
-        ScheduleScrollCapture(kScrollCaptureDelayMs);
-    }
-#endif
     return NPERR_NO_ERROR;
 }
 
 NPError
 PluginInstanceParent::NPP_GetValue(NPPVariable aVariable,
                                    void* _retval)
 {
     switch (aVariable) {
--- a/dom/plugins/ipc/PluginInstanceParent.h
+++ b/dom/plugins/ipc/PluginInstanceParent.h
@@ -396,17 +396,16 @@ private:
     PluginModuleParent* mParent;
     RefPtr<PluginAsyncSurrogate> mSurrogate;
     bool mUseSurrogate;
     NPP mNPP;
     const NPNetscapeFuncs* mNPNIface;
     nsCString mSrcAttribute;
     NPWindowType mWindowType;
     int16_t mDrawingModel;
-    IntSize mWindowSize;
 
     // Since plugins may request different drawing models to find a compatible
     // one, we only record the drawing model after a SetWindow call and if the
     // drawing model has changed.
     int mLastRecordedDrawingModel;
 
     nsDataHashtable<nsPtrHashKey<NPObject>, PluginScriptableObjectParent*> mScriptableObjects;
 
@@ -461,27 +460,15 @@ private:
     // the browser, but a "read-only" reference is sent to the plugin.
     //
     // We have explicitly chosen not to provide any guarantees about
     // the consistency of the pixels in |mBackground|.  A plugin may
     // be able to observe partial updates to the background.
     RefPtr<gfxASurface>    mBackground;
 
     RefPtr<ImageContainer> mImageContainer;
-
-#if defined(XP_WIN)
-    void ScheduleScrollCapture(int aTimeout);
-    void ScheduledUpdateScrollCaptureCallback();
-    bool UpdateScrollCapture(bool& aRequestNewCapture);
-    void CancelScheduledScrollCapture();
-
-    RefPtr<gfxASurface> mScrollCapture;
-    RefPtr<CancelableRunnable> mCaptureRefreshTask;
-    bool mValidFirstCapture;
-    bool mIsScrolling;
-#endif
 };
 
 
 } // namespace plugins
 } // namespace mozilla
 
 #endif // ifndef dom_plugins_PluginInstanceParent_h