Bug 606279, part 2: Use more concise types in PDocumentRenderer. r=joe

This commit is contained in:
Chris Jones 2010-10-26 17:20:53 -05:00
Родитель e5ab98f45e
Коммит cfd44f24b3
12 изменённых файлов: 123 добавлений и 94 удалений

Просмотреть файл

@ -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:

Просмотреть файл

@ -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:

Просмотреть файл

@ -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<nsPresContext> 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<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;
}

Просмотреть файл

@ -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<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;
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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<mozilla::ipc::DocumentRendererChild *>(__a);
DocumentRendererChild *render = static_cast<DocumentRendererChild *>(actor);
nsCOMPtr<nsIWebBrowser> 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*

Просмотреть файл

@ -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&,

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -586,6 +586,28 @@ struct ParamTraits<nsIntSize>
}
};
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>
{