uiacceltk/hitchcock/coretoolkit/src/HuiGc.cpp
changeset 0 15bf7259bb7c
child 6 10534483575f
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:   Implementation for CHuiGc (graphics context) class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "uiacceltk/HuiGc.h"  // Class definition
       
    21 #include "HuiRenderPlugin.h"
       
    22 #include "uiacceltk/HuiSegmentedTexture.h"
       
    23 #include "uiacceltk/HuiTextMesh.h"
       
    24 #include "uiacceltk/HuiFont.h"
       
    25 #include "uiacceltk/HuiImage.h"
       
    26 #include "uiacceltk/HuiTransformation.h"
       
    27 #include "uiacceltk/HuiPanic.h"
       
    28 #include "uiacceltk/HuiUtil.h"  // For hui assert.
       
    29 #include "uiacceltk/HuiTransformation.h"
       
    30 
       
    31 #include <e32math.h>
       
    32 #include <AknUtils.h>
       
    33 
       
    34 const TInt KHuiMaxRecycledRegionCount = 20;
       
    35 
       
    36 /** Default offset from the Z=0 plane (which 2D projection uses) to the
       
    37     eyepoint, in 3D projection mode. */
       
    38 LOCAL_D const TReal32 KDefaultOffset2D = 1199.0;
       
    39 
       
    40 
       
    41 EXPORT_C CHuiGc::CHuiGc()
       
    42         : iOrientation(EOrientationNormal),
       
    43           iNearClipDistance(20.f),
       
    44           iFarClipDistance(10000.f),
       
    45           iFovFactor(1.f),
       
    46           iPenColor(TRgb(255, 255, 255)), iPenAlpha(255),
       
    47           iAlignHorizontal(EHuiAlignHLeft), iAlignVertical(EHuiAlignVTop),
       
    48           iFrustumOffsetCompleteness(1.f),
       
    49           iQuality(EHuiQualityAccurate),
       
    50           iClipRegionStackCount(0)
       
    51     {
       
    52     /// @todo  Fix this: The real default is 1.f, but the application should
       
    53     ///        be able to adjust the completeness. Wowidle/Mmenu have been
       
    54     ///        developed with .666f.
       
    55     iFrustumOffsetCompleteness = .666f;
       
    56     }
       
    57 
       
    58 EXPORT_C CHuiGc::~CHuiGc()
       
    59     {
       
    60     iTempRegion.Close();
       
    61     iClipRegion.Close();
       
    62     iClipRegionStack.Reset();
       
    63     iRecycledRegions.ResetAndDestroy();    
       
    64     iWindowTransform = NULL;
       
    65     iCurrentFont = NULL;
       
    66     }
       
    67 
       
    68 
       
    69 EXPORT_C void CHuiGc::SetQuality(THuiQuality aQuality)
       
    70     {
       
    71     iQuality = aQuality;
       
    72     }
       
    73 
       
    74 
       
    75 EXPORT_C THuiQuality CHuiGc::Quality() const
       
    76     {
       
    77     return iQuality;
       
    78     }
       
    79 
       
    80 
       
    81 EXPORT_C void CHuiGc::SetDisplayArea(const TRect& aDisplayArea)
       
    82     {
       
    83     iDisplayArea = aDisplayArea;
       
    84     iClipRegion.Clear();
       
    85     iClipRegion.AddRect(aDisplayArea);
       
    86     }
       
    87 
       
    88 
       
    89 EXPORT_C TRect CHuiGc::DisplayArea() const
       
    90     {
       
    91     if(iOrientation == EOrientationNormal)
       
    92         {
       
    93         return iDisplayArea;
       
    94         }
       
    95     else
       
    96         {
       
    97         TInt width = iDisplayArea.Width();
       
    98         TInt height = iDisplayArea.Height();
       
    99         /// @todo  Should not always be at the top left corner.
       
   100         TRect rect(TPoint(0, 0), TSize(height, width));
       
   101         return rect;
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 EXPORT_C void CHuiGc::SetOrientation(TOrientation aOrientation)
       
   107     {
       
   108     iOrientation = aOrientation;
       
   109     }
       
   110 
       
   111 
       
   112 EXPORT_C CHuiGc::TOrientation CHuiGc::Orientation() const
       
   113     {
       
   114     return iOrientation;
       
   115     }
       
   116 
       
   117 
       
   118 EXPORT_C void CHuiGc::SetProjection(TProjection aProjection)
       
   119     {
       
   120     SetProjection(aProjection, iDisplayArea);
       
   121     }
       
   122 
       
   123 
       
   124 EXPORT_C CHuiGc::TProjection CHuiGc::Projection() const
       
   125     {
       
   126     return iProjection;
       
   127     }
       
   128 
       
   129 
       
   130 EXPORT_C void CHuiGc::SetProjection(TProjection aProjection, const TRect& aViewport)
       
   131     {
       
   132     iProjection = aProjection;
       
   133     iProjectionViewport = aViewport;
       
   134     iFrustumOffset = THuiRealPoint(0.f, 0.f);
       
   135 
       
   136     UpdateProjection();
       
   137     }
       
   138 
       
   139 
       
   140 EXPORT_C void CHuiGc::SetFrustumOffset(const THuiRealPoint& aFrustumOffset)
       
   141     {
       
   142     if(!iDisplayArea.Width() || !iDisplayArea.Height())
       
   143         {
       
   144         return;
       
   145         }
       
   146 
       
   147     THuiRealPoint local = aFrustumOffset;
       
   148     TRect area = DisplayArea(); // Orientation applied.
       
   149     local.iX -= area.Width()/2.f;
       
   150     local.iY -= area.Height()/2.f;
       
   151     local.iX /= area.Width()/2.f;
       
   152     local.iY /= area.Height()/2.f;
       
   153 
       
   154     // Adjust so that the perspective correction isn't complete.
       
   155     local.iX *= iFrustumOffsetCompleteness;
       
   156     local.iY *= iFrustumOffsetCompleteness;
       
   157 
       
   158     iFrustumOffset = local;
       
   159 
       
   160     UpdateProjection();
       
   161     }
       
   162 
       
   163 
       
   164 EXPORT_C void CHuiGc::Disable(TFeature aFeature)
       
   165     {
       
   166     Enable(aFeature, EFalse);
       
   167     }
       
   168 
       
   169 
       
   170 EXPORT_C TRect CHuiGc::UnOrientRect(const TRect& aOrientedRect) const
       
   171     {
       
   172     if(iOrientation == EOrientationCCW90)
       
   173         {
       
   174         // Un-orient 90 degrees clockwise.
       
   175         TSize size(aOrientedRect.Height(), aOrientedRect.Width());
       
   176         TPoint pos(iDisplayArea.Width() - aOrientedRect.iBr.iY,
       
   177                    aOrientedRect.iTl.iX);
       
   178         return TRect(pos, size);
       
   179         }
       
   180     else if(iOrientation == EOrientationCW90)
       
   181         {
       
   182         // Un-orient 90 degrees counterclockwise.
       
   183         TSize size(aOrientedRect.Height(), aOrientedRect.Width());
       
   184         TPoint pos(aOrientedRect.iTl.iY,
       
   185                    iDisplayArea.Height() - aOrientedRect.iBr.iX);
       
   186         return TRect(pos, size);
       
   187         }
       
   188     else
       
   189         {
       
   190         // No change because there is no orientation.
       
   191         return aOrientedRect;
       
   192         }
       
   193     }
       
   194 
       
   195 EXPORT_C void CHuiGc::UnOrientRegion(TRegion& aOrientedRegion) const
       
   196     {
       
   197     if(iOrientation == EOrientationCCW90 || iOrientation == EOrientationCW90)
       
   198         {
       
   199         iTempRegion.Clear();
       
   200         for (TInt i=0; i < aOrientedRegion.Count(); i++)
       
   201             {
       
   202             iTempRegion.AddRect(UnOrientRect(aOrientedRegion[i]));
       
   203             }        
       
   204         aOrientedRegion.Copy(iTempRegion);
       
   205         }
       
   206     else
       
   207         {
       
   208         // No change because there is no orientation.
       
   209         }
       
   210     }
       
   211 
       
   212 EXPORT_C void CHuiGc::PushClip()
       
   213     {
       
   214     RRegion* newRegion = CreateRecycledRegion();
       
   215     
       
   216     if (newRegion)
       
   217         {
       
   218         newRegion->Copy(iClipRegion);
       
   219         iClipRegionStack.Append(newRegion);    
       
   220         }
       
   221         
       
   222     // Out of memory situation is handled by keeping separate
       
   223     // counter which is checked at pop.   
       
   224     iClipRegionStackCount++;
       
   225     }
       
   226 
       
   227 EXPORT_C void CHuiGc::PopClip()
       
   228     {
       
   229     __ASSERT_ALWAYS(iClipRegionStack.Count() > 0,
       
   230                     THuiPanic::Panic(THuiPanic::EGcClipStackPopFromEmpty));
       
   231 
       
   232     // Check if out of memory situation has happened in the push, so we don't pop
       
   233     // because we have not really pushed anything.  
       
   234     if (iClipRegionStackCount > iClipRegionStack.Count())
       
   235         {
       
   236         iClipRegionStackCount--;    
       
   237         return;
       
   238         }
       
   239 
       
   240     if(iClipRegionStack.Count() > 0)
       
   241         {
       
   242         TInt index = iClipRegionStack.Count() - 1;
       
   243         SetClipRegion(*iClipRegionStack[index]);        
       
   244         RRegion* region = iClipRegionStack[index];        
       
   245         iClipRegionStack.Remove(index);
       
   246         DeleteRecycledRegion(region);
       
   247         region = NULL;
       
   248         iClipRegionStackCount--;    
       
   249         }
       
   250     }
       
   251 
       
   252 EXPORT_C void CHuiGc::SetClip(const TRect& aClipRect)
       
   253     {
       
   254     HUI_ASSERT(aClipRect.Width() >= 0);
       
   255     HUI_ASSERT(aClipRect.Height() >= 0);    
       
   256     
       
   257     iTempRegion.Clear();
       
   258     iTempRegion.AddRect(aClipRect);    
       
   259     CHuiGc::SetClipRegion(iTempRegion);
       
   260     }
       
   261 
       
   262 EXPORT_C TRect CHuiGc::ClipRect() const
       
   263     {
       
   264     // This does not really provide actually valid data anymore
       
   265     // since clipping is done with a region. 
       
   266     return iClipRegion.BoundingRect();
       
   267     }
       
   268 
       
   269 const TRegion& CHuiGc::ClipRegion() const
       
   270     {
       
   271     return iClipRegion;
       
   272     }
       
   273 
       
   274 
       
   275 EXPORT_C void CHuiGc::Clip(const TRect& aClipRect)
       
   276     {
       
   277     HUI_ASSERT(aClipRect.Width() >= 0);
       
   278     HUI_ASSERT(aClipRect.Height() >= 0);
       
   279     
       
   280     if(iClipRegion.Intersects(aClipRect))
       
   281         {
       
   282         iTempRegion.Clear();
       
   283         iTempRegion.AddRect(aClipRect);
       
   284         iClipRegion.Intersect(iTempRegion);
       
   285         }
       
   286     else
       
   287         {
       
   288         // Empty clipping rectangle.
       
   289         iClipRegion.Clear();
       
   290         }
       
   291     
       
   292     SetClipRegion(iClipRegion);        
       
   293     }
       
   294 
       
   295 EXPORT_C void CHuiGc::Clip(const TRegion& aClipRegion)
       
   296     {
       
   297     iClipRegion.Intersect(aClipRegion);
       
   298     SetClipRegion(iClipRegion);
       
   299     }
       
   300     
       
   301 EXPORT_C void CHuiGc::SetClipRegion(const TRegion& aClipRegion)
       
   302 	{
       
   303 	if (&aClipRegion != &iClipRegion)
       
   304 	    {
       
   305 	    iClipRegion.Copy(aClipRegion);        
       
   306 	    }
       
   307 	}
       
   308 	
       
   309 EXPORT_C void CHuiGc::CancelClipping()
       
   310     {
       
   311     }
       
   312 
       
   313 EXPORT_C TInt CHuiGc::ClipStackCount() const
       
   314     {
       
   315     return iClipRegionStack.Count();
       
   316     }
       
   317 
       
   318 
       
   319 EXPORT_C void CHuiGc::SetAlign(THuiAlignHorizontal aHorizontalAlign,
       
   320                                THuiAlignVertical aVerticalAlign)
       
   321     {
       
   322     switch(aHorizontalAlign)
       
   323         {
       
   324         case EHuiAlignHLocale:
       
   325             iAlignHorizontal = LocaleTextAlignment();
       
   326             break;
       
   327 
       
   328         case EHuiAlignHLocaleMirrored:
       
   329             iAlignHorizontal = LocaleTextAlignment();
       
   330             if(iAlignHorizontal == EHuiAlignHLeft)
       
   331                 {
       
   332                 iAlignHorizontal = EHuiAlignHRight;
       
   333                 }
       
   334             else
       
   335                 {
       
   336                 iAlignHorizontal = EHuiAlignHLeft;
       
   337                 }
       
   338             break;
       
   339 
       
   340         default:
       
   341             iAlignHorizontal = aHorizontalAlign;
       
   342             break;
       
   343         }
       
   344 
       
   345     iAlignVertical = aVerticalAlign;
       
   346     }
       
   347 
       
   348 
       
   349 EXPORT_C THuiAlignHorizontal CHuiGc::AlignHorizontal() const
       
   350     {
       
   351     return iAlignHorizontal;
       
   352     }
       
   353 
       
   354 
       
   355 EXPORT_C THuiAlignVertical CHuiGc::AlignVertical() const
       
   356     {
       
   357     return iAlignVertical;
       
   358     }
       
   359 
       
   360 
       
   361 EXPORT_C void CHuiGc::SetPenColor(const TRgb& aColor)
       
   362     {
       
   363     iPenColor = aColor;
       
   364     }
       
   365 
       
   366 
       
   367 EXPORT_C TRgb CHuiGc::PenColor() const
       
   368     {
       
   369     return iPenColor;
       
   370     }
       
   371 
       
   372 
       
   373 EXPORT_C void CHuiGc::SetPenColorAlpha(const TRgb& aColor)
       
   374     {
       
   375     iPenColor = aColor;
       
   376     iPenColor.SetAlpha(255);
       
   377 
       
   378     iPenAlpha = TUint8(aColor.Alpha()); // 8 bits should be enough
       
   379     }
       
   380 
       
   381 
       
   382 EXPORT_C TRgb CHuiGc::PenColorAlpha() const
       
   383     {
       
   384     TRgb color = iPenColor;
       
   385     color.SetAlpha(iPenAlpha);
       
   386     return color;
       
   387     }
       
   388 
       
   389 
       
   390 EXPORT_C void CHuiGc::SetPenAlpha(TInt aAlpha)
       
   391     {
       
   392     if(aAlpha < 0)
       
   393         {
       
   394         aAlpha = 0;
       
   395         }
       
   396     else if(aAlpha > 255)
       
   397         {
       
   398         aAlpha = 255;
       
   399         }
       
   400     else
       
   401         {
       
   402         // for PC lint
       
   403         }
       
   404     iPenAlpha = TUint8(aAlpha); // 8 bits should be enough
       
   405     }
       
   406 
       
   407 
       
   408 EXPORT_C TInt CHuiGc::PenAlpha() const
       
   409     {
       
   410     return iPenAlpha;
       
   411     }
       
   412 
       
   413 
       
   414 EXPORT_C void CHuiGc::SetFont(THuiFont& aFont)
       
   415     {
       
   416     iCurrentFont = &aFont;
       
   417     }
       
   418 
       
   419 
       
   420 EXPORT_C void CHuiGc::DrawTextL(const TDesC& aText,
       
   421                                 const THuiRealRect& aBounds,
       
   422                                 TReal32 aShadow) __SOFTFP
       
   423     {
       
   424     if(!Font())
       
   425         {
       
   426         return;
       
   427         }
       
   428     CHuiTextMesh* mesh = CHuiStatic::Renderer().CreateTextMeshL();
       
   429     CleanupStack::PushL(mesh);
       
   430     mesh->SetTextL(aText, ETrue);
       
   431     DrawText(*mesh, aBounds, aShadow);
       
   432     CleanupStack::PopAndDestroy(mesh);
       
   433     }
       
   434 
       
   435 
       
   436 EXPORT_C void CHuiGc::DrawText(const CHuiTextMesh& aTextMesh,
       
   437                                const THuiRealRect& aBounds,
       
   438                                TReal32 aShadow) __SOFTFP
       
   439     {
       
   440     /** @todo  This could be generalized: MHuiBoundedDrawable (for example) */
       
   441 
       
   442     // Font is defined in the text mesh.
       
   443 
       
   444     // Real bounding size of the text.
       
   445     TSize textBounds = aTextMesh.Extents();
       
   446 
       
   447     // Reference origin for the text.
       
   448     TPoint offset = AlignOffset(aBounds.Size());
       
   449 
       
   450     // Actual starting point for glyphs.
       
   451     THuiRealPoint pos = aBounds.iTl - offset;
       
   452     switch(AlignHorizontal())
       
   453         {
       
   454         case EHuiAlignHRight:
       
   455             pos.iX -= textBounds.iWidth;
       
   456             break;
       
   457 
       
   458         case EHuiAlignHCenter:
       
   459             pos.iX -= textBounds.iWidth / 2; // or 2.f?
       
   460             break;
       
   461 
       
   462         default:
       
   463             break;
       
   464         }
       
   465     switch(AlignVertical())
       
   466         {
       
   467         case EHuiAlignVBottom:
       
   468             pos.iY -= textBounds.iHeight;
       
   469             break;
       
   470 
       
   471         case EHuiAlignVCenter:
       
   472             pos.iY -= textBounds.iHeight / 2; // or 2.f?
       
   473             break;
       
   474 
       
   475         default:
       
   476             break;
       
   477         }
       
   478 
       
   479 
       
   480     // Apply the position.
       
   481     Push(EHuiGcMatrixModel);
       
   482     Translate(EHuiGcMatrixModel, pos.iX, pos.iY, 0.f);
       
   483 
       
   484     aTextMesh.Draw(*this, aShadow);
       
   485 
       
   486     Pop(EHuiGcMatrixModel);
       
   487     }
       
   488 
       
   489 
       
   490 EXPORT_C void CHuiGc::DrawImage(const THuiImage& aImage,
       
   491                                 const THuiRealPoint& aPos,
       
   492                                 const THuiRealSize& aSize)
       
   493     {
       
   494     if(!aImage.HasTexture())
       
   495         {
       
   496         return;
       
   497         }
       
   498 
       
   499     THuiRealPoint topLeft = aPos + AlignOffset(aSize);
       
   500     UpdateColor();
       
   501 
       
   502     // Update texture preferred size, toolkit may use this information to resize texture
       
   503     NotifyImagePreferredSize(aImage, THuiRealRect(topLeft,aSize));
       
   504     
       
   505     DoDrawImage(aImage, topLeft, aSize);
       
   506     }
       
   507 
       
   508 
       
   509 EXPORT_C void CHuiGc::DrawImages(const THuiImage& aImage,
       
   510                                  const THuiImage& aImage2,
       
   511                                  const THuiRealPoint& aPos,
       
   512                                  const THuiRealSize& aSize)
       
   513     {
       
   514     if(!aImage.HasTexture() || !aImage2.HasTexture())
       
   515         {
       
   516         return;
       
   517         }
       
   518 
       
   519     THuiRealPoint topLeft = aPos + AlignOffset(aSize);
       
   520     UpdateColor();
       
   521     
       
   522     // Update texture preferred size, toolkit may use this information to resize texture
       
   523     NotifyImagePreferredSize(aImage, THuiRealRect(topLeft,aSize));
       
   524     NotifyImagePreferredSize(aImage2, THuiRealRect(topLeft,aSize));
       
   525 
       
   526     DoDrawImages(aImage, aImage2, topLeft, aSize);
       
   527     }
       
   528 
       
   529 
       
   530 EXPORT_C void CHuiGc::DrawImage(const THuiImage& aImage,
       
   531                                 const THuiRealRect& aBounds)
       
   532     {
       
   533     if(!aImage.HasTexture())
       
   534         {
       
   535         return;
       
   536         }
       
   537 
       
   538     TSize space(TInt(aBounds.Width() - aImage.Texture().Size().iWidth),
       
   539                 TInt(aBounds.Height() - aImage.Texture().Size().iHeight));
       
   540 
       
   541     TPoint topLeft = aBounds.iTl - AlignOffset(space);
       
   542 
       
   543     UpdateColor();
       
   544 
       
   545     // Update texture preferred size, toolkit may use this information to resize texture
       
   546     NotifyImagePreferredSize(aImage, aBounds);
       
   547 
       
   548     DoDrawImage(aImage, topLeft, aImage.Texture().Size());
       
   549     }
       
   550 
       
   551 
       
   552 EXPORT_C void CHuiGc::DrawImage( const THuiImage& aImage,
       
   553                                  const THuiRealSize& aSize,
       
   554                                  const THuiRealRect& aBounds)
       
   555     {
       
   556     if(!aImage.HasTexture())
       
   557         {
       
   558         return;
       
   559         }
       
   560 
       
   561     TSize space(TInt(aBounds.Width() - aSize.iWidth),
       
   562                 TInt(aBounds.Height() - aSize.iHeight));
       
   563 
       
   564     TPoint topLeft = aBounds.iTl - AlignOffset(space);
       
   565 
       
   566     UpdateColor();
       
   567 
       
   568     // Update texture preferred size, toolkit may use this information to resize texture
       
   569     NotifyImagePreferredSize(aImage, THuiRealRect(topLeft,aSize));
       
   570 
       
   571     DoDrawImage(aImage, topLeft, aSize);
       
   572     }
       
   573 
       
   574 
       
   575 EXPORT_C void CHuiGc::DrawImages(const THuiImage& aImage,
       
   576                                  const THuiImage& aImage2,
       
   577                                  const THuiRealSize& aSize,
       
   578                                  const THuiRealRect& aBounds)
       
   579     {
       
   580     if(!aImage.HasTexture() || !aImage2.HasTexture())
       
   581         {
       
   582         return;
       
   583         }
       
   584 
       
   585     TSize space(TInt(aBounds.Width() - aSize.iWidth),
       
   586                 TInt(aBounds.Height() - aSize.iHeight));
       
   587 
       
   588     TPoint topLeft = aBounds.iTl - AlignOffset(space);
       
   589 
       
   590     UpdateColor();
       
   591 
       
   592     // Update texture preferred size, toolkit may use this information to resize texture
       
   593     NotifyImagePreferredSize(aImage, THuiRealRect(topLeft,aSize));
       
   594     NotifyImagePreferredSize(aImage2, THuiRealRect(topLeft,aSize));
       
   595 
       
   596     DoDrawImages(aImage, aImage2, topLeft, aSize);
       
   597     }
       
   598 
       
   599 
       
   600 EXPORT_C THuiFont* CHuiGc::Font()
       
   601     {
       
   602     return iCurrentFont;
       
   603     }
       
   604 
       
   605 
       
   606 EXPORT_C TPoint CHuiGc::AlignOffset(const TSize& aBounds) const
       
   607     {
       
   608     TPoint offset(0, 0);
       
   609 
       
   610     switch(iAlignHorizontal)
       
   611         {
       
   612         case EHuiAlignHRight:
       
   613             offset.iX = -aBounds.iWidth;
       
   614             break;
       
   615 
       
   616         case EHuiAlignHCenter:
       
   617             offset.iX = -aBounds.iWidth / 2;
       
   618             break;
       
   619 
       
   620         default:
       
   621             offset.iX = 0;
       
   622             break;
       
   623         }
       
   624 
       
   625     switch(iAlignVertical)
       
   626         {
       
   627         case EHuiAlignVBottom:
       
   628             offset.iY = -aBounds.iHeight;
       
   629             break;
       
   630 
       
   631         case EHuiAlignVCenter:
       
   632             offset.iY = -aBounds.iHeight / 2;
       
   633             break;
       
   634 
       
   635         default:
       
   636             offset.iY = 0;
       
   637             break;
       
   638         }
       
   639 
       
   640     return offset;
       
   641     }
       
   642 
       
   643 
       
   644 EXPORT_C TReal32 CHuiGc::Offset2D() const __SOFTFP
       
   645     {
       
   646     /// @todo  Make this configurable.
       
   647     //return 100.0 / FovFactor();
       
   648     return KDefaultOffset2D;
       
   649     }
       
   650 
       
   651 
       
   652 EXPORT_C void
       
   653 CHuiGc::SetWindowTransformation(CHuiTransformation* aWindowTransformation)
       
   654     {
       
   655     iWindowTransform = aWindowTransformation;
       
   656     }
       
   657 
       
   658 
       
   659 EXPORT_C TReal32 CHuiGc::NearClipDistance() const __SOFTFP
       
   660     {
       
   661     return iNearClipDistance;
       
   662     }
       
   663 
       
   664 
       
   665 EXPORT_C TReal32 CHuiGc::FarClipDistance() const __SOFTFP
       
   666     {
       
   667     return iFarClipDistance;
       
   668     }
       
   669 
       
   670 
       
   671 EXPORT_C TRect CHuiGc::ProjectionViewport() const
       
   672     {
       
   673     return iProjectionViewport;
       
   674     }
       
   675 
       
   676 
       
   677 EXPORT_C TRect CHuiGc::RawDisplayArea() const
       
   678     {
       
   679     return iDisplayArea;
       
   680     }
       
   681 
       
   682 
       
   683 EXPORT_C const CHuiTransformation* CHuiGc::WindowTransformation() const
       
   684     {
       
   685     return iWindowTransform;
       
   686     }
       
   687 
       
   688 
       
   689 EXPORT_C THuiRealPoint CHuiGc::FrustumOffset() const
       
   690     {
       
   691     return iFrustumOffset;
       
   692     }
       
   693 
       
   694 
       
   695 EXPORT_C TReal32 CHuiGc::FovFactor() const __SOFTFP
       
   696     {
       
   697     return 1.f / iFovFactor;
       
   698     }
       
   699 
       
   700 
       
   701 EXPORT_C THuiAlignHorizontal CHuiGc::LocaleTextAlignment()
       
   702     {
       
   703     if(CHuiStatic::LayoutMirrored())
       
   704         {
       
   705         return EHuiAlignHRight;
       
   706         }
       
   707     return EHuiAlignHLeft;
       
   708     }
       
   709 
       
   710 EXPORT_C void CHuiGc::DrawStretchImage(TStretchMode /*aMode*/,
       
   711                       const THuiImage& aImage,
       
   712                       const THuiRealRect& aRect,
       
   713                       TInt /*aStretchStartWidth*/,
       
   714                       TInt /*aStretchEndWidth*/)                      
       
   715     {
       
   716     // Update texture preferred size, toolkit may use this information to resize texture
       
   717     NotifyImagePreferredSize(aImage, aRect);        
       
   718     }
       
   719 
       
   720 
       
   721 EXPORT_C void CHuiGc::NotifyImagePreferredSize(const THuiImage& aImage, THuiRealRect aRect)
       
   722     {
       
   723     const CHuiTexture* texture = aImage.ImageDefaultTexture();    
       
   724     
       
   725     if  (texture)
       
   726         {        
       
   727         CHuiTexture* notifiedTexture = const_cast<CHuiTexture*> (texture);
       
   728         if (notifiedTexture->IsAutoSizeCalculationEnabled())
       
   729             {                
       
   730             TReal32 xratio = 1;
       
   731             TReal32 yratio = 1;
       
   732             
       
   733             // Take into account used texture coordinates of THuiImage       
       
   734             TReal32 relativeWidth = aImage.BottomRight().iX - aImage.TopLeft().iX;
       
   735             TReal32 relativeHeight = aImage.BottomRight().iY - aImage.TopLeft().iY;
       
   736             
       
   737             if (relativeWidth != 0.f && relativeHeight != 0.f)
       
   738                 {
       
   739                 xratio *= (1/relativeWidth);
       
   740                 yratio *= (1/relativeHeight);                
       
   741                 }
       
   742 
       
   743             TReal32 width = aRect.Size().iWidth * xratio;
       
   744             TReal32 height = aRect.Size().iHeight * yratio;
       
   745             
       
   746             // Take into account window transformation scale (To enable HiRes TV-OUT textures)
       
   747             // Other transformations are ignored for now. Possible those could be optionally
       
   748             // taken into account as well if resizing algortihm is lazy enough.
       
   749             CHuiTransformation* wt =  (CHuiTransformation*)WindowTransformation();
       
   750             if (wt)
       
   751                 {
       
   752                 TInt count = wt->Count();
       
   753                 for (TInt i=0;i<count;i++)
       
   754                     {
       
   755                     CHuiTransformation::TTransform& step = wt->Step(i);
       
   756                     if (step.iType == CHuiTransformation::ETypeScale)
       
   757                         {
       
   758                         width = width * step.iParams[EHuiTransformParamTranslateX].Now();    
       
   759                         height = height * step.iParams[EHuiTransformParamTranslateY].Now();    
       
   760                         }                        
       
   761                     }                    
       
   762                 }
       
   763             
       
   764             
       
   765             notifiedTexture->NotifyPreferredSize(THuiRealSize(width,height));    
       
   766             }
       
   767         }
       
   768     }
       
   769 
       
   770 EXPORT_C void CHuiGc::TransformDirtyRect(THuiRealRect& /*aRect*/)
       
   771     {
       
   772     // No sensible implementation for HuiGc base class. Implement at least in
       
   773     // HuiBitgdiGc child class.
       
   774     }
       
   775 
       
   776 EXPORT_C void CHuiGc::EnableTransformedClippingRects(TBool /*aEnable*/)
       
   777     {
       
   778     // No sensible implementation for HuiGc base class. Implement at least in
       
   779     // HuiBitgdiGc child class.
       
   780     }
       
   781 
       
   782 EXPORT_C void CHuiGc::SetClip(const TRect& /*aClipRect*/, TBool /*aTransformClipRect*/)
       
   783     {
       
   784     // No sensible implementation for HuiGc base class. Implement at least in
       
   785     // HuiBitgdiGc child class.
       
   786     }
       
   787 
       
   788 EXPORT_C void CHuiGc::GcExtension(const TUid& /*aExtensionUid*/, TAny** aExtensionParams)
       
   789     {
       
   790     // If no extension with given UID was found, indicate it by returning null
       
   791     *aExtensionParams = NULL;
       
   792     }
       
   793 
       
   794 RRegion* CHuiGc::CreateRecycledRegion()
       
   795     {
       
   796     RRegion* region = NULL;
       
   797     if (iRecycledRegions.Count())
       
   798         {
       
   799         // If there are recycled regionbufs, use one of those
       
   800         TInt last = iRecycledRegions.Count() - 1;
       
   801         region = iRecycledRegions[last];
       
   802         iRecycledRegions.Remove(last);    
       
   803         }
       
   804     else
       
   805         {
       
   806         // No recycled regionbufs available, create new one
       
   807         region = new RRegionBuf<KHuiGcClipRegionGranularity>();   
       
   808         }    
       
   809     return region;        
       
   810     }
       
   811 
       
   812 void CHuiGc::DeleteRecycledRegion(RRegion* aRegion)
       
   813     {
       
   814     TInt error = KErrNone;
       
   815     
       
   816     if (iRecycledRegions.Count() < KHuiMaxRecycledRegionCount)
       
   817         {
       
   818         aRegion->Clear();
       
   819         error = iRecycledRegions.Append(aRegion);            
       
   820         if (error)
       
   821             {
       
   822             aRegion->Destroy();
       
   823             }
       
   824         }
       
   825     else
       
   826         {
       
   827         aRegion->Destroy();
       
   828         }                    
       
   829     }