mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-07 04:35:53 +00:00
Fix build breakage in libstdc++: ../../third_party/dawn/src/dawn_wire/ChunkedCommandSerializer.h:84:34: error: ‘unique_ptr’ is not a member of ‘std’ 84 | auto cmdSpace = std::unique_ptr<char[]>(new (std::nothrow) char[requiredSize]); | ^~~~~~~~~~ ../../third_party/dawn/src/dawn_wire/ChunkedCommandSerializer.h:24:1: note: ‘std::unique_ptr’ is defined in header ‘<memory>’; did you forget to ‘#include <memory>’? Bug: chromium:957519 Change-Id: I35b129225882a3f9b758c4f49d1a3cace22aacfe Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30600 Commit-Queue: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
103 lines
3.9 KiB
C++
103 lines
3.9 KiB
C++
// Copyright 2020 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_CHUNKEDCOMMANDSERIALIZER_H_
|
|
#define DAWNWIRE_CHUNKEDCOMMANDSERIALIZER_H_
|
|
|
|
#include "common/Compiler.h"
|
|
#include "dawn_wire/Wire.h"
|
|
#include "dawn_wire/WireCmd_autogen.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
#include <memory>
|
|
|
|
namespace dawn_wire {
|
|
|
|
class ChunkedCommandSerializer {
|
|
public:
|
|
ChunkedCommandSerializer(CommandSerializer* serializer);
|
|
|
|
template <typename Cmd>
|
|
void SerializeCommand(const Cmd& cmd) {
|
|
SerializeCommand(cmd, 0, [](char*) {});
|
|
}
|
|
|
|
template <typename Cmd, typename ExtraSizeSerializeFn>
|
|
void SerializeCommand(const Cmd& cmd,
|
|
size_t extraSize,
|
|
ExtraSizeSerializeFn&& SerializeExtraSize) {
|
|
SerializeCommandImpl(
|
|
cmd,
|
|
[](const Cmd& cmd, size_t requiredSize, char* allocatedBuffer) {
|
|
cmd.Serialize(requiredSize, allocatedBuffer);
|
|
},
|
|
extraSize, std::forward<ExtraSizeSerializeFn>(SerializeExtraSize));
|
|
}
|
|
|
|
template <typename Cmd>
|
|
void SerializeCommand(const Cmd& cmd, const ObjectIdProvider& objectIdProvider) {
|
|
SerializeCommand(cmd, objectIdProvider, 0, [](char*) {});
|
|
}
|
|
|
|
template <typename Cmd, typename ExtraSizeSerializeFn>
|
|
void SerializeCommand(const Cmd& cmd,
|
|
const ObjectIdProvider& objectIdProvider,
|
|
size_t extraSize,
|
|
ExtraSizeSerializeFn&& SerializeExtraSize) {
|
|
SerializeCommandImpl(
|
|
cmd,
|
|
[&objectIdProvider](const Cmd& cmd, size_t requiredSize, char* allocatedBuffer) {
|
|
cmd.Serialize(requiredSize, allocatedBuffer, objectIdProvider);
|
|
},
|
|
extraSize, std::forward<ExtraSizeSerializeFn>(SerializeExtraSize));
|
|
}
|
|
|
|
private:
|
|
template <typename Cmd, typename SerializeCmdFn, typename ExtraSizeSerializeFn>
|
|
void SerializeCommandImpl(const Cmd& cmd,
|
|
SerializeCmdFn&& SerializeCmd,
|
|
size_t extraSize,
|
|
ExtraSizeSerializeFn&& SerializeExtraSize) {
|
|
size_t commandSize = cmd.GetRequiredSize();
|
|
size_t requiredSize = commandSize + extraSize;
|
|
|
|
if (requiredSize <= mMaxAllocationSize) {
|
|
char* allocatedBuffer = static_cast<char*>(mSerializer->GetCmdSpace(requiredSize));
|
|
if (allocatedBuffer != nullptr) {
|
|
SerializeCmd(cmd, requiredSize, allocatedBuffer);
|
|
SerializeExtraSize(allocatedBuffer + commandSize);
|
|
}
|
|
return;
|
|
}
|
|
|
|
auto cmdSpace = std::unique_ptr<char[]>(new (std::nothrow) char[requiredSize]);
|
|
if (!cmdSpace) {
|
|
return;
|
|
}
|
|
SerializeCmd(cmd, requiredSize, cmdSpace.get());
|
|
SerializeExtraSize(cmdSpace.get() + commandSize);
|
|
SerializeChunkedCommand(cmdSpace.get(), requiredSize);
|
|
}
|
|
|
|
void SerializeChunkedCommand(const char* allocatedBuffer, size_t remainingSize);
|
|
|
|
CommandSerializer* mSerializer;
|
|
size_t mMaxAllocationSize;
|
|
};
|
|
|
|
} // namespace dawn_wire
|
|
|
|
#endif // DAWNWIRE_CHUNKEDCOMMANDSERIALIZER_H_
|