Commit 88c01901 authored by Fernando Serboncini's avatar Fernando Serboncini

Register a thread_safe_sender to DWriteFontProxy

Allows a DWriteFontProxy to have a thread-safe way to send IPCs even
when it's not on main thread.

Bug: 722393
Change-Id: I6f840898bce9340ed5c12dcb43ae74ea3bbe7f47
Reviewed-on: https://chromium-review.googlesource.com/587415
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490781}
parent 42c97626
......@@ -86,6 +86,10 @@
#include "content/common/mac/app_nap_activity.h"
#endif
#if defined(OS_WIN)
#include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h"
#endif
using tracked_objects::ThreadData;
namespace content {
......@@ -591,6 +595,10 @@ void ChildThreadImpl::Init(const Options& options) {
field_trial_syncer_->InitFieldTrialObserving(
*base::CommandLine::ForCurrentProcess());
}
#if defined(OS_WIN)
UpdateDWriteFontProxySender(thread_safe_sender());
#endif
}
ChildThreadImpl::~ChildThreadImpl() {
......
......@@ -28,6 +28,7 @@ namespace content {
namespace {
mswr::ComPtr<DWriteFontCollectionProxy> g_font_collection;
mswr::ComPtr<FontFallback> g_font_fallback;
IPC::Sender* g_sender_override = nullptr;
// Windows-only DirectWrite support. These warm up the DirectWrite paths
......@@ -44,6 +45,13 @@ void CreateDirectWriteFactory(IDWriteFactory** factory) {
} // namespace
void UpdateDWriteFontProxySender(IPC::Sender* sender) {
if (g_font_collection)
g_font_collection.Get()->SetSenderOverride(sender);
if (g_font_fallback)
g_font_fallback.Get()->SetSenderOverride(sender);
}
void InitializeDWriteFontProxy() {
mswr::ComPtr<IDWriteFactory> factory;
......@@ -51,27 +59,20 @@ void InitializeDWriteFontProxy() {
IPC::Sender* sender = g_sender_override;
// Hack for crbug.com/631254: set the sender if we can get one, so that when
// Flash calls into the font proxy from a different thread we will have a
// sender available.
if (!sender && ChildThreadImpl::current())
sender = ChildThreadImpl::current()->thread_safe_sender();
if (!g_font_collection) {
mswr::MakeAndInitialize<DWriteFontCollectionProxy>(
&g_font_collection, factory.Get(), sender);
}
mswr::ComPtr<IDWriteFontFallback> font_fallback;
mswr::ComPtr<IDWriteFactory2> factory2;
if (SUCCEEDED(factory.As(&factory2)) && factory2.Get()) {
mswr::MakeAndInitialize<FontFallback>(
&font_fallback, g_font_collection.Get(), sender);
mswr::MakeAndInitialize<FontFallback>(&g_font_fallback,
g_font_collection.Get(), sender);
}
sk_sp<SkFontMgr> skia_font_manager = SkFontMgr_New_DirectWrite(
factory.Get(), g_font_collection.Get(), font_fallback.Get());
factory.Get(), g_font_collection.Get(), g_font_fallback.Get());
blink::WebFontRendering::SetSkiaFontManager(skia_font_manager);
SetDefaultSkiaFactory(std::move(skia_font_manager));
......@@ -83,7 +84,7 @@ void InitializeDWriteFontProxy() {
// instead fall back on WebKit's fallback logic, we don't use Skia's font
// fallback if IDWriteFontFallback is not available.
// This flag can be removed when Win8.0 and earlier are no longer supported.
bool fallback_available = font_fallback.Get() != nullptr;
bool fallback_available = g_font_fallback.Get() != nullptr;
DCHECK_EQ(fallback_available,
base::win::GetVersion() > base::win::VERSION_WIN8);
blink::WebFontRendering::SetUseSkiaFontFallback(fallback_available);
......
......@@ -23,6 +23,10 @@ CONTENT_EXPORT void UninitializeDWriteFontProxy();
// font IPC messages. This should only be called when running as a test.
CONTENT_EXPORT void SetDWriteFontProxySenderForTesting(IPC::Sender* sender);
// Allows ChildThreadImpl to register a thread saef sender to DWriteFontProxy
// so we don't depend on being on the main thread to use DWriteFontProxy.
CONTENT_EXPORT void UpdateDWriteFontProxySender(IPC::Sender*);
} // namespace content
#endif // CONTENT_CHILD_DWRITE_FONT_PROXY_DWRITE_FONT_PROXY_INIT_WIN_H_
......@@ -81,6 +81,8 @@ class CONTENT_EXPORT DWriteFontCollectionProxy
bool CreateFamily(UINT32 family_index);
void SetSenderOverride(IPC::Sender* sender) { sender_override_ = sender; }
private:
IPC::Sender* GetSender();
......
......@@ -44,6 +44,8 @@ class CONTENT_EXPORT FontFallback
RuntimeClassInitialize(DWriteFontCollectionProxy* collection,
IPC::Sender* sender_override);
void SetSenderOverride(IPC::Sender* sender) { sender_override_ = sender; }
protected:
~FontFallback() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment