Skip to content

Commit

Permalink
Roll Fuchsia SDK to bf318690d, fix FontProvider name breakage.
Browse files Browse the repository at this point in the history
The AutoRoll server is located here: https://autoroll.skia.org/r/fuchsia-sdk-chromium-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.


CQ_INCLUDE_TRYBOTS=luci.chromium.try:fuchsia_arm64_cast_audio;luci.chromium.try:fuchsia_x64_cast_audio
TBR=cr-fuchsia+bot@chromium.org

Change-Id: Iee9c1a2f249f0b660ed6d2f9e88f7e43eec2378d
Reviewed-on: https://chromium-review.googlesource.com/1226271
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591216}
  • Loading branch information
Kevin Marshall authored and Commit Bot committed Sep 14, 2018
1 parent 74e86f3 commit 09d6371
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 64 deletions.
2 changes: 1 addition & 1 deletion build/config/fuchsia/testing_sandbox_policy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"vulkan" ],
"dev": ["null", "zero"],
"services": [
"fuchsia.fonts.FontProvider",
"fuchsia.fonts.Provider",
"fuchsia.media.Audio",
"fuchsia.net.LegacySocketProvider",
"fuchsia.netstack.Netstack",
Expand Down
2 changes: 1 addition & 1 deletion build/fuchsia/linux.sdk.sha1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4654933febb76659749d66fe0ca6ff8ad68746e3
b1216b541e0f074020c47f7694c79a67dec15321
2 changes: 1 addition & 1 deletion build/fuchsia/mac.sdk.sha1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b945bb408f1e6ec1ecd0139100caa5d6b0a19539
a2592d225df950d7e35ffadb9514e0024e1602c3
2 changes: 1 addition & 1 deletion content/common/sandbox_policy_fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace content {
namespace {

constexpr const char* const kRendererServices[] = {
fuchsia::fonts::FontProvider::Name_};
fuchsia::fonts::Provider::Name_};

constexpr const char* const kGpuServices[] = {
fuchsia::ui::scenic::Scenic::Name_};
Expand Down
2 changes: 1 addition & 1 deletion skia/ext/fontmgr_default_fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ SK_API sk_sp<SkFontMgr> SkFontMgr::Factory() {
}
return sk_make_sp<skia::FuchsiaFontManager>(
base::fuchsia::ComponentContext::GetDefault()
->ConnectToServiceSync<fuchsia::fonts::FontProvider>());
->ConnectToServiceSync<fuchsia::fonts::Provider>());
}
56 changes: 28 additions & 28 deletions skia/ext/fontmgr_fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace {

constexpr char kDefaultFont[] = "Roboto";

// Currently FontProvider doesn't support font aliases. The map below is used to
// map common web fonts to font families that are expected to be present in
// FontProvider.
// Currently fonts::Provider doesn't support font aliases. The map below is
// used to map common web fonts to font families that are expected to be present
// in fonts::Provider.
constexpr struct {
const char* font_name_in;
const char* font_name_out;
Expand All @@ -50,10 +50,9 @@ constexpr struct {
{"courier new", "RobotoMono"},
{"monospace", "RobotoMono"}};

fuchsia::fonts::FontSlant ToFontSlant(SkFontStyle::Slant slant) {
return (slant == SkFontStyle::kItalic_Slant)
? fuchsia::fonts::FontSlant::ITALIC
: fuchsia::fonts::FontSlant::UPRIGHT;
fuchsia::fonts::Slant ToFontSlant(SkFontStyle::Slant slant) {
return (slant == SkFontStyle::kItalic_Slant) ? fuchsia::fonts::Slant::ITALIC
: fuchsia::fonts::Slant::UPRIGHT;
}

void UnmapMemory(const void* buffer, void* context) {
Expand Down Expand Up @@ -127,14 +126,14 @@ sk_sp<SkTypeface> CreateTypefaceFromSkStream(
name, std::move(on_deleted));
}

sk_sp<SkTypeface> CreateTypefaceFromFontData(fuchsia::fonts::FontData font_data,
base::OnceClosure on_deleted) {
sk_sp<SkData> data = BufferToSkData(std::move(font_data.buffer));
sk_sp<SkTypeface> CreateTypefaceFromBuffer(fuchsia::mem::Buffer buffer,
base::OnceClosure on_deleted) {
sk_sp<SkData> data = BufferToSkData(std::move(buffer));
if (!data)
return nullptr;

// TODO(https://crbug.com/800156): Initialize font arguments with font index
// when font collection support is implemented in FontProvider.
// when font collection support is implemented in Provider.
SkFontArguments args;

return CreateTypefaceFromSkStream(
Expand All @@ -149,15 +148,15 @@ class FuchsiaFontManager::FontCache {
FontCache();
~FontCache();

sk_sp<SkTypeface> GetTypefaceFromFontData(fuchsia::fonts::FontData font_data);
sk_sp<SkTypeface> GetTypefaceFromBuffer(fuchsia::mem::Buffer buffer);

private:
void OnTypefaceDeleted(zx_koid_t vmo_koid);

THREAD_CHECKER(thread_checker_);

// SkTypeface cache. They key is koid of the VMO that contains the typeface.
// This allows to reuse previously-created SkTypeface when FontProvider
// This allows to reuse previously-created SkTypeface when fonts::Provider
// returns FontData with the same VMO.
base::small_map<std::unordered_map<zx_koid_t, SkTypeface*>> typefaces_;

Expand All @@ -170,13 +169,13 @@ FuchsiaFontManager::FontCache::FontCache() : weak_factory_(this) {}

FuchsiaFontManager::FontCache::~FontCache() = default;

sk_sp<SkTypeface> FuchsiaFontManager::FontCache::GetTypefaceFromFontData(
fuchsia::fonts::FontData font_data) {
sk_sp<SkTypeface> FuchsiaFontManager::FontCache::GetTypefaceFromBuffer(
fuchsia::mem::Buffer buffer) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);

zx_info_handle_basic_t vmo_info;
zx_status_t status = font_data.buffer.vmo.get_info(
ZX_INFO_HANDLE_BASIC, &vmo_info, sizeof(vmo_info), nullptr, nullptr);
zx_status_t status = buffer.vmo.get_info(ZX_INFO_HANDLE_BASIC, &vmo_info,
sizeof(vmo_info), nullptr, nullptr);
if (status != ZX_OK) {
ZX_DLOG(ERROR, status) << "zx_object_get_info";
return nullptr;
Expand All @@ -187,8 +186,8 @@ sk_sp<SkTypeface> FuchsiaFontManager::FontCache::GetTypefaceFromFontData(
if (*cached_typeface) {
result = sk_ref_sp(*cached_typeface);
} else {
result = CreateTypefaceFromFontData(
std::move(font_data),
result = CreateTypefaceFromBuffer(
std::move(buffer),
base::BindOnce(&FontCache::OnTypefaceDeleted,
weak_factory_.GetWeakPtr(), vmo_info.koid));
*cached_typeface = result.get();
Expand All @@ -204,7 +203,7 @@ void FuchsiaFontManager::FontCache::OnTypefaceDeleted(zx_koid_t vmo_koid) {
}

FuchsiaFontManager::FuchsiaFontManager(
fuchsia::fonts::FontProviderSyncPtr font_provider)
fuchsia::fonts::ProviderSyncPtr font_provider)
: font_provider_(std::move(font_provider)), font_cache_(new FontCache()) {
for (auto& m : kFontMap) {
font_map_[m.font_name_in] = m.font_name_out;
Expand All @@ -214,7 +213,7 @@ FuchsiaFontManager::FuchsiaFontManager(
default_typeface_.reset(onMatchFamilyStyle(kDefaultFont, SkFontStyle()));
if (!default_typeface_) {
default_typeface_ = sk_make_sp<SkTypeface_Empty>();
LOG(ERROR) << "Failed to get default font from the FontProvider.";
LOG(ERROR) << "Failed to get default font from fonts::Provider.";
}
}

Expand Down Expand Up @@ -246,30 +245,31 @@ SkTypeface* FuchsiaFontManager::onMatchFamilyStyle(
const SkFontStyle& style) const {
std::string family_name_lowercase = base::ToLowerASCII(family_name);

fuchsia::fonts::FontRequest request;
fuchsia::fonts::Request request;
auto it = font_map_.find(family_name_lowercase);
request.family = (it != font_map_.end()) ? it->second.c_str() : family_name;
request.weight = style.weight();
request.width = style.width();
request.slant = ToFontSlant(style.slant());

fuchsia::fonts::FontResponsePtr response;
fuchsia::fonts::ResponsePtr response;
zx_status_t status = font_provider_->GetFont(std::move(request), &response);
if (status != ZX_OK) {
ZX_DLOG(ERROR, status) << "Failed to query font provider.";
} else if (response) {
sk_sp<SkTypeface> result =
font_cache_->GetTypefaceFromFontData(std::move(response->data));
font_cache_->GetTypefaceFromBuffer(std::move(response->buffer));
if (result)
return result.release();

LOG(ERROR) << "FontProvider returned invalid FontData for " << family_name;
LOG(ERROR) << "fonts::Provider returned invalid FontData for "
<< family_name;
}

// If Sans was requested and we failed to get a valid response from
// FontProvider then return |default_typeface_|. blink::FontCache queries Sans
// as a last-resort font. Returning |default_typeface_| here ensures that the
// renderer doesn't crash when FontProvider stops working.
// fonts::Provider then return |default_typeface_|. blink::FontCache queries
// Sans as a last-resort font. Returning |default_typeface_| here ensures that
// the renderer doesn't crash when fonts::Provider stops working.
if (family_name_lowercase == "sans") {
// Copy |default_typeface_| to increment ref-count before returning it.
sk_sp<SkTypeface> result = default_typeface_;
Expand Down
5 changes: 2 additions & 3 deletions skia/ext/fontmgr_fuchsia.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ namespace skia {

class SK_API FuchsiaFontManager : public SkFontMgr {
public:
explicit FuchsiaFontManager(
fuchsia::fonts::FontProviderSyncPtr font_provider);
explicit FuchsiaFontManager(fuchsia::fonts::ProviderSyncPtr font_provider);

~FuchsiaFontManager() override;

Expand Down Expand Up @@ -52,7 +51,7 @@ class SK_API FuchsiaFontManager : public SkFontMgr {
private:
class FontCache;

fuchsia::fonts::FontProviderSyncPtr font_provider_;
fuchsia::fonts::ProviderSyncPtr font_provider_;

// Map applied to font family name before sending requests to the FontService.
base::flat_map<std::string, std::string> font_map_;
Expand Down
52 changes: 25 additions & 27 deletions skia/ext/fontmgr_fuchsia_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@ namespace {
constexpr zx_rights_t kFontDataRights =
ZX_RIGHTS_BASIC | ZX_RIGHT_READ | ZX_RIGHT_MAP;

fuchsia::fonts::FontData LoadFont(const base::FilePath& file_path) {
fuchsia::mem::Buffer LoadFont(const base::FilePath& file_path) {
std::string file_content;
CHECK(ReadFileToString(file_path, &file_content));
fuchsia::fonts::FontData data;
zx_status_t status =
zx::vmo::create(file_content.size(), 0, &data.buffer.vmo);
fuchsia::mem::Buffer buffer;
zx_status_t status = zx::vmo::create(file_content.size(), 0, &buffer.vmo);
ZX_CHECK(status == ZX_OK, status);
status = data.buffer.vmo.write(file_content.data(), 0, file_content.size());
status = buffer.vmo.write(file_content.data(), 0, file_content.size());
ZX_CHECK(status == ZX_OK, status);
data.buffer.size = file_content.size();
return data;
buffer.size = file_content.size();
return buffer;
}

class MockFontProvider : public fuchsia::fonts::FontProvider {
class MockFontProvider : public fuchsia::fonts::Provider {
public:
MockFontProvider() {
base::FilePath assets_dir;
Expand All @@ -50,32 +49,32 @@ class MockFontProvider : public fuchsia::fonts::FontProvider {
roboto_slab_ = LoadFont(assets_dir.Append("test_fonts/Tinos-Regular.ttf"));
}

// fuchsia::fonts::FontProvider implementation.
void GetFont(fuchsia::fonts::FontRequest request,
// fuchsia::fonts::Provider implementation.
void GetFont(fuchsia::fonts::Request request,
GetFontCallback callback) override {
fuchsia::fonts::FontData* font_data = nullptr;
fuchsia::mem::Buffer* font_buffer = nullptr;
if (*request.family == "Roboto") {
font_data = &roboto_;
font_buffer = &roboto_;
} else if (*request.family == "RobotoSlab") {
font_data = &roboto_slab_;
font_buffer = &roboto_slab_;
}

if (!font_data) {
if (!font_buffer) {
callback(nullptr);
return;
}

auto response = fuchsia::fonts::FontResponse::New();
EXPECT_EQ(font_data->buffer.vmo.duplicate(kFontDataRights,
&(response->data.buffer.vmo)),
ZX_OK);
response->data.buffer.size = font_data->buffer.size;
auto response = fuchsia::fonts::Response::New();
EXPECT_EQ(
font_buffer->vmo.duplicate(kFontDataRights, &(response->buffer.vmo)),
ZX_OK);
response->buffer.size = font_buffer->size;
callback(std::move(response));
}

private:
fuchsia::fonts::FontData roboto_;
fuchsia::fonts::FontData roboto_slab_;
fuchsia::mem::Buffer roboto_;
fuchsia::mem::Buffer roboto_slab_;
};

class MockFontProviderService {
Expand All @@ -90,32 +89,31 @@ class MockFontProviderService {
std::move(provider_binding_));
}

void Bind(fidl::InterfaceRequest<fuchsia::fonts::FontProvider> request) {
void Bind(fidl::InterfaceRequest<fuchsia::fonts::Provider> request) {
provider_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&MockFontProviderService::DoBind,
base::Unretained(this), std::move(request)));
}

private:
void DoBind(fidl::InterfaceRequest<fuchsia::fonts::FontProvider> request) {
void DoBind(fidl::InterfaceRequest<fuchsia::fonts::Provider> request) {
provider_binding_ =
std::make_unique<fidl::Binding<fuchsia::fonts::FontProvider>>(
std::make_unique<fidl::Binding<fuchsia::fonts::Provider>>(
&provider_, std::move(request));
}

base::Thread provider_thread_;

MockFontProvider provider_;
std::unique_ptr<fidl::Binding<fuchsia::fonts::FontProvider>>
provider_binding_;
std::unique_ptr<fidl::Binding<fuchsia::fonts::Provider>> provider_binding_;
};

} // namespace

class FuchsiaFontManagerTest : public testing::Test {
public:
FuchsiaFontManagerTest() {
fuchsia::fonts::FontProviderSyncPtr font_provider;
fuchsia::fonts::ProviderSyncPtr font_provider;
font_provider_service_.Bind(font_provider.NewRequest());
font_manager_ = sk_make_sp<FuchsiaFontManager>(std::move(font_provider));
}
Expand Down
2 changes: 1 addition & 1 deletion webrunner/app/sandbox_policy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"features": [],
"services": [
"chromium.web.ContextProvider",
"fuchsia.fonts.FontProvider",
"fuchsia.fonts.Provider",
"fuchsia.media.Audio",
"fuchsia.net.LegacySocketProvider",
"fuchsia.netstack.Netstack",
Expand Down

0 comments on commit 09d6371

Please sign in to comment.