From cfd44f24b38d81c8c144d1c8ed4c0898ba9e81ab Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 26 Oct 2010 17:20:53 -0500 Subject: [PATCH] Bug 606279, part 2: Use more concise types in PDocumentRenderer. r=joe --- content/canvas/public/DocumentRendererChild.h | 7 ++-- .../canvas/public/DocumentRendererParent.h | 4 +- content/canvas/src/DocumentRendererChild.cpp | 32 ++++++++------- content/canvas/src/DocumentRendererParent.cpp | 23 ++++++----- .../canvas/src/nsCanvasRenderingContext2D.cpp | 11 +++-- dom/ipc/PBrowser.ipdl | 26 +++++++++--- dom/ipc/PDocumentRenderer.ipdl | 4 +- dom/ipc/TabChild.cpp | 41 ++++++++----------- dom/ipc/TabChild.h | 27 +++++------- dom/ipc/TabParent.cpp | 9 ++-- dom/ipc/TabParent.h | 11 ++--- ipc/glue/IPCMessageUtils.h | 22 ++++++++++ 12 files changed, 123 insertions(+), 94 deletions(-) diff --git a/content/canvas/public/DocumentRendererChild.h b/content/canvas/public/DocumentRendererChild.h index f793eb66fc7..c3ebb6c93e5 100644 --- a/content/canvas/public/DocumentRendererChild.h +++ b/content/canvas/public/DocumentRendererChild.h @@ -53,9 +53,10 @@ 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: diff --git a/content/canvas/public/DocumentRendererParent.h b/content/canvas/public/DocumentRendererParent.h index 312140d997f..888123bf409 100644 --- a/content/canvas/public/DocumentRendererParent.h +++ b/content/canvas/public/DocumentRendererParent.h @@ -54,10 +54,10 @@ public: 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: diff --git a/content/canvas/src/DocumentRendererChild.cpp b/content/canvas/src/DocumentRendererChild.cpp index ee497d17db8..ce73888fdb4 100644 --- a/content/canvas/src/DocumentRendererChild.cpp +++ b/content/canvas/src/DocumentRendererChild.cpp @@ -99,11 +99,14 @@ FlushLayoutForTree(nsIDOMWindow* aWindow) } 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 presContext; @@ -119,26 +122,27 @@ DocumentRendererChild::RenderDocument(nsIDOMWindow *window, const PRInt32& x, co 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 surf = new gfxImageSurface(reinterpret_cast(const_cast(data.get())), - gfxIntSize(_width, _height), - 4 * _width, gfxASurface::ImageFormatARGB32); + data.SetLength(w * h * 4); + nsRefPtr surf = + new gfxImageSurface(reinterpret_cast(data.BeginWriting()), + gfxIntSize(w, h), + 4 * w, + gfxASurface::ImageFormatARGB32); nsRefPtr ctx = new gfxContext(surf); - presShell->RenderDocument(r, flags, bgColor, ctx); + presShell->RenderDocument(documentRect, renderFlags, bgColor, ctx); + *renderedSize = nsIntSize(w, h); return true; } diff --git a/content/canvas/src/DocumentRendererParent.cpp b/content/canvas/src/DocumentRendererParent.cpp index 8e1eefed6dd..933067b4552 100644 --- a/content/canvas/src/DocumentRendererParent.cpp +++ b/content/canvas/src/DocumentRendererParent.cpp @@ -53,33 +53,36 @@ void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* mCanvasContext = ctx; } -void DocumentRendererParent::DrawToCanvas(PRUint32 aWidth, PRUint32 aHeight, +void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize, const nsCString& aData) { if (!mCanvas || !mCanvasContext) return; - nsRefPtr surf = new gfxImageSurface(reinterpret_cast(const_cast(aData.Data())), - gfxIntSize(aWidth, aHeight), - aWidth * 4, - gfxASurface::ImageFormatARGB32); + nsRefPtr surf = + new gfxImageSurface(reinterpret_cast(const_cast(aData).BeginWriting()), + gfxIntSize(aSize.width, aSize.height), + aSize.width * 4, + gfxASurface::ImageFormatARGB32); nsRefPtr 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; } diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 596cad0f116..67eb8ab5e14 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -3739,14 +3739,13 @@ nsCanvasRenderingContext2D::AsyncDrawXULElement(nsIDOMXULElement* aElem, float a 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) diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 8f14903cf03..3f979d4a1ae 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -51,13 +51,14 @@ include "IPC/nsGUIEventIPC.h"; using gfxMatrix; using IPC::URI; -using nsIntSize; using nsCompositionEvent; -using nsTextEvent; -using nsQueryContentEvent; -using nsSelectionEvent; -using RemoteDOMEvent; using nsIMEUpdatePreference; +using nsIntSize; +using nsQueryContentEvent; +using nsRect; +using nsSelectionEvent; +using nsTextEvent; +using RemoteDOMEvent; namespace mozilla { namespace dom { @@ -268,7 +269,20 @@ child: 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 diff --git a/dom/ipc/PDocumentRenderer.ipdl b/dom/ipc/PDocumentRenderer.ipdl index 11a2c68e961..a64a87c0dc5 100644 --- a/dom/ipc/PDocumentRenderer.ipdl +++ b/dom/ipc/PDocumentRenderer.ipdl @@ -37,6 +37,8 @@ include protocol PBrowser; +using nsIntSize; + namespace mozilla { namespace ipc { @@ -46,7 +48,7 @@ protocol PDocumentRenderer 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 diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 4b1324d9e26..bba713838db 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -91,6 +91,7 @@ #include "PCOMContentPermissionRequestChild.h" using namespace mozilla::dom; +using namespace mozilla::ipc; using namespace mozilla::layers; using namespace mozilla::layout; using namespace mozilla::docshell; @@ -591,16 +592,13 @@ TabChild::DispatchWidgetEvent(nsGUIEvent& event) 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 @@ -611,18 +609,13 @@ TabChild::DeallocPDocumentRenderer(PDocumentRendererChild* actor) } 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(__a); + DocumentRendererChild *render = static_cast(actor); nsCOMPtr browser = do_QueryInterface(mWebNav); if (!browser) @@ -634,14 +627,16 @@ TabChild::RecvPDocumentRendererConstructor( 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* diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index 031753a558e..2ccdf11366c 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -197,24 +197,17 @@ public: 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&, diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index 751834ff9f2..a2f8749c233 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -218,10 +218,11 @@ TabParent::GetSSLStatus(nsISupports ** aStatus) } -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(); } diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index c9b86fd5e43..b1f7e7fbb67 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -132,14 +132,9 @@ public: 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); diff --git a/ipc/glue/IPCMessageUtils.h b/ipc/glue/IPCMessageUtils.h index 42236f9384e..c3a9a9729b7 100644 --- a/ipc/glue/IPCMessageUtils.h +++ b/ipc/glue/IPCMessageUtils.h @@ -586,6 +586,28 @@ struct ParamTraits } }; +template<> +struct ParamTraits +{ + 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 {