2018-07-18 09:40:26 +00:00
|
|
|
//* Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//*
|
|
|
|
//* 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.
|
|
|
|
|
2018-07-24 14:30:14 +00:00
|
|
|
#ifndef DAWN_DAWNCPP_H_
|
|
|
|
#define DAWN_DAWNCPP_H_
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-25 10:41:29 +00:00
|
|
|
#include "dawn/dawn.h"
|
|
|
|
#include "dawn/dawn_export.h"
|
2018-07-18 12:32:45 +00:00
|
|
|
#include "dawn/EnumClassBitmasks.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-18 12:44:20 +00:00
|
|
|
namespace dawn {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
{% for type in by_category["enum"] %}
|
|
|
|
enum class {{as_cppType(type.name)}} : uint32_t {
|
|
|
|
{% for value in type.values %}
|
|
|
|
{{as_cppEnum(value.name)}} = 0x{{format(value.value, "08X")}},
|
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% for type in by_category["bitmask"] %}
|
|
|
|
enum class {{as_cppType(type.name)}} : uint32_t {
|
|
|
|
{% for value in type.values %}
|
|
|
|
{{as_cppEnum(value.name)}} = 0x{{format(value.value, "08X")}},
|
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% for type in by_category["bitmask"] %}
|
|
|
|
template<>
|
2018-07-18 13:26:19 +00:00
|
|
|
struct IsDawnBitmask<{{as_cppType(type.name)}}> {
|
2017-04-20 18:38:20 +00:00
|
|
|
static constexpr bool enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
2017-04-20 18:42:36 +00:00
|
|
|
{% for type in by_category["natively defined"] %}
|
|
|
|
using {{as_cppType(type.name)}} = {{as_cType(type.name)}};
|
|
|
|
{% endfor %}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
class {{as_cppType(type.name)}};
|
|
|
|
{% endfor %}
|
|
|
|
|
2018-05-17 20:55:53 +00:00
|
|
|
{% for type in by_category["structure"] %}
|
2018-08-27 21:12:56 +00:00
|
|
|
struct {{as_cppType(type.name)}};
|
2018-05-17 20:55:53 +00:00
|
|
|
{% endfor %}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
template<typename Derived, typename CType>
|
|
|
|
class ObjectBase {
|
|
|
|
public:
|
2017-05-29 19:27:28 +00:00
|
|
|
ObjectBase() = default;
|
2017-11-23 21:04:26 +00:00
|
|
|
ObjectBase(CType handle): mHandle(handle) {
|
2018-07-18 13:26:19 +00:00
|
|
|
if (mHandle) Derived::DawnReference(mHandle);
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
~ObjectBase() {
|
2018-07-18 13:26:19 +00:00
|
|
|
if (mHandle) Derived::DawnRelease(mHandle);
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 10:42:49 +00:00
|
|
|
ObjectBase(ObjectBase const& other)
|
|
|
|
: ObjectBase(other.Get()) {
|
|
|
|
}
|
|
|
|
Derived& operator=(ObjectBase const& other) {
|
|
|
|
if (&other != this) {
|
|
|
|
if (mHandle) Derived::DawnRelease(mHandle);
|
|
|
|
mHandle = other.mHandle;
|
|
|
|
if (mHandle) Derived::DawnReference(mHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<Derived&>(*this);
|
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
ObjectBase(ObjectBase&& other) {
|
2017-11-23 21:04:26 +00:00
|
|
|
mHandle = other.mHandle;
|
|
|
|
other.mHandle = 0;
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
Derived& operator=(ObjectBase&& other) {
|
2018-10-25 10:42:49 +00:00
|
|
|
if (&other != this) {
|
|
|
|
if (mHandle) Derived::DawnRelease(mHandle);
|
|
|
|
mHandle = other.mHandle;
|
|
|
|
other.mHandle = 0;
|
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
return static_cast<Derived&>(*this);
|
|
|
|
}
|
|
|
|
|
2018-12-05 04:10:52 +00:00
|
|
|
ObjectBase(std::nullptr_t) {}
|
|
|
|
Derived& operator=(std::nullptr_t) {
|
2018-12-04 12:13:03 +00:00
|
|
|
if (mHandle != nullptr) {
|
|
|
|
Derived::DawnRelease(mHandle);
|
|
|
|
mHandle = nullptr;
|
|
|
|
}
|
|
|
|
return static_cast<Derived&>(*this);
|
|
|
|
}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
explicit operator bool() const {
|
2017-11-23 21:04:26 +00:00
|
|
|
return mHandle != nullptr;
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
CType Get() const {
|
2017-11-23 21:04:26 +00:00
|
|
|
return mHandle;
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
CType Release() {
|
2017-11-23 21:04:26 +00:00
|
|
|
CType result = mHandle;
|
|
|
|
mHandle = 0;
|
2017-04-20 18:38:20 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
static Derived Acquire(CType handle) {
|
|
|
|
Derived result;
|
2017-11-23 21:04:26 +00:00
|
|
|
result.mHandle = handle;
|
2017-04-20 18:38:20 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2017-11-23 21:04:26 +00:00
|
|
|
CType mHandle = nullptr;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{% macro render_cpp_method_declaration(type, method) %}
|
|
|
|
{% set CppType = as_cppType(type.name) %}
|
2019-04-01 21:48:38 +00:00
|
|
|
DAWN_EXPORT {{as_cppType(method.return_type.name)}} {{method.name.CamelCase()}}(
|
2017-04-20 18:38:20 +00:00
|
|
|
{%- for arg in method.arguments -%}
|
|
|
|
{%- if not loop.first %}, {% endif -%}
|
|
|
|
{%- if arg.type.category == "object" and arg.annotation == "value" -%}
|
|
|
|
{{as_cppType(arg.type.name)}} const& {{as_varName(arg.name)}}
|
|
|
|
{%- else -%}
|
|
|
|
{{as_annotated_cppType(arg)}}
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endfor -%}
|
|
|
|
) const
|
|
|
|
{%- endmacro %}
|
|
|
|
|
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
{% set CppType = as_cppType(type.name) %}
|
|
|
|
{% set CType = as_cType(type.name) %}
|
2019-01-09 09:05:18 +00:00
|
|
|
class {{CppType}} : public ObjectBase<{{CppType}}, {{CType}}> {
|
2017-04-20 18:38:20 +00:00
|
|
|
public:
|
|
|
|
using ObjectBase::ObjectBase;
|
|
|
|
using ObjectBase::operator=;
|
|
|
|
|
2017-04-20 18:42:36 +00:00
|
|
|
{% for method in native_methods(type) %}
|
2017-04-20 18:38:20 +00:00
|
|
|
{{render_cpp_method_declaration(type, method)}};
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend ObjectBase<{{CppType}}, {{CType}}>;
|
2019-01-09 09:05:18 +00:00
|
|
|
static DAWN_EXPORT void DawnReference({{CType}} handle);
|
|
|
|
static DAWN_EXPORT void DawnRelease({{CType}} handle);
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
2018-08-27 21:12:56 +00:00
|
|
|
{% for type in by_category["structure"] %}
|
|
|
|
struct {{as_cppType(type.name)}} {
|
|
|
|
{% if type.extensible %}
|
|
|
|
const void* nextInChain = nullptr;
|
|
|
|
{% endif %}
|
|
|
|
{% for member in type.members %}
|
|
|
|
{{as_annotated_cppType(member)}};
|
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
2018-07-18 12:44:20 +00:00
|
|
|
} // namespace dawn
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-24 14:30:14 +00:00
|
|
|
#endif // DAWN_DAWNCPP_H_
|