|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32def.h> // MAKE_TINT64 |
|
19 #include "javax_microedition_lcdui_Graphics.h" |
|
20 #include "CMIDToolkit.h" |
|
21 #include "CMIDBuffer.h" |
|
22 #include "MIDUtils.h" |
|
23 #include <stdio.h> |
|
24 |
|
25 |
|
26 LOCAL_C void CreateL(CMIDToolkit* aToolkit,TInt* aHandle, MMIDComponent* aComponent) |
|
27 { |
|
28 MMIDGraphicsFactory& factory = aToolkit->GraphicsFactory(); |
|
29 |
|
30 MMIDGraphics* graphics = NULL; |
|
31 switch (aComponent->Type()) |
|
32 { |
|
33 case MMIDComponent::EImage: |
|
34 { |
|
35 graphics = factory.NewGraphicsL((MMIDImage*)aComponent); |
|
36 } |
|
37 break; |
|
38 |
|
39 case MMIDComponent::ECustomItem: |
|
40 { |
|
41 graphics = factory.NewGraphicsL((MMIDCustomItem*)aComponent); |
|
42 } |
|
43 break; |
|
44 |
|
45 case MMIDComponent::ECanvas: |
|
46 { |
|
47 graphics = factory.NewGraphicsL((MMIDCanvas*)aComponent); |
|
48 } |
|
49 break; |
|
50 |
|
51 case MMIDComponent::ECanvasGraphicsItemPainter: |
|
52 { |
|
53 graphics = factory.NewGraphicsL((MMIDCanvasGraphicsItemPainter*)aComponent); |
|
54 } |
|
55 break; |
|
56 |
|
57 default: |
|
58 break; |
|
59 } |
|
60 ASSERT(graphics); |
|
61 |
|
62 CleanupDisposePushL(graphics); |
|
63 *aHandle = aToolkit->RegisterComponentL(graphics, NULL); |
|
64 CleanupPopComponent(graphics); |
|
65 } |
|
66 |
|
67 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Graphics__1create |
|
68 (JNIEnv*, jobject, jint aToolkit, jint aDrawable) |
|
69 { |
|
70 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
71 TInt handle=0; |
|
72 MMIDComponent* drawable = MIDUnhandObject<MMIDComponent>(aDrawable); |
|
73 TInt err = toolkit->ExecuteTrap(&CreateL, toolkit, &handle, drawable); |
|
74 return err == KErrNone ? handle : err; |
|
75 } |
|
76 |
|
77 |
|
78 LOCAL_C TInt InvokeDisplayColor(MMIDGraphics* aGraphics, TUint32 aColor) |
|
79 { |
|
80 TUint32 color = aGraphics->DisplayColor(aColor); |
|
81 return TInt(color); |
|
82 } |
|
83 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Graphics__1getDisplayColor |
|
84 ( |
|
85 JNIEnv* /* aEnv */, |
|
86 jclass /* aCls */, |
|
87 jint aToolkit, |
|
88 jint aGraphics, |
|
89 jint aColor |
|
90 ) |
|
91 { |
|
92 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
93 MMIDGraphics* graphics = MIDUnhand<MMIDGraphics>(aGraphics); |
|
94 #ifdef _TRACE |
|
95 TInt red = (aColor >> 16) & 0xff; |
|
96 TInt green = (aColor >> 8) & 0xff; |
|
97 TInt blue = (aColor) & 0xff; |
|
98 RDebug::Print(_L("getDisplayColor(%d,%d,%d)"), red, green, blue); |
|
99 #endif |
|
100 return toolkit->Execute(InvokeDisplayColor, graphics, (TUint32)aColor); |
|
101 } |
|
102 |
|
103 struct TDrawPixels |
|
104 { |
|
105 TInt iType; |
|
106 TUint8* iAddress; // pixel array |
|
107 TInt iLength; // in bytes |
|
108 TInt iScanLength; // in bytes |
|
109 TBool iAlpha; |
|
110 TRect iRect; |
|
111 TInt iTransform; |
|
112 }; |
|
113 |
|
114 LOCAL_C TInt InvokeDrawPixels(MMIDGraphics* aGraphics, const TDrawPixels* aDrawPixels) |
|
115 { |
|
116 return aGraphics->DrawPixels( |
|
117 aDrawPixels->iType, |
|
118 aDrawPixels->iAddress, |
|
119 aDrawPixels->iLength, |
|
120 aDrawPixels->iScanLength, |
|
121 aDrawPixels->iAlpha, |
|
122 aDrawPixels->iRect, |
|
123 aDrawPixels->iTransform |
|
124 ); |
|
125 } |
|
126 |
|
127 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Graphics__1drawPixels |
|
128 ( |
|
129 JNIEnv* aEnv, |
|
130 jclass /* aClass */, |
|
131 jint aBuffer, |
|
132 jint aHandle, |
|
133 jint aType, |
|
134 jintArray aRgbData, |
|
135 jint aOffset, |
|
136 jint aLength, |
|
137 jint aScanLength, |
|
138 jboolean aProcessAlpha, |
|
139 jint aX, |
|
140 jint aY, |
|
141 jint aWidth, |
|
142 jint aHeight, |
|
143 jint aTransform |
|
144 ) |
|
145 { |
|
146 CMIDBuffer* buffer = JavaUnhand<CMIDBuffer>(aBuffer); |
|
147 MMIDGraphics* graphics = MIDUnhand<MMIDGraphics>(aHandle); |
|
148 |
|
149 TInt err = KErrNoMemory; |
|
150 TInt length = aEnv->GetArrayLength(aRgbData); |
|
151 jint* array = aEnv->GetIntArrayElements(aRgbData, NULL); |
|
152 if (array) |
|
153 { |
|
154 TDrawPixels drawPixels; |
|
155 |
|
156 drawPixels.iType = aType; |
|
157 drawPixels.iAddress = (TUint8*)(array + aOffset); |
|
158 drawPixels.iLength = aLength*sizeof(jint); |
|
159 drawPixels.iScanLength = aScanLength*sizeof(jint); |
|
160 drawPixels.iAlpha = aProcessAlpha; |
|
161 drawPixels.iRect.iTl.iX=aX; |
|
162 drawPixels.iRect.iTl.iY=aY; |
|
163 drawPixels.iRect.iBr.iX=aX+aWidth; |
|
164 drawPixels.iRect.iBr.iY=aY+aHeight; |
|
165 drawPixels.iTransform = aTransform; |
|
166 |
|
167 err = buffer->Execute(&InvokeDrawPixels, graphics, &const_cast<const TDrawPixels&>(drawPixels)); |
|
168 |
|
169 aEnv->ReleaseIntArrayElements(aRgbData, array, JNI_ABORT); // don't copy back |
|
170 } |
|
171 |
|
172 return err; |
|
173 } |