示例#1
0
PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformData, ShouldRetain shouldRetain)
{
    if (!platformData)
        return 0;

    Cache::iterator result = m_cache.find(*platformData);
    if (result == m_cache.end()) {
        pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::create(*platformData), shouldRetain == Retain ? 1 : 0);
        m_cache.set(*platformData, newValue);
        if (shouldRetain == DoNotRetain)
            m_inactiveFontData.add(newValue.first);
        return newValue.first.release();
    }

    if (!result.get()->value.second) {
        ASSERT(m_inactiveFontData.contains(result.get()->value.first));
        m_inactiveFontData.remove(result.get()->value.first);
    }

    if (shouldRetain == Retain) {
        result.get()->value.second++;
    } else if (!result.get()->value.second) {
        // If shouldRetain is DoNotRetain and count is 0, we want to remove the fontData from
        // m_inactiveFontData (above) and re-add here to update LRU position.
        m_inactiveFontData.add(result.get()->value.first);
    }

    return result.get()->value.first;
}
示例#2
0
PassRefPtr<SimpleFontData> FontDataCache::get(
    const FontPlatformData* platformData,
    ShouldRetain shouldRetain,
    bool subpixelAscentDescent) {
  if (!platformData)
    return nullptr;

  // TODO: crbug.com/446376 - This should not happen, but we currently
  // do not have a reproduction for the crash that an empty typeface()
  // causes downstream from here.
  if (!platformData->typeface()) {
    DLOG(ERROR)
        << "Empty typeface() in FontPlatformData when accessing FontDataCache.";
    return nullptr;
  }

  Cache::iterator result = m_cache.find(platformData);
  if (result == m_cache.end()) {
    std::pair<RefPtr<SimpleFontData>, unsigned> newValue(
        SimpleFontData::create(*platformData, nullptr, false,
                               subpixelAscentDescent),
        shouldRetain == Retain ? 1 : 0);
    // The new SimpleFontData takes a copy of the incoming FontPlatformData
    // object. The incoming key may be temporary. So, for cache storage, take
    // the address of the newly created FontPlatformData that is copied an owned
    // by SimpleFontData.
    m_cache.set(&newValue.first->platformData(), newValue);
    if (shouldRetain == DoNotRetain)
      m_inactiveFontData.add(newValue.first);
    return newValue.first.release();
  }

  if (!result.get()->value.second) {
    ASSERT(m_inactiveFontData.contains(result.get()->value.first));
    m_inactiveFontData.remove(result.get()->value.first);
  }

  if (shouldRetain == Retain) {
    result.get()->value.second++;
  } else if (!result.get()->value.second) {
    // If shouldRetain is DoNotRetain and count is 0, we want to remove the
    // fontData from m_inactiveFontData (above) and re-add here to update LRU
    // position.
    m_inactiveFontData.add(result.get()->value.first);
  }

  return result.get()->value.first;
}
PassRefPtr<SimpleFontData> FontDataCache::get(const FontPlatformData* platformData, ShouldRetain shouldRetain)
{
    if (!platformData)
        return nullptr;

    // TODO: crbug.com/446376 - This should not happen, but we currently
    // do not have a reproduction for the crash that an empty typeface()
    // causes downstream from here.
    if (!platformData->typeface()) {
        DLOG(ERROR) << "Empty typeface() in FontPlatformData when accessing FontDataCache.";
        return nullptr;
    }

    Cache::iterator result = m_cache.find(*platformData);
    if (result == m_cache.end()) {
        std::pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::create(*platformData), shouldRetain == Retain ? 1 : 0);
        m_cache.set(*platformData, newValue);
        if (shouldRetain == DoNotRetain)
            m_inactiveFontData.add(newValue.first);
        return newValue.first.release();
    }

    if (!result.get()->value.second) {
        ASSERT(m_inactiveFontData.contains(result.get()->value.first));
        m_inactiveFontData.remove(result.get()->value.first);
    }

    if (shouldRetain == Retain) {
        result.get()->value.second++;
    } else if (!result.get()->value.second) {
        // If shouldRetain is DoNotRetain and count is 0, we want to remove the fontData from
        // m_inactiveFontData (above) and re-add here to update LRU position.
        m_inactiveFontData.add(result.get()->value.first);
    }

    return result.get()->value.first;
}