Commit 194e48de authored by willchan@chromium.org's avatar willchan@chromium.org

Revert 114076 (broke Win shared builder) - Implement platform-independent DrawGlyphs for Flash.

This code was platform independent so could just be copied over into the
platform independent file with no changes.

Review URL: http://codereview.chromium.org/8899015

TBR=brettw@chromium.org
Review URL: http://codereview.chromium.org/8926003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114085 0039d316-1c4b-4281-b951-d872f2087c98
parent 2e77cb39
...@@ -266,6 +266,7 @@ ...@@ -266,6 +266,7 @@
'../plugins/ppapi/ppb_flash_file_impl.h', '../plugins/ppapi/ppb_flash_file_impl.h',
'../plugins/ppapi/ppb_flash_impl.cc', '../plugins/ppapi/ppb_flash_impl.cc',
'../plugins/ppapi/ppb_flash_impl.h', '../plugins/ppapi/ppb_flash_impl.h',
'../plugins/ppapi/ppb_flash_impl_linux.cc',
'../plugins/ppapi/ppb_flash_menu_impl.cc', '../plugins/ppapi/ppb_flash_menu_impl.cc',
'../plugins/ppapi/ppb_flash_menu_impl.h', '../plugins/ppapi/ppb_flash_menu_impl.h',
'../plugins/ppapi/ppb_flash_net_connector_impl.cc', '../plugins/ppapi/ppb_flash_net_connector_impl.cc',
......
...@@ -9,19 +9,10 @@ ...@@ -9,19 +9,10 @@
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/time.h" #include "base/time.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/c/private/ppb_flash.h" #include "ppapi/c/private/ppb_flash.h"
#include "ppapi/shared_impl/time_conversion.h" #include "ppapi/shared_impl/time_conversion.h"
#include "ppapi/shared_impl/var.h" #include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h" #include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_image_data_api.h"
#include "skia/ext/platform_canvas.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/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/host_globals.h"
#include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_delegate.h"
...@@ -29,12 +20,10 @@ ...@@ -29,12 +20,10 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_helper.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
using ppapi::PPTimeToTime; using ppapi::PPTimeToTime;
using ppapi::StringVar; using ppapi::StringVar;
using ppapi::thunk::EnterResource; using ppapi::thunk::EnterResource;
using ppapi::thunk::PPB_ImageData_API;
using ppapi::thunk::PPB_URLRequestInfo_API; using ppapi::thunk::PPB_URLRequestInfo_API;
namespace webkit { namespace webkit {
...@@ -49,97 +38,6 @@ void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) { ...@@ -49,97 +38,6 @@ void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) {
instance->set_always_on_top(PPBoolToBool(on_top)); instance->set_always_on_top(PPBoolToBool(on_top));
} }
PP_Bool DrawGlyphs(PP_Instance,
PP_Resource pp_image_data,
const PP_FontDescription_Dev* font_desc,
uint32_t color,
PP_Point position,
PP_Rect clip,
const float transformation[3][3],
uint32_t glyph_count,
const uint16_t glyph_indices[],
const PP_Point glyph_advances[]) {
EnterResource<PPB_ImageData_API> enter(pp_image_data, true);
if (enter.failed())
return PP_FALSE;
PPB_ImageData_Impl* image_resource =
static_cast<PPB_ImageData_Impl*>(enter.object());
ImageDataAutoMapper mapper(image_resource);
if (!mapper.is_valid())
return PP_FALSE;
// Set up the typeface.
StringVar* face_name = StringVar::FromPPVar(font_desc->face);
if (!face_name)
return PP_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 PP_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 PP_TRUE;
}
PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) {
PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
if (!instance) if (!instance)
...@@ -217,7 +115,7 @@ PP_Var GetCommandLineArgs(PP_Module pp_module) { ...@@ -217,7 +115,7 @@ PP_Var GetCommandLineArgs(PP_Module pp_module) {
const PPB_Flash ppb_flash = { const PPB_Flash ppb_flash = {
&SetInstanceAlwaysOnTop, &SetInstanceAlwaysOnTop,
&DrawGlyphs, &PPB_Flash_Impl::DrawGlyphs,
&GetProxyForURL, &GetProxyForURL,
&Navigate, &Navigate,
&RunMessageLoop, &RunMessageLoop,
......
...@@ -20,6 +20,22 @@ class PPB_Flash_Impl { ...@@ -20,6 +20,22 @@ class PPB_Flash_Impl {
// exposed to the plugin. // exposed to the plugin.
static const PPB_Flash* GetInterface(); static const PPB_Flash* GetInterface();
static PP_Bool DrawGlyphs(PP_Instance pp_instance,
PP_Resource pp_image_data,
const PP_FontDescription_Dev* font_desc,
uint32_t color,
PP_Point position,
PP_Rect clip,
const float transformation[3][3],
uint32_t glyph_count,
const uint16_t glyph_indices[],
const PP_Point glyph_advances[])
#if defined(OS_POSIX) && !defined(OS_MACOSX)
;
#else
{ return PP_FALSE; }
#endif
private: private:
DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Impl); DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Impl);
}; };
......
// Copyright (c) 2011 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/plugins/ppapi/ppb_flash_impl.h"
#include "ppapi/c/pp_point.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "skia/ext/platform_canvas.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/plugins/ppapi/ppb_image_data_impl.h"
using ppapi::StringVar;
using ppapi::thunk::EnterResource;
using ppapi::thunk::PPB_ImageData_API;
namespace webkit {
namespace ppapi {
PP_Bool PPB_Flash_Impl::DrawGlyphs(PP_Instance,
PP_Resource pp_image_data,
const PP_FontDescription_Dev* font_desc,
uint32_t color,
PP_Point position,
PP_Rect clip,
const float transformation[3][3],
uint32_t glyph_count,
const uint16_t glyph_indices[],
const PP_Point glyph_advances[]) {
EnterResource<PPB_ImageData_API> enter(pp_image_data, true);
if (enter.failed())
return PP_FALSE;
PPB_ImageData_Impl* image_resource =
static_cast<PPB_ImageData_Impl*>(enter.object());
ImageDataAutoMapper mapper(image_resource);
if (!mapper.is_valid())
return PP_FALSE;
// Set up the typeface.
StringVar* face_name = StringVar::FromPPVar(font_desc->face);
if (!face_name)
return PP_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 PP_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 PP_TRUE;
}
} // namespace ppapi
} // namespace webkit
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment