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

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

Issue 11510008: Refactor 4 PPB_Flash functions to the new PPAPI resource model. (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>
9 8
10 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
11 #include "ppapi/c/private/ppb_flash.h" 10 #include "ppapi/c/private/ppb_flash.h"
12 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" 11 #include "ppapi/c/trusted/ppb_browser_font_trusted.h"
13 #include "ppapi/shared_impl/time_conversion.h" 12 #include "ppapi/shared_impl/time_conversion.h"
14 #include "ppapi/shared_impl/var.h" 13 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/thunk/enter.h" 14 #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"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
28 #include "ui/gfx/rect.h"
29 #include "webkit/plugins/ppapi/common.h" 18 #include "webkit/plugins/ppapi/common.h"
30 #include "webkit/plugins/ppapi/host_globals.h" 19 #include "webkit/plugins/ppapi/host_globals.h"
31 #include "webkit/plugins/ppapi/plugin_delegate.h" 20 #include "webkit/plugins/ppapi/plugin_delegate.h"
32 #include "webkit/plugins/ppapi/plugin_module.h" 21 #include "webkit/plugins/ppapi/plugin_module.h"
33 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
34 #include "webkit/plugins/ppapi/resource_helper.h" 23 #include "webkit/plugins/ppapi/resource_helper.h"
35 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
36 24
37 using ppapi::PPTimeToTime; 25 using ppapi::PPTimeToTime;
38 using ppapi::StringVar; 26 using ppapi::StringVar;
39 using ppapi::thunk::EnterResourceNoLock; 27 using ppapi::thunk::EnterResourceNoLock;
40 using ppapi::thunk::PPB_ImageData_API;
41 using ppapi::thunk::PPB_URLRequestInfo_API;
42 28
43 namespace webkit { 29 namespace webkit {
44 namespace ppapi { 30 namespace ppapi {
45 31
46 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) 32 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) {
47 : instance_(instance) {
48 } 33 }
49 34
50 PPB_Flash_Impl::~PPB_Flash_Impl() { 35 PPB_Flash_Impl::~PPB_Flash_Impl() {
51 } 36 }
52 37
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
171 PP_Bool PPB_Flash_Impl::IsRectTopmost(PP_Instance instance,
172 const PP_Rect* rect) {
173 return PP_FromBool(instance_->IsRectTopmost(
174 gfx::Rect(rect->point.x, rect->point.y,
175 rect->size.width, rect->size.height)));
176 }
177
178 } // namespace ppapi 38 } // namespace ppapi
179 } // namespace webkit 39 } // 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