javauis/lcdui_akn/javalcdui/inc.nokialcdui/CMIDBufferProcessor.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     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:  Class for buffer processor.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CMIDBUFFERPROCESSOR_H
       
    20 #define CMIDBUFFERPROCESSOR_H
       
    21 
       
    22 
       
    23 #include <lcdui.h>
       
    24 #include "CMIDImage.h"
       
    25 #include "TMIDBitmapParameters.h"
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 
       
    29 class CMIDDirectGraphics;
       
    30 class CMIDGraphics;
       
    31 class CMIDToolkit;
       
    32 
       
    33 NONSHARABLE_CLASS(CMIDBufferProcessor): public CBase,
       
    34         public MMIDBufferProcessor, public MMIDComponent
       
    35 {
       
    36 public: // Construction
       
    37     static void NewL(CMIDToolkit* aToolkit, TInt* aHandle,
       
    38     CMIDGraphics* aGraphics, MMIDImage* aImage);
       
    39 
       
    40 public: // Destructor
       
    41     ~CMIDBufferProcessor();
       
    42 
       
    43 public: // From MMIDComponent
       
    44     void Dispose();
       
    45     TType Type() const;
       
    46     MMIDBufferProcessor* Processor();
       
    47 
       
    48 public:// From MMIDBufferProcessor
       
    49 #ifdef RD_JAVA_NGA_ENABLED
       
    50     TBool ProcessL(const TMIDBufferOp*& aBegin,
       
    51                    const TMIDBufferOp* aEnd, TInt& aCycles, java::util::Monitor* aMonitor);
       
    52 #else
       
    53     TBool ProcessL(const TMIDBufferOp*& aBegin,
       
    54                    const TMIDBufferOp* aEnd, TInt& aCycles, TRequestStatus* aStatus = NULL);
       
    55 #endif
       
    56     void  AbortAsync();
       
    57 
       
    58 public: // data
       
    59     // Owned
       
    60     CMIDDirectGraphics* iDirectGraphics;
       
    61     // Not owned
       
    62     CMIDGraphics* iGraphics;
       
    63 
       
    64 protected: // Construction
       
    65     CMIDBufferProcessor();
       
    66     void ConstructL(CMIDGraphics* aGraphics, MMIDImage* aImage);
       
    67 
       
    68 private:
       
    69 
       
    70     enum
       
    71     {
       
    72         EDrawTriangle = 102,
       
    73         EFillTriangle = 103,
       
    74         EDrawImage = 104
       
    75     };
       
    76 
       
    77     class TClipData
       
    78     {
       
    79     public:
       
    80         TPoint iTl;
       
    81         TSize iSize;
       
    82     };
       
    83 
       
    84     class TTriangleData
       
    85     {
       
    86     public:
       
    87         TInt x1;
       
    88         TInt y1;
       
    89         TInt x2;
       
    90         TInt y2;
       
    91         TInt x3;
       
    92         TInt y3;
       
    93         TInt color;
       
    94     };
       
    95     class TDirectImageData
       
    96     {
       
    97     public:
       
    98         TInt    iImage;
       
    99         TPoint  iPoint;
       
   100         TInt    iAnchor;
       
   101         TInt    iManipulation;
       
   102     };
       
   103 
       
   104     inline const TTriangleData& TriangleData(const TMIDBufferOp* aOp);
       
   105     inline const TRect RectData(const TMIDBufferOp* aOp);
       
   106     inline void UnlockedBitmapParameters(TMIDBitmapParameters& aParams,
       
   107                                          const TMIDBufferOp* aOp);
       
   108     inline void LockedBitmapParameters(TMIDBitmapParameters& aParams);
       
   109 
       
   110     /**
       
   111      * Draws image
       
   112      * @param aRead contains the image information
       
   113      * @param aUtil is used for locking the target bitmap
       
   114      */
       
   115     void DrawImageL(const TMIDBufferOp* aRead,
       
   116                     TBitmapUtil& aUtil);
       
   117 
       
   118     /**
       
   119      * Draws image. All bitmaps must be locked before calling this.
       
   120      * @param aParams contains the image information
       
   121      * @param aSourceUtil is used for locking the source bitmap
       
   122      * @param aTargetUtil is used for locking the target bitmap
       
   123      */
       
   124     void LockedDrawImageL(TMIDBitmapParameters& aParams,
       
   125                           TBitmapUtil& aSourceUtil,
       
   126                           TBitmapUtil& aTargetUtil);
       
   127 
       
   128 
       
   129     void DrawTriangle(const TTriangleData& aTriangle);
       
   130     void FillTriangle(const TTriangleData& aTriangle);
       
   131     void SetClipRect(const TRect& aRect);
       
   132 };
       
   133 
       
   134 template<class T>
       
   135 inline const T& OpData(const TMIDBufferOp* aOp)
       
   136 {
       
   137     ASSERT(aOp->Size() >= TInt(1 + (sizeof(T)/sizeof(TMIDBufferOp))));
       
   138     return *static_cast<const T*>(aOp->Data());
       
   139 }
       
   140 
       
   141 inline const CMIDBufferProcessor::TTriangleData&
       
   142 CMIDBufferProcessor::TriangleData(const TMIDBufferOp* aOp)
       
   143 {
       
   144     return OpData<CMIDBufferProcessor::TTriangleData>(aOp);
       
   145 }
       
   146 
       
   147 inline void
       
   148 CMIDBufferProcessor::UnlockedBitmapParameters(TMIDBitmapParameters& aParams,
       
   149         const TMIDBufferOp* aOp)
       
   150 {
       
   151     TDirectImageData imageData = OpData<CMIDBufferProcessor::TDirectImageData>(aOp);
       
   152 
       
   153     MMIDImage* image = MIDUnhandObject< MMIDImage >(imageData.iImage);
       
   154 
       
   155     // note: getting bitmap image increases its reference count
       
   156     MMIDBitmapImage* bitmapImage = image->BitmapImage();
       
   157 
       
   158     aParams.iBitmap = bitmapImage->ColorBitmap();
       
   159     CFbsBitmap* alphaBitmap = bitmapImage->AlphaBitmap();
       
   160     if (alphaBitmap)
       
   161     {
       
   162         aParams.iTransparency = ETrue;
       
   163         alphaBitmap->LockHeap();
       
   164         aParams.iAlpha = alphaBitmap->DataAddress();
       
   165         aParams.iAlphaMode = alphaBitmap->DisplayMode();
       
   166         TSize bitmapSize(alphaBitmap->SizeInPixels());
       
   167         TInt scanLineLength =
       
   168             CFbsBitmap::ScanLineLength(bitmapSize.iWidth,
       
   169                                        alphaBitmap->DisplayMode());
       
   170         TInt bitsPerPixel = alphaBitmap->Header().iBitsPerPixel;
       
   171         scanLineLength = (scanLineLength << 3) / bitsPerPixel;
       
   172         aParams.iAlphaSize = (scanLineLength * bitmapSize.iHeight *
       
   173                               bitsPerPixel) >> 3;
       
   174         alphaBitmap->UnlockHeap();
       
   175     }
       
   176 
       
   177     aParams.iManipulation = imageData.iManipulation;
       
   178     aParams.iAnchor = imageData.iAnchor;
       
   179     aParams.iX = imageData.iPoint.iX;
       
   180     aParams.iY = imageData.iPoint.iY;
       
   181 
       
   182     bitmapImage->RemoveRef();
       
   183 }
       
   184 
       
   185 inline void
       
   186 CMIDBufferProcessor::LockedBitmapParameters(TMIDBitmapParameters& aParams)
       
   187 {
       
   188     TSize bitmapSize(aParams.iBitmap->SizeInPixels());
       
   189     aParams.iWidth = bitmapSize.iWidth;
       
   190     aParams.iHeight = bitmapSize.iHeight;
       
   191 
       
   192     aParams.iScanLength =
       
   193         CFbsBitmap::ScanLineLength(bitmapSize.iWidth,
       
   194                                    aParams.iBitmap->DisplayMode());
       
   195     aParams.iScanLength = (aParams.iScanLength << 3) /
       
   196                           aParams.iBitmap->Header().iBitsPerPixel;
       
   197 
       
   198     aParams.iPixels = aParams.iBitmap->DataAddress();
       
   199     aParams.iPixelsSize = (aParams.iScanLength *
       
   200                            bitmapSize.iHeight *
       
   201                            aParams.iBitmap->Header().iBitsPerPixel) >> 3;
       
   202 
       
   203 }
       
   204 
       
   205 inline const TRect CMIDBufferProcessor::RectData(const TMIDBufferOp* aOp)
       
   206 {
       
   207     const TClipData& clipData = OpData< TClipData >(aOp);
       
   208     const TRect clipRect(clipData.iTl, clipData.iSize);
       
   209     return clipRect;
       
   210 }
       
   211 
       
   212 #endif // CMIDBUFFERPROCESSOR_H