当前位置: 首页>>代码示例>>C++>>正文


C++ GrContext::getResourceCachePurgeableBytes方法代码示例

本文整理汇总了C++中GrContext::getResourceCachePurgeableBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ GrContext::getResourceCachePurgeableBytes方法的具体用法?C++ GrContext::getResourceCachePurgeableBytes怎么用?C++ GrContext::getResourceCachePurgeableBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GrContext的用法示例。


在下文中一共展示了GrContext::getResourceCachePurgeableBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) {
    DisplayInfo displayInfo = renderThread.mainDisplayInfo();
    GrContext* grContext = renderThread.getGrContext();
    ASSERT_TRUE(grContext != nullptr);

    // create pairs of offscreen render targets and images until we exceed the
    // backgroundCacheSizeLimit
    std::vector<sk_sp<SkSurface>> surfaces;

    while (getCacheUsage(grContext) <= renderThread.cacheManager().getBackgroundCacheSize()) {
        SkImageInfo info = SkImageInfo::MakeA8(displayInfo.w, displayInfo.h);
        sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(grContext, SkBudgeted::kYes, info);
        surface->getCanvas()->drawColor(SK_AlphaTRANSPARENT);

        grContext->flush();

        surfaces.push_back(surface);
    }

    // create an image and pin it so that we have something with a unique key in the cache
    sk_sp<Bitmap> bitmap =
            Bitmap::allocateHeapBitmap(SkImageInfo::MakeA8(displayInfo.w, displayInfo.h));
    sk_sp<SkColorFilter> filter;
    sk_sp<SkImage> image = bitmap->makeImage(&filter);
    ASSERT_TRUE(SkImage_pinAsTexture(image.get(), grContext));

    // attempt to trim all memory while we still hold strong refs
    renderThread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete);
    ASSERT_TRUE(0 == grContext->getResourceCachePurgeableBytes());

    // free the surfaces
    for (size_t i = 0; i < surfaces.size(); i++) {
        ASSERT_TRUE(surfaces[i]->unique());
        surfaces[i].reset();
    }

    // unpin the image which should add a unique purgeable key to the cache
    SkImage_unpinAsTexture(image.get(), grContext);

    // verify that we have enough purgeable bytes
    const size_t purgeableBytes = grContext->getResourceCachePurgeableBytes();
    ASSERT_TRUE(renderThread.cacheManager().getBackgroundCacheSize() < purgeableBytes);

    // UI hidden and make sure only some got purged (unique should remain)
    renderThread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::UiHidden);
    ASSERT_TRUE(0 < grContext->getResourceCachePurgeableBytes());
    ASSERT_TRUE(renderThread.cacheManager().getBackgroundCacheSize() > getCacheUsage(grContext));

    // complete and make sure all get purged
    renderThread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete);
    ASSERT_TRUE(0 == grContext->getResourceCachePurgeableBytes());
}
开发者ID:AlanCheen,项目名称:platform_frameworks_base,代码行数:52,代码来源:CacheManagerTests.cpp


注:本文中的GrContext::getResourceCachePurgeableBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。