Commit 13d087e7 authored by Dominik Röttsches's avatar Dominik Röttsches Committed by Commit Bot

Pass DSF to FontCache before layout

Preparation for fixing the DSF that is used for querying render style
for strike, see crbug.com/849877.

If one renderer maintains multiple views, we need to inform the font
cache about this view's DSF before performing layout. This is because
FontPlatformData on Linux / CrOS needs the DSF for querying the
RenderStyle for fonts in this view correctly from out of process.

Prepare the FontCache for including the DSF in GetFontplatformData
queries.

Bug: 845468
Change-Id: Ib3de63dcdb18261502837905a04e563a30bcb42e
Reviewed-on: https://chromium-review.googlesource.com/1087908Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564978}
parent d88bd9df
......@@ -51,9 +51,9 @@ TEST(CSSFontFaceSourceTest, HashCollision) {
DummyFontFaceSource font_face_source;
// Even if the hash value collide, fontface cache should return different
// value for different fonts.
EXPECT_EQ(SimulateHashCalculation(2), SimulateHashCalculation(4925));
EXPECT_NE(font_face_source.GetFontDataForSize(2),
font_face_source.GetFontDataForSize(4925));
EXPECT_EQ(SimulateHashCalculation(527), SimulateHashCalculation(3099));
EXPECT_NE(font_face_source.GetFontDataForSize(527),
font_face_source.GetFontDataForSize(3099));
}
// Exercises the size font_data_table_ assertions in CSSFontFaceSource.
......
......@@ -23,7 +23,9 @@
#include <inttypes.h>
#include "build/build_config.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_screen_info.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
......@@ -53,6 +55,10 @@
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/transforms/transform_state.h"
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#include "third_party/blink/renderer/platform/fonts/font_cache.h"
#endif
namespace blink {
namespace {
......@@ -313,6 +319,21 @@ void LayoutView::UpdateLayout() {
DCHECK(!layout_state_);
LayoutState root_layout_state(*this);
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
// The font code in FontPlatformData does not have a direct connection to the
// document, the frame or anything from which we could retrieve the device
// scale factor. After using zoom for DSF, the GraphicsContext does only ever
// have a DSF of 1 on Linux. In order for the font code to be aware of an up
// to date DSF when layout happens, we plumb this through to the FontCache, so
// that we can correctly retrieve RenderStyleForStrike from out of
// process. crbug.com/845468
FontCache::SetDeviceScaleFactor(GetFrameView()
->GetFrame()
.GetChromeClient()
.GetScreenInfo()
.device_scale_factor);
#endif
LayoutBlockFlow::UpdateLayout();
#if DCHECK_IS_ON()
......
......@@ -190,8 +190,8 @@ void MediaControlsRotateToFullscreenDelegateTest::InitScreenAndVideo(
WebScreenInfo screen_info;
screen_info.orientation_type = initial_screen_orientation;
EXPECT_CALL(GetChromeClient(), GetScreenInfo())
.Times(1)
.WillOnce(Return(screen_info));
.Times(AtLeast(1))
.WillRepeatedly(Return(screen_info));
// Set up the WebMediaPlayer instance.
GetDocument().body()->AppendChild(&GetVideo());
......
......@@ -65,6 +65,10 @@ namespace blink {
SkFontMgr* FontCache::static_font_manager_ = nullptr;
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
float FontCache::device_scale_factor_ = 1.0;
#endif
#if defined(OS_WIN)
bool FontCache::antialiased_text_enabled_ = false;
bool FontCache::lcd_text_enabled_ = false;
......
......@@ -157,6 +157,15 @@ class PLATFORM_EXPORT FontCache {
sk_sp<SkFontMgr> FontManager() { return font_manager_; }
static void SetFontManager(sk_sp<SkFontMgr>);
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
// These are needed for calling QueryRenderStyleForStrike, since
// gfx::GetFontRenderParams makes distinctions based on DSF.
static float DeviceScaleFactor() { return device_scale_factor_; }
static void SetDeviceScaleFactor(float device_scale_factor) {
device_scale_factor_ = device_scale_factor;
}
#endif
#if !defined(OS_MACOSX)
static const AtomicString& SystemFontFamily();
#else
......@@ -319,6 +328,10 @@ class PLATFORM_EXPORT FontCache {
bool is_test_font_mgr_ = false;
#endif // defined(OS_WIN)
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
static float device_scale_factor_;
#endif
unsigned short generation_ = 0;
bool platform_init_ = false;
Persistent<HeapHashSet<WeakMember<FontCacheClient>>> font_cache_clients_;
......
......@@ -49,22 +49,31 @@ struct FontCacheKey {
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
public:
FontCacheKey() : creation_params_(), font_size_(0), options_(0) {}
FontCacheKey()
: creation_params_(),
font_size_(0),
options_(0),
device_scale_factor_(0) {}
FontCacheKey(FontFaceCreationParams creation_params,
float font_size,
unsigned options,
float device_scale_factor,
scoped_refptr<FontVariationSettings> variation_settings)
: creation_params_(creation_params),
font_size_(font_size * kFontSizePrecisionMultiplier),
options_(options),
device_scale_factor_(device_scale_factor),
variation_settings_(std::move(variation_settings)) {}
FontCacheKey(WTF::HashTableDeletedValueType)
: font_size_(HashTableDeletedSize()) {}
unsigned GetHash() const {
unsigned hash_codes[4] = {
// Convert from float with 3 digit precision before hashing.
unsigned device_scale_factor_hash = device_scale_factor_ * 1000;
unsigned hash_codes[5] = {
creation_params_.GetHash(), font_size_, options_,
device_scale_factor_hash,
variation_settings_ ? variation_settings_->GetHash() : 0};
return StringHasher::HashMemory<sizeof(hash_codes)>(hash_codes);
}
......@@ -72,6 +81,7 @@ struct FontCacheKey {
bool operator==(const FontCacheKey& other) const {
return creation_params_ == other.creation_params_ &&
font_size_ == other.font_size_ && options_ == other.options_ &&
device_scale_factor_ == other.device_scale_factor_ &&
variation_settings_ == other.variation_settings_;
}
......@@ -89,6 +99,11 @@ struct FontCacheKey {
FontFaceCreationParams creation_params_;
unsigned font_size_;
unsigned options_;
// FontCacheKey is the key to retrieve FontPlatformData entries from the
// FontCache. FontPlatformData queries the platform's font render style, which
// is dependent on the device scale factor. That's why we need
// device_scale_factor_ to be a part of computing the cache key.
float device_scale_factor_;
scoped_refptr<FontVariationSettings> variation_settings_;
};
......
......@@ -28,6 +28,7 @@
*/
#include "third_party/blink/renderer/platform/fonts/font_description.h"
#include "build/build_config.h"
#include "third_party/blink/public/platform/web_font_description.h"
#include "third_party/blink/renderer/platform/language.h"
......@@ -37,6 +38,10 @@
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_hash.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#include "third_party/blink/renderer/platform/fonts/font_cache.h"
#endif
namespace blink {
struct SameSizeAsFontDescription {
......@@ -217,9 +222,14 @@ FontCacheKey FontDescription::CacheKey(
static_cast<unsigned>(fields_.orientation_) << 1 | // bit 2-3
static_cast<unsigned>(fields_.subpixel_text_position_); // bit 1
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
float device_scale_factor_for_key = FontCache::DeviceScaleFactor();
#else
float device_scale_factor_for_key = 1.0f;
#endif
FontCacheKey cache_key(creation_params, EffectiveFontSize(),
options | font_selection_request_.GetHash() << 8,
variation_settings_);
device_scale_factor_for_key, variation_settings_);
return cache_key;
}
......
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