diff --git a/src/dawn_wire/client/Client.cpp b/src/dawn_wire/client/Client.cpp index 2c8b807b77..af0e40b091 100644 --- a/src/dawn_wire/client/Client.cpp +++ b/src/dawn_wire/client/Client.cpp @@ -19,6 +19,30 @@ namespace dawn_wire { namespace client { + namespace { + + class NoopCommandSerializer final : public CommandSerializer { + public: + static NoopCommandSerializer* GetInstance() { + static NoopCommandSerializer gNoopCommandSerializer; + return &gNoopCommandSerializer; + } + + ~NoopCommandSerializer() = default; + + size_t GetMaximumAllocationSize() const final { + return 0; + } + void* GetCmdSpace(size_t size) final { + return nullptr; + } + bool Flush() final { + return false; + } + }; + + } // anonymous namespace + Client::Client(CommandSerializer* serializer, MemoryTransferService* memoryTransferService) : ClientBase(), mSerializer(serializer), mMemoryTransferService(memoryTransferService) { if (mMemoryTransferService == nullptr) { @@ -53,11 +77,7 @@ namespace dawn_wire { namespace client { } void Client::Disconnect() { - if (mDisconnected) { - return; - } - - mDisconnected = true; + mSerializer = ChunkedCommandSerializer(NoopCommandSerializer::GetInstance()); if (mDevice != nullptr) { mDevice->HandleDeviceLost("GPU connection lost"); } diff --git a/src/dawn_wire/client/Client.h b/src/dawn_wire/client/Client.h index 228a417fdf..47ec95b5db 100644 --- a/src/dawn_wire/client/Client.h +++ b/src/dawn_wire/client/Client.h @@ -48,10 +48,6 @@ namespace dawn_wire { namespace client { template void SerializeCommand(const Cmd& cmd) { - // TODO(enga): Swap out the serializer with a no-op one on disconnect. - if (mDisconnected) { - return; - } mSerializer.SerializeCommand(cmd, *this); } @@ -59,10 +55,6 @@ namespace dawn_wire { namespace client { void SerializeCommand(const Cmd& cmd, size_t extraSize, ExtraSizeSerializeFn&& SerializeExtraSize) { - // TODO(enga): Swap out the serializer with a no-op one on disconnect. - if (mDisconnected) { - return; - } mSerializer.SerializeCommand(cmd, *this, extraSize, SerializeExtraSize); } @@ -76,7 +68,6 @@ namespace dawn_wire { namespace client { WireDeserializeAllocator mAllocator; MemoryTransferService* mMemoryTransferService = nullptr; std::unique_ptr mOwnedMemoryTransferService = nullptr; - bool mDisconnected = false; }; std::unique_ptr CreateInlineMemoryTransferService();