From 4e8f3b6d6ee9fe7494bc19bcef9211724e1fe7c0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 7 Jun 2016 11:17:48 +1000 Subject: [PATCH] Bug 1276824 (part 2) - Fix up checks for calls to gfxContext::Create{,PreservingTransform}OrNull(). r=milan. --HG-- extra : rebase_source : 80644c1a6658da553c13ae1ab3b8d03e916ee6e7 --- dom/canvas/CanvasRenderingContext2D.cpp | 5 ++++- gfx/layers/basic/BasicLayerManager.cpp | 2 -- gfx/tests/gtest/gfxFontSelectionTest.cpp | 3 +++ gfx/tests/gtest/gfxTextRunPerfTest.cpp | 3 +++ gfx/thebes/gfxPlatform.cpp | 2 +- layout/base/nsDisplayList.cpp | 5 +++-- layout/svg/nsSVGIntegrationUtils.cpp | 4 ++++ widget/cocoa/nsCocoaUtils.mm | 9 +++------ 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index c65482c67195..313b189c7b8b 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -3604,6 +3604,8 @@ struct MOZ_STACK_CLASS CanvasBidiProcessor : public nsBidiPresUtils::BidiProcess // not render well via the code below. if (mOp == CanvasRenderingContext2D::TextDrawOperation::FILL && mState->StyleIsColor(CanvasRenderingContext2D::Style::FILL)) { + // TODO: determine if mCtx->mTarget is guaranteed to be non-null and valid + // here. If it's not, thebes will be null and we'll crash. RefPtr thebes = gfxContext::CreatePreservingTransformOrNull(mCtx->mTarget); nscolor fill = mState->colorStyles[CanvasRenderingContext2D::Style::FILL]; @@ -4992,7 +4994,8 @@ CanvasRenderingContext2D::DrawWindow(nsGlobalWindow& aWindow, double aX, UsedOperation() == CompositionOp::OP_OVER) { thebes = gfxContext::CreateOrNull(mTarget); - MOZ_ASSERT(thebes); // alrady checked the draw target above + MOZ_ASSERT(thebes); // already checked the draw target above + // (in SupportsAzureContentForDrawTarget) thebes->SetMatrix(gfxMatrix(matrix._11, matrix._12, matrix._21, matrix._22, matrix._31, matrix._32)); } else { diff --git a/gfx/layers/basic/BasicLayerManager.cpp b/gfx/layers/basic/BasicLayerManager.cpp index 648ae798d3d7..9f97e1d765f7 100644 --- a/gfx/layers/basic/BasicLayerManager.cpp +++ b/gfx/layers/basic/BasicLayerManager.cpp @@ -932,8 +932,6 @@ BasicLayerManager::PaintLayer(gfxContext* aTarget, // Temporary fast fix for bug 725886 // Revert these changes when 725886 is ready - MOZ_ASSERT(untransformedDT && untransformedDT->IsValid(), - "We should always allocate an untransformed surface with 3d transforms!"); #ifdef DEBUG if (aLayer->GetDebugColorIndex() != 0) { Color color((aLayer->GetDebugColorIndex() & 1) ? 1.f : 0.f, diff --git a/gfx/tests/gtest/gfxFontSelectionTest.cpp b/gfx/tests/gtest/gfxFontSelectionTest.cpp index 767b7e0af38e..9c2453c14dff 100644 --- a/gfx/tests/gtest/gfxFontSelectionTest.cpp +++ b/gfx/tests/gtest/gfxFontSelectionTest.cpp @@ -193,6 +193,9 @@ MakeContext () CreateOffscreenContentDrawTarget(IntSize(size, size), SurfaceFormat::B8G8R8X8); RefPtr ctx = gfxContext::CreateOrNull(drawTarget); + if (!ctx) { + MOZ_CRASH("gfxContext creation failed"); + } return ctx.forget(); } diff --git a/gfx/tests/gtest/gfxTextRunPerfTest.cpp b/gfx/tests/gtest/gfxTextRunPerfTest.cpp index 3119b2672115..bb9610463694 100644 --- a/gfx/tests/gtest/gfxTextRunPerfTest.cpp +++ b/gfx/tests/gtest/gfxTextRunPerfTest.cpp @@ -44,6 +44,9 @@ MakeContext () CreateOffscreenContentDrawTarget(IntSize(size, size), SurfaceFormat::B8G8R8X8); RefPtr ctx = gfxContext::CreateOrNull(drawTarget); + if (!ctx) { + MOZ_CRASH("gfxContext creation failed"); + } return ctx.forget(); } diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index fc42213db981..494bca4aa64c 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -1238,7 +1238,7 @@ gfxPlatform::PopulateScreenInfo() bool gfxPlatform::SupportsAzureContentForDrawTarget(DrawTarget* aTarget) { - if (!aTarget) { + if (!aTarget || !aTarget->IsValid()) { return false; } diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 2cbeedfa971d..87edf368cbd5 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -565,10 +565,11 @@ GenerateAndPushTextMask(nsIFrame* aFrame, nsRenderingContext* aContext, RefPtr maskDT = sourceTarget->CreateSimilarDrawTarget(drawRect.Size(), SurfaceFormat::A8); - if (!maskDT) { - NS_ABORT_OOM(drawRect.width * drawRect.height); + if (!maskDT || !maskDT->IsValid()) { + return false; } RefPtr maskCtx = gfxContext::CreatePreservingTransformOrNull(maskDT); + MOZ_ASSERT(maskCtx); gfxMatrix currentMatrix = sourceCtx->CurrentMatrix(); maskCtx->SetMatrix(gfxMatrix::Translation(bounds.TopLeft()) * currentMatrix * diff --git a/layout/svg/nsSVGIntegrationUtils.cpp b/layout/svg/nsSVGIntegrationUtils.cpp index 71e097c6fd76..2d520ce058b0 100644 --- a/layout/svg/nsSVGIntegrationUtils.cpp +++ b/layout/svg/nsSVGIntegrationUtils.cpp @@ -455,8 +455,12 @@ GenerateMaskSurface(const nsSVGIntegrationUtils::PaintFramesParams& aParams, SurfaceFormat::A8) : ctx.GetDrawTarget()->CreateSimilarDrawTarget(maskSurfaceRect.Size(), SurfaceFormat::A8); + if (!maskDT || !maskDT->IsValid()) { + return; + } RefPtr maskContext = gfxContext::CreateOrNull(maskDT); + MOZ_ASSERT(maskContext); // Set ctx's matrix on maskContext, offset by the maskSurfaceRect's position. // This makes sure that we combine the masks in device space. diff --git a/widget/cocoa/nsCocoaUtils.mm b/widget/cocoa/nsCocoaUtils.mm index 3bed04ab1bcd..1e2300c56f63 100644 --- a/widget/cocoa/nsCocoaUtils.mm +++ b/widget/cocoa/nsCocoaUtils.mm @@ -481,16 +481,13 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer *aImage, ui RefPtr drawTarget = gfxPlatform::GetPlatform()-> CreateOffscreenContentDrawTarget(scaledSize, SurfaceFormat::B8G8R8A8); - if (!drawTarget) { - NS_ERROR("Failed to create DrawTarget"); + if (!drawTarget || !drawTarget->IsValid()) { + NS_ERROR("Failed to create valid DrawTarget"); return NS_ERROR_FAILURE; } RefPtr context = gfxContext::CreateOrNull(drawTarget); - if (!context) { - NS_ERROR("Failed to create gfxContext"); - return NS_ERROR_FAILURE; - } + MOZ_ASSERT(context); mozilla::image::DrawResult res = aImage->Draw(context, scaledSize, ImageRegion::Create(scaledSize),