24
|
1 |
/*------------------------------------------------------------------------
|
|
2 |
*
|
|
3 |
* OpenVG 1.1 Reference Implementation
|
|
4 |
* -----------------------------------
|
|
5 |
*
|
|
6 |
* Copyright (c) 2007 The Khronos Group Inc.
|
|
7 |
*
|
|
8 |
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
9 |
* copy of this software and /or associated documentation files
|
|
10 |
* (the "Materials "), to deal in the Materials without restriction,
|
|
11 |
* including without limitation the rights to use, copy, modify, merge,
|
|
12 |
* publish, distribute, sublicense, and/or sell copies of the Materials,
|
|
13 |
* and to permit persons to whom the Materials are furnished to do so,
|
|
14 |
* subject to the following conditions:
|
|
15 |
*
|
|
16 |
* The above copyright notice and this permission notice shall be included
|
|
17 |
* in all copies or substantial portions of the Materials.
|
|
18 |
*
|
|
19 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
20 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
21 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
22 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
23 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
24 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
|
|
25 |
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
26 |
*
|
|
27 |
*//**
|
|
28 |
* \file
|
|
29 |
* \brief Implementation of VGContext functions.
|
|
30 |
* \note
|
|
31 |
*//*-------------------------------------------------------------------*/
|
|
32 |
|
|
33 |
#include "riContext.h"
|
|
34 |
|
|
35 |
namespace OpenVGRI
|
|
36 |
{
|
|
37 |
|
|
38 |
/*-------------------------------------------------------------------*//*!
|
|
39 |
* \brief VGContext constructor.
|
|
40 |
* \param
|
|
41 |
* \return
|
|
42 |
* \note
|
|
43 |
*//*-------------------------------------------------------------------*/
|
|
44 |
|
|
45 |
VGContext::VGContext(VGContext* shareContext) :
|
|
46 |
// Mode settings
|
|
47 |
m_matrixMode(VG_MATRIX_PATH_USER_TO_SURFACE),
|
|
48 |
m_fillRule(VG_EVEN_ODD),
|
|
49 |
m_imageQuality(VG_IMAGE_QUALITY_FASTER),
|
|
50 |
m_renderingQuality(VG_RENDERING_QUALITY_BETTER),
|
|
51 |
m_blendMode(VG_BLEND_SRC_OVER),
|
|
52 |
m_imageMode(VG_DRAW_IMAGE_NORMAL),
|
|
53 |
|
|
54 |
// Scissor rectangles
|
|
55 |
m_scissor(),
|
|
56 |
|
|
57 |
// Stroke parameters
|
|
58 |
m_strokeLineWidth(1.0f),
|
|
59 |
m_inputStrokeLineWidth(1.0f),
|
|
60 |
m_strokeCapStyle(VG_CAP_BUTT),
|
|
61 |
m_strokeJoinStyle(VG_JOIN_MITER),
|
|
62 |
m_strokeMiterLimit(4.0f),
|
|
63 |
m_inputStrokeMiterLimit(4.0f),
|
|
64 |
m_strokeDashPattern(),
|
|
65 |
m_inputStrokeDashPattern(),
|
|
66 |
m_strokeDashPhase(0.0f),
|
|
67 |
m_inputStrokeDashPhase(0.0f),
|
|
68 |
m_strokeDashPhaseReset(VG_FALSE),
|
|
69 |
|
|
70 |
// Edge fill color for vgConvolve and pattern paint
|
|
71 |
m_tileFillColor(0,0,0,0, Color::sRGBA),
|
|
72 |
m_inputTileFillColor(0,0,0,0, Color::sRGBA),
|
|
73 |
|
|
74 |
// Color for vgClear
|
|
75 |
m_clearColor(0,0,0,0, Color::sRGBA),
|
|
76 |
m_inputClearColor(0,0,0,0, Color::sRGBA),
|
|
77 |
|
|
78 |
m_glyphOrigin(0.0f, 0.0f),
|
|
79 |
m_inputGlyphOrigin(0.0f, 0.0f),
|
|
80 |
|
|
81 |
m_masking(VG_FALSE),
|
|
82 |
m_scissoring(VG_FALSE),
|
|
83 |
|
|
84 |
m_pixelLayout(VG_PIXEL_LAYOUT_UNKNOWN),
|
|
85 |
|
|
86 |
m_filterFormatLinear(VG_FALSE),
|
|
87 |
m_filterFormatPremultiplied(VG_FALSE),
|
|
88 |
m_filterChannelMask(VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA),
|
|
89 |
|
|
90 |
// Matrices
|
|
91 |
m_pathUserToSurface(),
|
|
92 |
m_imageUserToSurface(),
|
|
93 |
m_glyphUserToSurface(),
|
|
94 |
m_fillPaintToUser(),
|
|
95 |
m_strokePaintToUser(),
|
|
96 |
|
|
97 |
m_fillPaint(VG_INVALID_HANDLE),
|
|
98 |
m_strokePaint(VG_INVALID_HANDLE),
|
|
99 |
|
|
100 |
m_colorTransform(VG_FALSE),
|
|
101 |
m_colorTransformValues(),
|
|
102 |
m_inputColorTransformValues(),
|
|
103 |
|
|
104 |
m_error(VG_NO_ERROR),
|
|
105 |
|
|
106 |
m_imageManager(NULL),
|
|
107 |
m_pathManager(NULL),
|
|
108 |
m_paintManager(NULL),
|
|
109 |
m_fontManager(NULL),
|
|
110 |
m_maskLayerManager(NULL),
|
|
111 |
|
|
112 |
m_eglDrawable(NULL)
|
|
113 |
{
|
|
114 |
if(shareContext)
|
|
115 |
{
|
|
116 |
m_imageManager = shareContext->m_imageManager;
|
|
117 |
m_pathManager = shareContext->m_pathManager;
|
|
118 |
m_paintManager = shareContext->m_paintManager;
|
|
119 |
m_fontManager = shareContext->m_fontManager;
|
|
120 |
m_maskLayerManager = shareContext->m_maskLayerManager;
|
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
try
|
|
125 |
{
|
|
126 |
m_imageManager = RI_NEW(OpenVGRI::ResourceManager<Image>, ()); //throws bad_alloc
|
|
127 |
m_pathManager = RI_NEW(OpenVGRI::ResourceManager<Path>, ()); //throws bad_alloc
|
|
128 |
m_paintManager = RI_NEW(OpenVGRI::ResourceManager<Paint>, ()); //throws bad_alloc
|
|
129 |
m_fontManager = RI_NEW(OpenVGRI::ResourceManager<Font>, ()); //throws bad_alloc
|
|
130 |
m_maskLayerManager = RI_NEW(OpenVGRI::ResourceManager<Surface>, ()); //throws bad_alloc
|
|
131 |
}
|
|
132 |
catch(std::bad_alloc)
|
|
133 |
{
|
|
134 |
RI_DELETE(m_imageManager);
|
|
135 |
RI_DELETE(m_pathManager);
|
|
136 |
RI_DELETE(m_paintManager);
|
|
137 |
RI_DELETE(m_fontManager);
|
|
138 |
RI_DELETE(m_maskLayerManager);
|
|
139 |
|
|
140 |
throw;
|
|
141 |
}
|
|
142 |
}
|
|
143 |
RI_ASSERT(m_imageManager);
|
|
144 |
RI_ASSERT(m_pathManager);
|
|
145 |
RI_ASSERT(m_paintManager);
|
|
146 |
RI_ASSERT(m_fontManager);
|
|
147 |
RI_ASSERT(m_maskLayerManager);
|
|
148 |
|
|
149 |
m_imageManager->addReference();
|
|
150 |
m_pathManager->addReference();
|
|
151 |
m_paintManager->addReference();
|
|
152 |
m_fontManager->addReference();
|
|
153 |
m_maskLayerManager->addReference();
|
|
154 |
|
|
155 |
m_inputColorTransformValues[0] = 1.0f;
|
|
156 |
m_inputColorTransformValues[1] = 1.0f;
|
|
157 |
m_inputColorTransformValues[2] = 1.0f;
|
|
158 |
m_inputColorTransformValues[3] = 1.0f;
|
|
159 |
m_inputColorTransformValues[4] = 0.0f;
|
|
160 |
m_inputColorTransformValues[5] = 0.0f;
|
|
161 |
m_inputColorTransformValues[6] = 0.0f;
|
|
162 |
m_inputColorTransformValues[7] = 0.0f;
|
|
163 |
m_colorTransformValues[0] = 1.0f;
|
|
164 |
m_colorTransformValues[1] = 1.0f;
|
|
165 |
m_colorTransformValues[2] = 1.0f;
|
|
166 |
m_colorTransformValues[3] = 1.0f;
|
|
167 |
m_colorTransformValues[4] = 0.0f;
|
|
168 |
m_colorTransformValues[5] = 0.0f;
|
|
169 |
m_colorTransformValues[6] = 0.0f;
|
|
170 |
m_colorTransformValues[7] = 0.0f;
|
|
171 |
|
|
172 |
}
|
|
173 |
|
|
174 |
/*-------------------------------------------------------------------*//*!
|
|
175 |
* \brief VGContext destructor.
|
|
176 |
* \param
|
|
177 |
* \return
|
|
178 |
* \note
|
|
179 |
*//*-------------------------------------------------------------------*/
|
|
180 |
|
|
181 |
VGContext::~VGContext()
|
|
182 |
{
|
|
183 |
releasePaint(VG_FILL_PATH | VG_STROKE_PATH);
|
|
184 |
setDefaultDrawable(NULL);
|
|
185 |
|
|
186 |
//destroy own images, paths and paints
|
|
187 |
while(Image* i = m_imageManager->getFirstResource(this))
|
|
188 |
m_imageManager->removeResource(i);
|
|
189 |
while(Path* p = m_pathManager->getFirstResource(this))
|
|
190 |
m_pathManager->removeResource(p);
|
|
191 |
while(Paint* t = m_paintManager->getFirstResource(this))
|
|
192 |
m_paintManager->removeResource(t);
|
|
193 |
while(Font* t = m_fontManager->getFirstResource(this))
|
|
194 |
m_fontManager->removeResource(t);
|
|
195 |
while(Surface* t = m_maskLayerManager->getFirstResource(this))
|
|
196 |
m_maskLayerManager->removeResource(t);
|
|
197 |
|
|
198 |
//decrease the reference count of resource managers
|
|
199 |
if(!m_imageManager->removeReference())
|
|
200 |
RI_DELETE(m_imageManager);
|
|
201 |
if(!m_pathManager->removeReference())
|
|
202 |
RI_DELETE(m_pathManager);
|
|
203 |
if(!m_paintManager->removeReference())
|
|
204 |
RI_DELETE(m_paintManager);
|
|
205 |
if(!m_fontManager->removeReference())
|
|
206 |
RI_DELETE(m_fontManager);
|
|
207 |
if(!m_maskLayerManager->removeReference())
|
|
208 |
RI_DELETE(m_maskLayerManager);
|
|
209 |
}
|
|
210 |
|
|
211 |
/*-------------------------------------------------------------------*//*!
|
|
212 |
* \brief Sets new default drawable.
|
|
213 |
* \param drawable New drawable or NULL when context is unbound
|
|
214 |
* \return
|
|
215 |
* \note
|
|
216 |
*//*-------------------------------------------------------------------*/
|
|
217 |
|
|
218 |
void VGContext::setDefaultDrawable(Drawable* drawable)
|
|
219 |
{
|
|
220 |
if(m_eglDrawable)
|
|
221 |
{
|
|
222 |
if(!m_eglDrawable->removeReference())
|
|
223 |
RI_DELETE(m_eglDrawable);
|
|
224 |
}
|
|
225 |
m_eglDrawable = drawable;
|
|
226 |
if(m_eglDrawable)
|
|
227 |
{
|
|
228 |
m_eglDrawable->addReference();
|
|
229 |
}
|
|
230 |
}
|
|
231 |
|
|
232 |
/*-------------------------------------------------------------------*//*!
|
|
233 |
* \brief Returns true if the given image is generated through any
|
|
234 |
* context that is shared with this one.
|
|
235 |
* \param
|
|
236 |
* \return
|
|
237 |
* \note
|
|
238 |
*//*-------------------------------------------------------------------*/
|
|
239 |
|
|
240 |
bool VGContext::isValidImage(VGImage image)
|
|
241 |
{
|
|
242 |
return m_imageManager->isValid((Image*)image);
|
|
243 |
}
|
|
244 |
|
|
245 |
/*-------------------------------------------------------------------*//*!
|
|
246 |
* \brief Returns true if the given path is generated through any
|
|
247 |
* context that is shared with this one.
|
|
248 |
* \param
|
|
249 |
* \return
|
|
250 |
* \note
|
|
251 |
*//*-------------------------------------------------------------------*/
|
|
252 |
|
|
253 |
bool VGContext::isValidPath(VGPath path)
|
|
254 |
{
|
|
255 |
return m_pathManager->isValid((Path*)path);
|
|
256 |
}
|
|
257 |
|
|
258 |
/*-------------------------------------------------------------------*//*!
|
|
259 |
* \brief Returns true if the given paint is generated through any
|
|
260 |
* context that is shared with this one.
|
|
261 |
* \param
|
|
262 |
* \return
|
|
263 |
* \note
|
|
264 |
*//*-------------------------------------------------------------------*/
|
|
265 |
|
|
266 |
bool VGContext::isValidPaint(VGPaint paint)
|
|
267 |
{
|
|
268 |
return m_paintManager->isValid((Paint*)paint);
|
|
269 |
}
|
|
270 |
|
|
271 |
/*-------------------------------------------------------------------*//*!
|
|
272 |
* \brief Returns true if the given font is generated through any
|
|
273 |
* context that is shared with this one.
|
|
274 |
* \param
|
|
275 |
* \return
|
|
276 |
* \note
|
|
277 |
*//*-------------------------------------------------------------------*/
|
|
278 |
|
|
279 |
bool VGContext::isValidFont(VGFont font)
|
|
280 |
{
|
|
281 |
return m_fontManager->isValid((Font*)font);
|
|
282 |
}
|
|
283 |
|
|
284 |
/*-------------------------------------------------------------------*//*!
|
|
285 |
* \brief Returns true if the given mask layer is generated through any
|
|
286 |
* context that is shared with this one.
|
|
287 |
* \param
|
|
288 |
* \return
|
|
289 |
* \note
|
|
290 |
*//*-------------------------------------------------------------------*/
|
|
291 |
|
|
292 |
bool VGContext::isValidMaskLayer(VGMaskLayer layer)
|
|
293 |
{
|
|
294 |
return m_maskLayerManager->isValid((Surface*)layer);
|
|
295 |
}
|
|
296 |
|
|
297 |
/*-------------------------------------------------------------------*//*!
|
|
298 |
* \brief Releases the given paint objects of the context.
|
|
299 |
* \param
|
|
300 |
* \return
|
|
301 |
* \note
|
|
302 |
*//*-------------------------------------------------------------------*/
|
|
303 |
|
|
304 |
void VGContext::releasePaint(VGbitfield paintModes)
|
|
305 |
{
|
|
306 |
if(paintModes & VG_FILL_PATH)
|
|
307 |
{
|
|
308 |
//release previous paint
|
|
309 |
Paint* prev = (Paint*)m_fillPaint;
|
|
310 |
if(prev)
|
|
311 |
{
|
|
312 |
if(!prev->removeReference())
|
|
313 |
RI_DELETE(prev);
|
|
314 |
}
|
|
315 |
m_fillPaint = VG_INVALID_HANDLE;
|
|
316 |
}
|
|
317 |
if(paintModes & VG_STROKE_PATH)
|
|
318 |
{
|
|
319 |
//release previous paint
|
|
320 |
Paint* prev = (Paint*)m_strokePaint;
|
|
321 |
if(prev)
|
|
322 |
{
|
|
323 |
if(!prev->removeReference())
|
|
324 |
RI_DELETE(prev);
|
|
325 |
}
|
|
326 |
m_strokePaint = VG_INVALID_HANDLE;
|
|
327 |
}
|
|
328 |
}
|
|
329 |
|
|
330 |
//==============================================================================================
|
|
331 |
|
|
332 |
} //namespace OpenVGRI
|