Ejemplo n.º 1
0
/*******************************************************************************
 * Function Name  : DoScaleOrigin
 * Description    : Demonstrate the effect of scaling from the origin.
 *******************************************************************************/
void CTransforms::DoScaleOrigin()
{
	// Make sure we're operating on the path user-to-surface matrix
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);

	// Load Identity matrix. This clears all previous transformations
	vgLoadIdentity();

	// To be independent of screen resolution, we need to scale the
	// coordinates so everything in the range [0, 1] will be visible
	vgScale((float) PVRShellGet(prefWidth), (float) PVRShellGet(prefHeight));

	// turn time(ms) into a periodic triangle function
	int i32Zigzag = m_ui32AbsTime % 2000;

	if(i32Zigzag > 1000)
		i32Zigzag = 2000 - i32Zigzag;

	i32Zigzag = PVRT_MAX(100, PVRT_MIN(900, i32Zigzag));

	float fScaleFactor = 0.3f + (i32Zigzag * 0.0009f);

	// Scaling a scene from the origin means that objects will
	// either get pulled towards the origin or move away from it
	// along with being resized.
	vgScale(fScaleFactor, fScaleFactor);

	// draw first path
	vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH);
	// draw second path
	vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH);
}
Ejemplo n.º 2
0
void display(float interval)
{
  VGfloat cc[] = {0,0,0,1};
  
  vgSetfv(VG_CLEAR_COLOR, 4, cc);
  vgClear(0,0,testWidth(),testHeight());
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
  vgLoadIdentity();
  vgTranslate(tx, ty);
  vgScale(sx, sy);
  vgRotate(a);
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
  vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
  vgLoadIdentity();
  
  vgSetPaint(patternFill, VG_FILL_PATH);
  /*vgDrawPath(p, VG_FILL_PATH);*/
  vgDrawImage(backImage);
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  vgTranslate(tx, ty);
  vgScale(sx, sy);
  vgRotate(a);
  
  vgSetPaint(blackFill, VG_FILL_PATH | VG_STROKE_PATH);
  vgDrawPath(org, VG_FILL_PATH);
}
Ejemplo n.º 3
0
void display(float interval)
{
  VGfloat cc[] = {0,0,0,1};
  
  vgSetfv(VG_CLEAR_COLOR, 4, cc);
  vgClear(0,0,testWidth(),testHeight());
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
  vgLoadIdentity();
  vgTranslate(tx, ty);
  vgRotate(ang);
  vgScale(sx, sy);
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  
  vgSetPaint(radialFill, VG_FILL_PATH);
  vgDrawPath(p, VG_FILL_PATH);
  
  vgTranslate(tx, ty);
  vgRotate(ang);
  vgScale(sx, sy);
  
  vgSetPaint(blackFill, VG_FILL_PATH | VG_STROKE_PATH);
  vgDrawPath(radius, VG_STROKE_PATH);
  vgDrawPath(center, VG_STROKE_PATH);
  vgDrawPath(focus, VG_FILL_PATH);
}
Ejemplo n.º 4
0
/*******************************************************************************
 * Function Name  : DoScaleCentered
 * Description    : Demonstrate the effect of scaling from the centre of a
 *                  shape. Each path is transformed separately.
 *******************************************************************************/
void CTransforms::DoScaleCentered()
{
	// Make sure we're operating on the path user-to-surface matrix
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);

	// Load Identity matrix. This clears all previous transformations
	vgLoadIdentity();

	// To be independent of screen resolution, we need to scale the
	// coordinates so everything in the range [0, 1] will be visible
	vgScale((float) PVRShellGet(prefWidth), (float) PVRShellGet(prefHeight));

	// Unlike OpenGL, OpenVG does not maintain a matrix stack. So instead of
	// pushing the current matrix to the stack, we have to store it ourselves
	float afUnitMatrix[3*3];
	vgGetMatrix(afUnitMatrix);

	// turn time(ms) into a periodic triangle function
	int i32Zigzag = m_ui32AbsTime % 2000;

	if(i32Zigzag > 1000)
		i32Zigzag = 2000 - i32Zigzag;

	float fScaleFactor = 0.5f + (i32Zigzag * 0.001f);

	// Scaling a shape from its center is identical to moving it to the
	// origin, scaling it there, and moving it back where it was.
	//
	// IMPORTANT:
	// Since OpenVG right-multiplies matrices, you conceptually need to
	// call the transformation functions in backwards order.
	vgTranslate(0.5f, 0.75f);
	vgScale(fScaleFactor, fScaleFactor);
	vgTranslate(-0.5f, -0.75f);

	// draw first path
	vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH);

	// restore the unit matrix ([0, 1] visible)
	vgLoadMatrix(afUnitMatrix);

	// transformation for second path
	fScaleFactor = 2 - fScaleFactor;
	vgTranslate(0.5f, 0.25f);
	vgScale(fScaleFactor, fScaleFactor);
	vgTranslate(-0.5f, -0.25f);

	// draw second path
	vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH);
}
Ejemplo n.º 5
0
void render(int w, int h)
{
	{
		float clearColor[4] = {1,1,1,1};
		float scale = w / (tigerMaxX - tigerMinX);

		eglSwapBuffers(egldisplay, eglsurface);	//force EGL to recognize resize

		vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
		vgClear(0, 0, w, h);

		vgLoadIdentity();
                vgTranslate(w * 0.5f, h * 0.5f);
                vgRotate(rotateN);
                vgTranslate(-w * 0.5f, -h * 0.5f);
		vgScale(scale, scale);
		vgTranslate(-tigerMinX, -tigerMinY + 0.5f * (h / scale - (tigerMaxY - tigerMinY)));

		PS_render(tiger);
		assert(vgGetError() == VG_NO_ERROR);

		renderWidth = w;
		renderHeight = h;
	}
}
Ejemplo n.º 6
0
void loadTiger()
{
  int i;
  VGPath temp;
  
  temp = testCreatePath();  
  tigerPaths = (VGPath*)malloc(pathCount * sizeof(VGPath));
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgTranslate(-100,100);
  vgScale(1,-1);
  
  for (i=0; i<pathCount; ++i) {
    
    vgClearPath(temp, VG_PATH_CAPABILITY_ALL);
    vgAppendPathData(temp, commandCounts[i],
                     commandArrays[i], dataArrays[i]);
    
    tigerPaths[i] = testCreatePath();
    vgTransformPath(tigerPaths[i], temp);
  }
  
  tigerStroke = vgCreatePaint();
  tigerFill = vgCreatePaint();
  vgSetPaint(tigerStroke, VG_STROKE_PATH);
  vgSetPaint(tigerFill, VG_FILL_PATH);
  vgLoadIdentity();
  vgDestroyPath(temp);
}
Ejemplo n.º 7
0
//Display functions
void display(float interval)
{
  int i;
  const VGfloat *style;
  VGfloat clearColor[] = {1,1,1,1};
  
  if (animate) {
    ang += interval * 360 * 0.1f;
    if (ang > 360) ang -= 360;
  }
  
  vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
  vgClear(0,0,testWidth(),testHeight());
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  vgTranslate(testWidth()/2 + tx,testHeight()/2 + ty);
  vgScale(sx, sy);
  vgRotate(ang);
  
  for (i=0; i<pathCount; ++i) {
    
    style = styleArrays[i];
    vgSetParameterfv(tigerStroke, VG_PAINT_COLOR, 4, &style[0]);
    vgSetParameterfv(tigerFill, VG_PAINT_COLOR, 4, &style[4]);
    vgSetf(VG_STROKE_LINE_WIDTH, style[8]);
    vgDrawPath(tigerPaths[i], (VGint)style[9]); // Bingo!!, Draw it!! 
  }
  vgFlush();
}
Ejemplo n.º 8
0
/*******************************************************************************
 * Function Name  : DoShearOrigin
 * Description    : Demonstrate the effect of shearing from the origin.
 *******************************************************************************/
void CTransforms::DoShearOrigin()
{
	// Make sure we're operating on the path user-to-surface matrix
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);

	// Load Identity matrix. This clears all previous transformations
	vgLoadIdentity();

	// To be independent of screen resolution, we need to scale the
	// coordinates so everything in the range [0, 1] will be visible
	vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight));

	// turn time(ms) into a periodic triangle function
	int i32Zigzag = m_ui32AbsTime % 2000;

	if(i32Zigzag > 1000)
		i32Zigzag = 2000 - i32Zigzag;

	i32Zigzag = PVRT_MAX(100, PVRT_MIN(900, i32Zigzag)) - 500;

	vgShear(i32Zigzag * 0.001f, 0);

	// draw first path
	vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH);
	// draw second path
	vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH);
}
Ejemplo n.º 9
0
void OVGFont::DrawLine(VGFont &vgFont, VGint i32Size, VGuint *pStr, float fHeight, float fScale)
{
	static float fOrigin[] = {0.0f, 0.0f};

	/*
		Everytime vgDrawGlyph(s) is called the glyph(s) are drawn at the position
		defined by VG_GLYPH_ORIGIN. This value is updated after each call by the
		escapement vector defined by the glyph.

		As we don't want our text to follow any of the text previously drawn we're
		setting the glyph orign to 0,0.
	*/
	vgSetfv(VG_GLYPH_ORIGIN, 2, fOrigin);

	/*
		Using the matrix mode MATRIX_GLYPH_USER_TO_SURFACE translate and scale
		the font.
	*/
	vgLoadIdentity();
	vgTranslate(0.0f, fHeight);
	vgScale(fScale, fScale);

	/*
		Our string is only a few glyphs long so we're going to repeatedly
		draw it until the x value of the GLYPH_ORIGIN is greater than the
		scaled width.
	*/

	float fGlyphOrigin[2];
	fGlyphOrigin[0] = 0.0f;
	fGlyphOrigin[1] = 0.0f;

	float fScaledWidth = m_ui32ScreenWidth / fScale;

	while(fGlyphOrigin[0] < fScaledWidth)
	{
		/*
			Draw i32Size no of glyphs from pStr. The VG_FILL_PATH parameter
			defines how you would like the glyph (if a path) to be displayed.
			You can also have it stroked by using VG_STROKE_PATH. This parameter
			doesn't affect image based glyphs unless it's value is set to 0
			in which case no glyph (path or image based) will be drawn.

			The fourth and fifth parameters are the x and y adjustments
			for each glyph. These can be set to adjust the position of the glyphs
			drawn or can be set to NULL.

			The final parameter (set to VG_TRUE) disables or enables autohinting.
			If equal to true autohinting may be applied to alter the glyphs slightly
			to improve the render quality.
		*/
		vgDrawGlyphs(vgFont, i32Size, &pStr[0], NULL,NULL, VG_FILL_PATH, VG_TRUE);

		// Get the updated GLYPH_ORIGIN
		vgGetfv(VG_GLYPH_ORIGIN, 2, &fGlyphOrigin[0]);
	}
}
Ejemplo n.º 10
0
	// C function:: void vgScale(VGfloat sx, VGfloat sy);
	JNIEXPORT jint JNICALL
	Java_com_example_startvg_VG11_vgScale(
	  JNIEnv* env, jobject obj,
	  jfloat sx, jfloat sy){
			
			vgScale(
			(VGfloat) sx, 
			(VGfloat) sy
			);
	}
Ejemplo n.º 11
0
/****************************************************************************
** InitView() is called by PVRShell each time a rendering variable is changed
** in the Shell menu (Z-Buffer On/Off, resolution change, buffering mode...)
** In this function one should initialise all variables that are dependant on
** general rendering variables (screen mode, 3D device, etc...)
****************************************************************************/
bool CIntroducingPVRShell::InitView()
{
	/*
	Initially, the OpenVG coordinate system is based on the output resolution.
	To get a device independent coordinate system, we need to apply a
	transformation. Scaling by the output resolution means that coordinates
	between (0, 0) and (1, 1) will be visible on screen.

	It should be noted, however, that different aspect ratios usually require
	special attention regarding the layout of elements on screen.
	*/
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();
	vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight));

	/*
	Drawing shapes with OpenVG requires a path which represents a series of
	line and curve segments describing the outline of the shape. The shape
	does not need to be closed, but for now we will start with a simple
	triangle.
	First we create a path object, then we append segment and point data.
	*/
	m_vgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
							1.0f, 0.0f, 4, 3, (unsigned int)VG_PATH_CAPABILITY_ALL);

	VGubyte aui8PathSegments[4] = {
		VG_MOVE_TO_ABS,
		VG_LINE_TO_ABS,
		VG_LINE_TO_ABS,
		VG_CLOSE_PATH,
	};
	VGfloat afPoints[6] = {
			0.3f, 0.3f,
			0.7f, 0.3f,
			0.5f, 0.7f,
	};
	vgAppendPathData(m_vgPath, 4, aui8PathSegments, afPoints);

	/*
	To fill a shape, we need a paint that describes how to fill it: a gradient,
	pattern, or single colour. Here we choose a simple opaque red.
	*/
	m_vgFillPaint = vgCreatePaint();
	vgSetParameteri(m_vgFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_vgFillPaint, PVRTRGBA(255,255,170,255));

	/*
	The clear colour will be used whenever calling vgClear(). The colour is given
	as non-premultiplied sRGBA.
	*/
	VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f };
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	return true;
}
Ejemplo n.º 12
0
/*!***************************************************************************
 @Function		SetupScaleToSize
 @Input			fTargetWidth	Target width to scale to
 @Input			fTargetHeight	Target height to scale to
 @Input			bKeepAspect		Maintain the aspect ratio
 @Description	Function used to fit the artwork on the screen.
*****************************************************************************/
void CPVRTPVGObject::SetupScaleToSize(float fTargetWidth, float fTargetHeight, bool bKeepAspect)
{
	float fScaleH = fTargetWidth / m_fWidth;
	float fScaleV = fTargetHeight / m_fHeight;
	if(bKeepAspect)
	{
		fScaleH = fabs(fScaleH) < fabs(fScaleV) ? fScaleH : fScaleV;
		fScaleV = fScaleH;
	}
	vgScale(fScaleH, fScaleV);
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
/*******************************************************************************
 * Function Name  : DoTranslate
 * Description    : Demonstrate the effect of translations. Each path is
 *                  translated separately
 *******************************************************************************/
void CTransforms::DoTranslate()
{
	// Make sure we're operating on the path user-to-surface matrix
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);

	// Load Identity matrix. This clears all previous transformations
	vgLoadIdentity();

	// To be independent of screen resolution, we need to scale the
	// coordinates so everything in the range [0, 1] will be visible
	vgScale((float) PVRShellGet(prefWidth), (float) PVRShellGet(prefHeight));

	// Unlike OpenGL, OpenVG does not maintain a matrix stack. So instead of
	// pushing the current matrix to the stack, we have to store it ourselves
	float afUnitMatrix[3 * 3];
	vgGetMatrix(afUnitMatrix);

	// turn time(ms) into a clipped periodic triangle function
	int i32Zigzag1 = m_ui32AbsTime % 2000;

	if(i32Zigzag1 > 1000)
		i32Zigzag1 = 2000 - i32Zigzag1;

	i32Zigzag1 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag1)) - 500;

	// and again, now with shifted phase
	int i32Zigzag2 = (m_ui32AbsTime + 500) % 2000;

	if(i32Zigzag2 > 1000)
		i32Zigzag2 = 2000 - i32Zigzag2;

	i32Zigzag2 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag2)) - 250;

	// translation for first path
	vgTranslate(-0.001f * i32Zigzag1, -0.001f * i32Zigzag2);

	// draw first path
	vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH);

	// restore the unit matrix ([0, 1] visible)
	vgLoadMatrix(afUnitMatrix);

	// translation for second path
	vgTranslate(0.001f * i32Zigzag1, 0.001f * i32Zigzag2);

	// draw second path
	vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH);
}
Ejemplo n.º 15
0
void CTSmallWindowOpenVG::RenderL()
	{
	CTWindow::RenderL();

	// Make sure that this egl status is active
	eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);

    VGfloat clearColor[4] = {0.1f, 0.2f, 0.4f, 1.f};
    VGfloat scaleFactor = Size().iWidth/200.f;
    if (Size().iHeight/200.f < scaleFactor)
        {
        scaleFactor = Size().iHeight/200.f;
        }        

    iCurrentRotation = iTime;

    if (iCurrentRotation >= 360.f)
        {
        iCurrentRotation -= 360.f;
        }

    vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
    vgClear(0, 0, Size().iWidth, Size().iHeight);

    vgLoadIdentity();
    vgTranslate((float)Size().iHeight / 2, (float)Size().iHeight / 2);
    vgScale(scaleFactor, scaleFactor);
    vgRotate(iCurrentRotation);
    vgTranslate(-50.f, -50.f);

    vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
    vgSeti(VG_FILL_RULE, VG_EVEN_ODD);

    vgSetPaint(iFillPaint, VG_FILL_PATH);

    vgSetf(VG_STROKE_LINE_WIDTH, 10.f);
    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND);
    vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
    vgSetf(VG_STROKE_MITER_LIMIT, 0.f);
    vgSetPaint(iStrokePaint, VG_STROKE_PATH);

    vgDrawPath(iPath, VG_FILL_PATH | VG_STROKE_PATH);

	iTime++;
	eglSwapBuffers(iDisplay, iSurface);
	}
Ejemplo n.º 16
0
static void
draw(void)
{
    VGPath line;
    VGPaint fillPaint;
    VGubyte lineCommands[3] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS};
    VGfloat lineCoords[] =   {-2.0f,-1.0f, 0.0f,0.0f, -1.0f, -2.0f};
    VGfloat clearColor[] = {0.0f, 0.0f, 0.0f, 1.0f};/* black color */
    VGfloat fillColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */
    //VGfloat testRadius = 60.0f;
    VGfloat testRadius = 10.0f;
    int WINDSIZEX = window_width();
    int WINDSIZEY = window_height();

    line = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
                        1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
    fillPaint = vgCreatePaint();

    vgSetf(VG_STROKE_LINE_WIDTH, 1.0f);
    //vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND);
    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT);
    vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
    //vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL);

    vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);

    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
    vgLoadIdentity();
    vgTranslate(60, 60);
    vgScale(testRadius * 2, testRadius * 2);

    vgAppendPathData(line, 3, lineCommands, lineCoords);

    vgSetfv(VG_CLEAR_COLOR, 4, clearColor);

    vgSetPaint(fillPaint, VG_STROKE_PATH);

    vgSetParameterfv(fillPaint, VG_PAINT_COLOR, 4, fillColor);
    vgSetParameteri( fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);

    vgClear(0, 0, WINDSIZEX, WINDSIZEY);
    vgDrawPath(line, VG_STROKE_PATH);

    vgDestroyPath(line);
    vgDestroyPaint(fillPaint);
}
Ejemplo n.º 17
0
void display(float interval)
{
  VGfloat cc[] = {0,0,0,1};

  angle += interval * 0.4 * PI;
  if (angle > 2*PI) angle -= 2*PI;
  amount = (sin(angle) + 1) * 0.5f;
  createMorph();

  vgSetfv(VG_CLEAR_COLOR, 4, cc);
  vgClear(0,0,testWidth(),testHeight());

  vgLoadIdentity();
  vgTranslate(testWidth()/2, testHeight()/2);
  vgScale(1.5, 1.5);
  vgDrawPath(iMorph, VG_FILL_PATH);
}
Ejemplo n.º 18
0
static void draw(EGLmanager *eglman)
{
    VGfloat black[]   = {0.f, 0.f, 0.f, 1.f};

    // Render 3D scene by GL
    eglBindAPI(EGL_OPENGL_ES_API);
    eglMakeCurrent(eglman->dpy, eglman->pbuf_surface, eglman->pbuf_surface, eglman->es_ctx);

    // Modify GL texture source
    glClearColor(1.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2);
    glClearColor(0.0, 1.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, TEXTURE_WIDTH/2, 0, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2);
    glClearColor(0.0, 0.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, TEXTURE_HEIGHT/2, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2);
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2);

    // Make current to VG content
    eglBindAPI(EGL_OPENVG_API);
    eglMakeCurrent(eglman->dpy, eglman->win_surface, eglman->win_surface, eglman->vg_ctx);

    // Draw VGImage target
    vgSetfv(VG_CLEAR_COLOR, 4, black);
    vgClear(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
    vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
    vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
    vgLoadIdentity();
    vgTranslate(WINDOW_WIDTH/2.0f, WINDOW_HEIGHT/2.0f);
    vgScale((VGfloat)WINDOW_WIDTH/(VGfloat)TEXTURE_WIDTH * 0.8f, (VGfloat)WINDOW_HEIGHT/(VGfloat)TEXTURE_HEIGHT * 0.8f);
    vgTranslate(-TEXTURE_WIDTH/2.0f, -TEXTURE_HEIGHT/2.0f);
    vgDrawImage(eglman->vg_image);

    // Swap buffer
    eglSwapBuffers(eglman->dpy, eglman->win_surface);

    return;
}
Ejemplo n.º 19
0
void createApple(VGPath p)
{
  VGPath temp;

  VGubyte segs[] = {
    VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS,
    VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS,
    VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH,
    VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH };

  VGfloat data[] = {
    1.53125,-44.681982, -3.994719,-44.681982, -8.0085183,-50.562501,
    -26.5625,-50.562501, -42.918439,-50.562501, -56.46875,-34.239393,
    -56.46875,-12.187501, -56.46875,26.520416, -34.65822,61.731799,
    -16.84375,61.812499, -7.1741233,61.812499, -2.9337937,55.656199,
    4.15625,55.656199, 11.746294,55.656199, 17.981627,62.281199,
    25.4375,62.281199, 33.88615,62.281199, 50.53251,44.282999,
    58.75,15.718799, 47.751307,9.086518, 40.999985,-0.228074,
    41,-13.046574, 41,-27.849147, 46.64686,-34.763001,
    52.4375,-39.937501, 46.111827,-47.219094, 39.0413,-50.503784,
    29.09375,-50.446384, 11.146487,-50.342824, 8.6341912,-44.681982,
    1.53125,-44.681982,

    0.23972344,-52.075169, -2.8344902,-69.754133, 5.9303785,-81.915323,
    24.152707,-86.881406, 23.71828,-70.367255, 15.114064,-58.365865,
    0.23972344,-52.075169 };

  temp = testCreatePath();
  vgAppendPathData(temp, sizeof(segs), segs, data);

  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  vgScale(1,-1);
  vgTransformPath(p, temp);
  vgDestroyPath(temp);
}
Ejemplo n.º 20
0
void createPear(VGPath p)
{
  VGPath temp;

  VGubyte segs[] = {
    VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS,
    VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS,
    VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH,
    VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH };

  VGfloat data[] = {
    0.0625,-90.625001, -29.44062,-89.191161, -23.07159,-32.309301,
    -30.5625,-14.062501, -38.29681,4.7771994, -56.8077,20.767199,
    -56.46875,42.812499, -56.1298,64.502999, -40.15822,79.731799,
    -22.34375,79.812499, -4.17446,79.893199, -1.93369,71.113999,
    4.15625,71.156199, 10.49619,71.198499, 13.70293,80.336799,
    30.4375,80.281199, 42.49257,80.241199, 53.53251,70.782999,
    58.75,58.218799, 47.0442,54.768499, 38.5,43.943499,
    38.5,31.124999, 38.50001,22.754099, 42.14686,15.236999,
    47.9375,10.062499, 42.2834,1.5737994, 36.5413,-6.6199006,
    34.09375,-14.062501, 28.48694,-31.111801, 32.99356,-90.265511,
    1.5,-90.625001,

    5.1056438,-97.8762, -12.766585,-99.48239, -22.244878,-111.09615,
    -22.325466,-129.98288, -6.486451,-125.28908, 2.8790668,-113.87186,
    5.1056438,-97.8762 };

  temp = testCreatePath();
  vgAppendPathData(temp, sizeof(segs), segs, data);

  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  vgScale(1,-1);
  vgTransformPath(p, temp);
  vgDestroyPath(temp);
}
Ejemplo n.º 21
0
/****************************************************************************
** Application entry point
****************************************************************************/
int main()
{
	// Variable set in the message handler to finish the demo
	bool				bDemoDone	= false;

	// X11 variables
	Display*			x11Display	= 0;
	Window				x11Window	= 0;
	Colormap			x11Colormap	= 0;

	EGLDisplay			eglDisplay	= 0;
	EGLConfig			eglConfig	= 0;
	EGLSurface			eglSurface	= 0;
	EGLContext			eglContext	= 0;
	int i32NumConfigs, i32MajorVersion, i32MinorVersion;

	/*
	Step 0 - Initialize OpenVG
	--------------------------

	The following code up to the next comment block consists of the
	steps 0 to 8 taken straight from the Initialization tutorial.
	*/
	Window					sRootWindow;
    XSetWindowAttributes	sWA;
	unsigned int			ui32Mask;
	int						i32Depth;

	// Initializes the display and screen
	x11Display = XOpenDisplay( 0 );
	if (!x11Display)
	{
		printf("Error: Unable to open X display\n");
		goto cleanup;
	}
	long x11Screen;
	x11Screen = XDefaultScreen( x11Display );

	// Gets the window parameters
	sRootWindow = RootWindow(x11Display, x11Screen);
	i32Depth = DefaultDepth(x11Display, x11Screen);
	XVisualInfo* x11Visual;
	x11Visual = new XVisualInfo;
	XMatchVisualInfo( x11Display, x11Screen, i32Depth, TrueColor, x11Visual);
	if (!x11Visual)
	{
		printf("Error: Unable to acquire visual\n");
		goto cleanup;
	}
    x11Colormap = XCreateColormap( x11Display, sRootWindow, x11Visual->visual, AllocNone );
    sWA.colormap = x11Colormap;

    // Add to these for handling other events
    sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask;
    ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;

	// Creates the X11 window
    x11Window = XCreateWindow( x11Display, RootWindow(x11Display, x11Screen), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
								 0, CopyFromParent, InputOutput, CopyFromParent, ui32Mask, &sWA);
	XMapWindow(x11Display, x11Window);
	XFlush(x11Display);

	eglDisplay = (EGLDisplay)eglGetDisplay((NativeDisplayType)x11Display);

	if(!eglInitialize(eglDisplay, &i32MajorVersion, &i32MinorVersion))
	{
		printf("Error: eglInitialize() failed.\n");
		goto cleanup;
	}

	eglBindAPI(EGL_OPENVG_API);

	static const int ai32ConfigAttribs[] =
	{
		EGL_RED_SIZE,       5,
		EGL_GREEN_SIZE,     6,
		EGL_BLUE_SIZE,      5,
		EGL_ALPHA_SIZE,     0,
		EGL_SURFACE_TYPE,   EGL_WINDOW_BIT,
		EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
		EGL_NONE
	};

	if(!eglChooseConfig(eglDisplay, ai32ConfigAttribs, &eglConfig, 1, &i32NumConfigs) || (i32NumConfigs != 1))
	{
		printf("Error: eglChooseConfig() failed.\n");
		goto cleanup;
	}

	eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (NativeWindowType)x11Window, NULL);
	if((eglGetError() != EGL_SUCCESS) || (eglSurface == EGL_NO_SURFACE))
	{
		printf("Error: eglCreateWindowSurface() failed.\n");
		goto cleanup;
	}

	eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
	if((eglGetError() != EGL_SUCCESS) || (eglContext == EGL_NO_CONTEXT))
	{
		printf("Error: eglCreateContext() failed.\n");
		goto cleanup;
	}

	eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
	if(eglGetError() != EGL_SUCCESS)
	{
		printf("Error: eglMakeCurrent() failed.\n");
		goto cleanup;
	}

	/*
	Steps 1 to 4 - Prepare OpenVG to draw a triangle
	------------------------------------------------

	At this point we could theoretically start drawing with OpenVG. But
	we have to specify what to draw and how to draw it first.
	*/

	/*
	Step 1 - Set up a device independent coordinate system
	------------------------------------------------------

	Initially, the OpenVG coordinate system is based on the output resolution.
	To get a device independent coordinate system, we need to apply a
	transformation: Scaling by the output resolution means that coordinates
	between (0, 0) and (1, 1) will be visible on screen, with the origin
	in the lower left corner.

	Transformations are described more in-depth in the Transforms tutorial.

	It should be noted that different aspect ratios often require
	special attention regarding the layout of elements on screen.
	*/

	int i32WindowWidth, i32WindowHeight;
	eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &i32WindowWidth);
	eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &i32WindowHeight);

	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();
	vgScale((float)i32WindowWidth, (float)i32WindowHeight);


	/*
	Step 2 - Create a path
	----------------------
	Drawing shapes with OpenVG requires a path which represents a series of
	line and curve segments describing the outline of the shape. The shape
	does not need to be closed, but for now we will start with a simple
	triangle.
	First we create a path handle, then we append segment and point data.

	Creating a path involves choosing a datatype used for point data (we use
	float here, indicated by VG_PATH_DATATYPE_F) and capabilities that we want
	to use. Picking the right capabilities is important as the OpenVG driver
	can use a more efficient and compact internal representation for paths
	with limited capabilities. We only need two capabilities for this tutorial:
	adding data	to the path and drawing it, with the latter being implicitly
	enabled	for all paths.
	*/
	VGPath vgTriangle;
	vgTriangle = vgCreatePath(
							VG_PATH_FORMAT_STANDARD,
							VG_PATH_DATATYPE_F,
							1.0f, 0.0f, 4, 3,
							(unsigned int)VG_PATH_CAPABILITY_APPEND_TO);

	/*
	The segments of a path are described as a series of commands, represented as
	an array of bytes. You can imagine the commands being performed by a pen:
	First the pen moves to a starting location without drawing, from there it
	draws a line to a second point. Then another line to a third point. After
	that, it closes the shape by drawing a line from the last point to the
	starting location: triangle finished!

	The suffixes _ABS and _REL attached to the commands indicate whether the
	coordinates are to be interpreted as absolute locations (seen from the
	origin)or as being relative to the location of the current point.
	*/
	VGubyte aui8PathSegments[4];
	aui8PathSegments[0] = VG_MOVE_TO_ABS;
	aui8PathSegments[1] = VG_LINE_TO_ABS;
	aui8PathSegments[2] = VG_LINE_TO_ABS;
	aui8PathSegments[3] = VG_CLOSE_PATH;

	/*
	In addition to the array of commands, the path needs a list of points. A
	command can "consume" from 0 to 6 values, depending on its type. MOVE_TO
	and LINE_TO each take two values, CLOSE_PATH takes none.
	A triangle requires 3 2D vertices.
	*/
	VGfloat afPoints[6];
	afPoints[0] = 0.3f;
	afPoints[1] = 0.3f;
	afPoints[2] = 0.7f;
	afPoints[3] = 0.3f;
	afPoints[4] = 0.5f;
	afPoints[5] = 0.7f;

	/*
	When appending data to the path, only the number of segments needs to be
	specified since the number of points used depends on the actual commands.
	*/
	vgAppendPathData(vgTriangle, 4, aui8PathSegments, afPoints);

	/*
	Path capabilities should be removed as soon as they are no longer needed.
	The OpenVG implementation might work more efficiently if it knows that
	path data will not change since it can use an optimized internal
	representation.
	*/
	vgRemovePathCapabilities(vgTriangle, VG_PATH_CAPABILITY_APPEND_TO);


	/*
	Step 3 - Create a paint
	-----------------------
	To fill a shape, we need a paint that describes how to fill it: a gradient,
	pattern, or single color. Here we choose a paint with type COLOR that
	is a simple opaque red. vgSetColor is a shortcut function that takes a
	non-premultiplied sRGBA color encoded as a 32bit integer in RGBA_8888 form.
	*/
	VGPaint vgFillPaint;
	vgFillPaint = vgCreatePaint();
	vgSetParameteri(vgFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(vgFillPaint, 0xFFFFAAFF);

	/*
	Step 4 - Prepare the render loop
	--------------------------------

	The clear color will be used whenever calling vgClear(). The color is given
	as non-premultiplied sRGBA, represented by four float values.
	*/
	VGfloat afClearColor[4];
	afClearColor[0] = 0.6f;
	afClearColor[1] = 0.8f;
	afClearColor[2] = 1.0f;
	afClearColor[3] = 1.0f;

	// Set the clear color
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColor);

	/*
	Step 5 - Render loop
	--------------------

	Start the render loop for 1000 frames!
	*/
	for(int i = 0; i < 1000; ++i)
	{
		// Check if the message handler finished the demo
		if (bDemoDone) break;

		// Clear the whole surface with the clear color
		vgClear(0, 0, i32WindowWidth, i32WindowHeight);

		// Set the current fill paint...
		vgSetPaint(vgFillPaint, VG_FILL_PATH);

		// Draw the triangle!
		vgDrawPath(vgTriangle, VG_FILL_PATH);

		/*
		Drawing is double buffered, so you never see any intermediate
		results of the drawing. When you have finished drawing
		you have to call eglSwapBuffers to make the results appear on
		screen.
		*/
		eglSwapBuffers(eglDisplay, eglSurface);

		// Managing the X11 messages
		int i32NumMessages = XPending( x11Display );
		for( int i = 0; i < i32NumMessages; i++ )
		{
			XEvent	event;
			XNextEvent( x11Display, &event );

			switch( event.type )
			{
			// Exit on mouse click
			case ButtonPress:
        		bDemoDone = true;
        		break;
			default:
				break;
			}
		}
	}

	/*
	Step 6 - Destroy resources
	--------------------------

	OpenVG resources like paths and paints need to be destroyed
	when they are no longer needed.
	*/
	vgDestroyPath(vgTriangle);
	vgDestroyPaint(vgFillPaint);


cleanup:
	/*
	Step 7 - Terminate OpenVG
	-------------------------

	Again, the following code is taken from the Initialization tutorial,
	steps 10 and 11.
	*/
	eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
	eglTerminate(eglDisplay);

	if (x11Window) XDestroyWindow(x11Display, x11Window);
    if (x11Colormap) XFreeColormap( x11Display, x11Colormap );
	if (x11Display) XCloseDisplay(x11Display);

	// Say goodbye
	printf("%s finished.", pszAppName);
	return 0;
}
Ejemplo n.º 22
0
// Scale scales by  x, y
void Scale(VGfloat x, VGfloat y) {
	vgScale(x, y);
}
Ejemplo n.º 23
0
// ---------------------------------------------------------------------------
// Computation of the viewport to viewbox transformation matrix
// ---------------------------------------------------------------------------
void CNvgFitToViewBoxImpl::SetWindowViewportTrans(TRect aViewPort, TSize aSize)
    {
    
    //VIEWPORT NUMBERS
    TReal lViewPortX = aViewPort.iTl.iX;
    TReal lViewPortY = aViewPort.iTl.iY;
    TReal lViewPortWidth = aViewPort.Width();
    TReal lViewPortHeight = aViewPort.Height();
    
    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
    vgTranslate(lViewPortX, lViewPortY );

    /* 2. Scale */

    TReal lViewBoxXmin;
    TReal lViewBoxYmin;
    TReal lViewBoxWidth;
    TReal lViewBoxHeight;

    if ( iViewBoxDefined ) 
        {
        lViewBoxXmin = ivbX;
        lViewBoxYmin = ivbY;
        lViewBoxWidth = ivbW;
        lViewBoxHeight = ivbH;
        }
    else
        {
        //this will default viewBox to <svg> element width and height
        lViewBoxXmin = 0;
        lViewBoxYmin = 0;
        lViewBoxWidth = aSize.iWidth;
        lViewBoxHeight = aSize.iHeight;
        }

	
    if ( lViewBoxWidth == 0.0f || lViewBoxHeight == 0.0f )
        {
        return;    
        }
	

	TReal sx = lViewPortWidth / lViewBoxWidth;
	TReal sy = lViewPortHeight / lViewBoxHeight;
	
    if ( sx == 0.0f || sy == 0.0f )
        {
        return;    
        }
    

    
    TReal xtrans = TReal( -1.0f ) * lViewBoxXmin;
    TReal ytrans = TReal( -1.0f ) * lViewBoxYmin;

    switch ( iAlign )
        {
            case ENvgPreserveAspectRatio_None:
            /* Non uniform scaling */
            //none - Do not force uniform scaling.
            //Scale the graphic content of the given element
            //non-uniformly if necessary such that the element's
            //bounding box exactly matches the viewport rectangle.

            //(Note: if <align> is none, then the optional <meetOrSlice> value is ignored.)
            break;

            case ENvgPreserveAspectRatio_XminYmin:
            //Align the <min-x> of the element's viewBox with the smallest X value of the viewport.
            //Align the <min-y> of the element's viewBox with the smallest Y value of the viewport.

            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;
                    //no change for xtrans...default above
                }
                else // ( sx < sy )
                {
                    sy = sx;
                    //no change for ytrans...default above
                }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if (sx > sy)
                {
                    sy = sx;
                }
                else // ( sx < sy )
                {
                    sx = sy;
                }
            }
            break;

            case ENvgPreserveAspectRatio_XmidYmin:
            //Align the midpoint X value of the element's viewBox with the midpoint X value of the viewport.
            //Align the <min-y> of the element's viewBox with the smallest Y value of the viewport.
            //Align the <min-x> of the element's viewBox with the smallest X value of the viewport.
            //Align the <min-y> of the element's viewBox with the smallest Y value of the viewport.

            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;
	                xtrans = ( ( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) )\
                           * 0.5 ) / sx - lViewBoxXmin;
	            }
                else // ( sx < sy )
                {
                    sy = sx;
                    //no change for ytrans...default above
                }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if ( sx > sy )
                {
                    sy = sx;
                }
                else //( sx < sy )
                {
                    sx = sy;
                    xtrans = lViewPortWidth - sx*lViewBoxWidth;
                    xtrans = xtrans/sx;
                    xtrans = xtrans/2.0 - lViewBoxXmin;
                }
            }
            break;

            case ENvgPreserveAspectRatio_XmaxYmin:
            //Align the <min-x>+<width> of the element's viewBox with the maximum X value of the viewport.
            //Align the <min-y> of the element's viewBox with the smallest Y value of the viewport.
            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;
	
                    xtrans = (( lViewPortWidth - ( ( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) ) / sx\
                           - lViewBoxXmin;
                }
                else // ( sx < sy )
                {
                    sy = sx;
                    //no change for ytrans...default above
                }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if ( sx > sy )
                {
                    sy = sx;
                    //no change for ytrans...default above
                }
                else // ( sx < sy )
                {
                    sx = sy;
                    xtrans = lViewPortWidth - sx*lViewBoxWidth;
                    xtrans = xtrans/sx - lViewBoxXmin;
                }
            }
            break;

            case ENvgPreserveAspectRatio_XminYmid:
            //Align the <min-x> of the element's viewBox with the smallest X value of the viewport.
            //Align the midpoint Y value of the element's viewBox with the midpoint Y value of the viewport.
            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;
                    //no change for xtrans...default above
                }
                else // ( sx < sy )
                {
                    sy = sx;
	                ytrans = ( ( TReal )
                           ( lViewPortHeight - ( ( TReal ) ( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) )\
                           * TReal(.5) ) /sy - lViewBoxYmin;
                }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if ( sx > sy )
                    {
                    sy = sx;
                    ytrans = lViewPortHeight - sx*lViewBoxHeight;
                    ytrans = ytrans/sx;
                    ytrans = ytrans/2.0 - lViewBoxYmin;
                    }
                else
                    {
                    sx = sy;
                    }
            }
            break;

            case ENvgPreserveAspectRatio_XmidYmid:
            //(default) case
            //Align the midpoint X value of the element's viewBox with the midpoint X value of the viewport.
            //Align the midpoint Y value of the element's viewBox with the midpoint Y value of the viewport.
            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;
                    xtrans = (( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) * \
                            0.5 ) / sx - lViewBoxXmin;

                }
                else if ( sx < sy )
                {
                    sy = sx;
	
                    ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) * \
                           0.5 ) /sy - lViewBoxYmin;
	            }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if ( sx > sy )
                {
                    sy = sx;
                    ytrans = lViewPortHeight - sx*lViewBoxHeight;
                    ytrans = ytrans/sx;
                    ytrans = ytrans/2.0 - lViewBoxYmin;
                }
                else // ( sx < sy )
                {
                    sx = sy;
                    xtrans = lViewPortWidth - sx*lViewBoxWidth;
                    xtrans = xtrans/sx;
                    xtrans = xtrans/2.0 - lViewBoxXmin;
                }
            }
            break;

            case ENvgPreserveAspectRatio_XmaxYmid:
            //Align the <min-x>+<width> of the element's viewBox with the maximum X value of the viewport.
            //Align the midpoint Y value of the element's viewBox with the midpoint Y value of the viewport.
            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;
                    xtrans = (( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) ) / sx \
                           - lViewBoxXmin;
                }
                else //( sx < sy )
                {
                    sy = sx;
	
                    ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) \
                           * 0.5 ) /sy - lViewBoxYmin;
	            }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if ( sx > sy )
                {
                    sy = sx;
                    ytrans = lViewPortHeight - sx*lViewBoxHeight;
                    ytrans = ytrans/sx;
                    ytrans = ytrans/2.0 - lViewBoxYmin;
                }
                else //( sx < sy )
                {
                    sx = sy;
                    xtrans = lViewPortWidth - sx*lViewBoxWidth;
                    xtrans = xtrans/sx - lViewBoxXmin;
                }
            }
            break;

            case ENvgPreserveAspectRatio_XminYmax:
            //Align the <min-x> of the element's viewBox with the smallest X value of the viewport.
            //Align the <min-y>+<height> of the element's viewBox with the maximum Y value of the viewport.
            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;
                    //no change for xtrans...default above
                }
                else //( sx < sy )
                {
                    sy = sx;

                    ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) ) /sy \
                           - lViewBoxYmin;
                }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if ( sx > sy )
                {
                    sy = sx;
                    ytrans = lViewPortHeight - sx*lViewBoxHeight;
                    ytrans = ytrans/sx - lViewBoxYmin;
                }
                else //( sx < sy )
                {
                    sx = sy;
                }
            }
            break;

            case ENvgPreserveAspectRatio_XmidYmax:
            //Align the midpoint X value of the element's viewBox with the midpoint X value of the viewport.
            //Align the <min-y>+<height> of the element's viewBox with the maximum Y value of the viewport.
            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;
	
                    xtrans = (( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) \
                           * 0.5 ) / sx - lViewBoxXmin;
	            }
                else //( sx < sy )
                {
                    sy = sx;

                    ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) ) /sy \
                           - lViewBoxYmin;
                }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if ( sx > sy )
                {
                    sy = sx;
                    ytrans = lViewPortHeight - sx*lViewBoxHeight;
                    ytrans = ytrans/sx - lViewBoxYmin;
                }
                else //( sx < sy )
                {
                    sx = sy;
                    xtrans = lViewPortWidth - sx*lViewBoxWidth;
                    xtrans = xtrans/sx;
                    xtrans = xtrans/2.0 - lViewBoxXmin;
                }
            }
            break;

            case ENvgPreserveAspectRatio_XmaxYmax:
            //Align the <min-x>+<width> of the element's viewBox with the maximum X value of the viewport.
            //Align the <min-y>+<height> of the element's viewBox with the maximum Y value of the viewport.
            if (iMeetSlice == ENvgMeet)
            {
                if ( sx > sy )
                {
                    sx = sy;

                    xtrans = (( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) ) / sx\
                           - lViewBoxXmin;
                }
                else //( sx < sy )
                {
                    sy = sx;

                    ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) ) /sy \
                           - lViewBoxYmin;
                }
            }
            else if (iMeetSlice == ENvgSlice)
            {
                if ( sx > sy )
                {
                    sy = sx;
                    ytrans = lViewPortHeight - sx*lViewBoxHeight;
                    ytrans = ytrans/sx - lViewBoxYmin;
                }
                else //( sx < sy )
                {
                    sx = sy;
                    xtrans = lViewPortWidth - sx*lViewBoxWidth;
                    xtrans = xtrans/sx - lViewBoxXmin;
                }
            }
            break;

        default:
            break;
        }
    vgScale( sx, sy);

    vgTranslate( xtrans, ytrans );

    }
Ejemplo n.º 24
0
/*******************************************************************************
 * 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 OVGMaskLayer::InitView()
{
	// Get screen dimensions
	m_ui32ScreenWidth = PVRShellGet(prefWidth);
	m_ui32ScreenHeight= PVRShellGet(prefHeight);

	// Create the paths so we have something to look at.
	CreatePath();

	// Set the render quality so the stroke borders have some form of anti-aliasing
	vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);

	// Create the paints that the paths will use
	m_avgColourPaint[0] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[0], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[0], PVRTRGBA(255,255,15,255));

	m_avgColourPaint[1] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[1], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[1], PVRTRGBA(255,50,0, 255));

	m_avgColourPaint[2] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[2], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[2], PVRTRGBA(50,250,15, 255));

	/*
		Load the images we're going to use to modify the mask layer.

		For more details on masking please refer to our OVGMasking training course
	*/

	// Create the VGImages.
	VGImage vgMaskImg, vgMaskImg2;

	// Using the PVR Tools we're going to load the mask data from a pvr file
	if(PVRTImageLoadFromPVR(c_szMask1File, &vgMaskImg) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to open mask1.pvr.");
		return false;
	}

	if(PVRTImageLoadFromPVR(c_szMask2File, &vgMaskImg2) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to open mask2.pvr.");
		return false;
	}

	/*
		Create a mask layer

		A VGMaskLayer is an object that allows you to store and manipulate the drawing surface's mask layer
	*/

	m_vgMaskLayer[0] = vgCreateMaskLayer(m_ui32ScreenWidth, m_ui32ScreenHeight);

	if(m_vgMaskLayer[0] == 0)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to create mask layer.");
		return false;
	}

	// Tile the first image in the drawing surface's masking layer
	TileImageInMask(vgMaskImg, VG_SET_MASK);

	/*
		Copy the contents of the drawing surface mask layer into our mask layer object

		vgCopyMask has the following parameters

		VGMaskLayer maskLayer, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)

		where

		masklayer is the masklayer to copy to
		dx, dy are the coordinates to start the copy at in the masklayer
		sx, sy are the coordinates to start the copy from in the source mask layer
		width and the height are the width and height of the region you wish to copy.

		In our case we're copying the full mask layer.
	*/

	vgCopyMask(m_vgMaskLayer[0], 0, 0, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Create the second mask layer
	m_vgMaskLayer[1] = vgCreateMaskLayer(m_ui32ScreenWidth, m_ui32ScreenHeight);

	if(m_vgMaskLayer[1] == 0)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to create mask layer.");
		return false;
	}

	// Replace the contents of the mask by tiling the second image
	TileImageInMask(vgMaskImg2, VG_SET_MASK);

	// Copy the contents of the mask into the second mask layer
	vgCopyMask(m_vgMaskLayer[1], 0, 0, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Destroy the images as they are no longer needed
	vgDestroyImage(vgMaskImg);
	vgDestroyImage(vgMaskImg2);

	// Set the mask to ones
	vgMask(VG_INVALID_HANDLE, VG_FILL_MASK, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Init PrintVG
	m_PrintVG.Initialize(m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Setup the transformation to scale the paths to fit the screen
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();

	vgScale((float) m_ui32ScreenWidth, (float) m_ui32ScreenHeight);

	// Reduce the stroke size to compensate for our scaling
	vgSetf(VG_STROKE_LINE_WIDTH, 1.0f / m_ui32ScreenHeight);

	//Create and set the clear colour
	VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f };
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	return true;
}
Ejemplo n.º 25
0
void text_widget_draw_text ( struct TEXT_WIDGET_HANDLE handle )
{
  if ( handle.d == NULL || handle.d->layout == NULL )
    return;

  vgSetPaint( handle.d->foreground, VG_FILL_PATH );

  vgSeti( VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE );
  vgLoadIdentity();
#if 0
  // Overscan (in dots, evidently).
  vgTranslate( 14.f, 8.f );
#endif
  // Offset in mm.
  vgScale( handle.d->dpmm_x, handle.d->dpmm_y );
  // Move to the corner.
  vgTranslate( handle.d->x_mm, handle.d->y_mm );
  // Back to dots.
  vgScale( 1.f/handle.d->dpmm_x, 1.f/handle.d->dpmm_y );

  int height = PANGO_PIXELS( pango_layout_get_height( handle.d->layout ) );

  PangoLayoutIter* li = pango_layout_get_iter( handle.d->layout );
  do {
    PangoLayoutRun* run = pango_layout_iter_get_run( li );
    if ( run == NULL )
      continue;

    PangoRectangle logical_rect;
    int baseline_pango = pango_layout_iter_get_baseline( li );
    int baseline_pixel = PANGO_PIXELS( baseline_pango );
    pango_layout_iter_get_run_extents( li, NULL, &logical_rect );
    int x_pixel = PANGO_PIXELS( logical_rect.x );

    PangoFont* pg_font = run->item->analysis.font;

    FT_Face face = pango_fc_font_lock_face( (PangoFcFont*)pg_font );

    if ( face != NULL ) {

      struct VG_DATA* vg_data = face->size->generic.data;
      if ( vg_data != NULL ) {
	// About the only extra attribute we can manage is the foreground
	// color. But, it might be nice to render a background color
	// to see just how badly the text is fitted into the widget
	// box.
	GSList* attr_item = run->item->analysis.extra_attrs;
	while ( attr_item ) {
	  PangoAttribute* attr = attr_item->data;
	  switch ( attr->klass->type ) {
	  case PANGO_ATTR_FOREGROUND:
	    {
	      PangoColor color = ((PangoAttrColor*)attr)->color;
	      VGfloat new_color[] = { (float)color.red / 65535.f,
				      (float)color.green / 65535.f,
				      (float)color.blue / 65535.f, 1.f };
	      VGPaint new_paint = vgCreatePaint();
	      vgSetParameterfv( new_paint, VG_PAINT_COLOR, 4, new_color );
	      vgSetPaint( new_paint, VG_FILL_PATH );
	      vgDestroyPaint( new_paint );
	    }
	    break;
	  default:
	    printf( "\tHmm. Unknown attribute: %d\n", attr->klass->type );
	  }
	  attr_item = attr_item->next;
	}

	// Note: inverted Y coordinate
	VGfloat point[2] = { x_pixel, height - baseline_pixel };
	vgSetfv( VG_GLYPH_ORIGIN, 2, point );
	VGFont vg_font = vg_data->font;
	int g;
	for ( g = 0; g < run->glyphs->num_glyphs; g++ ) {
	  vgDrawGlyph( vg_font, run->glyphs->glyphs[g].glyph, VG_FILL_PATH,
		       VG_TRUE );
	}

	if ( vgGetPaint( VG_FILL_PATH ) != handle.d->foreground ) {
	  vgSetPaint( handle.d->foreground, VG_FILL_PATH );
	}
      }
      pango_fc_font_unlock_face( (PangoFcFont*)pg_font );
    }
  } while ( pango_layout_iter_next_run( li ) );
  // Iterators are not free.
  pango_layout_iter_free( li);
}
Ejemplo n.º 26
0
/*******************************************************************************
 * 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 CStrokeStyles::RenderScene()
{
	/*
		If the left or right arrow keys are pressed then change the
		CapStyle or JoinStyle or DashStyle depending on which one is
		selected.
	*/
	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		switch(m_i32Selected)
		{
			case 0: m_i32CapStyle  = (m_i32CapStyle +  2) % 3; break;
			case 1: m_i32JoinStyle = (m_i32JoinStyle + 2) % 3; break;
			case 2: m_i32DashStyle = (m_i32DashStyle + 2) % 3; break;
		}
	}
	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		switch(m_i32Selected)
		{
			case 0: m_i32CapStyle  = (m_i32CapStyle +  1) % 3; break;
			case 1: m_i32JoinStyle = (m_i32JoinStyle + 1) % 3; break;
			case 2: m_i32DashStyle = (m_i32DashStyle + 1) % 3; break;
		}
	}

	/*
		If the up or down arrow is pressed then change which item is
		selected.
	*/
	if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
		m_i32Selected = (m_i32Selected + 2) % 3;

	if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
		m_i32Selected = (m_i32Selected + 1) % 3;

	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();
	vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight));

	// Clear the screen with clear colour.
	vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight));

	// Draw the path with the stroke styles that we want
	vgSeti(VG_STROKE_CAP_STYLE  , VG_CAP_BUTT   + m_i32CapStyle);
	vgSeti(VG_STROKE_JOIN_STYLE , VG_JOIN_MITER + m_i32JoinStyle);
	vgSetf(VG_STROKE_MITER_LIMIT, m_fMiterLimit * PVRShellGet(prefHeight));

	if(m_i32DashStyle > 0)
	{
		vgSetf(VG_STROKE_DASH_PHASE, m_fDashPhase);

		static float s_afDashes[] = { 0.1f, 0.15f, 0.23f, 0.11f };
		vgSetfv(VG_STROKE_DASH_PATTERN, 4, s_afDashes);

		if(m_i32DashStyle == 2)
			m_fDashPhase += 0.01f;
	}
	else
	{
		vgSetfv(VG_STROKE_DASH_PATTERN, 0, NULL);
	}

	vgSetf(VG_STROKE_LINE_WIDTH, 20.0f / PVRShellGet(prefHeight));

	vgDrawPath(m_vgPath, VG_STROKE_PATH);

	/*	Draw the text.

		If one of the pieces of text is currently selected then it will be
		drawn in yellow.
	*/

	static char* apszCapStrings[]  = { "Butt", "Round", "Square" };
	static char* apszJoinStrings[] = { "Miter", "Round", "Bevel" };
	static char* apszDashStrings[] = { "None", "Pattern", "Moving" };

	m_PrintVG.DisplayDefaultTitle("StrokeStyles", "", ePVRTPrint3DLogoIMG);

	float fHeight = PVRShellGet(prefHeight) - 40.0f;

	/*
		Draw the Cap text.
	*/
	m_PrintVG.DrawString(2.0f , fHeight, 0.6f, "Cap:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszCapStrings[m_i32CapStyle],
			m_i32Selected == 0 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	/*
		Draw the Join text.
	*/
	fHeight -= 20.0f;
	m_PrintVG.DrawString(2.0f, fHeight, 0.6f, "Join:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszJoinStrings[m_i32JoinStyle],
			m_i32Selected == 1 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	/*
		Draw the Dash text.
	*/
	fHeight -= 20.0f;
	m_PrintVG.DrawString(2.0f,fHeight, 0.6f, "Dash:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszDashStrings[m_i32DashStyle],
			m_i32Selected == 2 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	return true;
}
Ejemplo n.º 27
0
TInt CNVGCSIcon::DoDrawL(const TSize aSize)
    {
    TInt ret = KErrNone;
    
    vgSetPaint(iFillPaint,   VG_FILL_PATH);
    vgSetPaint(iStrokePaint, VG_STROKE_PATH);
    iLastFillPaintColor     = 0;
    iLastStrkePaintColor    = 0;
    iLastFillPaintType      = 0;
    iLastStrokePaintType    = 0;

    VGfloat lCurrentPathMatrix[9];
    vgGetMatrix(lCurrentPathMatrix);
    
    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);  
    vgLoadMatrix(lCurrentPathMatrix);
    SetRotation();
#ifdef __MIRROR_    
    vgScale(1.0f, -1.0f);
    vgTranslate(0, (VGfloat)(-aSize.iHeight) );
#endif
    
    SetViewBoxToViewTransformationL(aSize);
   
    
    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
    
    VGfloat currentMatrix[9];
    
    vgGetMatrix(currentMatrix);
    
    iNVGIconData->BeginRead();

    while (!iNVGIconData->EOF())
        {
        switch (iNVGIconData->ReadInt32L())
            {
            case EPath:
                {
                VGPath path = (VGPath)iNVGIconData->ReadInt32L();
                VGPaintMode paintMode = (VGPaintMode)iNVGIconData->ReadInt32L();

                if (path == VG_INVALID_HANDLE)
                    {
                    vgDrawPath(iPath, paintMode);
                    }
                else
                    {
                    vgDrawPath(path, paintMode);
                    }
                
                break;
                }
            case EPathData:
                {                
                if (iPath != VG_INVALID_HANDLE)
                    {
                    VGint numSegments;
                    VGubyte * pathSegments = 0;
                    VGubyte * pathData = 0;
                    
                    numSegments  = iNVGIconData->ReadInt32L();
                    pathSegments = new (ELeave) VGubyte[numSegments];
                    CleanupStack::PushL(TCleanupItem(CleanupArray, pathSegments));
                    if (pathSegments)
                        {
                        iNVGIconData->ReadL(pathSegments, numSegments);
                        VGint coordinateCount = iNVGIconData->ReadInt32L();
                        pathData = new (ELeave) VGubyte[coordinateCount * 4];
                        if (pathData)
                            {
                            CleanupStack::PushL(TCleanupItem(CleanupArray, pathData));
                            iNVGIconData->ReadL(pathData, coordinateCount * 4);
                            vgClearPath(iPath, VG_PATH_CAPABILITY_APPEND_TO);
                            vgAppendPathData(iPath, numSegments, pathSegments, pathData);
                            CleanupStack::PopAndDestroy();
                            }                        
                        }
                    CleanupStack::PopAndDestroy();
                    }
                break;
                }
            case EPaint:
                {
                DrawPaintL(iFillPaint, VG_MATRIX_FILL_PAINT_TO_USER, iLastFillPaintType, iLastFillPaintColor, VG_FILL_PATH);
                break;
                }
            case EColorRamp:
                {
                iNVGIconData->ReadInt32L();
                break;
                }
            case ETransform:
                {
                TInt flag;
                VGfloat transformMatrix[9];
                
                TPtr8 tmPtr((TUint8 *)transformMatrix, 9 * sizeof(VGfloat));
                
                iNVGIconData->ReadL(tmPtr, 9 * sizeof(VGfloat));
                flag = iNVGIconData->ReadInt32L();
                
                vgLoadMatrix(currentMatrix);
                if (flag)
                    {
                    vgMultMatrix(transformMatrix);
                    }
                }
                break;
            case EStrokeWidth:
                {
                VGfloat strokeWidth = iNVGIconData->ReadReal32L();
                vgSetf(VG_STROKE_LINE_WIDTH, strokeWidth);
                break;
                }
            case EStrokeMiterLimit:
                {
                VGfloat miterLimit = iNVGIconData->ReadReal32L();
                vgSetf(VG_STROKE_MITER_LIMIT, miterLimit);
                break;
                }
            case EStrokeLineJoinCap:
                {
                VGint lineJoin = iNVGIconData->ReadInt32L();
                VGint cap = iNVGIconData->ReadInt32L();
                
                vgSeti(VG_STROKE_JOIN_STYLE, (VGJoinStyle)lineJoin);
                vgSeti(VG_STROKE_CAP_STYLE, (VGCapStyle)cap);
                break;
                }
            case EStrokePaint:
                {
                DrawPaintL(iStrokePaint, VG_MATRIX_STROKE_PAINT_TO_USER, iLastStrokePaintType, iLastStrkePaintColor, VG_STROKE_PATH);
                break;
                }
            case EStrokeColorRamp:
                {
                iNVGIconData->ReadInt32L();
                break;
                }
            default:
                {
                User::Leave(KErrCorrupt);
                break;
                }
            }
        }
    
    iNVGIconData->EndRead();
    
    return ret;
    }
TBool CHuiFxVg10TransformFilter::Draw(CHuiFxEngine& /*aEngine*/, CHuiGc& /*aGc*/,
        CHuiFxRenderbuffer& aTarget, CHuiFxRenderbuffer& aSource,
        const TRect& /*aTargetRect*/, const TRect& aSourceRect, TBool /*aHasSurface*/)
    {
    aSource.BindAsTexture(ERenderbufferUsageReadOnly);
    aTarget.BindAsRenderTarget();

    VGImage srcImage  = (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(&aSource))->AcquireSubImage(aSourceRect);

    vgLoadIdentity();
    vgScale(iScaleX, iScaleY);
    vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
    vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
    
    identity();
    
    // Matrix multiplication is generally not commutative.
    // Therefore the order of the transformations matters.
    // In order to prevent the scaling ang skewing from affecting the translation,
    // if seems wiser to do the translation first, otherwise the results seem to be unpredictable.
    
    // Translation
    if (iTranslationX != 0.0f || iTranslationY != 0.0f || iTranslationZ != 0.0f)
        {
        translate(iTranslationX, iTranslationY, iTranslationZ);
        }    

    // Scaling
    if (iScaleX != 1.0f || iScaleY != 1.0f || iScaleZ != 1.0f)
        {
        translate(iScaleOriginX, iScaleOriginY, iScaleOriginZ);
        scale(iScaleX, iScaleY, iScaleZ); 
        translate(-iScaleOriginX, -iScaleOriginY, -iScaleOriginZ);
        }
    
    // Skewing
    if (iSkewAngleX != 0.0f || iSkewAngleY != 0.0f || iSkewAngleZ != 0.0f)
        {
        const TReal32 radsPerDeg = 2.0f * (float)M_PI / 360.0f;
        TReal32 skewX = tan(iSkewAngleX * radsPerDeg);
        TReal32 skewY = tan(iSkewAngleY * radsPerDeg);
        TReal32 skewZ = tan(iSkewAngleZ * radsPerDeg);
        translate(iSkewOriginX, iSkewOriginY, iSkewOriginZ);
        shear(skewX, skewY, skewZ); 
        translate(-iSkewOriginX, -iSkewOriginY, -iSkewOriginZ);
        }

    // Rotation
    if (iRotationAngle != 0.0f)
        {
        translate(iRotationOriginX, iRotationOriginY, iRotationOriginZ);
        rotate(iRotationAngle, iRotationAxisX, iRotationAxisY, iRotationAxisZ); 
        translate(-iRotationOriginX, -iRotationOriginY, -iRotationOriginZ);
        }

/*
    // Translation
    if (iTranslationX != 0.0f || iTranslationY != 0.0f || iTranslationZ != 0.0f)
        {
        translate(iTranslationX, iTranslationY, iTranslationZ);
        }    
*/
        
   ASSERT(!"TODO: implement the following:");
    // TODO: project vertices
    // TODO: create warp quad matrix from projected vertices,
    // see http://torus.untergrund.net/misc/projective_image_warping.pdf
    // TODO load matrix
    vgDrawImage(srcImage);
    
    // TODO: pixel relative parameters
    HUIFX_VG_INVARIANT();
    (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(&aSource))->ReleaseSubImage(srcImage);

    aTarget.UnbindAsRenderTarget();
    aSource.UnbindAsTexture();
    
    return ETrue;
    }