author | William Roberts <williamr@symbian.org> |
Thu, 03 Jun 2010 17:45:05 +0100 | |
branch | EGL_MERGE |
changeset 88 | a5a3a8cb368e |
permissions | -rw-r--r-- |
88
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
1 |
/*------------------------------------------------------------------------ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
2 |
* |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
3 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
4 |
* |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
6 |
* copy of this software and /or associated documentation files |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
7 |
* (the "Materials "), to deal in the Materials without restriction, |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
8 |
* including without limitation the rights to use, copy, modify, merge, |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
9 |
* publish, distribute, sublicense, and/or sell copies of the Materials, |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
10 |
* and to permit persons to whom the Materials are furnished to do so, |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
11 |
* subject to the following conditions: |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
12 |
* |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
13 |
* The above copyright notice and this permission notice shall be included |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
14 |
* in all copies or substantial portions of the Materials. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
15 |
* |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
16 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
18 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
19 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
20 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
21 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
22 |
* THE USE OR OTHER DEALINGS IN THE MATERIALS. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
23 |
* |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
24 |
*//*-------------------------------------------------------------------*/ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
25 |
|
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
26 |
#ifndef __RIUTILS_H_ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
27 |
# include "riUtils.h" |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
28 |
#endif |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
29 |
|
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
30 |
#include <string.h> |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
31 |
|
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
32 |
namespace OpenVGRI |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
33 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
34 |
|
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
35 |
/** |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
36 |
* \brief Sets mem areas to byte(s) in c. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
37 |
* \param dst Destination pointer. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
38 |
* \param c Data to set into dst. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
39 |
* \param nElements Amount of elements to set. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
40 |
* \param nBytesPerElement Amount of bytes for each element. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
41 |
* \note This is moslty an image-settings support function. It is assumed that several |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
42 |
* bytes / elements can be set at once, especially in 3-byte case. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
43 |
*/ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
44 |
void riMemSet32(void* dst, RIuint32 c, size_t nElements, size_t nBytesPerElement) |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
45 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
46 |
// \todo This function should be called from a function that handles npot element sizes. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
47 |
// \todo Investigate the status of (open) std::fill implementations. Some of that code |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
48 |
// did not _seem_ to bundle sets or use SSE, etc. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
49 |
// \todo Use SSE instructions on Intel? |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
50 |
|
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
51 |
RI_ASSERT(dst); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
52 |
RI_ASSERT(nElements); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
53 |
|
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
54 |
switch(nBytesPerElement) |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
55 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
56 |
case 4: |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
57 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
58 |
RIuint32* ptr = (RIuint32*)dst; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
59 |
do { |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
60 |
*ptr++ = c; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
61 |
} while(--nElements); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
62 |
break; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
63 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
64 |
case 3: |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
65 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
66 |
// \todo Endianness. |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
67 |
RIuint8* ptr = (RIuint8*)dst; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
68 |
RIuint8 b[3]; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
69 |
b[0] = c & 0xff; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
70 |
b[1] = (c >> 8)&0xff; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
71 |
b[2] = (c >> 16)&0xff; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
72 |
do { |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
73 |
*ptr++ = b[0]; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
74 |
*ptr++ = b[1]; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
75 |
*ptr++ = b[2]; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
76 |
} while(--nElements); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
77 |
break; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
78 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
79 |
case 2: |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
80 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
81 |
size_t dws = nElements / 2; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
82 |
if (dws) |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
83 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
84 |
RIuint32* ptr32 = (RIuint32*)dst; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
85 |
dst = (void*)(((RIuint8*)dst + dws * 4)); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
86 |
RIuint32 dw = c | (c<<16); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
87 |
do { |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
88 |
*ptr32++ = dw; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
89 |
} while(--dws); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
90 |
nElements &= 0x01; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
91 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
92 |
if (nElements) |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
93 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
94 |
RIuint16 *ptr16 = (RIuint16*)dst; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
95 |
const RIuint16 w = (RIuint16)c; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
96 |
do { |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
97 |
*ptr16++ = w; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
98 |
} while(--nElements); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
99 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
100 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
101 |
case 1: |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
102 |
{ |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
103 |
memset(dst, c, nElements); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
104 |
break; |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
105 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
106 |
default: |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
107 |
RI_ASSERT(false); |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
108 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
109 |
|
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
110 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
111 |
|
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
112 |
} |
a5a3a8cb368e
Merge the OpenVG RI optimisations into the extra copy of sfopenvg
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
113 |