mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1873866 - RawBuffer now forbids null/size-only. r=gfx-reviewers,ahale
Differential Revision: https://phabricator.services.mozilla.com/D199939
This commit is contained in:
parent
1888a4aae6
commit
1a11536997
@ -3453,9 +3453,7 @@ void ClientWebGLContext::BufferData(GLenum target, WebGLsizeiptr rawSize,
|
||||
EnqueueError(LOCAL_GL_OUT_OF_MEMORY, "`size` too large for platform.");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto data = RawBuffer<>{*size};
|
||||
Run<RPROC(BufferData)>(target, data, usage);
|
||||
Run<RPROC(BufferData_SizeOnly)>(target, *size, usage);
|
||||
}
|
||||
|
||||
void ClientWebGLContext::BufferData(
|
||||
|
@ -482,9 +482,12 @@ class HostWebGLContext final : public SupportsWeakPtr {
|
||||
return GetWebGL2Context()->GetBufferSubData(target, srcByteOffset, dest);
|
||||
}
|
||||
|
||||
void BufferData(GLenum target, const RawBuffer<>& data, GLenum usage) const {
|
||||
const auto& beginOrNull = data.begin();
|
||||
mContext->BufferData(target, data.size(), beginOrNull, usage);
|
||||
void BufferData(GLenum target, const RawBuffer<>& srcData, GLenum usage) const {
|
||||
mContext->BufferData(target, srcData.size(), srcData.begin(), usage);
|
||||
}
|
||||
|
||||
void BufferData_SizeOnly(GLenum target, size_t byteSize, GLenum usage) const {
|
||||
mContext->BufferData(target, byteSize, nullptr, usage);
|
||||
}
|
||||
|
||||
void BufferSubData(GLenum target, uint64_t dstByteOffset,
|
||||
|
@ -102,6 +102,7 @@ DEFINE_ASYNC(HostWebGLContext::BindBuffer)
|
||||
DEFINE_ASYNC(HostWebGLContext::BindBufferRange)
|
||||
DEFINE_ASYNC(HostWebGLContext::CopyBufferSubData)
|
||||
DEFINE_ASYNC(HostWebGLContext::BufferData)
|
||||
DEFINE_ASYNC(HostWebGLContext::BufferData_SizeOnly)
|
||||
DEFINE_ASYNC(HostWebGLContext::BufferSubData)
|
||||
DEFINE_ASYNC(HostWebGLContext::BlitFramebuffer)
|
||||
DEFINE_ASYNC(HostWebGLContext::InvalidateFramebuffer)
|
||||
|
@ -122,15 +122,10 @@ struct QueueParamTraits<RawBuffer<T>> {
|
||||
const auto& elemCount = in.size();
|
||||
auto status = view.WriteParam(elemCount);
|
||||
if (!status) return status;
|
||||
|
||||
if (!elemCount) return status;
|
||||
|
||||
const auto& begin = in.begin();
|
||||
const bool hasData = static_cast<bool>(begin);
|
||||
status = view.WriteParam(hasData);
|
||||
if (!status) return status;
|
||||
if (!hasData) return status;
|
||||
|
||||
status = view.WriteFromRange(in.Data());
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -139,20 +134,12 @@ struct QueueParamTraits<RawBuffer<T>> {
|
||||
size_t elemCount = 0;
|
||||
auto status = view.ReadParam(&elemCount);
|
||||
if (!status) return status;
|
||||
|
||||
if (!elemCount) {
|
||||
*out = {};
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t hasData = 0;
|
||||
status = view.ReadParam(&hasData);
|
||||
if (!status) return status;
|
||||
if (!hasData) {
|
||||
auto temp = RawBuffer<T>{elemCount};
|
||||
*out = std::move(temp);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto data = view.template ReadRange<T>(elemCount);
|
||||
if (!data) return false;
|
||||
*out = std::move(RawBuffer<T>{*data});
|
||||
|
@ -853,33 +853,31 @@ struct VertAttribPointerCalculated final {
|
||||
|
||||
} // namespace webgl
|
||||
|
||||
/**
|
||||
* Represents a block of memory that it may or may not own. The
|
||||
* inner data type must be trivially copyable by memcpy.
|
||||
*/
|
||||
// TODO: s/RawBuffer/Span/
|
||||
template <typename T = uint8_t>
|
||||
class RawBuffer final {
|
||||
const T* mBegin = nullptr;
|
||||
size_t mLen = 0;
|
||||
UniqueBuffer mOwned;
|
||||
|
||||
public:
|
||||
using ElementType = T;
|
||||
|
||||
/**
|
||||
* If aTakeData is true, RawBuffer will delete[] the memory when destroyed.
|
||||
*/
|
||||
explicit RawBuffer(const Range<const T>& data, UniqueBuffer&& owned = {})
|
||||
: mBegin(data.begin().get()),
|
||||
mLen(data.length()),
|
||||
mOwned(std::move(owned)) {}
|
||||
|
||||
explicit RawBuffer(const size_t len) : mLen(len) {}
|
||||
explicit RawBuffer(const Range<const T>& data)
|
||||
: mBegin(data.begin().get()), mLen(data.length()) {
|
||||
if (mLen) {
|
||||
MOZ_ASSERT(mBegin);
|
||||
}
|
||||
}
|
||||
|
||||
~RawBuffer() = default;
|
||||
|
||||
Range<const T> Data() const { return {mBegin, mLen}; }
|
||||
const auto& begin() const { return mBegin; }
|
||||
Range<const T> Data() const { return {begin(), mLen}; }
|
||||
const auto& begin() const {
|
||||
if (mLen) {
|
||||
MOZ_RELEASE_ASSERT(mBegin);
|
||||
}
|
||||
return mBegin;
|
||||
}
|
||||
const auto& size() const { return mLen; }
|
||||
|
||||
void Shrink(const size_t newLen) {
|
||||
|
Loading…
Reference in New Issue
Block a user