uiacceltk/hitchcock/ServerCore/Src/alfwindowbuffer.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <fbs.h>
       
    21 #include <bitdev.h>
       
    22 #include "alfwindowbuffer.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // TAlfWindowBufferData class declaration
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 class CAlfWindowBuffer::TAlfWindowBufferData
       
    29     {
       
    30     public:   
       
    31     TSize iSize;
       
    32     TInt iFormat;
       
    33     TUint iStride;
       
    34     TAny* iBufferPtr;
       
    35     CFbsBitmap* iTemp; // RnD enablers
       
    36     };
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // NewL
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C CAlfWindowBuffer* CAlfWindowBuffer::NewL( const TSize& aSize, 
       
    43                                             TInt aBufferFormat, 
       
    44                                             TUint aStrideInBytes, 
       
    45                                             TAny* aPtr)
       
    46     {
       
    47     CAlfWindowBuffer* self = new (ELeave) CAlfWindowBuffer;
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL(aSize, aBufferFormat, aStrideInBytes, aPtr);
       
    50     CleanupStack::Pop();
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // destructor
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 EXPORT_C CAlfWindowBuffer::~CAlfWindowBuffer()
       
    59     {
       
    60     if (iData)
       
    61         {
       
    62         delete iData->iTemp;
       
    63         delete iData;
       
    64         }
       
    65     }
       
    66         
       
    67 // ---------------------------------------------------------------------------
       
    68 // Size
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C TSize CAlfWindowBuffer::Size() const
       
    72     {
       
    73     if (iData)
       
    74         {
       
    75         return iData->iSize;
       
    76         }
       
    77     return TSize(0,0);
       
    78     }
       
    79     
       
    80 // ---------------------------------------------------------------------------
       
    81 // Format
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C TInt CAlfWindowBuffer::Format() const
       
    85     {
       
    86     if (iData)
       
    87         {
       
    88         return EColor16MA;
       
    89         //return iData->iFormat;
       
    90         }
       
    91     return 0;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // Stride
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C TUint CAlfWindowBuffer::Stride() const
       
    99     {
       
   100     if (iData)
       
   101         {
       
   102         return iData->iTemp->DataStride();
       
   103         //return iData->iStride;
       
   104         }
       
   105     return 0;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // BufferPtr
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C TAny* CAlfWindowBuffer::BufferPtr() const
       
   113     {
       
   114     if (iData)
       
   115         {
       
   116         return iData->iTemp->DataAddress(); // currently safe...
       
   117         //return iData->iBufferPtr;
       
   118         }
       
   119     return NULL;
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // SetSize
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C void CAlfWindowBuffer::SetSize(const TSize& aSize)
       
   127     {
       
   128     iData->iSize = aSize;
       
   129     //RnD
       
   130     iData->iTemp->Resize(aSize);
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // SetFormat
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C void CAlfWindowBuffer::SetFormat(TInt aBufferFormat)   
       
   138     {
       
   139     iData->iFormat = aBufferFormat;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // SetStride
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C void CAlfWindowBuffer::SetStride(TUint aStrideInBytes)
       
   147     {
       
   148     iData->iStride = aStrideInBytes;
       
   149     }
       
   150     
       
   151 // ---------------------------------------------------------------------------
       
   152 // SetBufferPtr
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void CAlfWindowBuffer::SetBufferPtr(TAny* aPtr) const
       
   156     {
       
   157     iData->iBufferPtr = aPtr;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // constructor
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 CAlfWindowBuffer::CAlfWindowBuffer()
       
   165     {
       
   166     }
       
   167     
       
   168 // ---------------------------------------------------------------------------
       
   169 // ConstructL
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CAlfWindowBuffer::ConstructL(const TSize& aSize, TInt aBufferFormat, TUint aStride, TAny* aPtr)
       
   173     {
       
   174     iData = new (ELeave)TAlfWindowBufferData;
       
   175     memset(iData,0,sizeof(TAlfWindowBufferData));
       
   176     iData->iBufferPtr = aPtr;
       
   177     iData->iFormat = aBufferFormat;
       
   178     iData->iSize = aSize;
       
   179     iData->iStride = aStride;    
       
   180     // RnD
       
   181     iData->iTemp = new (ELeave) CFbsBitmap();
       
   182     User::LeaveIfError(iData->iTemp->Create(aSize, EColor16MA));
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // ConstructL
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CAlfWindowBuffer* CAlfWindowBuffer::CreateCopyL(TBool aCopyContents )
       
   191     {
       
   192     CAlfWindowBuffer* copy = CAlfWindowBuffer::NewL( iData->iSize, 
       
   193                                             iData->iFormat, 
       
   194                                             iData->iStride, 
       
   195                                             iData->iBufferPtr);
       
   196     
       
   197     
       
   198     if (aCopyContents)
       
   199         {
       
   200         // Todo: memcopy would be likely faster and this works for bmp only..
       
   201         CleanupStack::PushL(copy);
       
   202         CFbsBitmapDevice* bd = CFbsBitmapDevice::NewL( copy->Bmp() );
       
   203         CleanupStack::PushL(bd);
       
   204         CFbsBitGc * gc = 0; 
       
   205         User::LeaveIfError(bd->CreateContext( gc ));
       
   206         gc->BitBlt(TPoint(0,0), Bmp());
       
   207         delete gc;
       
   208         CleanupStack::PopAndDestroy(2);
       
   209         }
       
   210        
       
   211 
       
   212     
       
   213     return copy;
       
   214     }
       
   215 
       
   216 
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // Handle
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 TInt CAlfWindowBuffer::Handle()
       
   223     {
       
   224     if (iData && iData->iTemp)
       
   225         {
       
   226         return iData->iTemp->Handle();
       
   227         }
       
   228     
       
   229     return 0;
       
   230     }
       
   231     
       
   232 // ---------------------------------------------------------------------------
       
   233 // Bmp
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 CFbsBitmap* CAlfWindowBuffer::Bmp()
       
   237     {
       
   238     if (iData && iData->iTemp)
       
   239         {
       
   240         return iData->iTemp;
       
   241         }
       
   242     
       
   243     return 0;
       
   244     }