void SdlApplication::onRender() { // Lock surface pixels. SDL_LockSurface(_screen); // Create Fog::Painter instance mapped to the SDL surface data. Fog::Painter p; // Setup image buffer for painter. Fog::ImageBits buf; buf.setData(Fog::SizeI(_screen->w, _screen->h), Fog::IMAGE_FORMAT_XRGB32, _screen->pitch, (reinterpret_cast<uint8_t*>(_screen->pixels))); // Call our paint handler. if (p.begin(buf) == Fog::ERR_OK) onPaint(p); // Never forget to call p.end(). Painting can be asynchronous and // SDL_UnlockSurface() can invalidate the surface->pixels pointer. p.end(); // Unlock surface pixels. SDL_UnlockSurface(_screen); // Flip buffer. //SDL_Flip(_screen); SDL_UpdateWindowSurface(win); }
bool loadSvgFile(Image &img, const char *path) { Fog::Logger::getGlobal()->setSeverity(100); Fog::Logger::getLocal()->setSeverity(100); size_t width = 400, height = 400; Fog::SvgDocument svg; unsigned err; if ((err=svg.readFromFile(StringW::fromAscii8(path)))) { fprintf(stderr, "Failed to load SVG %s error %05X ERR_XML_SAX_NO_DOCUMENT=%05X\n", path, err, Fog::ERR_XML_SAX_NO_DOCUMENT); return false; } Fog::SizeF size = svg.getDocumentSize(); if (size.w >= 2 && size.w <= 2048) width = size.w; if (size.h >= 2 && size.h <= 2048) height = size.h; svg.getResourceManager()->loadQueuedResources(); Fog::SizeI si; void *imgdata=malloc(width*height*4); if (!imgdata) return false; si.w = width; si.h = height; Fog::ImageBits imgbits(si, Fog::IMAGE_FORMAT_PRGB32, width*4, (unsigned char*)imgdata); Fog::Painter painter; if ((err=painter.begin(imgbits))) { fprintf(stderr, "Failed to select surface to SVG rendering %s error %05X\n", path, err); } painter.setSource(Fog::Argb32(0xFFFFFFFF)); painter.fillAll(); if ((err=svg.render(&painter))) { fprintf(stderr, "Failed to render SVG %s error %05X\n", path, err); } painter.flush(Fog::PAINTER_FLUSH_SYNC); painter.end(); load_from_pixels(img, imgdata, width, height, 4, true); free(imgdata); return true; }