Commit 4951143a authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Add font access for Linux

Testing on Cluster Telemetry with Linux found an issue where SkFontMgr
wasn't initialized properly resulting in inability to start the
compositor. This is due to the lack of font access since we didn't
call EnsureBlinkInitializedWithSandbox. However, the compositor only
needs a fraction of the features that come with that call. This CL
starts the font_service which enables the SkFontMgr to initialize. Note
that we don't require WebSandboxSupport to be initialized (at least for
Linux) as all the fonts are stored in the provided SkPictures.

Test coverage for this will be added as part of the end-to-end tests
for the player. That should catch any issues with other platforms.

Bug: 1023377
Change-Id: I95a224f6f3759b1b8f8df2989222757ebbd4f12e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1908062
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718149}
parent dba35724
include_rules = [
"+components/services/paint_preview_compositor",
]
// Copyright 2019 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 <utility>
#include <vector>
#include "base/bind.h"
#include "base/no_destructor.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "base/unguessable_token.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/services/paint_preview_compositor/paint_preview_compositor_collection_impl.h"
#include "components/services/paint_preview_compositor/public/mojom/paint_preview_compositor.mojom.h"
#include "content/public/browser/service_process_host.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/service_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace paint_preview {
class PaintPreviewCompositorCollectionBrowserTest
: public InProcessBrowserTest {
public:
PaintPreviewCompositorCollectionBrowserTest() = default;
~PaintPreviewCompositorCollectionBrowserTest() override = default;
protected:
mojo::Remote<mojom::PaintPreviewCompositorCollection> StartUtilityProcess() {
return content::ServiceProcessHost::Launch<
mojom::PaintPreviewCompositorCollection>(
content::ServiceProcessHost::Options()
.WithSandboxType(service_manager::SANDBOX_TYPE_PDF_COMPOSITOR)
.Pass());
}
};
IN_PROC_BROWSER_TEST_F(PaintPreviewCompositorCollectionBrowserTest,
TestInitializationSuccess) {
base::RunLoop loop;
mojo::Remote<mojom::PaintPreviewCompositorCollection> compositor_collection =
StartUtilityProcess();
EXPECT_TRUE(compositor_collection.is_bound());
EXPECT_TRUE(compositor_collection.is_connected());
// If the compositor_collection hasn't crashed during initialization due to
// lacking font support then this call should succeed.
compositor_collection->ListCompositors(base::BindOnce(
[](base::OnceClosure quit,
const std::vector<base::UnguessableToken>& ids) {
EXPECT_EQ(ids.size(), 0U);
std::move(quit).Run();
},
loop.QuitClosure()));
loop.Run();
}
} // namespace paint_preview
......@@ -696,6 +696,7 @@ if (!is_android) {
"//components/resources",
"//components/safe_browsing:buildflags",
"//components/safe_browsing/db:test_database_manager",
"//components/services/paint_preview_compositor/public/mojom",
"//components/services/patch/public/mojom",
"//components/services/quarantine:test_support",
"//components/signin/core/browser",
......@@ -1040,6 +1041,7 @@ if (!is_android) {
"../browser/page_load_metrics/observers/subresource_loading_page_load_metrics_observer_browsertest.cc",
"../browser/page_load_metrics/observers/third_party_metrics_observer_browsertest.cc",
"../browser/page_load_metrics/page_load_metrics_browsertest.cc",
"../browser/paint_preview/paint_preview_compositor_browsertest.cc",
"../browser/password_manager/credential_manager_browsertest.cc",
"../browser/password_manager/password_manager_browsertest.cc",
"../browser/pdf/pdf_extension_test.cc",
......
......@@ -21,12 +21,17 @@ static_library("paint_preview_compositor") {
"//components/discardable_memory/client",
"//components/paint_preview/common",
"//components/paint_preview/common/proto",
"//content/public/utility",
"//mojo/public/cpp/bindings",
"//skia",
"//ui/gfx/geometry",
"//url",
]
if (is_linux) {
deps += [ "//components/services/font/public/cpp" ]
}
if (is_win) {
deps += [ "//content/public/child" ]
}
......
include_rules = [
"+components/discardable_memory/client",
"+components/paint_preview",
"+components/services/font/public",
"+content/public/child", # Windows direct write proxy access.
"+content/public/utility",
"+mojo/public/cpp",
"+third_party/skia/include/core",
"+third_party/skia/include",
"+ui/gfx/geometry",
]
......@@ -9,10 +9,14 @@
#include "base/memory/discardable_memory.h"
#include "base/memory/discardable_memory_allocator.h"
#include "build/build_config.h"
#include "content/public/utility/utility_thread.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/ports/SkFontConfigInterface.h"
#if defined(OS_WIN)
#include "content/public/child/dwrite_font_proxy_init_win.h"
#elif defined(OS_LINUX)
#include "components/services/font/public/cpp/font_loader.h"
#endif
namespace paint_preview {
......@@ -28,10 +32,21 @@ PaintPreviewCompositorCollectionImpl::PaintPreviewCompositorCollectionImpl(
if (!initialize_environment)
return;
// Initialize font access for Skia.
#if defined(OS_WIN)
// Initialize direct write font proxy so skia can use it.
content::InitializeDWriteFontProxy();
#elif defined(OS_LINUX)
mojo::PendingRemote<font_service::mojom::FontService> font_service;
content::UtilityThread::Get()->BindHostReceiver(
font_service.InitWithNewPipeAndPassReceiver());
font_loader_ = sk_make_sp<font_service::FontLoader>(std::move(font_service));
SkFontConfigInterface::SetGlobal(font_loader_);
#endif
// TODO(crbug/1023377): Determine if EnsureBlinkInitialized*() does any other
// initialization we require. Possibly for other platforms (e.g. MacOS,
// Android). In theory, WebSandboxSupport isn't required since we subset and
// load all required fonts into the Skia Pictures for portability so they are
// all local; however, this may be required for initialization on MacOS?
// TODO(crbug/1013585): PDF compositor initializes Blink to leverage some
// codecs for images. This is a huge overhead and shouldn't be necessary for
......@@ -39,7 +54,15 @@ PaintPreviewCompositorCollectionImpl::PaintPreviewCompositorCollectionImpl(
// encoding to PNG or we could provide our own codec implementations.
// Sanity check that fonts are working.
#if defined(OS_LINUX)
// No WebSandbox is provided on Linux so the local fonts aren't accessible.
// This is fine since since the subsetted fonts are provided in the SkPicture.
// However, we still need to check that the SkFontMgr starts as it is used by
// Skia when handling the SkPicture.
DCHECK(SkFontMgr::RefDefault());
#else
DCHECK(SkFontMgr::RefDefault()->countFamilies());
#endif
}
PaintPreviewCompositorCollectionImpl::~PaintPreviewCompositorCollectionImpl() {
......
......@@ -12,12 +12,18 @@
#include "base/memory/scoped_refptr.h"
#include "base/single_thread_task_runner.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h"
#include "components/services/paint_preview_compositor/paint_preview_compositor_impl.h"
#include "components/services/paint_preview_compositor/public/mojom/paint_preview_compositor.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#if defined(OS_LINUX)
#include "components/services/font/public/cpp/font_loader.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#endif
namespace discardable_memory {
class ClientDiscardableSharedMemoryManager;
}
......@@ -62,6 +68,10 @@ class PaintPreviewCompositorCollectionImpl
std::unique_ptr<PaintPreviewCompositorImpl>>
compositors_;
#if defined(OS_LINUX)
sk_sp<font_service::FontLoader> font_loader_;
#endif
PaintPreviewCompositorCollectionImpl(
const PaintPreviewCompositorCollectionImpl&) = delete;
PaintPreviewCompositorCollectionImpl& operator=(
......
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