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

Side by Side Diff: ppapi/proxy/ppb_font_proxy.cc

Issue 6334016: Refactor PPAPI proxy resource handling to maintain which host they came from,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « ppapi/proxy/ppb_font_proxy.h ('k') | ppapi/proxy/ppb_graphics_2d_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/ppb_font_proxy.h" 5 #include "ppapi/proxy/ppb_font_proxy.h"
6 6
7 #include "ppapi/c/dev/ppb_font_dev.h" 7 #include "ppapi/c/dev/ppb_font_dev.h"
8 #include "ppapi/proxy/plugin_dispatcher.h" 8 #include "ppapi/proxy/plugin_dispatcher.h"
9 #include "ppapi/proxy/plugin_resource.h" 9 #include "ppapi/proxy/plugin_resource.h"
10 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/proxy/ppapi_messages.h"
11 11
12 namespace pp { 12 namespace pp {
13 namespace proxy { 13 namespace proxy {
14 14
15 class Font : public PluginResource { 15 class Font : public PluginResource {
16 public: 16 public:
17 Font(PP_Instance instance); 17 Font(const HostResource& resource);
18 virtual ~Font(); 18 virtual ~Font();
19 19
20 // PluginResource overrides. 20 // PluginResource overrides.
21 virtual Font* AsFont() { return this; } 21 virtual Font* AsFont() { return this; }
22 22
23 PP_FontDescription_Dev& desc() { return desc_; } 23 PP_FontDescription_Dev& desc() { return desc_; }
24 PP_FontDescription_Dev* desc_ptr() { return &desc_; } 24 PP_FontDescription_Dev* desc_ptr() { return &desc_; }
25 PP_FontMetrics_Dev& metrics() { return metrics_; } 25 PP_FontMetrics_Dev& metrics() { return metrics_; }
26 26
27 private: 27 private:
28 PP_FontDescription_Dev desc_; 28 PP_FontDescription_Dev desc_;
29 PP_FontMetrics_Dev metrics_; 29 PP_FontMetrics_Dev metrics_;
30 30
31 DISALLOW_COPY_AND_ASSIGN(Font); 31 DISALLOW_COPY_AND_ASSIGN(Font);
32 }; 32 };
33 33
34 Font::Font(PP_Instance instance) : PluginResource(instance) { 34 Font::Font(const HostResource& resource) : PluginResource(resource) {
35 memset(&desc_, 0, sizeof(PP_FontDescription_Dev)); 35 memset(&desc_, 0, sizeof(PP_FontDescription_Dev));
36 desc_.face.type = PP_VARTYPE_UNDEFINED; 36 desc_.face.type = PP_VARTYPE_UNDEFINED;
37 memset(&metrics_, 0, sizeof(PP_FontMetrics_Dev)); 37 memset(&metrics_, 0, sizeof(PP_FontMetrics_Dev));
38 } 38 }
39 39
40 Font::~Font() { 40 Font::~Font() {
41 PluginVarTracker::GetInstance()->Release(desc_.face); 41 PluginVarTracker::GetInstance()->Release(desc_.face);
42 } 42 }
43 43
44 namespace { 44 namespace {
45 45
46 PP_Resource Create(PP_Instance instance, 46 PP_Resource Create(PP_Instance instance,
47 const PP_FontDescription_Dev* description) { 47 const PP_FontDescription_Dev* description) {
48 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 48 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
49 if (!dispatcher) 49 if (!dispatcher)
50 return 0; 50 return 0;
51 51
52 SerializedFontDescription in_description; 52 SerializedFontDescription in_description;
53 in_description.SetFromPPFontDescription(dispatcher, *description, true); 53 in_description.SetFromPPFontDescription(dispatcher, *description, true);
54 54
55 PP_Resource result; 55 HostResource result;
56 SerializedFontDescription out_description; 56 SerializedFontDescription out_description;
57 std::string out_metrics; 57 std::string out_metrics;
58 dispatcher->Send(new PpapiHostMsg_PPBFont_Create( 58 dispatcher->Send(new PpapiHostMsg_PPBFont_Create(
59 INTERFACE_ID_PPB_FONT, 59 INTERFACE_ID_PPB_FONT,
60 instance, in_description, &result, &out_description, &out_metrics)); 60 instance, in_description, &result, &out_description, &out_metrics));
61 61
62 if (!result) 62 if (result.is_null())
63 return 0; // Failure creating font. 63 return 0; // Failure creating font.
64 64
65 linked_ptr<Font> object(new Font(instance)); 65 linked_ptr<Font> object(new Font(result));
66 out_description.SetToPPFontDescription(dispatcher, object->desc_ptr(), true); 66 out_description.SetToPPFontDescription(dispatcher, object->desc_ptr(), true);
67 67
68 // Convert the metrics, this is just serialized as a string of bytes. 68 // Convert the metrics, this is just serialized as a string of bytes.
69 if (out_metrics.size() != sizeof(PP_FontMetrics_Dev)) 69 if (out_metrics.size() != sizeof(PP_FontMetrics_Dev))
70 return 0; 70 return 0;
71 memcpy(&object->metrics(), out_metrics.data(), sizeof(PP_FontMetrics_Dev)); 71 memcpy(&object->metrics(), out_metrics.data(), sizeof(PP_FontMetrics_Dev));
72 72
73 PluginResourceTracker::GetInstance()->AddResource(result, object); 73 return PluginResourceTracker::GetInstance()->AddResource(object);
74 return result;
75 } 74 }
76 75
77 PP_Bool IsFont(PP_Resource resource) { 76 PP_Bool IsFont(PP_Resource resource) {
78 Font* object = PluginResource::GetAs<Font>(resource); 77 Font* object = PluginResource::GetAs<Font>(resource);
79 return BoolToPPBool(!!object); 78 return BoolToPPBool(!!object);
80 } 79 }
81 80
82 PP_Bool Describe(PP_Resource font_id, 81 PP_Bool Describe(PP_Resource font_id,
83 PP_FontDescription_Dev* description, 82 PP_FontDescription_Dev* description,
84 PP_FontMetrics_Dev* metrics) { 83 PP_FontMetrics_Dev* metrics) {
(...skipping 10 matching lines...) Expand all
95 return PP_TRUE; 94 return PP_TRUE;
96 } 95 }
97 96
98 PP_Bool DrawTextAt(PP_Resource font_id, 97 PP_Bool DrawTextAt(PP_Resource font_id,
99 PP_Resource image_data, 98 PP_Resource image_data,
100 const PP_TextRun_Dev* text, 99 const PP_TextRun_Dev* text,
101 const PP_Point* position, 100 const PP_Point* position,
102 uint32_t color, 101 uint32_t color,
103 const PP_Rect* clip, 102 const PP_Rect* clip,
104 PP_Bool image_data_is_opaque) { 103 PP_Bool image_data_is_opaque) {
105 Font* object = PluginResource::GetAs<Font>(font_id); 104 Font* font_object = PluginResource::GetAs<Font>(font_id);
106 if (!object) 105 if (!font_object)
106 return PP_FALSE;
107 PluginResource* image_object = PluginResourceTracker::GetInstance()->
108 GetResourceObject(image_data);
109 if (!image_object)
110 return PP_FALSE;
111 if (font_object->instance() != image_object->instance())
107 return PP_FALSE; 112 return PP_FALSE;
108 113
109 PPBFont_DrawTextAt_Params params; 114 PPBFont_DrawTextAt_Params params;
110 params.font = font_id; 115 params.font = font_object->host_resource();
111 params.image_data = image_data; 116 params.image_data = image_object->host_resource();
112 params.text_is_rtl = text->rtl; 117 params.text_is_rtl = text->rtl;
113 params.override_direction = text->override_direction; 118 params.override_direction = text->override_direction;
114 params.position = *position; 119 params.position = *position;
115 params.color = color; 120 params.color = color;
116 if (clip) { 121 if (clip) {
117 params.clip = *clip; 122 params.clip = *clip;
118 params.clip_is_null = false; 123 params.clip_is_null = false;
119 } else { 124 } else {
120 params.clip = PP_MakeRectFromXYWH(0, 0, 0, 0); 125 params.clip = PP_MakeRectFromXYWH(0, 0, 0, 0);
121 params.clip_is_null = true; 126 params.clip_is_null = true;
122 } 127 }
123 params.image_data_is_opaque = image_data_is_opaque; 128 params.image_data_is_opaque = image_data_is_opaque;
124 129
125 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); 130 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(
131 image_object->instance());
126 PP_Bool result = PP_FALSE; 132 PP_Bool result = PP_FALSE;
127 if (dispatcher) { 133 if (dispatcher) {
128 dispatcher->Send(new PpapiHostMsg_PPBFont_DrawTextAt( 134 dispatcher->Send(new PpapiHostMsg_PPBFont_DrawTextAt(
129 INTERFACE_ID_PPB_FONT, 135 INTERFACE_ID_PPB_FONT,
130 SerializedVarSendInput(dispatcher, text->text), 136 SerializedVarSendInput(dispatcher, text->text),
131 params, &result)); 137 params, &result));
132 } 138 }
133 return result; 139 return result;
134 } 140 }
135 141
136 int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) { 142 int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) {
137 Font* object = PluginResource::GetAs<Font>(font_id); 143 Font* object = PluginResource::GetAs<Font>(font_id);
138 if (!object) 144 if (!object)
139 return -1; 145 return -1;
140 146
141 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); 147 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
142 int32_t result = 0; 148 int32_t result = 0;
143 dispatcher->Send(new PpapiHostMsg_PPBFont_MeasureText( 149 dispatcher->Send(new PpapiHostMsg_PPBFont_MeasureText(
144 INTERFACE_ID_PPB_FONT, font_id, 150 INTERFACE_ID_PPB_FONT, object->host_resource(),
145 SerializedVarSendInput(dispatcher, text->text), 151 SerializedVarSendInput(dispatcher, text->text),
146 text->rtl, text->override_direction, &result)); 152 text->rtl, text->override_direction, &result));
147 return result; 153 return result;
148 } 154 }
149 155
150 uint32_t CharacterOffsetForPixel(PP_Resource font_id, 156 uint32_t CharacterOffsetForPixel(PP_Resource font_id,
151 const PP_TextRun_Dev* text, 157 const PP_TextRun_Dev* text,
152 int32_t pixel_position) { 158 int32_t pixel_position) {
153 Font* object = PluginResource::GetAs<Font>(font_id); 159 Font* object = PluginResource::GetAs<Font>(font_id);
154 if (!object) 160 if (!object)
155 return -1; 161 return -1;
156 162
157 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); 163 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
158 uint32_t result = 0; 164 uint32_t result = 0;
159 dispatcher->Send(new PpapiHostMsg_PPBFont_CharacterOffsetForPixel( 165 dispatcher->Send(new PpapiHostMsg_PPBFont_CharacterOffsetForPixel(
160 INTERFACE_ID_PPB_FONT, font_id, 166 INTERFACE_ID_PPB_FONT, object->host_resource(),
161 SerializedVarSendInput(dispatcher, text->text), 167 SerializedVarSendInput(dispatcher, text->text),
162 text->rtl, text->override_direction, pixel_position, &result)); 168 text->rtl, text->override_direction, pixel_position, &result));
163 return result; 169 return result;
164 } 170 }
165 171
166 int32_t PixelOffsetForCharacter(PP_Resource font_id, 172 int32_t PixelOffsetForCharacter(PP_Resource font_id,
167 const PP_TextRun_Dev* text, 173 const PP_TextRun_Dev* text,
168 uint32_t char_offset) { 174 uint32_t char_offset) {
169 Font* object = PluginResource::GetAs<Font>(font_id); 175 Font* object = PluginResource::GetAs<Font>(font_id);
170 if (!object) 176 if (!object)
171 return -1; 177 return -1;
172 178
173 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); 179 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
174 int32_t result = 0; 180 int32_t result = 0;
175 dispatcher->Send(new PpapiHostMsg_PPBFont_PixelOffsetForCharacter( 181 dispatcher->Send(new PpapiHostMsg_PPBFont_PixelOffsetForCharacter(
176 INTERFACE_ID_PPB_FONT, font_id, 182 INTERFACE_ID_PPB_FONT, object->host_resource(),
177 SerializedVarSendInput(dispatcher, text->text), 183 SerializedVarSendInput(dispatcher, text->text),
178 text->rtl, text->override_direction, char_offset, &result)); 184 text->rtl, text->override_direction, char_offset, &result));
179 return result; 185 return result;
180 } 186 }
181 187
182 const PPB_Font_Dev ppb_font_interface = { 188 const PPB_Font_Dev ppb_font_interface = {
183 &Create, 189 &Create,
184 &IsFont, 190 &IsFont,
185 &Describe, 191 &Describe,
186 &DrawTextAt, 192 &DrawTextAt,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFont_PixelOffsetForCharacter, 227 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFont_PixelOffsetForCharacter,
222 OnMsgPixelOffsetForCharacter) 228 OnMsgPixelOffsetForCharacter)
223 IPC_MESSAGE_UNHANDLED(handled = false) 229 IPC_MESSAGE_UNHANDLED(handled = false)
224 IPC_END_MESSAGE_MAP() 230 IPC_END_MESSAGE_MAP()
225 return handled; 231 return handled;
226 } 232 }
227 233
228 void PPB_Font_Proxy::OnMsgCreate( 234 void PPB_Font_Proxy::OnMsgCreate(
229 PP_Instance instance, 235 PP_Instance instance,
230 const SerializedFontDescription& in_description, 236 const SerializedFontDescription& in_description,
231 PP_Resource* result, 237 HostResource* result,
232 SerializedFontDescription* out_description, 238 SerializedFontDescription* out_description,
233 std::string* out_metrics) { 239 std::string* out_metrics) {
234 // Convert the face name in the input description. 240 // Convert the face name in the input description.
235 PP_FontDescription_Dev in_pp_desc; 241 PP_FontDescription_Dev in_pp_desc;
236 in_description.SetToPPFontDescription(dispatcher(), &in_pp_desc, false); 242 in_description.SetToPPFontDescription(dispatcher(), &in_pp_desc, false);
237 243
238 // Make sure the output is always defined so we can still serialize it back 244 // Make sure the output is always defined so we can still serialize it back
239 // to the plugin below. 245 // to the plugin below.
240 PP_FontDescription_Dev out_pp_desc; 246 PP_FontDescription_Dev out_pp_desc;
241 memset(&out_pp_desc, 0, sizeof(PP_FontDescription_Dev)); 247 memset(&out_pp_desc, 0, sizeof(PP_FontDescription_Dev));
242 out_pp_desc.face = PP_MakeUndefined(); 248 out_pp_desc.face = PP_MakeUndefined();
243 249
244 *result = ppb_font_target()->Create(instance, &in_pp_desc); 250 result->SetHostResource(instance,
245 if (*result) { 251 ppb_font_target()->Create(instance, &in_pp_desc));
252 if (result->is_null()) {
246 // Get the metrics and resulting description to return to the browser. 253 // Get the metrics and resulting description to return to the browser.
247 PP_FontMetrics_Dev metrics; 254 PP_FontMetrics_Dev metrics;
248 if (ppb_font_target()->Describe(*result, &out_pp_desc, &metrics)) { 255 if (ppb_font_target()->Describe(result->host_resource(), &out_pp_desc,
256 &metrics)) {
249 out_metrics->assign(reinterpret_cast<const char*>(&metrics), 257 out_metrics->assign(reinterpret_cast<const char*>(&metrics),
250 sizeof(PP_FontMetrics_Dev)); 258 sizeof(PP_FontMetrics_Dev));
251 } 259 }
252 } 260 }
253 261
254 // This must always get called or it will assert when trying to serialize 262 // This must always get called or it will assert when trying to serialize
255 // the un-filled-in SerializedFontDescription as the return value. 263 // the un-filled-in SerializedFontDescription as the return value.
256 out_description->SetFromPPFontDescription(dispatcher(), out_pp_desc, false); 264 out_description->SetFromPPFontDescription(dispatcher(), out_pp_desc, false);
257 } 265 }
258 266
259 void PPB_Font_Proxy::OnMsgDrawTextAt(SerializedVarReceiveInput text, 267 void PPB_Font_Proxy::OnMsgDrawTextAt(SerializedVarReceiveInput text,
260 const PPBFont_DrawTextAt_Params& params, 268 const PPBFont_DrawTextAt_Params& params,
261 PP_Bool* result) { 269 PP_Bool* result) {
262 PP_TextRun_Dev run; 270 PP_TextRun_Dev run;
263 run.text = text.Get(dispatcher()); 271 run.text = text.Get(dispatcher());
264 run.rtl = params.text_is_rtl; 272 run.rtl = params.text_is_rtl;
265 run.override_direction = params.override_direction; 273 run.override_direction = params.override_direction;
266 274
267 *result = ppb_font_target()->DrawTextAt(params.font, params.image_data, 275 *result = ppb_font_target()->DrawTextAt(params.font.host_resource(),
268 &run, &params.position, params.color, 276 params.image_data.host_resource(), &run, &params.position, params.color,
269 params.clip_is_null ? NULL : &params.clip, params.image_data_is_opaque); 277 params.clip_is_null ? NULL : &params.clip, params.image_data_is_opaque);
270 } 278 }
271 279
272 void PPB_Font_Proxy::OnMsgMeasureText(PP_Resource font, 280 void PPB_Font_Proxy::OnMsgMeasureText(HostResource font,
273 SerializedVarReceiveInput text, 281 SerializedVarReceiveInput text,
274 PP_Bool text_is_rtl, 282 PP_Bool text_is_rtl,
275 PP_Bool override_direction, 283 PP_Bool override_direction,
276 int32_t* result) { 284 int32_t* result) {
277 PP_TextRun_Dev run; 285 PP_TextRun_Dev run;
278 run.text = text.Get(dispatcher()); 286 run.text = text.Get(dispatcher());
279 run.rtl = text_is_rtl; 287 run.rtl = text_is_rtl;
280 run.override_direction = override_direction; 288 run.override_direction = override_direction;
281 289
282 *result = ppb_font_target()->MeasureText(font, &run); 290 *result = ppb_font_target()->MeasureText(font.host_resource(), &run);
283 } 291 }
284 292
285 void PPB_Font_Proxy::OnMsgCharacterOffsetForPixel( 293 void PPB_Font_Proxy::OnMsgCharacterOffsetForPixel(
286 PP_Resource font, 294 HostResource font,
287 SerializedVarReceiveInput text, 295 SerializedVarReceiveInput text,
288 PP_Bool text_is_rtl, 296 PP_Bool text_is_rtl,
289 PP_Bool override_direction, 297 PP_Bool override_direction,
290 int32_t pixel_pos, 298 int32_t pixel_pos,
291 uint32_t* result) { 299 uint32_t* result) {
292 PP_TextRun_Dev run; 300 PP_TextRun_Dev run;
293 run.text = text.Get(dispatcher()); 301 run.text = text.Get(dispatcher());
294 run.rtl = text_is_rtl; 302 run.rtl = text_is_rtl;
295 run.override_direction = override_direction; 303 run.override_direction = override_direction;
296 304
297 *result = ppb_font_target()->CharacterOffsetForPixel(font, &run, pixel_pos); 305 *result = ppb_font_target()->CharacterOffsetForPixel(font.host_resource(),
306 &run, pixel_pos);
298 } 307 }
299 308
300 void PPB_Font_Proxy::OnMsgPixelOffsetForCharacter( 309 void PPB_Font_Proxy::OnMsgPixelOffsetForCharacter(
301 PP_Resource font, 310 HostResource font,
302 SerializedVarReceiveInput text, 311 SerializedVarReceiveInput text,
303 PP_Bool text_is_rtl, 312 PP_Bool text_is_rtl,
304 PP_Bool override_direction, 313 PP_Bool override_direction,
305 uint32_t char_offset, 314 uint32_t char_offset,
306 int32_t* result) { 315 int32_t* result) {
307 PP_TextRun_Dev run; 316 PP_TextRun_Dev run;
308 run.text = text.Get(dispatcher()); 317 run.text = text.Get(dispatcher());
309 run.rtl = text_is_rtl; 318 run.rtl = text_is_rtl;
310 run.override_direction = override_direction; 319 run.override_direction = override_direction;
311 320
312 *result = ppb_font_target()->PixelOffsetForCharacter(font, &run, char_offset); 321 *result = ppb_font_target()->PixelOffsetForCharacter(font.host_resource(),
322 &run, char_offset);
313 } 323 }
314 324
315 } // namespace proxy 325 } // namespace proxy
316 } // namespace pp 326 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_font_proxy.h ('k') | ppapi/proxy/ppb_graphics_2d_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698