diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-08 05:19:33 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-08 05:19:33 +0000 |
commit | 9768dc7a627856efdafb8b8a6522eb1e31900617 (patch) | |
tree | cdded08624dc42b56b44d0ec3764bec1fc9f4cfd | |
parent | 2edc13910054851ce8848d532aa39f1a714be863 (diff) | |
download | chromium_src-9768dc7a627856efdafb8b8a6522eb1e31900617.zip chromium_src-9768dc7a627856efdafb8b8a6522eb1e31900617.tar.gz chromium_src-9768dc7a627856efdafb8b8a6522eb1e31900617.tar.bz2 |
Add a glyph drawing routine to private Pepper interface. The current
implementation is Linux only.
This also changes the Private font interface to use the "regular"
PP_FontDescription_Dev struct for specifying the font, which allows us to unify
some of the data here. I kept the character set stuff as a separate parameter
which is needed for compat in a few cases.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/3569013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61920 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/plugins/pepper_private.cc | 25 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_private2.cc | 3 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_private2.h | 19 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_private2_linux.cc | 110 | ||||
-rw-r--r-- | webkit/glue/plugins/ppb_private.h | 25 | ||||
-rw-r--r-- | webkit/glue/plugins/ppb_private2.h | 14 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 1 |
7 files changed, 173 insertions, 24 deletions
diff --git a/webkit/glue/plugins/pepper_private.cc b/webkit/glue/plugins/pepper_private.cc index cafd29e..1346ce3 100644 --- a/webkit/glue/plugins/pepper_private.cc +++ b/webkit/glue/plugins/pepper_private.cc @@ -18,14 +18,19 @@ #include "webkit/glue/plugins/pepper_plugin_module.h" #include "webkit/glue/plugins/pepper_var.h" #include "webkit/glue/plugins/ppb_private.h" +#include "webkit/glue/plugins/pepper_var.h" namespace pepper { #if defined(OS_LINUX) class PrivateFontFile : public Resource { public: - PrivateFontFile(PluginModule* module, int fd) : Resource(module), fd_(fd) {} - virtual ~PrivateFontFile() {} + PrivateFontFile(PluginModule* module, int fd) + : Resource(module), + fd_(fd) { + } + virtual ~PrivateFontFile() { + } // Resource overrides. PrivateFontFile* AsPrivateFontFile() { return this; } @@ -125,16 +130,22 @@ PP_Resource GetResourceImage(PP_Module module_id, PP_ResourceImage image_id) { PP_Resource GetFontFileWithFallback( PP_Module module_id, - const PP_PrivateFontFileDescription* description) { + const PP_FontDescription_Dev* description, + PP_PrivateFontCharset charset) { #if defined(OS_LINUX) PluginModule* module = PluginModule::FromPPModule(module_id); if (!module) return 0; - int fd = webkit_glue::MatchFontWithFallback(description->face, - description->weight >= 700, - description->italic, - description->charset); + scoped_refptr<StringVar> face_name(StringVar::FromPPVar(description->face)); + if (!face_name) + return 0; + + int fd = webkit_glue::MatchFontWithFallback( + face_name->value().c_str(), + description->weight >= PP_FONTWEIGHT_BOLD, + description->italic, + charset); if (fd == -1) return 0; diff --git a/webkit/glue/plugins/pepper_private2.cc b/webkit/glue/plugins/pepper_private2.cc index 9a740aa..0efa13a 100644 --- a/webkit/glue/plugins/pepper_private2.cc +++ b/webkit/glue/plugins/pepper_private2.cc @@ -19,7 +19,8 @@ void SetInstanceAlwaysOnTop(PP_Instance pp_instance, bool on_top) { } const PPB_Private2 ppb_private2 = { - &SetInstanceAlwaysOnTop + &SetInstanceAlwaysOnTop, + &Private2::DrawGlyphs }; } // namespace diff --git a/webkit/glue/plugins/pepper_private2.h b/webkit/glue/plugins/pepper_private2.h index 492669a..a8a4b6e 100644 --- a/webkit/glue/plugins/pepper_private2.h +++ b/webkit/glue/plugins/pepper_private2.h @@ -5,8 +5,12 @@ #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_PRIVATE2_H_ #define WEBKIT_GLUE_PLUGINS_PEPPER_PRIVATE2_H_ +#include "build/build_config.h" +#include "third_party/ppapi/c/pp_point.h" +#include "third_party/ppapi/c/pp_rect.h" #include "webkit/glue/plugins/pepper_resource.h" +struct PP_FontDescription_Dev; struct PPB_Private2; namespace pepper { @@ -16,6 +20,21 @@ class Private2 { // Returns a pointer to the interface implementing PPB_Private2 that is // exposed to the plugin. static const PPB_Private2* GetInterface(); + + static bool DrawGlyphs(PP_Resource pp_image_data, + const PP_FontDescription_Dev* font_desc, + uint32_t color, + PP_Point position, + PP_Rect clip, + float transformation[3][3], + uint32_t glyph_count, + uint16_t glyph_indices[], + PP_Point glyph_advances[]) +#if defined(OS_LINUX) + ; +#else + { return false; } +#endif }; } // namespace pepper diff --git a/webkit/glue/plugins/pepper_private2_linux.cc b/webkit/glue/plugins/pepper_private2_linux.cc new file mode 100644 index 0000000..4beb6b6 --- /dev/null +++ b/webkit/glue/plugins/pepper_private2_linux.cc @@ -0,0 +1,110 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/glue/plugins/pepper_private2.h" + +#include "skia/ext/platform_canvas.h" +#include "third_party/ppapi/c/pp_point.h" +#include "third_party/ppapi/c/pp_rect.h" +#include "third_party/ppapi/c/dev/ppb_font_dev.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkMatrix.h" +#include "third_party/skia/include/core/SkPaint.h" +#include "third_party/skia/include/core/SkPoint.h" +#include "third_party/skia/include/core/SkTemplates.h" +#include "third_party/skia/include/core/SkTypeface.h" +#include "webkit/glue/plugins/pepper_image_data.h" +#include "webkit/glue/plugins/pepper_var.h" + +namespace pepper { + +bool Private2::DrawGlyphs(PP_Resource pp_image_data, + const PP_FontDescription_Dev* font_desc, + uint32_t color, + PP_Point position, + PP_Rect clip, + float transformation[3][3], + uint32_t glyph_count, + uint16_t glyph_indices[], + PP_Point glyph_advances[]) { + scoped_refptr<ImageData> image_resource( + Resource::GetAs<ImageData>(pp_image_data)); + if (!image_resource.get()) + return false; + ImageDataAutoMapper mapper(image_resource); + if (!mapper.is_valid()) + return false; + + // Set up the typeface. + scoped_refptr<StringVar> face_name(StringVar::FromPPVar(font_desc->face)); + if (!face_name) + return false; + int style = SkTypeface::kNormal; + if (font_desc->weight >= PP_FONTWEIGHT_BOLD) + style |= SkTypeface::kBold; + if (font_desc->italic) + style |= SkTypeface::kItalic; + SkTypeface* typeface = + SkTypeface::CreateFromName(face_name->value().c_str(), + static_cast<SkTypeface::Style>(style)); + if (!typeface) + return false; + + // Set up the canvas. + SkCanvas* canvas = image_resource->mapped_canvas(); + canvas->save(); + + // Clip is applied in pixels before the transform. + SkRect clip_rect = { clip.point.x, clip.point.y, + clip.point.x + clip.size.width, + clip.point.y + clip.size.height }; + canvas->clipRect(clip_rect); + + // -- Do not return early below this. The canvas needs restoring and the + // typeface will leak if it's not assigned to the paint (it's refcounted and + // the refcount is currently 0). + + // Convert & set the matrix. + SkMatrix matrix; + matrix.set(SkMatrix::kMScaleX, SkFloatToScalar(transformation[0][0])); + matrix.set(SkMatrix::kMSkewX, SkFloatToScalar(transformation[0][1])); + matrix.set(SkMatrix::kMTransX, SkFloatToScalar(transformation[0][2])); + matrix.set(SkMatrix::kMSkewY, SkFloatToScalar(transformation[1][0])); + matrix.set(SkMatrix::kMScaleY, SkFloatToScalar(transformation[1][1])); + matrix.set(SkMatrix::kMTransY, SkFloatToScalar(transformation[1][2])); + matrix.set(SkMatrix::kMPersp0, SkFloatToScalar(transformation[2][0])); + matrix.set(SkMatrix::kMPersp1, SkFloatToScalar(transformation[2][1])); + matrix.set(SkMatrix::kMPersp2, SkFloatToScalar(transformation[2][2])); + canvas->concat(matrix); + + SkPaint paint; + paint.setColor(color); + paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); + paint.setAntiAlias(true); + paint.setHinting(SkPaint::kFull_Hinting); + paint.setTextSize(SkIntToScalar(font_desc->size)); + paint.setTypeface(typeface); // Takes a ref and manages lifetime. + paint.setSubpixelText(true); + paint.setLCDRenderText(true); + + SkScalar x = SkIntToScalar(position.x); + SkScalar y = SkIntToScalar(position.y); + + // Build up the skia advances. + SkAutoSTMalloc<32, SkPoint> storage(glyph_count); + SkPoint* sk_positions = storage.get(); + for (uint32_t i = 0; i < glyph_count; i++) { + sk_positions[i].set(x, y); + x += SkFloatToScalar(glyph_advances[i].x); + y += SkFloatToScalar(glyph_advances[i].y); + } + + canvas->drawPosText(glyph_indices, glyph_count * 2, sk_positions, paint); + + canvas->restore(); + return true; +} + +} // namespace pepper + diff --git a/webkit/glue/plugins/ppb_private.h b/webkit/glue/plugins/ppb_private.h index 9617b93..1615288 100644 --- a/webkit/glue/plugins/ppb_private.h +++ b/webkit/glue/plugins/ppb_private.h @@ -6,11 +6,15 @@ #define WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_ #include "base/string16.h" +#include "third_party/ppapi/c/dev/ppb_font_dev.h" #include "third_party/ppapi/c/pp_module.h" #include "third_party/ppapi/c/pp_var.h" #define PPB_PRIVATE_INTERFACE "PPB_Private;1" +// From the public PPB_Font_Dev file. +struct PP_FontDescription_Dev; + typedef enum { PP_RESOURCESTRING_PDFGETPASSWORD = 0, } PP_ResourceString; @@ -42,17 +46,6 @@ typedef enum { } PP_ResourceImage; typedef enum { - PP_PRIVATEFONTPITCH_DEFAULT = 0, - PP_PRIVATEFONTPITCH_FIXED = 1 -} PP_PrivateFontPitch; - -typedef enum { - PP_PRIVATEFONTFAMILY_DEFAULT = 0, - PP_PRIVATEFONTFAMILY_ROMAN = 1, - PP_PRIVATEFONTFAMILY_SCRIPT = 2 -} PP_PrivateFontFamily; - -typedef enum { PP_PRIVATEFONTCHARSET_ANSI = 0, PP_PRIVATEFONTCHARSET_DEFAULT = 1, PP_PRIVATEFONTCHARSET_SYMBOL = 2, @@ -78,9 +71,6 @@ struct PP_PrivateFontFileDescription { const char* face; uint32_t weight; bool italic; - PP_PrivateFontPitch pitch; - PP_PrivateFontFamily family; - PP_PrivateFontCharset charset; }; struct PP_PrivateFindResult { @@ -97,10 +87,13 @@ struct PPB_Private { PP_ResourceImage image_id); // Returns a resource identifying a font file corresponding to the given font - // request after applying the browser-specific fallback. Linux only. + // request after applying the browser-specific fallback. + // + // Currently Linux-only. PP_Resource (*GetFontFileWithFallback)( PP_Module module, - const PP_PrivateFontFileDescription* description); + const PP_FontDescription_Dev* description, + PP_PrivateFontCharset charset); // Given a resource previously returned by GetFontFileWithFallback, returns // a pointer to the requested font table. Linux only. diff --git a/webkit/glue/plugins/ppb_private2.h b/webkit/glue/plugins/ppb_private2.h index ca45471..fe84f7f 100644 --- a/webkit/glue/plugins/ppb_private2.h +++ b/webkit/glue/plugins/ppb_private2.h @@ -7,15 +7,29 @@ #include "third_party/ppapi/c/pp_instance.h" #include "third_party/ppapi/c/pp_module.h" +#include "third_party/ppapi/c/pp_point.h" +#include "third_party/ppapi/c/pp_rect.h" #include "third_party/ppapi/c/pp_var.h" #define PPB_PRIVATE2_INTERFACE "PPB_Private2;1" +struct PP_FontDescription_Dev; + struct PPB_Private2 { // Sets or clears the rendering hint that the given plugin instance is always // on top of page content. Somewhat more optimized painting can be used in // this case. void (*SetInstanceAlwaysOnTop)(PP_Instance instance, bool on_top); + + bool (*DrawGlyphs)(PP_Resource pp_image_data, + const PP_FontDescription_Dev* font_desc, + uint32_t color, + PP_Point position, + PP_Rect clip, + float transformation[3][3], + uint32_t glyph_count, + uint16_t glyph_indices[], + PP_Point glyph_advances[]); }; #endif // WEBKIT_GLUE_PLUGINS_PPB_PRIVATE2_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 9c1f92e..50dda7a 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -226,6 +226,7 @@ 'plugins/pepper_private.h', 'plugins/pepper_private2.cc', 'plugins/pepper_private2.h', + 'plugins/pepper_private2_linux.cc', 'plugins/pepper_resource_tracker.cc', 'plugins/pepper_resource_tracker.h', 'plugins/pepper_resource.cc', |