OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_GFX_MOJO_ICC_PROFILE_STRUCT_TRAITS_H_ | |
6 #define UI_GFX_MOJO_ICC_PROFILE_STRUCT_TRAITS_H_ | |
7 | |
8 #include <algorithm> | |
9 #include <memory> | |
10 | |
11 #include "base/memory/ptr_util.h" | |
12 #include "mojo/public/cpp/bindings/struct_traits.h" | |
13 #include "ui/gfx/icc_profile.h" | |
14 #include "ui/gfx/mojo/icc_profile.mojom.h" | |
15 | |
16 namespace mojo { | |
17 | |
18 template <> | |
19 struct StructTraits<gfx::mojom::ICCProfileDataView, gfx::ICCProfile> { | |
20 static bool valid(const gfx::ICCProfile& profile) { return profile.valid_; } | |
21 static const std::vector<int8_t>& data(const gfx::ICCProfile& profile, | |
22 void* context) { | |
23 return *static_cast<std::vector<int8_t>*>(context); | |
24 } | |
25 static uint64_t id(const gfx::ICCProfile& profile) { return profile.id_; } | |
26 | |
27 static void* SetUpContext(const gfx::ICCProfile& profile) { | |
28 std::unique_ptr<std::vector<int8_t>> data = | |
dcheng
2016/09/30 06:30:37
Nit: out of line SetUpContext / TearDownContext.
Ken Rockot(use gerrit already)
2016/09/30 20:02:54
Better: I removed these and eliminated the extra c
| |
29 base::MakeUnique<std::vector<int8_t>>(profile.GetData().size()); | |
30 std::copy(profile.GetData().begin(), profile.GetData().end(), | |
31 data->begin()); | |
32 return data.release(); | |
33 } | |
34 | |
35 static void TearDownContext(const gfx::ICCProfile& profile, void* context) { | |
36 delete static_cast<std::vector<uint8_t>*>(context); | |
37 } | |
38 | |
39 static bool Read(gfx::mojom::ICCProfileDataView data, | |
40 gfx::ICCProfile* profile); | |
41 }; | |
42 | |
43 } // namespace mojo | |
44 | |
45 #endif // UI_GFX_MOJO_ICC_PROFILE_STRUCT_TRAITS_H_ | |
OLD | NEW |