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

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

Issue 11576016: Revert 172806 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
10 #include "ppapi/c/private/ppb_flash.h" 11 #include "ppapi/c/private/ppb_flash.h"
11 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" 12 #include "ppapi/c/trusted/ppb_browser_font_trusted.h"
12 #include "ppapi/shared_impl/time_conversion.h" 13 #include "ppapi/shared_impl/time_conversion.h"
13 #include "ppapi/shared_impl/var.h" 14 #include "ppapi/shared_impl/var.h"
14 #include "ppapi/thunk/enter.h" 15 #include "ppapi/thunk/enter.h"
16 #include "ppapi/thunk/ppb_image_data_api.h"
17 #include "ppapi/thunk/ppb_url_request_info_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"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
28 #include "ui/gfx/rect.h"
18 #include "webkit/plugins/ppapi/common.h" 29 #include "webkit/plugins/ppapi/common.h"
19 #include "webkit/plugins/ppapi/host_globals.h" 30 #include "webkit/plugins/ppapi/host_globals.h"
20 #include "webkit/plugins/ppapi/plugin_delegate.h" 31 #include "webkit/plugins/ppapi/plugin_delegate.h"
21 #include "webkit/plugins/ppapi/plugin_module.h" 32 #include "webkit/plugins/ppapi/plugin_module.h"
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 33 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
23 #include "webkit/plugins/ppapi/resource_helper.h" 34 #include "webkit/plugins/ppapi/resource_helper.h"
35 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
24 36
25 using ppapi::PPTimeToTime; 37 using ppapi::PPTimeToTime;
26 using ppapi::StringVar; 38 using ppapi::StringVar;
27 using ppapi::thunk::EnterResourceNoLock; 39 using ppapi::thunk::EnterResourceNoLock;
40 using ppapi::thunk::PPB_ImageData_API;
41 using ppapi::thunk::PPB_URLRequestInfo_API;
28 42
29 namespace webkit { 43 namespace webkit {
30 namespace ppapi { 44 namespace ppapi {
31 45
32 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) 46 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance)
33 : instance_(instance) { 47 : instance_(instance) {
34 } 48 }
35 49
36 PPB_Flash_Impl::~PPB_Flash_Impl() { 50 PPB_Flash_Impl::~PPB_Flash_Impl() {
37 } 51 }
38 52
53 void PPB_Flash_Impl::SetInstanceAlwaysOnTop(PP_Instance instance,
54 PP_Bool on_top) {
55 instance_->set_always_on_top(PP_ToBool(on_top));
56 }
57
58 PP_Bool PPB_Flash_Impl::DrawGlyphs(
59 PP_Instance instance,
60 PP_Resource pp_image_data,
61 const PP_BrowserFont_Trusted_Description* font_desc,
62 uint32_t color,
63 const PP_Point* position,
64 const PP_Rect* clip,
65 const float transformation[3][3],
66 PP_Bool allow_subpixel_aa,
67 uint32_t glyph_count,
68 const uint16_t glyph_indices[],
69 const PP_Point glyph_advances[]) {
70 EnterResourceNoLock<PPB_ImageData_API> enter(pp_image_data, true);
71 if (enter.failed())
72 return PP_FALSE;
73 PPB_ImageData_Impl* image_resource =
74 static_cast<PPB_ImageData_Impl*>(enter.object());
75
76 ImageDataAutoMapper mapper(image_resource);
77 if (!mapper.is_valid())
78 return PP_FALSE;
79
80 // Set up the typeface.
81 StringVar* face_name = StringVar::FromPPVar(font_desc->face);
82 if (!face_name)
83 return PP_FALSE;
84 int style = SkTypeface::kNormal;
85 if (font_desc->weight >= PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD)
86 style |= SkTypeface::kBold;
87 if (font_desc->italic)
88 style |= SkTypeface::kItalic;
89 skia::RefPtr<SkTypeface> typeface = skia::AdoptRef(
90 SkTypeface::CreateFromName(face_name->value().c_str(),
91 static_cast<SkTypeface::Style>(style)));
92 if (!typeface)
93 return PP_FALSE;
94
95 // Set up the canvas.
96 SkCanvas* canvas = image_resource->GetPlatformCanvas();
97 SkAutoCanvasRestore acr(canvas, true);
98
99 // Clip is applied in pixels before the transform.
100 SkRect clip_rect = { SkIntToScalar(clip->point.x),
101 SkIntToScalar(clip->point.y),
102 SkIntToScalar(clip->point.x + clip->size.width),
103 SkIntToScalar(clip->point.y + clip->size.height) };
104 canvas->clipRect(clip_rect);
105
106 // Convert & set the matrix.
107 SkMatrix matrix;
108 matrix.set(SkMatrix::kMScaleX, SkFloatToScalar(transformation[0][0]));
109 matrix.set(SkMatrix::kMSkewX, SkFloatToScalar(transformation[0][1]));
110 matrix.set(SkMatrix::kMTransX, SkFloatToScalar(transformation[0][2]));
111 matrix.set(SkMatrix::kMSkewY, SkFloatToScalar(transformation[1][0]));
112 matrix.set(SkMatrix::kMScaleY, SkFloatToScalar(transformation[1][1]));
113 matrix.set(SkMatrix::kMTransY, SkFloatToScalar(transformation[1][2]));
114 matrix.set(SkMatrix::kMPersp0, SkFloatToScalar(transformation[2][0]));
115 matrix.set(SkMatrix::kMPersp1, SkFloatToScalar(transformation[2][1]));
116 matrix.set(SkMatrix::kMPersp2, SkFloatToScalar(transformation[2][2]));
117 canvas->concat(matrix);
118
119 SkPaint paint;
120 paint.setColor(color);
121 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
122 paint.setAntiAlias(true);
123 paint.setHinting(SkPaint::kFull_Hinting);
124 paint.setTextSize(SkIntToScalar(font_desc->size));
125 paint.setTypeface(typeface.get()); // Takes a ref and manages lifetime.
126 if (allow_subpixel_aa) {
127 paint.setSubpixelText(true);
128 paint.setLCDRenderText(true);
129 }
130
131 SkScalar x = SkIntToScalar(position->x);
132 SkScalar y = SkIntToScalar(position->y);
133
134 // Build up the skia advances.
135 if (glyph_count == 0)
136 return PP_TRUE;
137 std::vector<SkPoint> storage;
138 storage.resize(glyph_count);
139 SkPoint* sk_positions = &storage[0];
140 for (uint32_t i = 0; i < glyph_count; i++) {
141 sk_positions[i].set(x, y);
142 x += SkFloatToScalar(glyph_advances[i].x);
143 y += SkFloatToScalar(glyph_advances[i].y);
144 }
145
146 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint);
147
148 return PP_TRUE;
149 }
150
151 int32_t PPB_Flash_Impl::Navigate(PP_Instance instance,
152 PP_Resource request_info,
153 const char* target,
154 PP_Bool from_user_action) {
155 EnterResourceNoLock<PPB_URLRequestInfo_API> enter(request_info, true);
156 if (enter.failed())
157 return PP_ERROR_BADRESOURCE;
158 return Navigate(instance, enter.object()->GetData(), target,
159 from_user_action);
160 }
161
162 int32_t PPB_Flash_Impl::Navigate(PP_Instance instance,
163 const ::ppapi::URLRequestInfoData& data,
164 const char* target,
165 PP_Bool from_user_action) {
166 if (!target)
167 return PP_ERROR_BADARGUMENT;
168 return instance_->Navigate(data, target, PP_ToBool(from_user_action));
169 }
170
39 double PPB_Flash_Impl::GetLocalTimeZoneOffset(PP_Instance instance, 171 double PPB_Flash_Impl::GetLocalTimeZoneOffset(PP_Instance instance,
40 PP_Time t) { 172 PP_Time t) {
41 // Evil hack. The time code handles exact "0" values as special, and produces 173 // Evil hack. The time code handles exact "0" values as special, and produces
42 // a "null" Time object. This will represent some date hundreds of years ago 174 // a "null" Time object. This will represent some date hundreds of years ago
43 // and will give us funny results at 1970 (there are some tests where this 175 // and will give us funny results at 1970 (there are some tests where this
44 // comes up, but it shouldn't happen in real life). To work around this 176 // comes up, but it shouldn't happen in real life). To work around this
45 // special handling, we just need to give it some nonzero value. 177 // special handling, we just need to give it some nonzero value.
46 if (t == 0.0) 178 if (t == 0.0)
47 t = 0.0000000001; 179 t = 0.0000000001;
48 180
49 // We can't do the conversion here because on Linux, the localtime calls 181 // We can't do the conversion here because on Linux, the localtime calls
50 // require filesystem access prohibited by the sandbox. 182 // require filesystem access prohibited by the sandbox.
51 return instance_->delegate()->GetLocalTimeZoneOffset(PPTimeToTime(t)); 183 return instance_->delegate()->GetLocalTimeZoneOffset(PPTimeToTime(t));
52 } 184 }
53 185
186 PP_Bool PPB_Flash_Impl::IsRectTopmost(PP_Instance instance,
187 const PP_Rect* rect) {
188 return PP_FromBool(instance_->IsRectTopmost(
189 gfx::Rect(rect->point.x, rect->point.y,
190 rect->size.width, rect->size.height)));
191 }
192
54 PP_Var PPB_Flash_Impl::GetSetting(PP_Instance instance, 193 PP_Var PPB_Flash_Impl::GetSetting(PP_Instance instance,
55 PP_FlashSetting setting) { 194 PP_FlashSetting setting) {
56 switch(setting) { 195 switch(setting) {
57 case PP_FLASHSETTING_LSORESTRICTIONS: { 196 case PP_FLASHSETTING_LSORESTRICTIONS: {
58 return PP_MakeInt32( 197 return PP_MakeInt32(
59 instance_->delegate()->GetLocalDataRestrictions( 198 instance_->delegate()->GetLocalDataRestrictions(
60 instance_->container()->element().document().url(), 199 instance_->container()->element().document().url(),
61 instance_->plugin_url())); 200 instance_->plugin_url()));
62 } 201 }
63 default: 202 default:
64 // No other settings are supported in-process. 203 // No other settings are supported in-process.
65 return PP_MakeUndefined(); 204 return PP_MakeUndefined();
66 } 205 }
67 } 206 }
68 207
69 } // namespace ppapi 208 } // namespace ppapi
70 } // namespace webkit 209 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698