зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1140113 - Catch direct (and some indirect) callers of CreateDrawTarget* and deal with failure. r=mstange
This commit is contained in:
Родитель
56b490ea76
Коммит
76dd5cd892
|
@ -80,6 +80,10 @@ DocumentRendererChild::RenderDocument(nsIDOMWindow *window,
|
|||
IntSize(renderSize.width, renderSize.height),
|
||||
4 * renderSize.width,
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
if (!dt) {
|
||||
gfxWarning() << "DocumentRendererChild::RenderDocument failed to Factory::CreateDrawTargetForData";
|
||||
return false;
|
||||
}
|
||||
nsRefPtr<gfxContext> ctx = new gfxContext(dt);
|
||||
ctx->SetMatrix(mozilla::gfx::ThebesMatrix(transform));
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "2D.h"
|
||||
#include "Filters.h"
|
||||
#include "Logging.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -183,6 +184,11 @@ public:
|
|||
Factory::CreateDrawTargetForData(BackendType::CAIRO, mappedSurf.mData,
|
||||
GetSize(), mappedSurf.mStride, GetFormat());
|
||||
|
||||
if (!dt) {
|
||||
gfxWarning() << "DrawTargetTiled::GetDataSurface failed in CreateDrawTargetForData";
|
||||
surf->Unmap();
|
||||
return nullptr;
|
||||
}
|
||||
for (size_t i = 0; i < mSnapshots.size(); i++) {
|
||||
RefPtr<DataSourceSurface> dataSurf = mSnapshots[i]->GetDataSurface();
|
||||
dt->CopySurface(dataSurf, IntRect(IntPoint(0, 0), mSnapshots[i]->GetSize()), mOrigins[i]);
|
||||
|
|
|
@ -994,6 +994,11 @@ FilterNodeBlendSoftware::Render(const IntRect& aRect)
|
|||
target->Stride(),
|
||||
target->GetFormat());
|
||||
|
||||
if (!dt) {
|
||||
gfxWarning() << "FilterNodeBlendSoftware::Render failed in CreateDrawTargetForData";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Rect r(0, 0, size.width, size.height);
|
||||
dt->DrawSurface(input2, r, r, DrawSurfaceOptions(), DrawOptions(1.0f, ToBlendOp(mBlendMode)));
|
||||
dt->Flush();
|
||||
|
@ -1099,6 +1104,7 @@ FilterNodeTransformSoftware::Render(const IntRect& aRect)
|
|||
mapping.mStride,
|
||||
surf->GetFormat());
|
||||
if (!dt) {
|
||||
gfxWarning() << "FilterNodeTransformSoftware::Render failed in CreateDrawTargetForData";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -225,6 +225,10 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
|
|||
{
|
||||
// We must not keep a reference to the DrawTarget after it has been unlocked.
|
||||
DrawTarget* dt = texture->BorrowDrawTarget();
|
||||
if (!dt) {
|
||||
gfxWarning() << "ImageClientSingle::UpdateImage failed in BorrowDrawTarget";
|
||||
return false;
|
||||
}
|
||||
MOZ_ASSERT(surface.get());
|
||||
dt->CopySurface(surface, IntRect(IntPoint(), surface->GetSize()), IntPoint());
|
||||
}
|
||||
|
|
|
@ -532,7 +532,17 @@ bool TextureClient::CopyToTextureClient(TextureClient* aTarget,
|
|||
}
|
||||
|
||||
RefPtr<DrawTarget> destinationTarget = aTarget->BorrowDrawTarget();
|
||||
if (!destinationTarget) {
|
||||
gfxWarning() << "TextureClient::CopyToTextureClient (dest) failed in BorrowDrawTarget";
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<DrawTarget> sourceTarget = BorrowDrawTarget();
|
||||
if (!sourceTarget) {
|
||||
gfxWarning() << "TextureClient::CopyToTextureClient (src) failed in BorrowDrawTarget";
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<gfx::SourceSurface> source = sourceTarget->Snapshot();
|
||||
destinationTarget->CopySurface(source,
|
||||
aRect ? *aRect : gfx::IntRect(gfx::IntPoint(0, 0), GetSize()),
|
||||
|
|
|
@ -270,11 +270,19 @@ TextureClientD3D11::Lock(OpenMode aMode)
|
|||
|
||||
if (mNeedsClear) {
|
||||
mDrawTarget = BorrowDrawTarget();
|
||||
if (!mDrawTarget) {
|
||||
Unlock();
|
||||
return false;
|
||||
}
|
||||
mDrawTarget->ClearRect(Rect(0, 0, GetSize().width, GetSize().height));
|
||||
mNeedsClear = false;
|
||||
}
|
||||
if (mNeedsClearWhite) {
|
||||
mDrawTarget = BorrowDrawTarget();
|
||||
if (!mDrawTarget) {
|
||||
Unlock();
|
||||
return false;
|
||||
}
|
||||
mDrawTarget->FillRect(Rect(0, 0, GetSize().width, GetSize().height), ColorPattern(Color(1.0, 1.0, 1.0, 1.0)));
|
||||
mNeedsClearWhite = false;
|
||||
}
|
||||
|
|
|
@ -290,17 +290,19 @@ TextureSourceD3D9::SurfaceToTexture(DeviceManagerD3D9* aDeviceManager,
|
|||
reinterpret_cast<unsigned char*>(lockedRect.pBits),
|
||||
aSize, lockedRect.Pitch,
|
||||
gfxPlatform::GetPlatform()->Optimal2DFormatForContent(aSurface->GetContentType()));
|
||||
NativeSurface nativeSurf;
|
||||
nativeSurf.mSize = aSize;
|
||||
nativeSurf.mType = NativeSurfaceType::CAIRO_SURFACE;
|
||||
// We don't know that this is actually the right format, but it's the best
|
||||
// we can get for the content type. In practice this probably always works.
|
||||
nativeSurf.mFormat = dt->GetFormat();
|
||||
nativeSurf.mSurface = aSurface->CairoSurface();
|
||||
|
||||
RefPtr<SourceSurface> surf = dt->CreateSourceSurfaceFromNativeSurface(nativeSurf);
|
||||
if (dt) {
|
||||
NativeSurface nativeSurf;
|
||||
nativeSurf.mSize = aSize;
|
||||
nativeSurf.mType = NativeSurfaceType::CAIRO_SURFACE;
|
||||
// We don't know that this is actually the right format, but it's the best
|
||||
// we can get for the content type. In practice this probably always works.
|
||||
nativeSurf.mFormat = dt->GetFormat();
|
||||
nativeSurf.mSurface = aSurface->CairoSurface();
|
||||
|
||||
dt->CopySurface(surf, IntRect(IntPoint(), aSize), IntPoint());
|
||||
RefPtr<SourceSurface> surf = dt->CreateSourceSurfaceFromNativeSurface(nativeSurf);
|
||||
dt->CopySurface(surf, IntRect(IntPoint(), aSize), IntPoint());
|
||||
}
|
||||
}
|
||||
|
||||
FinishTextures(aDeviceManager, texture, surface);
|
||||
|
@ -618,11 +620,19 @@ CairoTextureClientD3D9::Lock(OpenMode aMode)
|
|||
|
||||
if (mNeedsClear) {
|
||||
mDrawTarget = BorrowDrawTarget();
|
||||
if (!mDrawTarget) {
|
||||
Unlock();
|
||||
return false;
|
||||
}
|
||||
mDrawTarget->ClearRect(Rect(0, 0, GetSize().width, GetSize().height));
|
||||
mNeedsClear = false;
|
||||
}
|
||||
if (mNeedsClearWhite) {
|
||||
mDrawTarget = BorrowDrawTarget();
|
||||
if (!mDrawTarget) {
|
||||
Unlock();
|
||||
return false;
|
||||
}
|
||||
mDrawTarget->FillRect(Rect(0, 0, GetSize().width, GetSize().height), ColorPattern(Color(1.0, 1.0, 1.0, 1.0)));
|
||||
mNeedsClearWhite = false;
|
||||
}
|
||||
|
|
|
@ -1229,9 +1229,10 @@ CompositorOGL::EndFrame()
|
|||
mWidget->GetBounds(rect);
|
||||
}
|
||||
RefPtr<DrawTarget> target = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(IntSize(rect.width, rect.height), SurfaceFormat::B8G8R8A8);
|
||||
CopyToTarget(target, nsIntPoint(), Matrix());
|
||||
|
||||
WriteSnapshotToDumpFile(this, target);
|
||||
if (target) {
|
||||
CopyToTarget(target, nsIntPoint(), Matrix());
|
||||
WriteSnapshotToDumpFile(this, target);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1343,6 +1344,7 @@ CompositorOGL::SetDestinationSurfaceSize(const gfx::IntSize& aSize)
|
|||
void
|
||||
CompositorOGL::CopyToTarget(DrawTarget* aTarget, const nsIntPoint& aTopLeft, const gfx::Matrix& aTransform)
|
||||
{
|
||||
MOZ_ASSERT(aTarget);
|
||||
IntRect rect;
|
||||
if (mUseExternalSurfaceSize) {
|
||||
rect = IntRect(0, 0, mSurfaceSize.width, mSurfaceSize.height);
|
||||
|
|
|
@ -727,6 +727,10 @@ gfxPlatform::CreateDrawTargetForSurface(gfxASurface *aSurface, const IntSize& aS
|
|||
{
|
||||
SurfaceFormat format = Optimal2DFormatForContent(aSurface->GetContentType());
|
||||
RefPtr<DrawTarget> drawTarget = Factory::CreateDrawTargetForCairoSurface(aSurface->CairoSurface(), aSize, &format);
|
||||
if (!drawTarget) {
|
||||
gfxWarning() << "gfxPlatform::CreateDrawTargetForSurface failed in CreateDrawTargetForCairoSurface";
|
||||
return nullptr;
|
||||
}
|
||||
aSurface->SetData(&kDrawTarget, drawTarget, nullptr);
|
||||
return drawTarget.forget();
|
||||
}
|
||||
|
@ -909,6 +913,10 @@ gfxPlatform::GetSourceSurfaceForSurface(DrawTarget *aTarget, gfxASurface *aSurfa
|
|||
surf.mSize = ToIntSize(aSurface->GetSize());
|
||||
RefPtr<DrawTarget> drawTarget =
|
||||
Factory::CreateDrawTarget(BackendType::CAIRO, IntSize(1, 1), format);
|
||||
if (!drawTarget) {
|
||||
gfxWarning() << "gfxPlatform::GetSourceSurfaceForSurface failed in CreateDrawTarget";
|
||||
return nullptr;
|
||||
}
|
||||
srcBuffer = drawTarget->CreateSourceSurfaceFromNativeSurface(surf);
|
||||
if (srcBuffer) {
|
||||
srcBuffer = aTarget->OptimizeSourceSurface(srcBuffer);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "mozilla/Base64.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/DataSurfaceHelpers.h"
|
||||
#include "mozilla/gfx/Logging.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Vector.h"
|
||||
|
@ -1037,6 +1038,11 @@ gfxUtils::CopySurfaceToDataSourceSurfaceWithFormat(SourceSurface* aSurface,
|
|||
// GPU.
|
||||
RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->
|
||||
CreateOffscreenContentDrawTarget(aSurface->GetSize(), aFormat);
|
||||
if (!dt) {
|
||||
gfxWarning() << "gfxUtils::CopySurfaceToDataSourceSurfaceWithFormat failed in CreateOffscreenContentDrawTarget";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Using DrawSurface() here rather than CopySurface() because CopySurface
|
||||
// is optimized for memcpy and therefore isn't good for format conversion.
|
||||
// Using OP_OVER since in our case it's equivalent to OP_SOURCE and
|
||||
|
|
|
@ -184,6 +184,10 @@ DynamicImage::GetFrame(uint32_t aWhichFrame,
|
|||
RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->
|
||||
CreateOffscreenContentDrawTarget(IntSize(size.width, size.height),
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
if (!dt) {
|
||||
gfxWarning() << "DynamicImage::GetFrame failed in CreateOffscreenContentDrawTarget";
|
||||
return nullptr;
|
||||
}
|
||||
nsRefPtr<gfxContext> context = new gfxContext(dt);
|
||||
|
||||
auto result = Draw(context, size, ImageRegion::Create(size),
|
||||
|
|
|
@ -692,6 +692,10 @@ RasterImage::CopyFrame(uint32_t aWhichFrame, uint32_t aFlags)
|
|||
size,
|
||||
mapping.mStride,
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
if (!target) {
|
||||
gfxWarning() << "RasterImage::CopyFrame failed in CreateDrawTargetForData";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsIntRect intFrameRect = frameRef->GetRect();
|
||||
Rect rect(intFrameRect.x, intFrameRect.y,
|
||||
|
|
|
@ -483,6 +483,10 @@ nsresult imgFrame::Optimize()
|
|||
mapping.mStride,
|
||||
optFormat);
|
||||
|
||||
if (!target) {
|
||||
gfxWarning() << "imgFrame::Optimize failed in CreateDrawTargetForData";
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
Rect rect(0, 0, mSize.width, mSize.height);
|
||||
target->DrawSurface(mImageSurface, rect, rect);
|
||||
target->Flush();
|
||||
|
@ -882,6 +886,10 @@ imgFrame::Deoptimize()
|
|||
mSize,
|
||||
mapping.mStride,
|
||||
format);
|
||||
if (!target) {
|
||||
gfxWarning() << "imgFrame::Deoptimize failed in CreateDrawTargetForData";
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
Rect rect(0, 0, mSize.width, mSize.height);
|
||||
if (mSinglePixel)
|
||||
|
|
|
@ -221,6 +221,11 @@ NS_IMETHODIMP imgTools::EncodeScaledImage(imgIContainer *aContainer,
|
|||
dataSurface->GetSize(),
|
||||
map.mStride,
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
if (!dt) {
|
||||
gfxWarning() << "imgTools::EncodeImage failed in CreateDrawTargetForData";
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
dt->DrawSurface(frame,
|
||||
Rect(0, 0, aScaledWidth, aScaledHeight),
|
||||
Rect(0, 0, frameWidth, frameHeight),
|
||||
|
@ -293,6 +298,10 @@ NS_IMETHODIMP imgTools::EncodeCroppedImage(imgIContainer *aContainer,
|
|||
dataSurface->GetSize(),
|
||||
map.mStride,
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
if (!dt) {
|
||||
gfxWarning() << "imgTools::EncodeCroppedImage failed in CreateDrawTargetForData";
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
dt->CopySurface(frame,
|
||||
IntRect(aOffsetX, aOffsetY, aWidth, aHeight),
|
||||
IntPoint(0, 0));
|
||||
|
|
|
@ -2716,9 +2716,11 @@ PaintInactiveLayer(nsDisplayListBuilder* aBuilder,
|
|||
tempDT = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
||||
itemVisibleRect.Size().ToIntSize(),
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
context = new gfxContext(tempDT);
|
||||
context->SetMatrix(gfxMatrix::Translation(-itemVisibleRect.x,
|
||||
-itemVisibleRect.y));
|
||||
if (tempDT) {
|
||||
context = new gfxContext(tempDT);
|
||||
context->SetMatrix(gfxMatrix::Translation(-itemVisibleRect.x,
|
||||
-itemVisibleRect.y));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
basic->BeginTransaction();
|
||||
|
@ -2740,7 +2742,7 @@ PaintInactiveLayer(nsDisplayListBuilder* aBuilder,
|
|||
basic->SetTarget(nullptr);
|
||||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
if (gfxUtils::sDumpPainting) {
|
||||
if (gfxUtils::sDumpPainting && tempDT) {
|
||||
RefPtr<SourceSurface> surface = tempDT->Snapshot();
|
||||
DumpPaintedImage(aItem, surface);
|
||||
|
||||
|
|
|
@ -3460,6 +3460,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
|
|||
gfx::Factory::CreateDrawTargetForCairoCGContext(aContext,
|
||||
gfx::IntSize(backingSize.width,
|
||||
backingSize.height));
|
||||
MOZ_ASSERT(dt); // see implementation
|
||||
dt->AddUserData(&gfxContext::sDontUseAsSourceKey, dt, nullptr);
|
||||
targetContext = new gfxContext(dt);
|
||||
} else if (gfxPlatform::GetPlatform()->SupportsAzureContentForType(gfx::BackendType::CAIRO)) {
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "pixelflinger/format.h"
|
||||
#include "mozilla/BasicEvents.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/Logging.h"
|
||||
#include "mozilla/layers/APZCTreeManager.h"
|
||||
#include "mozilla/layers/APZThreadUtils.h"
|
||||
#include "mozilla/layers/CompositorParent.h"
|
||||
|
@ -704,6 +705,9 @@ nsWindow::StartRemoteDrawing()
|
|||
mFramebufferTarget = Factory::CreateDrawTargetForData(
|
||||
BackendType::CAIRO, (uint8_t*)vaddr,
|
||||
IntSize(width, height), mFramebuffer->stride * bytepp, format);
|
||||
if (!mFramebufferTarget) {
|
||||
MOZ_CRASH("nsWindow::StartRemoteDrawing failed in CreateDrawTargetForData");
|
||||
}
|
||||
if (!mBackBuffer ||
|
||||
mBackBuffer->GetSize() != mFramebufferTarget->GetSize() ||
|
||||
mBackBuffer->GetFormat() != mFramebufferTarget->GetFormat()) {
|
||||
|
|
|
@ -1198,6 +1198,10 @@ AsyncFaviconDataReady::OnComplete(nsIURI *aFaviconURI,
|
|||
dataSurface->GetSize(),
|
||||
map.mStride,
|
||||
dataSurface->GetFormat());
|
||||
if (!dt) {
|
||||
gfxWarning() << "AsyncFaviconDataReady::OnComplete failed in CreateDrawTargetForData";
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
dt->FillRect(Rect(0, 0, size.width, size.height),
|
||||
ColorPattern(Color(1.0f, 1.0f, 1.0f, 1.0f)));
|
||||
dt->DrawSurface(surface,
|
||||
|
|
|
@ -390,6 +390,11 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t aNestingLevel)
|
|||
gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(targetSurface,
|
||||
IntSize(paintRect.right - paintRect.left,
|
||||
paintRect.bottom - paintRect.top));
|
||||
if (!dt) {
|
||||
gfxWarning() << "nsWindow::OnPaint failed in CreateDrawTargetForSurface";
|
||||
return false;
|
||||
}
|
||||
|
||||
// don't need to double buffer with anything but GDI
|
||||
BufferMode doubleBuffering = mozilla::layers::BufferMode::BUFFER_NONE;
|
||||
if (IsRenderMode(gfxWindowsPlatform::RENDER_GDI) ||
|
||||
|
@ -627,6 +632,10 @@ nsresult nsWindowGfx::CreateIcon(imgIContainer *aContainer,
|
|||
dataSurface->GetSize(),
|
||||
map.mStride,
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
if (!dt) {
|
||||
gfxWarning() << "nsWindowGfx::CreatesIcon failed in CreateDrawTargetForData";
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
dt->DrawSurface(surface,
|
||||
Rect(0, 0, iconSize.width, iconSize.height),
|
||||
Rect(0, 0, frameSize.width, frameSize.height),
|
||||
|
|
Загрузка…
Ссылка в новой задаче