Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: content/common/fontmgr_messages.h

Issue 132113015: IPC interface for font management. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Match final interface and cleanup usage. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 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 // IPC messages for font discovery.
6 // Multiply-included message file, hence no include guard.
7
8 #include <string>
9
10 #include "content/common/content_export.h"
11 #include "content/common/content_param_traits.h"
12 #include "content/public/common/common_param_traits.h"
13 #include "ipc/ipc_message_macros.h"
14 #include "skia/ext/refptr.h"
15 #include "third_party/skia/include/core/SkDataTable.h"
16 #include "third_party/skia/include/core/SkStream.h"
17 #include "third_party/skia/include/ports/SkFontStyle.h"
18 #include "third_party/skia/include/ports/SkRemotableFontMgr.h"
19
20 #undef IPC_MESSAGE_EXPORT
21 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
22
23 #ifdef IPC_MESSAGE_START
24 #error IPC_MESSAGE_START
25 #endif
26
27 #define IPC_MESSAGE_START FontMsgStart
28
29 #ifndef CONTENT_COMMON_FONTMGR_MESSAGES_H_
30 #define CONTENT_COMMON_FONTMGR_MESSAGES_H_
31
32 namespace IPC {
33
34 template<class T>
35 class Optional {
36 public:
37 Optional() : set_(false) {}
38
39 void emplace(const T& value) {
40 value_ = value;
41 set_ = true;
42 }
43
44 void setHasValue() { set_ = true; }
45
46 const T& value() const { return value_; }
47 T& value() { return value_; }
48
49 const T* operator->() const { return &value_; }
50 T* operator->() { return &value_; }
51 const T& operator*() const { return value_ }
52 T& operator*() { return value_ }
53
54 typedef bool Optional::*unspecified_bool_type;
55 operator unspecified_bool_type() const {
56 return set_ ? &Optional::set_ : NULL;
57 }
58
59 private:
60 bool set_;
61 T value_;
62 };
63
64 template <class P>
65 struct ParamTraits<Optional<P> > {
66 typedef Optional<P> param_type;
67 static void Write(Message* m, const param_type& p) {
68 m->WriteBool(p);
69 if (p)
70 WriteParam(m, p.value());
71 }
72 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
73 bool has_value;
74 if (!m->ReadBool(iter, &has_value))
75 return false;
76
77 if (has_value) {
78 if (!ReadParam(m, iter, &r->value()))
79 return false;
80 r->setHasValue();
81 }
82 return true;
83 }
84 static void Log(const param_type& p, std::string* l) {
85 l->append(p ? "Optional (has value)" : "Optional (no value)");
86 if (p)
87 LogParam(p.value(), l);
88 }
89 };
90
91 // SkStream is not default constructable, no ParamTraits<T>.
92 template<>
93 struct ParamTraits<skia::RefPtr<SkStreamAsset> > {
94 typedef skia::RefPtr<SkStreamAsset> param_type;
95 static void Write(Message* m, const param_type& p);
96 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
97 static void Log(const param_type& p, std::string* l);
98 };
99
100 // SkDataTable is not default constructable, no ParamTraits<T>.
101 template<>
102 struct ParamTraits<skia::RefPtr<SkDataTable> > {
103 typedef skia::RefPtr<SkDataTable> param_type;
104 static void Write(Message* m, const param_type& p);
105 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
106 static void Log(const param_type& p, std::string* l);
107 };
108
109 // SkRemotableFontIdentitySet not default constructable, no ParamTraits<T>.
110 template<>
111 struct ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> > {
112 typedef skia::RefPtr<SkRemotableFontIdentitySet> param_type;
113 static void Write(Message* m, const param_type& p);
114 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
115 static void Log(const param_type& p, std::string* l);
116 };
117
118 template<>
119 struct ParamTraits<SkFontStyle> {
120 typedef SkFontStyle param_type;
121 static void Write(Message* m, const param_type& p);
122 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
123 static void Log(const param_type& p, std::string* l);
124 };
125
126 } // namespace IPC
127
128 #endif // CONTENT_COMMON_FONTMGR_MESSAGES_H_
129
130 IPC_STRUCT_TRAITS_BEGIN(SkFontIdentity)
131 IPC_STRUCT_TRAITS_MEMBER(fDataId)
132 IPC_STRUCT_TRAITS_MEMBER(fTtcIndex)
133 IPC_STRUCT_TRAITS_MEMBER(fFontStyle)
134 IPC_STRUCT_TRAITS_END()
135
136 IPC_SYNC_MESSAGE_ROUTED0_1(FontMsg_GetFamilyNames,
137 skia::RefPtr<SkDataTable> /*family_names*/)
138
139 IPC_SYNC_MESSAGE_ROUTED1_1(FontMsg_GetIndex,
140 int /*family_index*/,
141 skia::RefPtr<SkRemotableFontIdentitySet> /*styles*/)
142
143 IPC_SYNC_MESSAGE_ROUTED2_1(FontMsg_MatchIndexStyle,
144 int /*family_index*/,
145 SkFontStyle /*style*/,
146 SkFontIdentity /*identity*/)
147
148 IPC_SYNC_MESSAGE_ROUTED1_1(FontMsg_MatchName,
149 IPC::Optional<std::string> /*family_name*/,
150 skia::RefPtr<SkRemotableFontIdentitySet> /*styles*/)
151
152 IPC_SYNC_MESSAGE_ROUTED2_1(FontMsg_MatchNameStyle,
153 IPC::Optional<std::string> /*family_name*/,
154 SkFontStyle /*style*/,
155 SkFontIdentity /*identity*/)
156
157 IPC_SYNC_MESSAGE_ROUTED4_1(FontMsg_MatchNameStyleCharacter,
158 IPC::Optional<std::string> /*family_name*/,
159 SkFontStyle /*style*/,
160 IPC::Optional<std::string> /*bpc47*/,
161 uint32_t /*character*/,
162 SkFontIdentity /*identity*/)
163
164 IPC_SYNC_MESSAGE_ROUTED1_1(FontMsg_GetData,
165 int /*data_id*/,
166 skia::RefPtr<SkStreamAsset> /* font_data */)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698