• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "dawn_wire/server/Server.h"
16 #include "dawn_wire/WireServer.h"
17 
18 namespace dawn_wire { namespace server {
19 
Server(DawnDevice device,const DawnProcTable & procs,CommandSerializer * serializer,MemoryTransferService * memoryTransferService)20     Server::Server(DawnDevice device,
21                    const DawnProcTable& procs,
22                    CommandSerializer* serializer,
23                    MemoryTransferService* memoryTransferService)
24         : mSerializer(serializer), mProcs(procs), mMemoryTransferService(memoryTransferService) {
25         if (mMemoryTransferService == nullptr) {
26             // If a MemoryTransferService is not provided, fallback to inline memory.
27             mOwnedMemoryTransferService = CreateInlineMemoryTransferService();
28             mMemoryTransferService = mOwnedMemoryTransferService.get();
29         }
30         // The client-server knowledge is bootstrapped with device 1.
31         auto* deviceData = DeviceObjects().Allocate(1);
32         deviceData->handle = device;
33 
34         mProcs.deviceSetErrorCallback(device, ForwardDeviceError, this);
35     }
36 
~Server()37     Server::~Server() {
38         DestroyAllObjects(mProcs);
39     }
40 
GetCmdSpace(size_t size)41     void* Server::GetCmdSpace(size_t size) {
42         return mSerializer->GetCmdSpace(size);
43     }
44 
InjectTexture(DawnTexture texture,uint32_t id,uint32_t generation)45     bool Server::InjectTexture(DawnTexture texture, uint32_t id, uint32_t generation) {
46         ObjectData<DawnTexture>* data = TextureObjects().Allocate(id);
47         if (data == nullptr) {
48             return false;
49         }
50 
51         data->handle = texture;
52         data->serial = generation;
53         data->allocated = true;
54 
55         // The texture is externally owned so it shouldn't be destroyed when we receive a destroy
56         // message from the client. Add a reference to counterbalance the eventual release.
57         mProcs.textureReference(texture);
58 
59         return true;
60     }
61 
62 }}  // namespace dawn_wire::server
63