mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1258609: Initialize nsICanvasRenderingContextInternal with a DrawTarget instead of a gfxASurface. r=jrmuizel
MozReview-Commit-ID: JNQ9GWvDUSq
This commit is contained in:
parent
d46718279a
commit
c4ec1107e4
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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; }
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user