Bug 631388. Part 1: Add nsIPluginInstance::GetImageSize. r=cjones,a=blocking
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 23 Feb 2011 18:38:09 +1300
changeset 62981 8b22f4933c311d788f1bd2f0d3f266d3b71e899e
parent 62980 d39a263d7f14335da94f8dedfebc5a0b937fdcee
child 62982 9ad79fc34fee1825e7ef6c11b29498030dd72b1f
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewerscjones, blocking
bugs631388
milestone2.0b13pre
Bug 631388. Part 1: Add nsIPluginInstance::GetImageSize. r=cjones,a=blocking
dom/plugins/PluginInstanceParent.cpp
dom/plugins/PluginInstanceParent.h
dom/plugins/PluginLibrary.h
dom/plugins/PluginModuleParent.cpp
dom/plugins/PluginModuleParent.h
modules/plugin/base/public/nsIPluginInstance.idl
modules/plugin/base/src/PluginPRLibrary.cpp
modules/plugin/base/src/PluginPRLibrary.h
modules/plugin/base/src/nsNPAPIPluginInstance.cpp
--- a/dom/plugins/PluginInstanceParent.cpp
+++ b/dom/plugins/PluginInstanceParent.cpp
@@ -637,16 +637,35 @@ PluginInstanceParent::GetImage(ImageCont
     cairoData.mSurface = mFrontSurface;
     cairoData.mSize = mFrontSurface->GetSize();
     pluginImage->SetData(cairoData);
 
     *aImage = image.forget().get();
     return NS_OK;
 }
 
+nsresult
+PluginInstanceParent::GetImageSize(nsIntSize* aSize)
+{
+    if (mFrontSurface) {
+        gfxIntSize size = mFrontSurface->GetSize();
+        *aSize = nsIntSize(size.width, size.height);
+        return NS_OK;
+    }
+
+#ifdef XP_MACOSX
+    if (mIOSurface) {
+        *aSize = nsIntSize(mIOSurface->GetWidth(), mIOSurface->GetHeight());
+        return NS_OK;
+    }
+#endif
+
+    return NS_ERROR_NOT_AVAILABLE;
+}
+
 #ifdef XP_MACOSX
 nsresult
 PluginInstanceParent::IsRemoteDrawingCoreAnimation(PRBool *aDrawing)
 {
     *aDrawing = (NPDrawingModelCoreAnimation == (NPDrawingModel)mDrawingModel ||
                  NPDrawingModelInvalidatingCoreAnimation == (NPDrawingModel)mDrawingModel);
     return NS_OK;
 }
--- a/dom/plugins/PluginInstanceParent.h
+++ b/dom/plugins/PluginInstanceParent.h
@@ -274,16 +274,17 @@ public:
 
 #if defined(OS_MACOSX)
     void Invalidate();
 #endif // definied(OS_MACOSX)
 
     nsresult AsyncSetWindow(NPWindow* window);
     nsresult GetSurface(gfxASurface** aSurface);
     nsresult GetImage(mozilla::layers::ImageContainer* aContainer, mozilla::layers::Image** aImage);
+    nsresult GetImageSize(nsIntSize* aSize);
 #ifdef XP_MACOSX
     nsresult IsRemoteDrawingCoreAnimation(PRBool *aDrawing);
 #endif
     nsresult SetBackgroundUnknown();
     nsresult BeginUpdateBackground(const nsIntRect& aRect,
                                    gfxContext** aCtx);
     nsresult EndUpdateBackground(gfxContext* aCtx,
                                  const nsIntRect& aRect);
--- a/dom/plugins/PluginLibrary.h
+++ b/dom/plugins/PluginLibrary.h
@@ -45,16 +45,17 @@
 #include "nscore.h"
 #include "nsTArray.h"
 #include "nsPluginError.h"
 
 class gfxASurface;
 class gfxContext;
 class nsCString;
 struct nsIntRect;
+struct nsIntSize;
 class nsNPAPIPlugin;
 
 namespace mozilla {
 namespace layers {
 class Image;
 class ImageContainer;
 }
 }
@@ -95,16 +96,17 @@ public:
 
   virtual nsresult NPP_ClearSiteData(const char* site, uint64_t flags,
                                      uint64_t maxAge) = 0;
   virtual nsresult NPP_GetSitesWithData(InfallibleTArray<nsCString>& aResult) = 0;
 
   virtual nsresult AsyncSetWindow(NPP instance, NPWindow* window) = 0;
   virtual nsresult GetSurface(NPP instance, gfxASurface** aSurface) = 0;
   virtual nsresult GetImage(NPP instance, ImageContainer* aContainer, Image** aImage) = 0;
+  virtual nsresult GetImageSize(NPP instance, nsIntSize* aSize) = 0;
   virtual bool UseAsyncPainting() = 0;
 #if defined(XP_MACOSX)
   virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing) = 0;
 #endif
   /**
    * The next three methods are the third leg in the trip to
    * PluginInstanceParent.  They approximately follow the ReadbackSink
    * API.
--- a/dom/plugins/PluginModuleParent.cpp
+++ b/dom/plugins/PluginModuleParent.cpp
@@ -687,16 +687,24 @@ PluginModuleParent::GetImage(NPP instanc
                              mozilla::layers::ImageContainer* aContainer,
                              mozilla::layers::Image** aImage)
 {
     PluginInstanceParent* i = InstCast(instance);
     return !i ? NS_ERROR_FAILURE : i->GetImage(aContainer, aImage);
 }
 
 nsresult
+PluginModuleParent::GetImageSize(NPP instance,
+                                 nsIntSize* aSize)
+{
+    PluginInstanceParent* i = InstCast(instance);
+    return !i ? NS_ERROR_FAILURE : i->GetImageSize(aSize);
+}
+
+nsresult
 PluginModuleParent::SetBackgroundUnknown(NPP instance)
 {
     PluginInstanceParent* i = InstCast(instance);
     if (!i)
         return NS_ERROR_FAILURE;
 
     return i->SetBackgroundUnknown();
 }
--- a/dom/plugins/PluginModuleParent.h
+++ b/dom/plugins/PluginModuleParent.h
@@ -227,16 +227,17 @@ private:
                                 void *value);
     static void NPP_URLRedirectNotify(NPP instance, const char* url,
                                       int32_t status, void* notifyData);
 
     virtual bool HasRequiredFunctions();
     virtual nsresult AsyncSetWindow(NPP instance, NPWindow* window);
     virtual nsresult GetSurface(NPP instance, gfxASurface** aSurface);
     virtual nsresult GetImage(NPP instance, mozilla::layers::ImageContainer* aContainer, mozilla::layers::Image** aImage);
+    virtual nsresult GetImageSize(NPP instance, nsIntSize* aSize);
     NS_OVERRIDE virtual bool UseAsyncPainting() { return true; }
     NS_OVERRIDE
     virtual nsresult SetBackgroundUnknown(NPP instance);
     NS_OVERRIDE
     virtual nsresult BeginUpdateBackground(NPP instance,
                                            const nsIntRect& aRect,
                                            gfxContext** aCtx);
     NS_OVERRIDE
--- a/modules/plugin/base/public/nsIPluginInstance.idl
+++ b/modules/plugin/base/public/nsIPluginInstance.idl
@@ -46,16 +46,17 @@ interface nsIOutputStream;
 #include "nsStringGlue.h"
 #include "gfxASurface.h"
 #include "ImageLayers.h"
 struct JSContext;
 struct JSObject;
 class gfxASurface;
 class gfxContext;
 struct nsIntRect;
+struct nsIntSize;
 
 namespace mozilla {
 namespace layers {
 class Image;
 class ImageContainer;
 }
 }
 
@@ -64,16 +65,17 @@ class ImageContainer;
 
 [ptr] native JSContextPtr(JSContext);
 [ptr] native JSObjectPtr(JSObject);
 [ptr] native gfxASurfacePtr(gfxASurface);
 [ptr] native gfxContextPtr(gfxContext);
 [ptr] native ImagePtr(mozilla::layers::Image);
 [ptr] native ImageContainerPtr(mozilla::layers::ImageContainer);
 [ptr] native nsIntRectPtr(nsIntRect);
+[ptr] native nsIntSizePtr(nsIntSize);
 
 [uuid(84994340-E120-4051-824F-D4EE8AEF1A3E)]
 interface nsIPluginInstance : nsISupports
 {
     /**
      * Initializes a newly created plugin instance.
      * 
      * @param aOwner - the plugin instance owner
@@ -248,32 +250,46 @@ interface nsIPluginInstance : nsISupport
 
     /**
      * Call this each time after the plugin has been painted to the screen
      */
     void notifyPainted();
 
     /**
      * This should return a valid gfxASurface pointer, or null if there is nothing to render yet.
+     * NO LONGER USED. Do not call.
      */
     void getSurface(out gfxASurfacePtr aSurface);
 
     /**
      * @return true if plugin module supports async rendering
      */
     PRBool useAsyncPainting();
 };
 
 
 // XXX kill me after branching
-[noscript, uuid(324f3c02-4fbd-430b-8afa-db083d3867fc)]
+[noscript, uuid(24235105-ac5f-483b-86ec-7c9446ddcb8a)]
 interface nsIPluginInstance_MOZILLA_2_0_BRANCH : nsIPluginInstance
 {
     PRBool isRemoteDrawingCoreAnimation();
+    /**
+     * Returns a new Image object which draws an asynchronously-rendered
+     * plugin. The Image is created using aContainer.
+     * Fails if the plugin is using async rendering but no image has yet
+     * been received, or if the plugin is not using async rendering.
+     */
     void getImage(in ImageContainerPtr aContainer, out ImagePtr aImage);
     /**
+     * Returns the size of the Image object that would be created if we called
+     * getImage.
+     * Fails if the plugin is using async rendering but no image has yet
+     * been received, or if the plugin is not using async rendering.
+     */
+    void getImageSize(in nsIntSizePtr aSize);
+    /**
      * This is the second leg in the trip to PluginInstanceParent.  It
      * approximately follows the ReadbackSink API.
      */
     void setBackgroundUnknown();
     void beginUpdateBackground(in nsIntRectPtr rect, out gfxContextPtr ctx);
     void endUpdateBackground(in gfxContextPtr ctx, in nsIntRectPtr rect);
 };
--- a/modules/plugin/base/src/PluginPRLibrary.cpp
+++ b/modules/plugin/base/src/PluginPRLibrary.cpp
@@ -244,29 +244,29 @@ PluginPRLibrary::AsyncSetWindow(NPP inst
   nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
   NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult
 PluginPRLibrary::GetSurface(NPP instance, gfxASurface** aSurface)
 {
-  nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
-  NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
-  *aSurface = nsnull;
-  return NS_OK;
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult
 PluginPRLibrary::GetImage(NPP instance, ImageContainer* aContainer, Image** aImage)
 {
-  nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
-  NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
-  *aImage = nsnull;
-  return NS_OK;
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+nsresult
+PluginPRLibrary::GetImageSize(NPP instance, nsIntSize* aSize)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 #if defined(XP_MACOSX)
 nsresult
 PluginPRLibrary::IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing)
 {
   nsNPAPIPluginInstance* inst = (nsNPAPIPluginInstance*)instance->ndata;
   NS_ENSURE_TRUE(inst, NS_ERROR_NULL_POINTER);
--- a/modules/plugin/base/src/PluginPRLibrary.h
+++ b/modules/plugin/base/src/PluginPRLibrary.h
@@ -137,16 +137,17 @@ public:
 
     virtual nsresult NPP_ClearSiteData(const char* site, uint64_t flags,
                                        uint64_t maxAge);
     virtual nsresult NPP_GetSitesWithData(InfallibleTArray<nsCString>& result);
 
     virtual nsresult AsyncSetWindow(NPP instance, NPWindow* window);
     virtual nsresult GetSurface(NPP instance, gfxASurface** aSurface);
     virtual nsresult GetImage(NPP instance, ImageContainer* aContainer, Image** aImage);
+    virtual nsresult GetImageSize(NPP instance, nsIntSize* aSize);
     NS_OVERRIDE virtual bool UseAsyncPainting() { return false; }
 #if defined(XP_MACOSX)
     virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, PRBool *aDrawing);
 #endif
     NS_OVERRIDE
     virtual nsresult SetBackgroundUnknown(NPP instance);
     NS_OVERRIDE
     virtual nsresult BeginUpdateBackground(NPP instance,
--- a/modules/plugin/base/src/nsNPAPIPluginInstance.cpp
+++ b/modules/plugin/base/src/nsNPAPIPluginInstance.cpp
@@ -868,24 +868,38 @@ nsNPAPIPluginInstance::GetSurface(gfxASu
     return NS_ERROR_FAILURE;
 
   return library->GetSurface(&mNPP, aSurface);
 }
 
 NS_IMETHODIMP
 nsNPAPIPluginInstance::GetImage(ImageContainer* aContainer, Image** aImage)
 {
+  *aImage = nsnull;
+
   if (RUNNING != mRunning)
     return NS_OK;
 
   AutoPluginLibraryCall library(this);
   return !library ? NS_ERROR_FAILURE : library->GetImage(&mNPP, aContainer, aImage);
 }
 
 NS_IMETHODIMP
+nsNPAPIPluginInstance::GetImageSize(nsIntSize* aSize)
+{
+  *aSize = nsIntSize(0, 0);
+
+  if (RUNNING != mRunning)
+    return NS_OK;
+
+  AutoPluginLibraryCall library(this);
+  return !library ? NS_ERROR_FAILURE : library->GetImageSize(&mNPP, aSize);
+}
+
+NS_IMETHODIMP
 nsNPAPIPluginInstance::NotifyPainted(void)
 {
   NS_NOTREACHED("Dead code, shouldn't be called.");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsNPAPIPluginInstance::UseAsyncPainting(PRBool* aIsAsync)