2012-05-21 04:12:37 -07: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 10:58:31 -07:00
|
|
|
|
2014-06-04 00:08:39 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2009-10-29 10:58:31 -07:00
|
|
|
#include "mozilla/ipc/DocumentRendererParent.h"
|
2014-06-04 00:08:39 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
2009-10-29 10:58:31 -07:00
|
|
|
#include "gfxPattern.h"
|
2012-06-06 00:42:47 -07:00
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
2009-10-29 10:58:31 -07:00
|
|
|
|
2014-06-04 00:08:39 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2009-10-29 10:58:31 -07:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
DocumentRendererParent::DocumentRendererParent()
|
|
|
|
{}
|
|
|
|
|
|
|
|
DocumentRendererParent::~DocumentRendererParent()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas,
|
|
|
|
gfxContext* ctx)
|
|
|
|
{
|
|
|
|
mCanvas = aCanvas;
|
|
|
|
mCanvasContext = ctx;
|
|
|
|
}
|
|
|
|
|
2010-10-26 15:20:53 -07:00
|
|
|
void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize,
|
2009-10-29 10:58:31 -07:00
|
|
|
const nsCString& aData)
|
|
|
|
{
|
|
|
|
if (!mCanvas || !mCanvasContext)
|
|
|
|
return;
|
|
|
|
|
2014-06-04 00:08:39 -07: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 10:58:31 -07:00
|
|
|
|
2010-10-26 15:20:53 -07:00
|
|
|
gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height));
|
2009-10-29 10:58:31 -07:00
|
|
|
mCanvasContext->NewPath();
|
2010-10-26 15:20:53 -07:00
|
|
|
mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat);
|
2009-10-29 10:58:31 -07:00
|
|
|
mCanvasContext->Fill();
|
|
|
|
|
2010-10-26 15:20:53 -07:00
|
|
|
// get rid of the pattern surface ref, because aData is very
|
|
|
|
// likely to go away shortly
|
2009-10-29 10:58:31 -07:00
|
|
|
mCanvasContext->SetColor(gfxRGBA(1,1,1,1));
|
|
|
|
|
2010-10-26 15:20:53 -07:00
|
|
|
gfxRect damageRect = mCanvasContext->UserToDevice(rect);
|
2009-10-29 10:58:31 -07:00
|
|
|
mCanvas->Redraw(damageRect);
|
|
|
|
}
|
2009-12-03 00:16:14 -08:00
|
|
|
|
2014-05-02 11:44:13 -07:00
|
|
|
void
|
|
|
|
DocumentRendererParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
// Implement me! Bug 1005139
|
|
|
|
}
|
|
|
|
|
2009-12-03 00:16:14 -08:00
|
|
|
bool
|
2010-10-26 15:20:53 -07:00
|
|
|
DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize,
|
2009-12-03 00:16:14 -08:00
|
|
|
const nsCString& data)
|
|
|
|
{
|
2010-10-26 15:20:53 -07:00
|
|
|
DrawToCanvas(renderedSize, data);
|
2009-12-03 00:16:14 -08:00
|
|
|
return true;
|
|
|
|
}
|