Add placeholder virtual functions to dawn_wire Read/WriteHandle

Updated interface design is at
https://bugs.chromium.org/p/dawn/issues/detail?id=773#c21

Prelanding CL to avoid breaking change.
The proposed usage is at
https://dawn-review.googlesource.com/c/dawn/+/51164

Bug: dawn:773
Change-Id: If27396e60574b4a52fcda60e111bad33c9d63563
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/54140
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shrek Shao <shrekshao@google.com>
diff --git a/src/dawn_wire/WireClient.cpp b/src/dawn_wire/WireClient.cpp
index aa83013..01ab45b 100644
--- a/src/dawn_wire/WireClient.cpp
+++ b/src/dawn_wire/WireClient.cpp
@@ -62,16 +62,6 @@
 
         MemoryTransferService::~MemoryTransferService() = default;
 
-        MemoryTransferService::ReadHandle*
-        MemoryTransferService::CreateReadHandle(WGPUBuffer buffer, uint64_t offset, size_t size) {
-            return CreateReadHandle(size);
-        }
-
-        MemoryTransferService::WriteHandle*
-        MemoryTransferService::CreateWriteHandle(WGPUBuffer buffer, uint64_t offset, size_t size) {
-            return CreateWriteHandle(size);
-        }
-
         MemoryTransferService::ReadHandle::ReadHandle() = default;
 
         MemoryTransferService::ReadHandle::~ReadHandle() = default;
diff --git a/src/include/dawn_wire/WireClient.h b/src/include/dawn_wire/WireClient.h
index 87f2bab..e633dc5 100644
--- a/src/include/dawn_wire/WireClient.h
+++ b/src/include/dawn_wire/WireClient.h
@@ -98,12 +98,6 @@
             // This may fail and return nullptr.
             virtual WriteHandle* CreateWriteHandle(size_t) = 0;
 
-            // Imported memory implementation needs to override these to create Read/Write
-            // handles associated with a particular buffer. The client should receive a file
-            // descriptor for the buffer out-of-band.
-            virtual ReadHandle* CreateReadHandle(WGPUBuffer, uint64_t offset, size_t size);
-            virtual WriteHandle* CreateWriteHandle(WGPUBuffer, uint64_t offset, size_t size);
-
             class DAWN_WIRE_EXPORT ReadHandle {
               public:
                 ReadHandle();
@@ -115,16 +109,33 @@
                 // Serialize the handle into |serializePointer| so it can be received by the server.
                 virtual void SerializeCreate(void* serializePointer) = 0;
 
-                // Load initial data and open the handle for reading.
-                // This function takes in the serialized result of
-                // server::MemoryTransferService::ReadHandle::SerializeInitialData.
-                // This function should write to |data| and |dataLength| the pointer and size of the
-                // mapped data for reading. It must live at least until the ReadHandle is
-                // destructed.
+                // Simply return the base address of the allocation (without applying any offset)
+                // Returns nullptr if the allocation failed.
+                // The data must live at least until the ReadHandle is destructued
+                // TODO(dawn:773): change to pure virtual after update on chromium side.
+                virtual const void* GetData() {
+                    return nullptr;
+                }
+
+                // Gets called when a MapReadCallback resolves.
+                // deserialize the data update and apply
+                // it to the range (offset, offset + size) of allocation
+                // There could be nothing to be deserialized (if using shared memory)
+                // TODO(dawn:773): change to pure virtual after update on chromium side.
+                virtual bool DeserializeDataUpdate(const void* deserializePointer,
+                                                   size_t deserializeSize,
+                                                   size_t offset,
+                                                   size_t size) {
+                    return false;
+                }
+
+                // TODO(dawn:773): remove after update on chromium side.
                 virtual bool DeserializeInitialData(const void* deserializePointer,
                                                     size_t deserializeSize,
                                                     const void** data,
-                                                    size_t* dataLength) = 0;
+                                                    size_t* dataLength) {
+                    return false;
+                }
 
               private:
                 ReadHandle(const ReadHandle&) = delete;
@@ -142,17 +153,44 @@
                 // Serialize the handle into |serializePointer| so it can be received by the server.
                 virtual void SerializeCreate(void* serializePointer) = 0;
 
-                // Open the handle for reading. The data returned should be zero-initialized.
+                // Simply return the base address of the allocation (without applying any offset)
+                // The data returned should be zero-initialized.
                 // The data returned must live at least until the WriteHandle is destructed.
                 // On failure, the pointer returned should be null.
-                virtual std::pair<void*, size_t> Open() = 0;
+                // TODO(dawn:773): change to pure virtual after update on chromium side.
+                virtual void* GetData() {
+                    return nullptr;
+                }
 
-                // Get the required serialization size for SerializeFlush
-                virtual size_t SerializeFlushSize() = 0;
+                // Get the required serialization size for SerializeDataUpdate
+                // TODO(dawn:773): change to pure virtual after update on chromium side.
+                virtual size_t SizeOfSerializeDataUpdate(size_t offset, size_t size) {
+                    return 0;
+                }
 
-                // Flush writes to the handle. This should serialize info to send updates to the
-                // server.
-                virtual void SerializeFlush(void* serializePointer) = 0;
+                // Serialize a command to send the modified contents of
+                // the subrange (offset, offset + size) of the allocation at buffer unmap
+                // This subrange is always the whole mapped region for now
+                // There could be nothing to be serialized (if using shared memory)
+                // TODO(dawn:773): change to pure virtual after update on chromium side.
+                virtual void SerializeDataUpdate(void* serializePointer,
+                                                 size_t offset,
+                                                 size_t size) {
+                }
+
+                // TODO(dawn:773): remove after update on chromium side.
+                virtual std::pair<void*, size_t> Open() {
+                    return std::make_pair(nullptr, 0);
+                }
+
+                // TODO(dawn:773): remove after update on chromium side.
+                virtual size_t SerializeFlushSize() {
+                    return 0;
+                }
+
+                // TODO(dawn:773): remove after update on chromium side.
+                virtual void SerializeFlush(void* serializePointer) {
+                }
 
               private:
                 WriteHandle(const WriteHandle&) = delete;
diff --git a/src/include/dawn_wire/WireServer.h b/src/include/dawn_wire/WireServer.h
index 14d2354..1e03880 100644
--- a/src/include/dawn_wire/WireServer.h
+++ b/src/include/dawn_wire/WireServer.h
@@ -91,14 +91,34 @@
                 ReadHandle();
                 virtual ~ReadHandle();
 
-                // Get the required serialization size for SerializeInitialData
-                virtual size_t SerializeInitialDataSize(const void* data, size_t dataLength) = 0;
+                // Return the size of the command serialized if
+                // SerializeDataUpdate is called with the same offset/size args
+                // TODO(dawn:773): change to pure virtual after update on chromium side.
+                virtual size_t SizeOfSerializeDataUpdate(size_t offset, size_t size) {
+                    return 0;
+                }
 
-                // Initialize the handle data.
-                // Serialize into |serializePointer| so the client can update handle data.
+                // Gets called when a MapReadCallback resolves.
+                // Serialize the data update for the range (offset, offset + size) into
+                // |serializePointer| to the client There could be nothing to be serialized (if
+                // using shared memory)
+                // TODO(dawn:773): change to pure virtual after update on chromium side.
+                virtual void SerializeDataUpdate(const void* data,
+                                                 size_t offset,
+                                                 size_t size,
+                                                 void* serializePointer) {
+                }
+
+                // TODO(dawn:773): remove after update on chromium side.
+                virtual size_t SerializeInitialDataSize(const void* data, size_t dataLength) {
+                    return 0;
+                }
+
+                // TODO(dawn:773): remove after update on chromium side.
                 virtual void SerializeInitialData(const void* data,
                                                   size_t dataLength,
-                                                  void* serializePointer) = 0;
+                                                  void* serializePointer) {
+                }
 
               private:
                 ReadHandle(const ReadHandle&) = delete;
@@ -112,15 +132,27 @@
 
                 // Set the target for writes from the client. DeserializeFlush should copy data
                 // into the target.
+                // TODO(dawn:773): only set backing buffer pointer data
                 void SetTarget(void* data, size_t dataLength);
 
-                // This function takes in the serialized result of
-                // client::MemoryTransferService::WriteHandle::SerializeFlush.
+                // TODO(dawn:773): remove after update on chromium side.
                 virtual bool DeserializeFlush(const void* deserializePointer,
-                                              size_t deserializeSize) = 0;
+                                              size_t deserializeSize) {
+                    return false;
+                }
+
+                // This function takes in the serialized result of
+                // client::MemoryTransferService::WriteHandle::SerializeDataUpdate.
+                virtual bool DeserializeDataUpdate(const void* deserializePointer,
+                                                   size_t deserializeSize,
+                                                   size_t offset,
+                                                   size_t size) {
+                    return false;
+                }
 
               protected:
                 void* mTargetData = nullptr;
+                // TODO(dawn:773): only set backing buffer pointer data
                 size_t mDataLength = 0;
 
               private: