javauis/m2g_qt/src/jni/M2GScalableGraphics.cpp
changeset 57 59b3b4473dc8
parent 56 abc41079b313
child 64 0ea12c182930
equal deleted inserted replaced
56:abc41079b313 57:59b3b4473dc8
     1 /*
       
     2 * Copyright (c) 2005-2006 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 methods
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CM2GEventSource.h"
       
    20 #include "com_nokia_microedition_m2g_M2GScalableGraphics.h"
       
    21 #include "CM2GRenderContext.h"
       
    22 #include "MM2GSVGProxy.h" // TM2GRenderRect
       
    23 #include <graphics.h>
       
    24 
       
    25 M2G_NS_START
       
    26 
       
    27 #include "M2GUtils.h"
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 // MACROS
       
    35 
       
    36 // LOCAL CONSTANTS AND MACROS
       
    37 
       
    38 // MODULE DATA STRUCTURES
       
    39 
       
    40 // LOCAL FUNCTION PROTOTYPES
       
    41 
       
    42 // FORWARD DECLARATIONS
       
    43 
       
    44 // CLASS DECLARATION
       
    45 
       
    46 // ================================ FUNCTIONS ==================================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // Java_com_nokia_microedition_m2g_M2GScalableGraphics::_bind
       
    50 // -----------------------------------------------------------------------------
       
    51 /**
       
    52  * Calls MM2GRenderContext::BindL method.
       
    53  * @since Series S60 3.0
       
    54  * @param aRenderContextHandle Render context handle.
       
    55  * @param aTargetHandle Target graphics handle
       
    56  * @throws exception if not ok
       
    57  
       
    58 LOCAL_C void DoBindL(TInt aRenderContextHandle, TInt aTargetHandle, TBool aUiToolkit)
       
    59 {
       
    60     MM2GRenderContext* rc = JavaUnhand<MM2GRenderContext>(aRenderContextHandle);
       
    61     rc->BindL(aTargetHandle, aUiToolkit);
       
    62 }
       
    63 */
       
    64 /**
       
    65  * JNI method
       
    66  
       
    67 JNIEXPORT jint JNICALL
       
    68 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1bind(
       
    69     JNIEnv* aJni,
       
    70     jobject,
       
    71     jint aEventSourceHandle,
       
    72     jint aRenderContextHandle,
       
    73     jint aTargetHandle,
       
    74     jboolean aUiToolkit)
       
    75  */
       
    76 
       
    77 
       
    78 
       
    79 JNIEXPORT jint JNICALL
       
    80 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1bind(
       
    81     JNIEnv* aJni,
       
    82     jobject,
       
    83     jint aRenderContextHandle,
       
    84     jint aTargetHandle )
       
    85 {
       
    86     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _bind - begin");
       
    87     
       
    88     TInt err = KM2GNotOk;
       
    89     
       
    90     M2G_DO_LOCK
       
    91     
       
    92     if (aRenderContextHandle)
       
    93         {
       
    94         MM2GRenderContext* rc = JavaUnhand<MM2GRenderContext>(aRenderContextHandle);
       
    95         TRAP(err,rc->BindL(aTargetHandle););
       
    96         }
       
    97 
       
    98     M2G_DO_UNLOCK(aJni)
       
    99     
       
   100     M2GGeneral::CheckErrorCode(aJni, err);
       
   101     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GScalableGraphics ) _bind: %d - end", err);
       
   102 
       
   103     return err; 
       
   104 }
       
   105 
       
   106 
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // Java_com_nokia_microedition_m2g_M2GScalableGraphics::_createRenderContext
       
   110 // -----------------------------------------------------------------------------
       
   111 /**
       
   112  * Calls MM2GRenderContext::NewL method.
       
   113  * @since Series S60 3.0
       
   114  * @param aSvgProxyHandle Proxy instance.
       
   115  * @param aHandle Render context handle.
       
   116  * @throws exception if not ok
       
   117  */
       
   118 
       
   119 
       
   120 
       
   121 JNIEXPORT jint JNICALL
       
   122 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1createRenderContext(
       
   123     JNIEnv* aJni,
       
   124     jobject,
       
   125     jint aSvgProxyHandle   )
       
   126 {
       
   127     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _createRenderContext - begin");
       
   128     TInt handle = M2G_INVALID_HANDLE;
       
   129     TInt  err = KM2GNotOk;
       
   130     
       
   131     M2G_DO_LOCK
       
   132   
       
   133     if (aSvgProxyHandle)
       
   134         {
       
   135          TRAP(err, MM2GRenderContext* rchandle = CM2GRenderContext::NewL(JavaUnhand<MM2GSVGProxy> (aSvgProxyHandle));  handle = JavaMakeHandle(rchandle); );
       
   136         }
       
   137     M2G_DO_UNLOCK(aJni)
       
   138     
       
   139     handle = M2GGeneral::CheckErrorCodeAndHandle(aJni, err, handle, err);
       
   140 
       
   141     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GScalableGraphics ) _createRenderContext: %d - end", handle);
       
   142     
       
   143 
       
   144     
       
   145     return handle;
       
   146 }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // Java_com_nokia_microedition_m2g_M2GScalableGraphics::_deleteRenderContext
       
   150 // -----------------------------------------------------------------------------
       
   151 /**
       
   152  * Class: com_nokia_microedition_m2g_M2GScalableGraphics
       
   153  * Method: deleteRenderContext
       
   154  * Signature:
       
   155  */
       
   156 JNIEXPORT void JNICALL
       
   157 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1deleteRenderContext(
       
   158     JNIEnv* aJni,
       
   159     jobject,
       
   160     jint aRenderContextHandle)
       
   161 {
       
   162     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _deleteRenderContext - begin");
       
   163     
       
   164     M2G_DO_LOCK
       
   165     
       
   166     if (aRenderContextHandle)
       
   167         {
       
   168         MM2GRenderContext* rc = JavaUnhand<MM2GRenderContext>(aRenderContextHandle);
       
   169         delete rc;
       
   170         }
       
   171     M2G_DO_UNLOCK(aJni)
       
   172     
       
   173     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _deleteRenderContext - end");
       
   174 }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // Java_com_nokia_microedition_m2g_M2GScalableGraphics::_release
       
   178 // -----------------------------------------------------------------------------
       
   179 /**
       
   180  * Calls MM2GRenderContext::ReleaseL method.
       
   181  * @since Series S60 3.0
       
   182  * @param aRenderContextHandle Context handle
       
   183  * @return KM2GOk if ok
       
   184  */
       
   185 
       
   186 
       
   187 /**
       
   188  * JNI method
       
   189  */
       
   190 JNIEXPORT jint JNICALL
       
   191 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1release(
       
   192     JNIEnv* aJni,
       
   193     jobject,
       
   194     jint aSurfaceHandle,
       
   195     jint aRenderContextHandle)
       
   196 {
       
   197     
       
   198     // Release used target surface
       
   199     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _release - begin");
       
   200     TInt err = KM2GNotOk;
       
   201     M2G_DO_LOCK
       
   202    
       
   203     if (aRenderContextHandle)
       
   204         {
       
   205         MM2GRenderContext* rc = JavaUnhand<MM2GRenderContext>(aRenderContextHandle);
       
   206         TRAP(err,rc->ReleaseL(););
       
   207     
       
   208         }
       
   209     M2G_DO_UNLOCK(aJni)//TODO Check for M2G_DO_LOCK M2G_DO_UNLOCK
       
   210     
       
   211     Java::GFX::WindowSurface* surf = reinterpret_cast<Java::GFX::WindowSurface*>(aSurfaceHandle);
       
   212     surf->release();  //TODO check This windows surface call detected from Graphics3d.inl 
       
   213     M2GGeneral::CheckErrorCode(aJni, err);
       
   214     
       
   215     return err; 
       
   216     
       
   217 }
       
   218 // -----------------------------------------------------------------------------
       
   219 // Java_com_nokia_microedition_m2g_M2GScalableGraphics::_render
       
   220 // -----------------------------------------------------------------------------
       
   221 /**
       
   222  * Calls MM2GRenderContext::RenderL method.
       
   223  * @since Series S60 3.0
       
   224  * @param aRenderContextHandle Context handle
       
   225  * @param aDocumentHandle Document handle.
       
   226  * @param aSvgW Svg width.
       
   227  * @param aSvgH Svg heigth.
       
   228  * @param aCurrentTime Current time.
       
   229  * @throws Exception if not ok
       
   230  */
       
   231 
       
   232 
       
   233 /**
       
   234  * JNI method
       
   235  */
       
   236 JNIEXPORT jint JNICALL
       
   237 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1renderLCDUI(
       
   238     JNIEnv* aJni,
       
   239     jobject,
       
   240     jint aRenderContextHandle,
       
   241     jint aDocumentHandle,
       
   242     jint aX, jint aY,
       
   243     jint aClipX, jint aClipY, jint aClipW, jint aClipH,
       
   244     jint aSvgW, jint aSvgH,
       
   245     jfloat aCurrentTime)
       
   246 {
       
   247     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GScalableGraphics ) _render, time:%f - begin", aCurrentTime);
       
   248 
       
   249     TM2GRenderRect rr(aX, aY, aClipX, aClipY, aClipW, aClipH);
       
   250     TInt err = KM2GNotOk;
       
   251 
       
   252     M2G_DO_LOCK
       
   253     
       
   254     if (aRenderContextHandle && aDocumentHandle)
       
   255         {
       
   256             MM2GRenderContext* rc = JavaUnhand<MM2GRenderContext>(aRenderContextHandle);
       
   257             TRAP(err,rc->RenderLCDUIL(aDocumentHandle, aCurrentTime, aSvgW, aSvgH, rr););
       
   258         }
       
   259     M2G_DO_UNLOCK(aJni)
       
   260     
       
   261     M2GGeneral::CheckErrorCode(aJni, err); 
       
   262     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GScalableGraphics ) _render: %d - end", err);
       
   263     return err;
       
   264 }
       
   265 
       
   266 
       
   267 JNIEXPORT jintArray JNICALL
       
   268 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1renderESWT(
       
   269     JNIEnv* aJni,
       
   270     jobject,
       
   271     jint aRenderContextHandle,
       
   272     jint aDocumentHandle,
       
   273     jint aX, jint aY,
       
   274     jint aClipX, jint aClipY, jint aClipW, jint aClipH,
       
   275     jint aSvgW, jint aSvgH,
       
   276     jfloat aCurrentTime,
       
   277     jint aUseNativeClear
       
   278 )
       
   279 {
       
   280     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GScalableGraphics ) _render, time:%f - begin", aCurrentTime);
       
   281     TM2GRenderRect rr(aX, aY, aClipX, aClipY, aClipW, aClipH);
       
   282     TInt err = KM2GNotOk;
       
   283     jintArray returnDataJava = aJni->NewIntArray(10);
       
   284     
       
   285     M2G_DO_LOCK
       
   286     
       
   287     TInt returnData[10];
       
   288     
       
   289     if (aRenderContextHandle && aDocumentHandle)
       
   290         {
       
   291         MM2GRenderContext* rc = JavaUnhand<MM2GRenderContext>(aRenderContextHandle);
       
   292         TRAP(err,rc->RenderESWTL(aDocumentHandle,aCurrentTime,aSvgW,aSvgH,rr,aUseNativeClear,returnData););    
       
   293         }
       
   294     M2G_DO_UNLOCK(aJni)
       
   295 
       
   296     
       
   297     if (returnDataJava != NULL)
       
   298         aJni->SetIntArrayRegion(returnDataJava, 0, 10, const_cast<TInt*>(returnData));
       
   299     
       
   300     M2GGeneral::CheckErrorCode(aJni, err); 
       
   301     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GScalableGraphics ) _render: %d - end", err);
       
   302     return returnDataJava;
       
   303 }
       
   304 // -----------------------------------------------------------------------------
       
   305 // Java_com_nokia_microedition_m2g_M2GScalableGraphics::_setRenderingQuality
       
   306 // -----------------------------------------------------------------------------
       
   307 /**
       
   308  * Calls MM2GRenderContext::SetRenderingQuality method.
       
   309  * @since Series S60 3.0
       
   310  * @param aRenderContextHandle Context handle
       
   311  * @param aMode
       
   312  * @throws Exception if not ok
       
   313  */
       
   314 JNIEXPORT void JNICALL
       
   315 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1setRenderingQuality(
       
   316     JNIEnv* aJni,
       
   317     jobject,
       
   318     jint aRenderContextHandle, jint aMode)
       
   319 {
       
   320     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _setRenderingQuality - begin");
       
   321     TInt err = KM2GNotOk;
       
   322     
       
   323     M2G_DO_LOCK
       
   324     
       
   325     if ( aRenderContextHandle)
       
   326         {
       
   327         MM2GRenderContext* rc = JavaUnhand<MM2GRenderContext>(aRenderContextHandle);
       
   328         TRAP(err,rc->SetRenderingQualityL(aMode););
       
   329         }
       
   330     M2G_DO_UNLOCK(aJni)
       
   331     
       
   332     M2GGeneral::CheckErrorCode(aJni, err);
       
   333 
       
   334     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _setRenderingQuality - end");
       
   335 }
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // Java_com_nokia_microedition_m2g_M2GScalableGraphics::_setTransparency
       
   339 // -----------------------------------------------------------------------------
       
   340 /**
       
   341  * Calls MM2GRenderContext::SetTransparency method.
       
   342  * @since Series S60 3.0
       
   343  * @param aRenderContextHandle Context handle
       
   344  * @param aAplha -
       
   345  */
       
   346 JNIEXPORT void JNICALL
       
   347 Java_com_nokia_microedition_m2g_M2GScalableGraphics__1setTransparency(
       
   348     JNIEnv* aJni,
       
   349     jobject,
       
   350     jint aRenderContextHandle,
       
   351     jfloat aAlpha)
       
   352 {
       
   353     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _setTransparency - begin");
       
   354     TInt err = KM2GNotOk;
       
   355     
       
   356     M2G_DO_LOCK
       
   357     
       
   358     if (aRenderContextHandle)
       
   359         {
       
   360         MM2GRenderContext* rc = JavaUnhand<MM2GRenderContext>(aRenderContextHandle);
       
   361         TRAP(err,rc->SetTransparency( (TReal32)aAlpha ););
       
   362         }
       
   363     M2G_DO_UNLOCK(aJni)
       
   364     
       
   365     M2GGeneral::CheckErrorCode(aJni, err);
       
   366 
       
   367     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GScalableGraphics ) _setTransparency - end");
       
   368 }
       
   369 
       
   370 M2G_NS_END
       
   371 
       
   372 
       
   373