uiacceltk/hitchcock/coretoolkit/rendervg10/inc/HuiVg10RenderPlugin.h
changeset 0 15bf7259bb7c
child 17 3ac8bf5c5014
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-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:   Definition of CHuiVg10RenderPlugin. Rendering plugin for OpenVG 1.0.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __HUIVG10RENDERPLUGIN_H__
       
    21 #define __HUIVG10RENDERPLUGIN_H__
       
    22 
       
    23 
       
    24 #include <e32base.h>
       
    25 
       
    26 #include <EGL/egl.h>
       
    27 
       
    28 #include <VG/openvg.h>
       
    29 
       
    30 #include "HuiRenderPlugin.h"
       
    31 #include "uiacceltk/HuiPanic.h"
       
    32 #include "uiacceltk/HuiMesh.h"
       
    33 
       
    34 class TEGLState
       
    35     {
       
    36 public:
       
    37     EGLContext iContext;
       
    38     EGLSurface iReadSurface;
       
    39     EGLSurface iDrawSurface;
       
    40     EGLDisplay iDisplay;
       
    41     };
       
    42 
       
    43 /**
       
    44  * OpenVG renderer specific state change flags
       
    45  */
       
    46 enum THuiVg10GcStateFlags
       
    47     {
       
    48     EHuiVg10GcStateFlagDirtyMatrixMode      = 1,
       
    49     EHuiVg10GcStateFlagDirtyMatrix          = 2,
       
    50     EHuiVg10GcStateFlagDirtyPaint           = 4,
       
    51     EHuiVg10GcStateFlagDirtyScissor         = 8,
       
    52     EHuiVg10GcStateFlagDirtyScissorRects    = 0x10,
       
    53     EHuiVg10GcStateFlagDirtyBlendMode       = 0x20
       
    54     };
       
    55 
       
    56 /* Forward declarations. */
       
    57 class MHuiRenderSurface;
       
    58 class CHuiVg10PBufferSurface;
       
    59 #ifdef __NVG
       
    60 class CNvgEngine;
       
    61 class MVGImageBinder;
       
    62 #endif
       
    63 
       
    64 /** Number of compatible EGL configurations queried. */
       
    65 const TInt KVg10ConfigsCount = 2;
       
    66 
       
    67 /**
       
    68  * Macro for asserting that the renderer's state is OK when entering
       
    69  * a function.
       
    70  */
       
    71 #define HUI_VG_INVARIANT() __ASSERT_DEBUG(CHuiVg10RenderPlugin::VgError() == VG_NO_ERROR, THuiPanic::Panic(THuiPanic::EVg10Invariant))
       
    72 
       
    73 /**
       
    74  * Macro for asserting that the latest OpenVG function call did not
       
    75  * fail. You may put this assert after any OpenVG function call.
       
    76  * Has no effect in release builds.
       
    77  *
       
    78  * @param aPanic  Panic code to use if the assertion fails.
       
    79  *
       
    80  * @see THuiPanic error codes, for at least the ERendererError.
       
    81  */
       
    82 #define HUI_VG_ASSERT_SUCCESS(aPanic) __ASSERT_DEBUG(CHuiVg10RenderPlugin::VgError() == VG_NO_ERROR, THuiPanic::Panic(aPanic))
       
    83 
       
    84 
       
    85 /**
       
    86  * Rendering plugin for OpenVG 1.0.
       
    87  *
       
    88  * @todo  GHuiVg10RenderPlugin should be derived from an abstract
       
    89  *        CHuiEglRenderPlugin, which would contain the common EGL-methods.
       
    90  *        OpenVG uses EGL, too.
       
    91  */
       
    92 NONSHARABLE_CLASS(CHuiVg10RenderPlugin) : public CHuiRenderPlugin
       
    93     {
       
    94 public:
       
    95 
       
    96     /* Constructors and destructor. */
       
    97 
       
    98     /**
       
    99      * Constructs a new OpenVG 1.0 rendering plugin instance.
       
   100      */
       
   101     static CHuiVg10RenderPlugin* NewL();
       
   102 
       
   103     /**
       
   104      * Constructs a new OpenVG 1.0 rendering plugin instance and leaves it
       
   105      * on the cleanup stack.
       
   106      */
       
   107     static CHuiVg10RenderPlugin* NewLC();
       
   108 
       
   109 
       
   110     /**
       
   111      * Destructor.
       
   112      */
       
   113     virtual ~CHuiVg10RenderPlugin();
       
   114 
       
   115 
       
   116     /* Methods. */
       
   117 
       
   118     TBool Allows(THuiRenderPluginAllow aAllow) const;
       
   119 
       
   120     /**
       
   121      * Creates a new rendering surface.
       
   122      *
       
   123      * @param aParams  Parameters for the surface. Ends in EHuiRenderSurfaceNone.
       
   124      */
       
   125     virtual MHuiRenderSurface* CreateRenderSurfaceL(CHuiDisplay& aDisplay);
       
   126 
       
   127     /**
       
   128      * Creates a new PBuffer surface for off-screen rendering purposes.
       
   129      *
       
   130      * @param aSize Size of the created PBuffer surface.
       
   131      * @return Pointer to the just created PBuffer surface object.
       
   132      */
       
   133     virtual CHuiVg10PBufferSurface* CreatePBufferSurfaceL(TSize aSize, TInt aEglBufferType = EGL_PBUFFER_BIT, TInt aBufferColorMode = 0);
       
   134 
       
   135     /**
       
   136      * Creates a new instance of a HUITK graphics context.
       
   137      */
       
   138     virtual CHuiGc* CreateGcL();
       
   139 
       
   140     /**
       
   141      * Creates a new instance of a texture.
       
   142      */
       
   143     virtual CHuiTexture* CreateTextureL(const THuiTextureHandle* aExistingTexture = 0);
       
   144 
       
   145     /**
       
   146      * Creates a new instance of a texture manager.
       
   147      */
       
   148     virtual CHuiTextureManager* CreateTextureManagerL(CHuiEnv& aEnv);
       
   149 
       
   150     /**
       
   151      * Creates a new instance of an effects engine.
       
   152      */
       
   153     virtual CHuiFxEngine* CreateEffectsEngineL();
       
   154 
       
   155 
       
   156     /**
       
   157      * Creates a new instance of a mesh. Leaves with KErrNotSupported if this renderer
       
   158      * does not support the given mesh type
       
   159      *
       
   160      * @param aMeshType  CHuiMesh derived concrete mesh type
       
   161      * 
       
   162      * @return  Created concrete mesh implementation.
       
   163      */
       
   164     virtual CHuiMesh* CreateMeshL(THuiMeshType aMeshType);
       
   165 
       
   166     /**
       
   167      * Creates a new instance of a text mesh.
       
   168      */
       
   169     virtual CHuiTextMesh* CreateTextMeshL();
       
   170 
       
   171     /**
       
   172      * Creates a new instance of a curve path.
       
   173      */
       
   174     virtual CHuiCurvePath* CreateCurvePathL();
       
   175 
       
   176     virtual void DeleteNamedTexture(TUint aName);
       
   177 
       
   178     /**
       
   179      * Notifies this render plugin of a change in current display count.
       
   180      *
       
   181      * @param aCount The current count of displays existing in the HuiToolkit environment.
       
   182      */
       
   183     virtual void NotifyDisplayCountL(TUint aCount);
       
   184 
       
   185     /**
       
   186      * Returns the EGL display currently used by the plugin.
       
   187      */
       
   188     EGLConfig EglDisplay();
       
   189 
       
   190     /**
       
   191      * Returns the shared EGL context.
       
   192      *
       
   193      * @param aOtherContext  Context that wants to join the shared context.
       
   194      */
       
   195     EGLContext EglSharedContext() const;
       
   196 
       
   197     /**
       
   198      * Sets the shared EGL context.
       
   199      *
       
   200      * @param aContext  Context that is available for sharing with.
       
   201      */
       
   202     void EglSetSharedContext(EGLContext aContext);
       
   203 
       
   204     /**
       
   205      * EGL utility method. See eglChooseConfig.
       
   206      *
       
   207      * @return  Number of configurations found.
       
   208      */
       
   209     TInt EglChooseConfig(const TInt* aAttribList);
       
   210 
       
   211     /**
       
   212      * EGL utility method. Returns one of the configurations determined by
       
   213      * EglChooseConfig.
       
   214      */
       
   215     TInt EglConfig(TInt aIndex);
       
   216 
       
   217     /**
       
   218      * EGL debug method. Prints (using CHuiStatic::Printf) all the attributes of
       
   219      * the specified configuration.
       
   220      */
       
   221     void EglPrintConfig(TInt aIndex);
       
   222 
       
   223     /**
       
   224      * Check if the OpenVG context is released. If it is released,
       
   225      * any drawing commands to the context will cause a panic.
       
   226      *
       
   227      * @return ETrue if the OpenVG context has been released.
       
   228      */
       
   229      TBool IsReleased() const;
       
   230 
       
   231     /* Static methods. */
       
   232 
       
   233     /**
       
   234      * GlErrorMessage returns string description for an OpenVG
       
   235      * error code. Can be used to clarify OpenVG errors when debugging.
       
   236      *
       
   237      * Error codes are from from the OpenVG 1.0 specification, chapter 4.
       
   238      *
       
   239      * @param aErrorCode  OpenVG error code, usually requested by calling
       
   240      *                    vgGetError().
       
   241      * @return  Descriptor with the error message.
       
   242      */
       
   243     static const TDesC& VgErrorMessage(VGErrorCode aErrorCode);
       
   244 
       
   245     /**
       
   246      * Returns the latest OpenVG error code. Equivalent to calling vgGetError(),
       
   247      * but also prints the GL error code as a debug message.
       
   248      */
       
   249     static VGErrorCode VgError();
       
   250 	
       
   251 	/**
       
   252 	 * IsHardwareAccelerated returns boolean value if hardware acceleration 
       
   253 	 * is available. Also stores value to the iIsHardwareAccelerated variable.
       
   254 	 *
       
   255 	 * @return  ETrue if hardware accelartion is available
       
   256 	 */
       
   257 	TBool IsHardwareAccelerated();
       
   258 	
       
   259     /**
       
   260      * Creates a new instance of a canvas graphics context.
       
   261      */
       
   262    virtual CHuiCanvasGc* CreateCanvasGcL();
       
   263 
       
   264    /**
       
   265     * Used to set flags that describe how the openvg state has changed.
       
   266     */
       
   267    virtual void AddRestoreStateFlags(TInt aFlags);
       
   268    
       
   269    /**
       
   270     * Return the flags, e.g. for vg10gc to reset its state
       
   271     */
       
   272    virtual TInt GetRestoreStateFlags();
       
   273    
       
   274    /**
       
   275     * Clear the stateflags
       
   276     */
       
   277    virtual void ClearRestoreStateFlags();
       
   278    
       
   279 #ifdef __NVG
       
   280    /**
       
   281     * Getter for NVGEngine, to be used with NVG drawing inside OpenVG plugin
       
   282     * 
       
   283     * @return   CNvgEngine object
       
   284     */
       
   285    CNvgEngine& NvgEngine() const;
       
   286 #endif
       
   287 
       
   288 	/**
       
   289 	*  Getter for texture upload context. This is called by CHuiVg10Texture.
       
   290 	*/
       
   291     TEGLState& GetUploadState()
       
   292 	    {
       
   293 	    return iEGLStateForTextureUpload;
       
   294 	    }
       
   295 	
       
   296 protected:
       
   297 
       
   298     /* Constructors. */
       
   299 
       
   300     /**
       
   301      * Default constructor.
       
   302      */
       
   303     CHuiVg10RenderPlugin(THuiRenderPluginId aId = EHuiRenderPluginVg10);
       
   304 
       
   305     /**
       
   306      * Second-phase constructor. Basicly calls RestoreL().
       
   307      */
       
   308     void ConstructL();
       
   309 
       
   310     /**
       
   311      * Release resources associated with EGL and OpenVG.
       
   312      * Also, will destroy the default render surface used
       
   313      * for sharing resources.
       
   314      *
       
   315      * @see RestoreL()
       
   316      */
       
   317     virtual void Release();
       
   318 
       
   319     /**
       
   320      * Restores resources needed for EGL/OpenVG rendering.
       
   321      * Finds an EGL display, initializes it for rendering
       
   322      * and restores a default shared render surface that
       
   323      * enables resources to be loaded without an existing
       
   324      * CHuiDisplay.
       
   325      */
       
   326     virtual void RestoreL();
       
   327 
       
   328 private:
       
   329     
       
   330     void ReadAllowsSwapBufferPreserved();
       
   331     void ReadAllowsVisualPBufferSurfaces();
       
   332         
       
   333 private:
       
   334 
       
   335     /** The display where the graphics are drawn. */
       
   336     EGLDisplay iEglDisplay;
       
   337 
       
   338     /** Describes the format, type and size of the color buffers and
       
   339         ancillary buffers for EGLSurface. */
       
   340     EGLConfig iConfigs[KVg10ConfigsCount];
       
   341 
       
   342     /**
       
   343      * EGL Context for shared resources. This will allow us to
       
   344      * for instance preload and create textures before actual
       
   345      * rendering surface exists.
       
   346      */
       
   347     EGLContext iSharedContext;
       
   348 
       
   349     /**
       
   350      * Dummy PBuffer surface to be used with default context before any
       
   351      * other rendering surfaces exist.
       
   352      */
       
   353     CHuiVg10PBufferSurface* iDefaultRenderSurface;
       
   354 
       
   355     TBool iIsHardwareAccelerated;
       
   356     
       
   357     /**
       
   358      * Member that stores the changed flags
       
   359      */
       
   360 	TInt iStateFlags;
       
   361     
       
   362 #ifdef __NVG
       
   363     /** NVG decoder for plugin classes to use **/
       
   364     CNvgEngine* iNvgEngine;
       
   365     /** Image binder for NVG-TLV "Group opacity" special case */
       
   366     MVGImageBinder* iMVGImageBinder;
       
   367 #endif
       
   368     
       
   369     TBool iAllowsSwapBufferPreserved;
       
   370     TBool iAllowsVisualPBufferSurfaces;
       
   371     
       
   372 	// This is initialized by CHuiVg10Texture during first texture upload
       
   373     TEGLState iEGLStateForTextureUpload;
       
   374     
       
   375     };
       
   376 
       
   377 
       
   378 #endif // __HUIVG10RENDERPLUGIN_H__