Return a span for WriteHandle Source Builds on the previous changes to WriteHandle to support bounds checking and updates the public method to return a span instead of a separate data/size. The data/size methods are still present, though now private, because that's the only way we can properly overload them from Chromium. Bug: 487522152 Change-Id: If276cf5961a33102673b37388ea31612d0010005 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/296376 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Auto-Submit: Brandon Jones <bajones@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/include/dawn/wire/WireServer.h b/include/dawn/wire/WireServer.h index ef3b31d..e0513ee 100644 --- a/include/dawn/wire/WireServer.h +++ b/include/dawn/wire/WireServer.h
@@ -140,16 +140,20 @@ size_t size) = 0; std::span<uint8_t> GetTarget() const; + std::span<uint8_t> GetSource() const { + return std::span<uint8_t>(GetSourceData(), GetSourceSize()); + } + + private: + WriteHandle(const WriteHandle&) = delete; + WriteHandle& operator=(const WriteHandle&) = delete; + // Returns a direct pointer to the source data that will // be copied into Target in DeserializeDataUpdate if accessible, nullptr // otherwise. virtual uint8_t* GetSourceData() const { return nullptr; } virtual size_t GetSourceSize() const { return 0; } - private: - WriteHandle(const WriteHandle&) = delete; - WriteHandle& operator=(const WriteHandle&) = delete; - uint8_t* mTargetData = nullptr; size_t mDataLength = 0; };
diff --git a/src/dawn/wire/server/ServerQueue.cpp b/src/dawn/wire/server/ServerQueue.cpp index cf45a39..2d355f7 100644 --- a/src/dawn/wire/server/ServerQueue.cpp +++ b/src/dawn/wire/server/ServerQueue.cpp
@@ -98,7 +98,7 @@ // Try first to use GetSourceData if the memory transfer service implements // it. If so, we can avoid a copy. - std::span<uint8_t> source(writeHandle->GetSourceData(), writeHandle->GetSourceSize()); + std::span<uint8_t> source = writeHandle->GetSource(); if (!source.empty()) { if (source.size() < size) { return WireResult::FatalError; @@ -171,7 +171,7 @@ // Try first to use GetSourceData if the memory transfer service implements // it. If so, we can avoid a copy. - std::span<uint8_t> source(writeHandle->GetSourceData(), writeHandle->GetSourceSize()); + std::span<uint8_t> source = writeHandle->GetSource(); if (!source.empty()) { if (source.size() < dataSize) { return WireResult::FatalError;