224 |
227 |
225 EXPORT_C void CHuiFxVisualLayer::AdvanceTime(TReal32 aElapsedTime) |
228 EXPORT_C void CHuiFxVisualLayer::AdvanceTime(TReal32 aElapsedTime) |
226 { |
229 { |
227 iParameterManager->AdvanceTime(aElapsedTime); |
230 iParameterManager->AdvanceTime(aElapsedTime); |
228 } |
231 } |
229 |
232 |
230 EXPORT_C TBool CHuiFxVisualLayer::PrepareDrawL(CHuiFxEngine& aEngine) |
233 EXPORT_C TBool CHuiFxVisualLayer::PrepareDrawL(CHuiFxEngine& aEngine) |
231 { |
234 { |
232 iParameterManager->Update(aEngine, VisualRect()); |
235 iParameterManager->Update(aEngine, VisualRect()); |
|
236 if(iVisual) |
|
237 { |
|
238 iVisual->EffectSetOpacityAdditive( iOpacity, EFalse ); |
|
239 } |
233 return ETrue; |
240 return ETrue; |
234 } |
241 } |
235 |
242 |
236 EXPORT_C void CHuiFxVisualLayer::Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer &aTarget, CHuiFxRenderbuffer& /*aSource*/, TBool /*aHasSurface*/) |
243 EXPORT_C void CHuiFxVisualLayer::Draw(CHuiFxEngine& aEngine, CHuiGc& aGc, CHuiFxRenderbuffer &aTarget, CHuiFxRenderbuffer& /*aSource*/, TBool /*aHasSurface*/) |
237 { |
244 { |
238 #ifdef HUIFX_TRACE |
245 #ifdef HUIFX_TRACE |
239 RDebug::Print(_L("CHuiFxVisualLayer::Draw - 0x%x "), this); |
246 RDebug::Print(_L("CHuiFxVisualLayer::Draw - 0x%x "), this); |
240 #endif |
247 #endif |
|
248 TRect backbufferRect = SourceRect(); |
|
249 TSize backbufferSize = backbufferRect.Size(); |
|
250 THuiFxEngineType engineType = aEngine.EngineType(); |
|
251 TBool forceRefresh = EFalse; |
|
252 |
|
253 if (iRenderBuffer && iRenderBuffer->Size() != backbufferSize) |
|
254 { |
|
255 iEngine->ReleaseRenderbuffer(iRenderBuffer); |
|
256 iRenderBuffer = NULL; |
|
257 } |
|
258 |
|
259 if(!iRenderBuffer) |
|
260 { |
|
261 iRenderBuffer = aEngine.AcquireRenderbuffer(backbufferSize, EFalse); |
|
262 if (!iRenderBuffer) |
|
263 { |
|
264 return; |
|
265 } |
|
266 iEngine = &aEngine; |
|
267 forceRefresh = ETrue; |
|
268 } |
|
269 |
|
270 // don't update render buffer if visual is not changed or screenshot is used |
|
271 if(forceRefresh || (iVisualContentChanged && iSrcType!=EVisualSrcInput1)) |
|
272 { |
|
273 if(!iVisualContentOpaque) |
|
274 { |
|
275 iRenderBuffer->PrepareForReuse(backbufferRect.Size()); |
|
276 } |
|
277 iRenderBuffer->BindAsRenderTarget(); |
|
278 |
|
279 // Translate the graphics context so that the content appears in the correct place |
|
280 aGc.Push(EHuiGcMatrixModel); |
|
281 if(engineType == EHuiFxEngineVg10) |
|
282 { |
|
283 aGc.Scale(EHuiGcMatrixModel, 1.0f, -1.0f, 1.0f); |
|
284 aGc.Translate(EHuiGcMatrixModel, 0.0f, -backbufferRect.Size().iHeight, 0.0f); |
|
285 } |
|
286 |
|
287 aGc.Translate(EHuiGcMatrixModel, -backbufferRect.iTl.iX, -backbufferRect.iTl.iY, 0.0f); |
|
288 aGc.SetBlendMode( CHuiGc::EBlendNormal ); |
|
289 |
|
290 // Set new clipping region which does not clip anything. |
|
291 // We want always draw visual fully to the aTarget. |
|
292 aGc.PushClip(); |
|
293 TRect bufferArea = TRect(TPoint(0,0), backbufferSize); |
|
294 aGc.SetClip(bufferArea); // this does not transform bufferArea which is fine for us |
|
295 |
|
296 // Draw visual content to aTarget |
|
297 iVisual->EffectSetSource(iSrcType==EVisualSrcInput1); |
|
298 iVisual->EffectDrawSelf( aGc, TargetRect() ); |
|
299 iVisual->EffectSetSource(EFalse); |
|
300 |
|
301 // Restore original clipping |
|
302 aGc.PopClip(); |
|
303 |
|
304 aGc.Pop(EHuiGcMatrixModel); |
|
305 iRenderBuffer->UnbindAsRenderTarget(); |
|
306 } |
|
307 |
241 aTarget.BindAsRenderTarget(); |
308 aTarget.BindAsRenderTarget(); |
|
309 |
|
310 // make effect transformations effective |
242 aGc.Push(EHuiGcMatrixModel); |
311 aGc.Push(EHuiGcMatrixModel); |
243 |
|
244 THuiFxEngineType engineType = aEngine.EngineType(); |
|
245 TRenderBufferType bufferType = aTarget.BufferType(); |
312 TRenderBufferType bufferType = aTarget.BufferType(); |
246 if(engineType == EHuiFxEngineGles20) |
313 if(engineType == EHuiFxEngineGles20) |
247 { |
314 { |
248 if(bufferType == EBufferTypeOffscreen) |
315 if(bufferType == EBufferTypeOffscreen) |
249 { |
316 { |
250 aGc.Enable(CHuiGc::EFeatureBlending, ETrue); |
317 aGc.Enable(CHuiGc::EFeatureBlending, ETrue); |
251 aGc.SetBlendMode(CHuiGc::EBlendReplace); |
318 aGc.SetBlendMode(CHuiGc::EBlendReplace); |
252 } |
319 } |
253 TRect viewPort(TPoint(0,0), aTarget.Size()); |
320 TRect viewPort(TPoint(0,0), aTarget.Size()); |
254 aGc.SetProjection(CHuiGc::EProjectionOrthographic, viewPort); |
321 aGc.SetProjection(CHuiGc::EProjectionOrthographic, viewPort); |
255 } |
322 } |
256 |
323 |
257 aGc.Translate(EHuiGcMatrixModel, VisualRect().iTl.iX, VisualRect().iTl.iY, 0.0f); |
324 aGc.Translate(EHuiGcMatrixModel, VisualRect().iTl.iX, VisualRect().iTl.iY, 0.0f); |
258 ApplyTransformations(aGc); |
325 ApplyTransformations(aGc); |
259 aGc.Translate(EHuiGcMatrixModel, -VisualRect().iTl.iX, -VisualRect().iTl.iY, 0.0f); |
326 aGc.Translate(EHuiGcMatrixModel, -VisualRect().iTl.iX, -VisualRect().iTl.iY, 0.0f); |
260 |
327 |
261 aGc.SetBlendMode( CHuiGc::EBlendNormal ); |
328 aGc.SetBlendMode( CHuiGc::EBlendNormal ); |
262 //iVisual->iOpacity.Set( iOpacity ); |
329 |
263 iVisual->EffectSetOpacity( iOpacity ); |
330 // do composition to aTarget |
264 |
331 TRect compositionTargetRect(TargetRect()); |
265 // Set new clipping region which does not clip anything. |
332 compositionTargetRect.Move(-aTarget.Position()); |
266 // We want always draw visual fully to the aTarget. |
333 |
267 aGc.PushClip(); |
334 aGc.Disable(CHuiGc::EFeatureClipping); |
268 TRect bufferArea = TRect(TPoint(0,0), aTarget.Size()); |
335 |
269 aGc.SetClip(bufferArea); // this does not transform bufferArea which is fine for us |
336 // following must always have aOpaque = Efalse because it is quite common that effected window |
270 |
337 // has areas which do not have any drawing. Even if iOpacity is 1.f these areas are drawn |
271 // Draw visual content to aTarget |
338 // incorrectly in this case -> we always blend |
272 //iVisual->DrawSelf(aGc, TargetRect()); |
339 aEngine.Composite(aGc, *iRenderBuffer, compositionTargetRect.iTl, EFalse, iOpacity*255); |
273 iVisual->EffectSetSource(iSrcType==EVisualSrcInput1); |
340 |
274 iVisual->EffectDrawSelf( aGc, TargetRect() ); |
341 aGc.Enable(CHuiGc::EFeatureClipping); |
275 iVisual->EffectSetSource(EFalse); |
|
276 |
|
277 // Restore original clipping |
|
278 aGc.PopClip(); |
|
279 |
342 |
280 if(engineType == EHuiFxEngineGles20) |
343 if(engineType == EHuiFxEngineGles20) |
281 { |
344 { |
282 if(bufferType == EBufferTypeOffscreen) |
345 if(bufferType == EBufferTypeOffscreen) |
283 { |
346 { |
284 aGc.SetBlendMode(CHuiGc::EBlendNormal); |
347 aGc.SetBlendMode(CHuiGc::EBlendNormal); |
285 } |
348 } |
286 aGc.SetProjection(CHuiGc::EProjectionOrthographic); |
349 aGc.SetProjection(CHuiGc::EProjectionOrthographic); |
287 } |
350 } |
288 |
351 |
289 aGc.Pop(EHuiGcMatrixModel); |
352 aGc.Pop(EHuiGcMatrixModel); |
|
353 |
290 aTarget.UnbindAsRenderTarget(); |
354 aTarget.UnbindAsRenderTarget(); |
291 } |
355 } |
292 |
356 |
293 void CHuiFxVisualLayer::ApplyTransformations(CHuiGc& aGc) |
357 void CHuiFxVisualLayer::ApplyTransformations(CHuiGc& aGc) |
294 { |
358 { |