blob: 228a417fdf2b6ffc67cd4641e4dd8d50ca629d74 [file] [log] [blame]
Austin Engacd8b7d2019-01-16 02:18:06 +00001// 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 Wallez1fdcb162019-10-24 22:27:27 +000018#include <dawn/webgpu.h>
Austin Engacd8b7d2019-01-16 02:18:06 +000019#include <dawn_wire/Wire.h>
20
Austin Engcac04422020-10-13 22:35:34 +000021#include "dawn_wire/ChunkedCommandSerializer.h"
Corentin Wallez339bd9d2019-03-28 12:57:11 +000022#include "dawn_wire/WireClient.h"
Austin Engacd8b7d2019-01-16 02:18:06 +000023#include "dawn_wire/WireCmd_autogen.h"
24#include "dawn_wire/WireDeserializeAllocator.h"
Austin Engcd4fd8e2019-01-30 02:31:37 +000025#include "dawn_wire/client/ClientBase_autogen.h"
Austin Engacd8b7d2019-01-16 02:18:06 +000026
27namespace dawn_wire { namespace client {
28
29 class Device;
Austin Eng6a5418a2019-07-19 16:01:48 +000030 class MemoryTransferService;
Austin Engacd8b7d2019-01-16 02:18:06 +000031
Austin Enge2c85132019-02-11 21:50:16 +000032 class Client : public ClientBase {
Austin Engacd8b7d2019-01-16 02:18:06 +000033 public:
Austin Eng6a5418a2019-07-19 16:01:48 +000034 Client(CommandSerializer* serializer, MemoryTransferService* memoryTransferService);
Austin Engcac04422020-10-13 22:35:34 +000035 ~Client() override;
36
37 // ChunkedCommandHandler implementation
38 const volatile char* HandleCommandsImpl(const volatile char* commands,
39 size_t size) override;
Austin Engcd4fd8e2019-01-30 02:31:37 +000040
Corentin Wallez409cf672020-04-23 21:21:52 +000041 WGPUDevice GetDevice();
Austin Enge2c85132019-02-11 21:50:16 +000042
Austin Eng6a5418a2019-07-19 16:01:48 +000043 MemoryTransferService* GetMemoryTransferService() const {
44 return mMemoryTransferService;
45 }
46
Austin Eng93bea5c2020-04-15 02:00:14 +000047 ReservedTexture ReserveTexture(WGPUDevice device);
48
Corentin Wallez90abd472020-06-19 16:49:43 +000049 template <typename Cmd>
Austin Engcac04422020-10-13 22:35:34 +000050 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 Wallez90abd472020-06-19 16:49:43 +000067 }
Austin Eng93bea5c2020-04-15 02:00:14 +000068
69 void Disconnect();
70
Austin Engacd8b7d2019-01-16 02:18:06 +000071 private:
Austin Eng3a8aa312019-05-17 20:42:33 +000072#include "dawn_wire/client/ClientPrototypes_autogen.inc"
Austin Engacd8b7d2019-01-16 02:18:06 +000073
Austin Engcd4fd8e2019-01-30 02:31:37 +000074 Device* mDevice = nullptr;
Austin Engcac04422020-10-13 22:35:34 +000075 ChunkedCommandSerializer mSerializer;
Austin Engacd8b7d2019-01-16 02:18:06 +000076 WireDeserializeAllocator mAllocator;
Austin Eng6a5418a2019-07-19 16:01:48 +000077 MemoryTransferService* mMemoryTransferService = nullptr;
78 std::unique_ptr<MemoryTransferService> mOwnedMemoryTransferService = nullptr;
Austin Engcac04422020-10-13 22:35:34 +000079 bool mDisconnected = false;
Austin Engacd8b7d2019-01-16 02:18:06 +000080 };
81
Austin Eng6a5418a2019-07-19 16:01:48 +000082 std::unique_ptr<MemoryTransferService> CreateInlineMemoryTransferService();
83
Austin Engacd8b7d2019-01-16 02:18:06 +000084}} // namespace dawn_wire::client
85
86#endif // DAWNWIRE_CLIENT_CLIENT_H_