Bug 1258609: Initialize nsICanvasRenderingContextInternal with a DrawTarget instead of a gfxASurface. r=jrmuizel

MozReview-Commit-ID: JNQ9GWvDUSq
This commit is contained in:
Bob Owen 2016-04-21 10:30:38 +01:00
parent d46718279a
commit c4ec1107e4
9 changed files with 26 additions and 56 deletions

View File

@ -1616,18 +1616,16 @@ CanvasRenderingContext2D::ReturnTarget()
}
NS_IMETHODIMP
CanvasRenderingContext2D::InitializeWithSurface(nsIDocShell* aShell,
gfxASurface* aSurface,
int32_t aWidth,
int32_t aHeight)
CanvasRenderingContext2D::InitializeWithDrawTarget(nsIDocShell* aShell,
gfx::DrawTarget* aTarget)
{
RemovePostRefreshObserver();
mDocShell = aShell;
AddPostRefreshObserverIfNecessary();
SetDimensions(aWidth, aHeight);
mTarget = gfxPlatform::GetPlatform()->
CreateDrawTargetForSurface(aSurface, IntSize(aWidth, aHeight));
IntSize size = aTarget->GetSize();
SetDimensions(size.width, size.height);
mTarget = aTarget;
if (!mTarget) {
EnsureErrorTarget();

View File

@ -443,7 +443,8 @@ public:
return nullptr;
}
NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;
NS_IMETHOD InitializeWithSurface(nsIDocShell* aShell, gfxASurface* aSurface, int32_t aWidth, int32_t aHeight) override;
NS_IMETHOD InitializeWithDrawTarget(nsIDocShell* aShell,
gfx::DrawTarget* aTarget) override;
NS_IMETHOD GetInputStream(const char* aMimeType,
const char16_t* aEncoderOptions,

View File

@ -82,10 +82,8 @@ ImageBitmapRenderingContext::SetDimensions(int32_t aWidth, int32_t aHeight)
}
NS_IMETHODIMP
ImageBitmapRenderingContext::InitializeWithSurface(nsIDocShell* aDocShell,
gfxASurface* aSurface,
int32_t aWidth,
int32_t aHeight)
ImageBitmapRenderingContext::InitializeWithDrawTarget(nsIDocShell* aDocShell,
gfx::DrawTarget* aTarget)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -12,6 +12,7 @@ namespace mozilla {
namespace gfx {
class DataSourceSurface;
class DrawTarget;
class SourceSurface;
}
@ -53,10 +54,8 @@ public:
NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;
NS_IMETHOD InitializeWithSurface(nsIDocShell* aDocShell,
gfxASurface* aSurface,
int32_t aWidth,
int32_t aHeight) override;
NS_IMETHOD InitializeWithDrawTarget(nsIDocShell* aDocShell,
gfx::DrawTarget* aTarget) override;
virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
NS_IMETHOD GetInputStream(const char* aMimeType,

View File

@ -240,8 +240,7 @@ public:
virtual int32_t GetHeight() const override;
NS_IMETHOD SetDimensions(int32_t width, int32_t height) override;
NS_IMETHOD InitializeWithSurface(nsIDocShell*, gfxASurface*, int32_t,
int32_t) override
NS_IMETHOD InitializeWithDrawTarget(nsIDocShell*, gfx::DrawTarget*) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -96,7 +96,10 @@ public:
// whenever the size of the element changes.
NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0;
NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0;
// Initializes with an nsIDocShell and DrawTarget. The size is taken from the
// DrawTarget.
NS_IMETHOD InitializeWithDrawTarget(nsIDocShell *aDocShell,
mozilla::gfx::DrawTarget* aTarget) = 0;
// Creates an image buffer. Returns null on failure.
virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* format) = 0;

View File

@ -122,24 +122,6 @@ gfxContext::~gfxContext()
MOZ_COUNT_DTOR(gfxContext);
}
already_AddRefed<gfxASurface>
gfxContext::CurrentSurface()
{
if (mDT->GetBackendType() == BackendType::CAIRO) {
cairo_t* ctx = static_cast<cairo_t*>
(mDT->GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT));
if (ctx) {
cairo_surface_t* s = cairo_get_group_target(ctx);
if (s) {
return gfxASurface::Wrap(s);
}
}
}
// An Azure context doesn't have a surface backing it.
return nullptr;
}
void
gfxContext::Save()
{

View File

@ -78,12 +78,6 @@ public:
static already_AddRefed<gfxContext>
ForDrawTargetWithTransform(mozilla::gfx::DrawTarget* aTarget);
/**
* Return the current transparency group target, if any. If no group is
* active, returns the surface the gfxContext was created with.
*/
already_AddRefed<gfxASurface> CurrentSurface();
mozilla::gfx::DrawTarget *GetDrawTarget() { return mDT; }
/**

View File

@ -638,32 +638,28 @@ nsSimplePageSequenceFrame::PrePrintNextPage(nsITimerCallback* aCallback, bool* a
RefPtr<gfxContext> renderingContext = dc->CreateRenderingContext();
NS_ENSURE_TRUE(renderingContext, NS_ERROR_OUT_OF_MEMORY);
RefPtr<gfxASurface> renderingSurface =
renderingContext->CurrentSurface();
NS_ENSURE_TRUE(renderingSurface, NS_ERROR_OUT_OF_MEMORY);
DrawTarget* drawTarget = renderingContext->GetDrawTarget();
if (NS_WARN_IF(!drawTarget)) {
return NS_ERROR_FAILURE;
}
for (int32_t i = mCurrentCanvasList.Length() - 1; i >= 0 ; i--) {
HTMLCanvasElement* canvas = mCurrentCanvasList[i];
nsIntSize size = canvas->GetSize();
RefPtr<gfxASurface> printSurface = renderingSurface->
CreateSimilarSurface(
gfxContentType::COLOR_ALPHA,
size
);
if (!printSurface) {
RefPtr<DrawTarget> canvasTarget =
drawTarget->CreateSimilarDrawTarget(size, drawTarget->GetFormat());
if (!canvasTarget) {
continue;
}
nsICanvasRenderingContextInternal* ctx = canvas->GetContextAtIndex(0);
if (!ctx) {
continue;
}
// Initialize the context with the new printSurface.
ctx->InitializeWithSurface(nullptr, printSurface, size.width, size.height);
// Initialize the context with the new DrawTarget.
ctx->InitializeWithDrawTarget(nullptr, canvasTarget);
// Start the rendering process.
nsWeakFrame weakFrame = this;