136 lines
3.9 KiB
C++
Executable File
136 lines
3.9 KiB
C++
Executable File
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef GPU_IPC_COMMON_SYNC_TOKEN_MOJOM_SHARED_INTERNAL_H_
|
|
#define GPU_IPC_COMMON_SYNC_TOKEN_MOJOM_SHARED_INTERNAL_H_
|
|
|
|
#include "mojo/public/cpp/bindings/lib/array_internal.h"
|
|
#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
|
|
#include "mojo/public/cpp/bindings/lib/map_data_internal.h"
|
|
#include "mojo/public/cpp/bindings/lib/buffer.h"
|
|
#include "mojo/public/cpp/bindings/lib/native_enum_data.h"
|
|
#include "mojo/public/interfaces/bindings/native_struct.mojom-shared-internal.h"
|
|
|
|
namespace mojo {
|
|
namespace internal {
|
|
class ValidationContext;
|
|
}
|
|
}
|
|
namespace gpu {
|
|
namespace mojom {
|
|
namespace internal {
|
|
class SyncToken_Data;
|
|
|
|
struct CommandBufferNamespace_Data {
|
|
public:
|
|
static bool constexpr kIsExtensible = false;
|
|
|
|
static bool IsKnownValue(int32_t value) {
|
|
switch (value) {
|
|
case -1:
|
|
case 0:
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static bool Validate(int32_t value,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (kIsExtensible || IsKnownValue(value))
|
|
return true;
|
|
|
|
ReportValidationError(validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNKNOWN_ENUM_VALUE);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
#pragma pack(push, 1)
|
|
class SyncToken_Data {
|
|
public:
|
|
class BufferWriter {
|
|
public:
|
|
BufferWriter() = default;
|
|
|
|
void Allocate(mojo::internal::Buffer* serialization_buffer) {
|
|
serialization_buffer_ = serialization_buffer;
|
|
index_ = serialization_buffer_->Allocate(sizeof(SyncToken_Data));
|
|
new (data()) SyncToken_Data();
|
|
}
|
|
|
|
bool is_null() const { return !serialization_buffer_; }
|
|
SyncToken_Data* data() {
|
|
DCHECK(!is_null());
|
|
return serialization_buffer_->Get<SyncToken_Data>(index_);
|
|
}
|
|
SyncToken_Data* operator->() { return data(); }
|
|
|
|
private:
|
|
mojo::internal::Buffer* serialization_buffer_ = nullptr;
|
|
size_t index_ = 0;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(BufferWriter);
|
|
};
|
|
|
|
static bool Validate(const void* data,
|
|
mojo::internal::ValidationContext* validation_context);
|
|
|
|
mojo::internal::StructHeader header_;
|
|
uint8_t verified_flush : 1;
|
|
uint8_t pad0_[3];
|
|
int32_t namespace_id;
|
|
uint64_t command_buffer_id;
|
|
uint64_t release_count;
|
|
|
|
private:
|
|
SyncToken_Data();
|
|
~SyncToken_Data() = delete;
|
|
};
|
|
static_assert(sizeof(SyncToken_Data) == 32,
|
|
"Bad sizeof(SyncToken_Data)");
|
|
// Used by SyncToken::WrapAsMessage to lazily serialize the struct.
|
|
template <typename UserType, typename DataView>
|
|
struct SyncToken_UnserializedMessageContext
|
|
: public mojo::internal::UnserializedMessageContext {
|
|
public:
|
|
static const mojo::internal::UnserializedMessageContext::Tag kMessageTag;
|
|
|
|
SyncToken_UnserializedMessageContext(
|
|
uint32_t message_name,
|
|
uint32_t message_flags,
|
|
UserType input)
|
|
: mojo::internal::UnserializedMessageContext(&kMessageTag, message_name, message_flags)
|
|
, user_data_(std::move(input)) {}
|
|
~SyncToken_UnserializedMessageContext() override = default;
|
|
|
|
UserType TakeData() {
|
|
return std::move(user_data_);
|
|
}
|
|
|
|
private:
|
|
// mojo::internal::UnserializedMessageContext:
|
|
void Serialize(mojo::internal::SerializationContext* context,
|
|
mojo::internal::Buffer* buffer) override {
|
|
SyncToken_Data::BufferWriter writer;
|
|
mojo::internal::Serialize<DataView>(user_data_, buffer, &writer, context);
|
|
}
|
|
|
|
UserType user_data_;
|
|
};
|
|
|
|
template <typename UserType, typename DataView>
|
|
const mojo::internal::UnserializedMessageContext::Tag
|
|
SyncToken_UnserializedMessageContext<UserType, DataView>::kMessageTag = {};
|
|
|
|
#pragma pack(pop)
|
|
|
|
} // namespace internal
|
|
} // namespace mojom
|
|
} // namespace gpu
|
|
|
|
#endif // GPU_IPC_COMMON_SYNC_TOKEN_MOJOM_SHARED_INTERNAL_H_
|