Chromium Code Reviews| Index: gpu/command_buffer/common/id_type.h |
| diff --git a/content/common/id_type.h b/gpu/command_buffer/common/id_type.h |
| similarity index 78% |
| rename from content/common/id_type.h |
| rename to gpu/command_buffer/common/id_type.h |
| index 5e1c45353acf3ea642b8ebba92c54509020d3511..a72daab14ee78db739c1e86f9e364ae2a87dc22c 100644 |
| --- a/content/common/id_type.h |
| +++ b/gpu/command_buffer/common/id_type.h |
| @@ -2,14 +2,18 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CONTENT_COMMON_ID_TYPE_H_ |
| -#define CONTENT_COMMON_ID_TYPE_H_ |
| +#ifndef GPU_COMMAND_BUFFER_COMMON_ID_TYPE_H_ |
| +#define GPU_COMMAND_BUFFER_COMMON_ID_TYPE_H_ |
| #include <stdint.h> |
| #include <cstddef> |
| #include <ostream> |
| #include <type_traits> |
| +#include "base/pickle.h" |
| +#include "ipc/ipc_message_utils.h" |
| +#include "ipc/ipc_param_traits.h" |
|
piman
2016/02/09 23:29:32
gpu/command_buffer shouldn't depend on IPC. You ca
Łukasz Anforowicz
2016/02/10 22:18:14
Done (into a separate gpu/ipc/id_type_traits.h hea
|
| + |
| // IdType32<>, IdType64<>, etc. wrap an integer id in a custom, type-safe type. |
| // |
| // IdType32<Foo> is an alternative to int, for a class Foo with methods like: |
| @@ -28,7 +32,7 @@ |
| // IdType32<T> / IdTypeU32<T>: Signed / unsigned 32-bit IDs |
| // IdType64<T> / IdTypeU64<T>: Signed / unsigned 64-bit IDs |
| // IdType<>: For when you need a different underlying type or |
| -// a default/invalid value other than zero. |
| +// a default/null value other than zero. |
| // |
| // IdType32<Foo> behaves just like an int32_t in the following aspects: |
| // - it can be used as a key in std::map and/or std::unordered_map; |
| @@ -42,7 +46,7 @@ |
| // - it ensures initialization to zero and allows checking against |
| // default-initialized values via is_null method. |
| -namespace content { |
| +namespace gpu { |
| template <typename TypeMarker, typename WrappedType, WrappedType kInvalidValue> |
| class IdType { |
| @@ -102,6 +106,31 @@ std::ostream& operator<<( |
| return stream << id.GetUnsafeValue(); |
| } |
| -} // namespace content |
| +} // namespace gpu |
| + |
| +namespace IPC { |
| + |
| +template <typename TypeMarker, typename WrappedType, WrappedType kInvalidValue> |
| +struct ParamTraits<gpu::IdType<TypeMarker, WrappedType, kInvalidValue>> { |
| + typedef gpu::IdType<TypeMarker, WrappedType, kInvalidValue> param_type; |
| + typedef ParamTraits<WrappedType> base_param_traits; |
| + static void Write(base::Pickle* m, const param_type& p) { |
| + base_param_traits::Write(m, p.GetUnsafeValue()); |
| + } |
| + static bool Read(const base::Pickle* m, |
| + base::PickleIterator* iter, |
| + param_type* r) { |
| + WrappedType value; |
| + if (!base_param_traits::Read(m, iter, &value)) |
| + return false; |
| + *r = param_type::FromUnsafeValue(value); |
| + return true; |
| + } |
| + static void Log(const param_type& p, std::string* l) { |
| + base_param_traits::Log(p.GetUnsafeValue(), l); |
| + } |
| +}; |
| + |
| +} // namespace IPC |
| #endif // CONTENT_COMMON_ID_TYPE_H_ |