mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-17 04:41:23 +00:00
This commit changes all the [Object]Allocators from the Client into a PerType<ObjectStore> member that contains a bunch of ObjectStore acting on ObjectBase. Adds a new (template) member functions to the client, Make/Get/Free that act on any object type, and update all the uses of previous [Object]Allocator to use these new methods. Also removes generated code that was generated per object type in favor of using the type-generic ObjectAllocator. Bug: dawn:1451 Change-Id: I6463b2fc4a827e3000c2a666abf08aa1a71c3b3b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93141 Reviewed-by: Austin Eng <enga@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
97 lines
3.8 KiB
C++
97 lines
3.8 KiB
C++
//* 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/common/Assert.h"
|
|
#include "dawn/wire/client/Client.h"
|
|
|
|
#include <string>
|
|
|
|
namespace dawn::wire::client {
|
|
{% for command in cmd_records["return command"] %}
|
|
bool Client::Handle{{command.name.CamelCase()}}(DeserializeBuffer* deserializeBuffer) {
|
|
Return{{command.name.CamelCase()}}Cmd cmd;
|
|
WireResult deserializeResult = cmd.Deserialize(deserializeBuffer, &mWireCommandAllocator);
|
|
|
|
if (deserializeResult == WireResult::FatalError) {
|
|
return false;
|
|
}
|
|
|
|
{% for member in command.members if member.handle_type %}
|
|
{% set Type = member.handle_type.name.CamelCase() %}
|
|
{% set name = as_varName(member.name) %}
|
|
|
|
{% if member.type.dict_name == "ObjectHandle" %}
|
|
{{Type}}* {{name}} = Get<{{Type}}>(cmd.{{name}}.id);
|
|
if ({{name}} != nullptr && {{name}}->GetWireGeneration() != cmd.{{name}}.generation) {
|
|
{{name}} = nullptr;
|
|
}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
return Do{{command.name.CamelCase()}}(
|
|
{%- for member in command.members -%}
|
|
{%- if member.handle_type -%}
|
|
{{as_varName(member.name)}}
|
|
{%- else -%}
|
|
cmd.{{as_varName(member.name)}}
|
|
{%- endif -%}
|
|
{%- if not loop.last -%}, {% endif %}
|
|
{%- endfor -%}
|
|
);
|
|
}
|
|
{% endfor %}
|
|
|
|
const volatile char* Client::HandleCommandsImpl(const volatile char* commands, size_t size) {
|
|
DeserializeBuffer deserializeBuffer(commands, size);
|
|
|
|
while (deserializeBuffer.AvailableSize() >= sizeof(CmdHeader) + sizeof(ReturnWireCmd)) {
|
|
// Start by chunked command handling, if it is done, then it means the whole buffer
|
|
// was consumed by it, so we return a pointer to the end of the commands.
|
|
switch (HandleChunkedCommands(deserializeBuffer.Buffer(), deserializeBuffer.AvailableSize())) {
|
|
case ChunkedCommandsResult::Consumed:
|
|
return commands + size;
|
|
case ChunkedCommandsResult::Error:
|
|
return nullptr;
|
|
case ChunkedCommandsResult::Passthrough:
|
|
break;
|
|
}
|
|
|
|
ReturnWireCmd cmdId = *static_cast<const volatile ReturnWireCmd*>(static_cast<const volatile void*>(
|
|
deserializeBuffer.Buffer() + sizeof(CmdHeader)));
|
|
bool success = false;
|
|
switch (cmdId) {
|
|
{% for command in cmd_records["return command"] %}
|
|
{% set Suffix = command.name.CamelCase() %}
|
|
case ReturnWireCmd::{{Suffix}}:
|
|
success = Handle{{Suffix}}(&deserializeBuffer);
|
|
break;
|
|
{% endfor %}
|
|
default:
|
|
success = false;
|
|
}
|
|
|
|
if (!success) {
|
|
return nullptr;
|
|
}
|
|
mWireCommandAllocator.Reset();
|
|
}
|
|
|
|
if (deserializeBuffer.AvailableSize() != 0) {
|
|
return nullptr;
|
|
}
|
|
|
|
return commands;
|
|
}
|
|
} // namespace dawn::wire::client
|