1 // Copyright 2017 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNWIRE_WIRE_H_ 16 #define DAWNWIRE_WIRE_H_ 17 18 #include <cstdint> 19 #include <limits> 20 21 #include "dawn/webgpu.h" 22 #include "dawn_wire/dawn_wire_export.h" 23 24 namespace dawn_wire { 25 26 class DAWN_WIRE_EXPORT CommandSerializer { 27 public: 28 CommandSerializer(); 29 virtual ~CommandSerializer(); 30 CommandSerializer(const CommandSerializer& rhs) = delete; 31 CommandSerializer& operator=(const CommandSerializer& rhs) = delete; 32 33 // Get space for serializing commands. 34 // GetCmdSpace will never be called with a value larger than 35 // what GetMaximumAllocationSize returns. Return nullptr to indicate 36 // a fatal error. 37 virtual void* GetCmdSpace(size_t size) = 0; 38 virtual bool Flush() = 0; 39 virtual size_t GetMaximumAllocationSize() const = 0; 40 virtual void OnSerializeError(); 41 }; 42 43 class DAWN_WIRE_EXPORT CommandHandler { 44 public: 45 CommandHandler(); 46 virtual ~CommandHandler(); 47 CommandHandler(const CommandHandler& rhs) = delete; 48 CommandHandler& operator=(const CommandHandler& rhs) = delete; 49 50 virtual const volatile char* HandleCommands(const volatile char* commands, size_t size) = 0; 51 }; 52 53 DAWN_WIRE_EXPORT size_t 54 SerializedWGPUDevicePropertiesSize(const WGPUDeviceProperties* deviceProperties); 55 56 DAWN_WIRE_EXPORT void SerializeWGPUDeviceProperties( 57 const WGPUDeviceProperties* deviceProperties, 58 char* serializeBuffer); 59 60 DAWN_WIRE_EXPORT bool DeserializeWGPUDeviceProperties(WGPUDeviceProperties* deviceProperties, 61 const volatile char* deserializeBuffer, 62 size_t deserializeBufferSize); 63 64 DAWN_WIRE_EXPORT size_t 65 SerializedWGPUSupportedLimitsSize(const WGPUSupportedLimits* supportedLimits); 66 67 DAWN_WIRE_EXPORT void SerializeWGPUSupportedLimits(const WGPUSupportedLimits* supportedLimits, 68 char* serializeBuffer); 69 70 DAWN_WIRE_EXPORT bool DeserializeWGPUSupportedLimits(WGPUSupportedLimits* supportedLimits, 71 const volatile char* deserializeBuffer, 72 size_t deserializeBufferSize); 73 74 } // namespace dawn_wire 75 76 #endif // DAWNWIRE_WIRE_H_ 77