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

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_impl.cc

Issue 8927001: Implement platform-independent DrawGlyphs for Flash. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years 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 | « webkit/plugins/ppapi/ppb_flash_impl.h ('k') | webkit/plugins/ppapi/ppb_flash_impl_linux.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) 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 9
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "base/time.h" 11 #include "base/time.h"
11 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "ppapi/c/dev/ppb_font_dev.h"
12 #include "ppapi/c/private/ppb_flash.h" 14 #include "ppapi/c/private/ppb_flash.h"
13 #include "ppapi/shared_impl/time_conversion.h" 15 #include "ppapi/shared_impl/time_conversion.h"
14 #include "ppapi/shared_impl/var.h" 16 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/thunk/enter.h" 17 #include "ppapi/thunk/enter.h"
18 #include "ppapi/thunk/ppb_image_data_api.h"
19 #include "skia/ext/platform_canvas.h"
20 #include "third_party/skia/include/core/SkCanvas.h"
21 #include "third_party/skia/include/core/SkMatrix.h"
22 #include "third_party/skia/include/core/SkPaint.h"
23 #include "third_party/skia/include/core/SkPoint.h"
24 #include "third_party/skia/include/core/SkTemplates.h"
25 #include "third_party/skia/include/core/SkTypeface.h"
16 #include "webkit/plugins/ppapi/common.h" 26 #include "webkit/plugins/ppapi/common.h"
17 #include "webkit/plugins/ppapi/host_globals.h" 27 #include "webkit/plugins/ppapi/host_globals.h"
18 #include "webkit/plugins/ppapi/plugin_delegate.h" 28 #include "webkit/plugins/ppapi/plugin_delegate.h"
19 #include "webkit/plugins/ppapi/plugin_module.h" 29 #include "webkit/plugins/ppapi/plugin_module.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 30 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" 31 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
22 #include "webkit/plugins/ppapi/resource_helper.h" 32 #include "webkit/plugins/ppapi/resource_helper.h"
33 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
23 34
24 using ppapi::PPTimeToTime; 35 using ppapi::PPTimeToTime;
25 using ppapi::StringVar; 36 using ppapi::StringVar;
26 using ppapi::thunk::EnterResource; 37 using ppapi::thunk::EnterResource;
38 using ppapi::thunk::PPB_ImageData_API;
27 using ppapi::thunk::PPB_URLRequestInfo_API; 39 using ppapi::thunk::PPB_URLRequestInfo_API;
28 40
29 namespace webkit { 41 namespace webkit {
30 namespace ppapi { 42 namespace ppapi {
31 43
32 namespace { 44 namespace {
33 45
34 void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) { 46 void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) {
35 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 47 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
36 if (!instance) 48 if (!instance)
37 return; 49 return;
38 instance->set_always_on_top(PPBoolToBool(on_top)); 50 instance->set_always_on_top(PPBoolToBool(on_top));
39 } 51 }
40 52
53
54 PP_Bool DrawGlyphs(PP_Instance,
55 PP_Resource pp_image_data,
56 const PP_FontDescription_Dev* font_desc,
57 uint32_t color,
58 PP_Point position,
59 PP_Rect clip,
60 const float transformation[3][3],
61 uint32_t glyph_count,
62 const uint16_t glyph_indices[],
63 const PP_Point glyph_advances[]) {
64 EnterResource<PPB_ImageData_API> enter(pp_image_data, true);
65 if (enter.failed())
66 return PP_FALSE;
67 PPB_ImageData_Impl* image_resource =
68 static_cast<PPB_ImageData_Impl*>(enter.object());
69
70 ImageDataAutoMapper mapper(image_resource);
71 if (!mapper.is_valid())
72 return PP_FALSE;
73
74 // Set up the typeface.
75 StringVar* face_name = StringVar::FromPPVar(font_desc->face);
76 if (!face_name)
77 return PP_FALSE;
78 int style = SkTypeface::kNormal;
79 if (font_desc->weight >= PP_FONTWEIGHT_BOLD)
80 style |= SkTypeface::kBold;
81 if (font_desc->italic)
82 style |= SkTypeface::kItalic;
83 SkTypeface* typeface =
84 SkTypeface::CreateFromName(face_name->value().c_str(),
85 static_cast<SkTypeface::Style>(style));
86 if (!typeface)
87 return PP_FALSE;
88
89 // Set up the canvas.
90 SkCanvas* canvas = image_resource->mapped_canvas();
91 canvas->save();
92
93 // Clip is applied in pixels before the transform.
94 SkRect clip_rect = { clip.point.x, clip.point.y,
95 clip.point.x + clip.size.width,
96 clip.point.y + clip.size.height };
97 canvas->clipRect(clip_rect);
98
99 // -- 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 // the refcount is currently 0).
102
103 // Convert & set the matrix.
104 SkMatrix matrix;
105 matrix.set(SkMatrix::kMScaleX, SkFloatToScalar(transformation[0][0]));
106 matrix.set(SkMatrix::kMSkewX, SkFloatToScalar(transformation[0][1]));
107 matrix.set(SkMatrix::kMTransX, SkFloatToScalar(transformation[0][2]));
108 matrix.set(SkMatrix::kMSkewY, SkFloatToScalar(transformation[1][0]));
109 matrix.set(SkMatrix::kMScaleY, SkFloatToScalar(transformation[1][1]));
110 matrix.set(SkMatrix::kMTransY, SkFloatToScalar(transformation[1][2]));
111 matrix.set(SkMatrix::kMPersp0, SkFloatToScalar(transformation[2][0]));
112 matrix.set(SkMatrix::kMPersp1, SkFloatToScalar(transformation[2][1]));
113 matrix.set(SkMatrix::kMPersp2, SkFloatToScalar(transformation[2][2]));
114 canvas->concat(matrix);
115
116 SkPaint paint;
117 paint.setColor(color);
118 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
119 paint.setAntiAlias(true);
120 paint.setHinting(SkPaint::kFull_Hinting);
121 paint.setTextSize(SkIntToScalar(font_desc->size));
122 paint.setTypeface(typeface); // Takes a ref and manages lifetime.
123 paint.setSubpixelText(true);
124 paint.setLCDRenderText(true);
125
126 SkScalar x = SkIntToScalar(position.x);
127 SkScalar y = SkIntToScalar(position.y);
128
129 // Build up the skia advances.
130 if (glyph_count == 0)
131 return;
132 std::vector<SkPoint> storage;
133 storage.resize(glyph_count);
134 SkPoint* sk_positions = &storage[0];
135 for (uint32_t i = 0; i < glyph_count; i++) {
136 sk_positions[i].set(x, y);
137 x += SkFloatToScalar(glyph_advances[i].x);
138 y += SkFloatToScalar(glyph_advances[i].y);
139 }
140
141 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint);
142
143 canvas->restore();
144 return PP_TRUE;
145 }
146
41 PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { 147 PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) {
42 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); 148 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
43 if (!instance) 149 if (!instance)
44 return PP_MakeUndefined(); 150 return PP_MakeUndefined();
45 151
46 GURL gurl(url); 152 GURL gurl(url);
47 if (!gurl.is_valid()) 153 if (!gurl.is_valid())
48 return PP_MakeUndefined(); 154 return PP_MakeUndefined();
49 155
50 std::string proxy_host = instance->delegate()->ResolveProxy(gurl); 156 std::string proxy_host = instance->delegate()->ResolveProxy(gurl);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 PluginInstance* instance = module->GetSomeInstance(); 214 PluginInstance* instance = module->GetSomeInstance();
109 if (!instance) 215 if (!instance)
110 return PP_MakeUndefined(); 216 return PP_MakeUndefined();
111 217
112 std::string args = instance->delegate()->GetFlashCommandLineArgs(); 218 std::string args = instance->delegate()->GetFlashCommandLineArgs();
113 return StringVar::StringToPPVar(args); 219 return StringVar::StringToPPVar(args);
114 } 220 }
115 221
116 const PPB_Flash ppb_flash = { 222 const PPB_Flash ppb_flash = {
117 &SetInstanceAlwaysOnTop, 223 &SetInstanceAlwaysOnTop,
118 &PPB_Flash_Impl::DrawGlyphs, 224 &DrawGlyphs,
119 &GetProxyForURL, 225 &GetProxyForURL,
120 &Navigate, 226 &Navigate,
121 &RunMessageLoop, 227 &RunMessageLoop,
122 &QuitMessageLoop, 228 &QuitMessageLoop,
123 &GetLocalTimeZoneOffset, 229 &GetLocalTimeZoneOffset,
124 &GetCommandLineArgs 230 &GetCommandLineArgs
125 }; 231 };
126 232
127 } // namespace 233 } // namespace
128 234
129 // static 235 // static
130 const PPB_Flash* PPB_Flash_Impl::GetInterface() { 236 const PPB_Flash* PPB_Flash_Impl::GetInterface() {
131 return &ppb_flash; 237 return &ppb_flash;
132 } 238 }
133 239
134 } // namespace ppapi 240 } // namespace ppapi
135 } // namespace webkit 241 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_impl.h ('k') | webkit/plugins/ppapi/ppb_flash_impl_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698