Bug 1297054 - remove null check in CanvasRenderingContext2D::InitializeWithDrawTarget. r?jrmuizel
MozReview-Commit-ID: GA3PntlpxBU
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -1791,32 +1791,27 @@ CanvasRenderingContext2D::ReturnTarget()
}
mBufferProvider->ReturnDrawTarget(mTarget.forget());
}
}
NS_IMETHODIMP
CanvasRenderingContext2D::InitializeWithDrawTarget(nsIDocShell* aShell,
- gfx::DrawTarget* aTarget)
+ NotNull<gfx::DrawTarget*> aTarget)
{
RemovePostRefreshObserver();
mDocShell = aShell;
AddPostRefreshObserverIfNecessary();
IntSize size = aTarget->GetSize();
SetDimensions(size.width, size.height);
- if (aTarget) {
- mTarget = aTarget;
- mBufferProvider = new PersistentBufferProviderBasic(aTarget);
- } else {
- EnsureErrorTarget();
- mTarget = sErrorTarget;
- }
+ mTarget = aTarget;
+ mBufferProvider = new PersistentBufferProviderBasic(aTarget);
if (mTarget->GetBackendType() == gfx::BackendType::CAIRO) {
// Cf comment in EnsureTarget
mTarget->PushClipRect(gfx::Rect(Point(0, 0), Size(mWidth, mHeight)));
}
return NS_OK;
}
--- a/dom/canvas/CanvasRenderingContext2D.h
+++ b/dom/canvas/CanvasRenderingContext2D.h
@@ -440,17 +440,17 @@ public:
}
if (mDocShell) {
return mDocShell->GetPresShell();
}
return nullptr;
}
NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;
NS_IMETHOD InitializeWithDrawTarget(nsIDocShell* aShell,
- gfx::DrawTarget* aTarget) override;
+ NotNull<gfx::DrawTarget*> aTarget) override;
NS_IMETHOD GetInputStream(const char* aMimeType,
const char16_t* aEncoderOptions,
nsIInputStream** aStream) override;
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) override
{
EnsureTarget();
--- a/dom/canvas/ImageBitmapRenderingContext.cpp
+++ b/dom/canvas/ImageBitmapRenderingContext.cpp
@@ -78,17 +78,17 @@ ImageBitmapRenderingContext::SetDimensio
{
mWidth = aWidth;
mHeight = aHeight;
return NS_OK;
}
NS_IMETHODIMP
ImageBitmapRenderingContext::InitializeWithDrawTarget(nsIDocShell* aDocShell,
- gfx::DrawTarget* aTarget)
+ NotNull<gfx::DrawTarget*> aTarget)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
already_AddRefed<DataSourceSurface>
ImageBitmapRenderingContext::MatchWithIntrinsicSize()
{
RefPtr<SourceSurface> surface = mImage->GetAsSourceSurface();
--- a/dom/canvas/ImageBitmapRenderingContext.h
+++ b/dom/canvas/ImageBitmapRenderingContext.h
@@ -50,17 +50,17 @@ public:
// nsICanvasRenderingContextInternal
virtual int32_t GetWidth() const override;
virtual int32_t GetHeight() const override;
NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;
NS_IMETHOD InitializeWithDrawTarget(nsIDocShell* aDocShell,
- gfx::DrawTarget* aTarget) override;
+ NotNull<gfx::DrawTarget*> aTarget) override;
virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
NS_IMETHOD GetInputStream(const char* aMimeType,
const char16_t* aEncoderOptions,
nsIInputStream** aStream) override;
virtual already_AddRefed<mozilla::gfx::SourceSurface>
GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) override;
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -235,17 +235,18 @@ public:
virtual void OnVisibilityChange() override;
virtual void OnMemoryPressure() override;
// nsICanvasRenderingContextInternal
virtual int32_t GetWidth() const override;
virtual int32_t GetHeight() const override;
NS_IMETHOD SetDimensions(int32_t width, int32_t height) override;
- NS_IMETHOD InitializeWithDrawTarget(nsIDocShell*, gfx::DrawTarget*) override
+ NS_IMETHOD InitializeWithDrawTarget(nsIDocShell*,
+ NotNull<gfx::DrawTarget*>) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD Reset() override {
/* (InitializeWithSurface) */
return NS_ERROR_NOT_IMPLEMENTED;
}
--- a/dom/canvas/nsICanvasRenderingContextInternal.h
+++ b/dom/canvas/nsICanvasRenderingContextInternal.h
@@ -10,16 +10,17 @@
#include "nsISupports.h"
#include "nsIInputStream.h"
#include "nsIDocShell.h"
#include "nsRefreshDriver.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/OffscreenCanvas.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
+#include "mozilla/NotNull.h"
#define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
{ 0xb84f2fed, 0x9d4b, 0x430b, \
{ 0xbd, 0xfb, 0x85, 0x57, 0x8a, 0xc2, 0xb4, 0x4b } }
class nsDisplayListBuilder;
namespace mozilla {
@@ -93,17 +94,17 @@ public:
// Sets the dimensions of the canvas, in pixels. Called
// whenever the size of the element changes.
NS_IMETHOD SetDimensions(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;
+ mozilla::NotNull<mozilla::gfx::DrawTarget*> aTarget) = 0;
// Creates an image buffer. Returns null on failure.
virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* format) = 0;
// Gives you a stream containing the image represented by this context.
// The format is given in mimeTime, for example "image/png".
//
// If the image format does not support transparency or includeTransparency
--- a/layout/generic/nsSimplePageSequenceFrame.cpp
+++ b/layout/generic/nsSimplePageSequenceFrame.cpp
@@ -654,17 +654,17 @@ nsSimplePageSequenceFrame::PrePrintNextP
}
nsICanvasRenderingContextInternal* ctx = canvas->GetContextAtIndex(0);
if (!ctx) {
continue;
}
// Initialize the context with the new DrawTarget.
- ctx->InitializeWithDrawTarget(nullptr, canvasTarget);
+ ctx->InitializeWithDrawTarget(nullptr, WrapNotNull(canvasTarget));
// Start the rendering process.
nsWeakFrame weakFrame = this;
canvas->DispatchPrintCallback(aCallback);
NS_ENSURE_STATE(weakFrame.IsAlive());
}
}
}