示例#1
0
void ResourceReader::addResourceToCache(ResourceSlot *slot, Resource *res) {
	_cacheDataSize += slot->size;

	if (_cacheDataSize >= kMaxResourceCacheSize) {
		purgeCache();
	}

	slot->res = res;
	slot->refCount = 1;
	_cacheCount++;
}
示例#2
0
/* Fetch sectors from the specified file.  csExtent may not be larger
   than the maximum cache size. */
CoreResult coreFetchSectors(CryptedVolume * pVolume,
   CryptedFileID id, SectorNumber sStart, SectorNumber csExtent,
   unsigned int flFlags)
{
   CoreResult cr;
   SectorNumber i;
   unsigned int csMissing;
   SectorNumber * pasMissing;
   CryptedFile * pFile;

   cr = accessFile(pVolume, id, &pFile);
   if (cr) return cr;
   
   if (!csExtent) return CORERC_OK;
   if (csExtent > pFile->pVolume->parms.csMaxCached)
      return CORERC_CACHE_OVERFLOW;

   /* Determine which sectors are not in the cache. */
   pasMissing = malloc(csExtent * sizeof(SectorNumber *));
   if (!pasMissing) return CORERC_NOT_ENOUGH_MEMORY;
   csMissing = 0;
   for (i = 0; i < csExtent; i++)
      if (!queryCachedSector(pVolume, id, sStart + i)) 
         pasMissing[csMissing++] = sStart + i;

   if (!csMissing) { /* everything already in cache */
      free(pasMissing);
      return CORERC_OK;
   }

   /* Make sure that there is enough room in the cache. */
   if (pFile->pVolume->csInCache + csMissing >
      pFile->pVolume->parms.csMaxCached)
   {
      cr = purgeCache(pFile->pVolume,
         pFile->pVolume->csInCache -
         (pFile->pVolume->parms.csMaxCached - csMissing),
         pFile, sStart, csExtent);
      if (cr) {
         free(pasMissing);
         return cr;
      }
   }

   cr = readSectors(pFile, csMissing, pasMissing, flFlags);
   free(pasMissing);
   return cr;
}
PathTexture* PathCache::addTexture(const PathDescription& entry, const SkPath *path,
        const SkPaint* paint) {
    ATRACE_CALL();

    float left, top, offset;
    uint32_t width, height;
    computePathBounds(path, paint, left, top, offset, width, height);

    if (!checkTextureSize(width, height)) return NULL;

    purgeCache(width, height);

    SkBitmap bitmap;
    drawPath(path, paint, bitmap, left, top, offset, width, height);

    PathTexture* texture = createTexture(left, top, offset, width, height,
            path->getGenerationID());
    generateTexture(entry, &bitmap, texture);

    return texture;
}
示例#4
0
ResourceCache::~ResourceCache() {
	purgeCache();
}