Bug 1743847 - Throw an exception in WebGPU GetCurrentTexture r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D133143
This commit is contained in:
Dzmitry Malyshau 2021-12-08 15:06:54 +00:00
parent ed77e7c029
commit 7f7df83147
5 changed files with 15 additions and 4 deletions

View File

@ -61,11 +61,14 @@ bool CanvasContext::UpdateWebRenderCanvasData(
void CanvasContext::Configure(const dom::GPUCanvasConfiguration& aDesc) {
Unconfigure();
// these formats are guaranteed by the spec
switch (aDesc.mFormat) {
case dom::GPUTextureFormat::Rgba8unorm:
case dom::GPUTextureFormat::Rgba8unorm_srgb:
mGfxFormat = gfx::SurfaceFormat::R8G8B8A8;
break;
case dom::GPUTextureFormat::Bgra8unorm:
case dom::GPUTextureFormat::Bgra8unorm_srgb:
mGfxFormat = gfx::SurfaceFormat::B8G8R8A8;
break;
default:
@ -102,13 +105,20 @@ void CanvasContext::Unconfigure() {
}
mBridge = nullptr;
mTexture = nullptr;
mGfxFormat = gfx::SurfaceFormat::UNKNOWN;
}
dom::GPUTextureFormat CanvasContext::GetPreferredFormat(Adapter&) const {
return dom::GPUTextureFormat::Bgra8unorm;
}
RefPtr<Texture> CanvasContext::GetCurrentTexture() { return mTexture; }
RefPtr<Texture> CanvasContext::GetCurrentTexture(ErrorResult& aRv) {
if (!mTexture) {
aRv.ThrowOperationError("Canvas not configured");
return nullptr;
}
return mTexture;
}
bool CanvasContext::UpdateWebRenderLocalCanvasData(
layers::WebRenderLocalCanvasData* aCanvasData) {

View File

@ -98,7 +98,7 @@ class CanvasContext final : public nsICanvasRenderingContextInternal,
void Unconfigure();
dom::GPUTextureFormat GetPreferredFormat(Adapter& aAdapter) const;
RefPtr<Texture> GetCurrentTexture();
RefPtr<Texture> GetCurrentTexture(ErrorResult& aRv);
private:
uint32_t mWidth = 0, mHeight = 0;

View File

@ -246,8 +246,8 @@ already_AddRefed<Texture> Device::InitSwapChain(
} else {
MOZ_CRASH("Unexpected union");
}
*aCanvasSize = size;
}
*aCanvasSize = size;
const layers::RGBDescriptor rgbDesc(size, aFormat);
// buffer count doesn't matter much, will be created on demand

View File

@ -20,7 +20,7 @@ static mozilla::LazyLogModule sLogger("WebGPU");
// TODO: refactor this to avoid stack-allocating the buffer all the time.
class ErrorBuffer {
// if the message doesn't fit, it will be truncated
static constexpr unsigned BUFFER_SIZE = 256;
static constexpr unsigned BUFFER_SIZE = 512;
char mUtf8[BUFFER_SIZE] = {};
bool mGuard = false;

View File

@ -1171,5 +1171,6 @@ interface GPUCanvasContext {
void unconfigure();
GPUTextureFormat getPreferredFormat(GPUAdapter adapter);
[Throws]
GPUTexture getCurrentTexture();
};