Пример #1
0
const ScaledImageFragment* ImageDecodingStore::insertAndLockCache(const ImageFrameGenerator* generator, PassOwnPtr<ScaledImageFragment> image)
{
    // Prune old cache entries to give space for the new one.
    prune();

    ScaledImageFragment* newImage = image.get();
    OwnPtr<ImageCacheEntry> newCacheEntry = ImageCacheEntry::createAndUse(generator, image);
    Vector<OwnPtr<CacheEntry> > cacheEntriesToDelete;
    {
        MutexLocker lock(m_mutex);

        ImageCacheMap::iterator iter = m_imageCacheMap.find(newCacheEntry->cacheKey());

        // It is rare but possible that the key of a new cache entry is found.
        // This happens if the generation ID of the image object wraps around.
        // In this case we will try to return the existing cached object and
        // discard the new cache object.
        if (iter != m_imageCacheMap.end()) {
            const ScaledImageFragment* oldImage;
            if (lockCacheEntryInternal(iter->value.get(), &oldImage, &cacheEntriesToDelete)) {
                newCacheEntry->decrementUseCount();
                return oldImage;
            }
        }

        // The new image is not locked yet so do it here.
        newImage->bitmap().lockPixels();
        insertCacheInternal(newCacheEntry.release(), &m_imageCacheMap, &m_imageCacheKeyMap);
    }
    return newImage;
}
Пример #2
0
void ImageDecodingStore::insertDecoder(const ImageFrameGenerator* generator, PassOwnPtr<ImageDecoder> decoder, bool isDiscardable)
{
    // Prune old cache entries to give space for the new one.
    prune();

    OwnPtr<DecoderCacheEntry> newCacheEntry = DecoderCacheEntry::create(generator, decoder, isDiscardable);

    MutexLocker lock(m_mutex);
    ASSERT(!m_decoderCacheMap.contains(newCacheEntry->cacheKey()));
    insertCacheInternal(newCacheEntry.release(), &m_decoderCacheMap, &m_decoderCacheKeyMap);
}
Пример #3
0
void ImageDecodingStore::insertDecoder(const ImageFrameGenerator* generator,
                                       std::unique_ptr<ImageDecoder> decoder) {
  // Prune old cache entries to give space for the new one.
  prune();

  std::unique_ptr<DecoderCacheEntry> newCacheEntry =
      DecoderCacheEntry::create(generator, std::move(decoder));

  MutexLocker lock(m_mutex);
  ASSERT(!m_decoderCacheMap.contains(newCacheEntry->cacheKey()));
  insertCacheInternal(std::move(newCacheEntry), &m_decoderCacheMap,
                      &m_decoderCacheKeyMap);
}
const ScaledImageFragment* ImageDecodingStore::insertAndLockCache(const ImageFrameGenerator* generator, PassOwnPtr<ScaledImageFragment> image, PassOwnPtr<ImageDecoder> decoder)
{
    // Prune old cache entries to give space for the new one.
    prune();

    ScaledImageFragment* cachedImage = image.get();
    OwnPtr<CacheEntry> newCacheEntry;

    // ImageDecoder is not used any more if cache is complete.
    if (image->isComplete())
        newCacheEntry = CacheEntry::createAndUse(generator, image);
    else
        newCacheEntry = CacheEntry::createAndUse(generator, image, decoder);

    MutexLocker lock(m_mutex);
    // Lock the underlying SkBitmap to prevent it from being purged.
    cachedImage->bitmap().lockPixels();
    ASSERT(!m_cacheMap.contains(newCacheEntry->cacheKey()));
    insertCacheInternal(newCacheEntry.release());
    return cachedImage;
}