summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-20 02:35:48 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-20 02:35:48 +0000
commitcd781859e94bc4cedb35371cf4d6d1e161e87a11 (patch)
tree568ca78f3ec265af5dae2b1f178fdc95604f0134
parentd38c1b0a6e3f4cfeb5a5700f00523c5364d49f27 (diff)
downloadchromium_src-cd781859e94bc4cedb35371cf4d6d1e161e87a11.zip
chromium_src-cd781859e94bc4cedb35371cf4d6d1e161e87a11.tar.gz
chromium_src-cd781859e94bc4cedb35371cf4d6d1e161e87a11.tar.bz2
Revert 118385 since this seems to break mac-debug build.
""" Remove the Webkit thread in the PPAPI plugin process and perform the text and font operations on the PPAPI main thread. This thread is now registered as the Webkit thread. Fixes performance issues seen in Flapper with text and font operations. It appears that the perf issues occur due to context switching between the main thread and the webkit thread. As per comments from Brett moving the font forwarding code inline to ppb_font_shared.cc. This file has been moved to ppapi/shared_impl/private as it now brings in a dependency on WebKit. The font creation has been wired up to the ResourceCreationAPI as suggested. BUG=110190 R=brettw Review URL: https://chromiumcodereview.appspot.com/9133015 TBR=ananta@chromium.org Review URL: https://chromiumcodereview.appspot.com/9150055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118399 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/chrome_ppb_pdf_impl.cc2
-rw-r--r--content/content_ppapi_plugin.gypi2
-rw-r--r--content/ppapi_plugin/ppapi_thread.cc20
-rw-r--r--content/ppapi_plugin/ppapi_thread.h13
-rw-r--r--content/ppapi_plugin/ppapi_webkit_thread.cc44
-rw-r--r--content/ppapi_plugin/ppapi_webkit_thread.h50
-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.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
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc7
-rw-r--r--webkit/plugins/ppapi/plugin_module.h6
-rw-r--r--webkit/plugins/ppapi/ppb_flash_impl.cc2
-rw-r--r--webkit/plugins/ppapi/ppb_font_impl.cc142
-rw-r--r--webkit/plugins/ppapi/ppb_font_impl.h43
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.cc6
-rw-r--r--webkit/plugins/ppapi/ppb_image_data_impl.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_image_data_impl.h3
-rw-r--r--webkit/plugins/ppapi/ppb_scrollbar_impl.cc2
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.cc10
-rw-r--r--webkit/plugins/ppapi/resource_helper.cc7
-rw-r--r--webkit/plugins/ppapi/resource_helper.h4
-rw-r--r--webkit/plugins/ppapi/webkit_forwarding_impl.cc (renamed from ppapi/shared_impl/private/ppb_font_shared.cc)241
-rw-r--r--webkit/plugins/ppapi/webkit_forwarding_impl.h30
37 files changed, 769 insertions, 330 deletions
diff --git a/chrome/renderer/chrome_ppb_pdf_impl.cc b/chrome/renderer/chrome_ppb_pdf_impl.cc
index 3f0c688..5a4592c 100644
--- a/chrome/renderer/chrome_ppb_pdf_impl.cc
+++ b/chrome/renderer/chrome_ppb_pdf_impl.cc
@@ -178,7 +178,7 @@ PP_Resource GetResourceImage(PP_Instance instance_id,
if (!mapper.is_valid())
return 0;
- skia::PlatformCanvas* canvas = image_data->GetPlatformCanvas();
+ skia::PlatformCanvas* canvas = image_data->mapped_canvas();
// Note: Do not skBitmap::copyTo the canvas bitmap directly because it will
// ignore the allocated pixels in shared memory and re-allocate a new buffer.
canvas->writePixels(*res_bitmap, 0, 0);
diff --git a/content/content_ppapi_plugin.gypi b/content/content_ppapi_plugin.gypi
index c5a2543..b428614 100644
--- a/content/content_ppapi_plugin.gypi
+++ b/content/content_ppapi_plugin.gypi
@@ -16,6 +16,8 @@
'ppapi_plugin/ppapi_plugin_main.cc',
'ppapi_plugin/ppapi_thread.cc',
'ppapi_plugin/ppapi_thread.h',
+ 'ppapi_plugin/ppapi_webkit_thread.cc',
+ 'ppapi_plugin/ppapi_webkit_thread.h',
'ppapi_plugin/ppapi_webkitplatformsupport_impl.cc',
'ppapi_plugin/ppapi_webkitplatformsupport_impl.h',
],
diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc
index 3277f1b..e989785 100644
--- a/content/ppapi_plugin/ppapi_thread.cc
+++ b/content/ppapi_plugin/ppapi_thread.cc
@@ -14,7 +14,7 @@
#include "content/common/child_process_messages.h"
#include "content/ppapi_plugin/broker_process_dispatcher.h"
#include "content/ppapi_plugin/plugin_process_dispatcher.h"
-#include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h"
+#include "content/ppapi_plugin/ppapi_webkit_thread.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/sandbox_init.h"
#include "ipc/ipc_channel_handle.h"
@@ -25,7 +25,7 @@
#include "ppapi/proxy/plugin_globals.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/interface_list.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
+#include "webkit/plugins/ppapi/webkit_forwarding_impl.h"
#if defined(OS_WIN)
#include "sandbox/src/sandbox.h"
@@ -50,8 +50,6 @@ PpapiThread::PpapiThread(bool is_broker)
base::RandInt(0, std::numeric_limits<PP_Module>::max())),
next_plugin_dispatcher_id_(1) {
ppapi::proxy::PluginGlobals::Get()->set_plugin_proxy_delegate(this);
- webkit_platform_support_.reset(new PpapiWebKitPlatformSupportImpl);
- WebKit::initialize(webkit_platform_support_.get());
}
PpapiThread::~PpapiThread() {
@@ -69,7 +67,6 @@ PpapiThread::~PpapiThread() {
library_.GetFunctionPointer("PPP_ShutdownModule"));
if (shutdown_function)
shutdown_function();
- WebKit::shutdown();
}
// The "regular" ChildThread implements this function and does some standard
@@ -114,6 +111,19 @@ std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() {
return &globally_seen_instance_ids_;
}
+ppapi::WebKitForwarding* PpapiThread::GetWebKitForwarding() {
+ if (!webkit_forwarding_.get())
+ webkit_forwarding_.reset(new webkit::ppapi::WebKitForwardingImpl);
+ return webkit_forwarding_.get();
+}
+
+void PpapiThread::PostToWebKitThread(const tracked_objects::Location& from_here,
+ const base::Closure& task) {
+ if (!webkit_thread_.get())
+ webkit_thread_.reset(new PpapiWebKitThread);
+ webkit_thread_->PostTask(from_here, task);
+}
+
bool PpapiThread::SendToBrowser(IPC::Message* msg) {
return Send(msg);
}
diff --git a/content/ppapi_plugin/ppapi_thread.h b/content/ppapi_plugin/ppapi_thread.h
index bff66db..56e12c5 100644
--- a/content/ppapi_plugin/ppapi_thread.h
+++ b/content/ppapi_plugin/ppapi_thread.h
@@ -22,7 +22,7 @@
#include "ppapi/proxy/plugin_proxy_delegate.h"
class FilePath;
-class PpapiWebKitPlatformSupportImpl;
+class PpapiWebKitThread;
namespace IPC {
struct ChannelHandle;
@@ -48,6 +48,9 @@ class PpapiThread : public ChildThread,
virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE;
// PluginProxyDelegate.
+ 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;
@@ -89,13 +92,15 @@ class PpapiThread : public ChildThread,
// See Dispatcher::Delegate::GetGloballySeenInstanceIDSet.
std::set<PP_Instance> globally_seen_instance_ids_;
+ // Lazily created by GetWebKitForwarding.
+ scoped_ptr<ppapi::WebKitForwarding> webkit_forwarding_;
+
+ scoped_ptr<PpapiWebKitThread> webkit_thread_;
+
// The PluginDispatcher instances contained in the map are not owned by it.
std::map<uint32, ppapi::proxy::PluginDispatcher*> plugin_dispatchers_;
uint32 next_plugin_dispatcher_id_;
- // The WebKitPlatformSupport implementation.
- scoped_ptr<PpapiWebKitPlatformSupportImpl> webkit_platform_support_;
-
DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread);
};
diff --git a/content/ppapi_plugin/ppapi_webkit_thread.cc b/content/ppapi_plugin/ppapi_webkit_thread.cc
new file mode 100644
index 0000000..cb3d482
--- /dev/null
+++ b/content/ppapi_plugin/ppapi_webkit_thread.cc
@@ -0,0 +1,44 @@
+// 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 "content/ppapi_plugin/ppapi_webkit_thread.h"
+
+#include "base/logging.h"
+#include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
+
+PpapiWebKitThread::PpapiWebKitThread() {
+ DCHECK(!webkit_thread_.get());
+
+ webkit_thread_.reset(new InternalWebKitThread);
+ bool started = webkit_thread_->Start();
+ DCHECK(started);
+}
+
+PpapiWebKitThread::~PpapiWebKitThread() {
+}
+
+void PpapiWebKitThread::PostTask(const tracked_objects::Location& from_here,
+ const base::Closure& task) {
+ webkit_thread_->message_loop()->PostTask(from_here, task);
+}
+
+PpapiWebKitThread::InternalWebKitThread::InternalWebKitThread()
+ : base::Thread("PPAPIWebKit") {
+}
+
+PpapiWebKitThread::InternalWebKitThread::~InternalWebKitThread() {
+ Stop();
+}
+
+void PpapiWebKitThread::InternalWebKitThread::Init() {
+ DCHECK(!webkit_platform_support_.get());
+ webkit_platform_support_.reset(new PpapiWebKitPlatformSupportImpl);
+ WebKit::initialize(webkit_platform_support_.get());
+}
+
+void PpapiWebKitThread::InternalWebKitThread::CleanUp() {
+ DCHECK(webkit_platform_support_.get());
+ WebKit::shutdown();
+}
diff --git a/content/ppapi_plugin/ppapi_webkit_thread.h b/content/ppapi_plugin/ppapi_webkit_thread.h
new file mode 100644
index 0000000..a7606f6
--- /dev/null
+++ b/content/ppapi_plugin/ppapi_webkit_thread.h
@@ -0,0 +1,50 @@
+// 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 CONTENT_PPAPI_PLUGIN_PPAPI_WEBKIT_THREAD_H_
+#define CONTENT_PPAPI_PLUGIN_PPAPI_WEBKIT_THREAD_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread.h"
+
+class PpapiWebKitPlatformSupportImpl;
+
+// This creates a WebKit main thread on instantiation on construction and kills
+// it on deletion. See also content/browser/in_process_webkit for the
+// corresponding concept in the browser process.
+class PpapiWebKitThread {
+ public:
+ PpapiWebKitThread();
+ ~PpapiWebKitThread();
+
+ // Posts the given task to the thread, see MessageLoop::PostTask.
+ void PostTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& task);
+
+ private:
+ // Must be private so that we can carefully control its lifetime.
+ class InternalWebKitThread : public base::Thread {
+ public:
+ InternalWebKitThread();
+ virtual ~InternalWebKitThread();
+ // Does the actual initialization and shutdown of WebKit. Called at the
+ // beginning and end of the thread's lifetime.
+ virtual void Init() OVERRIDE;
+ virtual void CleanUp() OVERRIDE;
+
+ private:
+ // The WebKitPlatformSupport implementation. Only access on WebKit thread.
+ scoped_ptr<PpapiWebKitPlatformSupportImpl> webkit_platform_support_;
+ };
+
+ // Pointer to the actual WebKitThread.
+ scoped_ptr<InternalWebKitThread> webkit_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(PpapiWebKitThread);
+};
+
+#endif // CONTENT_PPAPI_PLUGIN_PPAPI_WEBKIT_THREAD_H_
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.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
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 5894b9d..b0fa6ab 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -336,6 +336,8 @@
'../plugins/ppapi/resource_helper.h',
'../plugins/ppapi/string.cc',
'../plugins/ppapi/string.h',
+ '../plugins/ppapi/webkit_forwarding_impl.cc',
+ '../plugins/ppapi/webkit_forwarding_impl.h',
'../plugins/sad_plugin.cc',
'../plugins/sad_plugin.h',
'../plugins/webkit_plugins_export.h',
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 5ca81c8..c6af869 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -116,6 +116,7 @@
#include "webkit/plugins/ppapi/ppb_video_capture_impl.h"
#include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
#include "webkit/plugins/ppapi/ppb_video_layer_impl.h"
+#include "webkit/plugins/ppapi/webkit_forwarding_impl.h"
using ppapi::InputEventData;
using ppapi::PpapiGlobals;
@@ -590,6 +591,12 @@ PluginDelegate::PpapiBroker* PluginModule::GetBroker() {
return broker_;
}
+::ppapi::WebKitForwarding* PluginModule::GetWebKitForwarding() {
+ if (!webkit_forwarding_.get())
+ webkit_forwarding_.reset(new WebKitForwardingImpl);
+ return webkit_forwarding_.get();
+}
+
bool PluginModule::InitializeModule(const EntryPoints& entry_points) {
DCHECK(!out_of_process_proxy_.get()) << "Don't call for proxied modules.";
DCHECK(entry_points.initialize_module != NULL);
diff --git a/webkit/plugins/ppapi/plugin_module.h b/webkit/plugins/ppapi/plugin_module.h
index 928f8ac..7634268 100644
--- a/webkit/plugins/ppapi/plugin_module.h
+++ b/webkit/plugins/ppapi/plugin_module.h
@@ -141,6 +141,9 @@ class WEBKIT_PLUGINS_EXPORT PluginModule :
void SetBroker(PluginDelegate::PpapiBroker* broker);
PluginDelegate::PpapiBroker* GetBroker();
+ // Retrieves the forwarding interface used for talking to WebKit.
+ ::ppapi::WebKitForwarding* GetWebKitForwarding();
+
private:
// Calls the InitializeModule entrypoint. The entrypoint must have been
// set and the plugin must not be out of process (we don't maintain
@@ -193,6 +196,9 @@ class WEBKIT_PLUGINS_EXPORT PluginModule :
PP_Bool (*reserve_instance_id_)(PP_Module, PP_Instance);
+ // Lazily created by GetWebKitForwarding.
+ scoped_ptr< ::ppapi::WebKitForwarding> webkit_forwarding_;
+
DISALLOW_COPY_AND_ASSIGN(PluginModule);
};
diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc
index c1133ba..c65fbcc 100644
--- a/webkit/plugins/ppapi/ppb_flash_impl.cc
+++ b/webkit/plugins/ppapi/ppb_flash_impl.cc
@@ -89,7 +89,7 @@ PP_Bool DrawGlyphs(PP_Instance,
SkAutoUnref aur(typeface);
// Set up the canvas.
- SkCanvas* canvas = image_resource->GetPlatformCanvas();
+ SkCanvas* canvas = image_resource->mapped_canvas();
SkAutoCanvasRestore acr(canvas, true);
// Clip is applied in pixels before the transform.
diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc
index c18106a..0c439d0 100644
--- a/webkit/plugins/ppapi/ppb_font_impl.cc
+++ b/webkit/plugins/ppapi/ppb_font_impl.cc
@@ -4,12 +4,148 @@
#include "webkit/plugins/ppapi/ppb_font_impl.h"
+#include "ppapi/c/dev/ppb_font_dev.h"
+#include "ppapi/shared_impl/ppapi_preferences.h"
+#include "ppapi/shared_impl/ppb_font_shared.h"
+#include "ppapi/shared_impl/var.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/thunk.h"
+#include "webkit/plugins/ppapi/common.h"
+#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
+#include "webkit/plugins/ppapi/resource_helper.h"
+#include "webkit/plugins/ppapi/string.h"
-namespace webkit {
+using ppapi::StringVar;
+using ppapi::thunk::EnterResource;
+using ppapi::thunk::PPB_ImageData_API;
+using ppapi::WebKitForwarding;
+namespace webkit {
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 = PPBoolToBool(run->rtl);
+ output->override_direction = PPBoolToBool(run->override_direction);
+ return true;
+}
+
+} // namespace
+
+PPB_Font_Impl::PPB_Font_Impl(PP_Instance pp_instance,
+ const PP_FontDescription_Dev& desc)
+ : Resource(pp_instance) {
+ StringVar* face_name = StringVar::FromPPVar(desc.face);
+
+ WebKitForwarding::Font* result = NULL;
+ PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
+ if (plugin_instance) {
+ plugin_instance->module()->GetWebKitForwarding()->CreateFontForwarding(
+ NULL, desc, face_name ? face_name->value() : std::string(),
+ plugin_instance->delegate()->GetPreferences(), &result);
+ }
+ font_forwarding_.reset(result);
+}
+
+PPB_Font_Impl::~PPB_Font_Impl() {
+}
+
+// static
+PP_Resource PPB_Font_Impl::Create(PP_Instance instance,
+ const PP_FontDescription_Dev& description) {
+ if (!::ppapi::PPB_Font_Shared::IsPPFontDescriptionValid(description))
+ return 0;
+ return (new PPB_Font_Impl(instance, description))->GetReference();
+}
+
+::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsPPB_Font_API() {
+ return this;
+}
+
+PP_Bool PPB_Font_Impl::Describe(PP_FontDescription_Dev* description,
+ PP_FontMetrics_Dev* metrics) {
+ std::string face;
+ PP_Bool result = PP_FALSE;
+ font_forwarding_->Describe(NULL, description, &face, metrics, &result);
+ if (!result)
+ return PP_FALSE;
+
+ PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
+ if (!plugin_module)
+ return PP_FALSE;
+
+ // Convert the string.
+ description->face = StringVar::StringToPPVar(face);
+ return PP_TRUE;
+}
+
+PP_Bool PPB_Font_Impl::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) {
+ // Get and map the image data we're painting to.
+ EnterResource<PPB_ImageData_API> enter(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;
+
+ WebKitForwarding::Font::TextRun run;
+ if (!PPTextRunToTextRun(text, &run))
+ return PP_FALSE;
+
+ font_forwarding_->DrawTextAt(NULL, WebKitForwarding::Font::DrawTextParams(
+ image_resource->mapped_canvas(), run, position,
+ color, clip, image_data_is_opaque));
+ return PP_TRUE;
+}
+
+int32_t PPB_Font_Impl::MeasureText(const PP_TextRun_Dev* text) {
+ int32_t result = -1;
+ WebKitForwarding::Font::TextRun run;
+ if (PPTextRunToTextRun(text, &run))
+ font_forwarding_->MeasureText(NULL, run, &result);
+ return result;
+}
+
+uint32_t PPB_Font_Impl::CharacterOffsetForPixel(const PP_TextRun_Dev* text,
+ int32_t pixel_position) {
+ uint32_t result = -1;
+ WebKitForwarding::Font::TextRun run;
+ if (PPTextRunToTextRun(text, &run)) {
+ font_forwarding_->CharacterOffsetForPixel(NULL, run, pixel_position,
+ &result);
+ }
+ return result;
+}
+
+int32_t PPB_Font_Impl::PixelOffsetForCharacter(const PP_TextRun_Dev* text,
+ uint32_t char_offset) {
+ int32_t result = -1;
+ WebKitForwarding::Font::TextRun run;
+ if (PPTextRunToTextRun(text, &run)) {
+ font_forwarding_->PixelOffsetForCharacter(NULL, run, char_offset, &result);
+ }
+ return result;
+}
+
PPB_Font_FunctionImpl::PPB_Font_FunctionImpl(PluginInstance* instance)
: instance_(instance) {
}
@@ -22,12 +158,10 @@ PPB_Font_FunctionImpl::AsFont_FunctionAPI() {
return this;
}
-// TODO(ananta)
-// We need to wire this up to the proxy.
PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) {
return PP_MakeUndefined();
}
} // namespace ppapi
-
} // namespace webkit
+
diff --git a/webkit/plugins/ppapi/ppb_font_impl.h b/webkit/plugins/ppapi/ppb_font_impl.h
index c21b18e..4b9c7e0 100644
--- a/webkit/plugins/ppapi/ppb_font_impl.h
+++ b/webkit/plugins/ppapi/ppb_font_impl.h
@@ -6,9 +6,11 @@
#define WEBKIT_PLUGINS_PPAPI_PPB_FONT_IMPL_H_
#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "ppapi/c/pp_instance.h"
+#include "base/memory/scoped_ptr.h"
+#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/shared_impl/function_group_base.h"
+#include "ppapi/shared_impl/resource.h"
+#include "ppapi/shared_impl/webkit_forwarding.h"
#include "ppapi/thunk/ppb_font_api.h"
namespace webkit {
@@ -16,6 +18,40 @@ namespace ppapi {
class PluginInstance;
+class PPB_Font_Impl : public ::ppapi::Resource,
+ public ::ppapi::thunk::PPB_Font_API {
+ public:
+ virtual ~PPB_Font_Impl();
+
+ static PP_Resource Create(PP_Instance instance,
+ const PP_FontDescription_Dev& description);
+
+ // 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_Impl(PP_Instance instance, const PP_FontDescription_Dev& desc);
+
+ scoped_ptr< ::ppapi::WebKitForwarding::Font> font_forwarding_;
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_Font_Impl);
+};
+
class PPB_Font_FunctionImpl : public ::ppapi::FunctionGroupBase,
public ::ppapi::thunk::PPB_Font_FunctionAPI {
public:
@@ -35,7 +71,6 @@ class PPB_Font_FunctionImpl : public ::ppapi::FunctionGroupBase,
};
} // namespace ppapi
-
-} // namespace webkit.
+} // namespace webkit
#endif // WEBKIT_PLUGINS_PPAPI_PPB_FONT_IMPL_H_
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
index ddfea5f..027e8eb 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
@@ -398,7 +398,7 @@ bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image,
// Convert the image data if the format does not match.
ConvertImageData(image_data_, src_irect, image_resource, dest_rect);
} else {
- skia::PlatformCanvas* dest_canvas = image_resource->GetPlatformCanvas();
+ skia::PlatformCanvas* dest_canvas = image_resource->mapped_canvas();
// We want to replace the contents of the bitmap rather than blend.
SkPaint paint;
@@ -583,7 +583,7 @@ void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image,
ConvertImageData(image, src_irect, image_data_, dest_rect);
} else {
// We're guaranteed to have a mapped canvas since we mapped it in Init().
- skia::PlatformCanvas* backing_canvas = image_data_->GetPlatformCanvas();
+ skia::PlatformCanvas* backing_canvas = image_data_->mapped_canvas();
// We want to replace the contents of the bitmap rather than blend.
SkPaint paint;
@@ -596,7 +596,7 @@ void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image,
void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip,
int dx, int dy,
gfx::Rect* invalidated_rect) {
- gfx::ScrollCanvas(image_data_->GetPlatformCanvas(),
+ gfx::ScrollCanvas(image_data_->mapped_canvas(),
clip, gfx::Point(dx, dy));
*invalidated_rect = clip;
}
diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.cc b/webkit/plugins/ppapi/ppb_image_data_impl.cc
index fa30601..6563713 100644
--- a/webkit/plugins/ppapi/ppb_image_data_impl.cc
+++ b/webkit/plugins/ppapi/ppb_image_data_impl.cc
@@ -111,10 +111,6 @@ int32_t PPB_ImageData_Impl::GetSharedMemory(int* handle,
return PP_OK;
}
-skia::PlatformCanvas* PPB_ImageData_Impl::GetPlatformCanvas() {
- return mapped_canvas_.get();
-}
-
const SkBitmap* PPB_ImageData_Impl::GetMappedBitmap() const {
if (!mapped_canvas_.get())
return NULL;
diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.h b/webkit/plugins/ppapi/ppb_image_data_impl.h
index 817b238..64685d0 100644
--- a/webkit/plugins/ppapi/ppb_image_data_impl.h
+++ b/webkit/plugins/ppapi/ppb_image_data_impl.h
@@ -63,8 +63,9 @@ class PPB_ImageData_Impl : 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;
+ // The mapped bitmap and canvas will be NULL if the image is not mapped.
+ skia::PlatformCanvas* mapped_canvas() const { return mapped_canvas_.get(); }
const SkBitmap* GetMappedBitmap() const;
// Swaps the guts of this image data with another.
diff --git a/webkit/plugins/ppapi/ppb_scrollbar_impl.cc b/webkit/plugins/ppapi/ppb_scrollbar_impl.cc
index 3e3f2e9..97b80ff 100644
--- a/webkit/plugins/ppapi/ppb_scrollbar_impl.cc
+++ b/webkit/plugins/ppapi/ppb_scrollbar_impl.cc
@@ -134,7 +134,7 @@ void PPB_Scrollbar_Impl::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) {
PP_Bool PPB_Scrollbar_Impl::PaintInternal(const gfx::Rect& rect,
PPB_ImageData_Impl* image) {
ImageDataAutoMapper mapper(image);
- skia::PlatformCanvas* canvas = image->GetPlatformCanvas();
+ skia::PlatformCanvas* canvas = image->mapped_canvas();
if (!canvas || !scrollbar_.get())
return PP_FALSE;
scrollbar_->paint(webkit_glue::ToWebCanvas(canvas), rect);
diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc
index b1480a0..1f3943b 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.cc
+++ b/webkit/plugins/ppapi/resource_creation_impl.cc
@@ -6,7 +6,6 @@
#include "ppapi/c/pp_size.h"
#include "ppapi/shared_impl/ppb_audio_config_shared.h"
-#include "ppapi/shared_impl/private/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/var.h"
@@ -22,6 +21,7 @@
#include "webkit/plugins/ppapi/ppb_file_system_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_menu_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h"
+#include "webkit/plugins/ppapi/ppb_font_impl.h"
#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
#include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
@@ -35,7 +35,6 @@
#include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
#include "webkit/plugins/ppapi/ppb_video_layer_impl.h"
#include "webkit/plugins/ppapi/ppb_websocket_impl.h"
-#include "webkit/plugins/ppapi/resource_helper.h"
using ppapi::InputEventData;
using ppapi::PPB_InputEvent_Shared;
@@ -143,12 +142,7 @@ PP_Resource ResourceCreationImpl::CreateFlashNetConnector(
PP_Resource ResourceCreationImpl::CreateFontObject(
PP_Instance instance,
const PP_FontDescription_Dev* description) {
- PluginInstance* plugin_instance =
- ResourceHelper::PPInstanceToPluginInstance(instance);
- if (!plugin_instance)
- return 0;
- return ::ppapi::PPB_Font_Shared::CreateAsImpl(
- instance, *description, plugin_instance->delegate()->GetPreferences());
+ return PPB_Font_Impl::Create(instance, *description);
}
PP_Resource ResourceCreationImpl::CreateGraphics2D(
diff --git a/webkit/plugins/ppapi/resource_helper.cc b/webkit/plugins/ppapi/resource_helper.cc
index 0807e2e..1959961 100644
--- a/webkit/plugins/ppapi/resource_helper.cc
+++ b/webkit/plugins/ppapi/resource_helper.cc
@@ -17,12 +17,7 @@ namespace ppapi {
// static
PluginInstance* ResourceHelper::GetPluginInstance(
const ::ppapi::Resource* resource) {
- return PPInstanceToPluginInstance(resource->pp_instance());
-}
-
-PluginInstance* ResourceHelper::PPInstanceToPluginInstance(
- PP_Instance instance) {
- return HostGlobals::Get()->GetInstance(instance);
+ return HostGlobals::Get()->GetInstance(resource->pp_instance());
}
PluginModule* ResourceHelper::GetPluginModule(
diff --git a/webkit/plugins/ppapi/resource_helper.h b/webkit/plugins/ppapi/resource_helper.h
index cca66f0..1f245a1 100644
--- a/webkit/plugins/ppapi/resource_helper.h
+++ b/webkit/plugins/ppapi/resource_helper.h
@@ -6,7 +6,6 @@
#define WEBKIT_PLUGINS_PPAPI_RESOURCE_HELPER_H_
#include "base/basictypes.h"
-#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "webkit/plugins/webkit_plugins_export.h"
@@ -41,9 +40,6 @@ class ResourceHelper {
// resource has outlived its instance.
static PluginDelegate* GetPluginDelegate(const ::ppapi::Resource* resource);
- // Returns the instance implementation object for the pp_instance.
- static PluginInstance* PPInstanceToPluginInstance(PP_Instance instance);
-
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceHelper);
};
diff --git a/ppapi/shared_impl/private/ppb_font_shared.cc b/webkit/plugins/ppapi/webkit_forwarding_impl.cc
index 3af5288..967919b 100644
--- a/ppapi/shared_impl/private/ppb_font_shared.cc
+++ b/webkit/plugins/ppapi/webkit_forwarding_impl.cc
@@ -2,59 +2,44 @@
// 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 "webkit/plugins/ppapi/webkit_forwarding_impl.h"
+
+#include <string>
#include "base/debug/trace_event.h"
+#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/synchronization/waitable_event.h"
#include "base/utf_string_conversions.h"
#include "ppapi/c/dev/ppb_font_dev.h"
+#include "ppapi/c/pp_point.h"
+#include "ppapi/c/pp_rect.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/platform/WebRect.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/WebTextRun.h"
+#include "webkit/glue/webkit_glue.h"
-using ppapi::StringVar;
-using ppapi::thunk::EnterResource;
-using ppapi::thunk::EnterResourceNoLock;
-using ppapi::thunk::PPB_ImageData_API;
-using ppapi::WebKitForwarding;
+using ::ppapi::WebKitForwarding;
+using WebKit::WebCanvas;
using WebKit::WebFloatPoint;
using WebKit::WebFloatRect;
using WebKit::WebFont;
using WebKit::WebFontDescription;
using WebKit::WebRect;
using WebKit::WebTextRun;
-using WebKit::WebCanvas;
+namespace webkit {
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
@@ -151,17 +136,22 @@ class FontImpl : public WebKitForwarding::Font {
const ::ppapi::Preferences& prefs);
virtual ~FontImpl();
- 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) OVERRIDE;
- virtual void DrawTextAt(const DrawTextParams& params) OVERRIDE;
- virtual void MeasureText(const TextRun& text,
+ virtual void DrawTextAt(base::WaitableEvent* event,
+ const DrawTextParams& params) OVERRIDE;
+ virtual void MeasureText(base::WaitableEvent* event,
+ const TextRun& text,
int32_t* result) OVERRIDE;
- virtual void CharacterOffsetForPixel(const TextRun& text,
+ virtual void CharacterOffsetForPixel(base::WaitableEvent* event,
+ const TextRun& text,
int32_t pixel_position,
uint32_t* result) OVERRIDE;
- virtual void PixelOffsetForCharacter(const TextRun& text,
+ virtual void PixelOffsetForCharacter(base::WaitableEvent* event,
+ const TextRun& text,
uint32_t char_offset,
int32_t* result) OVERRIDE;
@@ -182,7 +172,8 @@ FontImpl::FontImpl(const PP_FontDescription_Dev& desc,
FontImpl::~FontImpl() {
}
-void FontImpl::Describe(PP_FontDescription_Dev* description,
+void FontImpl::Describe(base::WaitableEvent* event,
+ PP_FontDescription_Dev* description,
std::string* face,
PP_FontMetrics_Dev* metrics,
PP_Bool* result) {
@@ -214,9 +205,12 @@ void FontImpl::Describe(PP_FontDescription_Dev* description,
*result = PP_TRUE;
}
+ if (event)
+ event->Signal();
}
-void FontImpl::DrawTextAt(const DrawTextParams& params) {
+void FontImpl::DrawTextAt(base::WaitableEvent* event,
+ const DrawTextParams& params) {
TRACE_EVENT0("ppapi WebKit thread", "FontImpl::DrawTextAt");
WebTextRun run = TextRunToWebTextRun(params.text);
@@ -236,32 +230,34 @@ void FontImpl::DrawTextAt(const DrawTextParams& params) {
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,
+ font_->drawText(webkit_glue::ToWebCanvas(params.destination), run,
+ web_position, params.color, web_clip,
params.image_data_is_opaque == PP_TRUE);
+ if (event)
+ event->Signal();
}
-void FontImpl::MeasureText(const TextRun& text, int32_t* result) {
+void FontImpl::MeasureText(base::WaitableEvent* event,
+ const TextRun& text, int32_t* result) {
TRACE_EVENT0("ppapi WebKit thread", "FontImpl::MeasureText");
*result = font_->calculateWidth(TextRunToWebTextRun(text));
+ if (event)
+ event->Signal();
}
-void FontImpl::CharacterOffsetForPixel(const TextRun& text,
+void FontImpl::CharacterOffsetForPixel(base::WaitableEvent* event,
+ 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)));
+ if (event)
+ event->Signal();
}
-void FontImpl::PixelOffsetForCharacter(const TextRun& text,
+void FontImpl::PixelOffsetForCharacter(base::WaitableEvent* event,
+ const TextRun& text,
uint32_t char_offset,
int32_t* result) {
TRACE_EVENT0("ppapi WebKit thread", "FontImpl::PixelOffsetForCharacter");
@@ -273,147 +269,32 @@ void FontImpl::PixelOffsetForCharacter(const TextRun& text,
run, WebFloatPoint(0.0f, 0.0f), font_->height(), 0, char_offset);
*result = static_cast<int>(rect.width);
}
+ if (event)
+ event->Signal();
}
} // 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() {
-}
+// WebKitForwardingImpl --------------------------------------------------------
-::ppapi::thunk::PPB_Font_API* PPB_Font_Shared::AsPPB_Font_API() {
- return this;
+WebKitForwardingImpl::WebKitForwardingImpl() {
}
-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;
+WebKitForwardingImpl::~WebKitForwardingImpl() {
}
-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;
+void WebKitForwardingImpl::CreateFontForwarding(
+ base::WaitableEvent* event,
+ const PP_FontDescription_Dev& desc,
+ const std::string& desc_face,
+ const ::ppapi::Preferences& prefs,
+ Font** result) {
+ TRACE_EVENT0("ppapi WebKit thread",
+ "WebKitForwardingImpl::CreateFontForwarding");
+ *result = new FontImpl(desc, desc_face, prefs);
+ if (event)
+ event->Signal();
}
} // namespace ppapi
-
+} // namespace webkit
diff --git a/webkit/plugins/ppapi/webkit_forwarding_impl.h b/webkit/plugins/ppapi/webkit_forwarding_impl.h
new file mode 100644
index 0000000..ee39754
--- /dev/null
+++ b/webkit/plugins/ppapi/webkit_forwarding_impl.h
@@ -0,0 +1,30 @@
+// 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/webkit_forwarding.h"
+
+#include "base/compiler_specific.h"
+#include "webkit/plugins/webkit_plugins_export.h"
+
+namespace ppapi {
+struct Preferences;
+}
+
+namespace webkit {
+namespace ppapi {
+
+class WebKitForwardingImpl : public ::ppapi::WebKitForwarding {
+ public:
+ WEBKIT_PLUGINS_EXPORT WebKitForwardingImpl();
+ WEBKIT_PLUGINS_EXPORT virtual ~WebKitForwardingImpl();
+
+ virtual void CreateFontForwarding(base::WaitableEvent* event,
+ const PP_FontDescription_Dev& desc,
+ const std::string& desc_face,
+ const ::ppapi::Preferences& prefs,
+ Font** result) OVERRIDE;
+};
+
+} // namespace ppapi
+} // namespace webkit