void TiledImageOpenVG::detachTiles() { makeSharedContextCurrent(); // because we create new images int numTiles = m_tiles.size(); VGImage newTile, originalTile; for (int i = 0; i < numTiles; ++i) { originalTile = m_tiles.at(i); if (originalTile == VG_INVALID_HANDLE) continue; VGImageFormat format = (VGImageFormat) vgGetParameteri(originalTile, VG_IMAGE_FORMAT); VGint width = vgGetParameteri(originalTile, VG_IMAGE_WIDTH); VGint height = vgGetParameteri(originalTile, VG_IMAGE_HEIGHT); ASSERT_VG_NO_ERROR(); newTile = vgCreateImage(format, width, height, VG_IMAGE_QUALITY_FASTER); ASSERT_VG_NO_ERROR(); vgCopyImage(newTile, 0, 0, originalTile, 0, 0, width, height, VG_FALSE /* dither */); ASSERT_VG_NO_ERROR(); m_tiles.at(i) = newTile; } }
VGImage ResizeImage(VGImage src, int width, int height) { int orig_width = vgGetParameteri(src, VG_IMAGE_WIDTH); int orig_height = vgGetParameteri(src, VG_IMAGE_HEIGHT); printf("(%d, %d)\n", orig_width, orig_height); VGImage dst = vgCreateImage(VG_sABGR_8888, width, height, VG_IMAGE_QUALITY_BETTER); vgCopyImage(dst, 0, 0,src,0,0,width, height,0); return dst; }
void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) { if (type == QPixmapData::SgImage && pixmap) { #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); destroyImages(); prevSize = QSize(); vgImage = sgImageToVGImage(context, *sgImage); if (vgImage != VG_INVALID_HANDLE) { w = vgGetParameteri(vgImage, VG_IMAGE_WIDTH); h = vgGetParameteri(vgImage, VG_IMAGE_HEIGHT); d = 32; // We always use ARGB_Premultiplied for VG pixmaps. } is_null = (w <= 0 || h <= 0); source = QVolatileImage(); // readback will be done later, only when needed recreate = false; prevSize = QSize(w, h); updateSerial(); #endif } else if (type == QPixmapData::FbsBitmap && pixmap) { CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap *>(pixmap); QSize size(bitmap->SizeInPixels().iWidth, bitmap->SizeInPixels().iHeight); resize(size.width(), size.height()); source = QVolatileImage(bitmap); // duplicates only, if possible if (source.isNull()) return; if (!conversionLessFormat(source.format())) { // Here we may need to copy if the formats do not match. // (e.g. for display modes other than EColor16MAP and EColor16MU) source.beginDataAccess(); QImage::Format format = idealFormat(&source.imageRef(), Qt::AutoColor); source.endDataAccess(true); source.ensureFormat(format); } recreate = true; } else if (type == QPixmapData::VolatileImage && pixmap) { QVolatileImage *img = static_cast<QVolatileImage *>(pixmap); resize(img->width(), img->height()); source = *img; recreate = true; } else if (type == QPixmapData::NativeImageHandleProvider && pixmap) { destroyImages(); nativeImageHandleProvider = static_cast<QNativeImageHandleProvider *>(pixmap); // Cannot defer the retrieval, we need at least the size right away. createFromNativeImageHandleProvider(); } }
float Path::length() { m_path->makeCompatibleContextCurrent(); VGfloat length = vgPathLength(m_path->vgPath(), 0, vgGetParameteri(m_path->vgPath(), VG_PATH_NUM_SEGMENTS)); ASSERT_VG_NO_ERROR(); return length; }
/******************************************************************************* * Function Name : TileImageInMask * Description : This function tiles the passed in image to fill the mask layer with values *******************************************************************************/ void OVGMaskLayer::TileImageInMask(VGImage &vgImg, VGMaskOperation eOperation) { unsigned int ui32ImageWidth = vgGetParameteri(vgImg, VG_IMAGE_WIDTH); unsigned int ui32ImageHeight = vgGetParameteri(vgImg, VG_IMAGE_HEIGHT); // Tile the image in the mask for(int i32X = 0; i32X < (int) m_ui32ScreenWidth; i32X += ui32ImageWidth) { for(int i32Y = 0; i32Y < (int) m_ui32ScreenHeight; i32Y += ui32ImageHeight) { int i32W = i32X + ui32ImageWidth > m_ui32ScreenWidth ? m_ui32ScreenWidth - i32X : m_ui32ScreenWidth; int i32H = i32Y + ui32ImageHeight > m_ui32ScreenHeight ? m_ui32ScreenHeight - i32Y : m_ui32ScreenHeight; vgMask(vgImg, eOperation, i32X, i32Y, i32W, i32H); } } }
float Path::normalAngleAtLength(float length, bool& ok) { VGfloat tangentX, tangentY; m_path->makeCompatibleContextCurrent(); vgPointAlongPath(m_path->vgPath(), 0, vgGetParameteri(m_path->vgPath(), VG_PATH_NUM_SEGMENTS), length, 0, 0, &tangentX, &tangentY); ok = (vgGetError() == VG_NO_ERROR); return atan2f(tangentY, tangentX) * 180.0 / piFloat; // convert to degrees }
FloatPoint Path::pointAtLength(float length, bool& ok) { VGfloat x = 0, y = 0; m_path->makeCompatibleContextCurrent(); vgPointAlongPath(m_path->vgPath(), 0, vgGetParameteri(m_path->vgPath(), VG_PATH_NUM_SEGMENTS), length, &x, &y, 0, 0); ok = (vgGetError() == VG_NO_ERROR); return FloatPoint(x, y); }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool CChildImage::RenderScene() { //Clear the screen with the current clear color. vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight)); //Change the matrix mode to VG_MATRIX_IMAGE_USER_TO_SURFACE so we can transform the images vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); //Set the current matrix to the identiy vgLoadIdentity(); //Translate the image to the desired position vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f + 5.0f); //Draw the main image vgDrawImage(m_vgImage); //Reset the current matrix... vgLoadIdentity(); //...Perform a translation to position the first child image... int i32Height = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT); vgTranslate(PVRShellGet(prefWidth) * 0.5f - (vgGetParameteri(m_avgChildImages[1], VG_IMAGE_WIDTH) * 0.5f), PVRShellGet(prefHeight)* 0.5f - i32Height - 5.0f); //...and draw vgDrawImage(m_avgChildImages[0]); //Reset the current matrix... vgLoadIdentity(); //...Perform a translation to position the second child image... i32Height = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT) + vgGetParameteri(m_avgChildImages[1], VG_IMAGE_HEIGHT); vgTranslate(PVRShellGet(prefWidth) * 0.5f - (vgGetParameteri(m_avgChildImages[1], VG_IMAGE_WIDTH) * 0.5f), PVRShellGet(prefHeight)* 0.5f - i32Height - 10.0f); //...and draw vgDrawImage(m_avgChildImages[1]); m_PrintVG.DisplayDefaultTitle("ChildImage", "", ePVRTPrint3DLogoIMG); return true; }
//------------------------------------------------------------------------------ void term_init(tTermState * ts, float widthPer, float heightPer, int width, int height) { ts->image = 0; if(ts->image == 0) { if(width <= 0 || height <= 0) { ts->term_w = VTERM_WIDTH; ts->term_h = VTERM_HEIGHT; } else { ts->term_w = width; ts->term_h = height; } ts->term_vbuff = malloc(ts->term_w * ts->term_h * sizeof(tScrChr)); int w = (state->screen_width * widthPer); int h = (state->screen_height * heightPer); ts->image = create_image_from_buf((unsigned char *) tv_jpeg_raw_data, tv_jpeg_raw_size, w, h); term_clear(ts, VTERM_CLR); ts->tv_width = vgGetParameteri(ts->image, VG_IMAGE_WIDTH); ts->tv_height = vgGetParameteri(ts->image, VG_IMAGE_HEIGHT); ts->offsetXY.y = (ts->tv_height * .14f); ts->offsetXY.x = (ts->tv_width * .10f); ts->tvXY.x = (state->screen_width - ts->tv_width) / 2; ts->tvXY.y = (state->screen_height - ts->tv_height) / 2; ts->image_height = ts->tv_height - (ts->offsetXY.y * 2); ts->image_width = ts->tv_width - (ts->offsetXY.x * 2); ts->imageXY.x = (state->screen_width - ts->image_width) / 2; ts->imageXY.y = (state->screen_height - ts->image_height) / 2; ts->term_x_inc = ts->image_width / ts->term_w; ts->term_y_inc = ts->image_height / ts->term_h; ts->txtXY.x = ts->imageXY.x + ts->term_x_inc; ts->txtXY.y = state->screen_height - ts->imageXY.y - ts->term_y_inc * 1.5; ts->numPointFont = numPointFontMed; //med default ts->numFont = 1; //topaz font ts->term_color = 0; } }
static void append(VGPath path, int numSegments, const VGubyte* segments, int numCoordinates, const VGfloat* coordinates) { MK_ASSERT(numCoordinates <= 26); VGPathDatatype datatype = (VGPathDatatype)vgGetParameteri(path, VG_PATH_DATATYPE); VGfloat scale = vgGetParameterf(path, VG_PATH_SCALE); VGfloat bias = vgGetParameterf(path, VG_PATH_BIAS); switch(datatype) { case VG_PATH_DATATYPE_S_8: { int8_t data[26]; for(int i=0;i<numCoordinates;i++) data[i] = (int8_t)floor((coordinates[i] - bias) / scale + 0.5f); //add 0.5 for correct rounding vgAppendPathData(path, numSegments, segments, data); break; } case VG_PATH_DATATYPE_S_16: { int16_t data[26]; for(int i=0;i<numCoordinates;i++) data[i] = (int16_t)floor((coordinates[i] - bias) / scale + 0.5f); //add 0.5 for correct rounding vgAppendPathData(path, numSegments, segments, data); break; } case VG_PATH_DATATYPE_S_32: { int32_t data[26]; for(int i=0;i<numCoordinates;i++) data[i] = (int32_t)floor((coordinates[i] - bias) / scale + 0.5f); //add 0.5 for correct rounding vgAppendPathData(path, numSegments, segments, data); break; } default: { MK_ASSERT(datatype == VG_PATH_DATATYPE_F); float data[26]; for(int i=0;i<numCoordinates;i++) data[i] = (float)((coordinates[i] - bias) / scale); vgAppendPathData(path, numSegments, segments, data); break; } } }
/******************************************************************************* * Function Name : InitView * Returns : true if no error occured * Description : Code in InitView() will be called by the Shell upon a change * in the rendering context. * Used to initialise variables that are dependent on the rendering * context (e.g. textures, vertex buffers, etc.) *******************************************************************************/ bool CChildImage::InitView() { //Create an image m_vgImage = vgCreateImage(VG_sRGBA_8888, IMG_SIZE, IMG_SIZE, VG_IMAGE_QUALITY_NONANTIALIASED); /* Populate the image from memory. A 32bit integer array (8bits per component) is created and populated. */ VGuint* pui32ImgData = new VGuint[IMG_SIZE*IMG_SIZE]; for(int i = 0; i < IMG_SIZE; ++i) { for(int j = 0; j < IMG_SIZE; ++j) { // Fills the data with a fancy pattern if ( ((i*j)/8) % 2 ) pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255,255,0,255); else pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255, 255 - (j * 2), 255 - i, 255 - (i * 2)); } } /* The data in the array is then copied to the portion of the image starting at (0,0) through to (IMG_SIZE, IMG_SIZE), in this case that is the whole image. The coordinate system of the image places (0,0) at the bottom left-hand corner and (IMG_SIZE, IMG_SIZE) at the top right-hand corner. */ vgImageSubData(m_vgImage, pui32ImgData, sizeof(VGuint) * IMG_SIZE, VG_sRGBA_8888, 0, 0, IMG_SIZE, IMG_SIZE); // Delete the image data as it is now in OpenVG memory delete[] pui32ImgData; pui32ImgData = 0; //Create child images /* The first child is a child of m_vgImage and is made up of the region of m_vgImage from (0,0) to (IMG_SIZE / 2, IMG_SIZE / 2). Note: The area specified must be in the bounds of the parent. */ m_avgChildImages[0] = vgChildImage(m_vgImage, 0, 0, (VGint) (IMG_SIZE * 0.5), (VGint) (IMG_SIZE * 0.5)); //The second child is a clone of the first child. //Get the dimensions of the first child.. int i32ChildWidth = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_WIDTH); int i32ChildHeight= vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT); //..and use them to define the region for creating the second child. m_avgChildImages[1] = vgChildImage(m_avgChildImages[0], 0, 0, i32ChildWidth, i32ChildHeight); /* Clear a small portion of the bottom left-hand corner of m_avgChildImages[0] to red. This change will be seen in all relatives of m_avgChildImages[0], reason being they all share the same physical memory. Note: When clearing you specify the coordinate you want to start from and then how many pixels across and up you want to clear. */ VGfloat afClearColour[] = {1.0f, 0.0f, 0.0f, 1.0f}; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); vgClearImage(m_avgChildImages[0], 0, 0, 10, 10); //Set the clear colour for clearing the sceen afClearColour[0] = 0.6f; afClearColour[1] = 0.8f; afClearColour[2] = 1.0f; afClearColour[3] = 1.0f; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight)); return true; }
LOCAL_C void LaunchClientProcessL() { __UHEAP_MARK; RProcess::Rendezvous(KErrNone); RSemaphore sem; User::LeaveIfError(sem.OpenGlobal(KEglStressTest)); CleanupClosePushL(sem); //Access data passed from the main process TStressProcessInfo info; TPckg<TStressProcessInfo> pckgInfo(info); User::LeaveIfError(User::GetDesParameter(KMultiProcessSlot, pckgInfo)); //Create RSgDriver and open the image RSgDriver driver; User::LeaveIfError(driver.Open()); CleanupClosePushL(driver); RSgImage image; User::LeaveIfError(image.Open(info.iSgId)); CleanupClosePushL(image); EGLDisplay display; EGL_LEAVE_NULL(display, eglGetDisplay(EGL_DEFAULT_DISPLAY)); EGL_LEAVE_ERROR(eglInitialize(display, NULL, NULL)); EGL_LEAVE_ERROR(eglBindAPI(EGL_OPENVG_API)); //Initialise to remove arm compiler warnings EGLConfig config = 0; EGLContext context = EGL_NO_CONTEXT; EGLSurface surface = EGL_NO_SURFACE; if(info.iTestType == EStressRead) { TSgImageInfo sginfo; User::LeaveIfError(image.GetInfo(sginfo)); //Create an independant pixmap surface on which to copy the vgimage RSgImage image2; User::LeaveIfError(image2.Create(sginfo, NULL, NULL)); CleanupClosePushL(image2); ChooseConfigAndCreateContextL(display, context, config, image2, KStressTestChildAppPanic, info.iAlphaPre); EGL_LEAVE_NULL(surface, CreatePixmapSurfaceL(display, config, image2, info.iAlphaPre)); CleanupStack::PopAndDestroy(&image2); } else { ChooseConfigAndCreateContextL(display, context, config, image, KStressTestChildAppPanic, info.iAlphaPre); EGL_LEAVE_NULL(surface, CreatePixmapSurfaceL(display, config, image, info.iAlphaPre)); } EGL_LEAVE_ERROR(eglMakeCurrent(display, surface, surface, context)); VGImage vgImage; GenerateVgImageL(display, &image, vgImage); /* Create and install the active scheduler */ CActiveScheduler* sched = new(ELeave) CActiveScheduler; CActiveScheduler::Install(sched); CleanupStack::PushL(sched); TInt width = vgGetParameteri(vgImage, VG_IMAGE_WIDTH); VgLeaveIfErrorL(); TInt height = vgGetParameteri(vgImage, VG_IMAGE_HEIGHT); VgLeaveIfErrorL(); VGImageFormat format = static_cast<VGImageFormat>(vgGetParameteri(vgImage, VG_IMAGE_FORMAT)); VgLeaveIfErrorL(); TBool testPass = ETrue; CTReadWriteChild* painter = CTReadWriteChild::NewL(vgImage, width, height, info.iByteSize, format, info.iTestType, testPass); CleanupStack::PushL(painter); painter->After(TTimeIntervalMicroSeconds32(0)); //Data access is synchronised from the main process sem.Wait(); sched->Start(); if(testPass == EFalse) { // Leave with a 'known' test error so that we can catch this particular failure User::Leave(KTestStressUnexpectedPixelError); } CleanupStack::PopAndDestroy(5, &sem); //painter, sched, image, driver, sem __UHEAP_MARKEND; }
bool Path::hasCurrentPoint() const { m_path->makeCompatibleContextCurrent(); return vgGetParameteri(m_path->vgPath(), VG_PATH_NUM_SEGMENTS) > 0; }
bool Path::isEmpty() const { m_path->makeCompatibleContextCurrent(); return !vgGetParameteri(m_path->vgPath(), VG_PATH_NUM_SEGMENTS); }
TInt CHuiVg10VgImageBinder::BindClientBuffer(TUint aBuffer) { // This returns the index of the corresponding aBuffer stored in the array. // If KErrNotFound is returned,it indicates that this is the first BindClientBuffer // call for aBuffer and hence eglPbufferfromclient has to be created for this buffer TInt bufferIndex = iGroupOpacityImages.Find(aBuffer); // This check mandates that iSavedDraw/Read Surfaces are stored only for the first time // (i.e., before any pbufferfromclient surfaces are created).This is because when there are concurrent // BindToImageL calls,we would eventually be losing track of the base window surface on // top of which the vgImage has to be drawn. if(iGroupOpacityImages.Count() == 0) { // Save current context and surfaces iSavedContext = eglGetCurrentContext(); iSavedDrawSurface = eglGetCurrentSurface(EGL_DRAW); iSavedReadSurface = eglGetCurrentSurface(EGL_READ); } // Buffer Index would be KErrNotFound if this is the first BindClientBuffer call for aBuffer // (there would be multiple BindClientBuffer calls for an aBuffer) and hence corresponding // pbufferfromclient surface has to be created for that aBuffer. if(bufferIndex == KErrNotFound) { // Check whether we should use the Alpha format bit VGImageFormat imageFormat = (VGImageFormat)vgGetParameteri(aBuffer, VG_IMAGE_FORMAT); TInt maskBit = 0; if (imageFormat == VG_sRGBA_8888_PRE) { maskBit = EGL_VG_ALPHA_FORMAT_PRE_BIT; } const TInt BITS_PER_CHANNEL = 8; // Choose an EGL config const EGLint attrs[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, EGL_SURFACE_TYPE, EGL_PBUFFER_BIT | maskBit, EGL_RED_SIZE, BITS_PER_CHANNEL, EGL_GREEN_SIZE, BITS_PER_CHANNEL, EGL_BLUE_SIZE, BITS_PER_CHANNEL, EGL_ALPHA_SIZE, BITS_PER_CHANNEL, EGL_NONE }; // Create a context TInt configCount = iRenderPlugin->EglChooseConfig(attrs); EGLConfig config = iRenderPlugin->EglConfig(0); // Create a pbuffer surface iEglPBufferSurface_Client = eglCreatePbufferFromClientBuffer(iRenderPlugin->EglDisplay(), EGL_OPENVG_IMAGE, static_cast<EGLClientBuffer>(aBuffer), // Use the param image as buffer config, NULL); if (iEglPBufferSurface_Client == EGL_NO_SURFACE) { HUI_DEBUG1(_L("CHuiVg10VgImageBinder::BindClientBuffer() - EGL Surface could not be created, eglErr: %04x"), eglGetError() ); return KErrGeneral; } iGroupOpacitySurfaces.Append(iEglPBufferSurface_Client); iGroupOpacityImages.Append(aBuffer); } // Control would go to else part indicating that this is not the first BindClientBuffer for aBuffer // and hence the corresponding eglPBufferfromClient surface could be retrieved with the bufferIndex else { iEglPBufferSurface_Client = iGroupOpacitySurfaces[bufferIndex]; } EGLContext context = iRenderPlugin->EglSharedContext(); // eglMakeCurrent with EGL_NO_SURFACE de-couples vgImage from an old eglpbufferfromclient surface. // Otherwise in a multiple BindClientBuffer scenario for the same vgImage, eglMakeCurrent // fails with an EGL_BAD_ACCESS error (vgimage already inuse error) eglMakeCurrent(iRenderPlugin->EglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, context); // Bind our own PBuffer surface (from VGImage) if ( eglMakeCurrent(iRenderPlugin->EglDisplay(), iEglPBufferSurface_Client, iEglPBufferSurface_Client, context ) == EGL_FALSE ) { HUI_DEBUG1(_L("CHuiVg10VgImageBinder::BindClientBuffer() - EGL Surface could not be made current, eglErr: %04x"), eglGetError()); TInt eglError = eglGetError(); return KErrGeneral; } // Alles in Ordnung! return KErrNone; }