OLD | NEW |
1 // Copyright (c) 2011 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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "ppapi/c/dev/ppb_font_dev.h" | 9 #include "ppapi/c/dev/ppb_font_dev.h" |
10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 Font::Font(const HostResource& resource, | 95 Font::Font(const HostResource& resource, |
96 const PP_FontDescription_Dev& desc) | 96 const PP_FontDescription_Dev& desc) |
97 : PluginResource(resource), | 97 : PluginResource(resource), |
98 webkit_event_(false, false) { | 98 webkit_event_(false, false) { |
99 TRACE_EVENT0("ppapi proxy", "Font::Font"); | 99 TRACE_EVENT0("ppapi proxy", "Font::Font"); |
100 scoped_refptr<StringVar> face(StringVar::FromPPVar(desc.face)); | 100 scoped_refptr<StringVar> face(StringVar::FromPPVar(desc.face)); |
101 | 101 |
102 WebKitForwarding* forwarding = GetDispatcher()->GetWebKitForwarding(); | 102 WebKitForwarding* forwarding = GetDispatcher()->GetWebKitForwarding(); |
103 | 103 |
104 WebKitForwarding::Font* result = NULL; | 104 RunOnWebKitThread(true, |
105 RunOnWebKitThread(base::Bind(&WebKitForwarding::CreateFontForwarding, | 105 base::Bind(&WebKitForwarding::CreateFontForwarding, |
106 base::Unretained(forwarding), | 106 base::Unretained(forwarding), |
107 &webkit_event_, desc, | 107 &webkit_event_, desc, |
108 face.get() ? face->value() : std::string(), | 108 face.get() ? face->value() : std::string(), |
109 GetDispatcher()->preferences(), | 109 GetDispatcher()->preferences(), |
110 &result)); | 110 &font_forwarding_)); |
111 font_forwarding_.reset(result); | |
112 } | 111 } |
113 | 112 |
114 Font::~Font() { | 113 Font::~Font() { |
| 114 RunOnWebKitThread(false, base::Bind(&DeleteFontForwarding, font_forwarding_)); |
115 } | 115 } |
116 | 116 |
117 ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() { | 117 ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() { |
118 return this; | 118 return this; |
119 } | 119 } |
120 | 120 |
121 Font* Font::AsFont() { | 121 Font* Font::AsFont() { |
122 return this; | 122 return this; |
123 } | 123 } |
124 | 124 |
125 PP_Bool Font::Describe(PP_FontDescription_Dev* description, | 125 PP_Bool Font::Describe(PP_FontDescription_Dev* description, |
126 PP_FontMetrics_Dev* metrics) { | 126 PP_FontMetrics_Dev* metrics) { |
127 TRACE_EVENT0("ppapi proxy", "Font::Describe"); | 127 TRACE_EVENT0("ppapi proxy", "Font::Describe"); |
128 std::string face; | 128 std::string face; |
129 PP_Bool result = PP_FALSE; | 129 PP_Bool result = PP_FALSE; |
130 RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::Describe, | 130 RunOnWebKitThread(true, |
131 base::Unretained(font_forwarding_.get()), | 131 base::Bind(&WebKitForwarding::Font::Describe, |
| 132 base::Unretained(font_forwarding_), |
132 &webkit_event_, description, &face, metrics, | 133 &webkit_event_, description, &face, metrics, |
133 &result)); | 134 &result)); |
134 | 135 |
135 if (PP_ToBool(result)) | 136 if (PP_ToBool(result)) |
136 description->face = StringVar::StringToPPVar(0, face); | 137 description->face = StringVar::StringToPPVar(0, face); |
137 else | 138 else |
138 description->face = PP_MakeUndefined(); | 139 description->face = PP_MakeUndefined(); |
139 return result; | 140 return result; |
140 } | 141 } |
141 | 142 |
(...skipping 19 matching lines...) Expand all Loading... |
161 if (!canvas) | 162 if (!canvas) |
162 return PP_FALSE; // Failure mapping. | 163 return PP_FALSE; // Failure mapping. |
163 } | 164 } |
164 | 165 |
165 WebKitForwarding::Font::TextRun run; | 166 WebKitForwarding::Font::TextRun run; |
166 if (!PPTextRunToTextRun(text, &run)) { | 167 if (!PPTextRunToTextRun(text, &run)) { |
167 if (needs_unmapping) | 168 if (needs_unmapping) |
168 image_data->Unmap(); | 169 image_data->Unmap(); |
169 return PP_FALSE; | 170 return PP_FALSE; |
170 } | 171 } |
171 RunOnWebKitThread(base::Bind( | 172 RunOnWebKitThread( |
172 &WebKitForwarding::Font::DrawTextAt, | 173 true, |
173 base::Unretained(font_forwarding_.get()), | 174 base::Bind(&WebKitForwarding::Font::DrawTextAt, |
174 &webkit_event_, | 175 base::Unretained(font_forwarding_), &webkit_event_, |
175 WebKitForwarding::Font::DrawTextParams(canvas, run, position, color, | 176 WebKitForwarding::Font::DrawTextParams(canvas, run, position, |
176 clip, image_data_is_opaque))); | 177 color, clip, |
| 178 image_data_is_opaque))); |
177 | 179 |
178 if (needs_unmapping) | 180 if (needs_unmapping) |
179 image_data->Unmap(); | 181 image_data->Unmap(); |
180 return PP_TRUE; | 182 return PP_TRUE; |
181 } | 183 } |
182 | 184 |
183 int32_t Font::MeasureText(const PP_TextRun_Dev* text) { | 185 int32_t Font::MeasureText(const PP_TextRun_Dev* text) { |
184 TRACE_EVENT0("ppapi proxy", "Font::MeasureText"); | 186 TRACE_EVENT0("ppapi proxy", "Font::MeasureText"); |
185 WebKitForwarding::Font::TextRun run; | 187 WebKitForwarding::Font::TextRun run; |
186 if (!PPTextRunToTextRun(text, &run)) | 188 if (!PPTextRunToTextRun(text, &run)) |
187 return -1; | 189 return -1; |
188 int32_t result = -1; | 190 int32_t result = -1; |
189 RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::MeasureText, | 191 RunOnWebKitThread(true, |
190 base::Unretained(font_forwarding_.get()), | 192 base::Bind(&WebKitForwarding::Font::MeasureText, |
| 193 base::Unretained(font_forwarding_), |
191 &webkit_event_, run, &result)); | 194 &webkit_event_, run, &result)); |
192 return result; | 195 return result; |
193 } | 196 } |
194 | 197 |
195 uint32_t Font::CharacterOffsetForPixel(const PP_TextRun_Dev* text, | 198 uint32_t Font::CharacterOffsetForPixel(const PP_TextRun_Dev* text, |
196 int32_t pixel_position) { | 199 int32_t pixel_position) { |
197 TRACE_EVENT0("ppapi proxy", "Font::CharacterOffsetForPixel"); | 200 TRACE_EVENT0("ppapi proxy", "Font::CharacterOffsetForPixel"); |
198 WebKitForwarding::Font::TextRun run; | 201 WebKitForwarding::Font::TextRun run; |
199 if (!PPTextRunToTextRun(text, &run)) | 202 if (!PPTextRunToTextRun(text, &run)) |
200 return -1; | 203 return -1; |
201 uint32_t result = -1; | 204 uint32_t result = -1; |
202 RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::CharacterOffsetForPixel, | 205 RunOnWebKitThread(true, |
203 base::Unretained(font_forwarding_.get()), | 206 base::Bind(&WebKitForwarding::Font::CharacterOffsetForPixel, |
| 207 base::Unretained(font_forwarding_), |
204 &webkit_event_, run, pixel_position, &result)); | 208 &webkit_event_, run, pixel_position, &result)); |
205 return result; | 209 return result; |
206 } | 210 } |
207 | 211 |
208 int32_t Font::PixelOffsetForCharacter(const PP_TextRun_Dev* text, | 212 int32_t Font::PixelOffsetForCharacter(const PP_TextRun_Dev* text, |
209 uint32_t char_offset) { | 213 uint32_t char_offset) { |
210 TRACE_EVENT0("ppapi proxy", "Font::PixelOffsetForCharacter"); | 214 TRACE_EVENT0("ppapi proxy", "Font::PixelOffsetForCharacter"); |
211 WebKitForwarding::Font::TextRun run; | 215 WebKitForwarding::Font::TextRun run; |
212 if (!PPTextRunToTextRun(text, &run)) | 216 if (!PPTextRunToTextRun(text, &run)) |
213 return -1; | 217 return -1; |
214 int32_t result = -1; | 218 int32_t result = -1; |
215 RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::PixelOffsetForCharacter, | 219 RunOnWebKitThread(true, |
216 base::Unretained(font_forwarding_.get()), | 220 base::Bind(&WebKitForwarding::Font::PixelOffsetForCharacter, |
| 221 base::Unretained(font_forwarding_), |
217 &webkit_event_, run, char_offset, &result)); | 222 &webkit_event_, run, char_offset, &result)); |
218 return result; | 223 return result; |
219 } | 224 } |
220 | 225 |
221 void Font::RunOnWebKitThread(const base::Closure& task) { | 226 void Font::RunOnWebKitThread(bool blocking, const base::Closure& task) { |
222 GetDispatcher()->PostToWebKitThread(FROM_HERE, task); | 227 GetDispatcher()->PostToWebKitThread(FROM_HERE, task); |
223 webkit_event_.Wait(); | 228 if (blocking) |
| 229 webkit_event_.Wait(); |
| 230 } |
| 231 |
| 232 // static |
| 233 void Font::DeleteFontForwarding( |
| 234 ppapi::WebKitForwarding::Font* font_forwarding) { |
| 235 delete font_forwarding; |
224 } | 236 } |
225 | 237 |
226 } // namespace proxy | 238 } // namespace proxy |
227 } // namespace pp | 239 } // namespace pp |
OLD | NEW |