Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 1 | // Copyright 2019 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_CLIENT_CLIENT_H_ |
| 16 | #define DAWNWIRE_CLIENT_CLIENT_H_ |
| 17 | |
Corentin Wallez | 1fdcb16 | 2019-10-24 22:27:27 +0000 | [diff] [blame] | 18 | #include <dawn/webgpu.h> |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 19 | #include <dawn_wire/Wire.h> |
| 20 | |
Austin Eng | cac0442 | 2020-10-13 22:35:34 +0000 | [diff] [blame^] | 21 | #include "dawn_wire/ChunkedCommandSerializer.h" |
Corentin Wallez | 339bd9d | 2019-03-28 12:57:11 +0000 | [diff] [blame] | 22 | #include "dawn_wire/WireClient.h" |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 23 | #include "dawn_wire/WireCmd_autogen.h" |
| 24 | #include "dawn_wire/WireDeserializeAllocator.h" |
Austin Eng | cd4fd8e | 2019-01-30 02:31:37 +0000 | [diff] [blame] | 25 | #include "dawn_wire/client/ClientBase_autogen.h" |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 26 | |
| 27 | namespace dawn_wire { namespace client { |
| 28 | |
| 29 | class Device; |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 30 | class MemoryTransferService; |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 31 | |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 32 | class Client : public ClientBase { |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 33 | public: |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 34 | Client(CommandSerializer* serializer, MemoryTransferService* memoryTransferService); |
Austin Eng | cac0442 | 2020-10-13 22:35:34 +0000 | [diff] [blame^] | 35 | ~Client() override; |
| 36 | |
| 37 | // ChunkedCommandHandler implementation |
| 38 | const volatile char* HandleCommandsImpl(const volatile char* commands, |
| 39 | size_t size) override; |
Austin Eng | cd4fd8e | 2019-01-30 02:31:37 +0000 | [diff] [blame] | 40 | |
Corentin Wallez | 409cf67 | 2020-04-23 21:21:52 +0000 | [diff] [blame] | 41 | WGPUDevice GetDevice(); |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 42 | |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 43 | MemoryTransferService* GetMemoryTransferService() const { |
| 44 | return mMemoryTransferService; |
| 45 | } |
| 46 | |
Austin Eng | 93bea5c | 2020-04-15 02:00:14 +0000 | [diff] [blame] | 47 | ReservedTexture ReserveTexture(WGPUDevice device); |
| 48 | |
Corentin Wallez | 90abd47 | 2020-06-19 16:49:43 +0000 | [diff] [blame] | 49 | template <typename Cmd> |
Austin Eng | cac0442 | 2020-10-13 22:35:34 +0000 | [diff] [blame^] | 50 | void SerializeCommand(const Cmd& cmd) { |
| 51 | // TODO(enga): Swap out the serializer with a no-op one on disconnect. |
| 52 | if (mDisconnected) { |
| 53 | return; |
| 54 | } |
| 55 | mSerializer.SerializeCommand(cmd, *this); |
| 56 | } |
| 57 | |
| 58 | template <typename Cmd, typename ExtraSizeSerializeFn> |
| 59 | void SerializeCommand(const Cmd& cmd, |
| 60 | size_t extraSize, |
| 61 | ExtraSizeSerializeFn&& SerializeExtraSize) { |
| 62 | // TODO(enga): Swap out the serializer with a no-op one on disconnect. |
| 63 | if (mDisconnected) { |
| 64 | return; |
| 65 | } |
| 66 | mSerializer.SerializeCommand(cmd, *this, extraSize, SerializeExtraSize); |
Corentin Wallez | 90abd47 | 2020-06-19 16:49:43 +0000 | [diff] [blame] | 67 | } |
Austin Eng | 93bea5c | 2020-04-15 02:00:14 +0000 | [diff] [blame] | 68 | |
| 69 | void Disconnect(); |
| 70 | |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 71 | private: |
Austin Eng | 3a8aa31 | 2019-05-17 20:42:33 +0000 | [diff] [blame] | 72 | #include "dawn_wire/client/ClientPrototypes_autogen.inc" |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 73 | |
Austin Eng | cd4fd8e | 2019-01-30 02:31:37 +0000 | [diff] [blame] | 74 | Device* mDevice = nullptr; |
Austin Eng | cac0442 | 2020-10-13 22:35:34 +0000 | [diff] [blame^] | 75 | ChunkedCommandSerializer mSerializer; |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 76 | WireDeserializeAllocator mAllocator; |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 77 | MemoryTransferService* mMemoryTransferService = nullptr; |
| 78 | std::unique_ptr<MemoryTransferService> mOwnedMemoryTransferService = nullptr; |
Austin Eng | cac0442 | 2020-10-13 22:35:34 +0000 | [diff] [blame^] | 79 | bool mDisconnected = false; |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 82 | std::unique_ptr<MemoryTransferService> CreateInlineMemoryTransferService(); |
| 83 | |
Austin Eng | acd8b7d | 2019-01-16 02:18:06 +0000 | [diff] [blame] | 84 | }} // namespace dawn_wire::client |
| 85 | |
| 86 | #endif // DAWNWIRE_CLIENT_CLIENT_H_ |