|
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: JNI class for DirectGraphicsImpl.java. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CMIDGraphics.h" |
|
20 #include "CMIDImage.h" |
|
21 |
|
22 #include "javax_microedition_lcdui_DirectGraphicsImpl.h" |
|
23 #include "CMIDToolkit.h" |
|
24 #include "CMIDBufferProcessor.h" |
|
25 #include "CMIDDirectGraphics.h" |
|
26 #include "TMIDBitmapParameters.h" |
|
27 #include "CMIDConvertFactory.h" |
|
28 |
|
29 // Cleanup method for ensuring that bitmaputil is ended |
|
30 LOCAL_C void EndBitmapUtil(TAny* aBitmapUtil) |
|
31 { |
|
32 ((TBitmapUtil*)aBitmapUtil)->End(); |
|
33 } |
|
34 |
|
35 // wrapper for calling draw or get bitmap methods |
|
36 void DirectGraphicsCallL(CMIDDirectGraphics* aDirectGraphics, |
|
37 void(CMIDDirectGraphics::*aFunc)(TMIDBitmapParameters* aParams), |
|
38 TMIDBitmapParameters* aParams, |
|
39 CMIDBufferProcessor* aBufferProcessor) |
|
40 { |
|
41 // locking bitmap, just to be sure that data address does not change |
|
42 TBitmapUtil bitmapUtil(aBufferProcessor->iGraphics->Bitmap()); |
|
43 CleanupStack::PushL(TCleanupItem(&EndBitmapUtil, |
|
44 &bitmapUtil)); |
|
45 bitmapUtil.Begin(TPoint(0, 0)); |
|
46 |
|
47 (aDirectGraphics->*aFunc)(aParams); |
|
48 |
|
49 CleanupStack::Pop(); // CSI: 12 TCleanupItem parameter cannot be used with Pop # |
|
50 bitmapUtil.End(); |
|
51 } |
|
52 /* |
|
53 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
54 * Method: _createBufferProcessor |
|
55 * Signature: (I)I |
|
56 */ |
|
57 JNIEXPORT jint JNICALL |
|
58 Java_javax_microedition_lcdui_DirectGraphicsImpl__1createBufferProcessor( |
|
59 JNIEnv*, jobject, jint aToolkit, jint aGraphics, jint aImage) |
|
60 { |
|
61 CMIDGraphics* graphics = MIDUnhand<CMIDGraphics>(aGraphics); |
|
62 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
63 MMIDImage* image = MIDUnhandObject< MMIDImage >(aImage); |
|
64 TInt handle = 0; |
|
65 TInt err = toolkit->ExecuteTrap(&CMIDBufferProcessor::NewL, toolkit, |
|
66 &handle, graphics, image); |
|
67 return err == KErrNone ? handle : err; |
|
68 } |
|
69 |
|
70 /* |
|
71 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
72 * Method: _drawBitmapInt |
|
73 * Signature: ([IZIIIIIIII)I |
|
74 */ |
|
75 JNIEXPORT jint JNICALL |
|
76 Java_javax_microedition_lcdui_DirectGraphicsImpl__1drawBitmapInt( |
|
77 JNIEnv* aJni, jobject, jintArray aPixels, jboolean aTransparency, |
|
78 jint aOffset, jint aScanlength, |
|
79 jint aX, jint aY, jint aWidth, jint aHeight, jint aManipulation, |
|
80 jint aFormat, jint aBufferProcessorHandle, jint aToolkit) |
|
81 { |
|
82 jint* pixels = aJni->GetIntArrayElements(aPixels, 0); |
|
83 jint size = aJni->GetArrayLength(aPixels); |
|
84 size *= sizeof(jint); // jint is 32bit and contains 4 bytes |
|
85 |
|
86 |
|
87 TMIDBitmapParameters params; |
|
88 params.iPixels = (TUint32*)pixels; |
|
89 params.iPixelsSize = size; |
|
90 params.iFormat = aFormat; |
|
91 params.iManipulation = aManipulation; |
|
92 params.iX = aX; |
|
93 params.iY = aY; |
|
94 params.iWidth = aWidth; |
|
95 params.iHeight = aHeight; |
|
96 params.iScanLength = aScanlength; |
|
97 params.iOffset = aOffset; |
|
98 params.iTransparency = aTransparency & (aFormat == KMIDTypeInt8888ARGB); |
|
99 |
|
100 CMIDBufferProcessor* bufferProcessor = |
|
101 MIDUnhand<CMIDBufferProcessor>(aBufferProcessorHandle); |
|
102 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
103 |
|
104 TInt retval = toolkit->ExecuteTrap(&DirectGraphicsCallL, |
|
105 bufferProcessor->iDirectGraphics, |
|
106 &CMIDDirectGraphics::DrawBitmapL, |
|
107 ¶ms, |
|
108 bufferProcessor); |
|
109 |
|
110 aJni->ReleaseIntArrayElements(aPixels, pixels, JNI_ABORT); |
|
111 return retval; |
|
112 } |
|
113 |
|
114 /* |
|
115 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
116 * Method: _drawBitmapByte |
|
117 * Signature: ([B[BIIIIIIII)I |
|
118 */ |
|
119 JNIEXPORT jint JNICALL |
|
120 Java_javax_microedition_lcdui_DirectGraphicsImpl__1drawBitmapByte |
|
121 (JNIEnv* aJni, jobject, jbyteArray aPixels, jbyteArray aTransparencyMask, |
|
122 jint aOffset, jint aScanlength, |
|
123 jint aX, jint aY, jint aWidth, jint aHeight, jint aManipulation, |
|
124 jint aFormat, jint aBufferProcessorHandle, jint aToolkit) |
|
125 { |
|
126 jbyte* pixels = aJni->GetByteArrayElements(aPixels, 0); |
|
127 |
|
128 jbyte* transparency = NULL; |
|
129 jint sizeTrans = 0; |
|
130 if (aTransparencyMask) |
|
131 { |
|
132 transparency = aJni->GetByteArrayElements(aTransparencyMask, 0); |
|
133 sizeTrans = aJni->GetArrayLength(aTransparencyMask); |
|
134 } |
|
135 jint size = aJni->GetArrayLength(aPixels); |
|
136 |
|
137 TMIDBitmapParameters params; |
|
138 params.iPixels = (TUint32*)pixels; |
|
139 params.iPixelsSize = size; |
|
140 params.iAlpha = (TUint32*)transparency; |
|
141 params.iAlphaSize = sizeTrans; |
|
142 params.iFormat = aFormat; |
|
143 params.iManipulation = aManipulation; |
|
144 params.iX = aX; |
|
145 params.iY = aY; |
|
146 params.iWidth = aWidth; |
|
147 params.iHeight = aHeight; |
|
148 params.iScanLength = aScanlength; |
|
149 params.iOffset = aOffset; |
|
150 params.iTransparency = params.iAlpha ? ETrue : EFalse; |
|
151 |
|
152 CMIDBufferProcessor* bufferProcessor = |
|
153 MIDUnhand<CMIDBufferProcessor>(aBufferProcessorHandle); |
|
154 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
155 |
|
156 |
|
157 TInt retval = toolkit->ExecuteTrap(&DirectGraphicsCallL, |
|
158 bufferProcessor->iDirectGraphics, |
|
159 &CMIDDirectGraphics::DrawBitmapL, |
|
160 ¶ms, |
|
161 bufferProcessor); |
|
162 |
|
163 aJni->ReleaseByteArrayElements(aPixels, pixels, JNI_ABORT); |
|
164 if (aTransparencyMask) |
|
165 { |
|
166 aJni->ReleaseByteArrayElements(aTransparencyMask, transparency, |
|
167 JNI_ABORT); |
|
168 } |
|
169 return retval; |
|
170 } |
|
171 |
|
172 /* |
|
173 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
174 * Method: _drawBitmapShort |
|
175 * Signature: ([SZIIIIIIII)I |
|
176 */ |
|
177 JNIEXPORT jint JNICALL |
|
178 Java_javax_microedition_lcdui_DirectGraphicsImpl__1drawBitmapShort |
|
179 (JNIEnv* aJni, jobject, jshortArray aPixels, jboolean aTransparency, |
|
180 jint aOffset, jint aScanlength, |
|
181 jint aX, jint aY, jint aWidth, jint aHeight, jint aManipulation, |
|
182 jint aFormat, jint aBufferProcessorHandle, jint aToolkit) |
|
183 { |
|
184 jshort* pixels = aJni->GetShortArrayElements(aPixels, 0); |
|
185 jint size = aJni->GetArrayLength(aPixels); |
|
186 size *= sizeof(jshort); // short is 16 bit and contains two bytes |
|
187 |
|
188 TMIDBitmapParameters params; |
|
189 params.iPixels = (TUint32*)pixels; |
|
190 params.iPixelsSize = size; |
|
191 params.iFormat = aFormat; |
|
192 params.iManipulation = aManipulation; |
|
193 params.iX = aX; |
|
194 params.iY = aY; |
|
195 params.iWidth = aWidth; |
|
196 params.iHeight = aHeight; |
|
197 params.iScanLength = aScanlength; |
|
198 params.iOffset = aOffset; |
|
199 params.iTransparency = aTransparency |
|
200 & (aFormat == KMIDTypeUshort4444ARGB); |
|
201 |
|
202 CMIDBufferProcessor* bufferProcessor = |
|
203 MIDUnhand<CMIDBufferProcessor>(aBufferProcessorHandle); |
|
204 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
205 |
|
206 TInt retval = toolkit->ExecuteTrap(&DirectGraphicsCallL, |
|
207 bufferProcessor->iDirectGraphics, |
|
208 &CMIDDirectGraphics::DrawBitmapL, |
|
209 ¶ms, |
|
210 bufferProcessor); |
|
211 |
|
212 aJni->ReleaseShortArrayElements(aPixels, pixels, JNI_ABORT); |
|
213 return retval; |
|
214 } |
|
215 |
|
216 // For getting native pixel format |
|
217 TInt DirectGraphicsGetNativePixelFormat(CMIDDirectGraphics* aDirectGraphics, |
|
218 TInt(CMIDDirectGraphics::*aFunc)()) |
|
219 { |
|
220 return (aDirectGraphics->*aFunc)(); |
|
221 } |
|
222 |
|
223 /* |
|
224 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
225 * Method: _getPixelsInt |
|
226 * Signature: ([IIIIIIII)I |
|
227 */ |
|
228 JNIEXPORT jint JNICALL |
|
229 Java_javax_microedition_lcdui_DirectGraphicsImpl__1getPixelsInt |
|
230 (JNIEnv* aJni, jobject, jintArray aPixels, jint aOffset, jint aScanlength, |
|
231 jint aX, jint aY, |
|
232 jint aWidth, jint aHeight, jint aFormat, jint aBufferProcessorHandle, |
|
233 jint aToolkit) |
|
234 { |
|
235 jint* pixels = aJni->GetIntArrayElements(aPixels, 0); |
|
236 jint size = aJni->GetArrayLength(aPixels); |
|
237 size *= sizeof(jint); // jint is 32bit and contains 4 bytes |
|
238 |
|
239 TMIDBitmapParameters params; |
|
240 params.iPixels = (TUint32*)pixels; |
|
241 params.iPixelsSize = size; |
|
242 params.iFormat = aFormat; |
|
243 params.iX = aX; |
|
244 params.iY = aY; |
|
245 params.iWidth = aWidth; |
|
246 params.iHeight = aHeight; |
|
247 params.iScanLength = aScanlength; |
|
248 params.iOffset = aOffset; |
|
249 |
|
250 CMIDBufferProcessor* bufferProcessor = |
|
251 MIDUnhand<CMIDBufferProcessor>(aBufferProcessorHandle); |
|
252 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
253 |
|
254 TInt retval = toolkit->ExecuteTrap(&DirectGraphicsCallL, |
|
255 bufferProcessor->iDirectGraphics, |
|
256 &CMIDDirectGraphics::GetBitmapL, |
|
257 ¶ms, |
|
258 bufferProcessor); |
|
259 |
|
260 aJni->ReleaseIntArrayElements(aPixels, pixels, NULL); |
|
261 return retval; |
|
262 } |
|
263 |
|
264 /* |
|
265 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
266 * Method: _getPixelsByte |
|
267 * Signature: ([BIIIIIII)I |
|
268 */ |
|
269 JNIEXPORT jint JNICALL |
|
270 Java_javax_microedition_lcdui_DirectGraphicsImpl__1getPixelsByte |
|
271 (JNIEnv* aJni, jobject, jbyteArray aPixels, jbyteArray aTransparencyMask, |
|
272 jint aOffset, jint aScanlength, jint aX, jint aY, |
|
273 jint aWidth, jint aHeight, jint aFormat, jint aBufferProcessorHandle, |
|
274 jint aToolkit) |
|
275 { |
|
276 |
|
277 jbyte* pixels = aJni->GetByteArrayElements(aPixels, NULL); |
|
278 jint size = aJni->GetArrayLength(aPixels); // byte is 8bit |
|
279 |
|
280 jbyte* transparency = NULL; |
|
281 jint sizeTrans = 0; |
|
282 |
|
283 if (aTransparencyMask) |
|
284 { |
|
285 transparency = aJni->GetByteArrayElements(aTransparencyMask, NULL); |
|
286 sizeTrans = aJni->GetArrayLength(aTransparencyMask); |
|
287 } |
|
288 |
|
289 TMIDBitmapParameters params; |
|
290 params.iPixels = (TUint32*)pixels; |
|
291 params.iPixelsSize = size; |
|
292 params.iAlpha = (TUint32*)transparency; |
|
293 params.iAlphaSize = sizeTrans; |
|
294 params.iFormat = aFormat; |
|
295 params.iX = aX; |
|
296 params.iY = aY; |
|
297 params.iWidth = aWidth; |
|
298 params.iHeight = aHeight; |
|
299 params.iScanLength = aScanlength; |
|
300 params.iOffset = aOffset; |
|
301 |
|
302 CMIDBufferProcessor* bufferProcessor = |
|
303 MIDUnhand<CMIDBufferProcessor>(aBufferProcessorHandle); |
|
304 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
305 |
|
306 TInt retval = toolkit->ExecuteTrap(&DirectGraphicsCallL, |
|
307 bufferProcessor->iDirectGraphics, |
|
308 &CMIDDirectGraphics::GetBitmapL, |
|
309 ¶ms, |
|
310 bufferProcessor); |
|
311 |
|
312 aJni->ReleaseByteArrayElements(aPixels, pixels, NULL); |
|
313 |
|
314 if (aTransparencyMask) |
|
315 { |
|
316 aJni->ReleaseByteArrayElements(aTransparencyMask, transparency, |
|
317 NULL); |
|
318 } |
|
319 |
|
320 return retval; |
|
321 } |
|
322 |
|
323 /* |
|
324 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
325 * Method: _getPixelsShort |
|
326 * Signature: ([SIIIIIII)I |
|
327 */ |
|
328 JNIEXPORT jint JNICALL |
|
329 Java_javax_microedition_lcdui_DirectGraphicsImpl__1getPixelsShort |
|
330 (JNIEnv* aJni, jobject, jshortArray aPixels, jint aOffset, jint aScanlength, |
|
331 jint aX, jint aY, |
|
332 jint aWidth, jint aHeight, jint aFormat, jint aBufferProcessorHandle, |
|
333 jint aToolkit) |
|
334 { |
|
335 jshort* pixels = aJni->GetShortArrayElements(aPixels, 0); |
|
336 jint size = aJni->GetArrayLength(aPixels); |
|
337 size *= sizeof(jshort); // size is number of 8bit elements in array |
|
338 |
|
339 TMIDBitmapParameters params; |
|
340 params.iPixels = (TUint32*)pixels; |
|
341 params.iPixelsSize = size; |
|
342 params.iFormat = aFormat; |
|
343 params.iX = aX; |
|
344 params.iY = aY; |
|
345 params.iWidth = aWidth; |
|
346 params.iHeight = aHeight; |
|
347 params.iScanLength = aScanlength; |
|
348 params.iOffset = aOffset; |
|
349 |
|
350 CMIDBufferProcessor* bufferProcessor = |
|
351 MIDUnhand<CMIDBufferProcessor>(aBufferProcessorHandle); |
|
352 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
353 |
|
354 TInt retval = toolkit->ExecuteTrap(&DirectGraphicsCallL, |
|
355 bufferProcessor->iDirectGraphics, |
|
356 &CMIDDirectGraphics::GetBitmapL, |
|
357 ¶ms, |
|
358 bufferProcessor); |
|
359 |
|
360 aJni->ReleaseShortArrayElements(aPixels, pixels, NULL); |
|
361 return retval; |
|
362 } |
|
363 |
|
364 |
|
365 // For color setting |
|
366 void DirectGraphicsSetColorL(CMIDDirectGraphics* aDirectGraphics, |
|
367 void(CMIDDirectGraphics::*aFunc)(TUint32 aColor, TInt aImageHandle), |
|
368 TUint32 aColor, TInt aImageHandle) |
|
369 { |
|
370 (aDirectGraphics->*aFunc)(aColor, aImageHandle); |
|
371 } |
|
372 /* |
|
373 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
374 * Method: _setColor |
|
375 * Signature: (II)I |
|
376 */ |
|
377 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_DirectGraphicsImpl__1setColor |
|
378 (JNIEnv *, jobject, jint aColor, jint aBufferProcessor, jint aToolkit, |
|
379 jint aImageHandle) |
|
380 { |
|
381 CMIDBufferProcessor* bufferProcessor = |
|
382 MIDUnhand<CMIDBufferProcessor>(aBufferProcessor); |
|
383 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
384 |
|
385 TInt retval = toolkit->ExecuteTrap(&DirectGraphicsSetColorL, |
|
386 bufferProcessor->iDirectGraphics, |
|
387 &CMIDDirectGraphics::SetColorL, |
|
388 (TUint32)aColor, |
|
389 (TInt) aImageHandle); |
|
390 |
|
391 return retval; |
|
392 } |
|
393 |
|
394 /* |
|
395 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
396 * Method: _getNativePixelFormat |
|
397 * Signature: (I)I |
|
398 */ |
|
399 JNIEXPORT |
|
400 jint JNICALL Java_javax_microedition_lcdui_DirectGraphicsImpl__1getNativePixelFormat |
|
401 (JNIEnv*, jobject, jint aBufferProcessorHandle, jint aToolkit) |
|
402 { |
|
403 CMIDBufferProcessor* bufferProcessor = |
|
404 MIDUnhand<CMIDBufferProcessor>(aBufferProcessorHandle); |
|
405 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
406 TInt retval = toolkit->Execute(&DirectGraphicsGetNativePixelFormat, |
|
407 bufferProcessor->iDirectGraphics, |
|
408 &CMIDDirectGraphics::GetNativePixelFormat); |
|
409 return retval; |
|
410 } |
|
411 |
|
412 |
|
413 // For getting native pixel format |
|
414 void DirectGraphicsDrawPolygonL(CMIDDirectGraphics* aDirectGraphics, |
|
415 void(CMIDDirectGraphics::*aFunc)(CMIDDirectGraphics::TPolygonParameters* aParams), |
|
416 CMIDDirectGraphics::TPolygonParameters* aParams , |
|
417 CMIDBufferProcessor* aBufferProcessor) |
|
418 { |
|
419 // locking bitmap, just to be sure that data address does not change |
|
420 TBitmapUtil bitmapUtil(aBufferProcessor->iGraphics->Bitmap()); |
|
421 CleanupStack::PushL(TCleanupItem(&EndBitmapUtil, |
|
422 &bitmapUtil)); |
|
423 bitmapUtil.Begin(TPoint(0, 0)); |
|
424 |
|
425 (aDirectGraphics->*aFunc)(aParams); |
|
426 |
|
427 CleanupStack::Pop(); // CSI: 12 TCleanupItem parameter cannot be used with Pop # |
|
428 bitmapUtil.End(); |
|
429 } |
|
430 |
|
431 /* |
|
432 * Class: javax_microedition_lcdui_DirectGraphicsImpl |
|
433 * Method: _drawPolygon |
|
434 * Signature: ([II[IIIIIZ)I |
|
435 */ |
|
436 JNIEXPORT jint JNICALL |
|
437 Java_javax_microedition_lcdui_DirectGraphicsImpl__1drawPolygon( |
|
438 JNIEnv* aJni, jobject, jintArray aXPoints, jint aXOffset, jint aTransX, |
|
439 jintArray aYPoints, jint aYOffset, jint aTransY, |
|
440 jint aNPoints, jint aARGBColor, jint aBufferProcessorHandle, |
|
441 jboolean aFill, jint aToolkit) |
|
442 { |
|
443 jint* xPoints = aJni->GetIntArrayElements(aXPoints, 0); |
|
444 jint xSize = aJni->GetArrayLength(aXPoints); |
|
445 |
|
446 jint* yPoints = aJni->GetIntArrayElements(aYPoints, 0); |
|
447 jint ySize = aJni->GetArrayLength(aYPoints); |
|
448 |
|
449 CMIDBufferProcessor* bufferProcessor = |
|
450 MIDUnhand<CMIDBufferProcessor>(aBufferProcessorHandle); |
|
451 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
452 |
|
453 CMIDDirectGraphics::TPolygonParameters polygonParameters = |
|
454 { |
|
455 xPoints, xSize, aXOffset, aTransX, yPoints, ySize, aYOffset, aTransY, |
|
456 aNPoints, aARGBColor, aFill |
|
457 }; |
|
458 |
|
459 TInt retval = toolkit->ExecuteTrap(&DirectGraphicsDrawPolygonL, |
|
460 bufferProcessor->iDirectGraphics, |
|
461 &CMIDDirectGraphics::DrawPolygonL, |
|
462 &polygonParameters, |
|
463 bufferProcessor); |
|
464 aJni->ReleaseIntArrayElements(aXPoints, xPoints, JNI_ABORT); |
|
465 aJni->ReleaseIntArrayElements(aYPoints, yPoints, JNI_ABORT); |
|
466 return retval; |
|
467 } |