|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "HuiFxVisualLayer.h" |
|
21 #include "Matrix.h" |
|
22 #include "HuiFxParameterManager.h" |
|
23 #include <uiacceltk/HuiVisual.h> |
|
24 #include "HuiFxConstants.h" |
|
25 #include <e32math.h> |
|
26 #include "HuiCmdBufferBrush.h" |
|
27 |
|
28 EXPORT_C CHuiFxVisualLayer* CHuiFxVisualLayer::NewL(MHuiEffectable& aVisual) |
|
29 { |
|
30 CHuiFxVisualLayer* e = new (ELeave) CHuiFxVisualLayer(); |
|
31 CleanupStack::PushL(e); |
|
32 e->ConstructL(aVisual); |
|
33 CleanupStack::Pop(e); |
|
34 return e; |
|
35 } |
|
36 |
|
37 EXPORT_C void CHuiFxVisualLayer::ConstructL(MHuiEffectable& aVisual) |
|
38 { |
|
39 #ifdef HUIFX_TRACE |
|
40 RDebug::Print(_L("CHuiFxVisualLayer::ConstructL - 0x%x "), this); |
|
41 #endif |
|
42 CHuiFxLayer::ConstructL( ELayerTypeVisual ); |
|
43 iParameterManager = CHuiFxParameterManager::NewL(); |
|
44 iVisual = &aVisual; |
|
45 iSrcType = EVisualSrcVisual; |
|
46 iExtBitmapFile = NULL; |
|
47 |
|
48 iTranslationX = 0.0f; |
|
49 iTranslationY = 0.0f; |
|
50 iTranslationZ = 0.0f; |
|
51 |
|
52 iScaleX = 1.0f; |
|
53 iScaleY = 1.0f; |
|
54 iScaleZ = 1.0f; |
|
55 iScaleOriginX = 0.0f; |
|
56 iScaleOriginY = 0.0f; |
|
57 iScaleOriginZ = 0.0f; |
|
58 |
|
59 iRotationOriginX = 0.0f; |
|
60 iRotationOriginY = 0.0f; |
|
61 iRotationOriginZ = 0.0f; |
|
62 iRotationAngle = 0.0f; |
|
63 iRotationAxisX = 0.0f; |
|
64 iRotationAxisY = 0.0f; |
|
65 iRotationAxisZ = 1.0f; |
|
66 |
|
67 iSkewAngleX = 0.0f; |
|
68 iSkewAngleY = 0.0f; |
|
69 iSkewAngleZ = 0.0f; |
|
70 iSkewOriginX = 0.0f; |
|
71 iSkewOriginY = 0.0f; |
|
72 iSkewOriginZ = 0.0f; |
|
73 |
|
74 // We use the visual's own target opacity if we haven't set something explicitly |
|
75 if (iVisual) |
|
76 { |
|
77 //iOpacity = iVisual->iOpacity.Target(); |
|
78 iOpacity = iVisual->EffectOpacityTarget(); |
|
79 } |
|
80 else |
|
81 { |
|
82 iOpacity = 1.0; |
|
83 } |
|
84 RegisterParameterL(KLitTranslationX, &iTranslationX); |
|
85 RegisterParameterL(KLitTranslationY, &iTranslationY); |
|
86 RegisterParameterL(KLitTranslationZ, &iTranslationZ); |
|
87 |
|
88 RegisterParameterL(KLitScaleX, &iScaleX); |
|
89 RegisterParameterL(KLitScaleY, &iScaleY); |
|
90 RegisterParameterL(KLitScaleZ, &iScaleZ); |
|
91 RegisterParameterL(KLitScaleOriginX, &iScaleOriginX); |
|
92 RegisterParameterL(KLitScaleOriginY, &iScaleOriginY); |
|
93 RegisterParameterL(KLitScaleOriginZ, &iScaleOriginZ); |
|
94 |
|
95 RegisterParameterL(KLitRotationOriginX, &iRotationOriginX); |
|
96 RegisterParameterL(KLitRotationOriginY, &iRotationOriginY); |
|
97 RegisterParameterL(KLitRotationOriginZ, &iRotationOriginZ); |
|
98 RegisterParameterL(KLitRotationAngle, &iRotationAngle); |
|
99 RegisterParameterL(KLitRotationAxisX, &iRotationAxisX); |
|
100 RegisterParameterL(KLitRotationAxisY, &iRotationAxisY); |
|
101 RegisterParameterL(KLitRotationAxisZ, &iRotationAxisZ); |
|
102 |
|
103 RegisterParameterL(KLitSkewAngleX, &iSkewAngleX); |
|
104 RegisterParameterL(KLitSkewAngleY, &iSkewAngleY); |
|
105 RegisterParameterL(KLitSkewAngleZ, &iSkewAngleZ); |
|
106 RegisterParameterL(KLitSkewOriginX, &iSkewOriginX); |
|
107 RegisterParameterL(KLitSkewOriginY, &iSkewOriginY); |
|
108 RegisterParameterL(KLitSkewOriginZ, &iSkewOriginZ); |
|
109 |
|
110 RegisterParameterL(KLitOpacityParameter, &iOpacity); |
|
111 } |
|
112 |
|
113 EXPORT_C CHuiFxVisualLayer *CHuiFxVisualLayer::CloneL() const |
|
114 { |
|
115 CHuiFxVisualLayer *layer = new (ELeave) CHuiFxVisualLayer; |
|
116 layer->CHuiFxLayer::ConstructL( ELayerTypeVisual ); |
|
117 layer->CHuiFxLayer::CopyFromL(this); |
|
118 layer->iVisual = iVisual; // visual will be set later... |
|
119 layer->iParameterManager = iParameterManager->CloneL(); |
|
120 layer->iParameterManager->CopyParameterL(KLitTranslationX, &layer->iTranslationX, iParameterManager); |
|
121 layer->iParameterManager->CopyParameterL(KLitTranslationY, &layer->iTranslationY, iParameterManager); |
|
122 layer->iParameterManager->CopyParameterL(KLitTranslationZ, &layer->iTranslationZ, iParameterManager); |
|
123 |
|
124 layer->iParameterManager->CopyParameterL(KLitScaleX, &layer->iScaleX, iParameterManager); |
|
125 layer->iParameterManager->CopyParameterL(KLitScaleY, &layer->iScaleY, iParameterManager); |
|
126 layer->iParameterManager->CopyParameterL(KLitScaleZ, &layer->iScaleZ, iParameterManager); |
|
127 layer->iParameterManager->CopyParameterL(KLitScaleOriginX, &layer->iScaleOriginX, iParameterManager); |
|
128 layer->iParameterManager->CopyParameterL(KLitScaleOriginY, &layer->iScaleOriginY, iParameterManager); |
|
129 layer->iParameterManager->CopyParameterL(KLitScaleOriginZ, &layer->iScaleOriginZ, iParameterManager); |
|
130 |
|
131 layer->iParameterManager->CopyParameterL(KLitRotationOriginX, &layer->iRotationOriginX, iParameterManager); |
|
132 layer->iParameterManager->CopyParameterL(KLitRotationOriginY, &layer->iRotationOriginY, iParameterManager); |
|
133 layer->iParameterManager->CopyParameterL(KLitRotationOriginZ, &layer->iRotationOriginZ, iParameterManager); |
|
134 layer->iParameterManager->CopyParameterL(KLitRotationAngle, &layer->iRotationAngle, iParameterManager); |
|
135 layer->iParameterManager->CopyParameterL(KLitRotationAxisX, &layer->iRotationAxisX, iParameterManager); |
|
136 layer->iParameterManager->CopyParameterL(KLitRotationAxisY, &layer->iRotationAxisY, iParameterManager); |
|
137 layer->iParameterManager->CopyParameterL(KLitRotationAxisZ, &layer->iRotationAxisZ, iParameterManager); |
|
138 |
|
139 layer->iParameterManager->CopyParameterL(KLitSkewAngleX, &layer->iSkewAngleX, iParameterManager); |
|
140 layer->iParameterManager->CopyParameterL(KLitSkewAngleY, &layer->iSkewAngleY, iParameterManager); |
|
141 layer->iParameterManager->CopyParameterL(KLitSkewAngleZ, &layer->iSkewAngleZ, iParameterManager); |
|
142 layer->iParameterManager->CopyParameterL(KLitSkewOriginX, &layer->iSkewOriginX, iParameterManager); |
|
143 layer->iParameterManager->CopyParameterL(KLitSkewOriginY, &layer->iSkewOriginY, iParameterManager); |
|
144 layer->iParameterManager->CopyParameterL(KLitSkewOriginZ, &layer->iSkewOriginZ, iParameterManager); |
|
145 |
|
146 layer->iParameterManager->CopyParameterL(KLitOpacityParameter, &layer->iOpacity, iParameterManager); |
|
147 |
|
148 layer->iSrcType = iSrcType; |
|
149 layer->iTranslationX = iTranslationX; |
|
150 layer->iTranslationY = iTranslationY; |
|
151 layer->iTranslationZ = iTranslationZ; |
|
152 layer->iScaleX = iScaleX; |
|
153 layer->iScaleY = iScaleY; |
|
154 layer->iScaleZ = iScaleZ; |
|
155 layer->iScaleOriginX = iScaleOriginX; |
|
156 layer->iScaleOriginY = iScaleOriginY; |
|
157 layer->iScaleOriginZ = iScaleOriginZ; |
|
158 layer->iRotationOriginX = iRotationOriginX; |
|
159 layer->iRotationOriginY = iRotationOriginY; |
|
160 layer->iRotationOriginZ = iRotationOriginZ; |
|
161 layer->iRotationAngle = iRotationAngle; |
|
162 layer->iRotationAxisX = iRotationAxisX; |
|
163 layer->iRotationAxisY = iRotationAxisY; |
|
164 layer->iRotationAxisZ = iRotationAxisZ; |
|
165 layer->iSkewAngleX = iSkewAngleX; |
|
166 layer->iSkewAngleY = iSkewAngleY; |
|
167 layer->iSkewAngleZ = iSkewAngleZ; |
|
168 |
|
169 layer->iSkewOriginX = iSkewOriginX; |
|
170 layer->iSkewOriginY = iSkewOriginY; |
|
171 layer->iSkewOriginZ = iSkewOriginZ; |
|
172 if (iExtBitmapFile) |
|
173 layer->iExtBitmapFile = iExtBitmapFile->AllocL(); |
|
174 else |
|
175 layer->iExtBitmapFile = NULL; |
|
176 layer->iOpacity = iOpacity; |
|
177 return layer; |
|
178 } |
|
179 EXPORT_C void CHuiFxVisualLayer::SetExtRect( TRect * /*aExtRect*/ ) |
|
180 { |
|
181 // not needed.. |
|
182 } |
|
183 EXPORT_C void CHuiFxVisualLayer::SetVisual( CHuiVisual * aVisual ) |
|
184 { |
|
185 iVisual = aVisual->Effectable(); |
|
186 |
|
187 if (Math::IsInfinite(iOpacity)) |
|
188 { |
|
189 iOpacity = aVisual->iOpacity.Target(); |
|
190 } |
|
191 } |
|
192 EXPORT_C void CHuiFxVisualLayer::SetVisual( MHuiEffectable *aVisual ) |
|
193 { |
|
194 iVisual = aVisual; |
|
195 |
|
196 if (Math::IsInfinite(iOpacity)) |
|
197 { |
|
198 //iOpacity = iVisual->iOpacity.Target(); |
|
199 iOpacity = iVisual->EffectOpacityTarget(); |
|
200 } |
|
201 } |
|
202 |
|
203 |
|
204 |
|
205 EXPORT_C CHuiFxVisualLayer::~CHuiFxVisualLayer() |
|
206 { |
|
207 #ifdef HUIFX_TRACE |
|
208 RDebug::Print(_L("CHuiFxVisualLayer::~CHuiFxVisualLayer - 0x%x "), this); |
|
209 #endif |
|
210 delete iExtBitmapFile; |
|
211 delete iParameterManager; |
|
212 iParameterManager = NULL; |
|
213 } |
|
214 |
|
215 EXPORT_C TBool CHuiFxVisualLayer::Changed() const |
|
216 { |
|
217 TBool ret = iParameterManager->HasAnimatedParameters(); |
|
218 #ifdef HUIFX_TRACE |
|
219 RDebug::Print(_L("CHuiFxVisualLayer::Changed - 0x%x , ret %d"), this, ret); |
|
220 #endif |
|
221 return ret; |
|
222 } |
|
223 |
|
224 EXPORT_C void CHuiFxVisualLayer::AdvanceTime(TReal32 aElapsedTime) |
|
225 { |
|
226 iParameterManager->AdvanceTime(aElapsedTime); |
|
227 } |
|
228 |
|
229 EXPORT_C TBool CHuiFxVisualLayer::PrepareDrawL(CHuiFxEngine& aEngine) |
|
230 { |
|
231 iParameterManager->Update(aEngine, VisualRect()); |
|
232 return ETrue; |
|
233 } |
|
234 |
|
235 EXPORT_C void CHuiFxVisualLayer::Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer &aTarget, CHuiFxRenderbuffer& /*aSource*/) |
|
236 { |
|
237 #ifdef HUIFX_TRACE |
|
238 RDebug::Print(_L("CHuiFxVisualLayer::Draw - 0x%x "), this); |
|
239 #endif |
|
240 aTarget.BindAsRenderTarget(); |
|
241 aGc.Push(EHuiGcMatrixModel); |
|
242 |
|
243 THuiFxEngineType engineType = aEngine.EngineType(); |
|
244 TRenderBufferType bufferType = aTarget.BufferType(); |
|
245 if(engineType == EHuiFxEngineGles20) |
|
246 { |
|
247 if(bufferType == EBufferTypeOffscreen) |
|
248 { |
|
249 aGc.Enable(CHuiGc::EFeatureBlending, ETrue); |
|
250 aGc.SetBlendMode(CHuiGc::EBlendReplace); |
|
251 } |
|
252 TRect viewPort(TPoint(0,0), aTarget.Size()); |
|
253 aGc.SetProjection(CHuiGc::EProjectionOrthographic, viewPort); |
|
254 } |
|
255 |
|
256 aGc.Translate(EHuiGcMatrixModel, VisualRect().iTl.iX, VisualRect().iTl.iY, 0.0f); |
|
257 ApplyTransformations(aGc); |
|
258 aGc.Translate(EHuiGcMatrixModel, -VisualRect().iTl.iX, -VisualRect().iTl.iY, 0.0f); |
|
259 |
|
260 aGc.SetBlendMode( CHuiGc::EBlendNormal ); |
|
261 //iVisual->iOpacity.Set( iOpacity ); |
|
262 iVisual->EffectSetOpacity( iOpacity ); |
|
263 |
|
264 // Set new clipping region which does not clip anything. |
|
265 // We want always draw visual fully to the aTarget. |
|
266 aGc.PushClip(); |
|
267 TRect bufferArea = TRect(TPoint(0,0), aTarget.Size()); |
|
268 aGc.SetClip(bufferArea); // this does not transform bufferArea which is fine for us |
|
269 |
|
270 // Draw visual content to aTarget |
|
271 //iVisual->DrawSelf(aGc, TargetRect()); |
|
272 iVisual->EffectSetSource(iSrcType==EVisualSrcInput1); |
|
273 iVisual->EffectDrawSelf( aGc, TargetRect() ); |
|
274 iVisual->EffectSetSource(EFalse); |
|
275 |
|
276 // Restore original clipping |
|
277 aGc.PopClip(); |
|
278 |
|
279 if(engineType == EHuiFxEngineGles20) |
|
280 { |
|
281 if(bufferType == EBufferTypeOffscreen) |
|
282 { |
|
283 aGc.SetBlendMode(CHuiGc::EBlendNormal); |
|
284 } |
|
285 aGc.SetProjection(CHuiGc::EProjectionOrthographic); |
|
286 } |
|
287 |
|
288 aGc.Pop(EHuiGcMatrixModel); |
|
289 aTarget.UnbindAsRenderTarget(); |
|
290 } |
|
291 |
|
292 void CHuiFxVisualLayer::ApplyTransformations(CHuiGc& aGc) |
|
293 { |
|
294 #ifdef HUIFX_TRACE |
|
295 RDebug::Print(_L("CHuiFxVisualLayer::ApplyTransformations - 0x%x "), this); |
|
296 #endif |
|
297 // Matrix multiplication is generally not commutative. |
|
298 // Therefore the order of the transformations matters. |
|
299 // In order to prevent the scaling ang skewing from affecting the translation, |
|
300 // if seems wiser to do the translation first, otherwise the results seem to be unpredictable. |
|
301 |
|
302 // Translation |
|
303 if (iTranslationX != 0.0f || iTranslationY != 0.0f || iTranslationZ != 0.0f) |
|
304 { |
|
305 aGc.Translate(EHuiGcMatrixModel, iTranslationX, iTranslationY, iTranslationZ); |
|
306 } |
|
307 |
|
308 // Scaling |
|
309 if (iScaleX != 1.0f || iScaleY != 1.0f || iScaleZ != 1.0f) |
|
310 { |
|
311 if ( iScaleOriginX != 0 || iScaleOriginY != 0 || iScaleOriginZ != 0 ) |
|
312 { |
|
313 aGc.Translate(EHuiGcMatrixModel, iScaleOriginX, iScaleOriginY, iScaleOriginZ); |
|
314 aGc.Scale(EHuiGcMatrixModel, iScaleX, iScaleY, iScaleZ); |
|
315 aGc.Translate(EHuiGcMatrixModel, -iScaleOriginX, -iScaleOriginY, -iScaleOriginZ); |
|
316 } |
|
317 else |
|
318 { |
|
319 aGc.Scale(EHuiGcMatrixModel, iScaleX, iScaleY, iScaleZ); |
|
320 } |
|
321 } |
|
322 |
|
323 // Skewing |
|
324 if (iSkewAngleX != 0.0f || iSkewAngleY != 0.0f || iSkewAngleZ != 0.0f) |
|
325 { |
|
326 const TReal32 radsPerDeg = 2.0f * (float)M_PI / 360.0f; |
|
327 TReal32 skewX = tan(iSkewAngleX * radsPerDeg); |
|
328 TReal32 skewY = tan(iSkewAngleY * radsPerDeg); |
|
329 TReal32 skewZ = tan(iSkewAngleZ * radsPerDeg); |
|
330 if ( iSkewOriginX != 0 || iSkewOriginY != 0 || iSkewOriginZ != 0 ) |
|
331 { |
|
332 aGc.Translate(EHuiGcMatrixModel, iSkewOriginX, iSkewOriginY, iSkewOriginZ); |
|
333 aGc.Shear(EHuiGcMatrixModel, skewX, skewY, skewZ); |
|
334 aGc.Translate(EHuiGcMatrixModel, -iSkewOriginX, -iSkewOriginY, -iSkewOriginZ); |
|
335 } |
|
336 else |
|
337 { |
|
338 aGc.Shear(EHuiGcMatrixModel, skewX, skewY, skewZ); |
|
339 } |
|
340 } |
|
341 |
|
342 // Rotation |
|
343 if (iRotationAngle != 0.0f) |
|
344 { |
|
345 if ( iRotationOriginX != 0 || iRotationOriginY != 0 || iRotationOriginZ != 0 ) |
|
346 { |
|
347 aGc.Translate(EHuiGcMatrixModel, iRotationOriginX, iRotationOriginY, iRotationOriginZ); |
|
348 aGc.Rotate(EHuiGcMatrixModel, iRotationAngle, iRotationAxisX, iRotationAxisY, iRotationAxisZ); |
|
349 aGc.Translate(EHuiGcMatrixModel, -iRotationOriginX, -iRotationOriginY, -iRotationOriginZ); |
|
350 } |
|
351 else |
|
352 { |
|
353 aGc.Rotate(EHuiGcMatrixModel, iRotationAngle, iRotationAxisX, iRotationAxisY, iRotationAxisZ); |
|
354 } |
|
355 } |
|
356 |
|
357 // Translation |
|
358 /* |
|
359 if (iTranslationX != 0.0f || iTranslationY != 0.0f || iTranslationZ != 0.0f) |
|
360 { |
|
361 aGc.Translate(EHuiGcMatrixModel, iTranslationX, iTranslationY, iTranslationZ); |
|
362 } |
|
363 */ |
|
364 } |
|
365 |
|
366 EXPORT_C TBool CHuiFxVisualLayer::VisualArea( TRect& aRect ) |
|
367 { |
|
368 // TODO: cache? |
|
369 // TODO: transforms |
|
370 //aRect = iVisual->DisplayRect(); |
|
371 THuiRealRect rect = iVisual->EffectDisplayRect(); |
|
372 aRect = rect; |
|
373 return ETrue; |
|
374 } |
|
375 |
|
376 EXPORT_C TBool CHuiFxVisualLayer::Margin(TMargins &m) |
|
377 { |
|
378 m.iLeft = iTranslationX < 0.0 ? -iTranslationX : 0.0; |
|
379 m.iRight = iTranslationX > 0.0 ? iTranslationX : 0.0; |
|
380 m.iTop = iTranslationY < 0.0 ? -iTranslationY : 0.0; |
|
381 m.iBottom = iTranslationY > 0.0 ? iTranslationY : 0.0; |
|
382 return ETrue; |
|
383 } |
|
384 |
|
385 EXPORT_C MHuiFxParameter* CHuiFxVisualLayer::Parameter(const TDesC& aName) |
|
386 { |
|
387 return iParameterManager->Parameter(aName); |
|
388 } |
|
389 |
|
390 EXPORT_C void CHuiFxVisualLayer::RegisterParameterL(const TDesC& aName, TReal32* aValue) |
|
391 { |
|
392 iParameterManager->RegisterParameterL(aName, aValue); |
|
393 } |
|
394 |
|
395 EXPORT_C void CHuiFxVisualLayer::RegisterParameterL(const TDesC& aName, TRgb* aValue) |
|
396 { |
|
397 iParameterManager->RegisterParameterL(aName, aValue); |
|
398 } |
|
399 |
|
400 void CHuiFxVisualLayer::SetSourceType( const THuiFxVisualSrcType aSrcType ) |
|
401 { |
|
402 iSrcType = aSrcType; |
|
403 } |
|
404 |
|
405 THuiFxVisualSrcType CHuiFxVisualLayer::SourceType() const |
|
406 { |
|
407 return iSrcType; |
|
408 } |
|
409 |
|
410 void CHuiFxVisualLayer::SetExtBitmapFileL( TDesC& aFilename ) |
|
411 { |
|
412 #ifdef HUIFX_TRACE |
|
413 RDebug::Print(_L("CHuiFxVisualLayer::SetExtBitmapFileL - 0x%x, %S "), this, &aFilename); |
|
414 #endif |
|
415 delete iExtBitmapFile; |
|
416 iExtBitmapFile = NULL; |
|
417 if ( aFilename.Length() == 0 ) |
|
418 { |
|
419 // don't set an empty filename |
|
420 return; |
|
421 } |
|
422 iExtBitmapFile = HBufC::NewL( aFilename.Length() ); |
|
423 *iExtBitmapFile = aFilename; |
|
424 //TODO: the bitmap from this filename should be loaded as texture to the visual. |
|
425 } |
|
426 void CHuiFxVisualLayer::FxmlVisualInputs(RArray<THuiFxVisualSrcType> &aArray) |
|
427 { |
|
428 aArray.Append(iSrcType); |
|
429 } |
|
430 |
|
431 TBool CHuiFxVisualLayer::IsSemitransparent() const |
|
432 { |
|
433 if (iOpacity < 1.f) |
|
434 { |
|
435 return ETrue; |
|
436 } |
|
437 else |
|
438 { |
|
439 return EFalse; |
|
440 } |
|
441 } |