javauis/lcdui_qt/src/javax/microedition/lcdui/Graphics.java
changeset 78 71ad690e91f5
parent 67 63b81d807542
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
   999      *            rendered.
   999      *            rendered.
  1000      * @param w - width of the rectangle to be rendered.
  1000      * @param w - width of the rectangle to be rendered.
  1001      * @param h - height of the rectangle to be rendered.
  1001      * @param h - height of the rectangle to be rendered.
  1002      * @param alpha - true if alpha values should be rendered, false otherwise.
  1002      * @param alpha - true if alpha values should be rendered, false otherwise.
  1003      */
  1003      */
  1004     public void drawRGB(int[] rgb,
  1004     public void drawRGB(int[] aRgbData,
  1005                         int offset,
  1005                         int aOffset,
  1006                         int scanlength,
  1006                         int aScanLength,
  1007                         int x,
  1007                         int aX,
  1008                         int y,
  1008                         int aY,
  1009                         int w,
  1009                         int aWidth,
  1010                         int h,
  1010                         int aHeight,
  1011                         boolean alpha)
  1011                         boolean aProcessAlpha)
  1012     {
  1012     {
  1013 
  1013 
  1014         if(rgb == null)
  1014         if(aRgbData == null)
  1015         {
  1015         {
  1016             throw new NullPointerException(
  1016             throw new NullPointerException(
  1017                 MsgRepository.IMAGE_EXCEPTION_DATA_IS_NULL);
  1017                 MsgRepository.IMAGE_EXCEPTION_DATA_IS_NULL);
  1018         }
  1018         }
  1019         synchronized(graphicsBuffer)
  1019 
  1020         {
  1020         // setting of help variables
  1021             graphicsBuffer.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha, this);
  1021         int len = aRgbData.length;
       
  1022         int width = aWidth >= 0 ? aWidth : -aWidth;
       
  1023         int height = aHeight >= 0 ? aHeight : -aHeight;
       
  1024 
       
  1025         int scanLength;
       
  1026 
       
  1027         long end64 = (long)len - 1;
       
  1028         long offset64;
       
  1029         long scanLength64;
       
  1030 
       
  1031         if(aScanLength >= 0)
       
  1032         {
       
  1033             // If aScanLength is positive, we can use RGB data forward.
       
  1034             scanLength = aScanLength;
       
  1035             offset64   = (long)aOffset;
       
  1036         }
       
  1037         else
       
  1038         {
       
  1039             // If aScanlength is negative, we have to use RGB data backward.
       
  1040             scanLength = -aScanLength;
       
  1041             offset64 = (long)aOffset - (long)scanLength * ((long)height - 1);
       
  1042         }
       
  1043 
       
  1044         scanLength64 = (long)scanLength;
       
  1045         long min64 = offset64;
       
  1046         long max64 = offset64 + scanLength64 * ((long)height - 1) + (long)width - 1;
       
  1047 
       
  1048         // Check for incorrect data.
       
  1049         if ((min64 < 0) || (max64 > end64))
       
  1050         {
       
  1051             throw new ArrayIndexOutOfBoundsException();
       
  1052         }
       
  1053 
       
  1054         synchronized(graphicsBuffer)
       
  1055         {
       
  1056             graphicsBuffer.drawRGB(aRgbData, aOffset, aScanLength, aX, aY, aWidth,
       
  1057                 aHeight, aProcessAlpha, this);
  1022         }
  1058         }
  1023     }
  1059     }
  1024 
  1060 
  1025     /**
  1061     /**
  1026      * Fills the specified triangle with current color.
  1062      * Fills the specified triangle with current color.
  1072             throw new IllegalStateException(
  1108             throw new IllegalStateException(
  1073                 MsgRepository.GRAPHICS_EXCEPTION_DESTINATION_IS_SCREEN);
  1109                 MsgRepository.GRAPHICS_EXCEPTION_DESTINATION_IS_SCREEN);
  1074         }
  1110         }
  1075         synchronized(graphicsBuffer)
  1111         synchronized(graphicsBuffer)
  1076         {
  1112         {
       
  1113             /*
       
  1114              * Silently ignore - even if the source point is out of bounds.
       
  1115              */
       
  1116             if (w <= 0 || h <= 0)
       
  1117             {
       
  1118                 return;
       
  1119             }
       
  1120 
  1077             Image image = (Image)graphicsBuffer.getHost();
  1121             Image image = (Image)graphicsBuffer.getHost();
  1078             if(!javax.microedition.lcdui.Image.validateRegion(image
  1122             if(!javax.microedition.lcdui.Image.validateRegion(image.getWidth(), 
  1079                     .getWidth(), image.getHeight(), xFrom, yFrom, w, h))
  1123                 image.getHeight(), xFrom, yFrom, w, h))
  1080             {
  1124             {
  1081                 throw new IllegalArgumentException(
  1125                 throw new IllegalArgumentException(
  1082                     MsgRepository.IMAGE_EXCEPTION_INVALID_REGION);
  1126                     MsgRepository.IMAGE_EXCEPTION_INVALID_REGION);
  1083             }
  1127             }
  1084 
  1128 
  1202                 graphicsBuffer.drawImage(localCgfxImage,
  1246                 graphicsBuffer.drawImage(localCgfxImage,
  1203                     localX, localY, localW, localH, localXSrc, localYSrc, localW, localH, localGcTransform, self);
  1247                     localX, localY, localW, localH, localXSrc, localYSrc, localW, localH, localGcTransform, self);
  1204             }
  1248             }
  1205         }
  1249         }
  1206     }
  1250     }
  1207 
       
  1208     /**
       
  1209      * Performs synchronization on the graphics buffer, i.e.
       
  1210      * the buffered draw commands are rasterized to the surface.
       
  1211      */
       
  1212     void sync()
       
  1213     {
       
  1214         synchronized(graphicsBuffer) 
       
  1215         {
       
  1216             if(syncStrategy == SYNC_LEAVE_SURFACE_SESSION_OPEN)
       
  1217             {
       
  1218                 // This instance is used only with paint callbacks, thus  
       
  1219                 // sync is called with the indication that surface paint  
       
  1220                 // session can be left open as it will be closed when the 
       
  1221                 // callback returns.
       
  1222                 graphicsBuffer.sync(false);
       
  1223             }
       
  1224             else 
       
  1225             {
       
  1226                 graphicsBuffer.sync(true);
       
  1227             } 
       
  1228         }
       
  1229     }
       
  1230     
       
  1231     
  1251     
  1232     /**
  1252     /**
  1233      * Return DirectGraphics associated with this instance.
  1253      * Return DirectGraphics associated with this instance.
  1234      */
  1254      */
  1235     DirectGraphics getDirectGraphics()
  1255     DirectGraphics getDirectGraphics()
  1265             return GraphicsContext.STROKE_DOT;
  1285             return GraphicsContext.STROKE_DOT;
  1266         }
  1286         }
  1267         return INVALID_STROKE_STYLE;
  1287         return INVALID_STROKE_STYLE;
  1268     }
  1288     }
  1269 
  1289 
       
  1290     /*
       
  1291      * External renderer support.
       
  1292      * Closes surface session opened by startExternalRendering -call.
       
  1293      */
       
  1294     void endExternalRendering()
       
  1295     {
       
  1296         synchronized(graphicsBuffer) 
       
  1297         {
       
  1298         	ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
  1299             {
       
  1300                 public void run()
       
  1301                 {
       
  1302                     graphicsBuffer.endFrame();
       
  1303                 }
       
  1304             });
       
  1305         }	
       
  1306     }
       
  1307     
       
  1308     /*
       
  1309      * External renderer support.
       
  1310      * Flushes any pending draw commands to the surface and
       
  1311      * leaves the surface session open for external renderer.
       
  1312      */
       
  1313     void startExternalRendering()
       
  1314     {
       
  1315         synchronized(graphicsBuffer) 
       
  1316         {
       
  1317         	ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
  1318             {
       
  1319                 public void run()
       
  1320                 {
       
  1321                     graphicsBuffer.sync(false);
       
  1322                 }
       
  1323             });
       
  1324         }	
       
  1325     }
       
  1326     
       
  1327     /*
       
  1328      * Flushes any pending draw commands to surface.
       
  1329      */
       
  1330     void sync()
       
  1331     {
       
  1332         synchronized(graphicsBuffer) 
       
  1333         {
       
  1334         	ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
  1335             {
       
  1336                 public void run()
       
  1337                 {
       
  1338                 	if(syncStrategy == SYNC_LEAVE_SURFACE_SESSION_OPEN)
       
  1339                 	{
       
  1340                         graphicsBuffer.sync(false);
       
  1341                 	}
       
  1342                 	else 
       
  1343                 	{
       
  1344                 		graphicsBuffer.sync(true);
       
  1345                 	}
       
  1346                 }
       
  1347             });
       
  1348         }	
       
  1349     }
       
  1350     
       
  1351     Rectangle getClipInWindowCoordinates() 
       
  1352     {
       
  1353     	synchronized(graphicsBuffer) 
       
  1354         {
       
  1355     		return graphicsBuffer.toWindowCoordinates(currentClip[0] + translateX, 
       
  1356     		                                          currentClip[1] + translateY, 
       
  1357     		                                          currentClip[2], 
       
  1358     		                                          currentClip[3]);
       
  1359         }
       
  1360     }
       
  1361     
  1270     //
  1362     //
  1271     // Nokia UI API support
  1363     // Nokia UI API support
  1272     //
  1364     //
  1273     void drawRGB(int[] rgb, int offset, int scanlength, int x, int y, int w,
  1365     void drawRGB(int[] rgb, int offset, int scanlength, int x, int y, int w,
  1274                  int h, boolean processAlpha, int manipulation)
  1366                  int h, boolean processAlpha, int manipulation)