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

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

Issue 6282007: First pass at making the proxy handle multiple renderers. This associates the... (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_flash_proxy.cc ('k') | ppapi/proxy/ppb_fullscreen_proxy.cc » ('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) 2010 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(); 17 Font(PP_Instance instance);
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() { 34 Font::Font(PP_Instance instance) : PluginResource(instance) {
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 PluginDispatcher::Get()->plugin_var_tracker()->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::Get(); 48 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
49 if (!dispatcher)
50 return 0;
49 51
50 SerializedFontDescription in_description; 52 SerializedFontDescription in_description;
51 in_description.SetFromPPFontDescription(dispatcher, *description, true); 53 in_description.SetFromPPFontDescription(dispatcher, *description, true);
52 54
53 PP_Resource result; 55 PP_Resource result;
54 SerializedFontDescription out_description; 56 SerializedFontDescription out_description;
55 std::string out_metrics; 57 std::string out_metrics;
56 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFont_Create( 58 dispatcher->Send(new PpapiHostMsg_PPBFont_Create(
57 INTERFACE_ID_PPB_FONT, 59 INTERFACE_ID_PPB_FONT,
58 instance, in_description, &result, &out_description, &out_metrics)); 60 instance, in_description, &result, &out_description, &out_metrics));
59 61
60 if (!result) 62 if (!result)
61 return 0; // Failure creating font. 63 return 0; // Failure creating font.
62 64
63 linked_ptr<Font> object(new Font); 65 linked_ptr<Font> object(new Font(instance));
64 out_description.SetToPPFontDescription(dispatcher, object->desc_ptr(), true); 66 out_description.SetToPPFontDescription(dispatcher, object->desc_ptr(), true);
65 67
66 // 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.
67 if (out_metrics.size() != sizeof(PP_FontMetrics_Dev)) 69 if (out_metrics.size() != sizeof(PP_FontMetrics_Dev))
68 return 0; 70 return 0;
69 memcpy(&object->metrics(), out_metrics.data(), sizeof(PP_FontMetrics_Dev)); 71 memcpy(&object->metrics(), out_metrics.data(), sizeof(PP_FontMetrics_Dev));
70 72
71 dispatcher->plugin_resource_tracker()->AddResource(result, object); 73 PluginResourceTracker::GetInstance()->AddResource(result, object);
72 return result; 74 return result;
73 } 75 }
74 76
75 PP_Bool IsFont(PP_Resource resource) { 77 PP_Bool IsFont(PP_Resource resource) {
76 Font* object = PluginResource::GetAs<Font>(resource); 78 Font* object = PluginResource::GetAs<Font>(resource);
77 return BoolToPPBool(!!object); 79 return BoolToPPBool(!!object);
78 } 80 }
79 81
80 PP_Bool Describe(PP_Resource font_id, 82 PP_Bool Describe(PP_Resource font_id,
81 PP_FontDescription_Dev* description, 83 PP_FontDescription_Dev* description,
82 PP_FontMetrics_Dev* metrics) { 84 PP_FontMetrics_Dev* metrics) {
83 Font* object = PluginResource::GetAs<Font>(font_id); 85 Font* object = PluginResource::GetAs<Font>(font_id);
84 if (!object) 86 if (!object)
85 return PP_FALSE; 87 return PP_FALSE;
86 88
87 // Copy the description, the caller expects its face PP_Var to have a ref 89 // Copy the description, the caller expects its face PP_Var to have a ref
88 // added to it on its behalf. 90 // added to it on its behalf.
89 memcpy(description, &object->desc(), sizeof(PP_FontDescription_Dev)); 91 memcpy(description, &object->desc(), sizeof(PP_FontDescription_Dev));
90 PluginDispatcher::Get()->plugin_var_tracker()->AddRef(description->face); 92 PluginVarTracker::GetInstance()->AddRef(description->face);
91 93
92 memcpy(metrics, &object->metrics(), sizeof(PP_FontMetrics_Dev)); 94 memcpy(metrics, &object->metrics(), sizeof(PP_FontMetrics_Dev));
93 return PP_TRUE; 95 return PP_TRUE;
94 } 96 }
95 97
96 PP_Bool DrawTextAt(PP_Resource font_id, 98 PP_Bool DrawTextAt(PP_Resource font_id,
97 PP_Resource image_data, 99 PP_Resource image_data,
98 const PP_TextRun_Dev* text, 100 const PP_TextRun_Dev* text,
99 const PP_Point* position, 101 const PP_Point* position,
100 uint32_t color, 102 uint32_t color,
101 const PP_Rect* clip, 103 const PP_Rect* clip,
102 PP_Bool image_data_is_opaque) { 104 PP_Bool image_data_is_opaque) {
105 Font* object = PluginResource::GetAs<Font>(font_id);
106 if (!object)
107 return PP_FALSE;
108
103 PPBFont_DrawTextAt_Params params; 109 PPBFont_DrawTextAt_Params params;
104 params.font = font_id; 110 params.font = font_id;
105 params.image_data = image_data; 111 params.image_data = image_data;
106 params.text_is_rtl = text->rtl; 112 params.text_is_rtl = text->rtl;
107 params.override_direction = text->override_direction; 113 params.override_direction = text->override_direction;
108 params.position = *position; 114 params.position = *position;
109 params.color = color; 115 params.color = color;
110 if (clip) { 116 if (clip) {
111 params.clip = *clip; 117 params.clip = *clip;
112 params.clip_is_null = false; 118 params.clip_is_null = false;
113 } else { 119 } else {
114 params.clip = PP_MakeRectFromXYWH(0, 0, 0, 0); 120 params.clip = PP_MakeRectFromXYWH(0, 0, 0, 0);
115 params.clip_is_null = true; 121 params.clip_is_null = true;
116 } 122 }
117 params.image_data_is_opaque = image_data_is_opaque; 123 params.image_data_is_opaque = image_data_is_opaque;
118 124
119 Dispatcher* dispatcher = PluginDispatcher::Get(); 125 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
120 PP_Bool result = PP_FALSE; 126 PP_Bool result = PP_FALSE;
121 dispatcher->Send(new PpapiHostMsg_PPBFont_DrawTextAt( 127 if (dispatcher) {
122 INTERFACE_ID_PPB_FONT, 128 dispatcher->Send(new PpapiHostMsg_PPBFont_DrawTextAt(
123 SerializedVarSendInput(dispatcher, text->text), 129 INTERFACE_ID_PPB_FONT,
124 params, &result)); 130 SerializedVarSendInput(dispatcher, text->text),
131 params, &result));
132 }
125 return result; 133 return result;
126 } 134 }
127 135
128 int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) { 136 int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) {
129 Dispatcher* dispatcher = PluginDispatcher::Get(); 137 Font* object = PluginResource::GetAs<Font>(font_id);
138 if (!object)
139 return -1;
140
141 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
130 int32_t result = 0; 142 int32_t result = 0;
131 dispatcher->Send(new PpapiHostMsg_PPBFont_MeasureText( 143 dispatcher->Send(new PpapiHostMsg_PPBFont_MeasureText(
132 INTERFACE_ID_PPB_FONT, font_id, 144 INTERFACE_ID_PPB_FONT, font_id,
133 SerializedVarSendInput(dispatcher, text->text), 145 SerializedVarSendInput(dispatcher, text->text),
134 text->rtl, text->override_direction, &result)); 146 text->rtl, text->override_direction, &result));
135 return result; 147 return result;
136 } 148 }
137 149
138 uint32_t CharacterOffsetForPixel(PP_Resource font_id, 150 uint32_t CharacterOffsetForPixel(PP_Resource font_id,
139 const PP_TextRun_Dev* text, 151 const PP_TextRun_Dev* text,
140 int32_t pixel_position) { 152 int32_t pixel_position) {
141 Dispatcher* dispatcher = PluginDispatcher::Get(); 153 Font* object = PluginResource::GetAs<Font>(font_id);
154 if (!object)
155 return -1;
156
157 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
142 uint32_t result = 0; 158 uint32_t result = 0;
143 dispatcher->Send(new PpapiHostMsg_PPBFont_CharacterOffsetForPixel( 159 dispatcher->Send(new PpapiHostMsg_PPBFont_CharacterOffsetForPixel(
144 INTERFACE_ID_PPB_FONT, font_id, 160 INTERFACE_ID_PPB_FONT, font_id,
145 SerializedVarSendInput(dispatcher, text->text), 161 SerializedVarSendInput(dispatcher, text->text),
146 text->rtl, text->override_direction, pixel_position, &result)); 162 text->rtl, text->override_direction, pixel_position, &result));
147 return result; 163 return result;
148 } 164 }
149 165
150 int32_t PixelOffsetForCharacter(PP_Resource font_id, 166 int32_t PixelOffsetForCharacter(PP_Resource font_id,
151 const PP_TextRun_Dev* text, 167 const PP_TextRun_Dev* text,
152 uint32_t char_offset) { 168 uint32_t char_offset) {
153 Dispatcher* dispatcher = PluginDispatcher::Get(); 169 Font* object = PluginResource::GetAs<Font>(font_id);
170 if (!object)
171 return -1;
172
173 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
154 int32_t result = 0; 174 int32_t result = 0;
155 dispatcher->Send(new PpapiHostMsg_PPBFont_PixelOffsetForCharacter( 175 dispatcher->Send(new PpapiHostMsg_PPBFont_PixelOffsetForCharacter(
156 INTERFACE_ID_PPB_FONT, font_id, 176 INTERFACE_ID_PPB_FONT, font_id,
157 SerializedVarSendInput(dispatcher, text->text), 177 SerializedVarSendInput(dispatcher, text->text),
158 text->rtl, text->override_direction, char_offset, &result)); 178 text->rtl, text->override_direction, char_offset, &result));
159 return result; 179 return result;
160 } 180 }
161 181
162 const PPB_Font_Dev ppb_font_interface = { 182 const PPB_Font_Dev ppb_font_interface = {
163 &Create, 183 &Create,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 PP_TextRun_Dev run; 307 PP_TextRun_Dev run;
288 run.text = text.Get(dispatcher()); 308 run.text = text.Get(dispatcher());
289 run.rtl = text_is_rtl; 309 run.rtl = text_is_rtl;
290 run.override_direction = override_direction; 310 run.override_direction = override_direction;
291 311
292 *result = ppb_font_target()->PixelOffsetForCharacter(font, &run, char_offset); 312 *result = ppb_font_target()->PixelOffsetForCharacter(font, &run, char_offset);
293 } 313 }
294 314
295 } // namespace proxy 315 } // namespace proxy
296 } // namespace pp 316 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_flash_proxy.cc ('k') | ppapi/proxy/ppb_fullscreen_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698