Create wire Client and Server classes with private impl
This creates proper Client and Server interfaces which will be necessary for adding additional features to the Wire for chrome integration Bug: dawn:103 Change-Id: I181e95079b0bac85c2c6152ad8066a94b80c8d28 Reviewed-on: https://dawn-review.googlesource.com/c/4002 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
62e83971ca
commit
e2c851372a
5
BUILD.gn
5
BUILD.gn
|
@ -760,6 +760,8 @@ source_set("libdawn_wire_headers") {
|
|||
public_configs = [ ":dawn_public" ]
|
||||
sources = [
|
||||
"src/include/dawn_wire/Wire.h",
|
||||
"src/include/dawn_wire/WireClient.h",
|
||||
"src/include/dawn_wire/WireServer.h",
|
||||
"src/include/dawn_wire/dawn_wire_export.h",
|
||||
]
|
||||
}
|
||||
|
@ -797,9 +799,10 @@ dawn_component("libdawn_wire") {
|
|||
configs = [ ":dawn_internal" ]
|
||||
sources = get_target_outputs(":libdawn_wire_gen")
|
||||
sources += [
|
||||
"src/dawn_wire/DawnWire.cpp",
|
||||
"src/dawn_wire/WireClient.cpp",
|
||||
"src/dawn_wire/WireDeserializeAllocator.cpp",
|
||||
"src/dawn_wire/WireDeserializeAllocator.h",
|
||||
"src/dawn_wire/WireServer.cpp",
|
||||
"src/dawn_wire/client/ApiObjects.h",
|
||||
"src/dawn_wire/client/ApiProcs.cpp",
|
||||
"src/dawn_wire/client/Buffer.cpp",
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
#include "utils/TerribleCommandBuffer.h"
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
#include <dawn/dawncpp.h>
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn/dawncpp.h>
|
||||
#include <dawn_native/DawnNative.h>
|
||||
#include <dawn_wire/WireClient.h>
|
||||
#include <dawn_wire/WireServer.h>
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include <cstring>
|
||||
|
@ -61,8 +63,8 @@ static utils::BackendBinding* binding = nullptr;
|
|||
|
||||
static GLFWwindow* window = nullptr;
|
||||
|
||||
static dawn_wire::CommandHandler* wireServer = nullptr;
|
||||
static dawn_wire::CommandHandler* wireClient = nullptr;
|
||||
static dawn_wire::WireServer* wireServer = nullptr;
|
||||
static dawn_wire::WireClient* wireClient = nullptr;
|
||||
static utils::TerribleCommandBuffer* c2sBuf = nullptr;
|
||||
static utils::TerribleCommandBuffer* s2cBuf = nullptr;
|
||||
|
||||
|
@ -101,12 +103,12 @@ dawn::Device CreateCppDawnDevice() {
|
|||
c2sBuf = new utils::TerribleCommandBuffer();
|
||||
s2cBuf = new utils::TerribleCommandBuffer();
|
||||
|
||||
wireServer = dawn_wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf);
|
||||
wireServer = new dawn_wire::WireServer(backendDevice, backendProcs, s2cBuf);
|
||||
c2sBuf->SetHandler(wireServer);
|
||||
|
||||
dawnDevice clientDevice;
|
||||
dawnProcTable clientProcs;
|
||||
wireClient = dawn_wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf);
|
||||
wireClient = new dawn_wire::WireClient(c2sBuf);
|
||||
dawnDevice clientDevice = wireClient->GetDevice();
|
||||
dawnProcTable clientProcs = wireClient->GetProcs();
|
||||
s2cBuf->SetHandler(wireClient);
|
||||
|
||||
procs = clientProcs;
|
||||
|
|
|
@ -12,19 +12,28 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "dawn_wire/WireClient.h"
|
||||
#include "dawn_wire/client/Client.h"
|
||||
#include "dawn_wire/server/Server.h"
|
||||
|
||||
namespace dawn_wire {
|
||||
CommandHandler* NewClientDevice(dawnProcTable* procs,
|
||||
dawnDevice* device,
|
||||
CommandSerializer* serializer) {
|
||||
return new client::Client(procs, device, serializer);
|
||||
|
||||
WireClient::WireClient(CommandSerializer* serializer) : mImpl(new client::Client(serializer)) {
|
||||
}
|
||||
|
||||
CommandHandler* NewServerCommandHandler(dawnDevice device,
|
||||
const dawnProcTable& procs,
|
||||
CommandSerializer* serializer) {
|
||||
return new server::Server(device, procs, serializer);
|
||||
WireClient::~WireClient() {
|
||||
mImpl.reset();
|
||||
}
|
||||
|
||||
dawnDevice WireClient::GetDevice() const {
|
||||
return mImpl->GetDevice();
|
||||
}
|
||||
|
||||
dawnProcTable WireClient::GetProcs() const {
|
||||
return client::GetProcs();
|
||||
}
|
||||
|
||||
const char* WireClient::HandleCommands(const char* commands, size_t size) {
|
||||
return mImpl->HandleCommands(commands, size);
|
||||
}
|
||||
|
||||
} // namespace dawn_wire
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "dawn_wire/WireServer.h"
|
||||
#include "dawn_wire/server/Server.h"
|
||||
|
||||
namespace dawn_wire {
|
||||
|
||||
WireServer::WireServer(dawnDevice device,
|
||||
const dawnProcTable& procs,
|
||||
CommandSerializer* serializer)
|
||||
: mImpl(new server::Server(device, procs, serializer)) {
|
||||
}
|
||||
|
||||
WireServer::~WireServer() {
|
||||
mImpl.reset();
|
||||
}
|
||||
|
||||
const char* WireServer::HandleCommands(const char* commands, size_t size) {
|
||||
return mImpl->HandleCommands(commands, size);
|
||||
}
|
||||
|
||||
} // namespace dawn_wire
|
|
@ -17,12 +17,10 @@
|
|||
|
||||
namespace dawn_wire { namespace client {
|
||||
|
||||
Client::Client(dawnProcTable* procs, dawnDevice* device, CommandSerializer* serializer)
|
||||
Client::Client(CommandSerializer* serializer)
|
||||
: ClientBase(),
|
||||
mDevice(DeviceAllocator().New(this)->object.get()),
|
||||
mSerializer(serializer) {
|
||||
*device = reinterpret_cast<dawnDeviceImpl*>(mDevice);
|
||||
*procs = client::GetProcs();
|
||||
}
|
||||
|
||||
Client::~Client() {
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace dawn_wire { namespace client {
|
|||
|
||||
class Device;
|
||||
|
||||
class Client : public ClientBase, public CommandHandler {
|
||||
class Client : public ClientBase {
|
||||
public:
|
||||
Client(dawnProcTable* procs, dawnDevice* device, CommandSerializer* serializer);
|
||||
Client(CommandSerializer* serializer);
|
||||
~Client();
|
||||
|
||||
const char* HandleCommands(const char* commands, size_t size);
|
||||
|
@ -36,6 +36,10 @@ namespace dawn_wire { namespace client {
|
|||
return mSerializer->GetCmdSpace(size);
|
||||
}
|
||||
|
||||
dawnDevice GetDevice() const {
|
||||
return reinterpret_cast<dawnDeviceImpl*>(mDevice);
|
||||
}
|
||||
|
||||
private:
|
||||
#include "dawn_wire/client/ClientPrototypes_autogen.inl"
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace dawn_wire { namespace server {
|
|||
uint64_t value;
|
||||
};
|
||||
|
||||
class Server : public ServerBase, public CommandHandler {
|
||||
class Server : public ServerBase {
|
||||
public:
|
||||
Server(dawnDevice device, const dawnProcTable& procs, CommandSerializer* serializer);
|
||||
~Server();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "common/Assert.h"
|
||||
#include "dawn/dawncpp.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn_wire/Wire.h"
|
||||
#include "dawn_wire/WireServer.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -61,8 +61,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
ASSERT(nullDevice.Get() != nullptr);
|
||||
|
||||
DevNull devNull;
|
||||
std::unique_ptr<dawn_wire::CommandHandler> wireServer(
|
||||
dawn_wire::NewServerCommandHandler(nullDevice.Get(), procs, &devNull));
|
||||
std::unique_ptr<dawn_wire::WireServer> wireServer(
|
||||
new dawn_wire::WireServer(nullDevice.Get(), procs, &devNull));
|
||||
|
||||
wireServer->HandleCommands(reinterpret_cast<const char*>(data), size);
|
||||
|
||||
|
|
|
@ -35,13 +35,6 @@ namespace dawn_wire {
|
|||
virtual const char* HandleCommands(const char* commands, size_t size) = 0;
|
||||
};
|
||||
|
||||
DAWN_WIRE_EXPORT CommandHandler* NewClientDevice(dawnProcTable* procs,
|
||||
dawnDevice* device,
|
||||
CommandSerializer* serializer);
|
||||
DAWN_WIRE_EXPORT CommandHandler* NewServerCommandHandler(dawnDevice device,
|
||||
const dawnProcTable& procs,
|
||||
CommandSerializer* serializer);
|
||||
|
||||
} // namespace dawn_wire
|
||||
|
||||
#endif // DAWNWIRE_WIRE_H_
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef DAWNWIRE_WIRECLIENT_H_
|
||||
#define DAWNWIRE_WIRECLIENT_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "dawn_wire/Wire.h"
|
||||
|
||||
namespace dawn_wire {
|
||||
|
||||
namespace client {
|
||||
class Client;
|
||||
}
|
||||
|
||||
class DAWN_WIRE_EXPORT WireClient : public CommandHandler {
|
||||
public:
|
||||
WireClient(CommandSerializer* serializer);
|
||||
~WireClient();
|
||||
|
||||
dawnDevice GetDevice() const;
|
||||
dawnProcTable GetProcs() const;
|
||||
const char* HandleCommands(const char* commands, size_t size) override final;
|
||||
|
||||
private:
|
||||
std::unique_ptr<client::Client> mImpl;
|
||||
};
|
||||
|
||||
} // namespace dawn_wire
|
||||
|
||||
#endif // DAWNWIRE_WIRECLIENT_H_
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef DAWNWIRE_WIRESERVER_H_
|
||||
#define DAWNWIRE_WIRESERVER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "dawn_wire/Wire.h"
|
||||
|
||||
namespace dawn_wire {
|
||||
|
||||
namespace server {
|
||||
class Server;
|
||||
}
|
||||
|
||||
class DAWN_WIRE_EXPORT WireServer : public CommandHandler {
|
||||
public:
|
||||
WireServer(dawnDevice device, const dawnProcTable& procs, CommandSerializer* serializer);
|
||||
~WireServer();
|
||||
|
||||
const char* HandleCommands(const char* commands, size_t size) override final;
|
||||
|
||||
private:
|
||||
std::unique_ptr<server::Server> mImpl;
|
||||
};
|
||||
|
||||
} // namespace dawn_wire
|
||||
|
||||
#endif // DAWNWIRE_WIRESERVER_H_
|
|
@ -19,7 +19,8 @@
|
|||
#include "common/Math.h"
|
||||
#include "common/Platform.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn_wire/Wire.h"
|
||||
#include "dawn_wire/WireClient.h"
|
||||
#include "dawn_wire/WireServer.h"
|
||||
#include "utils/BackendBinding.h"
|
||||
#include "utils/DawnHelpers.h"
|
||||
#include "utils/SystemUtils.h"
|
||||
|
@ -192,13 +193,12 @@ void DawnTest::SetUp() {
|
|||
mC2sBuf = std::make_unique<utils::TerribleCommandBuffer>();
|
||||
mS2cBuf = std::make_unique<utils::TerribleCommandBuffer>();
|
||||
|
||||
mWireServer.reset(
|
||||
dawn_wire::NewServerCommandHandler(backendDevice, backendProcs, mS2cBuf.get()));
|
||||
mWireServer.reset(new dawn_wire::WireServer(backendDevice, backendProcs, mS2cBuf.get()));
|
||||
mC2sBuf->SetHandler(mWireServer.get());
|
||||
|
||||
dawnDevice clientDevice;
|
||||
dawnProcTable clientProcs;
|
||||
mWireClient.reset(dawn_wire::NewClientDevice(&clientProcs, &clientDevice, mC2sBuf.get()));
|
||||
mWireClient.reset(new dawn_wire::WireClient(mC2sBuf.get()));
|
||||
dawnDevice clientDevice = mWireClient->GetDevice();
|
||||
dawnProcTable clientProcs = mWireClient->GetProcs();
|
||||
mS2cBuf->SetHandler(mWireClient.get());
|
||||
|
||||
procs = clientProcs;
|
||||
|
|
|
@ -72,7 +72,8 @@ namespace detail {
|
|||
}
|
||||
|
||||
namespace dawn_wire {
|
||||
class CommandHandler;
|
||||
class WireClient;
|
||||
class WireServer;
|
||||
} // namespace dawn_wire
|
||||
|
||||
class DawnTest : public ::testing::TestWithParam<dawn_native::BackendType> {
|
||||
|
@ -129,8 +130,8 @@ class DawnTest : public ::testing::TestWithParam<dawn_native::BackendType> {
|
|||
|
||||
private:
|
||||
// Things used to set up testing through the Wire.
|
||||
std::unique_ptr<dawn_wire::CommandHandler> mWireServer;
|
||||
std::unique_ptr<dawn_wire::CommandHandler> mWireClient;
|
||||
std::unique_ptr<dawn_wire::WireServer> mWireServer;
|
||||
std::unique_ptr<dawn_wire::WireClient> mWireClient;
|
||||
std::unique_ptr<utils::TerribleCommandBuffer> mC2sBuf;
|
||||
std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
|
||||
void FlushWire();
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
|
||||
#include "common/Assert.h"
|
||||
#include "common/Constants.h"
|
||||
#include "dawn_wire/Wire.h"
|
||||
#include "dawn_wire/WireClient.h"
|
||||
#include "dawn_wire/WireServer.h"
|
||||
#include "utils/TerribleCommandBuffer.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace testing;
|
||||
using namespace dawn_wire;
|
||||
|
||||
// Definition of a "Lambda predicate matcher" for GMock to allow checking deep structures
|
||||
// are passed correctly by the wire.
|
||||
|
@ -156,11 +156,12 @@ class WireTestsBase : public Test {
|
|||
mS2cBuf = std::make_unique<utils::TerribleCommandBuffer>();
|
||||
mC2sBuf = std::make_unique<utils::TerribleCommandBuffer>(mWireServer.get());
|
||||
|
||||
mWireServer.reset(NewServerCommandHandler(mockDevice, mockProcs, mS2cBuf.get()));
|
||||
mWireServer.reset(new dawn_wire::WireServer(mockDevice, mockProcs, mS2cBuf.get()));
|
||||
mC2sBuf->SetHandler(mWireServer.get());
|
||||
|
||||
dawnProcTable clientProcs;
|
||||
mWireClient.reset(NewClientDevice(&clientProcs, &device, mC2sBuf.get()));
|
||||
mWireClient.reset(new dawn_wire::WireClient(mC2sBuf.get()));
|
||||
dawnProcTable clientProcs = mWireClient->GetProcs();
|
||||
device = mWireClient->GetDevice();
|
||||
dawnSetProcs(&clientProcs);
|
||||
mS2cBuf->SetHandler(mWireClient.get());
|
||||
|
||||
|
@ -197,8 +198,8 @@ class WireTestsBase : public Test {
|
|||
private:
|
||||
bool mIgnoreSetCallbackCalls = false;
|
||||
|
||||
std::unique_ptr<CommandHandler> mWireServer;
|
||||
std::unique_ptr<CommandHandler> mWireClient;
|
||||
std::unique_ptr<dawn_wire::WireServer> mWireServer;
|
||||
std::unique_ptr<dawn_wire::WireClient> mWireClient;
|
||||
std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
|
||||
std::unique_ptr<utils::TerribleCommandBuffer> mC2sBuf;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue