/******************************************************************************* * Function Name : ReleaseView * Returns : true if no error occured * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool CImage::ReleaseView() { // Cleanup: destroy OpenVG images vgDestroyImage(m_avgImage[0]); m_avgImage[0] = 0; vgDestroyImage(m_avgImage[1]); m_avgImage[1] = 0; m_PrintVG.Terminate(); return true; }
static void draw(void) { const VGint w = 48; VGImage img1, img2; VGint x, y; vgSetfv(VG_CLEAR_COLOR, 4, white); vgClear(0, 0, window_width(), window_height()); img1 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); img2 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); x = 5; y = (window_height() - w) / 2; /* test vgSetPixels */ vgSetfv(VG_CLEAR_COLOR, 4, red); vgClearImage(img1, 0, 0, w, w / 2); vgSetfv(VG_CLEAR_COLOR, 4, black); vgClearImage(img1, 0, w / 2, w, w / 2); vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgDrawImage */ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(x, y); vgDrawImage(img1); /* test vgGetPixels */ vgGetPixels(img1, 0, 0, x, y, w, w); x += w + 5; vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgCopyImage */ vgCopyImage(img2, 0, 0, img1, 0, 0, w, w, VG_FALSE); vgSetPixels(x, y, img2, 0, 0, w, w); /* vgCopyPixels */ vgCopyPixels(x + w + 5, y, x, y, w, w); vgDestroyImage(img1); vgDestroyImage(img2); }
static void vg_copy_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch) { vg_t *vg = (vg_t*)data; if (vg->mEglImageBuf) { EGLImageKHR img = 0; bool new_egl = vg->driver->write_egl_image(frame, width, height, pitch, (vg->mTexType == VG_sXRGB_8888), 0, &img); rarch_assert(img != EGL_NO_IMAGE_KHR); if (new_egl) { vgDestroyImage(vg->mImage); vg->mImage = pvgCreateEGLImageTargetKHR((VGeglImageKHR) img); if (!vg->mImage) { RARCH_ERR("[VG:EGLImage] Error creating image: %08x\n", vgGetError()); exit(2); } vg->last_egl_image = img; } } else { vgImageSubData(vg->mImage, frame, pitch, vg->mTexType, 0, 0, width, height); } }
void QVGImagePool::releaseImage(QVGPixmapData *data, VGImage image) { // Very simple strategy at the moment: just destroy the image. if (data) removeFromLRU(data); vgDestroyImage(image); }
/******************************************************************************* * Function Name : ReleaseView * Returns : true if no error occured * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool CChildImage::ReleaseView() { // Cleanup: destroy OpenVG image. vgDestroyImage(m_vgImage); m_vgImage = 0; //Destroy the children as well otherwise the memory isn't reclaimed vgDestroyImage(m_avgChildImages[0]); m_avgChildImages[0] = 0; vgDestroyImage(m_avgChildImages[1]); m_avgChildImages[1] = 0; m_PrintVG.Terminate(); return true; }
/** @SYMTestCaseID GRAPHICS-EGL-0129 @SYMTestPriority 1 @SYMPREQ 39 @SYMREQ See SGL.GT0386.401 document @SYMTestCaseDesc Any attemp to create a VGImage from a bad EGLImage handle has to fail. @SYMTestActions Create a reference Bitmap Create and fully construct an RSgImage object having the same content as the reference bitmap • Set the iUsage bit to ESgUsageBitOpenVgImage Pass the RSgImage object into eglCreateImageKHR() with • The target parameter set to EGL_NATIVE_PIXMAP_KHR • Use the current display and EGL_NO_CONTEXT • Use a NULL attr_list Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR. Create a surface and a current context. Destroy the EGLImage but retain the handle value. Try to create a VGImage from this invalid handle. Check that the error VG_ILLEGAL_ARGUMENT_ERROR is raised. Check for memory and handle leaks. @SYMTestExpectedResults vgCreateImageTargetKHR raises a VG_ILLEGAL_ARGUMENT_ERROR error. Check for memory and handle leaks. */ TVerdict CEglTest_EGL_Image_VGImage_From_Invalid_EGLHandle::doTestStepL() { SetTestStepID(_L("GRAPHICS-EGL-0129")); INFO_PRINTF1(_L("CEglTest_VGImage_From_Invalid_EGLHandle::doTestStepL")); TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image); if(!ret) { // The extension is not supported RecordTestResultL(); CloseTMSGraphicsStep(); return TestStepResult(); } // This test is performed for default pixel format PrintUsedPixelConfiguration(); // Create display object GetDisplayL(); CreateEglSessionL(); iEglSess->InitializeL(); iEglSess->OpenSgDriverL(); INFO_PRINTF1(_L("Creating one RSgImage")); TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize); #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE imageInfo.iCpuAccess = ESgCpuAccessReadWrite; #endif RSgImage sgImage; CleanupClosePushL(sgImage); ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone); INFO_PRINTF1(_L("Creating one EGLImage from it")); EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue); ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR); //Create a Surface and Link it to a Context bound to OpenVG TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat); TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize); iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly); INFO_PRINTF1(_L("Destroying the EGLImage but retain the handle value")); ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR)); INFO_PRINTF1(_L("Attemptimg to create a VGImage from an invalid handle")); VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR); ASSERT_VG_TRUE(vgImage == VG_INVALID_HANDLE); ASSERT_TRUE(vgGetError()==VG_ILLEGAL_ARGUMENT_ERROR); vgDestroyImage(vgImage); ASSERT_TRUE(vgGetError()==VG_BAD_HANDLE_ERROR); //cleanup CleanupStack::PopAndDestroy(&sgImage); CleanAll(); RecordTestResultL(); CloseTMSGraphicsStep(); return TestStepResult(); }
// makeimage makes an image from a raw raster of red, green, blue, alpha values void makeimage(VGfloat x, VGfloat y, int w, int h, VGubyte * data) { unsigned int dstride = w * 4; VGImageFormat rgbaFormat = VG_sABGR_8888; VGImage img = vgCreateImage(rgbaFormat, w, h, VG_IMAGE_QUALITY_BETTER); vgImageSubData(img, (void *)data, dstride, rgbaFormat, 0, 0, w, h); vgSetPixels(x, y, img, 0, 0, w, h); vgDestroyImage(img); }
Weather::~Weather() { if (doc_) { xmlFreeDoc(doc_); } if (icon_ != VG_INVALID_HANDLE) { vgDestroyImage(icon_); } }
int mouse_close() { close(mouse_fd); restore_pixels(CursorBuffer); // not strictly necessary as display will be closed vgDestroyImage(CursorBuffer); // tidy up memory finish(); // Graphics cleanup return 1; }
void QVGPixmapDropShadowFilter::draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const { if (src.isNull()) return; if (src.pixmapData()->classId() != QPixmapData::OpenVGClass) { // The pixmap data is not an instance of QVGPixmapData, so fall // back to the default drop shadow filter implementation. QPixmapDropShadowFilter::draw(painter, dest, src, srcRect); return; } QVGPixmapData *pd = static_cast<QVGPixmapData *>(src.pixmapData()); VGImage srcImage = pd->toVGImage(); if (srcImage == VG_INVALID_HANDLE) return; QSize size = pd->size(); VGImage dstImage = QVGImagePool::instance()->createTemporaryImage (VG_A_8, size.width(), size.height(), VG_IMAGE_QUALITY_FASTER, pd); if (dstImage == VG_INVALID_HANDLE) return; // Clamp the radius range. We divide by 2 because the OpenVG blur // is "too blurry" compared to the default raster implementation. VGfloat maxRadius = VGfloat(vgGeti(VG_MAX_GAUSSIAN_STD_DEVIATION)); VGfloat radiusF = VGfloat(blurRadius()) / 2.0f; if (radiusF < 0.001f) radiusF = 0.001f; else if (radiusF > maxRadius) radiusF = maxRadius; // Blur the blackened source image. vgGaussianBlur(dstImage, srcImage, radiusF, radiusF, VG_TILE_PAD); VGImage child = VG_INVALID_HANDLE; QRect srect; if (srcRect.isNull() || (srcRect.topLeft().isNull() && srcRect.size() == size)) { child = dstImage; srect = QRect(0, 0, size.width(), size.height()); } else { srect = srcRect.toRect(); child = vgChildImage(dstImage, srect.x(), srect.y(), srect.width(), srect.height()); } qt_vg_drawVGImageStencil(painter, dest + offset(), child, color()); if(child != dstImage) vgDestroyImage(child); QVGImagePool::instance()->releaseImage(0, dstImage); // Now draw the actual pixmap over the top. painter->drawPixmap(dest, src, srect); }
void QVGPixmapData::destroyImages() { if (inImagePool) { QVGImagePool *pool = QVGImagePool::instance(); if (vgImage != VG_INVALID_HANDLE) pool->releaseImage(this, vgImage); if (vgImageOpacity != VG_INVALID_HANDLE) pool->releaseImage(this, vgImageOpacity); } else { if (vgImage != VG_INVALID_HANDLE) vgDestroyImage(vgImage); if (vgImageOpacity != VG_INVALID_HANDLE) vgDestroyImage(vgImageOpacity); } vgImage = VG_INVALID_HANDLE; vgImageOpacity = VG_INVALID_HANDLE; inImagePool = false; }
//------------------------------------------------------------------------------ void term_free(tTermState * ts) { if(ts->image != 0) { vgDestroyImage(ts->image); ts->image = 0; free(ts->term_vbuff); } }
void CEglTest_EGL_Image_Multi_Thread_Parallel::doThreadFunctionL(TInt aIdx) { INFO_PRINTF2(_L("CEglTest_EGL_Image_Multi_Thread_Parallel::doThreadFunctionL, Thread %d"),aIdx); GetDisplayL(); CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, aIdx); eglSess->InitializeL(); eglSess->OpenSgDriverL(); // create a reference bitmap (we give index 7, as there's only 1 image in this test case) TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(KDefaultSourceFormat); CFbsBitmap* bitmap = eglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7); CleanupStack::PushL(bitmap); // Create an RSgImage INFO_PRINTF2(_L("Thread %d, Creating a RSgImage having the reference bitmap's content"),aIdx); TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(KDefaultSourceFormat, KPixmapSize); RSgImage rSgImageLocal; CleanupClosePushL(rSgImageLocal); ASSERT_EQUALS(rSgImageLocal.Create(imageInfo,bitmap->DataAddress(),bitmap->DataStride()), KErrNone); INFO_PRINTF2(_L("Thread %d, Creating an EGLImage from the shared RSgImage"),aIdx); EGLImageKHR eglImageLocal = eglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &rSgImageLocal, KEglImageAttribsPreservedTrue); ASSERT_EGL_TRUE(eglImageLocal != EGL_NO_IMAGE_KHR); CleanupStack::PopAndDestroy(&rSgImageLocal); //transferring ownership of the buffer to the EGLImage CleanupStack::PopAndDestroy(bitmap); INFO_PRINTF2(_L("Thread %d, Creating a Surface and a Context bound to OpenVG"),aIdx); TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(KDefaultSurfaceFormat); TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize); // Create a pixmap surface matching the native image pixel format eglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2,CTestEglSession::EResourceCloseSgImageEarly); INFO_PRINTF2(_L("Thread %d, Creating one VGImage from the EGLImage"),aIdx); VGImage vgImageLocal = eglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImageLocal); ASSERT_VG_TRUE(vgImageLocal != VG_INVALID_HANDLE); ASSERT_EGL_TRUE(eglSess->DestroyEGLImage(iDisplay, eglImageLocal)); // Copy the source VGImage to the surface vgSetPixels(0, 0, vgImageLocal, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight); ASSERT_TRUE(vgGetError()==VG_NO_ERROR); eglWaitClient(); // destroy VGImage vgDestroyImage(vgImageLocal); ASSERT_TRUE(vgGetError()==VG_NO_ERROR); // we can now compare the VgImage to the one we would expect for this particular thread CFbsBitmap* refBitmap = eglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7); CleanupStack::PushL(refBitmap); eglSess->CheckVgDrawingL(KDefaultSurfaceFormat, refBitmap); CleanupStack::PopAndDestroy(refBitmap); INFO_PRINTF2(_L("Drawing successful, Thread %d"),aIdx); // cleanup eglSess->CloseSgDriver(); CleanupStack::PopAndDestroy(eglSess); }
int render(int width, int height) { static DWORD startTick =0; static DWORD frames = 0; VGImage image; char buf[256]; if((startTick == 0)||(frames > 50)) { if(frames > 50) frames = 0; startTick = GetTickCount(); frames++; } else { sprintf(buf, "fps:%2.2f frames/sec \n", (float)(frames++)*1000/(GetTickCount() - startTick)); OutputDebugString(buf); } if(pReadFile == NULL) { pReadFile = fopen("test.rgb","rb"); if(pReadFile) fseek(pReadFile, 0 , SEEK_SET); } if(pReadFile && (feof(pReadFile))) fseek(pReadFile, 0 , SEEK_SET); if(pReadFile) fread(pBuff, sizeof(BYTE),SRC_WIDTH*SRC_HEIGHT*2,pReadFile); image = vgCreateImage( VG_sRGB_565, SRC_WIDTH, SRC_HEIGHT, VG_IMAGE_QUALITY_BETTER ); if(image == NULL) return -1; vgImageSubData( image, pBuff, SRC_WIDTH*2, VG_sRGB_565, 0, 0, SRC_WIDTH, SRC_HEIGHT); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgScale((VGfloat)width/SRC_WIDTH, (VGfloat)height/SRC_HEIGHT); vgTranslate(SRC_WIDTH, SRC_HEIGHT); vgRotate(180.0f); vgDrawImage( image ); vgDestroyImage( image ); if ( vgGetError() == VG_NO_ERROR ) eglSwapBuffers( egldisplay, eglsurface ); return 0; }
//------------------------------------------------------------------------------ void free_boing() { int frame = 0; do { if(boingAnim[frame].image != -1) { vgDestroyImage(boingAnim[frame].image); boingAnim[frame].image= -1; } } while (boingAnim[++frame].image == -2); }
void QVGEGLWindowSurfaceVGImage::beginPaint(QWidget *widget) { QEglContext *context = ensureContext(widget); if (context) { if (recreateBackBuffer || backBufferSurface == EGL_NO_SURFACE) { // Create a VGImage object to act as the back buffer // for this window. We have to create the VGImage with a // current context, so activate the main surface for the window. context->makeCurrent(mainSurface()); recreateBackBuffer = false; if (backBufferSurface != EGL_NO_SURFACE) { eglDestroySurface(QEgl::display(), backBufferSurface); backBufferSurface = EGL_NO_SURFACE; } if (backBuffer != VG_INVALID_HANDLE) { vgDestroyImage(backBuffer); } VGImageFormat format = qt_vg_config_to_vg_format(context); backBuffer = vgCreateImage (format, size.width(), size.height(), VG_IMAGE_QUALITY_FASTER); if (backBuffer != VG_INVALID_HANDLE) { // Create an EGL surface for rendering into the VGImage. backBufferSurface = eglCreatePbufferFromClientBuffer (QEgl::display(), EGL_OPENVG_IMAGE, (EGLClientBuffer)(backBuffer), context->config(), NULL); if (backBufferSurface == EGL_NO_SURFACE) { vgDestroyImage(backBuffer); backBuffer = VG_INVALID_HANDLE; } } } if (backBufferSurface != EGL_NO_SURFACE) context->makeCurrent(backBufferSurface); else context->makeCurrent(mainSurface()); isPaintingActive = true; } }
void QVGPixmapBlurFilter::draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const { if (src.isNull()) return; if (src.pixmapData()->classId() != QPixmapData::OpenVGClass) { // The pixmap data is not an instance of QVGPixmapData, so fall // back to the default blur filter implementation. QPixmapBlurFilter::draw(painter, dest, src, srcRect); return; } QVGPixmapData *pd = static_cast<QVGPixmapData *>(src.pixmapData()); VGImage srcImage = pd->toVGImage(); if (srcImage == VG_INVALID_HANDLE) return; QSize size = pd->size(); VGImage dstImage = QVGImagePool::instance()->createTemporaryImage (VG_sARGB_8888_PRE, size.width(), size.height(), VG_IMAGE_QUALITY_FASTER, pd); if (dstImage == VG_INVALID_HANDLE) return; // Clamp the radius range. We divide by 2 because the OpenVG blur // is "too blurry" compared to the default raster implementation. VGfloat maxRadius = VGfloat(vgGeti(VG_MAX_GAUSSIAN_STD_DEVIATION)); VGfloat radiusF = VGfloat(radius()) / 2.0f; if (radiusF < 0.001f) radiusF = 0.001f; else if (radiusF > maxRadius) radiusF = maxRadius; vgGaussianBlur(dstImage, srcImage, radiusF, radiusF, VG_TILE_PAD); VGImage child = VG_INVALID_HANDLE; if (srcRect.isNull() || (srcRect.topLeft().isNull() && srcRect.size() == size)) { child = dstImage; } else { QRect src = srcRect.toRect(); child = vgChildImage(dstImage, src.x(), src.y(), src.width(), src.height()); } qt_vg_drawVGImage(painter, dest, child); if(child != dstImage) vgDestroyImage(child); QVGImagePool::instance()->releaseImage(0, dstImage); }
void QVGPixmapData::destroyImages() { if (inImagePool) { QVGImagePool *pool = QVGImagePool::instance(); if (vgImage != VG_INVALID_HANDLE) pool->releaseImage(this, vgImage); if (vgImageOpacity != VG_INVALID_HANDLE) pool->releaseImage(this, vgImageOpacity); } else { if (vgImage != VG_INVALID_HANDLE) vgDestroyImage(vgImage); if (vgImageOpacity != VG_INVALID_HANDLE) vgDestroyImage(vgImageOpacity); } vgImage = VG_INVALID_HANDLE; vgImageOpacity = VG_INVALID_HANDLE; inImagePool = false; #if defined(Q_OS_SYMBIAN) releaseNativeImageHandle(); #endif }
static void vg_es_deinit(EGLmanager *eglman) { // Destroy GL eglDestroyImageKHR(eglman->dpy, eglman->egl_image); eglBindAPI(EGL_OPENGL_ES_API); eglMakeCurrent(eglman->dpy, eglman->pbuf_surface, eglman->pbuf_surface, eglman->es_ctx); glDeleteTextures(1, &eglman->texture); glBindTexture(GL_TEXTURE_2D, 0); // Destroy VG eglBindAPI(EGL_OPENVG_API); eglMakeCurrent(eglman->dpy, eglman->win_surface, eglman->win_surface, eglman->vg_ctx); vgDestroyImage(eglman->vg_image); }
void TiledImageOpenVG::destroyTiles() { makeCompatibleContextCurrent(); Vector<VGImage>::const_iterator it = m_tiles.begin(); Vector<VGImage>::const_iterator end = m_tiles.end(); for (; it != end; ++it) { if (*it != VG_INVALID_HANDLE) vgDestroyImage(*it); } ASSERT_VG_NO_ERROR(); m_tiles.fill(VG_INVALID_HANDLE); }
static void rpi_render_message(rpi_t *rpi, const char *msg) { free(rpi->mLastMsg); rpi->mLastMsg = strdup(msg); if (rpi->mMsgLength) { while (--rpi->mMsgLength) vgClearGlyph(rpi->mFont, rpi->mMsgLength); vgClearGlyph(rpi->mFont, 0); } struct font_output_list out; font_renderer_msg(rpi->mFontRenderer, msg, &out); struct font_output *head = out.head; while (head) { if (rpi->mMsgLength >= 1024) break; VGfloat origin[2], escapement[2]; VGImage img; escapement[0] = head->advance_x; escapement[1] = head->advance_y; origin[0] = -head->char_off_x; origin[1] = -head->char_off_y; img = vgCreateImage(VG_A_8, head->width, head->height, VG_IMAGE_QUALITY_NONANTIALIASED); // flip it for (unsigned i = 0; i < head->height; i++) vgImageSubData(img, head->output + head->pitch * i, head->pitch, VG_A_8, 0, head->height - i - 1, head->width, 1); vgSetGlyphToImage(rpi->mFont, rpi->mMsgLength, img, origin, escapement); vgDestroyImage(img); rpi->mMsgLength++; head = head->next; } font_renderer_free_output(&out); for (unsigned i = 0; i < rpi->mMsgLength; i++) rpi->mGlyphIndices[i] = i; }
bool Weather::Refresh() { std::string escaped_city = city_; std::replace(escaped_city.begin(), escaped_city.end(), ' ', '+'); const std::string url = std::string("http://www.google.com/ig/api?weather=") + escaped_city; std::unique_ptr<void> context(xmlNanoHTTPOpen(url.c_str(), NULL)); if (context.get() == NULL) { fprintf(stderr, "xmlNanoHTTPOpen failed\n"); return false; } // TODO: better buffer size logic std::unique_ptr<char[]> buffer(new char[4096]); int bytes_read = xmlNanoHTTPRead(context.get(), buffer.get(), 4096); if (bytes_read == -1) { fprintf(stderr, "xmlNanoHTTPRead failed due to parameter error\n"); return false; } if (doc_) { xmlFreeDoc(doc_); doc_ = NULL; } doc_ = xmlReadMemory(buffer.get(), strlen(buffer.get()), url.c_str(), NULL, 0); if (doc_ == NULL) { fprintf(stderr, "xmlReadMemory failed\n"); return false; } if (icon_ != VG_INVALID_HANDLE) { vgDestroyImage(icon_); icon_ = VG_INVALID_HANDLE; } std::string icon_url = std::string("http://www.google.com") + EvaluateXPath("/xml_api_reply/weather/current_conditions/icon"); icon_ = ImageLoader::Load(icon_url); if (icon_ == VG_INVALID_HANDLE) { return false; } return true; }
static void vg_free(void *data) { vg_t *vg = (vg_t*)data; vgDestroyImage(vg->mImage); if (vg->mFontsOn) { vgDestroyFont(vg->mFont); vg->font_driver->free(vg->mFontRenderer); vgDestroyPaint(vg->mPaintFg); vgDestroyPaint(vg->mPaintBg); } vg->driver->destroy(); free(vg); }
QVGEGLWindowSurfaceVGImage::~QVGEGLWindowSurfaceVGImage() { destroyPaintEngine(); if (context) { if (backBufferSurface != EGL_NO_SURFACE) { // We need a current context to be able to destroy the image. // We use the shared surface because the native window handle // associated with "windowSurface" may have been destroyed already. context->makeCurrent(qt_vg_shared_surface()); context->destroySurface(backBufferSurface); vgDestroyImage(backBuffer); context->doneCurrent(); } if (windowSurface != EGL_NO_SURFACE) context->destroySurface(windowSurface); qt_vg_destroy_context(context, QInternal::Widget); } }
static void vg_free(void *data) { vg_t *vg = (vg_t*)data; if (!vg) return; vgDestroyImage(vg->mImage); if (vg->mFontsOn) { vgDestroyFont(vg->mFont); vg->font_driver->free(vg->mFontRenderer); vgDestroyPaint(vg->mPaintFg); vgDestroyPaint(vg->mPaintBg); } gfx_ctx_free(vg); free(vg); }
int main() { int width, height, cursorx, cursory, cbsize; init(&width, &height); // Graphics initialization cursorx = width / 2; cursory = height / 2; cbsize = (CUR_SIZ * 2) + 1; VGImage CursorBuffer = vgCreateImage(VG_sABGR_8888, cbsize, cbsize, VG_IMAGE_QUALITY_BETTER); if (mouseinit(width, height) != 0) { fprintf(stderr, "Unable to initialize the mouse\n"); exit(1); } Start(width, height); // Start the picture Background(0, 0, 0); // Black background Fill(44, 77, 232, 1); // Big blue marble Circle(width / 2, 0, width); // The "world" Fill(255, 255, 255, 1); // White text TextMid(width / 2, height / 2, "hello, world", SerifTypeface, width / 10); // Greetings End(); // update picture // MAIN LOOP while (left_count < 2) { // Loop until the left mouse button pressed & released // if the mouse moved... if (mouse.x != cursorx || mouse.y != cursory) { restoreCursor(CursorBuffer); cursorx = mouse.x; cursory = mouse.y; saveCursor(CursorBuffer, cursorx, cursory, width, height, CUR_SIZ); circleCursor(cursorx, cursory, width, height, CUR_SIZ); End(); // update picture } } restoreCursor(CursorBuffer); // not strictly necessary as display will be closed vgDestroyImage(CursorBuffer); // tidy up memory finish(); // Graphics cleanup exit(0); }
COpenVGHandleStore::~COpenVGHandleStore() { TInt handleListCount = iHandles.Count(); for (TInt i = 0; i < handleListCount; i++) { if (iHandles[i].iVGHandle) { switch (iHandles[i].iHandleType) { case TLVVGHandlePair::EVGPath: vgDestroyPath(iHandles[i].iVGHandle); break; case TLVVGHandlePair::EVGPaint: vgDestroyPaint(iHandles[i].iVGHandle); break; case TLVVGHandlePair::EVGImage: vgDestroyImage(iHandles[i].iVGHandle); break; } } } iHandles.Close(); }
static void rpi_free(void *data) { rpi_t *rpi = (rpi_t*)data; vgDestroyImage(rpi->mImage); #ifdef HAVE_FREETYPE if (rpi->mFontsOn) { vgDestroyFont(rpi->mFont); font_renderer_free(rpi->mFontRenderer); vgDestroyPaint(rpi->mPaintFg); vgDestroyPaint(rpi->mPaintBg); } #endif // Release EGL resources eglMakeCurrent(rpi->mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface(rpi->mDisplay, rpi->mSurface); eglDestroyContext(rpi->mDisplay, rpi->mContext); eglTerminate(rpi->mDisplay); free(rpi); }
void SubtitleRenderer::load_glyph(char32_t codepoint) { VGfloat escapement[2]{}; auto load_glyph_internal = [&](FT_Face ft_face, VGFont vg_font, bool border) { try { auto glyph_index = FT_Get_Char_Index(ft_face, codepoint); ENFORCE(!FT_Load_Glyph(ft_face, glyph_index, FT_LOAD_NO_HINTING)); FT_Glyph glyph; ENFORCE(!FT_Get_Glyph(ft_face->glyph, &glyph)); SCOPE_EXIT {FT_Done_Glyph(glyph);}; if (border) ENFORCE(!FT_Glyph_StrokeBorder(&glyph, ft_stroker_, 0, 1)); ENFORCE(!FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, NULL, 1)); FT_BitmapGlyph bit_glyph = (FT_BitmapGlyph) glyph; FT_Bitmap& bitmap = bit_glyph->bitmap; VGImage image{}; VGfloat glyph_origin[2]{}; if (bitmap.width > 0 && bitmap.rows > 0) { constexpr VGfloat blur_stddev = 0.6; const int padding = static_cast<int>(3*blur_stddev + 0.5); const int image_width = bitmap.width + padding*2; const int image_height = bitmap.rows + padding*2; image = vgCreateImage(VG_A_8, image_width, image_height, VG_IMAGE_QUALITY_NONANTIALIASED); assert(image); if (bitmap.pitch > 0) { vgImageSubData(image, bitmap.buffer + bitmap.pitch*(bitmap.rows-1), -bitmap.pitch, VG_A_8, padding, padding, bitmap.width, bitmap.rows); assert(!vgGetError()); } else { vgImageSubData(image, bitmap.buffer, bitmap.pitch, VG_A_8, padding, padding, bitmap.width, bitmap.rows); assert(!vgGetError()); } auto softened_image = vgCreateImage(VG_A_8, image_width, image_height, VG_IMAGE_QUALITY_NONANTIALIASED); assert(image); // Even out hard and soft edges vgGaussianBlur(softened_image, image, blur_stddev, blur_stddev, VG_TILE_FILL); assert(!vgGetError()); vgDestroyImage(image); assert(!vgGetError()); image = softened_image; glyph_origin[0] = static_cast<VGfloat>(padding - bit_glyph->left); glyph_origin[1] = static_cast<VGfloat>(padding + bitmap.rows - bit_glyph->top - 1); } escapement[0] = static_cast<VGfloat>((ft_face->glyph->advance.x + 32) / 64); escapement[1] = 0; vgSetGlyphToImage(vg_font, codepoint, image, glyph_origin, escapement); assert(!vgGetError()); if (image) { vgDestroyImage(image); assert(!vgGetError()); } } catch(...) { escapement[0] = 0; escapement[1] = 0; vgSetGlyphToImage(vg_font, codepoint, VG_INVALID_HANDLE, escapement, escapement); assert(!vgGetError()); } }; load_glyph_internal(ft_face_, vg_font_, false); glyphs_[codepoint].advance = escapement[0]; load_glyph_internal(ft_face_, vg_font_border_, true); }
void QSymbianVGFontGlyphCache::cacheGlyphs(QVGPaintEnginePrivate *d, QFontEngine *fontEngine, const glyph_t *g, int count) { #ifdef QT_SYMBIAN_HARDWARE_GLYPH_CACHE QFontEngineS60 *s60fontEngine = static_cast<QFontEngineS60*>(fontEngine); if (s60fontEngine->m_activeFont->TypeUid() != KCFbsFontUid) return QVGFontGlyphCache::cacheGlyphs(d, fontEngine, g, count); QVector<glyph_t> uncachedGlyphs; while (count-- > 0) { // Skip this glyph if we have already cached it before. glyph_t glyph = *g++; if (((glyph < 256) && ((cachedGlyphsMask[glyph / 32] & (1 << (glyph % 32))) != 0)) || cachedGlyphs.contains(glyph)) continue; if (!uncachedGlyphs.contains(glyph)) uncachedGlyphs.append(glyph); } if (!uncachedGlyphs.isEmpty()) { CFbsFont *cfbsFont = static_cast<CFbsFont *>(s60fontEngine->m_activeFont); RFbsGlyphDataIterator iter; int err = iter.Open(*cfbsFont, (const unsigned int*)uncachedGlyphs.constData(), uncachedGlyphs.count()); if (err == KErrNotSupported || err == KErrInUse) { // Fallback in possibly supported error cases iter.Close(); qWarning("Falling back to default QVGFontGlyphCache"); return QVGFontGlyphCache::cacheGlyphs(d, fontEngine, g, count); } for (; err == KErrNone; err = iter.Next()) { const unsigned int glyph = iter.GlyphCode(); const RSgImage& image = iter.Image(); const TOpenFontCharMetrics& metrics = iter.Metrics(); TRect glyphBounds; metrics.GetHorizBounds(glyphBounds); VGImage vgImage = sgImageToVGImage(0, image); VGfloat origin[2]; VGfloat escapement[2]; origin[0] = -glyphBounds.iTl.iX; origin[1] = glyphBounds.iBr.iY; escapement[0] = 0; escapement[1] = 0; vgSetGlyphToImage(font, glyph, vgImage, origin, escapement); vgDestroyImage(vgImage); // Add to cache if (glyph < 256) cachedGlyphsMask[glyph / 32] |= (1 << (glyph % 32)); else cachedGlyphs.insert(glyph); } iter.Close(); if (err == KErrNoMemory || err == KErrNoGraphicsMemory) qWarning("Not enough memory to cache glyph"); else if (err != KErrNotFound) qWarning("Received error %d from glyph cache", err); } #else QVGFontGlyphCache::cacheGlyphs(d, fontEngine, g, count); #endif }