Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: content/renderer/renderer_main_platform_delegate_win.cc

Issue 209163002: Support DirectWrite with sandbox on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add todo Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« content/common/sandbox_win.cc ('K') | « content/common/sandbox_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/renderer_main_platform_delegate_win.cc
diff --git a/content/renderer/renderer_main_platform_delegate_win.cc b/content/renderer/renderer_main_platform_delegate_win.cc
index 58fce15cc41f4c4400a749c489c7a34fde5de828..508b8ad69d28a01348b273cd6c310b2c7e7b03a9 100644
--- a/content/renderer/renderer_main_platform_delegate_win.cc
+++ b/content/renderer/renderer_main_platform_delegate_win.cc
@@ -8,7 +8,10 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
+#include "base/win/scoped_comptr.h"
#include "base/win/win_util.h"
+#include "base/win/windows_version.h"
+#include "content/common/sandbox_win.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/injection_test_win.h"
#include "content/public/renderer/render_thread.h"
@@ -22,10 +25,13 @@
#include "v8/src/third_party/vtune/v8-vtune.h"
#endif
+#include <dwrite.h>
+
namespace content {
namespace {
// Windows-only skia sandbox support
+// These are used for GDI-path rendering.
void SkiaPreCacheFont(const LOGFONT& logfont) {
RenderThread* render_thread = RenderThread::Get();
if (render_thread) {
@@ -44,6 +50,51 @@ void SkiaPreCacheFontCharacters(const LOGFONT& logfont,
}
}
+// Windows-only DirectWrite support. These warm up the DirectWrite paths
+// before sandbox lock down to allow Skia access to the Font Manager service.
+bool CreateDirectWriteFactory(IDWriteFactory** factory) {
+ typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
+ DWriteCreateFactoryProc dwrite_create_factory_proc =
+ reinterpret_cast<DWriteCreateFactoryProc>(
+ GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory"));
+ if (!dwrite_create_factory_proc)
+ return false;
+ CHECK(SUCCEEDED(
+ dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED,
+ __uuidof(IDWriteFactory),
+ reinterpret_cast<IUnknown**>(factory))));
+ return true;
+}
+
+void WarmupDirectWrite() {
+ base::win::ScopedComPtr<IDWriteFactory> factory;
+ if (!CreateDirectWriteFactory(factory.Receive()))
+ return;
+
+ base::win::ScopedComPtr<IDWriteFontCollection> font_collection;
+ CHECK(SUCCEEDED(
+ factory->GetSystemFontCollection(font_collection.Receive(), FALSE)));
+ base::win::ScopedComPtr<IDWriteFontFamily> font_family;
+
+ UINT32 index;
+ BOOL exists;
+ CHECK(SUCCEEDED(
+ font_collection->FindFamilyName(L"Times New Roman", &index, &exists)));
+ CHECK(exists);
+ CHECK(
+ SUCCEEDED(font_collection->GetFontFamily(index, font_family.Receive())));
+ base::win::ScopedComPtr<IDWriteFont> font;
+ base::win::ScopedComPtr<IDWriteFontFace> font_face;
+ CHECK(SUCCEEDED(font_family->GetFirstMatchingFont(DWRITE_FONT_WEIGHT_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL,
+ DWRITE_FONT_STYLE_NORMAL,
+ font.Receive())));
+ CHECK(SUCCEEDED(font->CreateFontFace(font_face.Receive())));
+ DWRITE_GLYPH_METRICS gm;
+ UINT16 glyph = L'S';
+ CHECK(SUCCEEDED(font_face->GetDesignGlyphMetrics(&glyph, 1, &gm)));
+}
+
} // namespace
RendererMainPlatformDelegate::RendererMainPlatformDelegate(
@@ -75,9 +126,14 @@ void RendererMainPlatformDelegate::PlatformInitialize() {
// cached and there's no more need to access the registry. If the sandbox
// is disabled, we don't have to make this dummy call.
scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
- SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont);
- skia::SetSkiaEnsureTypefaceCharactersAccessible(
- SkiaPreCacheFontCharacters);
+
+ if (content::ShouldUseDirectWrite()) {
jam 2014/03/25 22:57:26 ditto
+ WarmupDirectWrite();
+ } else {
+ SkTypeface_SetEnsureLOGFONTAccessibleProc(SkiaPreCacheFont);
+ skia::SetSkiaEnsureTypefaceCharactersAccessible(
+ SkiaPreCacheFontCharacters);
+ }
}
}
« content/common/sandbox_win.cc ('K') | « content/common/sandbox_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698