egl/sfopenvg/riContext.h
branchEGL_MERGE
changeset 180 f767bd5f4cfc
parent 119 5f371025658c
child 181 c1509651cd2b
equal deleted inserted replaced
119:5f371025658c 180:f767bd5f4cfc
     1 #ifndef __RICONTEXT_H
       
     2 #define __RICONTEXT_H
       
     3 
       
     4 /*------------------------------------------------------------------------
       
     5  *
       
     6  * OpenVG 1.1 Reference Implementation
       
     7  * -----------------------------------
       
     8  *
       
     9  * Copyright (c) 2007 The Khronos Group Inc.
       
    10  *
       
    11  * Permission is hereby granted, free of charge, to any person obtaining a
       
    12  * copy of this software and /or associated documentation files
       
    13  * (the "Materials "), to deal in the Materials without restriction,
       
    14  * including without limitation the rights to use, copy, modify, merge,
       
    15  * publish, distribute, sublicense, and/or sell copies of the Materials,
       
    16  * and to permit persons to whom the Materials are furnished to do so,
       
    17  * subject to the following conditions: 
       
    18  *
       
    19  * The above copyright notice and this permission notice shall be included 
       
    20  * in all copies or substantial portions of the Materials. 
       
    21  *
       
    22  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    25  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
       
    26  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
       
    27  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
       
    28  * THE USE OR OTHER DEALINGS IN THE MATERIALS.
       
    29  *
       
    30  *//**
       
    31  * \file
       
    32  * \brief	VGContext class. Used for storing OpenVG state.
       
    33  * \note	
       
    34  *//*-------------------------------------------------------------------*/
       
    35 
       
    36 #ifndef OPENVG_H
       
    37 #include "openvg.h"
       
    38 #endif
       
    39 
       
    40 #ifndef __RIDEFS_H
       
    41 #include "riDefs.h"
       
    42 #endif
       
    43 
       
    44 #ifndef __RIMATH_H
       
    45 #include "riMath.h"
       
    46 #endif
       
    47 
       
    48 #ifndef __RIIMAGE_H
       
    49 #include "riImage.h"
       
    50 #endif
       
    51 
       
    52 #ifndef __RIPATH_H
       
    53 #include "riPath.h"
       
    54 #endif
       
    55 
       
    56 #ifndef __RIFONT_H
       
    57 #include "riFont.h"
       
    58 #endif
       
    59 
       
    60 #ifndef __RIARRAY_H
       
    61 #include "riArray.h"
       
    62 #endif
       
    63 
       
    64 //==============================================================================================
       
    65 
       
    66 namespace OpenVGRI
       
    67 {
       
    68 
       
    69 class VGContext;
       
    70 
       
    71 /*-------------------------------------------------------------------*//*!
       
    72 * \brief	A list of resources (Images, Paths, or Paints) shared by a
       
    73 *			set of contexts.
       
    74 * \param	
       
    75 * \return	
       
    76 * \note		
       
    77 *//*-------------------------------------------------------------------*/
       
    78 
       
    79 template <class Resource> class ResourceManager
       
    80 {
       
    81 public:
       
    82 	ResourceManager() :
       
    83 		m_referenceCount(0),
       
    84 		m_resources()
       
    85 	{
       
    86 	}
       
    87 
       
    88 	~ResourceManager()
       
    89 	{
       
    90 		RI_ASSERT(m_referenceCount == 0);
       
    91 		RI_ASSERT(m_resources.size() == 0);
       
    92 	}
       
    93 
       
    94 	void			addReference()
       
    95 	{
       
    96 		m_referenceCount++;
       
    97 	}
       
    98 
       
    99 	int				removeReference()
       
   100 	{
       
   101 		m_referenceCount--;
       
   102 		RI_ASSERT(m_referenceCount >= 0);
       
   103 		return m_referenceCount;
       
   104 	}
       
   105 
       
   106 	void			addResource(Resource* resource, VGContext* context)
       
   107 	{
       
   108 		Entry r;
       
   109 		r.resource = resource;
       
   110 		r.context = context;
       
   111 		m_resources.push_back(r);	//throws bad_alloc
       
   112 		resource->addReference();
       
   113 	}
       
   114 
       
   115 	void			removeResource(Resource* resource)
       
   116 	{
       
   117 		if(!resource->removeReference())
       
   118 			RI_DELETE(resource);
       
   119 
       
   120 		int i=0;
       
   121 		bool found = false;
       
   122 		for(;i<m_resources.size();i++)
       
   123 		{
       
   124 			if(m_resources[i].resource == resource)
       
   125 			{
       
   126 				found = true;
       
   127 				break;
       
   128 			}
       
   129 		}
       
   130 		RI_ASSERT(found);
       
   131 
       
   132 		for(;i<m_resources.size()-1;i++)
       
   133 		{
       
   134 			m_resources[i] = m_resources[i+1];
       
   135 		}
       
   136 		m_resources.resize(m_resources.size()-1);
       
   137 	}
       
   138 
       
   139 	bool			isValid(Resource* resource)
       
   140 	{
       
   141 		for(int i=0;i<m_resources.size();i++)
       
   142 		{
       
   143 			if(m_resources[i].resource == resource)
       
   144 				return true;
       
   145 		}
       
   146 		return false;
       
   147 	}
       
   148 
       
   149 	Resource*		getFirstResource(VGContext* context)
       
   150 	{
       
   151 		for(int i=0;i<m_resources.size();i++)
       
   152 		{
       
   153 			if(m_resources[i].context == context)
       
   154 				return m_resources[i].resource;
       
   155 		}
       
   156 		return NULL;
       
   157 	}
       
   158 
       
   159 private:
       
   160 	ResourceManager(const ResourceManager&);
       
   161 	ResourceManager operator=(const ResourceManager&);
       
   162 
       
   163 	struct Entry
       
   164 	{
       
   165 		Resource*	resource;
       
   166 		VGContext*	context;
       
   167 	};
       
   168 
       
   169 	int				m_referenceCount;
       
   170 	Array<Entry>	m_resources;
       
   171 };
       
   172 
       
   173 /*-------------------------------------------------------------------*//*!
       
   174 * \brief	
       
   175 * \param	
       
   176 * \return	
       
   177 * \note		
       
   178 *//*-------------------------------------------------------------------*/
       
   179 
       
   180 class VGContext
       
   181 {
       
   182 public:
       
   183 	VGContext(VGContext* shareContext);	//throws bad_alloc
       
   184 	~VGContext();
       
   185 
       
   186     void            setDefaultDrawable(Drawable* drawable); //called from EGL
       
   187     Drawable*       getCurrentDrawable()        { return m_eglDrawable; }
       
   188 
       
   189 	bool			isValidImage(VGImage image);
       
   190 	bool			isValidPath(VGPath path);
       
   191 	bool			isValidPaint(VGPaint paint);
       
   192 	bool			isValidFont(VGFont font);
       
   193 	bool			isValidMaskLayer(VGMaskLayer layer);
       
   194 
       
   195 	void			releasePaint(VGbitfield paintModes);
       
   196 
       
   197 	void			setError(VGErrorCode error)		{ if(m_error == VG_NO_ERROR) m_error = error; }
       
   198 
       
   199 	// Mode settings
       
   200 	VGMatrixMode					m_matrixMode;
       
   201 	VGFillRule						m_fillRule;
       
   202 	VGImageQuality					m_imageQuality;
       
   203 	VGRenderingQuality				m_renderingQuality;
       
   204 	VGBlendMode						m_blendMode;
       
   205 	VGImageMode						m_imageMode;
       
   206 	
       
   207 	// Scissor rectangles
       
   208 	Array<Rectangle>				m_scissor;
       
   209 
       
   210 	// Stroke parameters
       
   211 	RIfloat							m_strokeLineWidth;
       
   212 	RIfloat							m_inputStrokeLineWidth;
       
   213 	VGCapStyle						m_strokeCapStyle;
       
   214 	VGJoinStyle						m_strokeJoinStyle;
       
   215 	RIfloat							m_strokeMiterLimit;
       
   216 	RIfloat							m_inputStrokeMiterLimit;
       
   217 	Array<RIfloat>					m_strokeDashPattern;
       
   218 	Array<RIfloat>					m_inputStrokeDashPattern;
       
   219 	RIfloat							m_strokeDashPhase;
       
   220 	RIfloat							m_inputStrokeDashPhase;
       
   221 	VGboolean						m_strokeDashPhaseReset;
       
   222 
       
   223 	// Edge fill color for vgConvolve and pattern paint
       
   224 	Color							m_tileFillColor;
       
   225 	Color							m_inputTileFillColor;
       
   226 
       
   227 	// Color for vgClear
       
   228 	Color							m_clearColor;
       
   229 	Color							m_inputClearColor;
       
   230 
       
   231     Vector2                         m_glyphOrigin;
       
   232     Vector2                         m_inputGlyphOrigin;
       
   233 
       
   234 	VGboolean						m_masking;
       
   235 	VGboolean						m_scissoring;
       
   236 
       
   237 	VGPixelLayout					m_pixelLayout;
       
   238 
       
   239 	VGboolean						m_filterFormatLinear;
       
   240 	VGboolean						m_filterFormatPremultiplied;
       
   241 	VGbitfield						m_filterChannelMask;
       
   242 
       
   243 	// Matrices
       
   244 	Matrix3x3						m_pathUserToSurface;
       
   245 	Matrix3x3						m_imageUserToSurface;
       
   246 	Matrix3x3						m_glyphUserToSurface;
       
   247 	Matrix3x3						m_fillPaintToUser;
       
   248 	Matrix3x3						m_strokePaintToUser;
       
   249 
       
   250 	VGPaint							m_fillPaint;
       
   251 	VGPaint							m_strokePaint;
       
   252 
       
   253     VGboolean                       m_colorTransform;
       
   254     RIfloat                         m_colorTransformValues[8];
       
   255     RIfloat                         m_inputColorTransformValues[8];
       
   256 
       
   257 	VGErrorCode						m_error;
       
   258 
       
   259 	ResourceManager<Image>*			m_imageManager;
       
   260 	ResourceManager<Path>*			m_pathManager;
       
   261 	ResourceManager<Paint>*			m_paintManager;
       
   262 	ResourceManager<Font>*			m_fontManager;
       
   263 	ResourceManager<Surface>*		m_maskLayerManager;
       
   264 private:
       
   265 	Drawable*                       m_eglDrawable;
       
   266 
       
   267 	VGContext(const VGContext&);			//!< Not allowed.
       
   268 	void operator=(const VGContext&);		//!< Not allowed.
       
   269 };
       
   270 
       
   271 //==============================================================================================
       
   272 
       
   273 }	//namespace OpenVGRI
       
   274 
       
   275 //==============================================================================================
       
   276 
       
   277 #endif /* __RICONTEXT_H */