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

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

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