コード例 #1
0
bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client,
                                     SkImage::CachingHint chint) {
    if (this->tryLockAsBitmap(bitmap, client, chint)) {
        return check_output_bitmap(*bitmap, fUniqueID);
    }

#if SK_SUPPORT_GPU
    // Try to get a texture and read it back to raster (and then cache that with our ID)
    SkAutoTUnref<GrTexture> tex;

    {
        ScopedGenerator generator(this);
        SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height());
        tex.reset(generator->generateTexture(nullptr, &subset));
    }
    if (!tex) {
        bitmap->reset();
        return false;
    }

    if (!bitmap->tryAllocPixels(fInfo)) {
        bitmap->reset();
        return false;
    }

    const uint32_t pixelOpsFlags = 0;
    if (!tex->readPixels(0, 0, bitmap->width(), bitmap->height(), SkImageInfo2GrPixelConfig(fInfo),
                         bitmap->getPixels(), bitmap->rowBytes(), pixelOpsFlags)) {
        bitmap->reset();
        return false;
    }

    bitmap->pixelRef()->setImmutableWithID(fUniqueID);
    if (SkImage::kAllow_CachingHint == chint) {
        SkBitmapCache::Add(fUniqueID, *bitmap);
        if (client) {
            as_IB(client)->notifyAddedToCache();
        }
    }
    return check_output_bitmap(*bitmap, fUniqueID);
#else
    return false;
#endif
}
コード例 #2
0
ファイル: SkImageCacherator.cpp プロジェクト: wzugang/skia
bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) {
    if (SkBitmapCache::Find(fUniqueID, bitmap)) {
        return check_output_bitmap(*bitmap, fUniqueID);
    }

    if (!this->generateBitmap(bitmap)) {
        return false;
    }

    bitmap->pixelRef()->setImmutableWithID(fUniqueID);
    SkBitmapCache::Add(fUniqueID, *bitmap);
    return true;
}
コード例 #3
0
bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) {
    const uint32_t uniqueID = fGenerator->uniqueID();

    if (SkBitmapCache::Find(uniqueID, bitmap)) {
        return check_output_bitmap(*bitmap, uniqueID);
    }
    if (!generate_bitmap(fGenerator, bitmap)) {
        return false;
    }

    bitmap->pixelRef()->setImmutableWithID(uniqueID);
    SkBitmapCache::Add(uniqueID, *bitmap);
    return true;
}
コード例 #4
0
bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap) {
    const uint32_t uniqueID = fGenerator->uniqueID();

    if (this->tryLockAsBitmap(bitmap)) {
        return check_output_bitmap(*bitmap, uniqueID);
    }

#if SK_SUPPORT_GPU
    // Try to get a texture and read it back to raster (and then cache that with our ID)

    SkAutoTUnref<GrTexture> tex(fGenerator->generateTexture(nullptr, kUntiled_SkImageUsageType));
    if (!tex) {
        bitmap->reset();
        return false;
    }

    const SkImageInfo& info = this->info();
    if (!bitmap->tryAllocPixels(info)) {
        bitmap->reset();
        return false;
    }

    const uint32_t pixelOpsFlags = 0;
    if (!tex->readPixels(0, 0, bitmap->width(), bitmap->height(), SkImageInfo2GrPixelConfig(info),
                         bitmap->getPixels(), bitmap->rowBytes(), pixelOpsFlags)) {
        bitmap->reset();
        return false;
    }

    bitmap->pixelRef()->setImmutableWithID(uniqueID);
    SkBitmapCache::Add(uniqueID, *bitmap);
    return check_output_bitmap(*bitmap, uniqueID);
#else
    return false;
#endif
}
コード例 #5
0
ファイル: SkImageCacherator.cpp プロジェクト: Just-D/skia
bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client) {
    if (SkBitmapCache::Find(fUniqueID, bitmap)) {
        return check_output_bitmap(*bitmap, fUniqueID);
    }

    if (!this->generateBitmap(bitmap)) {
        return false;
    }

    bitmap->pixelRef()->setImmutableWithID(fUniqueID);
    SkBitmapCache::Add(fUniqueID, *bitmap);
    if (client) {
        as_IB(client)->notifyAddedToCache();
    }

    return true;
}
コード例 #6
0
ファイル: SkImage_Lazy.cpp プロジェクト: molikto/Skia
bool SkImage_Lazy::lockAsBitmap(SkBitmap* bitmap, SkImage::CachingHint chint, CachedFormat format,
                                const SkImageInfo& info,
                                SkTransferFunctionBehavior behavior) const {
    if (this->lockAsBitmapOnlyIfAlreadyCached(bitmap, format)) {
        return true;
    }

    uint32_t uniqueID = this->getUniqueID(format);

    SkBitmap tmpBitmap;
    SkBitmapCache::RecPtr cacheRec;
    SkPixmap pmap;
    if (SkImage::kAllow_CachingHint == chint) {
        auto desc = SkBitmapCacheDesc::Make(uniqueID, info.width(), info.height());
        cacheRec = SkBitmapCache::Alloc(desc, info, &pmap);
        if (!cacheRec) {
            return false;
        }
    } else {
        if (!tmpBitmap.tryAllocPixels(info)) {
            return false;
        }
        if (!tmpBitmap.peekPixels(&pmap)) {
            return false;
        }
    }

    ScopedGenerator generator(fSharedGenerator);
    if (!generate_pixels(generator, pmap, fOrigin.x(), fOrigin.y(), behavior)) {
        return false;
    }

    if (cacheRec) {
        SkBitmapCache::Add(std::move(cacheRec), bitmap);
        SkASSERT(bitmap->getPixels());  // we're locked
        SkASSERT(bitmap->isImmutable());
        SkASSERT(bitmap->getGenerationID() == uniqueID);
        this->notifyAddedToCache();
    } else {
        *bitmap = tmpBitmap;
        bitmap->pixelRef()->setImmutableWithID(uniqueID);
    }

    check_output_bitmap(*bitmap, uniqueID);
    return true;
}
コード例 #7
0
bool SkImageCacherator::lockAsBitmapOnlyIfAlreadyCached(SkBitmap* bitmap) {
    return SkBitmapCache::Find(fUniqueID, bitmap) && check_output_bitmap(*bitmap, fUniqueID);
}
コード例 #8
0
ファイル: SkImage_Lazy.cpp プロジェクト: molikto/Skia
bool SkImage_Lazy::lockAsBitmapOnlyIfAlreadyCached(SkBitmap* bitmap, CachedFormat format) const {
    uint32_t uniqueID = this->getUniqueID(format);
    return SkBitmapCache::Find(SkBitmapCacheDesc::Make(uniqueID,
                                                       fInfo.width(), fInfo.height()), bitmap) &&
           check_output_bitmap(*bitmap, uniqueID);
}