80
|
1 |
/*
|
87
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
80
|
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: Render context implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
#include <eikenv.h> // CCoeEnv
|
|
20 |
#include <graphics.h>
|
|
21 |
|
|
22 |
#include "CM2GRenderContext.h"
|
|
23 |
#include "MM2GSVGProxy.h"
|
|
24 |
#include "svgtbitmap.h"
|
|
25 |
#include <ImageConversion.h>
|
|
26 |
#include <f32file.h>
|
|
27 |
|
|
28 |
M2G_NS_START
|
|
29 |
|
|
30 |
// EXTERNAL DATA STRUCTURES
|
|
31 |
|
|
32 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
33 |
|
|
34 |
// CONSTANTS
|
|
35 |
/* static */ const TReal32 MM2GRenderContext::KFullOpaque = 1.0;
|
|
36 |
/* static */
|
|
37 |
const TReal32 MM2GRenderContext::KFullTransparency = 0.0;
|
|
38 |
/* static */
|
|
39 |
const TUint8 MM2GRenderContext::KMaxAlphaValue = 255;
|
|
40 |
/* static */
|
|
41 |
const TDisplayMode MM2GRenderContext::KDefaultDisplayMode = EColor16MA;
|
|
42 |
/* static */
|
|
43 |
const TDisplayMode MM2GRenderContext::KMaskDisplayMode = EGray256;
|
|
44 |
|
|
45 |
// MACROS
|
|
46 |
|
|
47 |
// LOCAL CONSTANTS AND MACROS
|
|
48 |
|
|
49 |
// MODULE DATA STRUCTURES
|
|
50 |
|
|
51 |
// LOCAL FUNCTION PROTOTYPES
|
|
52 |
|
|
53 |
// FORWARD DECLARATIONS
|
|
54 |
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
// CM2GRenderContext::CM2GRenderContext
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
CM2GRenderContext::CM2GRenderContext()
|
|
59 |
: CBase(),
|
|
60 |
iProxy(NULL),
|
|
61 |
iEngineHandle(M2G_INVALID_HANDLE),
|
|
62 |
iAlpha(MM2GRenderContext::KFullOpaque),
|
|
63 |
iScaledAlpha(MM2GRenderContext::KMaxAlphaValue),
|
|
64 |
iImgBmp(NULL),
|
|
65 |
iWindowSurface(NULL)
|
|
66 |
{
|
|
67 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::CM2GRenderContext");
|
|
68 |
}
|
|
69 |
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
// CM2GRenderContext::NewL
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
CM2GRenderContext* CM2GRenderContext::NewL(MM2GSVGProxy* aProxy)
|
|
74 |
{
|
|
75 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::NewL()");
|
|
76 |
|
|
77 |
CM2GRenderContext* self = new(ELeave) CM2GRenderContext;
|
|
78 |
CleanupStack::PushL(self);
|
|
79 |
|
|
80 |
self->ConstructL(aProxy);
|
|
81 |
|
|
82 |
CleanupStack::Pop();
|
|
83 |
|
|
84 |
return self;
|
|
85 |
}
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
// CM2GRenderContext::~CM2GRenderContext
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
CM2GRenderContext::~CM2GRenderContext()
|
|
90 |
{
|
|
91 |
M2G_DEBUG_2("M2G_DEBUG: CM2GRenderContext::~CM2GRenderContext() - proxy=%d, engine=%d", iProxy, iEngineHandle);
|
|
92 |
if ((iEngineHandle != M2G_INVALID_HANDLE) && (iProxy != NULL))
|
|
93 |
{
|
|
94 |
TRAP_IGNORE(iProxy->DeleteSvgEngineL(iEngineHandle));
|
|
95 |
}
|
87
|
96 |
if (iWindowSurface)
|
|
97 |
{
|
|
98 |
delete iWindowSurface;
|
|
99 |
}
|
|
100 |
if (targetBitmap)
|
|
101 |
{
|
80
|
102 |
delete targetBitmap;
|
87
|
103 |
}
|
|
104 |
if (iTargetQImage)
|
|
105 |
{
|
80
|
106 |
delete iTargetQImage;
|
87
|
107 |
}
|
|
108 |
if (tempBitmapForMask)
|
|
109 |
{
|
80
|
110 |
delete tempBitmapForMask;
|
87
|
111 |
}
|
80
|
112 |
delete iImgBmp;
|
|
113 |
iFbsSession.Disconnect();
|
|
114 |
}
|
|
115 |
|
|
116 |
// -----------------------------------------------------------------------------
|
|
117 |
// CM2GRenderContext::BindL
|
|
118 |
// -----------------------------------------------------------------------------
|
|
119 |
void CM2GRenderContext::BindL(TInt& aTargetHandle)
|
87
|
120 |
{
|
80
|
121 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::BindL()");
|
|
122 |
// get the screen size
|
87
|
123 |
TSize screenSize = CEikonEnv::Static()->ScreenDevice()->SizeInPixels();
|
|
124 |
|
80
|
125 |
iWindowSurface = (reinterpret_cast<Java::GFX::WindowSurface*>(aTargetHandle));
|
87
|
126 |
|
|
127 |
iWindowSurface->bind(Java::GFX::WsTypeQtImage);
|
|
128 |
|
|
129 |
wSurfaceType = (Java::GFX::WindowSurfaceType)iWindowSurface->getType();
|
80
|
130 |
|
87
|
131 |
switch (wSurfaceType)
|
|
132 |
{
|
|
133 |
case Java::GFX::WsTypeQtImage:
|
|
134 |
User::LeaveIfNull(iOffScreenQImage = iWindowSurface->getQtImage());
|
|
135 |
targetBitmap = new CSvgtBitmap((TInt8*)iOffScreenQImage->bits(),
|
|
136 |
TSize(iOffScreenQImage->size().width(),iOffScreenQImage->size().height()),
|
|
137 |
EColor16MA,iOffScreenQImage->bytesPerLine());
|
|
138 |
break;
|
|
139 |
|
|
140 |
case Java::GFX::WsTypeSymbianBitmap:
|
|
141 |
break;
|
|
142 |
|
|
143 |
default:
|
|
144 |
User::Leave(KErrNotSupported);
|
|
145 |
break;
|
80
|
146 |
}
|
|
147 |
|
87
|
148 |
}
|
|
149 |
|
80
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
// -----------------------------------------------------------------------------
|
|
152 |
// CM2GRenderContext::InitImageBitmapL
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
void CM2GRenderContext::InitImageBitmapL()
|
87
|
155 |
{
|
80
|
156 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::InitImageBitmapL() - begin");
|
|
157 |
// get the screen size
|
|
158 |
TSize screenSize = CEikonEnv::Static()->ScreenDevice()->SizeInPixels();
|
|
159 |
switch (wSurfaceType)
|
87
|
160 |
{
|
|
161 |
case Java::GFX::WsTypeQtImage:
|
|
162 |
{
|
|
163 |
break;
|
|
164 |
}
|
|
165 |
case Java::GFX::WsTypeSymbianBitmap:
|
|
166 |
{
|
|
167 |
break;
|
|
168 |
}
|
|
169 |
|
|
170 |
default:
|
|
171 |
break;
|
|
172 |
}
|
80
|
173 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::InitImageBitmapL() - end");
|
87
|
174 |
}
|
80
|
175 |
// CM2GRenderContext::ReleaseL
|
|
176 |
// -----------------------------------------------------------------------------
|
|
177 |
void CM2GRenderContext::ReleaseL()
|
87
|
178 |
{
|
80
|
179 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::ReleaseL() - begin");
|
87
|
180 |
|
80
|
181 |
iTargetQImage = NULL;
|
|
182 |
iOffScreenQImage = NULL;
|
|
183 |
iWindowSurface->release();
|
|
184 |
|
|
185 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::ReleaseL() - end");
|
87
|
186 |
}
|
80
|
187 |
|
|
188 |
// -----------------------------------------------------------------------------
|
|
189 |
// CM2GRenderContext::RenderL
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
void CM2GRenderContext::RenderLCDUIL(
|
|
192 |
TM2GSvgDocumentHandle& aSvgDocHandle,
|
|
193 |
const TReal32 aCurrentTime,
|
|
194 |
TInt aSvgW, TInt aSvgH,
|
|
195 |
TM2GRenderRect& aRect
|
|
196 |
)
|
|
197 |
{
|
|
198 |
// prepare viewbox
|
|
199 |
TRect viewbox;
|
|
200 |
TPoint anchor;
|
|
201 |
|
|
202 |
PrepareViewbox(aRect, aSvgW, aSvgH, viewbox, anchor);
|
|
203 |
RenderLCDUIL(aSvgDocHandle, aCurrentTime, viewbox, anchor);
|
|
204 |
}
|
|
205 |
|
|
206 |
// -----------------------------------------------------------------------------
|
|
207 |
void CM2GRenderContext::RenderESWTL(
|
|
208 |
TM2GSvgDocumentHandle& aSvgDocHandle,
|
|
209 |
const TReal32 aCurrentTime,
|
|
210 |
TInt aSvgW, TInt aSvgH,
|
|
211 |
TM2GRenderRect& aRect,
|
|
212 |
TBool aUseNativeClear,
|
|
213 |
TInt* aReturnData)
|
|
214 |
{
|
|
215 |
// prepare viewbox
|
|
216 |
TRect viewbox;
|
|
217 |
TPoint anchor;
|
|
218 |
|
|
219 |
PrepareViewbox(aRect, aSvgW, aSvgH, viewbox, anchor);
|
|
220 |
|
|
221 |
aReturnData[0] = 0;
|
|
222 |
aReturnData[1] = 0;
|
|
223 |
aReturnData[2] = 0;
|
|
224 |
aReturnData[3] = 0;
|
|
225 |
aReturnData[4] = anchor.iX;
|
|
226 |
aReturnData[5] = anchor.iY;
|
|
227 |
aReturnData[6] = viewbox.iTl.iX;
|
|
228 |
aReturnData[7] = viewbox.iTl.iY;
|
|
229 |
aReturnData[8] = viewbox.Width();
|
|
230 |
aReturnData[9] = viewbox.Height();
|
|
231 |
|
|
232 |
RenderESWTL(aSvgDocHandle, aCurrentTime, viewbox, anchor, aUseNativeClear, aReturnData);
|
|
233 |
|
|
234 |
return;
|
|
235 |
}
|
|
236 |
// CM2GRenderContext::SetRenderingQualityL
|
|
237 |
// -----------------------------------------------------------------------------
|
|
238 |
void CM2GRenderContext::SetRenderingQualityL(TInt aMode)
|
|
239 |
{
|
|
240 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::SetRenderingQualityL()");
|
|
241 |
User::LeaveIfNull(iProxy);
|
|
242 |
iProxy->RenderQualityL(iEngineHandle, aMode);
|
|
243 |
}
|
|
244 |
|
|
245 |
// -----------------------------------------------------------------------------
|
|
246 |
// CM2GRenderContext::SetTransparencyL
|
|
247 |
// -----------------------------------------------------------------------------
|
|
248 |
void CM2GRenderContext::SetTransparency(TReal32 aAlpha)
|
|
249 |
{
|
|
250 |
iAlpha = aAlpha;
|
|
251 |
iScaledAlpha = STATIC_CAST(TUint8, (aAlpha * MM2GRenderContext::KMaxAlphaValue));
|
|
252 |
}
|
|
253 |
|
|
254 |
// -----------------------------------------------------------------------------
|
|
255 |
// CM2GRenderContext::ConstructL
|
|
256 |
// -----------------------------------------------------------------------------
|
|
257 |
void CM2GRenderContext::ConstructL(MM2GSVGProxy* aProxy)
|
87
|
258 |
{
|
80
|
259 |
// Init member variables
|
|
260 |
SetTransparency(MM2GRenderContext::KFullOpaque);
|
|
261 |
|
|
262 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::ConstructL() - begin");
|
|
263 |
|
|
264 |
if (aProxy)
|
|
265 |
{
|
|
266 |
iProxy = aProxy;
|
|
267 |
iProxy->CreateSvgEngineL(iEngineHandle);
|
|
268 |
M2G_DEBUG_2("M2G_DEBUG: CM2GRenderContext::ConstructL() - proxy: %d, new engine: %d", iProxy, iEngineHandle);
|
|
269 |
}
|
|
270 |
else
|
|
271 |
{
|
|
272 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::ConstructL() - proxy is invalid");
|
|
273 |
M2G_THROW(KM2GArgNotOk);
|
|
274 |
}
|
|
275 |
|
|
276 |
User::LeaveIfError(iFbsSession.Connect());
|
|
277 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::ConstructL() - end");
|
87
|
278 |
}
|
80
|
279 |
// -----------------------------------------------------------------------------
|
|
280 |
// CM2GRenderContext::PrepareViewbox
|
|
281 |
// -----------------------------------------------------------------------------
|
|
282 |
void CM2GRenderContext::PrepareViewbox(
|
|
283 |
TM2GRenderRect& aRr,
|
|
284 |
TInt aSvgW, TInt aSvgH,
|
|
285 |
TRect& aViewbox, TPoint& aAnchor)
|
|
286 |
{
|
|
287 |
M2G_DEBUG_6("M2G_DEBUG: CM2GRenderContext::PrepareViewbox() cX=%d, cY=%d, cW=%d, cH=%d, anchorX=%d, anchorY=%d - begin", aRr.GetClipX(), aRr.GetClipY(), aRr.GetClipW(), aRr.GetClipH(), aRr.GetAnchorX(), aRr.GetAnchorY());
|
|
288 |
|
|
289 |
// Create an anchor point and an svg render area rect
|
|
290 |
aAnchor.SetXY(aRr.GetAnchorX(), aRr.GetAnchorY());
|
|
291 |
aViewbox.SetRect(aAnchor, TSize(aSvgW, aSvgH));
|
|
292 |
|
|
293 |
// NOTE: It's already verified in Java side that the SVG render area and
|
|
294 |
// the clip area intersects each other
|
|
295 |
aViewbox.Intersection(aRr);
|
|
296 |
|
|
297 |
// Check if the clip rect has changes the svg rect
|
|
298 |
if (aViewbox.iTl != aAnchor)
|
|
299 |
{
|
|
300 |
// Update anchor position
|
|
301 |
TPoint oldAnchor(aAnchor);
|
|
302 |
aAnchor = aViewbox.iTl;
|
|
303 |
|
|
304 |
// Update svg rect
|
|
305 |
aViewbox.Move((-oldAnchor.iX), (-oldAnchor.iY));
|
|
306 |
}
|
|
307 |
else
|
|
308 |
{
|
|
309 |
// The clip rect has not changed the svg rect. Only the
|
|
310 |
// anchor position need to be updated
|
|
311 |
aViewbox.Move(-aAnchor.iX, -aAnchor.iY);
|
|
312 |
}
|
|
313 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::PrepareViewbox() - end");
|
|
314 |
}
|
|
315 |
|
|
316 |
void CM2GRenderContext::RenderLCDUIL(
|
87
|
317 |
TM2GSvgDocumentHandle& aSvgDocHandle,
|
|
318 |
TReal32 aCurrentTime,
|
|
319 |
const TRect& /*aViewbox*/,
|
|
320 |
const TPoint& /*aAnchor*/)
|
|
321 |
{
|
80
|
322 |
M2G_DEBUG_4("M2G_DEBUG: CM2GRenderContext::RenderL() viewbox: x=%d, y=%d, w=%d, h=%d begin", aViewbox.iTl.iX, aViewbox.iTl.iY, aViewbox.Size().iWidth, aViewbox.Size().iHeight);
|
|
323 |
|
|
324 |
// No need to render if content is fully transparency (i.e. alpha=0)
|
|
325 |
if (iScaledAlpha == 0)
|
|
326 |
{
|
|
327 |
return;
|
|
328 |
}
|
|
329 |
|
|
330 |
// 1: render the svg document on the iImgBmp
|
|
331 |
iProxy->RenderDocumentL(
|
|
332 |
iEngineHandle,
|
|
333 |
aSvgDocHandle,
|
87
|
334 |
(TM2GSvgBitmapHandle)targetBitmap
|
80
|
335 |
, (TUint)NULL, aCurrentTime);
|
87
|
336 |
|
|
337 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::RenderL() end");
|
|
338 |
}
|
80
|
339 |
|
|
340 |
// -----------------------------------------------------------------------------
|
87
|
341 |
/*
|
|
342 |
* Write the separate RenderDocumentL method for QImage and CFbsBitmap
|
80
|
343 |
* also handle subsequent BitBlt and
|
|
344 |
* CreateAlphaBlendMaskL
|
|
345 |
* */
|
|
346 |
void CM2GRenderContext::RenderESWTL(
|
|
347 |
TM2GSvgDocumentHandle& aSvgDocHandle,
|
|
348 |
TReal32 aCurrentTime,
|
87
|
349 |
const TRect& /*aViewbox*/,
|
|
350 |
const TPoint& /*aAnchor*/,
|
80
|
351 |
TBool /*aUseNativeClear*/,
|
87
|
352 |
TInt* /*aReturnData*/)
|
80
|
353 |
{
|
|
354 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::RenderESWTL() Start");
|
|
355 |
// No need to render if content is fully transparency (i.e. alpha=0)
|
|
356 |
if (iScaledAlpha == 0)
|
|
357 |
{
|
|
358 |
return;
|
|
359 |
}
|
87
|
360 |
|
80
|
361 |
// 1: render the svg document on the iImgBmp
|
87
|
362 |
iProxy->RenderDocumentL(iEngineHandle,
|
|
363 |
aSvgDocHandle,
|
|
364 |
(TM2GSvgBitmapHandle)targetBitmap, (TUint)NULL, aCurrentTime);
|
|
365 |
M2G_DEBUG_0("M2G_DEBUG: CM2GRenderContext::RenderESWTL() end");
|
80
|
366 |
|
|
367 |
}
|
|
368 |
|
|
369 |
M2G_NS_END
|