summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/ppapi_shared.gypi7
-rw-r--r--ppapi/proxy/plugin_dispatcher.h1
-rw-r--r--ppapi/proxy/plugin_proxy_delegate.h10
-rw-r--r--ppapi/proxy/ppapi_proxy_test.cc11
-rw-r--r--ppapi/proxy/ppapi_proxy_test.h3
-rw-r--r--ppapi/proxy/ppb_font_proxy.cc182
-rw-r--r--ppapi/proxy/ppb_font_proxy.h50
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.cc4
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.h3
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc10
-rw-r--r--ppapi/shared_impl/ppb_font_shared.cc35
-rw-r--r--ppapi/shared_impl/ppb_font_shared.h32
-rw-r--r--ppapi/shared_impl/private/ppb_font_shared.cc419
-rw-r--r--ppapi/shared_impl/private/ppb_font_shared.h72
-rw-r--r--ppapi/shared_impl/webkit_forwarding.h29
-rw-r--r--ppapi/thunk/ppb_font_api.h3
-rw-r--r--ppapi/thunk/ppb_image_data_api.h7
17 files changed, 355 insertions, 523 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index 7016fb6..2802b5d 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -17,8 +17,6 @@
'../net/net.gyp:net',
'../skia/skia.gyp:skia',
'../third_party/icu/icu.gyp:icuuc',
- # TODO(ananta) : The WebKit dependency needs to move to a new target for NACL.
- '../third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
'../ui/gfx/surface/surface.gyp:surface',
],
'defines': [
@@ -60,6 +58,8 @@
'shared_impl/ppb_file_io_shared.h',
'shared_impl/ppb_file_ref_shared.cc',
'shared_impl/ppb_file_ref_shared.h',
+ 'shared_impl/ppb_font_shared.cc',
+ 'shared_impl/ppb_font_shared.h',
'shared_impl/ppb_graphics_3d_shared.cc',
'shared_impl/ppb_graphics_3d_shared.h',
'shared_impl/ppb_image_data_shared.cc',
@@ -107,9 +107,6 @@
'shared_impl/private/net_address_private_impl.cc',
'shared_impl/private/net_address_private_impl.h',
- 'shared_impl/private/ppb_font_shared.cc',
- 'shared_impl/private/ppb_font_shared.h',
-
'shared_impl/private/tcp_socket_private_impl.cc',
'shared_impl/private/tcp_socket_private_impl.h',
'shared_impl/private/udp_socket_private_impl.cc',
diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h
index 947ab0a..47df95d 100644
--- a/ppapi/proxy/plugin_dispatcher.h
+++ b/ppapi/proxy/plugin_dispatcher.h
@@ -24,6 +24,7 @@ namespace ppapi {
struct Preferences;
class Resource;
+class WebKitForwarding;
namespace proxy {
diff --git a/ppapi/proxy/plugin_proxy_delegate.h b/ppapi/proxy/plugin_proxy_delegate.h
index 5045ba7..07287ed 100644
--- a/ppapi/proxy/plugin_proxy_delegate.h
+++ b/ppapi/proxy/plugin_proxy_delegate.h
@@ -12,6 +12,16 @@ class PPAPI_PROXY_EXPORT PluginProxyDelegate {
public:
virtual ~PluginProxyDelegate() {}
+ // Returns the WebKit forwarding object used to make calls into WebKit.
+ // Necessary only on the plugin side.
+ virtual WebKitForwarding* GetWebKitForwarding() = 0;
+
+ // Posts the given task to the WebKit thread associated with this plugin
+ // process. The WebKit thread should be lazily created if it does not
+ // exist yet.
+ virtual void PostToWebKitThread(const tracked_objects::Location& from_here,
+ const base::Closure& task) = 0;
+
// Sends the given message to the browser. Identical semantics to
// IPC::Message::Sender interface.
virtual bool SendToBrowser(IPC::Message* msg) = 0;
diff --git a/ppapi/proxy/ppapi_proxy_test.cc b/ppapi/proxy/ppapi_proxy_test.cc
index 7bfacc5..15dc967 100644
--- a/ppapi/proxy/ppapi_proxy_test.cc
+++ b/ppapi/proxy/ppapi_proxy_test.cc
@@ -212,6 +212,17 @@ void PluginProxyTestHarness::PluginDelegateMock::Unregister(
uint32 plugin_dispatcher_id) {
}
+ppapi::WebKitForwarding*
+PluginProxyTestHarness::PluginDelegateMock::GetWebKitForwarding() {
+ NOTREACHED();
+ return NULL;
+}
+
+void PluginProxyTestHarness::PluginDelegateMock::PostToWebKitThread(
+ const tracked_objects::Location& from_here, const base::Closure& task) {
+ NOTREACHED();
+}
+
bool PluginProxyTestHarness::PluginDelegateMock::SendToBrowser(
IPC::Message* msg) {
NOTREACHED();
diff --git a/ppapi/proxy/ppapi_proxy_test.h b/ppapi/proxy/ppapi_proxy_test.h
index 6278f71..5816188 100644
--- a/ppapi/proxy/ppapi_proxy_test.h
+++ b/ppapi/proxy/ppapi_proxy_test.h
@@ -121,6 +121,9 @@ class PluginProxyTestHarness : public ProxyTestHarnessBase {
virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE;
// PluginPepperDelegate implementation.
+ virtual ppapi::WebKitForwarding* GetWebKitForwarding() OVERRIDE;
+ virtual void PostToWebKitThread(const tracked_objects::Location& from_here,
+ const base::Closure& task) OVERRIDE;
virtual bool SendToBrowser(IPC::Message* msg) OVERRIDE;
virtual void PreCacheFont(const void* logfontw) OVERRIDE;
diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc
index b12c22e..49d3892 100644
--- a/ppapi/proxy/ppb_font_proxy.cc
+++ b/ppapi/proxy/ppb_font_proxy.cc
@@ -4,18 +4,46 @@
#include "ppapi/proxy/ppb_font_proxy.h"
+#include "base/bind.h"
+#include "base/debug/trace_event.h"
#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_globals.h"
#include "ppapi/proxy/plugin_proxy_delegate.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/ppb_image_data_proxy.h"
+#include "ppapi/proxy/serialized_var.h"
+#include "ppapi/shared_impl/ppapi_preferences.h"
+#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/var.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_image_data_api.h"
+#include "ppapi/thunk/thunk.h"
+using ppapi::thunk::EnterResourceNoLock;
+using ppapi::thunk::PPB_Font_API;
using ppapi::thunk::PPB_Font_FunctionAPI;
+using ppapi::thunk::PPB_ImageData_API;
namespace ppapi {
namespace proxy {
+namespace {
+
+bool PPTextRunToTextRun(const PP_TextRun_Dev* run,
+ WebKitForwarding::Font::TextRun* output) {
+ StringVar* str = StringVar::FromPPVar(run->text);
+ if (!str)
+ return false;
+
+ output->text = str->value();
+ output->rtl = PP_ToBool(run->rtl);
+ output->override_direction = PP_ToBool(run->override_direction);
+ return true;
+}
+
+} // namespace
+
PPB_Font_Proxy::PPB_Font_Proxy(Dispatcher* dispatcher)
: InterfaceProxy(dispatcher) {
}
@@ -27,8 +55,6 @@ PPB_Font_FunctionAPI* PPB_Font_Proxy::AsPPB_Font_FunctionAPI() {
return this;
}
-// TODO(ananta)
-// This needs to be wired up to the PPAPI plugin code.
PP_Var PPB_Font_Proxy::GetFontFamilies(PP_Instance instance) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
@@ -50,5 +76,157 @@ bool PPB_Font_Proxy::OnMessageReceived(const IPC::Message& msg) {
return false;
}
+Font::Font(const HostResource& resource,
+ const PP_FontDescription_Dev& desc)
+ : Resource(resource),
+ webkit_event_(false, false),
+ font_forwarding_(NULL) {
+ TRACE_EVENT0("ppapi proxy", "Font::Font");
+ StringVar* face = StringVar::FromPPVar(desc.face);
+
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
+ if (!dispatcher)
+ return;
+ WebKitForwarding* forwarding =
+ PluginGlobals::Get()->plugin_proxy_delegate()->GetWebKitForwarding();
+
+ RunOnWebKitThread(true,
+ base::Bind(&WebKitForwarding::CreateFontForwarding,
+ base::Unretained(forwarding),
+ &webkit_event_, desc,
+ face ? face->value() : std::string(),
+ dispatcher->preferences(),
+ &font_forwarding_));
+}
+
+Font::~Font() {
+ if (font_forwarding_) {
+ RunOnWebKitThread(false,
+ base::Bind(&DeleteFontForwarding, font_forwarding_));
+ }
+}
+
+PPB_Font_API* Font::AsPPB_Font_API() {
+ return this;
+}
+
+PP_Bool Font::Describe(PP_FontDescription_Dev* description,
+ PP_FontMetrics_Dev* metrics) {
+ TRACE_EVENT0("ppapi proxy", "Font::Describe");
+ std::string face;
+ PP_Bool result = PP_FALSE;
+ if (font_forwarding_) {
+ RunOnWebKitThread(true,
+ base::Bind(&WebKitForwarding::Font::Describe,
+ base::Unretained(font_forwarding_),
+ &webkit_event_, description, &face, metrics,
+ &result));
+ }
+
+ if (PP_ToBool(result))
+ description->face = StringVar::StringToPPVar(face);
+ else
+ description->face = PP_MakeUndefined();
+ return result;
+}
+
+PP_Bool Font::DrawTextAt(PP_Resource pp_image_data,
+ const PP_TextRun_Dev* text,
+ const PP_Point* position,
+ uint32_t color,
+ const PP_Rect* clip,
+ PP_Bool image_data_is_opaque) {
+ TRACE_EVENT0("ppapi proxy", "Font::DrawTextAt");
+ if (!font_forwarding_)
+ return PP_FALSE;
+
+ // Convert to an ImageData object.
+ EnterResourceNoLock<PPB_ImageData_API> enter(pp_image_data, true);
+ if (enter.failed())
+ return PP_FALSE;
+ ImageData* image_data = static_cast<ImageData*>(enter.object());
+
+ skia::PlatformCanvas* canvas = image_data->mapped_canvas();
+ bool needs_unmapping = false;
+ if (!canvas) {
+ needs_unmapping = true;
+ image_data->Map();
+ canvas = image_data->mapped_canvas();
+ if (!canvas)
+ return PP_FALSE; // Failure mapping.
+ }
+
+ WebKitForwarding::Font::TextRun run;
+ if (!PPTextRunToTextRun(text, &run)) {
+ if (needs_unmapping)
+ image_data->Unmap();
+ return PP_FALSE;
+ }
+ RunOnWebKitThread(
+ true,
+ base::Bind(&WebKitForwarding::Font::DrawTextAt,
+ base::Unretained(font_forwarding_), &webkit_event_,
+ WebKitForwarding::Font::DrawTextParams(canvas, run, position,
+ color, clip,
+ image_data_is_opaque)));
+
+ if (needs_unmapping)
+ image_data->Unmap();
+ return PP_TRUE;
+}
+
+int32_t Font::MeasureText(const PP_TextRun_Dev* text) {
+ TRACE_EVENT0("ppapi proxy", "Font::MeasureText");
+ WebKitForwarding::Font::TextRun run;
+ if (!font_forwarding_ || !PPTextRunToTextRun(text, &run))
+ return -1;
+ int32_t result = -1;
+ RunOnWebKitThread(true,
+ base::Bind(&WebKitForwarding::Font::MeasureText,
+ base::Unretained(font_forwarding_),
+ &webkit_event_, run, &result));
+ return result;
+}
+
+uint32_t Font::CharacterOffsetForPixel(const PP_TextRun_Dev* text,
+ int32_t pixel_position) {
+ TRACE_EVENT0("ppapi proxy", "Font::CharacterOffsetForPixel");
+ WebKitForwarding::Font::TextRun run;
+ if (!font_forwarding_ || !PPTextRunToTextRun(text, &run))
+ return -1;
+ uint32_t result = -1;
+ RunOnWebKitThread(true,
+ base::Bind(&WebKitForwarding::Font::CharacterOffsetForPixel,
+ base::Unretained(font_forwarding_),
+ &webkit_event_, run, pixel_position, &result));
+ return result;
+}
+
+int32_t Font::PixelOffsetForCharacter(const PP_TextRun_Dev* text,
+ uint32_t char_offset) {
+ TRACE_EVENT0("ppapi proxy", "Font::PixelOffsetForCharacter");
+ WebKitForwarding::Font::TextRun run;
+ if (!font_forwarding_ || !PPTextRunToTextRun(text, &run))
+ return -1;
+ int32_t result = -1;
+ RunOnWebKitThread(true,
+ base::Bind(&WebKitForwarding::Font::PixelOffsetForCharacter,
+ base::Unretained(font_forwarding_),
+ &webkit_event_, run, char_offset, &result));
+ return result;
+}
+
+void Font::RunOnWebKitThread(bool blocking, const base::Closure& task) {
+ PluginGlobals::Get()->plugin_proxy_delegate()->PostToWebKitThread(
+ FROM_HERE, task);
+ if (blocking)
+ webkit_event_.Wait();
+}
+
+// static
+void Font::DeleteFontForwarding(WebKitForwarding::Font* font_forwarding) {
+ delete font_forwarding;
+}
+
} // namespace proxy
} // namespace ppapi
diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h
index 2849f3d..58fdc22 100644
--- a/ppapi/proxy/ppb_font_proxy.h
+++ b/ppapi/proxy/ppb_font_proxy.h
@@ -6,10 +6,12 @@
#define PPAPI_PROXY_PPB_FONT_PROXY_H_
#include "base/callback_forward.h"
+#include "base/synchronization/waitable_event.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/shared_impl/function_group_base.h"
#include "ppapi/shared_impl/host_resource.h"
#include "ppapi/shared_impl/resource.h"
+#include "ppapi/shared_impl/webkit_forwarding.h"
#include "ppapi/thunk/ppb_font_api.h"
namespace ppapi {
@@ -36,6 +38,54 @@ class PPB_Font_Proxy : public InterfaceProxy,
DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy);
};
+class Font : public ppapi::Resource,
+ public ppapi::thunk::PPB_Font_API {
+ public:
+ // Note that there isn't a "real" resource in the renderer backing a font,
+ // it lives entirely in the plugin process. So the resource ID in the host
+ // resource should be 0. However, various code assumes the instance in the
+ // host resource is valid (this is how resources are associated with
+ // instances), so that should be set.
+ Font(const ppapi::HostResource& resource, const PP_FontDescription_Dev& desc);
+ virtual ~Font();
+
+ // Resource.
+ virtual ppapi::thunk::PPB_Font_API* AsPPB_Font_API() OVERRIDE;
+
+ // PPB_Font_API implementation.
+ virtual PP_Bool Describe(PP_FontDescription_Dev* description,
+ PP_FontMetrics_Dev* metrics) OVERRIDE;
+ virtual PP_Bool DrawTextAt(PP_Resource image_data,
+ const PP_TextRun_Dev* text,
+ const PP_Point* position,
+ uint32_t color,
+ const PP_Rect* clip,
+ PP_Bool image_data_is_opaque) OVERRIDE;
+ virtual int32_t MeasureText(const PP_TextRun_Dev* text) OVERRIDE;
+ virtual uint32_t CharacterOffsetForPixel(const PP_TextRun_Dev* text,
+ int32_t pixel_position) OVERRIDE;
+ virtual int32_t PixelOffsetForCharacter(const PP_TextRun_Dev* text,
+ uint32_t char_offset) OVERRIDE;
+
+ private:
+ // Posts the given closure to the WebKit thread.
+ // If |blocking| is true, the method waits on |webkit_event_| for the task to
+ // continue.
+ void RunOnWebKitThread(bool blocking, const base::Closure& task);
+
+ static void DeleteFontForwarding(
+ ppapi::WebKitForwarding::Font* font_forwarding);
+
+ base::WaitableEvent webkit_event_;
+
+ // This class owns |font_forwarding_|.
+ // |font_forwarding_| should always be used on the WebKit thread (including
+ // destruction).
+ ppapi::WebKitForwarding::Font* font_forwarding_;
+
+ DISALLOW_COPY_AND_ASSIGN(Font);
+};
+
} // namespace proxy
} // namespace ppapi
diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc
index c02e136..20f8f62 100644
--- a/ppapi/proxy/ppb_image_data_proxy.cc
+++ b/ppapi/proxy/ppb_image_data_proxy.cc
@@ -77,10 +77,6 @@ int32_t ImageData::GetSharedMemory(int* /* handle */,
return PP_ERROR_NOACCESS;
}
-skia::PlatformCanvas* ImageData::GetPlatformCanvas() {
- return mapped_canvas_.get();
-}
-
#if defined(OS_WIN)
const ImageHandle ImageData::NullHandle = NULL;
#elif defined(OS_MACOSX)
diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h
index 00fec80..7890641 100644
--- a/ppapi/proxy/ppb_image_data_proxy.h
+++ b/ppapi/proxy/ppb_image_data_proxy.h
@@ -51,7 +51,8 @@ class ImageData : public ppapi::Resource,
virtual void* Map() OVERRIDE;
virtual void Unmap() OVERRIDE;
virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE;
- virtual skia::PlatformCanvas* GetPlatformCanvas() OVERRIDE;
+
+ skia::PlatformCanvas* mapped_canvas() const { return mapped_canvas_.get(); }
const PP_ImageDataDesc& desc() const { return desc_; }
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index 6c99ac1..02f2723 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -33,10 +33,10 @@
#include "ppapi/shared_impl/function_group_base.h"
#include "ppapi/shared_impl/host_resource.h"
#include "ppapi/shared_impl/ppb_audio_config_shared.h"
+#include "ppapi/shared_impl/ppb_font_shared.h"
#include "ppapi/shared_impl/ppb_input_event_shared.h"
#include "ppapi/shared_impl/ppb_resource_array_shared.h"
#include "ppapi/shared_impl/ppb_url_request_info_shared.h"
-#include "ppapi/shared_impl/private/ppb_font_shared.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_image_data_api.h"
@@ -152,12 +152,10 @@ PP_Resource ResourceCreationProxy::CreateFlashNetConnector(
PP_Resource ResourceCreationProxy::CreateFontObject(
PP_Instance instance,
const PP_FontDescription_Dev* description) {
- PluginDispatcher* dispatcher =
- PluginDispatcher::GetForInstance(instance);
- if (!dispatcher)
+ if (!PPB_Font_Shared::IsPPFontDescriptionValid(*description))
return 0;
- return PPB_Font_Shared::CreateAsProxy(instance, *description,
- dispatcher->preferences());
+ return (new Font(HostResource::MakeInstanceOnly(instance), *description))->
+ GetReference();
}
PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance,
diff --git a/ppapi/shared_impl/ppb_font_shared.cc b/ppapi/shared_impl/ppb_font_shared.cc
new file mode 100644
index 0000000..a714643
--- /dev/null
+++ b/ppapi/shared_impl/ppb_font_shared.cc
@@ -0,0 +1,35 @@
+// 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 "ppapi/shared_impl/ppb_font_shared.h"
+
+#include "ppapi/c/dev/ppb_font_dev.h"
+
+namespace ppapi {
+
+// static
+bool PPB_Font_Shared::IsPPFontDescriptionValid(
+ const PP_FontDescription_Dev& desc) {
+ // Check validity of string. We can't check the actual text since we could
+ // be on the wrong thread and don't know if we're in the plugin or the host.
+ if (desc.face.type != PP_VARTYPE_STRING &&
+ desc.face.type != PP_VARTYPE_UNDEFINED)
+ return false;
+
+ // Check enum ranges.
+ if (static_cast<int>(desc.family) < PP_FONTFAMILY_DEFAULT ||
+ static_cast<int>(desc.family) > PP_FONTFAMILY_MONOSPACE)
+ return false;
+ if (static_cast<int>(desc.weight) < PP_FONTWEIGHT_100 ||
+ static_cast<int>(desc.weight) > PP_FONTWEIGHT_900)
+ return false;
+
+ // Check for excessive sizes which may cause layout to get confused.
+ if (desc.size > 200)
+ return false;
+
+ return true;
+}
+
+} // namespace ppapi
diff --git a/ppapi/shared_impl/ppb_font_shared.h b/ppapi/shared_impl/ppb_font_shared.h
new file mode 100644
index 0000000..af0f681
--- /dev/null
+++ b/ppapi/shared_impl/ppb_font_shared.h
@@ -0,0 +1,32 @@
+// 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.
+
+#ifndef PPAPI_SHARED_IMPL_PPB_FONT_SHARED_H_
+#define PPAPI_SHARED_IMPL_PPB_FONT_SHARED_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_stdint.h"
+#include "ppapi/shared_impl/ppapi_shared_export.h"
+
+struct PP_FontDescription_Dev;
+
+namespace ppapi {
+
+class PPAPI_SHARED_EXPORT PPB_Font_Shared {
+ public:
+ // Validates the parameters in thee description. Can be called on any thread.
+ static bool IsPPFontDescriptionValid(const PP_FontDescription_Dev& desc);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PPB_Font_Shared);
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_PPB_FONT_SHARED_H_
diff --git a/ppapi/shared_impl/private/ppb_font_shared.cc b/ppapi/shared_impl/private/ppb_font_shared.cc
deleted file mode 100644
index 3af5288..0000000
--- a/ppapi/shared_impl/private/ppb_font_shared.cc
+++ /dev/null
@@ -1,419 +0,0 @@
-// 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 "ppapi/shared_impl/private/ppb_font_shared.h"
-
-#include "base/debug/trace_event.h"
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#include "ppapi/c/dev/ppb_font_dev.h"
-#include "ppapi/shared_impl/ppapi_preferences.h"
-#include "ppapi/shared_impl/var.h"
-#include "ppapi/thunk/enter.h"
-#include "ppapi/thunk/ppb_image_data_api.h"
-#include "ppapi/thunk/thunk.h"
-#include "skia/ext/platform_canvas.h"
-#include "third_party/skia/include/core/SkRect.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebFont.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebFontDescription.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextRun.h"
-
-using ppapi::StringVar;
-using ppapi::thunk::EnterResource;
-using ppapi::thunk::EnterResourceNoLock;
-using ppapi::thunk::PPB_ImageData_API;
-using ppapi::WebKitForwarding;
-using WebKit::WebFloatPoint;
-using WebKit::WebFloatRect;
-using WebKit::WebFont;
-using WebKit::WebFontDescription;
-using WebKit::WebRect;
-using WebKit::WebTextRun;
-using WebKit::WebCanvas;
-
-namespace ppapi {
-
-namespace {
-
-// Converts the given PP_TextRun to a TextRun, returning true on success.
-// False means the input was invalid.
-bool PPTextRunToTextRun(const PP_TextRun_Dev* run,
- WebKitForwarding::Font::TextRun* output) {
- StringVar* text_string = StringVar::FromPPVar(run->text);
- if (!text_string)
- return false;
-
- output->text = text_string->value();
- output->rtl = run->rtl == PP_TRUE ? true : false;
- output->override_direction =
- run->override_direction == PP_TRUE ? true : false;
- return true;
-}
-
-// The PP_* version lacks "None", so is just one value shifted from the
-// WebFontDescription version. These values are checked in
-// PPFontDescToWebFontDesc to make sure the conversion is correct. This is a
-// macro so it can also be used in the COMPILE_ASSERTS.
-#define PP_FONTFAMILY_TO_WEB_FONTFAMILY(f) \
- static_cast<WebFontDescription::GenericFamily>(f + 1)
-
-// Assumes the given PP_FontDescription has been validated.
-WebFontDescription PPFontDescToWebFontDesc(const PP_FontDescription_Dev& font,
- const std::string& face,
- const ::ppapi::Preferences& prefs) {
- // Verify that the enums match so we can just static cast.
- COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight100) ==
- static_cast<int>(PP_FONTWEIGHT_100),
- FontWeight100);
- COMPILE_ASSERT(static_cast<int>(WebFontDescription::Weight900) ==
- static_cast<int>(PP_FONTWEIGHT_900),
- FontWeight900);
- COMPILE_ASSERT(WebFontDescription::GenericFamilyStandard ==
- PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_DEFAULT),
- StandardFamily);
- COMPILE_ASSERT(WebFontDescription::GenericFamilySerif ==
- PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_SERIF),
- SerifFamily);
- COMPILE_ASSERT(WebFontDescription::GenericFamilySansSerif ==
- PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_SANSSERIF),
- SansSerifFamily);
- COMPILE_ASSERT(WebFontDescription::GenericFamilyMonospace ==
- PP_FONTFAMILY_TO_WEB_FONTFAMILY(PP_FONTFAMILY_MONOSPACE),
- MonospaceFamily);
-
- WebFontDescription result;
- string16 resolved_family;
- if (face.empty()) {
- // Resolve the generic family.
- switch (font.family) {
- case PP_FONTFAMILY_SERIF:
- resolved_family = prefs.serif_font_family;
- break;
- case PP_FONTFAMILY_SANSSERIF:
- resolved_family = prefs.sans_serif_font_family;
- break;
- case PP_FONTFAMILY_MONOSPACE:
- resolved_family = prefs.fixed_font_family;
- break;
- case PP_FONTFAMILY_DEFAULT:
- default:
- resolved_family = prefs.standard_font_family;
- break;
- }
- } else {
- // Use the exact font.
- resolved_family = UTF8ToUTF16(face);
- }
- result.family = resolved_family;
-
- result.genericFamily = PP_FONTFAMILY_TO_WEB_FONTFAMILY(font.family);
-
- if (font.size == 0) {
- // Resolve the default font size, using the resolved family to see if
- // we should use the fixed or regular font size. It's difficult at this
- // level to detect if the requested font is fixed width, so we only apply
- // the alternate font size to the default fixed font family.
- if (StringToLowerASCII(resolved_family) ==
- StringToLowerASCII(prefs.fixed_font_family))
- result.size = static_cast<float>(prefs.default_fixed_font_size);
- else
- result.size = static_cast<float>(prefs.default_font_size);
- } else {
- // Use the exact size.
- result.size = static_cast<float>(font.size);
- }
-
- result.italic = font.italic != PP_FALSE;
- result.smallCaps = font.small_caps != PP_FALSE;
- result.weight = static_cast<WebFontDescription::Weight>(font.weight);
- result.letterSpacing = static_cast<short>(font.letter_spacing);
- result.wordSpacing = static_cast<short>(font.word_spacing);
- return result;
-}
-
-WebTextRun TextRunToWebTextRun(const WebKitForwarding::Font::TextRun& run) {
- return WebTextRun(UTF8ToUTF16(run.text),
- run.rtl != PP_FALSE,
- run.override_direction != PP_FALSE);
-}
-
-// FontImpl --------------------------------------------------------------------
-
-class FontImpl : public WebKitForwarding::Font {
- public:
- FontImpl(const PP_FontDescription_Dev& desc,
- const std::string& desc_face,
- const ::ppapi::Preferences& prefs);
- virtual ~FontImpl();
-
- virtual void Describe(PP_FontDescription_Dev* description,
- std::string* face,
- PP_FontMetrics_Dev* metrics,
- PP_Bool* result) OVERRIDE;
- virtual void DrawTextAt(const DrawTextParams& params) OVERRIDE;
- virtual void MeasureText(const TextRun& text,
- int32_t* result) OVERRIDE;
- virtual void CharacterOffsetForPixel(const TextRun& text,
- int32_t pixel_position,
- uint32_t* result) OVERRIDE;
- virtual void PixelOffsetForCharacter(const TextRun& text,
- uint32_t char_offset,
- int32_t* result) OVERRIDE;
-
- private:
- scoped_ptr<WebFont> font_;
-
- DISALLOW_COPY_AND_ASSIGN(FontImpl);
-};
-
-FontImpl::FontImpl(const PP_FontDescription_Dev& desc,
- const std::string& desc_face,
- const ::ppapi::Preferences& prefs) {
- WebFontDescription web_font_desc = PPFontDescToWebFontDesc(desc, desc_face,
- prefs);
- font_.reset(WebFont::create(web_font_desc));
-}
-
-FontImpl::~FontImpl() {
-}
-
-void FontImpl::Describe(PP_FontDescription_Dev* description,
- std::string* face,
- PP_FontMetrics_Dev* metrics,
- PP_Bool* result) {
- TRACE_EVENT0("ppapi WebKit thread", "FontImpl::Describe");
- if (description->face.type != PP_VARTYPE_UNDEFINED) {
- *result = PP_FALSE;
- } else {
- WebFontDescription web_desc = font_->fontDescription();
-
- // While converting the other way in PPFontDescToWebFontDesc we validated
- // that the enums can be casted.
- description->face = PP_MakeUndefined();
- description->family =
- static_cast<PP_FontFamily_Dev>(web_desc.genericFamily);
- description->size = static_cast<uint32_t>(web_desc.size);
- description->weight = static_cast<PP_FontWeight_Dev>(web_desc.weight);
- description->italic = web_desc.italic ? PP_TRUE : PP_FALSE;
- description->small_caps = web_desc.smallCaps ? PP_TRUE : PP_FALSE;
- description->letter_spacing = static_cast<int32_t>(web_desc.letterSpacing);
- description->word_spacing = static_cast<int32_t>(web_desc.wordSpacing);
-
- *face = UTF16ToUTF8(web_desc.family);
-
- metrics->height = font_->height();
- metrics->ascent = font_->ascent();
- metrics->descent = font_->descent();
- metrics->line_spacing = font_->lineSpacing();
- metrics->x_height = static_cast<int32_t>(font_->xHeight());
-
- *result = PP_TRUE;
- }
-}
-
-void FontImpl::DrawTextAt(const DrawTextParams& params) {
- TRACE_EVENT0("ppapi WebKit thread", "FontImpl::DrawTextAt");
- WebTextRun run = TextRunToWebTextRun(params.text);
-
- // Convert position and clip.
- WebFloatPoint web_position(static_cast<float>(params.position->x),
- static_cast<float>(params.position->y));
- WebRect web_clip;
- if (!params.clip) {
- // Use entire canvas. SkCanvas doesn't have a size on it, so we just use
- // the current clip bounds.
- SkRect skclip;
- params.destination->getClipBounds(&skclip);
- web_clip = WebRect(skclip.fLeft, skclip.fTop, skclip.fRight - skclip.fLeft,
- skclip.fBottom - skclip.fTop);
- } else {
- web_clip = WebRect(params.clip->point.x, params.clip->point.y,
- params.clip->size.width, params.clip->size.height);
- }
-
-#if WEBKIT_USING_SKIA
- WebCanvas* canvas = params.destination;
-#elif WEBKIT_USING_CG
- WebCanvas* canvas = skia::GetBitmapContext(skia::GetTopDevice(*destination));
-#else
- NOTIMPLEMENTED();
- return;
-#endif
- font_->drawText(canvas, run, web_position, params.color, web_clip,
- params.image_data_is_opaque == PP_TRUE);
-}
-
-void FontImpl::MeasureText(const TextRun& text, int32_t* result) {
- TRACE_EVENT0("ppapi WebKit thread", "FontImpl::MeasureText");
- *result = font_->calculateWidth(TextRunToWebTextRun(text));
-}
-
-void FontImpl::CharacterOffsetForPixel(const TextRun& text,
- int32_t pixel_position,
- uint32_t* result) {
- TRACE_EVENT0("ppapi WebKit thread", "FontImpl::CharacterOffsetForPixel");
- *result = static_cast<uint32_t>(font_->offsetForPosition(
- TextRunToWebTextRun(text), static_cast<float>(pixel_position)));
-}
-
-void FontImpl::PixelOffsetForCharacter(const TextRun& text,
- uint32_t char_offset,
- int32_t* result) {
- TRACE_EVENT0("ppapi WebKit thread", "FontImpl::PixelOffsetForCharacter");
- WebTextRun run = TextRunToWebTextRun(text);
- if (char_offset >= run.text.length()) {
- *result = -1;
- } else {
- WebFloatRect rect = font_->selectionRectForText(
- run, WebFloatPoint(0.0f, 0.0f), font_->height(), 0, char_offset);
- *result = static_cast<int>(rect.width);
- }
-}
-
-} // namespace
-
-// static
-bool PPB_Font_Shared::IsPPFontDescriptionValid(
- const PP_FontDescription_Dev& desc) {
- // Check validity of string. We can't check the actual text since we could
- // be on the wrong thread and don't know if we're in the plugin or the host.
- if (desc.face.type != PP_VARTYPE_STRING &&
- desc.face.type != PP_VARTYPE_UNDEFINED)
- return false;
-
- // Check enum ranges.
- if (static_cast<int>(desc.family) < PP_FONTFAMILY_DEFAULT ||
- static_cast<int>(desc.family) > PP_FONTFAMILY_MONOSPACE)
- return false;
- if (static_cast<int>(desc.weight) < PP_FONTWEIGHT_100 ||
- static_cast<int>(desc.weight) > PP_FONTWEIGHT_900)
- return false;
-
- // Check for excessive sizes which may cause layout to get confused.
- if (desc.size > 200)
- return false;
-
- return true;
-}
-
-// static
-PP_Resource PPB_Font_Shared::CreateAsImpl(
- PP_Instance instance,
- const PP_FontDescription_Dev& description,
- const ::ppapi::Preferences& prefs) {
- if (!::ppapi::PPB_Font_Shared::IsPPFontDescriptionValid(description))
- return 0;
- return (new PPB_Font_Shared(instance, description, prefs))->GetReference();
-}
-
-// static
-PP_Resource PPB_Font_Shared::CreateAsProxy(
- PP_Instance instance,
- const PP_FontDescription_Dev& description,
- const ::ppapi::Preferences& prefs) {
- return CreateAsImpl(instance, description, prefs);
-}
-
-PPB_Font_Shared::PPB_Font_Shared(PP_Instance pp_instance,
- const PP_FontDescription_Dev& desc,
- const ::ppapi::Preferences& prefs)
- : Resource(pp_instance) {
- StringVar* face_name = StringVar::FromPPVar(desc.face);
-
- font_impl_.reset(new FontImpl(
- desc, face_name ? face_name->value() : std::string(), prefs));
-}
-
-PPB_Font_Shared::~PPB_Font_Shared() {
-}
-
-::ppapi::thunk::PPB_Font_API* PPB_Font_Shared::AsPPB_Font_API() {
- return this;
-}
-
-PP_Bool PPB_Font_Shared::Describe(PP_FontDescription_Dev* description,
- PP_FontMetrics_Dev* metrics) {
- std::string face;
- PP_Bool result = PP_FALSE;
- font_impl_->Describe(description, &face, metrics, &result);
- if (!result)
- return PP_FALSE;
-
- // Convert the string.
- description->face = StringVar::StringToPPVar(face);
- return PP_TRUE;
-}
-
-PP_Bool PPB_Font_Shared::DrawTextAt(PP_Resource image_data,
- const PP_TextRun_Dev* text,
- const PP_Point* position,
- uint32_t color,
- const PP_Rect* clip,
- PP_Bool image_data_is_opaque) {
- PP_Bool result = PP_FALSE;
- // Get and map the image data we're painting to.
- EnterResource<PPB_ImageData_API> enter(image_data, true);
- if (enter.failed())
- return result;
-
- // TODO(ananta)
- // We need to remove dependency on skia from this layer.
- PPB_ImageData_API* image = static_cast<PPB_ImageData_API*>(
- enter.object());
- skia::PlatformCanvas* canvas = image->GetPlatformCanvas();
- bool needs_unmapping = false;
- if (!canvas) {
- needs_unmapping = true;
- image->Map();
- canvas = image->GetPlatformCanvas();
- if (!canvas)
- return result; // Failure mapping.
- }
-
- WebKitForwarding::Font::TextRun run;
- if (PPTextRunToTextRun(text, &run)) {
- font_impl_->DrawTextAt(WebKitForwarding::Font::DrawTextParams(
- canvas, run, position, color, clip, image_data_is_opaque));
- result = PP_TRUE;
- }
-
- if (needs_unmapping)
- image->Unmap();
- return result;
-}
-
-int32_t PPB_Font_Shared::MeasureText(const PP_TextRun_Dev* text) {
- int32_t result = -1;
- WebKitForwarding::Font::TextRun run;
- if (PPTextRunToTextRun(text, &run))
- font_impl_->MeasureText(run, &result);
- return result;
-}
-
-uint32_t PPB_Font_Shared::CharacterOffsetForPixel(const PP_TextRun_Dev* text,
- int32_t pixel_position) {
- uint32_t result = -1;
- WebKitForwarding::Font::TextRun run;
- if (PPTextRunToTextRun(text, &run)) {
- font_impl_->CharacterOffsetForPixel(run, pixel_position, &result);
- }
- return result;
-}
-
-int32_t PPB_Font_Shared::PixelOffsetForCharacter(const PP_TextRun_Dev* text,
- uint32_t char_offset) {
- int32_t result = -1;
- WebKitForwarding::Font::TextRun run;
- if (PPTextRunToTextRun(text, &run)) {
- font_impl_->PixelOffsetForCharacter(run, char_offset, &result);
- }
- return result;
-}
-
-} // namespace ppapi
-
diff --git a/ppapi/shared_impl/private/ppb_font_shared.h b/ppapi/shared_impl/private/ppb_font_shared.h
deleted file mode 100644
index 3b852bf..0000000
--- a/ppapi/shared_impl/private/ppb_font_shared.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// 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.
-
-#ifndef PPAPI_SHARED_IMPL_PRIVATE_PPB_FONT_SHARED_H_
-#define PPAPI_SHARED_IMPL_PRIVATE_PPB_FONT_SHARED_H_
-#pragma once
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "ppapi/c/pp_bool.h"
-#include "ppapi/c/pp_instance.h"
-#include "ppapi/c/pp_resource.h"
-#include "ppapi/c/pp_stdint.h"
-#include "ppapi/shared_impl/ppapi_preferences.h"
-#include "ppapi/shared_impl/ppapi_shared_export.h"
-#include "ppapi/shared_impl/resource.h"
-#include "ppapi/shared_impl/webkit_forwarding.h"
-#include "ppapi/thunk/ppb_font_api.h"
-
-struct PP_FontDescription_Dev;
-
-namespace ppapi {
-
-class PPAPI_SHARED_EXPORT PPB_Font_Shared
- : public ::ppapi::Resource,
- public ::ppapi::thunk::PPB_Font_API {
- public:
- // Validates the parameters in thee description. Can be called on any thread.
- static bool IsPPFontDescriptionValid(const PP_FontDescription_Dev& desc);
-
- virtual ~PPB_Font_Shared();
-
- static PP_Resource CreateAsImpl(PP_Instance instance,
- const PP_FontDescription_Dev& description,
- const ::ppapi::Preferences& prefs);
- static PP_Resource CreateAsProxy(PP_Instance instance,
- const PP_FontDescription_Dev& description,
- const ::ppapi::Preferences& prefs);
-
- // Resource.
- virtual ::ppapi::thunk::PPB_Font_API* AsPPB_Font_API() OVERRIDE;
-
- // PPB_Font implementation.
- virtual PP_Bool Describe(PP_FontDescription_Dev* description,
- PP_FontMetrics_Dev* metrics) OVERRIDE;
- virtual PP_Bool DrawTextAt(PP_Resource image_data,
- const PP_TextRun_Dev* text,
- const PP_Point* position,
- uint32_t color,
- const PP_Rect* clip,
- PP_Bool image_data_is_opaque) OVERRIDE;
- virtual int32_t MeasureText(const PP_TextRun_Dev* text) OVERRIDE;
- virtual uint32_t CharacterOffsetForPixel(const PP_TextRun_Dev* text,
- int32_t pixel_position) OVERRIDE;
- virtual int32_t PixelOffsetForCharacter(const PP_TextRun_Dev* text,
- uint32_t char_offset) OVERRIDE;
-
- private:
- PPB_Font_Shared(PP_Instance instance, const PP_FontDescription_Dev& desc,
- const ::ppapi::Preferences& prefs);
-
- scoped_ptr< ::ppapi::WebKitForwarding::Font> font_impl_;
-
- DISALLOW_COPY_AND_ASSIGN(PPB_Font_Shared);
-};
-
-} // namespace ppapi
-
-#endif // PPAPI_SHARED_IMPL_PRIVATE_PPB_FONT_SHARED_H_
diff --git a/ppapi/shared_impl/webkit_forwarding.h b/ppapi/shared_impl/webkit_forwarding.h
index 2bef621..d571aaa 100644
--- a/ppapi/shared_impl/webkit_forwarding.h
+++ b/ppapi/shared_impl/webkit_forwarding.h
@@ -16,6 +16,10 @@ struct PP_FontMetrics_Dev;
struct PP_Point;
struct PP_Rect;
+namespace base {
+class WaitableEvent;
+}
+
namespace skia {
class PlatformCanvas;
}
@@ -63,22 +67,37 @@ class PPAPI_SHARED_EXPORT WebKitForwarding {
// on creating vars. Instead, the face name is placed into the given
// string. See class description for waitable_event documentation. If
// non-null, the given event will be set on completion.
- virtual void Describe(PP_FontDescription_Dev* description,
+ virtual void Describe(base::WaitableEvent* event,
+ PP_FontDescription_Dev* description,
std::string* face,
PP_FontMetrics_Dev* metrics,
PP_Bool* result) = 0;
- virtual void DrawTextAt(const DrawTextParams& params) = 0;
- virtual void MeasureText(const TextRun& text,
+ virtual void DrawTextAt(base::WaitableEvent* event,
+ const DrawTextParams& params) = 0;
+ virtual void MeasureText(base::WaitableEvent* event,
+ const TextRun& text,
int32_t* result) = 0;
- virtual void CharacterOffsetForPixel(const TextRun& text,
+ virtual void CharacterOffsetForPixel(base::WaitableEvent* event,
+ const TextRun& text,
int32_t pixel_position,
uint32_t* result) = 0;
- virtual void PixelOffsetForCharacter(const TextRun& text,
+ virtual void PixelOffsetForCharacter(base::WaitableEvent* event,
+ const TextRun& text,
uint32_t char_offset,
int32_t* result) = 0;
};
virtual ~WebKitForwarding();
+
+ // Creates a new font with the given description. The desc_face is the face
+ // name already extracted from the description. The caller owns the result
+ // pointer, which will never be NULL. If non-null, the given event will be
+ // set on completion.
+ virtual void CreateFontForwarding(base::WaitableEvent* event,
+ const PP_FontDescription_Dev& desc,
+ const std::string& desc_face,
+ const Preferences& prefs,
+ Font** result) = 0;
};
} // namespace ppapi
diff --git a/ppapi/thunk/ppb_font_api.h b/ppapi/thunk/ppb_font_api.h
index e85bb1b..e3bac24 100644
--- a/ppapi/thunk/ppb_font_api.h
+++ b/ppapi/thunk/ppb_font_api.h
@@ -7,7 +7,6 @@
#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/shared_impl/api_id.h"
-#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
namespace thunk {
@@ -23,7 +22,7 @@ class PPB_Font_FunctionAPI {
};
// API for font resources.
-class PPAPI_THUNK_EXPORT PPB_Font_API {
+class PPB_Font_API {
public:
virtual ~PPB_Font_API() {}
diff --git a/ppapi/thunk/ppb_image_data_api.h b/ppapi/thunk/ppb_image_data_api.h
index b7a3e69..c22e899 100644
--- a/ppapi/thunk/ppb_image_data_api.h
+++ b/ppapi/thunk/ppb_image_data_api.h
@@ -8,10 +8,6 @@
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/ppb_image_data.h"
-namespace skia {
-class PlatformCanvas;
-}
-
namespace ppapi {
namespace thunk {
@@ -25,9 +21,6 @@ class PPB_ImageData_API {
// Trusted inteface.
virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) = 0;
-
- // The canvas will be NULL if the image is not mapped.
- virtual skia::PlatformCanvas* GetPlatformCanvas() = 0;
};
} // namespace thunk