|
1 // Copyright (c) 2010 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 // |
|
15 |
|
16 |
|
17 /** |
|
18 @file |
|
19 @publishedPartner |
|
20 @prototype |
|
21 */ |
|
22 |
|
23 |
|
24 #include "eglwindowinterface.h" |
|
25 #include "eglwindow.h" |
|
26 #include <e32base.h> |
|
27 #include <w32std.h> |
|
28 #include <hal.h> |
|
29 |
|
30 |
|
31 EXPORT_C TEglWindowInterface::TEglWindowInterface(EGLNativeWindowType aNativeWindow) : |
|
32 iEglWindow(reinterpret_cast<REglWindowBase*>(aNativeWindow)) |
|
33 { |
|
34 } |
|
35 |
|
36 |
|
37 EXPORT_C TBool TEglWindowInterface::IsValid() const |
|
38 { |
|
39 if(iEglWindow->IsRWindow()) |
|
40 { |
|
41 TInt wsHandle = reinterpret_cast<const RWindow*>(iEglWindow)->WsHandle(); |
|
42 return (wsHandle != 0); |
|
43 } |
|
44 else |
|
45 { |
|
46 return iEglWindow->IsValid(); |
|
47 } |
|
48 } |
|
49 |
|
50 |
|
51 EXPORT_C TSize TEglWindowInterface::SizeInPixels() const |
|
52 { |
|
53 if(iEglWindow->IsRWindow()) |
|
54 { |
|
55 return reinterpret_cast<const RWindow*>(iEglWindow)->Size(); |
|
56 } |
|
57 else |
|
58 { |
|
59 return iEglWindow->SizeInPixels(); |
|
60 } |
|
61 } |
|
62 |
|
63 |
|
64 EXPORT_C TSize TEglWindowInterface::SizeInTwips() const |
|
65 { |
|
66 if(iEglWindow->IsRWindow()) |
|
67 { |
|
68 //This is a simple solution to get the twip size of an RWindow. |
|
69 //A temporary CWsScreenDevice is constructed for the screen that |
|
70 //the RWindow exists on and is used to convert the size in pixels |
|
71 //to a size in twips. The temporary CWsScreenDevice is then destructed. |
|
72 //If this is found to be non-performant, we could use a TLS thread |
|
73 //singleton that lazily creates screen devices and maintains a list |
|
74 //thoughout its lifetime. The singleton could be destroyed though a |
|
75 //static function on TEglWindowInterface as part of eglReleaseThread(). |
|
76 //This represents more complexity and should only be considered as an |
|
77 //optimisation if it is found to be neccessary. Note that use of the HAL |
|
78 //interface is not really an option, since we need to find the pixel |
|
79 //size of the screen and this could be virtualised by the screen. |
|
80 |
|
81 const RWindow* window = reinterpret_cast<const RWindow*>(iEglWindow); |
|
82 RWsSession* winSession = window->Session(); |
|
83 EGL_WINDOW_ASSERT_DEBUG(winSession, EEglWindowPanicRWindowHasNoSession); |
|
84 |
|
85 //Do a placement new to avoid the possible KErrNoMemory error. |
|
86 TUint8 screenDevMem[sizeof(CWsScreenDevice)]; |
|
87 CWsScreenDevice* screenDev = new (screenDevMem) CWsScreenDevice(*winSession); |
|
88 |
|
89 //Nothing we can do about this error. |
|
90 TInt err = screenDev->Construct(window->ScreenNumber()); |
|
91 if(err != KErrNone) |
|
92 { |
|
93 screenDev->~CWsScreenDevice(); |
|
94 return TSize(0,0); |
|
95 } |
|
96 |
|
97 TSize pixelSize = window->Size(); |
|
98 TInt twipWidth = screenDev->HorizontalPixelsToTwips(pixelSize.iWidth); |
|
99 TInt twipHeight = screenDev->VerticalPixelsToTwips(pixelSize.iHeight); |
|
100 TSize twipSize(twipWidth, twipHeight); |
|
101 |
|
102 screenDev->~CWsScreenDevice(); |
|
103 return twipSize; |
|
104 } |
|
105 else |
|
106 { |
|
107 return iEglWindow->SizeInTwips(); |
|
108 } |
|
109 } |
|
110 |
|
111 |
|
112 EXPORT_C TInt TEglWindowInterface::ScreenNumber() const |
|
113 { |
|
114 if(iEglWindow->IsRWindow()) |
|
115 { |
|
116 return reinterpret_cast<const RWindow*>(iEglWindow)->ScreenNumber(); |
|
117 } |
|
118 else |
|
119 { |
|
120 return iEglWindow->ScreenNumber(); |
|
121 } |
|
122 } |
|
123 |
|
124 |
|
125 EXPORT_C void TEglWindowInterface::SetBackgroundColor(TRgb aColor, TBool aTriggerRedraw) |
|
126 { |
|
127 if(iEglWindow->IsRWindow()) |
|
128 { |
|
129 RWindow* window = reinterpret_cast<RWindow*>(iEglWindow); |
|
130 window->SetBackgroundColor(aColor); |
|
131 if(aTriggerRedraw) |
|
132 { |
|
133 window->Invalidate(); |
|
134 } |
|
135 } |
|
136 else |
|
137 { |
|
138 iEglWindow->SetBackgroundColor(aColor, aTriggerRedraw); |
|
139 } |
|
140 } |
|
141 |
|
142 |
|
143 EXPORT_C TInt TEglWindowInterface::SetBackgroundSurface(const TSurfaceConfiguration &aConfiguration, TBool aTriggerRedraw) |
|
144 { |
|
145 if(iEglWindow->IsRWindow()) |
|
146 { |
|
147 #ifdef _DEBUG |
|
148 TSurfaceId surface; |
|
149 aConfiguration.GetSurfaceId(surface); |
|
150 EGL_WINDOW_ASSERT_DEBUG(!surface.IsNull(), EEglWindowPanicInvalidSurface); |
|
151 #endif |
|
152 return reinterpret_cast<RWindow*>(iEglWindow)->SetBackgroundSurface(aConfiguration, aTriggerRedraw); |
|
153 } |
|
154 else |
|
155 { |
|
156 return iEglWindow->SetBackgroundSurface(aConfiguration, aTriggerRedraw); |
|
157 } |
|
158 } |
|
159 |
|
160 |
|
161 EXPORT_C void TEglWindowInterface::RemoveBackgroundSurface(TBool aTriggerRedraw) |
|
162 { |
|
163 if(iEglWindow->IsRWindow()) |
|
164 { |
|
165 RWindow* window = reinterpret_cast<RWindow*>(iEglWindow); |
|
166 RWsSession* winSession = window->Session(); |
|
167 EGL_WINDOW_ASSERT_DEBUG(winSession, EEglWindowPanicRWindowHasNoSession); |
|
168 window->RemoveBackgroundSurface(aTriggerRedraw); |
|
169 } |
|
170 else |
|
171 { |
|
172 iEglWindow->RemoveBackgroundSurface(aTriggerRedraw); |
|
173 } |
|
174 } |