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

Side by Side Diff: webkit/glue/plugins/pepper_private2_linux.cc

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

Powered by Google App Engine
This is Rietveld 408576698