Commit 5c69afb2 authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Remove DEFINE_FONT_DATA_TYPE_CASTS and use new downcast helper

This CL has two goals,
  1. Remove DEFINE_FONT_DATA_TYPE_CASTS.
  2. Use new downast helpers for blink::SegmentedFontData and
     blink::SimpleFontData.

Bug: 891908
Change-Id: Ia42e0f889a11462545463c205a324152900d7ea6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2019749Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#751253}
parent 51ae055c
......@@ -57,15 +57,6 @@ class PLATFORM_EXPORT FontData : public RefCounted<FontData> {
DISALLOW_COPY_AND_ASSIGN(FontData);
};
#define DEFINE_FONT_DATA_TYPE_CASTS(thisType, predicate) \
template <typename T> \
inline thisType* To##thisType(const scoped_refptr<T>& fontData) { \
return To##thisType(fontData.get()); \
} \
DEFINE_TYPE_CASTS(thisType, FontData, fontData, \
fontData->IsSegmented() == predicate, \
fontData.IsSegmented() == predicate)
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_DATA_H_
......@@ -153,7 +153,7 @@ scoped_refptr<FontDataForRangeSet> FontFallbackIterator::Next(
current_font_data_index_++;
if (!font_data->IsLoading()) {
scoped_refptr<SimpleFontData> non_segmented =
const_cast<SimpleFontData*>(ToSimpleFontData(font_data));
const_cast<SimpleFontData*>(To<SimpleFontData>(font_data));
// The fontData object that we have here is tracked in m_fontList of
// FontFallbackList and gets released in the font cache when the
// FontFallbackList is destroyed.
......@@ -165,7 +165,7 @@ scoped_refptr<FontDataForRangeSet> FontFallbackIterator::Next(
// Iterate over ranges of a segmented font below.
const SegmentedFontData* segmented = ToSegmentedFontData(font_data);
const auto* segmented = To<SegmentedFontData>(font_data);
if (fallback_stage_ != kSegmentedFace) {
segmented_face_index_ = 0;
fallback_stage_ = kSegmentedFace;
......
......@@ -69,7 +69,7 @@ void FontFallbackList::ReleaseFontData() {
if (!font_list_[i]->IsCustomFont()) {
DCHECK(!font_list_[i]->IsSegmented());
FontCache::GetFontCache()->ReleaseFontData(
ToSimpleFontData(font_list_[i]));
To<SimpleFontData>(font_list_[i].get()));
}
}
shape_cache_.reset(); // Clear the weak pointer to the cache instance.
......@@ -125,8 +125,8 @@ const SimpleFontData* FontFallbackList::DeterminePrimarySimpleFontData(
return last_resort_fallback;
}
if (font_data->IsSegmented() &&
!ToSegmentedFontData(font_data)->ContainsCharacter(kSpaceCharacter))
const auto* segmented = DynamicTo<SegmentedFontData>(font_data);
if (segmented && !segmented->ContainsCharacter(kSpaceCharacter))
continue;
const SimpleFontData* font_data_for_space =
......@@ -139,8 +139,7 @@ const SimpleFontData* FontFallbackList::DeterminePrimarySimpleFontData(
if (!font_data_for_space->IsLoadingFallback())
return font_data_for_space;
if (font_data->IsSegmented()) {
const SegmentedFontData* segmented = ToSegmentedFontData(font_data);
if (segmented) {
for (unsigned i = 0; i < segmented->NumFaces(); i++) {
const SimpleFontData* range_font_data =
segmented->FaceAt(i)->FontData();
......@@ -223,8 +222,9 @@ FallbackListCompositeKey FontFallbackList::CompositeKey(
if (result) {
bool is_unique_match = false;
key.Add(font_description.CacheKey(params, is_unique_match));
if (!result->IsSegmented() && !result->IsCustomFont())
FontCache::GetFontCache()->ReleaseFontData(ToSimpleFontData(result));
auto* font_data = DynamicTo<SimpleFontData>(result.get());
if (!font_data && !result->IsCustomFont())
FontCache::GetFontCache()->ReleaseFontData(font_data);
}
}
current_family = current_family->Next();
......
......@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/platform/fonts/font_data.h"
#include "third_party/blink/renderer/platform/fonts/font_data_for_range_set.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
class SimpleFontData;
......@@ -61,7 +62,12 @@ class PLATFORM_EXPORT SegmentedFontData : public FontData {
Vector<scoped_refptr<FontDataForRangeSet>, 1> faces_;
};
DEFINE_FONT_DATA_TYPE_CASTS(SegmentedFontData, true);
template <>
struct DowncastTraits<SegmentedFontData> {
static bool AllowFrom(const FontData& fontData) {
return fontData.IsSegmented();
}
};
} // namespace blink
......
......@@ -39,6 +39,7 @@
#include "third_party/blink/renderer/platform/fonts/typesetting_features.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
#include "third_party/skia/include/core/SkFont.h"
......@@ -245,7 +246,12 @@ ALWAYS_INLINE float SimpleFontData::WidthForGlyph(Glyph glyph) const {
#endif
}
DEFINE_FONT_DATA_TYPE_CASTS(SimpleFontData, false);
template <>
struct DowncastTraits<SimpleFontData> {
static bool AllowFrom(const FontData& fontData) {
return !fontData.IsSegmented();
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_SIMPLE_FONT_DATA_H_
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