From d0ca78d5bed7397a91a138022b072fdb02263b09 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 29 Dec 2015 13:05:50 +0100 Subject: [PATCH] Bug 1176024 - Have TextureClient::Lock check that it can expose a DrawTarget when it makes sense. r=Bas --- gfx/layers/client/TextureClient.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index 3e2646111d61..b8c71290582a 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -363,6 +363,25 @@ TextureClient::Lock(OpenMode aMode) mIsLocked = mData->Lock(aMode, mReleaseFenceHandle.IsValid() ? &mReleaseFenceHandle : nullptr); mOpenMode = aMode; + auto format = GetFormat(); + + if (mIsLocked && CanExposeDrawTarget() && + (aMode & OpenMode::OPEN_WRITE) && + NS_IsMainThread() && + // the formats that we apparently expect, in the cairo backend. Any other + // format will trigger an assertion in GfxFormatToCairoFormat. + (format == SurfaceFormat::A8R8G8B8_UINT32 || + format == SurfaceFormat::X8R8G8B8_UINT32 || + format == SurfaceFormat::A8 || + format == SurfaceFormat::R5G6B5_UINT16)) { + if (!BorrowDrawTarget()) { + // Failed to get a DrawTarget, means we won't be able to write into the + // texture, might as well fail now. + Unlock(); + return false; + } + } + return mIsLocked; }