Changeset 79818 in webkit


Ignore:
Timestamp:
Feb 27, 2011 7:56:01 AM (13 years ago)
Author:
andreas.kling@nokia.com
Message:

2011-02-27 Andreas Kling <kling@webkit.org>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Use WTF ref counting for FontPlatformDataPrivate
https://bugs.webkit.org/show_bug.cgi?id=55303

Make FontPlatformDataPrivate a RefCounted<FPDP>.
Incidentally fixes an uninitialized member bug in FontPlatformData().

  • platform/graphics/qt/FontPlatformData.h: (WebCore::FontPlatformDataPrivate::FontPlatformDataPrivate): (WebCore::FontPlatformData::FontPlatformData): (WebCore::FontPlatformData::isHashTableDeletedValue): (WebCore::FontPlatformData::font): (WebCore::FontPlatformData::size): (WebCore::FontPlatformData::family): (WebCore::FontPlatformData::bold): (WebCore::FontPlatformData::italic): (WebCore::FontPlatformData::smallCaps): (WebCore::FontPlatformData::pixelSize):
  • platform/graphics/qt/FontPlatformDataQt.cpp: (WebCore::toQFontWeight): (WebCore::FontPlatformData::operator==): (WebCore::FontPlatformData::hash):
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r79817 r79818  
     12011-02-27  Andreas Kling  <kling@webkit.org>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Use WTF ref counting for FontPlatformDataPrivate
     6        https://bugs.webkit.org/show_bug.cgi?id=55303
     7
     8        Make FontPlatformDataPrivate a RefCounted<FPDP>.
     9        Incidentally fixes an uninitialized member bug in FontPlatformData().
     10
     11        * platform/graphics/qt/FontPlatformData.h:
     12        (WebCore::FontPlatformDataPrivate::FontPlatformDataPrivate):
     13        (WebCore::FontPlatformData::FontPlatformData):
     14        (WebCore::FontPlatformData::isHashTableDeletedValue):
     15        (WebCore::FontPlatformData::font):
     16        (WebCore::FontPlatformData::size):
     17        (WebCore::FontPlatformData::family):
     18        (WebCore::FontPlatformData::bold):
     19        (WebCore::FontPlatformData::italic):
     20        (WebCore::FontPlatformData::smallCaps):
     21        (WebCore::FontPlatformData::pixelSize):
     22        * platform/graphics/qt/FontPlatformDataQt.cpp:
     23        (WebCore::toQFontWeight):
     24        (WebCore::FontPlatformData::operator==):
     25        (WebCore::FontPlatformData::hash):
     26
    1272011-02-27  Benjamin Poulain  <ikipou@gmail.com>
    228
  • trunk/Source/WebCore/platform/graphics/qt/FontPlatformData.h

    r76248 r79818  
    2525#define FontPlatformData_h
    2626
    27 #include <wtf/Forward.h>
    2827#include "FontDescription.h"
    2928#include "FontOrientation.h"
    3029#include <QFont>
    3130#include <QHash>
     31#include <wtf/Forward.h>
     32#include <wtf/RefCounted.h>
    3233
    3334namespace WebCore {
    3435
    35 class FontPlatformDataPrivate {
     36class FontPlatformDataPrivate : public RefCounted<FontPlatformDataPrivate> {
    3637    WTF_MAKE_NONCOPYABLE(FontPlatformDataPrivate); WTF_MAKE_FAST_ALLOCATED;
    3738public:
    3839    FontPlatformDataPrivate()
    39         : refCount(1)
     40        : size(font.pixelSize())
     41        , bold(font.bold())
     42        , oblique(false)
     43        , isDeletedValue(false)
     44    { }
     45    FontPlatformDataPrivate(const float size, const bool bold, const bool oblique)
     46        : size(size)
     47        , bold(bold)
     48        , oblique(oblique)
     49        , isDeletedValue(false)
     50    { }
     51    FontPlatformDataPrivate(const QFont& font)
     52        : font(font)
    4053        , size(font.pixelSize())
    4154        , bold(font.bold())
    4255        , oblique(false)
    43     {}
    44     FontPlatformDataPrivate(const float size, const bool bold, const bool oblique)
    45         : refCount(1)
    46         , size(size)
    47         , bold(bold)
    48         , oblique(oblique)
    49     {}
    50     FontPlatformDataPrivate(const QFont& font)
    51         : refCount(1)
    52         , font(font)
    53         , size(font.pixelSize())
    54         , bold(font.bold())
    55         , oblique(false)
    56     {}
    57     unsigned refCount;
     56        , isDeletedValue(false)
     57    { }
     58    FontPlatformDataPrivate(WTF::HashTableDeletedValueType)
     59        : isDeletedValue(true)
     60    { }
     61
    5862    QFont font;
    5963    float size;
    6064    bool bold : 1;
    6165    bool oblique : 1;
     66    bool isDeletedValue : 1;
    6267};
    63 
    64 
    6568
    6669class FontPlatformData {
    6770    WTF_MAKE_FAST_ALLOCATED;
    6871public:
    69     FontPlatformData() { }
    7072    FontPlatformData(float size, bool bold, bool oblique);
    71     FontPlatformData(const FontPlatformData &);
    7273    FontPlatformData(const FontDescription&, const AtomicString& familyName, int wordSpacing = 0, int letterSpacing = 0);
    7374    FontPlatformData(const QFont& font)
    74         : m_data(new FontPlatformDataPrivate(font))
    75     {}
     75        : m_data(adoptRef(new FontPlatformDataPrivate(font)))
     76    { }
    7677    FontPlatformData(WTF::HashTableDeletedValueType)
    77         : m_data(reinterpret_cast<FontPlatformDataPrivate*>(-1))
    78     {}
     78        : m_data(adoptRef(new FontPlatformDataPrivate()))
     79    {
     80        m_data->isDeletedValue = true;
     81    }
    7982
    80     ~FontPlatformData();
    81 
    82     FontPlatformData& operator=(const FontPlatformData&);
    8383    bool operator==(const FontPlatformData&) const;
    8484
    8585    bool isHashTableDeletedValue() const
    8686    {
    87         return m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1);
    88     }
    89 
    90     static inline QFont::Weight toQFontWeight(FontWeight fontWeight)
    91     {
    92         switch (fontWeight) {
    93         case FontWeight100:
    94         case FontWeight200:
    95             return QFont::Light;  // QFont::Light == Weight of 25
    96         case FontWeight600:
    97             return QFont::DemiBold;  // QFont::DemiBold == Weight of 63
    98         case FontWeight700:
    99         case FontWeight800:
    100             return QFont::Bold;  // QFont::Bold == Weight of 75
    101         case FontWeight900:
    102             return QFont::Black;  // QFont::Black == Weight of 87
    103         case FontWeight300:
    104         case FontWeight400:
    105         case FontWeight500:
    106         default:
    107             return QFont::Normal;  // QFont::Normal == Weight of 50
    108         }
     87        return m_data && m_data->isDeletedValue;
    10988    }
    11089
    11190    QFont font() const
    11291    {
    113         Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));
    114         if (m_data)
    115             return m_data->font;
    116         return QFont();
     92        Q_ASSERT(!isHashTableDeletedValue());
     93        if (!m_data)
     94            return QFont();
     95        return m_data->font;
    11796    }
    11897    float size() const
    11998    {
    120         Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));
    121         if (m_data)
    122             return m_data->size;
    123         return 0.0f;
     99        Q_ASSERT(!isHashTableDeletedValue());
     100        if (!m_data)
     101            return 0;
     102        return m_data->size;
    124103    }
    125104    QString family() const
    126105    {
    127         Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));
    128         if (m_data)
    129             return m_data->font.family();
    130         return QString();
     106        Q_ASSERT(!isHashTableDeletedValue());
     107        if (!m_data)
     108            return QString();
     109        return m_data->font.family();
    131110    }
    132111    bool bold() const
    133112    {
    134         Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));
    135         if (m_data)
    136             return m_data->bold;
    137         return false;
     113        Q_ASSERT(!isHashTableDeletedValue());
     114        if (!m_data)
     115            return false;
     116        return m_data->bold;
    138117    }
    139118    bool italic() const
    140119    {
    141         Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));
    142         if (m_data)
    143             return m_data->font.italic();
    144         return false;
     120        Q_ASSERT(!isHashTableDeletedValue());
     121        if (!m_data)
     122            return false;
     123        return m_data->font.italic();
    145124    }
    146125    bool smallCaps() const
    147126    {
    148         Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));
    149         if (m_data)
    150             return m_data->font.capitalization() == QFont::SmallCaps;
    151         return false;
     127        Q_ASSERT(!isHashTableDeletedValue());
     128        if (!m_data)
     129            return false;
     130        return m_data->font.capitalization() == QFont::SmallCaps;
    152131    }
    153132    int pixelSize() const
    154133    {
    155         Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1));
    156         if (m_data) {
    157             // WebKit allows font size zero but QFont does not.
    158             if (!m_data->size)
    159                 return m_data->size;
    160             return m_data->font.pixelSize();
    161         }
    162         return 0;
     134        Q_ASSERT(!isHashTableDeletedValue());
     135        if (!m_data)
     136            return 0;
     137        // WebCore allows a font size of zero, but QFont does not.
     138        if (!m_data->size)
     139            return 0;
     140        return m_data->font.pixelSize();
    163141    }
    164142   
     
    171149#endif
    172150private:
    173     FontPlatformDataPrivate* m_data;
     151    RefPtr<FontPlatformDataPrivate> m_data;
    174152};
    175153
  • trunk/Source/WebCore/platform/graphics/qt/FontPlatformDataQt.cpp

    r73341 r79818  
    22    Copyright (C) 2008 Holger Hans Peter Freyther
    33    Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
     4    Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
    45
    56    This library is free software; you can redistribute it and/or
     
    2728namespace WebCore {
    2829
     30static inline QFont::Weight toQFontWeight(FontWeight fontWeight)
     31{
     32    switch (fontWeight) {
     33    case FontWeight100:
     34    case FontWeight200:
     35        return QFont::Light; // QFont::Light == Weight of 25
     36    case FontWeight600:
     37        return QFont::DemiBold; // QFont::DemiBold == Weight of 63
     38    case FontWeight700:
     39    case FontWeight800:
     40        return QFont::Bold; // QFont::Bold == Weight of 75
     41    case FontWeight900:
     42        return QFont::Black; // QFont::Black == Weight of 87
     43    case FontWeight300:
     44    case FontWeight400:
     45    case FontWeight500:
     46    default:
     47        return QFont::Normal; // QFont::Normal == Weight of 50
     48    }
     49}
     50
    2951static inline bool isEmptyValue(const float size, const bool bold, const bool oblique)
    3052{
     
    3557FontPlatformData::FontPlatformData(float size, bool bold, bool oblique)
    3658{
    37     if (isEmptyValue(size, bold, oblique))
    38         m_data = 0;
    39     else
    40         m_data = new FontPlatformDataPrivate(size, bold, oblique);
    41 }
    42 
    43 FontPlatformData::FontPlatformData(const FontPlatformData &other) : m_data(other.m_data)
    44 {
    45     if (m_data && m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1))
    46         ++m_data->refCount;
     59    if (!isEmptyValue(size, bold, oblique))
     60        m_data = adoptRef(new FontPlatformDataPrivate(size, bold, oblique));
    4761}
    4862
    4963FontPlatformData::FontPlatformData(const FontDescription& description, const AtomicString& familyName, int wordSpacing, int letterSpacing)
    50     : m_data(new FontPlatformDataPrivate())
     64    : m_data(adoptRef(new FontPlatformDataPrivate()))
    5165{
    5266    QFont& font = m_data->font;
     
    7185}
    7286
    73 FontPlatformData::~FontPlatformData()
    74 {
    75     if (!m_data || m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1))
    76         return;
    77     --m_data->refCount;
    78     if (!m_data->refCount)
    79         delete m_data;
    80 }
    81 
    82 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other)
    83 {
    84     if (m_data == other.m_data)
    85         return *this;
    86     if (m_data && m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)) {
    87         --m_data->refCount;
    88         if (!m_data->refCount)
    89             delete m_data;
    90     }
    91     m_data = other.m_data;
    92     if (m_data && m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1))
    93         ++m_data->refCount;
    94     return *this;
    95 }
    96 
    9787bool FontPlatformData::operator==(const FontPlatformData& other) const
    9888{
     
    10090        return true;
    10191
    102     if (!m_data || !other.m_data
    103         || m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1) || other.m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1))
    104         return  false;
     92    if (!m_data || !other.m_data || m_data->isDeletedValue || other.m_data->isDeletedValue)
     93        return false;
    10594
    10695    const bool equals = (m_data->size == other.m_data->size
     
    115104    if (!m_data)
    116105        return 0;
    117     if (m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1))
     106    if (m_data->isDeletedValue)
    118107        return 1;
    119108    return qHash(m_data->font.toString())
Note: See TracChangeset for help on using the changeset viewer.