diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /dom/canvas/TexUnpackBlob.cpp | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-upstream/125.0.1.tar.xz firefox-upstream/125.0.1.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/canvas/TexUnpackBlob.cpp')
-rw-r--r-- | dom/canvas/TexUnpackBlob.cpp | 87 |
1 files changed, 63 insertions, 24 deletions
diff --git a/dom/canvas/TexUnpackBlob.cpp b/dom/canvas/TexUnpackBlob.cpp index 8598c36227..e13dc1c064 100644 --- a/dom/canvas/TexUnpackBlob.cpp +++ b/dom/canvas/TexUnpackBlob.cpp @@ -476,8 +476,7 @@ bool TexUnpackBytes::Validate(const WebGLContext* const webgl, CheckedInt<size_t> availBytes = 0; if (mDesc.cpuData) { - const auto& range = mDesc.cpuData->Data(); - availBytes = range.length(); + availBytes = mDesc.cpuData->size(); } else if (mDesc.pboOffset) { const auto& pboOffset = *mDesc.pboOffset; @@ -514,11 +513,7 @@ bool TexUnpackBytes::TexOrSubImage(bool isSubImage, bool needsRespec, const uint8_t* uploadPtr = nullptr; if (mDesc.cpuData) { - const auto range = mDesc.cpuData->Data(); - uploadPtr = range.begin().get(); - if (!uploadPtr) { - MOZ_ASSERT(!range.length()); - } + uploadPtr = mDesc.cpuData->data(); } else if (mDesc.pboOffset) { uploadPtr = reinterpret_cast<const uint8_t*>(*mDesc.pboOffset); } @@ -673,11 +668,10 @@ bool TexUnpackImage::Validate(const WebGLContext* const webgl, return ValidateUnpackPixels(webgl, pi, fullRows, *this); } -Maybe<std::string> BlitPreventReason(const int32_t level, const ivec3& offset, - const GLenum internalFormat, - const webgl::PackingInfo& pi, - const TexUnpackBlobDesc& desc, - const bool isRgb8Renderable) { +Maybe<std::string> BlitPreventReason( + const int32_t level, const ivec3& offset, const GLenum internalFormat, + const webgl::PackingInfo& pi, const TexUnpackBlobDesc& desc, + const OptionalRenderableFormatBits optionalRenderableFormatBits) { const auto& size = desc.size; const auto& unpacking = desc.unpacking; @@ -710,26 +704,71 @@ Maybe<std::string> BlitPreventReason(const int32_t level, const ivec3& offset, const auto formatReason = [&]() -> const char* { if (pi.type != LOCAL_GL_UNSIGNED_BYTE) { - return "`type` must be `UNSIGNED_BYTE`"; + return "`unpackType` must be `UNSIGNED_BYTE`"; } - switch (internalFormat) { + switch (pi.format) { case LOCAL_GL_RGBA: - case LOCAL_GL_RGBA8: - return nullptr; + return nullptr; // All internalFormats for unpackFormat=RGBA are + // renderable. case LOCAL_GL_RGB: + break; + + default: + return "`unpackFormat` must be `RGBA` or maybe `RGB`"; + } + + // - + + struct { + OptionalRenderableFormatBits bits; + const char* errorMsg; + } required; + + switch (internalFormat) { + case LOCAL_GL_RGB565: + return nullptr; + case LOCAL_GL_RGB: case LOCAL_GL_RGB8: - if (isRgb8Renderable) { - return nullptr; - } + required = { + OptionalRenderableFormatBits::RGB8, + "Unavailable, as blitting internalFormats RGB or RGB8 requires " + "that RGB8 must be a renderable format.", + }; + break; + case LOCAL_GL_SRGB: + case LOCAL_GL_SRGB8: + required = { + OptionalRenderableFormatBits::SRGB8, + "Unavailable, as blitting internalFormats SRGB or SRGB8 requires " + "that SRGB8 must be a renderable format.", + }; + break; + case 0: + // texSubImage, so internalFormat is unknown, and could be anything! + required = { + OptionalRenderableFormatBits::RGB8 | + OptionalRenderableFormatBits::SRGB8, + "Unavailable, as blitting texSubImage with unpackFormat=RGB " + "requires that RGB8 and SRGB8 must be renderable formats.", + }; break; + default: + gfxCriticalError() + << "Unexpected internalFormat for unpackFormat=RGB: 0x" + << gfx::hexa(internalFormat); + return "Unexpected internalFormat for unpackFormat=RGB"; } - if (isRgb8Renderable) { - return "effective format must be RGB8 or RGBA8"; - } else { - return "effective format must be RGBA8"; + + const auto availableBits = optionalRenderableFormatBits; + if ((required.bits | availableBits) != availableBits) { + return required.errorMsg; } + + // - + + return nullptr; }(); if (formatReason) return formatReason; @@ -761,7 +800,7 @@ bool TexUnpackImage::TexOrSubImage(bool isSubImage, bool needsRespec, const auto reason = BlitPreventReason(level, {xOffset, yOffset, zOffset}, dui->internalFormat, - pi, mDesc, webgl->mIsRgb8Renderable); + pi, mDesc, webgl->mOptionalRenderableFormatBits); if (reason) { webgl->GeneratePerfWarning( "Failed to hit GPU-copy fast-path." |