2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-29 17:58:31 +00:00
|
|
|
|
2014-06-04 07:08:39 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2009-10-29 17:58:31 +00:00
|
|
|
#include "mozilla/ipc/DocumentRendererParent.h"
|
2014-06-04 07:08:39 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2009-10-29 17:58:31 +00:00
|
|
|
#include "gfxPattern.h"
|
2012-06-06 07:42:47 +00:00
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
2009-10-29 17:58:31 +00:00
|
|
|
|
2014-06-04 07:08:39 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2009-10-29 17:58:31 +00:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
DocumentRendererParent::DocumentRendererParent()
|
|
|
|
{}
|
|
|
|
|
|
|
|
DocumentRendererParent::~DocumentRendererParent()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas,
|
|
|
|
gfxContext* ctx)
|
|
|
|
{
|
|
|
|
mCanvas = aCanvas;
|
|
|
|
mCanvasContext = ctx;
|
|
|
|
}
|
|
|
|
|
2010-10-26 22:20:53 +00:00
|
|
|
void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize,
|
2009-10-29 17:58:31 +00:00
|
|
|
const nsCString& aData)
|
|
|
|
{
|
|
|
|
if (!mCanvas || !mCanvasContext)
|
|
|
|
return;
|
|
|
|
|
2014-06-04 07:08:39 +00:00
|
|
|
RefPtr<DataSourceSurface> dataSurface =
|
|
|
|
Factory::CreateWrappingDataSourceSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()),
|
|
|
|
aSize.width * 4,
|
|
|
|
IntSize(aSize.width, aSize.height),
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
|
|
|
nsRefPtr<gfxPattern> pat = new gfxPattern(dataSurface, Matrix());
|
2009-10-29 17:58:31 +00:00
|
|
|
|
2010-10-26 22:20:53 +00:00
|
|
|
gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height));
|
2009-10-29 17:58:31 +00:00
|
|
|
mCanvasContext->NewPath();
|
2010-10-26 22:20:53 +00:00
|
|
|
mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat);
|
2009-10-29 17:58:31 +00:00
|
|
|
mCanvasContext->Fill();
|
|
|
|
|
2010-10-26 22:20:53 +00:00
|
|
|
// get rid of the pattern surface ref, because aData is very
|
|
|
|
// likely to go away shortly
|
2009-10-29 17:58:31 +00:00
|
|
|
mCanvasContext->SetColor(gfxRGBA(1,1,1,1));
|
|
|
|
|
2010-10-26 22:20:53 +00:00
|
|
|
gfxRect damageRect = mCanvasContext->UserToDevice(rect);
|
2009-10-29 17:58:31 +00:00
|
|
|
mCanvas->Redraw(damageRect);
|
|
|
|
}
|
2009-12-03 08:16:14 +00:00
|
|
|
|
2014-05-02 18:44:13 +00:00
|
|
|
void
|
|
|
|
DocumentRendererParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
// Implement me! Bug 1005139
|
|
|
|
}
|
|
|
|
|
2009-12-03 08:16:14 +00:00
|
|
|
bool
|
2010-10-26 22:20:53 +00:00
|
|
|
DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize,
|
2009-12-03 08:16:14 +00:00
|
|
|
const nsCString& data)
|
|
|
|
{
|
2010-10-26 22:20:53 +00:00
|
|
|
DrawToCanvas(renderedSize, data);
|
2009-12-03 08:16:14 +00:00
|
|
|
return true;
|
|
|
|
}
|