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
|
|
|
|
|
|
|
#include "mozilla/ipc/DocumentRendererParent.h"
|
2014-10-24 07:26:27 +00:00
|
|
|
|
|
|
|
#include "gfx2DGlue.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2014-06-04 07:08:39 +00:00
|
|
|
#include "mozilla/RefPtr.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-10-24 07:26:27 +00:00
|
|
|
DrawTarget* drawTarget = mCanvasContext->GetDrawTarget();
|
|
|
|
Rect rect(0, 0, aSize.width, aSize.height);
|
|
|
|
MaybeSnapToDevicePixels(rect, *drawTarget, true);
|
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);
|
2014-10-24 07:26:27 +00:00
|
|
|
SurfacePattern pattern(dataSurface, ExtendMode::CLAMP);
|
|
|
|
drawTarget->FillRect(rect, pattern);
|
2009-10-29 17:58:31 +00:00
|
|
|
|
2014-10-24 07:26:27 +00:00
|
|
|
gfxRect damageRect = mCanvasContext->UserToDevice(ThebesRect(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;
|
|
|
|
}
|