Commit 1a035880 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[webgl] Handle trivial case in GLES2Implementation::ReadPixels

ReadPixels required the {pixels} parameter not to be nullptr, even when
it pointed into an ArrayBuffer of size 0. This requires the ArrayBuffer
implementation to allocate a backing store of size 0 instead of just
keeping a nullptr.

With this CL we handle the trivial case (width == 0 or height == 0) in
the beginning as a no-op, so that nullptr as backing store is okay.

Bug: chromium:1008840
Change-Id: If7337bf2bb625e4f8addb0d346c5db276b555695
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893059Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712999}
parent bfda5c0c
......@@ -139,7 +139,7 @@ scoped_refptr<ArrayBuffer> ArrayBuffer::Create(const void* source,
}
scoped_refptr<ArrayBuffer> ArrayBuffer::Create(ArrayBufferContents& contents) {
CHECK(contents.DataMaybeShared());
CHECK(contents.DataLength() == 0 || contents.DataMaybeShared());
return base::AdoptRef(new ArrayBuffer(contents));
}
......
......@@ -4446,8 +4446,21 @@ void WebGLRenderingContextBase::ReadPixelsHelper(GLint x,
return;
}
ClearIfComposited();
uint8_t* data = static_cast<uint8_t*>(pixels->BaseAddressMaybeShared()) +
offset_in_bytes.ValueOrDie();
// We add special handling here if the 'ArrayBufferView' is size '0' and the
// backing store is 'nullptr'. 'ReadPixels' creates an error if the provided
// data is 'nullptr'. However, in the case that we want to read zero pixels,
// we want to avoid this error. Therefore we provide temporary memory here if
// 'ArrayBufferView' does not provide a backing store but we actually read
// zero pixels.
base::Optional<Vector<uint8_t>> buffer;
if (!data && (width == 0 || height == 0)) {
buffer.emplace(32);
data = buffer->data();
}
{
ScopedDrawingBufferBinder binder(GetDrawingBuffer(), framebuffer);
ContextGL()->ReadPixels(x, y, width, height, format, type, data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment