javauis/mmapi_qt/baseline/src/cmmacanvasdisplay.cpp
changeset 26 dc7c549001d5
parent 23 98ccebc37403
child 47 f40128debb5d
equal deleted inserted replaced
23:98ccebc37403 26:dc7c549001d5
    30 
    30 
    31 // CONSTRUCTION
    31 // CONSTRUCTION
    32 // Static constructor, leaves pointer to cleanup-stack
    32 // Static constructor, leaves pointer to cleanup-stack
    33 CMMACanvasDisplay* CMMACanvasDisplay::NewLC(MMAFunctionServer* aEventSource, jobject obj/*MMIDCanvas* aCanvas*/)
    33 CMMACanvasDisplay* CMMACanvasDisplay::NewLC(MMAFunctionServer* aEventSource, jobject obj/*MMIDCanvas* aCanvas*/)
    34 {
    34 {
    35 	CMMACanvasDisplay* self =
    35     CMMACanvasDisplay* self =
    36         new(ELeave) CMMACanvasDisplay(aEventSource, obj/*aCanvas*/);
    36         new(ELeave) CMMACanvasDisplay();
    37 
    37 
    38     CleanupStack::PushL(self);
    38     CleanupStack::PushL(self);
    39     self->Construct(aEventSource,obj);
    39     self->Construct(aEventSource,obj);
    40     return self;
    40     return self;
    41 }
    41 }
    43 // Destructor (virtual by CBase)
    43 // Destructor (virtual by CBase)
    44 CMMACanvasDisplay::~CMMACanvasDisplay()
    44 CMMACanvasDisplay::~CMMACanvasDisplay()
    45 {
    45 {
    46 }
    46 }
    47 
    47 
    48 CMMACanvasDisplay::CMMACanvasDisplay(MMAFunctionServer* aEventSource ,jobject aJavaDisplayRef)
    48 
    49 {
       
    50 	/*
       
    51 iJni = aEventSource->getValidJniEnv();
       
    52 javaDisplayObject = iJni->NewGlobalRef(javadisplayref);
       
    53 javaDisplayClass = iJni->GetObjectClass(javaDisplayObject);
       
    54 */
       
    55 }
       
    56 
    49 
    57 
    50 
    58 /*
    51 /*
    59 void CMMACanvasDisplay::SourceSizeChanged(const TSize& aSourceSize)
    52 void CMMACanvasDisplay::SourceSizeChanged(const TSize& aSourceSize)
    60 {
    53 {
    61     LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged");
    54     LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged");
    62 
    55 
    63     #ifdef RD_JAVA_NGA_ENABLED
    56     #ifdef RD_JAVA_NGA_ENABLED
    64     if ( iWindow )
    57     if ( iWindow )
    65 			{
    58             {
    66     	iWindow->SetVideoCropRegion( TRect( iUserRect.iTl, aSourceSize ) );
    59         iWindow->SetVideoCropRegion( TRect( iUserRect.iTl, aSourceSize ) );
    67     	}
    60         }
    68     #endif
    61     #endif
    69 
    62 
    70     iSourceSize = aSourceSize;
    63     iSourceSize = aSourceSize;
    71     jmethodID getDisplayWidthID = iJni->GetMethodID(
    64     jmethodID getDisplayWidthID = iJni->GetMethodID(
    72                                          iJavaDisplayClass,
    65                                          iJavaDisplayClass,
    80 
    73 
    81 
    74 
    82      TInt x =  iJni->CallIntMethod(iJavaDisplayObject,getDisplayWidthID);
    75      TInt x =  iJni->CallIntMethod(iJavaDisplayObject,getDisplayWidthID);
    83      TInt y = iJni->CallIntMethod(iJavaDisplayObject,getDisplayHeightID);
    76      TInt y = iJni->CallIntMethod(iJavaDisplayObject,getDisplayHeightID);
    84 
    77 
    85    // TSize fullScreenSize(100,100);    // TO-Do remove hardcoded with the relevent one
    78    // TSize iFullScreenSize(100,100);    // TO-Do remove hardcoded with the relevent one
    86 	LOG2(EJavaMMAPI,EInfo,"CMMACanvasdisplay.cpp : SourceSizeChanged () fullScreenSize is x = %d ,y = %d ",x,y);
    79     LOG2(EJavaMMAPI,EInfo,"CMMACanvasdisplay.cpp : SourceSizeChanged () iFullScreenSize is x = %d ,y = %d ",x,y);
    87 	// get the ScreenSize from canvas in java
    80     // get the ScreenSize from canvas in java
    88     TSize canvasSize(x, y);
    81     TSize canvasSize(x, y);
    89     fullScreenSize = canvasSize;
    82     iFullScreenSize = canvasSize;
    90     TBool sourceIsBigger = (aSourceSize.iWidth > fullScreenSize.iWidth ||
    83     TBool sourceIsBigger = (aSourceSize.iWidth > iFullScreenSize.iWidth ||
    91                             aSourceSize.iHeight > fullScreenSize.iHeight);
    84                             aSourceSize.iHeight > iFullScreenSize.iHeight);
    92 
    85 
    93     if (sourceIsBigger)
    86     if (sourceIsBigger)
    94     {
    87     {
    95         // Source is larger than display area.
    88         // Source is larger than display area.
    96         // Shrink draw are to fit in display.
    89         // Shrink draw are to fit in display.
    97         iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize));
    90         iWindow->SetDrawRect(ScaleToFullScreen(iFullScreenSize, iSourceSize));
    98     }
    91     }
    99     else
    92     else
   100     {
    93     {
   101         // source is smaller than display area
    94         // source is smaller than display area
   102         iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize));
    95         iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize));
   117     }
   110     }
   118 }
   111 }
   119 
   112 
   120 */
   113 */
   121 
   114 
       
   115 void CMMACanvasDisplay::SourceSizeChanged(TInt aJavaControlWidth, TInt aJavaControlHeight,TInt /*x*/, TInt /*y*/,TRect /*aBoundsRect*/)
       
   116 {
       
   117     JELOG2(EJavaMMAPI);
       
   118     LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged(aSourceSize,aJavaControlWidth,aJavaControlHeight) + aJavaControlWidth = %d ,aJavaControlHeight = %d",aJavaControlWidth,aJavaControlHeight);
       
   119     iSourceSize = SourceSize();
       
   120     LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged(aSourceSize,aJavaControlWidth,aJavaControlHeight) + sourcesize = %d X %d",iSourceSize.iWidth , iSourceSize.iHeight);
       
   121 #ifdef RD_JAVA_NGA_ENABLED
       
   122     if (iWindow)
       
   123     {
       
   124         iWindow->SetVideoCropRegion(TRect(iUserRect.iTl, iSourceSize));
       
   125     }
       
   126 #endif
       
   127 
       
   128     // size of canvas in java
       
   129     TSize canvasSize(aJavaControlWidth, aJavaControlHeight);
       
   130     iFullScreenSize = canvasSize;
       
   131     TBool sourceIsBigger = (iSourceSize.iWidth > iFullScreenSize.iWidth ||
       
   132                             iSourceSize.iHeight > iFullScreenSize.iHeight);
       
   133 
       
   134     if (sourceIsBigger)
       
   135     {
       
   136         // Source is larger than display area.
       
   137         // Shrink draw are to fit in display.
       
   138         LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged - source is bigger than display area");
       
   139         iWindow->SetDrawRect(ScaleToFullScreen(iFullScreenSize, iSourceSize));
       
   140         LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged - source is bigger than display area - after SetDrawRect");
       
   141 
       
   142     }
       
   143     else
       
   144     {
       
   145         // source is smaller than display area
       
   146         LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged - source is smaller than display area");
       
   147         iWindow->SetDrawRect(TRect(iUserRect.iTl, iSourceSize));
       
   148     }
       
   149 
       
   150     SetClippingRegion();
       
   151 
       
   152     if (iUserRect.IsEmpty())
       
   153     {
       
   154         // Java side hasn't set size.
       
   155         iUserRect = iWindow->DrawRect();
       
   156 
       
   157         if (!sourceIsBigger)
       
   158         {
       
   159             // Addjusting rect to top left corner.
       
   160             iUserRect = TRect(iUserRect.Size());
       
   161         }
       
   162     }
       
   163     LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SourceSizeChanged(aJavaControlWidth,aJavaControlHeight)-");
       
   164 }
       
   165 
       
   166 
   122 void CMMACanvasDisplay::SetFullScreenL(TBool aFullScreen)
   167 void CMMACanvasDisplay::SetFullScreenL(TBool aFullScreen)
   123 {
   168 {
   124 	LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL +");
   169     LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL +");
   125     iFullScreen = aFullScreen;
   170     iFullScreen = aFullScreen;
   126     if (iContainerVisible)
   171     if (iContainerVisible)
   127     {
   172     {
   128         RemoveClippingRegion();
   173         RemoveClippingRegion();
   129 
   174 
   130         if (aFullScreen)
   175         if (aFullScreen)
   131         {
   176         {
   132             // use new scaled rect
   177             // use new scaled rect
   133             // iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize));
   178             // iWindow->SetDrawRect(ScaleToFullScreen(fullScreenSize, iSourceSize));
   134             iWindow->SetDrawRectThread(ScaleToFullScreen(fullScreenSize, iSourceSize));
   179             iWindow->SetDrawRectThread(ScaleToFullScreen(iFullScreenSize, iSourceSize));
   135 		}
   180         }
   136         else
   181         else
   137         {
   182         {
   138 			// use size set from java
   183             // use size set from java
   139             //iWindow->SetDrawRect(iUserRect);
   184             //iWindow->SetDrawRect(iUserRect);
   140             iWindow->SetDrawRectThread(iUserRect);
   185             iWindow->SetDrawRectThread(iUserRect);
   141         }
   186         }
   142 
   187 
   143         AddClippingRegion();
   188         AddClippingRegion();
   145     LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL +");
   190     LOG(EJavaMMAPI,EInfo,"CMMACanvasDisplay::SetFullScreenL +");
   146 }
   191 }
   147 
   192 
   148 void CMMACanvasDisplay::SetWindowL(MMMADisplayWindow* aWindow)
   193 void CMMACanvasDisplay::SetWindowL(MMMADisplayWindow* aWindow)
   149 {
   194 {
   150     LOG( EJavaMMAPI, EInfo, "CMMACanvasDisplay::SetWindowL");
   195     LOG(EJavaMMAPI, EInfo, "CMMACanvasDisplay::SetWindowL");
   151     CMMADisplay::SetWindowL(aWindow);
   196     CMMADisplay::SetWindowL(aWindow);
   152     if (!iWindow)
   197     if (!iWindow)
   153     {
   198     {
   154         LOG( EJavaMMAPI, EInfo, "CMMACanvasDisplay::SetWindowL: NULL window, returning");
   199         LOG(EJavaMMAPI, EInfo, "CMMACanvasDisplay::SetWindowL: NULL window, returning");
   155         return;
   200         return;
   156     }
   201     }
   157 	/*
   202     /*
   158     CFbsBitmap* bitmap = iCanvas->FrameBuffer();
   203     CFbsBitmap* bitmap = iCanvas->FrameBuffer();
   159 
   204 
   160     __ASSERT_DEBUG(bitmap,
   205     __ASSERT_DEBUG(bitmap,
   161                    User::Panic(_L("Canvas has no bitmap"),
   206                    User::Panic(_L("Canvas has no bitmap"),
   162                                KErrNotFound));
   207                                KErrNotFound));
   166     // Check that container exists
   211     // Check that container exists
   167     User::LeaveIfNull(iDirectContainer);
   212     User::LeaveIfNull(iDirectContainer);
   168 
   213 
   169     LOG2( EJavaMMAPI, EInfo, "MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() TL %d %d", iDirectContainer->MdcContentBounds().iTl.iX, iDirectContainer->MdcContentBounds().iTl.iY);
   214     LOG2( EJavaMMAPI, EInfo, "MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() TL %d %d", iDirectContainer->MdcContentBounds().iTl.iX, iDirectContainer->MdcContentBounds().iTl.iY);
   170     LOG2( EJavaMMAPI, EInfo, "MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() BR %d %d", iDirectContainer->MdcContentBounds().iBr.iX, iDirectContainer->MdcContentBounds().iBr.iY);
   215     LOG2( EJavaMMAPI, EInfo, "MMA::CMMACanvasDisplay::SetWindowL iDirectContainer->MdcContentBounds() BR %d %d", iDirectContainer->MdcContentBounds().iBr.iX, iDirectContainer->MdcContentBounds().iBr.iY);
   171 	*/
   216     */
   172 	LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::before calling  BoundRect");
   217     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::before calling  BoundRect");
   173 	TRect boundrect = BoundRect();
   218     TRect boundrect = BoundRect();
   174     iWindow->SetWindowRect(boundrect/*iDirectContainer->MdcContentBounds()*/, MMMADisplay::EMmaThread);
   219     iWindow->SetWindowRect(boundrect/*iDirectContainer->MdcContentBounds()*/, MMMADisplay::EMmaThread);
   175 
   220 
   176     #ifdef RD_JAVA_NGA_ENABLED
   221 #ifdef RD_JAVA_NGA_ENABLED
   177     //iWindow->SetRWindowRect( iDirectContainer->MdcContainerWindowRect(),
   222     //iWindow->SetRWindowRect( iDirectContainer->MdcContainerWindowRect(),
   178     //                         MMMADisplay::EMmaThread );
   223     //                         MMMADisplay::EMmaThread );
   179 	iWindow->SetRWindowRect( boundrect,
   224     iWindow->SetRWindowRect(boundrect,
   180      							MMMADisplay::EMmaThread );
   225                             MMMADisplay::EMmaThread);
   181     #endif
   226 #endif
   182     
   227 
   183     SetClippingRegion();
   228     SetClippingRegion();
   184 }
   229 }
   185 
   230 
   186 
   231 
   187 
   232 
   188 TRect& CMMACanvasDisplay::BoundRect()
   233 TRect CMMACanvasDisplay::BoundRect()
   189 {
   234 {
   190   LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect +");
   235     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect +");
   191   jmethodID getBoundRectID = iJni->GetMethodID(
   236     jmethodID getBoundRectID = iJni->GetMethodID(
   192 	                                         iJavaDisplayClass,
   237                                    iJavaDisplayClass,
   193 	                                         "getBoundRect",
   238                                    "getBoundRect",
   194                                          "()V");
   239                                    "()V");
   195 
   240 
   196   LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --1");
   241     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --1");
   197   // set the value to java,so that we can access those from array
   242     // set the value to java,so that we can access those from array
   198   iJni->CallVoidMethod(iJavaDisplayObject,getBoundRectID);
   243     iJni->CallVoidMethod(iJavaDisplayObject,getBoundRectID);
   199   jfieldID field = iJni->GetFieldID(iJavaDisplayClass, "displayboundarr", "[I");
   244     jfieldID field = iJni->GetFieldID(iJavaDisplayClass, "displayboundarr", "[I");
   200   if(field == NULL)
   245     if (field == NULL)
   201   {
   246     {
   202 	  // handle error
   247         // handle error
   203   }
   248     }
   204   /* Read the instance field s */
   249     /* Read the instance field s */
   205   jintArray javaboundinfoarr = (jintArray)iJni->GetObjectField(iJavaDisplayObject, field);
   250     jintArray javaboundinfoarr = (jintArray)iJni->GetObjectField(iJavaDisplayObject, field);
   206   LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --2");
   251     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --2");
   207   jint* nativeboundinfoarr = iJni->GetIntArrayElements(javaboundinfoarr, NULL);
   252     jint* nativeboundinfoarr = iJni->GetIntArrayElements(javaboundinfoarr, NULL);
   208     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --3");
   253     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --3");
   209     if (!nativeboundinfoarr)
   254     if (!nativeboundinfoarr)
   210     {    // outputBuffer was already allocated
   255     {
       
   256         // outputBuffer was already allocated
   211         iJni->ReleaseIntArrayElements(javaboundinfoarr, nativeboundinfoarr, JNI_ABORT);
   257         iJni->ReleaseIntArrayElements(javaboundinfoarr, nativeboundinfoarr, JNI_ABORT);
   212         // return invalid rect.
   258         // return invalid rect.
   213         TRect rect(0,0,0,0);
   259         TRect rect(0,0,0,0);
   214         return rect;
   260         return rect;
   215     }
   261     }
   216   LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --4");
   262     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect --4");
   217 // create TRect
   263 // create TRect
   218   TInt xcoordinate = nativeboundinfoarr[0];
   264     TInt xcoordinate = nativeboundinfoarr[0];
   219   TInt ycoordinate = nativeboundinfoarr[1];
   265     TInt ycoordinate = nativeboundinfoarr[1];
   220   TInt width = nativeboundinfoarr[2];
   266     TInt width = nativeboundinfoarr[2];
   221   TInt height = nativeboundinfoarr[3];
   267     TInt height = nativeboundinfoarr[3];
   222   LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay: BoundRect() co-ordinate of topleftcorner is x = %d,y =%d",xcoordinate,ycoordinate);
   268     LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay: BoundRect() co-ordinate of topleftcorner is x = %d,y =%d",xcoordinate,ycoordinate);
   223   LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay: BoundRect() size of bound rect is width = %d,height =%d",width,height);
   269     LOG2(EJavaMMAPI,EInfo,"CMMACanvasDisplay: BoundRect() size of bound rect is width = %d,height =%d",width,height);
   224   TPoint topleft(xcoordinate,ycoordinate);
   270     TPoint topleft(xcoordinate,ycoordinate);
   225   TSize rectsize(width,height);
   271     TSize rectsize(width,height);
   226   TRect boundRect(topleft,rectsize);
   272     TRect boundRect(topleft,rectsize);
   227   iJni->ReleaseIntArrayElements(javaboundinfoarr, nativeboundinfoarr, JNI_COMMIT);
   273     iJni->ReleaseIntArrayElements(javaboundinfoarr, nativeboundinfoarr, JNI_COMMIT);
   228    LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect -");
   274     LOG(EJavaMMAPI,EInfo,"MMA::CMMACanvasDisplay::BoundRect -");
   229   return boundRect;
   275     return boundRect;
   230 }
   276 }
   231 
   277 
   232 // ask java side peer about the container rect size
   278 // ask java side peer about the container rect size
   233 // currently assuming the boundrect and containerrect will be same in case of canvas
   279 // currently assuming the boundrect and containerrect will be same in case of canvas
   234 TRect& CMMACanvasDisplay::ContainerWindowRect()
   280 TRect CMMACanvasDisplay::ContainerWindowRect()
   235 {
   281 {
   236 
   282 
   237   return BoundRect();
   283     return BoundRect();
   238 
   284 
   239 }
   285 }
   240 
   286 
   241 
   287 
   242 void CMMACanvasDisplay::SetDisplayLocationL(const TPoint& aPosition)
   288 void CMMACanvasDisplay::SetDisplayLocationL(const TPoint& aPosition)