Bug 1878930 - s/RawBuffer/Span/: TexImage: Use span, fix dtwebgl callers. r=gfx-reviewers,lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D202027
This commit is contained in:
Kelsey Gilbert
2024-02-20 17:59:08 +00:00
parent 036bbae6bb
commit 15143f68a7
4 changed files with 15 additions and 19 deletions

View File

@@ -4142,7 +4142,8 @@ void webgl::TexUnpackBlobDesc::Shrink(const webgl::PackingInfo& pi) {
CheckedInt<size_t>(unpack.metrics.bytesPerRowStride) * CheckedInt<size_t>(unpack.metrics.bytesPerRowStride) *
unpack.metrics.totalRows; unpack.metrics.totalRows;
if (bytesUpperBound.isValid()) { if (bytesUpperBound.isValid()) {
cpuData->Shrink(bytesUpperBound.value()); auto& span = *cpuData;
span = span.subspan(0, std::min(span.size(), bytesUpperBound.value()));
} }
} }
} }
@@ -4218,7 +4219,7 @@ void ClientWebGLContext::TexImage(uint8_t funcDims, GLenum imageTarget,
return Some(webgl::TexUnpackBlobDesc{imageTarget, return Some(webgl::TexUnpackBlobDesc{imageTarget,
size.value(), size.value(),
gfxAlphaType::NonPremult, gfxAlphaType::NonPremult,
Some(RawBuffer<>{*range}), Some(*range),
{}}); {}});
}); });
} }

View File

@@ -621,13 +621,13 @@ bool SharedContextWebgl::SetNoClipMask() {
} }
mWebgl->ActiveTexture(1); mWebgl->ActiveTexture(1);
mWebgl->BindTexture(LOCAL_GL_TEXTURE_2D, mNoClipMask); mWebgl->BindTexture(LOCAL_GL_TEXTURE_2D, mNoClipMask);
static const uint8_t solidMask[4] = {0xFF, 0xFF, 0xFF, 0xFF}; static const auto solidMask = std::array<const uint8_t, 4>{0xFF, 0xFF, 0xFF, 0xFF};
mWebgl->TexImage( mWebgl->TexImage(0, LOCAL_GL_RGBA8, {0, 0, 0},
0, LOCAL_GL_RGBA8, {0, 0, 0}, {LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE}, {LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE},
{LOCAL_GL_TEXTURE_2D, {LOCAL_GL_TEXTURE_2D,
{1, 1, 1}, {1, 1, 1},
gfxAlphaType::NonPremult, gfxAlphaType::NonPremult,
Some(RawBuffer(Range<const uint8_t>(solidMask, sizeof(solidMask))))}); Some(Span{solidMask})});
InitTexParameters(mNoClipMask, false); InitTexParameters(mNoClipMask, false);
mWebgl->ActiveTexture(0); mWebgl->ActiveTexture(0);
mLastClipMask = mNoClipMask; mLastClipMask = mNoClipMask;
@@ -1916,11 +1916,11 @@ bool SharedContextWebgl::UploadSurface(DataSourceSurface* aData,
int32_t bpp = BytesPerPixel(aFormat); int32_t bpp = BytesPerPixel(aFormat);
// Get the data pointer range considering the sampling rect offset and // Get the data pointer range considering the sampling rect offset and
// size. // size.
Range<const uint8_t> range( Span<const uint8_t> range(
map.GetData() + aSrcRect.y * size_t(stride) + aSrcRect.x * bpp, map.GetData() + aSrcRect.y * size_t(stride) + aSrcRect.x * bpp,
std::max(aSrcRect.height - 1, 0) * size_t(stride) + std::max(aSrcRect.height - 1, 0) * size_t(stride) +
aSrcRect.width * bpp); aSrcRect.width * bpp);
texDesc.cpuData = Some(RawBuffer(range)); texDesc.cpuData = Some(range);
// If the stride happens to be 4 byte aligned, assume that is the // If the stride happens to be 4 byte aligned, assume that is the
// desired alignment regardless of format (even A8). Otherwise, we // desired alignment regardless of format (even A8). Otherwise, we
// default to byte alignment. // default to byte alignment.

View File

@@ -476,8 +476,7 @@ bool TexUnpackBytes::Validate(const WebGLContext* const webgl,
CheckedInt<size_t> availBytes = 0; CheckedInt<size_t> availBytes = 0;
if (mDesc.cpuData) { if (mDesc.cpuData) {
const auto& range = mDesc.cpuData->Data(); availBytes = mDesc.cpuData->size();
availBytes = range.length();
} else if (mDesc.pboOffset) { } else if (mDesc.pboOffset) {
const auto& pboOffset = *mDesc.pboOffset; const auto& pboOffset = *mDesc.pboOffset;
@@ -514,11 +513,7 @@ bool TexUnpackBytes::TexOrSubImage(bool isSubImage, bool needsRespec,
const uint8_t* uploadPtr = nullptr; const uint8_t* uploadPtr = nullptr;
if (mDesc.cpuData) { if (mDesc.cpuData) {
const auto range = mDesc.cpuData->Data(); uploadPtr = mDesc.cpuData->data();
uploadPtr = range.begin().get();
if (!uploadPtr) {
MOZ_ASSERT(!range.length());
}
} else if (mDesc.pboOffset) { } else if (mDesc.pboOffset) {
uploadPtr = reinterpret_cast<const uint8_t*>(*mDesc.pboOffset); uploadPtr = reinterpret_cast<const uint8_t*>(*mDesc.pboOffset);
} }

View File

@@ -1097,7 +1097,7 @@ struct TexUnpackBlobDesc final {
uvec3 size; uvec3 size;
gfxAlphaType srcAlphaType = gfxAlphaType::NonPremult; gfxAlphaType srcAlphaType = gfxAlphaType::NonPremult;
Maybe<RawBuffer<>> cpuData; Maybe<Span<const uint8_t>> cpuData;
Maybe<uint64_t> pboOffset; Maybe<uint64_t> pboOffset;
Maybe<uvec2> structuredSrcSize; Maybe<uvec2> structuredSrcSize;