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

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_impl_linux.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.cc ('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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/ppapi/ppb_flash_impl.h"
6
7 #include "ppapi/c/pp_point.h"
8 #include "ppapi/c/pp_rect.h"
9 #include "ppapi/c/dev/ppb_font_dev.h"
10 #include "ppapi/shared_impl/var.h"
11 #include "ppapi/thunk/enter.h"
12 #include "skia/ext/platform_canvas.h"
13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkMatrix.h"
15 #include "third_party/skia/include/core/SkPaint.h"
16 #include "third_party/skia/include/core/SkPoint.h"
17 #include "third_party/skia/include/core/SkTemplates.h"
18 #include "third_party/skia/include/core/SkTypeface.h"
19 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
20
21 using ppapi::StringVar;
22 using ppapi::thunk::EnterResource;
23 using ppapi::thunk::PPB_ImageData_API;
24
25 namespace webkit {
26 namespace ppapi {
27
28 PP_Bool PPB_Flash_Impl::DrawGlyphs(PP_Instance,
29 PP_Resource pp_image_data,
30 const PP_FontDescription_Dev* font_desc,
31 uint32_t color,
32 PP_Point position,
33 PP_Rect clip,
34 const float transformation[3][3],
35 uint32_t glyph_count,
36 const uint16_t glyph_indices[],
37 const PP_Point glyph_advances[]) {
38 EnterResource<PPB_ImageData_API> enter(pp_image_data, true);
39 if (enter.failed())
40 return PP_FALSE;
41 PPB_ImageData_Impl* image_resource =
42 static_cast<PPB_ImageData_Impl*>(enter.object());
43
44 ImageDataAutoMapper mapper(image_resource);
45 if (!mapper.is_valid())
46 return PP_FALSE;
47
48 // Set up the typeface.
49 StringVar* face_name = StringVar::FromPPVar(font_desc->face);
50 if (!face_name)
51 return PP_FALSE;
52 int style = SkTypeface::kNormal;
53 if (font_desc->weight >= PP_FONTWEIGHT_BOLD)
54 style |= SkTypeface::kBold;
55 if (font_desc->italic)
56 style |= SkTypeface::kItalic;
57 SkTypeface* typeface =
58 SkTypeface::CreateFromName(face_name->value().c_str(),
59 static_cast<SkTypeface::Style>(style));
60 if (!typeface)
61 return PP_FALSE;
62
63 // Set up the canvas.
64 SkCanvas* canvas = image_resource->mapped_canvas();
65 canvas->save();
66
67 // Clip is applied in pixels before the transform.
68 SkRect clip_rect = { clip.point.x, clip.point.y,
69 clip.point.x + clip.size.width,
70 clip.point.y + clip.size.height };
71 canvas->clipRect(clip_rect);
72
73 // -- Do not return early below this. The canvas needs restoring and the
74 // typeface will leak if it's not assigned to the paint (it's refcounted and
75 // the refcount is currently 0).
76
77 // Convert & set the matrix.
78 SkMatrix matrix;
79 matrix.set(SkMatrix::kMScaleX, SkFloatToScalar(transformation[0][0]));
80 matrix.set(SkMatrix::kMSkewX, SkFloatToScalar(transformation[0][1]));
81 matrix.set(SkMatrix::kMTransX, SkFloatToScalar(transformation[0][2]));
82 matrix.set(SkMatrix::kMSkewY, SkFloatToScalar(transformation[1][0]));
83 matrix.set(SkMatrix::kMScaleY, SkFloatToScalar(transformation[1][1]));
84 matrix.set(SkMatrix::kMTransY, SkFloatToScalar(transformation[1][2]));
85 matrix.set(SkMatrix::kMPersp0, SkFloatToScalar(transformation[2][0]));
86 matrix.set(SkMatrix::kMPersp1, SkFloatToScalar(transformation[2][1]));
87 matrix.set(SkMatrix::kMPersp2, SkFloatToScalar(transformation[2][2]));
88 canvas->concat(matrix);
89
90 SkPaint paint;
91 paint.setColor(color);
92 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
93 paint.setAntiAlias(true);
94 paint.setHinting(SkPaint::kFull_Hinting);
95 paint.setTextSize(SkIntToScalar(font_desc->size));
96 paint.setTypeface(typeface); // Takes a ref and manages lifetime.
97 paint.setSubpixelText(true);
98 paint.setLCDRenderText(true);
99
100 SkScalar x = SkIntToScalar(position.x);
101 SkScalar y = SkIntToScalar(position.y);
102
103 // Build up the skia advances.
104 SkAutoSTMalloc<32, SkPoint> storage(glyph_count);
105 SkPoint* sk_positions = storage.get();
106 for (uint32_t i = 0; i < glyph_count; i++) {
107 sk_positions[i].set(x, y);
108 x += SkFloatToScalar(glyph_advances[i].x);
109 y += SkFloatToScalar(glyph_advances[i].y);
110 }
111
112 canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint);
113
114 canvas->restore();
115 return PP_TRUE;
116 }
117
118 } // namespace ppapi
119 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698