|
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 HuiVg10VGImageBinder |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "HuiVg10VgImageBinder.h" |
|
19 #include "HuiVg10RenderPlugin.h" |
|
20 #include "uiacceltk/HuiUtil.h" |
|
21 |
|
22 CHuiVg10VgImageBinder::CHuiVg10VgImageBinder(CHuiVg10RenderPlugin* aRenderPlugin): |
|
23 iRenderPlugin(aRenderPlugin) |
|
24 { |
|
25 } |
|
26 |
|
27 void CHuiVg10VgImageBinder::ConstructL() |
|
28 { |
|
29 } |
|
30 |
|
31 CHuiVg10VgImageBinder::~CHuiVg10VgImageBinder() |
|
32 { |
|
33 if (iEglPBufferSurface_Client) |
|
34 { |
|
35 eglDestroySurface( iRenderPlugin->EglDisplay(), iEglPBufferSurface_Client ); |
|
36 iEglPBufferSurface_Client = EGL_NO_SURFACE; |
|
37 } |
|
38 // Not owned, don't delete. |
|
39 iRenderPlugin = NULL; |
|
40 } |
|
41 |
|
42 CHuiVg10VgImageBinder* CHuiVg10VgImageBinder::NewL(CHuiVg10RenderPlugin* aRenderPlugin) |
|
43 { |
|
44 CHuiVg10VgImageBinder* self = new (ELeave) CHuiVg10VgImageBinder(aRenderPlugin); |
|
45 self->ConstructL(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 TInt CHuiVg10VgImageBinder::BindClientBuffer(TUint aBuffer) |
|
50 { |
|
51 // Check whether we should use the Alpha format bit |
|
52 VGImageFormat imageFormat = (VGImageFormat)vgGetParameteri(aBuffer, VG_IMAGE_FORMAT); |
|
53 TInt maskBit = 0; |
|
54 if (imageFormat == VG_sRGBA_8888_PRE) |
|
55 { |
|
56 maskBit = EGL_VG_ALPHA_FORMAT_PRE_BIT; |
|
57 } |
|
58 |
|
59 const TInt BITS_PER_CHANNEL = 8; |
|
60 // Choose an EGL config |
|
61 const EGLint attrs[] = |
|
62 { |
|
63 EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, |
|
64 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT | maskBit, |
|
65 EGL_RED_SIZE, BITS_PER_CHANNEL, |
|
66 EGL_GREEN_SIZE, BITS_PER_CHANNEL, |
|
67 EGL_BLUE_SIZE, BITS_PER_CHANNEL, |
|
68 EGL_ALPHA_SIZE, BITS_PER_CHANNEL, |
|
69 EGL_NONE |
|
70 }; |
|
71 |
|
72 // Create a context |
|
73 TInt configCount = iRenderPlugin->EglChooseConfig(attrs); |
|
74 EGLConfig config = iRenderPlugin->EglConfig(0); |
|
75 |
|
76 // Create a pbuffer surface |
|
77 iEglPBufferSurface_Client = eglCreatePbufferFromClientBuffer(iRenderPlugin->EglDisplay(), |
|
78 EGL_OPENVG_IMAGE, |
|
79 static_cast<EGLClientBuffer>(aBuffer), // Use the param image as buffer |
|
80 config, NULL); |
|
81 |
|
82 if (iEglPBufferSurface_Client == EGL_NO_SURFACE) |
|
83 { |
|
84 HUI_DEBUG1(_L("CHuiVg10VgImageBinder::BindClientBuffer() - EGL Surface could not be created, eglErr: %04x"), eglGetError() ); |
|
85 return KErrGeneral; |
|
86 } |
|
87 |
|
88 // Save current context and surfaces |
|
89 iSavedContext = eglGetCurrentContext(); |
|
90 iSavedDrawSurface = eglGetCurrentSurface(EGL_DRAW); |
|
91 iSavedReadSurface = eglGetCurrentSurface(EGL_READ); |
|
92 |
|
93 EGLContext context = iRenderPlugin->EglSharedContext(); |
|
94 |
|
95 // Bind our own PBuffer surface (from VGImage) |
|
96 if ( eglMakeCurrent(iRenderPlugin->EglDisplay(), iEglPBufferSurface_Client, iEglPBufferSurface_Client, context /*iSavedContext*/) == EGL_FALSE ) |
|
97 { |
|
98 HUI_DEBUG1(_L("CHuiVg10VgImageBinder::BindClientBuffer() - EGL Surface could not be made current, eglErr: %04x"), eglGetError()); |
|
99 return KErrGeneral; |
|
100 } |
|
101 |
|
102 // Alles in Ordnung! |
|
103 return KErrNone; |
|
104 } |
|
105 |
|
106 TInt CHuiVg10VgImageBinder::UnBindClientBuffer() |
|
107 { |
|
108 if ( eglMakeCurrent(iRenderPlugin->EglDisplay(), iSavedDrawSurface, iSavedReadSurface, iSavedContext) == EGL_FALSE ) |
|
109 { |
|
110 HUI_DEBUG1(_L("CHuiVg10VgImageBinder::BindClientBuffer() - EGL Surface could not be made current, eglErr: %04x"), eglGetError()); |
|
111 return KErrGeneral; |
|
112 } |
|
113 |
|
114 iSavedDrawSurface = 0; |
|
115 iSavedReadSurface = 0; |
|
116 iSavedContext = 0; |
|
117 |
|
118 if (iEglPBufferSurface_Client) |
|
119 { |
|
120 eglDestroySurface( iRenderPlugin->EglDisplay(), iEglPBufferSurface_Client ); |
|
121 iEglPBufferSurface_Client = EGL_NO_SURFACE; |
|
122 } |
|
123 |
|
124 // Everything went fine |
|
125 return KErrNone; |
|
126 } |
|
127 |
|
128 // End of file |
|
129 |