Bug 1506665 - Add more GLContext failure handling r=jgilbert

Differential Revision: https://phabricator.services.mozilla.com/D19623

--HG--
extra : moz-landing-system : lando
This commit is contained in:
sotaro 2019-03-01 22:37:37 +00:00
Родитель 17dc68fa03
Коммит 055881c3c0
5 изменённых файлов: 30 добавлений и 31 удалений

Просмотреть файл

@ -1150,6 +1150,11 @@ already_AddRefed<layers::Layer> WebGLContext::GetCanvasLayer(
CanvasRenderer* canvasRenderer = canvasLayer->CreateOrGetCanvasRenderer();
if (!InitializeCanvasRenderer(builder, canvasRenderer)) return nullptr;
if (!gl) {
NS_WARNING("GLContext is null!");
return nullptr;
}
uint32_t flags = gl->Caps().alpha ? 0 : Layer::CONTENT_OPAQUE;
canvasLayer->SetContentFlags(flags);
@ -1203,10 +1208,10 @@ bool WebGLContext::InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
data.mDidTransCallbackData = this;
}
data.mGLContext = gl;
data.mSize = DrawingBufferSize();
data.mHasAlpha = mOptions.alpha;
data.mIsGLAlphaPremult = IsPremultAlpha() || !data.mHasAlpha;
data.mGLContext = gl;
aRenderer->Initialize(data);
aRenderer->SetDirty();

Просмотреть файл

@ -9,6 +9,9 @@
namespace mozilla {
namespace layers {
CanvasInitializeData::CanvasInitializeData() = default;
CanvasInitializeData::~CanvasInitializeData() = default;
CanvasRenderer::CanvasRenderer()
: mPreTransCallback(nullptr),
mPreTransCallbackData(nullptr),

Просмотреть файл

@ -28,39 +28,30 @@ class CopyableCanvasRenderer;
class PersistentBufferProvider;
class WebRenderCanvasRendererAsync;
struct CanvasInitializeData {
CanvasInitializeData()
: mBufferProvider(nullptr),
mGLContext(nullptr),
mRenderer(nullptr),
mPreTransCallback(nullptr),
mPreTransCallbackData(nullptr),
mDidTransCallback(nullptr),
mDidTransCallbackData(nullptr),
mSize(0, 0),
mHasAlpha(false),
mIsGLAlphaPremult(true) {}
struct CanvasInitializeData final {
CanvasInitializeData();
~CanvasInitializeData();
// One of these three must be specified for Canvas2D, but never more than one
PersistentBufferProvider*
RefPtr<PersistentBufferProvider>
mBufferProvider; // A BufferProvider for the Canvas contents
mozilla::gl::GLContext* mGLContext; // or this, for GL.
AsyncCanvasRenderer* mRenderer; // or this, for OffscreenCanvas
RefPtr<mozilla::gl::GLContext> mGLContext; // or this, for GL.
RefPtr<AsyncCanvasRenderer> mRenderer; // or this, for OffscreenCanvas
typedef void (*TransactionCallback)(void* closureData);
TransactionCallback mPreTransCallback;
void* mPreTransCallbackData;
TransactionCallback mDidTransCallback;
void* mDidTransCallbackData;
TransactionCallback mPreTransCallback = nullptr;
void* mPreTransCallbackData = nullptr;
TransactionCallback mDidTransCallback = nullptr;
void* mDidTransCallbackData = nullptr;
// The size of the canvas content
gfx::IntSize mSize;
gfx::IntSize mSize = {0,0};
// Whether the canvas drawingbuffer has an alpha channel.
bool mHasAlpha;
bool mHasAlpha = false;
// Whether mGLContext contains data that is alpha-premultiplied.
bool mIsGLAlphaPremult;
bool mIsGLAlphaPremult = true;
};
// Based class which used for canvas rendering. There are many derived classes

Просмотреть файл

@ -53,6 +53,9 @@ void CopyableCanvasRenderer::Initialize(const CanvasInitializeData& aData) {
CanvasRenderer::Initialize(aData);
if (aData.mGLContext) {
if (aData.mGLContext->IsDestroyed()) {
return;
}
mGLContext = aData.mGLContext;
mIsAlphaPremultiplied = aData.mIsGLAlphaPremult;
mOriginPos = gl::OriginPos::BottomLeft;
@ -64,10 +67,6 @@ void CopyableCanvasRenderer::Initialize(const CanvasInitializeData& aData) {
} else if (aData.mRenderer) {
mAsyncRenderer = aData.mRenderer;
mOriginPos = gl::OriginPos::BottomLeft;
} else {
MOZ_CRASH(
"GFX: CanvasRenderer created without BufferProvider, DrawTarget or "
"GLContext?");
}
mOpaque = !aData.mHasAlpha;

Просмотреть файл

@ -295,8 +295,10 @@ static already_AddRefed<TextureClient> TexClientFromReadback(
MOZ_CRASH("GFX: Bad `read{Format,Type}`.");
}
MOZ_ASSERT(texClient);
if (!texClient) return nullptr;
if (!texClient) {
gfxWarning() << "Couldn't create texClient for readback.";
return nullptr;
}
// With a texClient, we can lock for writing.
TextureClientAutoLock autoLock(texClient, OpenMode::OPEN_WRITE);
@ -455,10 +457,9 @@ void CanvasClientSharedSurface::UpdateRenderer(gfx::IntSize aSize,
asyncRenderer->CopyFromTextureClient(mReadbackClient);
}
MOZ_ASSERT(newFront);
if (!newFront) {
// May happen in a release build in case of memory pressure.
gfxCriticalError()
gfxWarning()
<< "Failed to allocate a TextureClient for SharedSurface Canvas. Size: "
<< aSize;
return;