dawn::wire: Separate ObjectHandle to its own header.

This allows using it without including all of WireCmd_autogen.h. Start
using in client::ObjectBase to use the typedef for ObjectId.

Bug: dawn:1451
Change-Id: I80e7247cc0e83ae48818b0d73b5236c6980204d1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93145
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2022-06-14 13:22:16 +00:00 committed by Dawn LUCI CQ
parent b0f0012481
commit 87af04b769
7 changed files with 102 additions and 49 deletions

View File

@ -651,31 +651,6 @@
namespace dawn::wire { namespace dawn::wire {
ObjectHandle::ObjectHandle() = default;
ObjectHandle::ObjectHandle(ObjectId id, ObjectGeneration generation)
: id(id), generation(generation) {
}
ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs)
: id(rhs.id), generation(rhs.generation) {
}
ObjectHandle& ObjectHandle::operator=(const volatile ObjectHandle& rhs) {
id = rhs.id;
generation = rhs.generation;
return *this;
}
ObjectHandle& ObjectHandle::AssignFrom(const ObjectHandle& rhs) {
id = rhs.id;
generation = rhs.generation;
return *this;
}
ObjectHandle& ObjectHandle::AssignFrom(const volatile ObjectHandle& rhs) {
id = rhs.id;
generation = rhs.generation;
return *this;
}
namespace { namespace {
// Allocates enough space from allocator to countain T[count] and return it in out. // Allocates enough space from allocator to countain T[count] and return it in out.
// Return FatalError if the allocator couldn't allocate the memory. // Return FatalError if the allocator couldn't allocate the memory.

View File

@ -19,32 +19,11 @@
#include "dawn/wire/BufferConsumer.h" #include "dawn/wire/BufferConsumer.h"
#include "dawn/wire/ObjectType_autogen.h" #include "dawn/wire/ObjectType_autogen.h"
#include "dawn/wire/ObjectHandle.h"
#include "dawn/wire/WireResult.h" #include "dawn/wire/WireResult.h"
namespace dawn::wire { namespace dawn::wire {
using ObjectId = uint32_t;
using ObjectGeneration = uint32_t;
struct ObjectHandle {
ObjectId id;
ObjectGeneration generation;
ObjectHandle();
ObjectHandle(ObjectId id, ObjectGeneration generation);
ObjectHandle(const volatile ObjectHandle& rhs);
ObjectHandle& operator=(const volatile ObjectHandle& rhs);
// MSVC has a bug where it thinks the volatile copy assignment is a duplicate.
// Workaround this by forwarding to a different function AssignFrom.
template <typename T>
ObjectHandle& operator=(const T& rhs) {
return AssignFrom(rhs);
}
ObjectHandle& AssignFrom(const ObjectHandle& rhs);
ObjectHandle& AssignFrom(const volatile ObjectHandle& rhs);
};
// Interface to allocate more space to deserialize pointed-to data. // Interface to allocate more space to deserialize pointed-to data.
// nullptr is treated as an error. // nullptr is treated as an error.
class DeserializeAllocator { class DeserializeAllocator {

View File

@ -65,6 +65,8 @@ dawn_component("wire") {
"ChunkedCommandHandler.h", "ChunkedCommandHandler.h",
"ChunkedCommandSerializer.cpp", "ChunkedCommandSerializer.cpp",
"ChunkedCommandSerializer.h", "ChunkedCommandSerializer.h",
"ObjectHandle.cpp",
"ObjectHandle.h",
"SupportedFeatures.cpp", "SupportedFeatures.cpp",
"SupportedFeatures.h", "SupportedFeatures.h",
"Wire.cpp", "Wire.cpp",

View File

@ -38,6 +38,8 @@ target_sources(dawn_wire PRIVATE
"ChunkedCommandHandler.h" "ChunkedCommandHandler.h"
"ChunkedCommandSerializer.cpp" "ChunkedCommandSerializer.cpp"
"ChunkedCommandSerializer.h" "ChunkedCommandSerializer.h"
"ObjectHandle.cpp"
"ObjectHandle.h"
"SupportedFeatures.cpp" "SupportedFeatures.cpp"
"SupportedFeatures.h" "SupportedFeatures.h"
"Wire.cpp" "Wire.cpp"

View File

@ -0,0 +1,45 @@
// Copyright 2022 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/ObjectHandle.h"
namespace dawn::wire {
ObjectHandle::ObjectHandle() = default;
ObjectHandle::ObjectHandle(ObjectId id, ObjectGeneration generation)
: id(id), generation(generation) {}
ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs)
: id(rhs.id), generation(rhs.generation) {}
ObjectHandle& ObjectHandle::operator=(const volatile ObjectHandle& rhs) {
id = rhs.id;
generation = rhs.generation;
return *this;
}
ObjectHandle::ObjectHandle(const ObjectHandle& rhs) = default;
ObjectHandle& ObjectHandle::operator=(const ObjectHandle& rhs) = default;
ObjectHandle& ObjectHandle::AssignFrom(const ObjectHandle& rhs) {
id = rhs.id;
generation = rhs.generation;
return *this;
}
ObjectHandle& ObjectHandle::AssignFrom(const volatile ObjectHandle& rhs) {
id = rhs.id;
generation = rhs.generation;
return *this;
}
} // namespace dawn::wire

View File

@ -0,0 +1,49 @@
// Copyright 2022 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 DAWN_WIRE_OBJECTHANDLE_H_
#define DAWN_WIRE_OBJECTHANDLE_H_
#include <cstdint>
namespace dawn::wire {
using ObjectId = uint32_t;
using ObjectGeneration = uint32_t;
struct ObjectHandle {
ObjectId id;
ObjectGeneration generation;
ObjectHandle();
ObjectHandle(ObjectId id, ObjectGeneration generation);
explicit ObjectHandle(const volatile ObjectHandle& rhs);
ObjectHandle& operator=(const volatile ObjectHandle& rhs);
ObjectHandle(const ObjectHandle& rhs);
ObjectHandle& operator=(const ObjectHandle& rhs);
// MSVC has a bug where it thinks the volatile copy assignment is a duplicate.
// Workaround this by forwarding to a different function AssignFrom.
template <typename T>
ObjectHandle& operator=(const T& rhs) {
return AssignFrom(rhs);
}
ObjectHandle& AssignFrom(const ObjectHandle& rhs);
ObjectHandle& AssignFrom(const volatile ObjectHandle& rhs);
};
} // namespace dawn::wire
#endif // DAWN_WIRE_OBJECTHANDLE_H_

View File

@ -19,6 +19,7 @@
#include "dawn/common/LinkedList.h" #include "dawn/common/LinkedList.h"
#include "dawn/wire/ObjectType_autogen.h" #include "dawn/wire/ObjectType_autogen.h"
#include "dawn/wire/ObjectHandle.h"
namespace dawn::wire::client { namespace dawn::wire::client {
@ -26,7 +27,7 @@ class Client;
struct ObjectBaseParams { struct ObjectBaseParams {
Client* client; Client* client;
uint32_t id; ObjectId id;
}; };
// All objects on the client side have: // All objects on the client side have:
@ -42,7 +43,7 @@ struct ObjectBase : public LinkNode<ObjectBase> {
Client* const client; Client* const client;
uint32_t refcount; uint32_t refcount;
const uint32_t id; const ObjectId id;
}; };
} // namespace dawn::wire::client } // namespace dawn::wire::client