Bug 606279, part 2: Use more concise types in PDocumentRenderer. r=joe
authorChris Jones <jones.chris.g@gmail.com>
Tue, 26 Oct 2010 17:20:53 -0500
changeset 56521 9f99e62fefb62c840fc3bc883498fefbada45aa4
parent 56520 8eb26a77a90eb518492d72d04fa8f116ea208cb7
child 56522 302c05f763445c922e241694329935012d6bc901
push id16595
push usercjones@mozilla.com
push dateTue, 26 Oct 2010 22:21:11 +0000
treeherdermozilla-central@3a1b694e8824 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs606279
milestone2.0b8pre
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 606279, part 2: Use more concise types in PDocumentRenderer. r=joe
content/canvas/public/DocumentRendererChild.h
content/canvas/public/DocumentRendererParent.h
content/canvas/src/DocumentRendererChild.cpp
content/canvas/src/DocumentRendererParent.cpp
content/canvas/src/nsCanvasRenderingContext2D.cpp
dom/ipc/PBrowser.ipdl
dom/ipc/PDocumentRenderer.ipdl
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
ipc/glue/IPCMessageUtils.h
--- a/content/canvas/public/DocumentRendererChild.h
+++ b/content/canvas/public/DocumentRendererChild.h
@@ -48,19 +48,20 @@ namespace mozilla {
 namespace ipc {
 
 class DocumentRendererChild : public PDocumentRendererChild
 {
 public:
     DocumentRendererChild();
     virtual ~DocumentRendererChild();
     
-    bool RenderDocument(nsIDOMWindow *window, const PRInt32& x, const PRInt32& y, const PRInt32& w, const PRInt32& h,
-			    const nsString& bgcolor, const PRUint32& flags, const PRBool& flush, 
-			    PRUint32& _width, PRUint32& _height, nsCString& data);
+    bool RenderDocument(nsIDOMWindow *window,
+                        const nsRect& documentRect, const nsString& bgcolor,
+                        PRUint32 renderFlags, PRBool flushLayout, 
+                        nsIntSize* renderedSize, nsCString& data);
 
 private:
 
     DISALLOW_EVIL_CONSTRUCTORS(DocumentRendererChild);
 };
 
 }
 }
--- a/content/canvas/public/DocumentRendererParent.h
+++ b/content/canvas/public/DocumentRendererParent.h
@@ -49,20 +49,20 @@ namespace ipc {
 class DocumentRendererParent : public PDocumentRendererParent
 {
 public:
     DocumentRendererParent();
     virtual ~DocumentRendererParent();
 
     void SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas,
 			  gfxContext* ctx);
-    void DrawToCanvas(PRUint32 aWidth, PRUint32 aHeight,
+    void DrawToCanvas(const nsIntSize& renderedSize,
 		      const nsCString& aData);
 
-    virtual bool Recv__delete__(const PRUint32& w, const PRUint32& h,
+    virtual bool Recv__delete__(const nsIntSize& renderedSize,
                                 const nsCString& data);
 
 private:
     nsCOMPtr<nsICanvasRenderingContextInternal> mCanvas;
     nsRefPtr<gfxContext> mCanvasContext;
 
     DISALLOW_EVIL_CONSTRUCTORS(DocumentRendererParent);
 };
--- a/content/canvas/src/DocumentRendererChild.cpp
+++ b/content/canvas/src/DocumentRendererChild.cpp
@@ -94,51 +94,55 @@ FlushLayoutForTree(nsIDOMWindow* aWindow
             if (win) {
                 FlushLayoutForTree(win);
             }
         }
     }
 }
 
 bool
-DocumentRendererChild::RenderDocument(nsIDOMWindow *window, const PRInt32& x, const PRInt32& y, const PRInt32& w, const PRInt32& h,
-                                      const nsString& aBGColor, const PRUint32& flags, const PRBool& flush, 
-                                      PRUint32& _width, PRUint32& _height, nsCString& data)
+DocumentRendererChild::RenderDocument(nsIDOMWindow *window,
+                                      const nsRect& documentRect,
+                                      const nsString& bgcolor,
+                                      PRUint32 renderFlags,
+                                      PRBool flushLayout, 
+                                      nsIntSize* renderedSize, nsCString& data)
 {
-    if (flush)
+    if (flushLayout)
         FlushLayoutForTree(window);
 
     nsCOMPtr<nsPresContext> presContext;
     nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window);
     if (win) {
         nsIDocShell* docshell = win->GetDocShell();
         if (docshell) {
             docshell->GetPresContext(getter_AddRefs(presContext));
         }
     }
     if (!presContext)
         return false;
 
     nscolor bgColor;
     nsCSSParser parser;
-    nsresult rv = parser.ParseColorString(PromiseFlatString(aBGColor),
+    nsresult rv = parser.ParseColorString(PromiseFlatString(bgcolor),
                                           nsnull, 0, &bgColor);
     if (NS_FAILED(rv))
         return false;
 
     nsIPresShell* presShell = presContext->PresShell();
 
-    nsRect r(x, y, w, h);
-
-    _width = nsPresContext::AppUnitsToIntCSSPixels(w);
-    _height = nsPresContext::AppUnitsToIntCSSPixels(h);
+    PRInt32 w = nsPresContext::AppUnitsToIntCSSPixels(documentRect.width);
+    PRInt32 h = nsPresContext::AppUnitsToIntCSSPixels(documentRect.height);
 
     // Draw directly into the output array.
-    data.SetLength(_width * _height * 4);
-    nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(reinterpret_cast<PRUint8*>(const_cast<char*>(data.get())),
-                                                         gfxIntSize(_width, _height),
-                                                         4 * _width, gfxASurface::ImageFormatARGB32);
+    data.SetLength(w * h * 4);
+    nsRefPtr<gfxImageSurface> surf =
+        new gfxImageSurface(reinterpret_cast<uint8*>(data.BeginWriting()),
+                            gfxIntSize(w, h),
+                            4 * w,
+                            gfxASurface::ImageFormatARGB32);
     nsRefPtr<gfxContext> ctx = new gfxContext(surf);
 
-    presShell->RenderDocument(r, flags, bgColor, ctx);
+    presShell->RenderDocument(documentRect, renderFlags, bgColor, ctx);
+    *renderedSize = nsIntSize(w, h);
 
     return true;
 }
--- a/content/canvas/src/DocumentRendererParent.cpp
+++ b/content/canvas/src/DocumentRendererParent.cpp
@@ -48,38 +48,41 @@ DocumentRendererParent::~DocumentRendere
 
 void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas,
                                               gfxContext* ctx)
 {
     mCanvas = aCanvas;
     mCanvasContext = ctx;
 }
 
-void DocumentRendererParent::DrawToCanvas(PRUint32 aWidth, PRUint32 aHeight,
+void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize,
                                           const nsCString& aData)
 {
     if (!mCanvas || !mCanvasContext)
         return;
 
-    nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(reinterpret_cast<PRUint8*>(const_cast<char*>(aData.Data())),
-                                                         gfxIntSize(aWidth, aHeight),
-                                                         aWidth * 4,
-                                                         gfxASurface::ImageFormatARGB32);
+    nsRefPtr<gfxImageSurface> surf =
+        new gfxImageSurface(reinterpret_cast<uint8*>(const_cast<nsCString&>(aData).BeginWriting()),
+                            gfxIntSize(aSize.width, aSize.height),
+                            aSize.width * 4,
+                            gfxASurface::ImageFormatARGB32);
     nsRefPtr<gfxPattern> pat = new gfxPattern(surf);
 
+    gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height));
     mCanvasContext->NewPath();
-    mCanvasContext->PixelSnappedRectangleAndSetPattern(gfxRect(0, 0, aWidth, aHeight), pat);
+    mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat);
     mCanvasContext->Fill();
 
-    // get rid of the pattern surface ref, because aData is very likely to go away shortly
+    // get rid of the pattern surface ref, because aData is very
+    // likely to go away shortly
     mCanvasContext->SetColor(gfxRGBA(1,1,1,1));
 
-    gfxRect damageRect = mCanvasContext->UserToDevice(gfxRect(0, 0, aWidth, aHeight));
+    gfxRect damageRect = mCanvasContext->UserToDevice(rect);
     mCanvas->Redraw(damageRect);
 }
 
 bool
-DocumentRendererParent::Recv__delete__(const PRUint32& w, const PRUint32& h,
+DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize,
                                        const nsCString& data)
 {
-    DrawToCanvas(w, h, data);
+    DrawToCanvas(renderedSize, data);
     return true;
 }
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -3734,24 +3734,23 @@ nsCanvasRenderingContext2D::AsyncDrawXUL
     PRUint32 renderDocFlags = nsIPresShell::RENDER_IGNORE_VIEWPORT_SCROLLING;
     if (flags & nsIDOMCanvasRenderingContext2D::DRAWWINDOW_DRAW_CARET) {
         renderDocFlags |= nsIPresShell::RENDER_CARET;
     }
     if (flags & nsIDOMCanvasRenderingContext2D::DRAWWINDOW_DRAW_VIEW) {
         renderDocFlags &= ~nsIPresShell::RENDER_IGNORE_VIEWPORT_SCROLLING;
     }
 
-    PRInt32 x = nsPresContext::CSSPixelsToAppUnits(aX),
-            y = nsPresContext::CSSPixelsToAppUnits(aY),
-            w = nsPresContext::CSSPixelsToAppUnits(aW),
-            h = nsPresContext::CSSPixelsToAppUnits(aH);
-
+    nsRect rect(nsPresContext::CSSPixelsToAppUnits(aX),
+                nsPresContext::CSSPixelsToAppUnits(aY),
+                nsPresContext::CSSPixelsToAppUnits(aW),
+                nsPresContext::CSSPixelsToAppUnits(aH));
     if (mIPC) {
         PDocumentRendererParent *pdocrender =
-            child->SendPDocumentRendererConstructor(x, y, w, h,
+            child->SendPDocumentRendererConstructor(rect,
                                                     nsString(aBGColor),
                                                     renderDocFlags, flush);
         if (!pdocrender)
             return NS_ERROR_FAILURE;
 
         DocumentRendererParent *docrender =
             static_cast<DocumentRendererParent *>(pdocrender);
 
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -46,23 +46,24 @@ include protocol POfflineCacheUpdate;
 
 include "TabMessageUtils.h";
 include "gfxMatrix.h";
 include "mozilla/net/NeckoMessageUtils.h";
 include "IPC/nsGUIEventIPC.h";
 
 using gfxMatrix;
 using IPC::URI;
+using nsCompositionEvent;
+using nsIMEUpdatePreference;
 using nsIntSize;
-using nsCompositionEvent;
-using nsTextEvent;
 using nsQueryContentEvent;
+using nsRect;
 using nsSelectionEvent;
+using nsTextEvent;
 using RemoteDOMEvent;
-using nsIMEUpdatePreference;
 
 namespace mozilla {
 namespace dom {
 
 rpc protocol PBrowser
 {
     manager PContent;
 
@@ -263,17 +264,30 @@ child:
 
     /**
      * Activate event forwarding from client to parent.
      */
     ActivateFrameEvent(nsString aType, bool capture);
 
     LoadRemoteScript(nsString aURL);
 
-    PDocumentRenderer(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h, nsString bgcolor, PRUint32 flags, bool flush);
+    /**
+     * Create a asynchronous request to render whatever document is
+     * loaded in the child when this message arrives.  When the
+     * request finishes, PDocumentRenderer:__delete__ is sent back to
+     * this side to notify completion.
+     *
+     * |documentRect| is the area of the remote document to draw.  The
+     * rendered area will have the default background color |bgcolor|.
+     * |renderFlags| are the nsIPresShell::RenderDocument() flags to
+     * use on the remote side, and if true, |flushLayout| will do just
+     * that before rendering the document.
+     */
+    PDocumentRenderer(nsRect documentRect, nsString bgcolor,
+                      PRUint32 renderFlags, bool flushLayout);
 
     /**
      * Sent by the chrome process when it no longer wants this remote
      * <browser>.  The child side cleans up in response, then
      * finalizing its death by sending back __delete__() to the
      * parent.
      */
     Destroy();
--- a/dom/ipc/PDocumentRenderer.ipdl
+++ b/dom/ipc/PDocumentRenderer.ipdl
@@ -32,22 +32,24 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 include protocol PBrowser;
 
+using nsIntSize;
+
 namespace mozilla {
 namespace ipc {
 
 protocol PDocumentRenderer
 {
   manager PBrowser;
 
 parent:
     // Returns the width and height, in pixels, of the returned ARGB32 data.
-    __delete__(PRUint32 w, PRUint32 h, nsCString data);
+    __delete__(nsIntSize renderedSize, nsCString data);
 };
 
 } // namespace ipc
 } // namespace mozilla
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -86,16 +86,17 @@
 #include "nsISSLStatusProvider.h"
 #include "nsSerializationHelper.h"
 #include "nsIFrame.h"
 #include "nsIView.h"
 #include "nsIEventListenerManager.h"
 #include "PCOMContentPermissionRequestChild.h"
 
 using namespace mozilla::dom;
+using namespace mozilla::ipc;
 using namespace mozilla::layers;
 using namespace mozilla::layout;
 using namespace mozilla::docshell;
 
 NS_IMPL_ISUPPORTS1(ContentListener, nsIDOMEventListener)
 
 NS_IMETHODIMP
 ContentListener::HandleEvent(nsIDOMEvent* aEvent)
@@ -586,67 +587,61 @@ TabChild::DispatchWidgetEvent(nsGUIEvent
     return false;
 
   nsEventStatus status;
   event.widget = mWidget;
   NS_ENSURE_SUCCESS(mWidget->DispatchEvent(&event, status), false);
   return true;
 }
 
-mozilla::ipc::PDocumentRendererChild*
-TabChild::AllocPDocumentRenderer(const PRInt32& x,
-                                 const PRInt32& y,
-                                 const PRInt32& w,
-                                 const PRInt32& h,
+PDocumentRendererChild*
+TabChild::AllocPDocumentRenderer(const nsRect& documentRect,
                                  const nsString& bgcolor,
-                                 const PRUint32& flags,
-                                 const bool& flush)
+                                 const PRUint32& renderFlags,
+                                 const bool& flushLayout)
 {
-    return new mozilla::ipc::DocumentRendererChild();
+    return new DocumentRendererChild();
 }
 
 bool
 TabChild::DeallocPDocumentRenderer(PDocumentRendererChild* actor)
 {
     delete actor;
     return true;
 }
 
 bool
-TabChild::RecvPDocumentRendererConstructor(
-        mozilla::ipc::PDocumentRendererChild *__a,
-        const PRInt32& aX,
-        const PRInt32& aY,
-        const PRInt32& aW,
-        const PRInt32& aH,
-        const nsString& bgcolor,
-        const PRUint32& flags,
-        const bool& flush)
+TabChild::RecvPDocumentRendererConstructor(PDocumentRendererChild* actor,
+                                           const nsRect& documentRect,
+                                           const nsString& bgcolor,
+                                           const PRUint32& renderFlags,
+                                           const bool& flushLayout)
 {
-    mozilla::ipc::DocumentRendererChild *render = 
-        static_cast<mozilla::ipc::DocumentRendererChild *>(__a);
+    DocumentRendererChild *render = static_cast<DocumentRendererChild *>(actor);
 
     nsCOMPtr<nsIWebBrowser> browser = do_QueryInterface(mWebNav);
     if (!browser)
         return true; // silently ignore
     nsCOMPtr<nsIDOMWindow> window;
     if (NS_FAILED(browser->GetContentDOMWindow(getter_AddRefs(window))) ||
         !window)
     {
         return true; // silently ignore
     }
 
-    PRUint32 width, height;
+    nsIntSize renderedSize;
     nsCString data;
-    bool ret = render->RenderDocument(window, aX, aY, aW, aH, bgcolor, flags, flush,
-                                      width, height, data);
+    bool ret = render->RenderDocument(window,
+                                      documentRect, bgcolor,
+                                      renderFlags, flushLayout,
+                                      &renderedSize, data);
     if (!ret)
         return true; // silently ignore
 
-    return PDocumentRendererChild::Send__delete__(__a, width, height, data);
+    return PDocumentRendererChild::Send__delete__(actor, renderedSize, data);
 }
 
 PContentDialogChild*
 TabChild::AllocPContentDialog(const PRUint32&,
                               const nsCString&,
                               const nsCString&,
                               const nsTArray<int>&,
                               const nsTArray<nsString>&)
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -192,34 +192,27 @@ public:
                               const bool&     aPreventDefault);
     virtual bool RecvCompositionEvent(const nsCompositionEvent& event);
     virtual bool RecvTextEvent(const nsTextEvent& event);
     virtual bool RecvSelectionEvent(const nsSelectionEvent& event);
     virtual bool RecvActivateFrameEvent(const nsString& aType, const bool& capture);
     virtual bool RecvLoadRemoteScript(const nsString& aURL);
     virtual bool RecvAsyncMessage(const nsString& aMessage,
                                   const nsString& aJSON);
-    virtual mozilla::ipc::PDocumentRendererChild* AllocPDocumentRenderer(
-            const PRInt32& x,
-            const PRInt32& y,
-            const PRInt32& w,
-            const PRInt32& h,
-            const nsString& bgcolor,
-            const PRUint32& flags,
-            const bool& flush);
+
+    virtual PDocumentRendererChild*
+    AllocPDocumentRenderer(const nsRect& documentRect, const nsString& bgcolor,
+                           const PRUint32& renderFlags, const bool& flushLayout);
     virtual bool DeallocPDocumentRenderer(PDocumentRendererChild* actor);
-    virtual bool RecvPDocumentRendererConstructor(
-            mozilla::ipc::PDocumentRendererChild *__a,
-            const PRInt32& x,
-            const PRInt32& y,
-            const PRInt32& w,
-            const PRInt32& h,
-            const nsString& bgcolor,
-            const PRUint32& flags,
-            const bool& flush);
+    virtual bool RecvPDocumentRendererConstructor(PDocumentRendererChild* actor,
+                                                  const nsRect& documentRect,
+                                                  const nsString& bgcolor,
+                                                  const PRUint32& renderFlags,
+                                                  const bool& flushLayout);
+
     virtual PContentDialogChild* AllocPContentDialog(const PRUint32&,
                                                      const nsCString&,
                                                      const nsCString&,
                                                      const nsTArray<int>&,
                                                      const nsTArray<nsString>&);
     virtual bool DeallocPContentDialog(PContentDialogChild* aDialog);
     static void ParamsToArrays(nsIDialogParamBlock* aParams,
                                nsTArray<int>& aIntParams,
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -213,20 +213,21 @@ TabParent::GetTooltipText(nsAString & aT
 NS_IMETHODIMP
 TabParent::GetSSLStatus(nsISupports ** aStatus)
 {
   NS_IF_ADDREF(*aStatus = mSecurityStatusObject);
   return NS_OK;
 }
 
 
-mozilla::ipc::PDocumentRendererParent*
-TabParent::AllocPDocumentRenderer(const PRInt32& x,
-        const PRInt32& y, const PRInt32& w, const PRInt32& h, const nsString& bgcolor,
-        const PRUint32& flags, const bool& flush)
+PDocumentRendererParent*
+TabParent::AllocPDocumentRenderer(const nsRect& documentRect,
+                                  const nsString& bgcolor,
+                                  const PRUint32& renderFlags,
+                                  const bool& flushLayout)
 {
     return new DocumentRendererParent();
 }
 
 bool
 TabParent::DeallocPDocumentRenderer(PDocumentRendererParent* actor)
 {
     delete actor;
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -127,24 +127,19 @@ public:
     void Activate();
     void SendMouseEvent(const nsAString& aType, float aX, float aY,
                         PRInt32 aButton, PRInt32 aClickCount,
                         PRInt32 aModifiers, PRBool aIgnoreRootScrollFrame);
     void SendKeyEvent(const nsAString& aType, PRInt32 aKeyCode,
                       PRInt32 aCharCode, PRInt32 aModifiers,
                       PRBool aPreventDefault);
 
-    virtual mozilla::ipc::PDocumentRendererParent* AllocPDocumentRenderer(
-            const PRInt32& x,
-            const PRInt32& y,
-            const PRInt32& w,
-            const PRInt32& h,
-            const nsString& bgcolor,
-            const PRUint32& flags,
-            const bool& flush);
+    virtual PDocumentRendererParent*
+    AllocPDocumentRenderer(const nsRect& documentRect, const nsString& bgcolor,
+                           const PRUint32& renderFlags, const bool& flushLayout);
     virtual bool DeallocPDocumentRenderer(PDocumentRendererParent* actor);
 
     virtual PContentPermissionRequestParent* AllocPContentPermissionRequest(const nsCString& aType, const IPC::URI& uri);
     virtual bool DeallocPContentPermissionRequest(PContentPermissionRequestParent* actor);
 
     virtual POfflineCacheUpdateParent* AllocPOfflineCacheUpdate(
             const URI& aManifestURI,
             const URI& aDocumentURI,
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -582,16 +582,38 @@ struct ParamTraits<nsIntSize>
   static bool Read(const Message* msg, void** iter, paramType* result)
   {
     return (ReadParam(msg, iter, &result->width) &&
             ReadParam(msg, iter, &result->height));
   }
 };
 
 template<>
+struct ParamTraits<nsRect>
+{
+  typedef nsRect paramType;
+  
+  static void Write(Message* msg, const paramType& param)
+  {
+    WriteParam(msg, param.x);
+    WriteParam(msg, param.y);
+    WriteParam(msg, param.width);
+    WriteParam(msg, param.height);
+  }
+
+  static bool Read(const Message* msg, void** iter, paramType* result)
+  {
+    return (ReadParam(msg, iter, &result->x) &&
+            ReadParam(msg, iter, &result->y) &&
+            ReadParam(msg, iter, &result->width) &&
+            ReadParam(msg, iter, &result->height));
+  }
+};
+
+template<>
 struct ParamTraits<gfxIntSize>
 {
   typedef gfxIntSize paramType;
   
   static void Write(Message* msg, const paramType& param)
   {
     WriteParam(msg, param.width);
     WriteParam(msg, param.height);