void *second_thread(void *arg) { (void) arg; set_address_handler(42); populate_cache(); return NULL; }
void onPreDraw() override { fContext.reset(GrContext::CreateMockContext()); if (!fContext) { return; } // Set the cache budget to be very large so no purging occurs. fContext->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); GrResourceCache* cache = fContext->getResourceCache(); // Make sure the cache is empty. cache->purgeAllUnlocked(); SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes()); GrGpu* gpu = fContext->getGpu(); populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count); }
void onDraw(const int loops, SkCanvas* canvas) override { SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); if (NULL == context) { return; } // Set the cache budget to be very large so no purging occurs. context->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); GrResourceCache* cache = context->getResourceCache(); // Make sure the cache is empty. cache->purgeAllUnlocked(); SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes()); GrGpu* gpu = context->getGpu(); for (int i = 0; i < loops; ++i) { populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count); SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); } }
// Read len bytes, starting at file position pos, into buf. // Unread bytes will be set to 0. void dbuf_read(dbuf *f, u8 *buf, i64 pos, i64 len) { i64 bytes_read = 0; i64 bytes_to_read; deark *c; c = f->c; bytes_to_read = len; if(pos >= f->len) { bytes_to_read = 0; } else if(pos + bytes_to_read > f->len) { bytes_to_read = f->len - pos; } if(bytes_to_read<1) { goto done_read; } if(!f->cache && f->cache_policy==DE_CACHE_POLICY_ENABLED) { populate_cache(f); } // If the data we need is all cached, get it from cache. if(f->cache && pos >= f->cache_start_pos && pos + bytes_to_read <= f->cache_start_pos + f->cache_bytes_used) { de_memcpy(buf, &f->cache[pos - f->cache_start_pos], (size_t)bytes_to_read); bytes_read = bytes_to_read; goto done_read; } switch(f->btype) { case DBUF_TYPE_IFILE: if(!f->fp) { de_err(c, "Internal: File not open"); de_fatalerror(c); return; } // For performance reasons, don't call fseek if we're already at the // right position. if(!f->file_pos_known || f->file_pos!=pos) { de_fseek(f->fp, pos, SEEK_SET); } bytes_read = fread(buf, 1, (size_t)bytes_to_read, f->fp); f->file_pos = pos + bytes_read; f->file_pos_known = 1; break; case DBUF_TYPE_IDBUF: // Recursive call to the parent dbuf. dbuf_read(f->parent_dbuf, buf, f->offset_into_parent_dbuf+pos, bytes_to_read); // The parent dbuf always writes 'bytes_to_read' bytes. bytes_read = bytes_to_read; break; case DBUF_TYPE_MEMBUF: de_memcpy(buf, &f->membuf_buf[pos], (size_t)bytes_to_read); bytes_read = bytes_to_read; break; default: de_err(c, "Internal: getbytes from this I/O type not implemented"); de_fatalerror(c); return; } done_read: // Zero out any requested bytes that were not read. if(bytes_read < len) { de_zeromem(buf+bytes_read, (size_t)(len - bytes_read)); } }