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