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 "webkit/plugins/ppapi/ppb_flash_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_flash_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 if (!instance) | 48 if (!instance) |
49 return; | 49 return; |
50 instance->set_always_on_top(PPBoolToBool(on_top)); | 50 instance->set_always_on_top(PPBoolToBool(on_top)); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 PP_Bool DrawGlyphs(PP_Instance, | 54 PP_Bool DrawGlyphs(PP_Instance, |
55 PP_Resource pp_image_data, | 55 PP_Resource pp_image_data, |
56 const PP_FontDescription_Dev* font_desc, | 56 const PP_FontDescription_Dev* font_desc, |
57 uint32_t color, | 57 uint32_t color, |
58 PP_Point position, | 58 const PP_Point* position, |
59 PP_Rect clip, | 59 const PP_Rect* clip, |
60 const float transformation[3][3], | 60 const float transformation[3][3], |
| 61 PP_Bool allow_subpixel_aa, |
61 uint32_t glyph_count, | 62 uint32_t glyph_count, |
62 const uint16_t glyph_indices[], | 63 const uint16_t glyph_indices[], |
63 const PP_Point glyph_advances[]) { | 64 const PP_Point glyph_advances[]) { |
64 EnterResource<PPB_ImageData_API> enter(pp_image_data, true); | 65 EnterResource<PPB_ImageData_API> enter(pp_image_data, true); |
65 if (enter.failed()) | 66 if (enter.failed()) |
66 return PP_FALSE; | 67 return PP_FALSE; |
67 PPB_ImageData_Impl* image_resource = | 68 PPB_ImageData_Impl* image_resource = |
68 static_cast<PPB_ImageData_Impl*>(enter.object()); | 69 static_cast<PPB_ImageData_Impl*>(enter.object()); |
69 | 70 |
70 ImageDataAutoMapper mapper(image_resource); | 71 ImageDataAutoMapper mapper(image_resource); |
(...skipping 13 matching lines...) Expand all Loading... |
84 SkTypeface::CreateFromName(face_name->value().c_str(), | 85 SkTypeface::CreateFromName(face_name->value().c_str(), |
85 static_cast<SkTypeface::Style>(style)); | 86 static_cast<SkTypeface::Style>(style)); |
86 if (!typeface) | 87 if (!typeface) |
87 return PP_FALSE; | 88 return PP_FALSE; |
88 | 89 |
89 // Set up the canvas. | 90 // Set up the canvas. |
90 SkCanvas* canvas = image_resource->mapped_canvas(); | 91 SkCanvas* canvas = image_resource->mapped_canvas(); |
91 canvas->save(); | 92 canvas->save(); |
92 | 93 |
93 // Clip is applied in pixels before the transform. | 94 // Clip is applied in pixels before the transform. |
94 SkRect clip_rect = { clip.point.x, clip.point.y, | 95 SkRect clip_rect = { clip->point.x, clip->point.y, |
95 clip.point.x + clip.size.width, | 96 clip->point.x + clip->size.width, |
96 clip.point.y + clip.size.height }; | 97 clip->point.y + clip->size.height }; |
97 canvas->clipRect(clip_rect); | 98 canvas->clipRect(clip_rect); |
98 | 99 |
99 // -- Do not return early below this. The canvas needs restoring and the | 100 // -- Do not return early below this. The canvas needs restoring and the |
100 // typeface will leak if it's not assigned to the paint (it's refcounted and | 101 // typeface will leak if it's not assigned to the paint (it's refcounted and |
101 // the refcount is currently 0). | 102 // the refcount is currently 0). |
102 | 103 |
103 // Convert & set the matrix. | 104 // Convert & set the matrix. |
104 SkMatrix matrix; | 105 SkMatrix matrix; |
105 matrix.set(SkMatrix::kMScaleX, SkFloatToScalar(transformation[0][0])); | 106 matrix.set(SkMatrix::kMScaleX, SkFloatToScalar(transformation[0][0])); |
106 matrix.set(SkMatrix::kMSkewX, SkFloatToScalar(transformation[0][1])); | 107 matrix.set(SkMatrix::kMSkewX, SkFloatToScalar(transformation[0][1])); |
107 matrix.set(SkMatrix::kMTransX, SkFloatToScalar(transformation[0][2])); | 108 matrix.set(SkMatrix::kMTransX, SkFloatToScalar(transformation[0][2])); |
108 matrix.set(SkMatrix::kMSkewY, SkFloatToScalar(transformation[1][0])); | 109 matrix.set(SkMatrix::kMSkewY, SkFloatToScalar(transformation[1][0])); |
109 matrix.set(SkMatrix::kMScaleY, SkFloatToScalar(transformation[1][1])); | 110 matrix.set(SkMatrix::kMScaleY, SkFloatToScalar(transformation[1][1])); |
110 matrix.set(SkMatrix::kMTransY, SkFloatToScalar(transformation[1][2])); | 111 matrix.set(SkMatrix::kMTransY, SkFloatToScalar(transformation[1][2])); |
111 matrix.set(SkMatrix::kMPersp0, SkFloatToScalar(transformation[2][0])); | 112 matrix.set(SkMatrix::kMPersp0, SkFloatToScalar(transformation[2][0])); |
112 matrix.set(SkMatrix::kMPersp1, SkFloatToScalar(transformation[2][1])); | 113 matrix.set(SkMatrix::kMPersp1, SkFloatToScalar(transformation[2][1])); |
113 matrix.set(SkMatrix::kMPersp2, SkFloatToScalar(transformation[2][2])); | 114 matrix.set(SkMatrix::kMPersp2, SkFloatToScalar(transformation[2][2])); |
114 canvas->concat(matrix); | 115 canvas->concat(matrix); |
115 | 116 |
116 SkPaint paint; | 117 SkPaint paint; |
117 paint.setColor(color); | 118 paint.setColor(color); |
118 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 119 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
119 paint.setAntiAlias(true); | 120 paint.setAntiAlias(true); |
120 paint.setHinting(SkPaint::kFull_Hinting); | 121 paint.setHinting(SkPaint::kFull_Hinting); |
121 paint.setTextSize(SkIntToScalar(font_desc->size)); | 122 paint.setTextSize(SkIntToScalar(font_desc->size)); |
122 paint.setTypeface(typeface); // Takes a ref and manages lifetime. | 123 paint.setTypeface(typeface); // Takes a ref and manages lifetime. |
123 paint.setSubpixelText(true); | 124 if (allow_subpixel_aa) { |
124 paint.setLCDRenderText(true); | 125 paint.setSubpixelText(true); |
| 126 paint.setLCDRenderText(true); |
| 127 } |
125 | 128 |
126 SkScalar x = SkIntToScalar(position.x); | 129 SkScalar x = SkIntToScalar(position->x); |
127 SkScalar y = SkIntToScalar(position.y); | 130 SkScalar y = SkIntToScalar(position->y); |
128 | 131 |
129 // Build up the skia advances. | 132 // Build up the skia advances. |
130 if (glyph_count == 0) | 133 if (glyph_count == 0) |
131 return PP_TRUE; | 134 return PP_TRUE; |
132 std::vector<SkPoint> storage; | 135 std::vector<SkPoint> storage; |
133 storage.resize(glyph_count); | 136 storage.resize(glyph_count); |
134 SkPoint* sk_positions = &storage[0]; | 137 SkPoint* sk_positions = &storage[0]; |
135 for (uint32_t i = 0; i < glyph_count; i++) { | 138 for (uint32_t i = 0; i < glyph_count; i++) { |
136 sk_positions[i].set(x, y); | 139 sk_positions[i].set(x, y); |
137 x += SkFloatToScalar(glyph_advances[i].x); | 140 x += SkFloatToScalar(glyph_advances[i].x); |
138 y += SkFloatToScalar(glyph_advances[i].y); | 141 y += SkFloatToScalar(glyph_advances[i].y); |
139 } | 142 } |
140 | 143 |
141 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint); | 144 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint); |
142 | 145 |
143 canvas->restore(); | 146 canvas->restore(); |
144 return PP_TRUE; | 147 return PP_TRUE; |
145 } | 148 } |
146 | 149 |
| 150 PP_Bool DrawGlyphs11(PP_Instance instance, |
| 151 PP_Resource pp_image_data, |
| 152 const PP_FontDescription_Dev* font_desc, |
| 153 uint32_t color, |
| 154 PP_Point position, |
| 155 PP_Rect clip, |
| 156 const float transformation[3][3], |
| 157 uint32_t glyph_count, |
| 158 const uint16_t glyph_indices[], |
| 159 const PP_Point glyph_advances[]) { |
| 160 return DrawGlyphs(instance, pp_image_data, font_desc, color, &position, |
| 161 &clip, transformation, PP_TRUE, glyph_count, |
| 162 glyph_indices, glyph_advances); |
| 163 } |
| 164 |
147 PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { | 165 PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { |
148 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | 166 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
149 if (!instance) | 167 if (!instance) |
150 return PP_MakeUndefined(); | 168 return PP_MakeUndefined(); |
151 | 169 |
152 GURL gurl(url); | 170 GURL gurl(url); |
153 if (!gurl.is_valid()) | 171 if (!gurl.is_valid()) |
154 return PP_MakeUndefined(); | 172 return PP_MakeUndefined(); |
155 | 173 |
156 std::string proxy_host = instance->delegate()->ResolveProxy(gurl); | 174 std::string proxy_host = instance->delegate()->ResolveProxy(gurl); |
157 if (proxy_host.empty()) | 175 if (proxy_host.empty()) |
158 return PP_MakeUndefined(); // No proxy. | 176 return PP_MakeUndefined(); // No proxy. |
159 return StringVar::StringToPPVar(proxy_host); | 177 return StringVar::StringToPPVar(proxy_host); |
160 } | 178 } |
161 | 179 |
162 int32_t Navigate(PP_Resource request_id, | 180 int32_t Navigate(PP_Resource request_id, |
163 const char* target, | 181 const char* target, |
164 bool from_user_action) { | 182 PP_Bool from_user_action) { |
165 EnterResource<PPB_URLRequestInfo_API> enter(request_id, true); | 183 EnterResource<PPB_URLRequestInfo_API> enter(request_id, true); |
166 if (enter.failed()) | 184 if (enter.failed()) |
167 return PP_ERROR_BADRESOURCE; | 185 return PP_ERROR_BADRESOURCE; |
168 PPB_URLRequestInfo_Impl* request = | 186 PPB_URLRequestInfo_Impl* request = |
169 static_cast<PPB_URLRequestInfo_Impl*>(enter.object()); | 187 static_cast<PPB_URLRequestInfo_Impl*>(enter.object()); |
170 | 188 |
171 if (!target) | 189 if (!target) |
172 return PP_ERROR_BADARGUMENT; | 190 return PP_ERROR_BADARGUMENT; |
173 | 191 |
174 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(request); | 192 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(request); |
175 if (!plugin_instance) | 193 if (!plugin_instance) |
176 return PP_ERROR_FAILED; | 194 return PP_ERROR_FAILED; |
177 return plugin_instance->Navigate(request, target, from_user_action); | 195 return plugin_instance->Navigate(request, target, |
| 196 PP_ToBool(from_user_action)); |
| 197 } |
| 198 |
| 199 int32_t Navigate11(PP_Resource request_id, |
| 200 const char* target, |
| 201 bool from_user_action) { |
| 202 return Navigate(request_id, target, PP_FromBool(from_user_action)); |
178 } | 203 } |
179 | 204 |
180 void RunMessageLoop(PP_Instance instance) { | 205 void RunMessageLoop(PP_Instance instance) { |
181 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 206 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
182 MessageLoop::current()->SetNestableTasksAllowed(true); | 207 MessageLoop::current()->SetNestableTasksAllowed(true); |
183 MessageLoop::current()->Run(); | 208 MessageLoop::current()->Run(); |
184 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 209 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
185 } | 210 } |
186 | 211 |
187 void QuitMessageLoop(PP_Instance instance) { | 212 void QuitMessageLoop(PP_Instance instance) { |
(...skipping 24 matching lines...) Expand all Loading... |
212 return PP_MakeUndefined(); | 237 return PP_MakeUndefined(); |
213 | 238 |
214 PluginInstance* instance = module->GetSomeInstance(); | 239 PluginInstance* instance = module->GetSomeInstance(); |
215 if (!instance) | 240 if (!instance) |
216 return PP_MakeUndefined(); | 241 return PP_MakeUndefined(); |
217 | 242 |
218 std::string args = instance->delegate()->GetFlashCommandLineArgs(); | 243 std::string args = instance->delegate()->GetFlashCommandLineArgs(); |
219 return StringVar::StringToPPVar(args); | 244 return StringVar::StringToPPVar(args); |
220 } | 245 } |
221 | 246 |
222 const PPB_Flash ppb_flash = { | 247 void PreLoadFontInWindows(const void* logfontw) { |
| 248 // TODO(brettw) implement this. |
| 249 } |
| 250 |
| 251 const PPB_Flash_11 ppb_flash_11 = { |
| 252 &SetInstanceAlwaysOnTop, |
| 253 &DrawGlyphs11, |
| 254 &GetProxyForURL, |
| 255 &Navigate11, |
| 256 &RunMessageLoop, |
| 257 &QuitMessageLoop, |
| 258 &GetLocalTimeZoneOffset, |
| 259 &GetCommandLineArgs |
| 260 }; |
| 261 |
| 262 const PPB_Flash ppb_flash_12 = { |
223 &SetInstanceAlwaysOnTop, | 263 &SetInstanceAlwaysOnTop, |
224 &DrawGlyphs, | 264 &DrawGlyphs, |
225 &GetProxyForURL, | 265 &GetProxyForURL, |
226 &Navigate, | 266 &Navigate, |
227 &RunMessageLoop, | 267 &RunMessageLoop, |
228 &QuitMessageLoop, | 268 &QuitMessageLoop, |
229 &GetLocalTimeZoneOffset, | 269 &GetLocalTimeZoneOffset, |
230 &GetCommandLineArgs | 270 &GetCommandLineArgs, |
| 271 &PreLoadFontInWindows |
231 }; | 272 }; |
232 | 273 |
233 } // namespace | 274 } // namespace |
234 | 275 |
235 // static | 276 // static |
236 const PPB_Flash* PPB_Flash_Impl::GetInterface() { | 277 const PPB_Flash_11* PPB_Flash_Impl::GetInterface11() { |
237 return &ppb_flash; | 278 return &ppb_flash_11; |
| 279 } |
| 280 |
| 281 // static |
| 282 const PPB_Flash* PPB_Flash_Impl::GetInterface12() { |
| 283 return &ppb_flash_12; |
238 } | 284 } |
239 | 285 |
240 } // namespace ppapi | 286 } // namespace ppapi |
241 } // namespace webkit | 287 } // namespace webkit |
OLD | NEW |