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