зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
17dc68fa03
Коммит
055881c3c0
|
@ -1150,6 +1150,11 @@ already_AddRefed<layers::Layer> WebGLContext::GetCanvasLayer(
|
||||||
CanvasRenderer* canvasRenderer = canvasLayer->CreateOrGetCanvasRenderer();
|
CanvasRenderer* canvasRenderer = canvasLayer->CreateOrGetCanvasRenderer();
|
||||||
if (!InitializeCanvasRenderer(builder, canvasRenderer)) return nullptr;
|
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;
|
uint32_t flags = gl->Caps().alpha ? 0 : Layer::CONTENT_OPAQUE;
|
||||||
canvasLayer->SetContentFlags(flags);
|
canvasLayer->SetContentFlags(flags);
|
||||||
|
|
||||||
|
@ -1203,10 +1208,10 @@ bool WebGLContext::InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder,
|
||||||
data.mDidTransCallbackData = this;
|
data.mDidTransCallbackData = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.mGLContext = gl;
|
|
||||||
data.mSize = DrawingBufferSize();
|
data.mSize = DrawingBufferSize();
|
||||||
data.mHasAlpha = mOptions.alpha;
|
data.mHasAlpha = mOptions.alpha;
|
||||||
data.mIsGLAlphaPremult = IsPremultAlpha() || !data.mHasAlpha;
|
data.mIsGLAlphaPremult = IsPremultAlpha() || !data.mHasAlpha;
|
||||||
|
data.mGLContext = gl;
|
||||||
|
|
||||||
aRenderer->Initialize(data);
|
aRenderer->Initialize(data);
|
||||||
aRenderer->SetDirty();
|
aRenderer->SetDirty();
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace layers {
|
namespace layers {
|
||||||
|
|
||||||
|
CanvasInitializeData::CanvasInitializeData() = default;
|
||||||
|
CanvasInitializeData::~CanvasInitializeData() = default;
|
||||||
|
|
||||||
CanvasRenderer::CanvasRenderer()
|
CanvasRenderer::CanvasRenderer()
|
||||||
: mPreTransCallback(nullptr),
|
: mPreTransCallback(nullptr),
|
||||||
mPreTransCallbackData(nullptr),
|
mPreTransCallbackData(nullptr),
|
||||||
|
|
|
@ -28,39 +28,30 @@ class CopyableCanvasRenderer;
|
||||||
class PersistentBufferProvider;
|
class PersistentBufferProvider;
|
||||||
class WebRenderCanvasRendererAsync;
|
class WebRenderCanvasRendererAsync;
|
||||||
|
|
||||||
struct CanvasInitializeData {
|
struct CanvasInitializeData final {
|
||||||
CanvasInitializeData()
|
CanvasInitializeData();
|
||||||
: mBufferProvider(nullptr),
|
~CanvasInitializeData();
|
||||||
mGLContext(nullptr),
|
|
||||||
mRenderer(nullptr),
|
|
||||||
mPreTransCallback(nullptr),
|
|
||||||
mPreTransCallbackData(nullptr),
|
|
||||||
mDidTransCallback(nullptr),
|
|
||||||
mDidTransCallbackData(nullptr),
|
|
||||||
mSize(0, 0),
|
|
||||||
mHasAlpha(false),
|
|
||||||
mIsGLAlphaPremult(true) {}
|
|
||||||
|
|
||||||
// One of these three must be specified for Canvas2D, but never more than one
|
// One of these three must be specified for Canvas2D, but never more than one
|
||||||
PersistentBufferProvider*
|
RefPtr<PersistentBufferProvider>
|
||||||
mBufferProvider; // A BufferProvider for the Canvas contents
|
mBufferProvider; // A BufferProvider for the Canvas contents
|
||||||
mozilla::gl::GLContext* mGLContext; // or this, for GL.
|
RefPtr<mozilla::gl::GLContext> mGLContext; // or this, for GL.
|
||||||
AsyncCanvasRenderer* mRenderer; // or this, for OffscreenCanvas
|
RefPtr<AsyncCanvasRenderer> mRenderer; // or this, for OffscreenCanvas
|
||||||
|
|
||||||
typedef void (*TransactionCallback)(void* closureData);
|
typedef void (*TransactionCallback)(void* closureData);
|
||||||
TransactionCallback mPreTransCallback;
|
TransactionCallback mPreTransCallback = nullptr;
|
||||||
void* mPreTransCallbackData;
|
void* mPreTransCallbackData = nullptr;
|
||||||
TransactionCallback mDidTransCallback;
|
TransactionCallback mDidTransCallback = nullptr;
|
||||||
void* mDidTransCallbackData;
|
void* mDidTransCallbackData = nullptr;
|
||||||
|
|
||||||
// The size of the canvas content
|
// The size of the canvas content
|
||||||
gfx::IntSize mSize;
|
gfx::IntSize mSize = {0,0};
|
||||||
|
|
||||||
// Whether the canvas drawingbuffer has an alpha channel.
|
// Whether the canvas drawingbuffer has an alpha channel.
|
||||||
bool mHasAlpha;
|
bool mHasAlpha = false;
|
||||||
|
|
||||||
// Whether mGLContext contains data that is alpha-premultiplied.
|
// 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
|
// 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);
|
CanvasRenderer::Initialize(aData);
|
||||||
|
|
||||||
if (aData.mGLContext) {
|
if (aData.mGLContext) {
|
||||||
|
if (aData.mGLContext->IsDestroyed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mGLContext = aData.mGLContext;
|
mGLContext = aData.mGLContext;
|
||||||
mIsAlphaPremultiplied = aData.mIsGLAlphaPremult;
|
mIsAlphaPremultiplied = aData.mIsGLAlphaPremult;
|
||||||
mOriginPos = gl::OriginPos::BottomLeft;
|
mOriginPos = gl::OriginPos::BottomLeft;
|
||||||
|
@ -64,10 +67,6 @@ void CopyableCanvasRenderer::Initialize(const CanvasInitializeData& aData) {
|
||||||
} else if (aData.mRenderer) {
|
} else if (aData.mRenderer) {
|
||||||
mAsyncRenderer = aData.mRenderer;
|
mAsyncRenderer = aData.mRenderer;
|
||||||
mOriginPos = gl::OriginPos::BottomLeft;
|
mOriginPos = gl::OriginPos::BottomLeft;
|
||||||
} else {
|
|
||||||
MOZ_CRASH(
|
|
||||||
"GFX: CanvasRenderer created without BufferProvider, DrawTarget or "
|
|
||||||
"GLContext?");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mOpaque = !aData.mHasAlpha;
|
mOpaque = !aData.mHasAlpha;
|
||||||
|
|
|
@ -295,8 +295,10 @@ static already_AddRefed<TextureClient> TexClientFromReadback(
|
||||||
MOZ_CRASH("GFX: Bad `read{Format,Type}`.");
|
MOZ_CRASH("GFX: Bad `read{Format,Type}`.");
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_ASSERT(texClient);
|
if (!texClient) {
|
||||||
if (!texClient) return nullptr;
|
gfxWarning() << "Couldn't create texClient for readback.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// With a texClient, we can lock for writing.
|
// With a texClient, we can lock for writing.
|
||||||
TextureClientAutoLock autoLock(texClient, OpenMode::OPEN_WRITE);
|
TextureClientAutoLock autoLock(texClient, OpenMode::OPEN_WRITE);
|
||||||
|
@ -455,10 +457,9 @@ void CanvasClientSharedSurface::UpdateRenderer(gfx::IntSize aSize,
|
||||||
asyncRenderer->CopyFromTextureClient(mReadbackClient);
|
asyncRenderer->CopyFromTextureClient(mReadbackClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_ASSERT(newFront);
|
|
||||||
if (!newFront) {
|
if (!newFront) {
|
||||||
// May happen in a release build in case of memory pressure.
|
// May happen in a release build in case of memory pressure.
|
||||||
gfxCriticalError()
|
gfxWarning()
|
||||||
<< "Failed to allocate a TextureClient for SharedSurface Canvas. Size: "
|
<< "Failed to allocate a TextureClient for SharedSurface Canvas. Size: "
|
||||||
<< aSize;
|
<< aSize;
|
||||||
return;
|
return;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче