os/graphics/graphicsdeviceinterface/directgdiadaptation/hwsrc/directgdidriverprocessstate.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // directhdidriverprocessstate.h
    15 // 
    16 //
    17 
    18 #ifndef _DIRECTGDIDRIVERPROCESSSTATE_H_
    19 #define _DIRECTGDIDRIVERPROCESSSTATE_H_
    20 
    21 /**
    22 @file
    23 @internalComponent
    24 */
    25 
    26 #include "directgdiadapter.h"
    27 #include <graphics/sgimage.h>
    28 #include <EGL/egl.h>
    29 #include <VG/openvg.h>
    30 #include <e32base.h>
    31 
    32 
    33 /**
    34 Function pointers for use with eglGetProcAddress for creation and deletion of EGLImages and creation of VGImages
    35  */
    36 typedef EGLImageKHR (*TeglCreateImageKHRTypefPtr) (EGLDisplay dpy, EGLContext ctx, EGLenum aTarget, EGLClientBuffer buffer, EGLint*attrib_list);
    37 typedef EGLBoolean (*TeglDestroyImageKHRTypefPtr) (EGLDisplay dpy, EGLImageKHR image);
    38 typedef EGLBoolean (*TvgCreateEGLImageTargetKHRTypefPtr) (VGeglImageKHR image);
    39 
    40 /**
    41 Helper class used by CDirectGdiDriverProcessState to group together related EGL and VG images.
    42  */
    43 NONSHARABLE_CLASS(CImageSourceData): public CBase
    44 	{
    45 public:
    46 	CImageSourceData(const TSgDrawableId& aSgImageId, EGLImageKHR aEglImage, VGImage aVgImage);
    47 	virtual ~CImageSourceData();
    48 	
    49 	inline const TSgDrawableId& SgImageId() const; 
    50 	inline EGLImageKHR EglImage() const;
    51 	inline VGImage VgImage() const;
    52 	inline TInt Open();
    53 	inline TInt Close();	
    54 	
    55 private:
    56 	TSgDrawableId iSgImageId;
    57 	EGLImageKHR iEglImage;
    58 	VGImage iVgImage;
    59 	TInt iRefCount;	
    60 	};
    61 
    62 
    63 
    64 /**
    65 Class for storing the state of CDirectGdiDriver objects within the current process. This class is 
    66 responsible for maintaining an instance count of the number of drivers open in this process. There may 
    67 be more than one thread that creates and opens a driver in this process. This class initializes EGL and  
    68 terminates it using an instance count, as EGL terminate should not be called until all drivers in this 
    69 process have been closed, not when each thread closes as another thread may be using EGL in the same
    70 process.
    71 
    72 This class is also responsible for storing a list of all EGLImageKHR objects and associated RSgImage IDs
    73 created in this process, as there is a restriction that an EGLImageKHR can only be created
    74 from a particular RSgImage once per process. This allows EGL images that have already been created
    75 from RSgImages to be shared among threads. The list of EGL images is created on a shared process heap
    76 so that it can be shared between all threads.
    77 
    78 Users of this class should call CreateVGImageFromSgImage
    79  */
    80 NONSHARABLE_CLASS(XDirectGdiDriverProcessState): public CBase
    81 	{
    82 public:
    83 	XDirectGdiDriverProcessState();	
    84 	virtual ~XDirectGdiDriverProcessState();
    85 		
    86 	TInt Initialize(EGLDisplay aDisplay);
    87 	TInt CreateVgImage(EGLDisplay aDisplay, VGImage& aVgImageRet, const RSgImage& aSgImage);
    88 	TInt DestroyVgImage(EGLDisplay aDisplay, VGImage aVgImage);
    89 	
    90 	void OpenDriver();
    91 	void CloseDriver(EGLDisplay& aDriverEglDisplay);
    92 	
    93 	inline TInt MutexCreationStatus() const;
    94 	
    95 private:	
    96 	TInt CheckAllEglExtensions(EGLDisplay aDisplay) const ;
    97 	TInt CheckForEglExtension(EGLDisplay aDisplay, const TDesC8& aExtensionString) const;
    98 	
    99 	// Always use the mutex iImagesMutex around the following methods
   100 	TBool ImageExists(const RSgImage& aSgImage, VGImage& aVgImageRet);
   101 	CImageSourceData* FindImage(const RSgImage& aSgImage);
   102 	TInt AddImage(const RSgImage& aSgImage, EGLImageKHR aEglImage, VGImage aVgImage);
   103 	TInt RemoveImage(EGLDisplay aDisplay, VGImage aVgImage);
   104 		
   105 	TInt iDriverInstanceCount;
   106 	RHeap* iLocalHeap;		
   107 	RPointerArray<CImageSourceData> iImages;
   108 	RMutex iMutex;
   109 	// Holds the error state for creating the mutex in the constructor, so that it can be reported
   110 	// outside of the constructor.
   111 	TInt iCreateMutexErr;	
   112 	TBool iCheckedExtensionsAvailable;
   113 	
   114 	// Function pointers for creation and destruction of EGLImageKHR and creation of VGImage
   115 	TeglCreateImageKHRTypefPtr iPfnEglCreateImageKHR;
   116 	TeglDestroyImageKHRTypefPtr iPfnEglDestroyImageKHR;
   117 	TvgCreateEGLImageTargetKHRTypefPtr iPfnVgCreateImageTargetKHR;
   118 	};
   119 
   120 
   121 #include "directgdidriverprocessstate.inl"
   122 
   123 #endif // _DIRECTGDIDRIVERPROCESSSTATE_H_