void WidgetSkin::draw(int x, int y, int width, int height, eType type) { MAHandle cached = 0; // Calculate numTiles needed to be drawn, if they are many, we need to cache, otherwise draw directly... int numTiles = calculateNumTiles(width, height); if(!useCache || numTiles<100) { drawDirect(x, y, width, height, type); return; } CacheKey newKey = CacheKey(this, width, height, type); cached = getFromCache(newKey); // If we didn't find a cached widgetskin, let's generate one and save it in the cache. if(!cached) { // set malloc handler to null so that we can catch if we're out of heap and write directly to the screen then. #ifndef MOSYNC_NATIVE malloc_handler mh = set_malloc_handler(NULL); #endif int *data = new int[width*height]; if(!data) { drawDirect(x, y, width, height, type); return; } #ifndef MOSYNC_NATIVE set_malloc_handler(mh); #endif drawToData(data, 0, 0, width, height, type); CacheElement cacheElem; flushCacheUntilNewImageFits(width*height); cacheElem.image = maCreatePlaceholder(); if(maCreateImageRaw(cacheElem.image,data,EXTENT(width,height),1)!=RES_OK) { maPanic(1, "Could not create raw image"); } delete data; cacheElem.lastUsed = maGetMilliSecondCount(); cached = cacheElem.image; addToCache(newKey, cacheElem); } // Draw the cached widgetskin. Gfx_drawImage(cached, x, y); }
int MAMain() { set_malloc_handler(nil); startTime = maGetMilliSecondCount(); //srand(maTime()); //urand(); //urand(); allocHalf(0); while(1) { allocHalf(3); freeHalf(0); allocHalf(0); freeHalf(3); } FREEZE; }
static void install_stdmalloc_hooks() { set_malloc_handler(std_malloc_handler); }