|
1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 * |
|
3 * Permission is hereby granted, free of charge, to any person obtaining a |
|
4 * copy of this software and /or associated documentation files |
|
5 * (the "Materials "), to deal in the Materials without restriction, |
|
6 * including without limitation the rights to use, copy, modify, merge, |
|
7 * publish, distribute, sublicense, and/or sell copies of the Materials, |
|
8 * and to permit persons to whom the Materials are furnished to do so, |
|
9 * subject to the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice shall be included |
|
12 * in all copies or substantial portions of the Materials. |
|
13 * |
|
14 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
20 * THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
21 */ |
|
22 |
|
23 #include "sfBlitter.h" |
|
24 |
|
25 #include "sfCompiler.h" |
|
26 |
|
27 namespace OpenVGRI { |
|
28 |
|
29 DynamicBlitter::DynamicBlitter() : |
|
30 m_maskOperation(VG_SET_MASK), |
|
31 m_isMaskOperation(false), |
|
32 m_fillColor(), |
|
33 m_isFill(false), |
|
34 |
|
35 m_signatureState(), |
|
36 m_uniforms() |
|
37 { |
|
38 } |
|
39 |
|
40 DynamicBlitter::~DynamicBlitter() |
|
41 { |
|
42 } |
|
43 |
|
44 /*static*/ void DynamicBlitter::calculateHash(BlitterHash& hash, const BlitSignatureState& state) |
|
45 { |
|
46 const RIuint32 descBits = 10; |
|
47 const RIuint32 maskOperationBits = 3; |
|
48 const RIuint32 boolBits = 1; |
|
49 |
|
50 RIuint32 srcFormat = (RIuint32)(state.srcDesc.toIndex()); |
|
51 RIuint32 dstFormat = (RIuint32)(state.dstDesc.toIndex()); |
|
52 RIuint32 maskOperation = ((RIuint32)(state.maskOperation - VG_CLEAR_MASK)); |
|
53 RIuint32 incompatibleStride = ((RIuint32)state.incompatibleStrides); |
|
54 RIuint32 isMaskOperation = ((RIuint32)state.isMaskOperation); |
|
55 RIuint32 unsafeInput = (RIuint32)state.unsafeInput; |
|
56 |
|
57 int b = 0; |
|
58 |
|
59 b = riInsertBits32(hash.value, sizeof(hash.value), srcFormat, descBits, b); |
|
60 b = riInsertBits32(hash.value, sizeof(hash.value), dstFormat, descBits, b); |
|
61 b = riInsertBits32(hash.value, sizeof(hash.value), maskOperation, maskOperationBits, b); |
|
62 b = riInsertBits32(hash.value, sizeof(hash.value), incompatibleStride, boolBits, b); |
|
63 b = riInsertBits32(hash.value, sizeof(hash.value), isMaskOperation, boolBits, b); |
|
64 b = riInsertBits32(hash.value, sizeof(hash.value), unsafeInput, boolBits, b); |
|
65 } |
|
66 |
|
67 /** |
|
68 * \brief Blit a region. The input coordinates and dimensions must be validated outside |
|
69 * the blitter currently. |
|
70 * \note The user must also apply the storage offset to the image(s). |
|
71 */ |
|
72 void DynamicBlitter::prepareBlit(Image* dst, const Image* src, int sx, int sy, int dx, int dy, int w, int h) |
|
73 { |
|
74 //const Image *srcImage = src->getImage(); |
|
75 //Image* dstImage = dst->m_image; |
|
76 |
|
77 // \todo Move these to derivation of the state? |
|
78 m_signatureState.srcDesc = src->getDescriptor(); |
|
79 m_signatureState.dstDesc = dst->getDescriptor(); |
|
80 m_signatureState.isMaskOperation = m_isMaskOperation; |
|
81 m_signatureState.maskOperation = m_isMaskOperation ? m_maskOperation : VG_CLEAR_MASK; |
|
82 m_signatureState.incompatibleStrides = false; |
|
83 m_signatureState.unsafeInput = false; |
|
84 |
|
85 m_uniforms.src = src->getData(); |
|
86 m_uniforms.dst = dst->getData(); |
|
87 m_uniforms.srcX = sx; |
|
88 m_uniforms.srcY = sy; |
|
89 m_uniforms.dstX = dx; |
|
90 m_uniforms.dstY = dy; |
|
91 m_uniforms.width = w; |
|
92 m_uniforms.height = h; |
|
93 m_uniforms.srcStride = src->getStride(); |
|
94 m_uniforms.dstStride = dst->getStride(); |
|
95 |
|
96 if (m_signatureState.srcDesc.isZeroConversion(m_signatureState.dstDesc)) |
|
97 { |
|
98 const int fullCopyStride = Image::descriptorToStride(m_signatureState.srcDesc, m_uniforms.width); |
|
99 |
|
100 if ((m_uniforms.dstStride != m_uniforms.srcStride) || (fullCopyStride != m_uniforms.srcStride)) |
|
101 m_signatureState.incompatibleStrides = true; |
|
102 } |
|
103 |
|
104 if (src->isUnsafe()) |
|
105 m_signatureState.unsafeInput = true; |
|
106 |
|
107 } |
|
108 |
|
109 void DynamicBlitter::blit() |
|
110 { |
|
111 #if 1 |
|
112 bool compiledBlitter = false; |
|
113 { |
|
114 PPCompiler& compiler = PPCompiler::getCompiler(); |
|
115 PPCompiler::BlitterHandle blitterHandle = compiler.compileBlitter(getSignatureState()); |
|
116 if (blitterHandle) |
|
117 { |
|
118 compiledBlitter = true; |
|
119 BlitterFunction func = compiler.getBlitterPtr(blitterHandle); |
|
120 func(getUniforms()); |
|
121 compiler.releaseBlitter(blitterHandle); |
|
122 } |
|
123 } |
|
124 |
|
125 if (!compiledBlitter) |
|
126 #endif |
|
127 { |
|
128 executeBlitter(getSignatureState(), getUniforms()); |
|
129 } |
|
130 } |
|
131 |
|
132 } |