javauis/lcdui_qt/src/javax/microedition/lcdui/Graphics.java
changeset 50 023eef975703
parent 35 85266cc22c7f
child 56 abc41079b313
equal deleted inserted replaced
49:35baca0e7a2e 50:023eef975703
    93     // Set default sync strategy as closed
    93     // Set default sync strategy as closed
    94     private int syncStrategy = SYNC_LEAVE_SURFACE_SESSION_CLOSED; 
    94     private int syncStrategy = SYNC_LEAVE_SURFACE_SESSION_CLOSED; 
    95     
    95     
    96     private DirectGraphics directGraphics;
    96     private DirectGraphics directGraphics;
    97     private Buffer graphicsBuffer;
    97     private Buffer graphicsBuffer;
    98 
    98     
    99     // Current font for rendering texts.
    99     // Cache for settings
       
   100     // these members have package visibility,
       
   101     // however they meant to be accessed only by 
       
   102     // this (Graphics) instance or related (Buffer) 
       
   103     // greaphicsBuffer instance
   100     Font currentFont;
   104     Font currentFont;
   101     int currentColor;
   105     int currentColor;
   102     int translateX;
   106     int translateX;
   103     int translateY;
   107     int translateY;
   104     int[] currentClip = new int[4];
   108     int[] currentClip = new int[4];
   105     int currentStrokeStyle;
   109     int currentStrokeStyle;
   106 
   110     
   107     private com.nokia.mj.impl.rt.support.Finalizer finalizer;
   111     private com.nokia.mj.impl.rt.support.Finalizer finalizer;
   108 
   112 
   109     //Constructor
   113     //Constructor
   110     Graphics(Buffer buffer, Rectangle clipRect)
   114     Graphics(Buffer buffer, Rectangle clipRect)
   111     {
   115     {
   133         });
   137         });
   134         currentClip[0] = clipRect.x;
   138         currentClip[0] = clipRect.x;
   135         currentClip[1] = clipRect.y;
   139         currentClip[1] = clipRect.y;
   136         currentClip[2] = clipRect.width;
   140         currentClip[2] = clipRect.width;
   137         currentClip[3] = clipRect.height;
   141         currentClip[3] = clipRect.height;
       
   142         setDefaultSettings();
   138         graphicsBuffer = buffer;
   143         graphicsBuffer = buffer;
   139         reset();
       
   140     }
   144     }
   141 
   145 
   142 
   146 
   143 
   147 
   144     /**
   148     /**
   152         }
   156         }
   153     }
   157     }
   154 
   158 
   155     /**
   159     /**
   156      * Resets Graphics state to initial.
   160      * Resets Graphics state to initial.
       
   161      * Reset does not set the clip.
   157      */
   162      */
   158     void reset()
   163     void reset()
       
   164     {
       
   165     	synchronized(graphicsBuffer) {
       
   166     		// setDefaultSettings() must be called 
       
   167     		// before the setGraphicsDefaults() since
       
   168     		// graphicsBuffer (Buffer implementation) uses 
       
   169     		// the member values of this instance when setting the defaults
       
   170     		setDefaultSettings();
       
   171     		graphicsBuffer.setGraphicsDefaults(this);
       
   172     	}
       
   173     }
       
   174 
       
   175     void setDefaultSettings() 
   159     {
   176     {
   160         currentFont = Buffer.defaultFont;
   177         currentFont = Buffer.defaultFont;
   161         currentColor = Buffer.defaultColor;
   178         currentColor = Buffer.defaultColor;
   162         currentStrokeStyle = Buffer.defaultStrokeStyle;
   179         currentStrokeStyle = Buffer.defaultStrokeStyle;
   163         translateX = Buffer.defaultTranslateX;
   180         translateX = Buffer.defaultTranslateX;
   164         translateY = Buffer.defaultTranslateY;
   181         translateY = Buffer.defaultTranslateY;
   165     }
   182     }
   166 
   183     
   167     /**
   184     /**
   168      * Cleans the Canvas background.
   185      * Cleans the Canvas background.
   169      */
   186      */
   170     void cleanBackground(Rectangle area)
   187     void cleanBackground(Rectangle area)
   171     {
   188     {
   191      * This affects on the behavior of the sync method of this class
   208      * This affects on the behavior of the sync method of this class
   192      * which is called via LCDUIInvoker
   209      * which is called via LCDUIInvoker
   193      */
   210      */
   194     void setSyncStrategy(int strategy)
   211     void setSyncStrategy(int strategy)
   195     {
   212     {
   196     	if((strategy != SYNC_LEAVE_SURFACE_SESSION_CLOSED) && (strategy != SYNC_LEAVE_SURFACE_SESSION_OPEN)) 
   213         if((strategy != SYNC_LEAVE_SURFACE_SESSION_CLOSED) && (strategy != SYNC_LEAVE_SURFACE_SESSION_OPEN)) 
   197     	{
   214         {
   198     		throw new IllegalArgumentException("Internal: Invalid strategy value");
   215             throw new IllegalArgumentException("Internal: Invalid strategy value");
   199     	}
   216         }
   200     	syncStrategy = strategy;
   217         syncStrategy = strategy;
   201     }
   218     }
   202 
   219 
   203     /**
   220     /**
   204      * Sets coordinate translation. Translations are cumulative.
   221      * Sets coordinate translation. Translations are cumulative.
   205      *
   222      *
   262      */
   279      */
   263     public int getRedComponent()
   280     public int getRedComponent()
   264     {
   281     {
   265         synchronized(graphicsBuffer)
   282         synchronized(graphicsBuffer)
   266         {
   283         {
   267             return currentColor >> 16;
   284             return (currentColor >> 16) & COMPONENT_MASK;
   268         }
   285         }
   269     }
   286     }
   270 
   287 
   271     /**
   288     /**
   272      * Returns green component of current color.
   289      * Returns green component of current color.
   873 
   890 
   874             synchronized(image.graphicsBuffer)
   891             synchronized(image.graphicsBuffer)
   875             {
   892             {
   876                 final Image localLcduiImage = image;
   893                 final Image localLcduiImage = image;
   877                 final org.eclipse.swt.internal.qt.graphics.Image localCgfxImage = 
   894                 final org.eclipse.swt.internal.qt.graphics.Image localCgfxImage = 
   878                 	Internal_GfxPackageSupport.getImage(Image.getESWTImage(image));
   895                     Internal_GfxPackageSupport.getImage(Image.getESWTImage(image));
   879                 final int localX = x;
   896                 final int localX = x;
   880                 final int localY = y;
   897                 final int localY = y;
   881                 final Graphics self = this;
   898                 final Graphics self = this;
   882                 
   899                 
   883                 ESWTUIThreadRunner.safeSyncExec(new Runnable() 
   900                 if(image.graphicsBuffer.containsDrawnPrimitives()) {
   884     			{
   901                     localLcduiImage.sync(true);
   885     				public void run()
   902                 }
   886     				{
   903                 graphicsBuffer.drawImage(localCgfxImage, localX, localY, self);
   887     					localLcduiImage.sync(false);
       
   888     					graphicsBuffer.drawImage(localCgfxImage, localX, localY, self);
       
   889     				}
       
   890     			});
       
   891                 
       
   892             }
   904             }
   893         }
   905         }
   894     }
   906     }
   895 
   907 
   896     /**
   908     /**
  1180                 x = xDst - srcImage.getWidth();
  1192                 x = xDst - srcImage.getWidth();
  1181             }
  1193             }
  1182             final int gcTransform = Image.getCgTransformValue(transform);
  1194             final int gcTransform = Image.getCgTransformValue(transform);
  1183             synchronized(srcImage.graphicsBuffer)
  1195             synchronized(srcImage.graphicsBuffer)
  1184             {
  1196             {
  1185             	final Image localLcduiSrcImage = srcImage;
  1197                 final Image localLcduiSrcImage = srcImage;
  1186             	final org.eclipse.swt.internal.qt.graphics.Image localCgfxImage = 
  1198                 final org.eclipse.swt.internal.qt.graphics.Image localCgfxImage = 
  1187                 	Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage));
  1199                     Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage));
  1188             	final int localX = x;
  1200                 final int localX = x;
  1189             	final int localY = y;
  1201                 final int localY = y;
  1190             	final int localW = width;
  1202                 final int localW = width;
  1191             	final int localH = height;
  1203                 final int localH = height;
  1192             	final int localXSrc = xSrc;
  1204                 final int localXSrc = xSrc;
  1193             	final int localYSrc = ySrc;
  1205                 final int localYSrc = ySrc;
  1194             	final int localGcTransform = gcTransform;
  1206                 final int localGcTransform = gcTransform;
  1195             	final Graphics self = this;
  1207                 final Graphics self = this;
  1196             	ESWTUIThreadRunner.safeSyncExec(new Runnable()
  1208                 if(srcImage.graphicsBuffer.containsDrawnPrimitives()) {
  1197                 {
  1209                     localLcduiSrcImage.sync(true);
  1198                     public void run()
  1210                 }
  1199                     {
  1211                 graphicsBuffer.drawImage(localCgfxImage,
  1200                     	localLcduiSrcImage.sync(false);
  1212                     localX, localY, localW, localH, localXSrc, localYSrc, localW, localH, localGcTransform, self);
  1201                         graphicsBuffer.drawImage(localCgfxImage,
       
  1202                         		localX, localY, localW, localH, localXSrc, localYSrc, localW, localH, localGcTransform, self);
       
  1203                     }
       
  1204                 });
       
  1205             }
  1213             }
  1206         }
  1214         }
  1207     }
  1215     }
  1208 
  1216 
  1209     /**
  1217     /**
  1210      * Performs synchronization on the graphics buffer, i.e.
  1218      * Performs synchronization on the graphics buffer, i.e.
  1211      * the buffered draw commands are rasterized to the surface.
  1219      * the buffered draw commands are rasterized to the surface.
  1212      */
  1220      */
  1213     void sync()
  1221     void sync()
  1214     {
  1222     {
  1215     	synchronized(graphicsBuffer) 
  1223         synchronized(graphicsBuffer) 
  1216     	{
  1224         {
  1217     		if(syncStrategy == SYNC_LEAVE_SURFACE_SESSION_OPEN)
  1225             if(syncStrategy == SYNC_LEAVE_SURFACE_SESSION_OPEN)
  1218     		{
  1226             {
  1219     			// This instance is used only with paint callbacks, thus  
  1227                 // This instance is used only with paint callbacks, thus  
  1220     			// sync is called with the indication that surface paint  
  1228                 // sync is called with the indication that surface paint  
  1221     			// session can be left open as it will be closed when the 
  1229                 // session can be left open as it will be closed when the 
  1222     			// callback returns.
  1230                 // callback returns.
  1223     		    graphicsBuffer.sync(false);
  1231                 graphicsBuffer.sync(false);
  1224     		}
  1232             }
  1225     		else 
  1233             else 
  1226     		{
  1234             {
  1227     			graphicsBuffer.sync(true);
  1235                 graphicsBuffer.sync(true);
  1228     		} 
  1236             } 
  1229     	}
  1237         }
  1230     }
  1238     }
  1231     
  1239     
  1232     
  1240     
  1233     /**
  1241     /**
  1234      * Return DirectGraphics associated with this instance.
  1242      * Return DirectGraphics associated with this instance.
  1241         }
  1249         }
  1242         return directGraphics;
  1250         return directGraphics;
  1243     }
  1251     }
  1244 
  1252 
  1245     /**
  1253     /**
  1246 	 * Getter for graphics buffer.
  1254      * Getter for graphics buffer.
  1247 	 * @return The Buffer.
  1255      * @return The Buffer.
  1248 	 */
  1256      */
  1249     Buffer getGraphicsBuffer()
  1257     Buffer getGraphicsBuffer()
  1250     {
  1258     {
  1251         return graphicsBuffer;
  1259         return graphicsBuffer;
  1252     }
  1260     }
  1253 	
  1261     
  1254     /**
  1262     /**
  1255      * Maps stroke style constant from values used by
  1263      * Maps stroke style constant from values used by
  1256      * Graphics to values defined in GraphicsContext
  1264      * Graphics to values defined in GraphicsContext
  1257      */
  1265      */
  1258     static int mapStrokeStyle(int strokeStyle)
  1266     static int mapStrokeStyle(int strokeStyle)