javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/org/eclipse/swt/internal/qt/graphics/JavaCommandBuffer.java
changeset 47 f40128debb5d
parent 26 dc7c549001d5
child 48 e0d6e9bd3ca7
equal deleted inserted replaced
35:85266cc22c7f 47:f40128debb5d
    24  * supported see the methods of this class. In principal GraphicsContext supports all draw and set operations,
    24  * supported see the methods of this class. In principal GraphicsContext supports all draw and set operations,
    25  * when JavaCommandBuffer is set as rendering target.
    25  * when JavaCommandBuffer is set as rendering target.
    26  */
    26  */
    27 public final class JavaCommandBuffer {
    27 public final class JavaCommandBuffer {
    28 
    28 
    29 	// All collected drawing operations and their parameters
    29     // All collected drawing operations and their parameters
    30 	private int[] intParams;
    30     private int[] intParams;
    31 	private int intCount;
    31     private int intCount;
    32 	private StringBuffer strParams;
    32     private StringBuffer strParams;
    33 
    33 
    34 	// Holder for images
    34     // Holder for images
    35 	private Vector images;
    35     private Vector images;
    36 
    36 
    37 	// holder for rgbData
    37     // holder for rgbData
    38 	private Vector rgbData;
    38     private Vector rgbData;
    39 
    39 
    40 	// This flag is indicates if this buffer is bound by some GraphicsContext
    40     // This flag is indicates if this buffer is bound by some GraphicsContext
    41 	private boolean bound;
    41     private boolean bound;
    42 
    42 
    43     // This flag indicates if this buffer is empty or not
    43     // This flag indicates if this buffer is empty or not
    44 	private boolean containsData;
    44     private boolean containsData;
    45 	
    45     
    46 	// This flag indicates if this buffer has any draw commands in it
    46     // This flag indicates if this buffer has any draw commands in it
    47 	private boolean containsPrimitiveData;
    47     private boolean containsPrimitiveData;
    48 
    48 
    49     // Memory management configuration constants
    49     // Memory management configuration constants
    50 	private static final int INT_BUF_GRANULARITY     	 = 10;
    50     private static final int INT_BUF_GRANULARITY         = 10;
    51 	private static final int INT_BUF_INITIAL_SIZE    	 = 250;
    51     private static final int INT_BUF_INITIAL_SIZE        = 250;
    52 	private static final int IMAGE_BUF_INITIAL_SIZE 	 = 3;
    52     private static final int IMAGE_BUF_INITIAL_SIZE      = 3;
    53 	private static final int IMAGE_BUF_GRANULARITY  	 = 2;
    53     private static final int IMAGE_BUF_GRANULARITY       = 2;
    54 	private static final int STRING_BUFFER_INITIAL_SIZE = 10;
    54     private static final int STRING_BUFFER_INITIAL_SIZE = 10;
    55 
    55 
    56 	// Prefixes for different categories of op codes, stored in MSB
    56     // Prefixes for different categories of op codes, stored in MSB
    57 	final static int DRAW_PREFIX = 0;
    57     final static int DRAW_PREFIX = 0;
    58 	final static int FILL_PREFIX = 1;
    58     final static int FILL_PREFIX = 1;
    59 	final static int SET_PREFIX = 2;
    59     final static int SET_PREFIX = 2;
    60 	final static int MISC_PREFIX = 3;
    60     final static int MISC_PREFIX = 3;
    61 
    61 
    62 	// Unique operation codes for all the gc operations that can be buffered.
    62     // Unique operation codes for all the gc operations that can be buffered.
    63 	static final int OP_DRAWARC            = ((DRAW_PREFIX << 24) | 1);
    63     static final int OP_DRAWARC            = ((DRAW_PREFIX << 24) | 1);
    64 	static final int OP_DRAWFOCUS          = ((DRAW_PREFIX << 24) | 2);
    64     static final int OP_DRAWFOCUS          = ((DRAW_PREFIX << 24) | 2);
    65 	static final int OP_DRAWIMAGE1         = ((DRAW_PREFIX << 24) | 3);
    65     static final int OP_DRAWIMAGE1         = ((DRAW_PREFIX << 24) | 3);
    66 	static final int OP_DRAWIMAGE2         = ((DRAW_PREFIX << 24) | 4);
    66     static final int OP_DRAWIMAGE2         = ((DRAW_PREFIX << 24) | 4);
    67 	static final int OP_DRAWLINE           = ((DRAW_PREFIX << 24) | 5);
    67     static final int OP_DRAWLINE           = ((DRAW_PREFIX << 24) | 5);
    68 	static final int OP_DRAWELLIPSE        = ((DRAW_PREFIX << 24) | 6);
    68     static final int OP_DRAWELLIPSE        = ((DRAW_PREFIX << 24) | 6);
    69 	static final int OP_DRAWPOINT          = ((DRAW_PREFIX << 24) | 7);
    69     static final int OP_DRAWPOINT          = ((DRAW_PREFIX << 24) | 7);
    70 	static final int OP_DRAWPOLYGON        = ((DRAW_PREFIX << 24) | 8);
    70     static final int OP_DRAWPOLYGON        = ((DRAW_PREFIX << 24) | 8);
    71 	static final int OP_DRAWPOLYLINE       = ((DRAW_PREFIX << 24) | 9);
    71     static final int OP_DRAWPOLYLINE       = ((DRAW_PREFIX << 24) | 9);
    72 	static final int OP_DRAWRECT           = ((DRAW_PREFIX << 24) | 10);
    72     static final int OP_DRAWRECT           = ((DRAW_PREFIX << 24) | 10);
    73 	static final int OP_DRAWRGB_INT        = ((DRAW_PREFIX << 24) | 11);
    73     static final int OP_DRAWRGB_INT        = ((DRAW_PREFIX << 24) | 11);
    74 	static final int OP_DRAWRGB_BYTE       = ((DRAW_PREFIX << 24) | 12);
    74     static final int OP_DRAWRGB_BYTE       = ((DRAW_PREFIX << 24) | 12);
    75 	static final int OP_DRAWRGB_SHORT      = ((DRAW_PREFIX << 24) | 13);
    75     static final int OP_DRAWRGB_SHORT      = ((DRAW_PREFIX << 24) | 13);
    76 	static final int OP_DRAWROUNDRECT      = ((DRAW_PREFIX << 24) | 14);
    76     static final int OP_DRAWROUNDRECT      = ((DRAW_PREFIX << 24) | 14);
    77 	static final int OP_DRAWSTRING         = ((DRAW_PREFIX << 24) | 15);
    77     static final int OP_DRAWSTRING         = ((DRAW_PREFIX << 24) | 15);
    78 	static final int OP_FILLARC            = ((FILL_PREFIX << 24) | 16);
    78     static final int OP_FILLARC            = ((FILL_PREFIX << 24) | 16);
    79 	static final int OP_FILLGRADIENTRECT   = ((FILL_PREFIX << 24) | 17);
    79     static final int OP_FILLGRADIENTRECT   = ((FILL_PREFIX << 24) | 17);
    80 	static final int OP_FILLELLIPSE        = ((FILL_PREFIX << 24) | 18);
    80     static final int OP_FILLELLIPSE        = ((FILL_PREFIX << 24) | 18);
    81 	static final int OP_FILLPOLYGON        = ((FILL_PREFIX << 24) | 19);
    81     static final int OP_FILLPOLYGON        = ((FILL_PREFIX << 24) | 19);
    82 	static final int OP_FILLRECT           = ((FILL_PREFIX << 24) | 20);
    82     static final int OP_FILLRECT           = ((FILL_PREFIX << 24) | 20);
    83 	static final int OP_FILLROUNDRECT      = ((FILL_PREFIX << 24) | 21);
    83     static final int OP_FILLROUNDRECT      = ((FILL_PREFIX << 24) | 21);
    84 	static final int OP_SETBACKGROUNDALPHA = ((SET_PREFIX << 24) | 22);
    84     static final int OP_SETBACKGROUNDALPHA = ((SET_PREFIX << 24) | 22);
    85 	static final int OP_SETBACKGROUNDCOLOR = ((SET_PREFIX << 24) | 23);
    85     static final int OP_SETBACKGROUNDCOLOR = ((SET_PREFIX << 24) | 23);
    86 	static final int OP_SETBLENDINGMODE    = ((SET_PREFIX << 24) | 24);
    86     static final int OP_SETBLENDINGMODE    = ((SET_PREFIX << 24) | 24);
    87 	static final int OP_SETCLIP            = ((SET_PREFIX << 24) | 25);
    87     static final int OP_SETCLIP            = ((SET_PREFIX << 24) | 25);
    88 	static final int OP_CANCELCLIPPING     = ((SET_PREFIX << 24) | 26);
    88     static final int OP_CANCELCLIPPING     = ((SET_PREFIX << 24) | 26);
    89 	static final int OP_SETFONT            = ((SET_PREFIX << 24) | 27);
    89     static final int OP_SETFONT            = ((SET_PREFIX << 24) | 27);
    90 	static final int OP_SETFOREGROUNDALPHA = ((SET_PREFIX << 24) | 28);
    90     static final int OP_SETFOREGROUNDALPHA = ((SET_PREFIX << 24) | 28);
    91 	static final int OP_SETFOREGROUNDCOLOR = ((SET_PREFIX << 24) | 29);
    91     static final int OP_SETFOREGROUNDCOLOR = ((SET_PREFIX << 24) | 29);
    92 	static final int OP_SETSTROKESTYLE     = ((SET_PREFIX << 24) | 30);
    92     static final int OP_SETSTROKESTYLE     = ((SET_PREFIX << 24) | 30);
    93 	static final int OP_SETSTROKEWIDTH     = ((SET_PREFIX << 24) | 31);
    93     static final int OP_SETSTROKEWIDTH     = ((SET_PREFIX << 24) | 31);
    94 	static final int OP_TRANSLATE          = ((MISC_PREFIX << 24) | 32);
    94     static final int OP_TRANSLATE          = ((MISC_PREFIX << 24) | 32);
    95 	static final int OP_SCALE              = ((MISC_PREFIX << 24) | 33);
    95     static final int OP_SCALE              = ((MISC_PREFIX << 24) | 33);
    96 	static final int OP_RESETTRANSFORM     = ((MISC_PREFIX << 24) | 34);
    96     static final int OP_RESETTRANSFORM     = ((MISC_PREFIX << 24) | 34);
    97 	static final int OP_COPYAREA1          = ((MISC_PREFIX << 24) | 35);
    97     static final int OP_COPYAREA1          = ((MISC_PREFIX << 24) | 35);
    98 	static final int OP_COPYAREA2          = ((MISC_PREFIX << 24) | 36);
    98     static final int OP_COPYAREA2          = ((MISC_PREFIX << 24) | 36);
    99 
    99 
   100 	/**
   100     /**
   101 	 * Constructs empty command buffer with defined buffer sizes.
   101      * Constructs empty command buffer with defined buffer sizes.
   102 	 */
   102      */
   103 	public JavaCommandBuffer() {
   103     public JavaCommandBuffer() {
   104 		intParams = new int[INT_BUF_INITIAL_SIZE];
   104         intParams = new int[INT_BUF_INITIAL_SIZE];
   105 		strParams = new StringBuffer(STRING_BUFFER_INITIAL_SIZE);
   105         strParams = new StringBuffer(STRING_BUFFER_INITIAL_SIZE);
   106 		images = new Vector(IMAGE_BUF_INITIAL_SIZE, IMAGE_BUF_GRANULARITY);
   106         images = new Vector(IMAGE_BUF_INITIAL_SIZE, IMAGE_BUF_GRANULARITY);
   107 		rgbData = new Vector(IMAGE_BUF_INITIAL_SIZE, IMAGE_BUF_GRANULARITY);
   107         rgbData = new Vector(IMAGE_BUF_INITIAL_SIZE, IMAGE_BUF_GRANULARITY);
   108 	}
   108     }
   109 
   109 
   110 	/**
   110     /**
   111 	 * Resets the buffer, i.e. removes all recorded commands and related data. The integer array containing
   111      * Resets the buffer, i.e. removes all recorded commands and related data. The integer array containing
   112 	 * the actual operation codes is not deleted, only the index pointer is rested, thus the memory consumption of that is not freed.
   112      * the actual operation codes is not deleted, only the index pointer is rested, thus the memory consumption of that is not freed.
   113 	 * CommandBuffer can be reseted only if it is not bound by any GraphicsContext
   113      * CommandBuffer can be reseted only if it is not bound by any GraphicsContext
   114 	 * @throws IllegalStateException if this CommandBuffer is bound while calling reset
   114      * @throws IllegalStateException if this CommandBuffer is bound while calling reset
   115 	 */
   115      */
   116 	public void reset() {
   116     public void reset() {
   117 		if(bound) {
   117         if(bound) {
   118 			throw new IllegalStateException("CommandBuffer is still bound by gc");
   118             throw new IllegalStateException("CommandBuffer is still bound by gc");
   119 		}
   119         }
   120 		intCount = 0;
   120         intCount = 0;
   121 		strParams.setLength(0);
   121         strParams.setLength(0);
   122 
   122 
   123 		Enumeration allImages = images.elements();
   123         Enumeration allImages = images.elements();
   124 		while(allImages.hasMoreElements()) {
   124         while(allImages.hasMoreElements()) {
   125 			Image image = (Image)allImages.nextElement();
   125             Image image = (Image)allImages.nextElement();
   126 			if(!image.isDisposed()) {
   126             if(image != null) {
   127 				image.dispose();
   127                 image.freeCommandBufferCopy();
   128 			}
   128             }
   129 		}
   129         }
   130 		images.removeAllElements();
   130         images.removeAllElements();
   131 		rgbData.removeAllElements();
   131         rgbData.removeAllElements();
   132 		containsData = false;
   132         containsData = false;
   133 		containsPrimitiveData = false;
   133         containsPrimitiveData = false;
   134 	}
   134     }
   135 
   135 
   136 	/**
   136     /**
   137 	 * Checks that does this buffer contain any commands
   137      * Checks that does this buffer contain any commands
   138 	 * @return true if any command has been written to buffer otherwise false
   138      * @return true if any command has been written to buffer otherwise false
   139 	 */
   139      */
   140 	public boolean containsData() {
   140     public boolean containsData() {
   141 		return containsData;
   141         return containsData;
   142 	}
   142     }
   143 	
   143     
   144 	/**
   144     /**
   145 	 * Checks that does this buffer contain any draw commands, i.e. any setters etc. 
   145      * Checks that does this buffer contain any draw commands, i.e. any setters etc. 
   146 	 * that does to cause any pixels to be rendered are ignored 
   146      * that does to cause any pixels to be rendered are ignored 
   147 	 * @return true if any draw command has been written to buffer otherwise false
   147      * @return true if any draw command has been written to buffer otherwise false
   148 	 */
   148      */
   149 	public boolean containsDrawnPrimitives() {
   149     public boolean containsDrawnPrimitives() {
   150 		return containsPrimitiveData;
   150         return containsPrimitiveData;
   151 	}
   151     }
   152 	
   152     
   153 	/**
   153     /**
   154 	 * Binds this buffer
   154      * Binds this buffer
   155 	 */
   155      */
   156 	void bind() {
   156     void bind() {
   157 		bound = true;
   157         bound = true;
   158 	}
   158     }
   159 
   159 
   160 	/**
   160     /**
   161 	 * Provides the binding status of this buffer
   161      * Provides the binding status of this buffer
   162 	 * @return true if this buffer has been already bound otherwise false
   162      * @return true if this buffer has been already bound otherwise false
   163 	 */
   163      */
   164 	boolean isBound() {
   164     boolean isBound() {
   165 		return bound;
   165         return bound;
   166 	}
   166     }
   167 
   167 
   168 	/**
   168     /**
   169 	 * Releases this buffer, i.e. it can be bound by some other GraphicsContext
   169      * Releases this buffer, i.e. it can be bound by some other GraphicsContext
   170 	 */
   170      */
   171 	void release() {
   171     void release() {
   172 		bound = false;
   172         bound = false;
   173 	}
   173     }
   174 
   174 
   175 	/**
   175     /**
   176 	 * Writes an integer to given array.
   176      * Writes an integer to given array.
   177 	 * @param item The item to be added to the array
   177      * @param item The item to be added to the array
   178 	 * @param array The array where to append given item
   178      * @param array The array where to append given item
   179 	 * @param elementsUsed The size of slots used in given array
   179      * @param elementsUsed The size of slots used in given array
   180 	 * @param granularity The granularity used if the array needs to be enlarged
   180      * @param granularity The granularity used if the array needs to be enlarged
   181 	 * @return Array containing the added item
   181      * @return Array containing the added item
   182 	 */
   182      */
   183 	private int[] writeToArray(int item, int[] array, int elementsUsed, int granularity) {
   183     private int[] writeToArray(int item, int[] array, int elementsUsed, int granularity) {
   184 		if( array.length < elementsUsed + 1) {
   184         if( array.length < elementsUsed + 1) {
   185 			int[] src = array;
   185             int[] src = array;
   186 			int[] dst = new int[array.length + granularity];
   186             int[] dst = new int[array.length + granularity];
   187 			System.arraycopy(src, 0, dst, 0, src.length);
   187             System.arraycopy(src, 0, dst, 0, src.length);
   188 			array = dst;
   188             array = dst;
   189 		}
   189         }
   190 		array[elementsUsed] = item;
   190         array[elementsUsed] = item;
   191 		return array;
   191         return array;
   192 	}
   192     }
   193 
   193 
   194 	private void writeInt(int param) {
   194     private void writeInt(int param) {
   195 		intParams = writeToArray(param, intParams, intCount++, INT_BUF_GRANULARITY);
   195         intParams = writeToArray(param, intParams, intCount++, INT_BUF_GRANULARITY);
   196 		containsData = true;
   196         containsData = true;
   197 	}
   197     }
   198 
   198 
   199 	private void writeImage(Image image) {
   199     private void writeImage(Image image) {
   200 		images.addElement(image);
   200         images.addElement(image);
   201 	}
   201     }
   202 
   202 
   203 	private void writeStr(String string) {
   203     private void writeStr(String string) {
   204     	strParams.append(string);
   204         strParams.append(string);
   205 	}
   205     }
   206 
   206 
   207 	private void writeRgb(int[] rgb) {
   207     private void writeRgb(int[] rgb) {
   208 		rgbData.addElement(rgb);
   208         rgbData.addElement(rgb);
   209 	}
   209     }
   210 	private void writeRgb(byte[] rgb) {
   210     private void writeRgb(byte[] rgb) {
   211 		rgbData.addElement(rgb);
   211         rgbData.addElement(rgb);
   212 	}
   212     }
   213 
   213 
   214 	private void writeRgb(short[] rgb) {
   214     private void writeRgb(short[] rgb) {
   215 		rgbData.addElement(rgb);
   215         rgbData.addElement(rgb);
   216 	}
   216     }
   217 
   217 
   218 	private void reportNotSupported() {
   218     private void reportNotSupported() {
   219 		throw new RuntimeException("Intenal: Operation not supported with JavaCommandBuffer");
   219         throw new RuntimeException("Intenal: Operation not supported with JavaCommandBuffer");
   220 	}
   220     }
   221 
   221 
   222 	private void printBufferInfo() {
   222     private void printBufferInfo() {
   223 		System.out.println("CommandBuffer Info: " +this);
   223         System.out.println("CommandBuffer Info: " +this);
   224 		System.out.println("intParamCount: " + intCount);
   224         System.out.println("intParamCount: " + intCount);
   225 		System.out.println("intBuffer Size: " + intParams.length);
   225         System.out.println("intBuffer Size: " + intParams.length);
   226 		System.out.println("StringBuffer Size: " + strParams.length());
   226         System.out.println("StringBuffer Size: " + strParams.length());
   227 	}
   227     }
   228 
   228 
   229 	private void raisePrimitiveFlag() {
   229     private void raisePrimitiveFlag() {
   230 		containsPrimitiveData = true;
   230         containsPrimitiveData = true;
   231 	}
   231     }
   232 	
   232     
   233 	int[] intParams() {
   233     int[] intParams() {
   234 		return intParams;
   234         return intParams;
   235 	}
   235     }
   236 
   236 
   237 	int intParamCount() {
   237     int intParamCount() {
   238         return intCount;
   238         return intCount;
   239 	}
   239     }
   240 
   240 
   241 	Vector rgbParams() {
   241     Vector rgbParams() {
   242 		return rgbData;
   242         return rgbData;
   243 	}
   243     }
   244 
   244 
   245 	Vector images() {
   245     Vector images() {
   246 		return images;
   246         return images;
   247 	}
   247     }
   248 
   248 
   249 	String strParams() {
   249     String strParams() {
   250 		return strParams.toString();
   250         return strParams.toString();
   251 	}
   251     }
   252 
   252 
   253 	void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
   253     void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
   254 		writeInt(OP_DRAWARC);
   254         writeInt(OP_DRAWARC);
   255 		writeInt(x);
   255         writeInt(x);
   256 		writeInt(y);
   256         writeInt(y);
   257 		writeInt(width);
   257         writeInt(width);
   258 		writeInt(height);
   258         writeInt(height);
   259 		writeInt(startAngle);
   259         writeInt(startAngle);
   260 		writeInt(arcAngle);
   260         writeInt(arcAngle);
   261 		raisePrimitiveFlag();
   261         raisePrimitiveFlag();
   262 	}
   262     }
   263 
   263 
   264 	void drawFocus (int x, int y, int width, int height) {
   264     void drawFocus (int x, int y, int width, int height) {
   265 		writeInt(OP_DRAWFOCUS);
   265         writeInt(OP_DRAWFOCUS);
   266 		writeInt(x);
   266         writeInt(x);
   267 		writeInt(y);
   267         writeInt(y);
   268 		writeInt(width);
   268         writeInt(width);
   269 		writeInt(height);
   269         writeInt(height);
   270 		raisePrimitiveFlag();
   270         raisePrimitiveFlag();
   271 	}
   271     }
   272 
   272 
   273 	// must be called from UI thread as images cannot be creates outside that
   273     // must be called from UI thread as images cannot be creates outside that
   274 	void drawImage(Image image, int x, int y) {
   274     void drawImage(Image image, int x, int y) {
   275 		writeInt(OP_DRAWIMAGE1);
   275         writeInt(OP_DRAWIMAGE1);
   276 		writeInt(x);
   276         writeInt(x);
   277 		writeInt(y);
   277         writeInt(y);
   278 		// creating copy of image here uses implicit data sharing,
   278         // creating copy of image here uses implicit data sharing,
   279 		// thus only a shallow copy is made
   279         // thus only a shallow copy is made
   280 		writeImage(new Image(image));
   280         writeImage(image.getCommandBufferCopy());
   281 		raisePrimitiveFlag();
   281         raisePrimitiveFlag();
   282 	}
   282     }
   283 
   283 
   284 	// must be called from UI thread as images cannot be creates outside that
   284     // must be called from UI thread as images cannot be creates outside that
   285 	void drawImage(Image image, int tx, int ty, int tw, int th,int sx, int sy, int sw, int sh, int manipulation) {
   285     void drawImage(Image image, int tx, int ty, int tw, int th,int sx, int sy, int sw, int sh, int manipulation) {
   286 		writeInt(OP_DRAWIMAGE2);
   286         writeInt(OP_DRAWIMAGE2);
   287 		writeInt(tx);
   287         writeInt(tx);
   288 		writeInt(ty);
   288         writeInt(ty);
   289 		writeInt(tw);
   289         writeInt(tw);
   290 		writeInt(th);
   290         writeInt(th);
   291 		writeInt(sx);
   291         writeInt(sx);
   292 		writeInt(sy);
   292         writeInt(sy);
   293 		writeInt(sw);
   293         writeInt(sw);
   294 		writeInt(sh);
   294         writeInt(sh);
   295 		writeInt(manipulation);
   295         writeInt(manipulation);
   296 		// creating copy of image here uses implicit data sharing,
   296         // creating copy of image here uses implicit data sharing,
   297 		// thus only a shallow copy is made
   297         // thus only a shallow copy is made
   298 		writeImage(new Image(image));
   298         writeImage(image.getCommandBufferCopy());
   299 		raisePrimitiveFlag();
   299         raisePrimitiveFlag();
   300 	}
   300     }
   301 
   301 
   302 	void drawLine (int x1, int y1, int x2, int y2) {
   302     void drawLine (int x1, int y1, int x2, int y2) {
   303 		writeInt(OP_DRAWLINE);
   303         writeInt(OP_DRAWLINE);
   304 		writeInt(x1);
   304         writeInt(x1);
   305 		writeInt(y1);
   305         writeInt(y1);
   306 		writeInt(x2);
   306         writeInt(x2);
   307 		writeInt(y2);
   307         writeInt(y2);
   308 		raisePrimitiveFlag();
   308         raisePrimitiveFlag();
   309 	}
   309     }
   310 
   310 
   311 	void drawEllipse (int x, int y, int width, int height) {
   311     void drawEllipse (int x, int y, int width, int height) {
   312 		writeInt(OP_DRAWELLIPSE);
   312         writeInt(OP_DRAWELLIPSE);
   313 		writeInt(x);
   313         writeInt(x);
   314 		writeInt(y);
   314         writeInt(y);
   315 		writeInt(width);
   315         writeInt(width);
   316 		writeInt(height);
   316         writeInt(height);
   317 		raisePrimitiveFlag();
   317         raisePrimitiveFlag();
   318 	}
   318     }
   319 
   319 
   320 	void drawPoint (int x, int y) {
   320     void drawPoint (int x, int y) {
   321 		writeInt(OP_DRAWPOINT);
   321         writeInt(OP_DRAWPOINT);
   322 		writeInt(x);
   322         writeInt(x);
   323 		writeInt(y);
   323         writeInt(y);
   324 		raisePrimitiveFlag();
   324         raisePrimitiveFlag();
   325 	}
   325     }
   326 
   326 
   327 	void drawPolygon(int[] pointArray) {
   327     void drawPolygon(int[] pointArray) {
   328 		writeInt(OP_DRAWPOLYGON);
   328         writeInt(OP_DRAWPOLYGON);
   329 		writeInt(pointArray.length);
   329         writeInt(pointArray.length);
   330 		for(int i = 0; i < pointArray.length; ++i) {
   330         for(int i = 0; i < pointArray.length; ++i) {
   331 			writeInt(pointArray[i]);
   331             writeInt(pointArray[i]);
   332 		}
   332         }
   333 		raisePrimitiveFlag();
   333         raisePrimitiveFlag();
   334 	}
   334     }
   335 
   335 
   336 	void drawPolyline(int[] pointArray) {
   336     void drawPolyline(int[] pointArray) {
   337 		writeInt(OP_DRAWPOLYLINE);
   337         writeInt(OP_DRAWPOLYLINE);
   338 		writeInt(pointArray.length);
   338         writeInt(pointArray.length);
   339 		for(int i = 0; i < pointArray.length; ++i) {
   339         for(int i = 0; i < pointArray.length; ++i) {
   340 			writeInt(pointArray[i]);
   340             writeInt(pointArray[i]);
   341 		}
   341         }
   342 		raisePrimitiveFlag();
   342         raisePrimitiveFlag();
   343 	}
   343     }
   344 
   344 
   345 	void drawRect (int x, int y, int width, int height) {
   345     void drawRect (int x, int y, int width, int height) {
   346 		writeInt(OP_DRAWRECT);
   346         writeInt(OP_DRAWRECT);
   347 		writeInt(x);
   347         writeInt(x);
   348 		writeInt(y);
   348         writeInt(y);
   349 		writeInt(width);
   349         writeInt(width);
   350 		writeInt(height);
   350         writeInt(height);
   351 		raisePrimitiveFlag();
   351         raisePrimitiveFlag();
   352 	}
   352     }
   353 
   353 
   354 	void drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha, int manipulation) {
   354     void drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha, int manipulation) {
   355 		writeInt(OP_DRAWRGB_INT);
   355         writeInt(OP_DRAWRGB_INT);
   356 		writeInt(offset);
   356         writeInt(offset);
   357 		writeInt(scanlength);
   357         writeInt(scanlength);
   358 		writeInt(x);
   358         writeInt(x);
   359 		writeInt(y);
   359         writeInt(y);
   360 		writeInt(width);
   360         writeInt(width);
   361 		writeInt(height);
   361         writeInt(height);
   362 		writeInt(processAlpha? 1 : 0);
   362         writeInt(processAlpha? 1 : 0);
   363 		writeInt(manipulation);
   363         writeInt(manipulation);
   364 		writeRgb(rgbData);
   364         writeRgb(rgbData);
   365 		raisePrimitiveFlag();
   365         raisePrimitiveFlag();
   366 	}
   366     }
   367 
   367 
   368 	void drawRGB(byte[] rgbData, byte[] transparencyMask,int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format) {
   368     void drawRGB(byte[] rgbData, byte[] transparencyMask,int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format) {
   369 		writeInt(OP_DRAWRGB_BYTE);
   369         writeInt(OP_DRAWRGB_BYTE);
   370 		writeInt(offset);
   370         writeInt(offset);
   371 		writeInt(scanlength);
   371         writeInt(scanlength);
   372 		writeInt(x);
   372         writeInt(x);
   373 		writeInt(y);
   373         writeInt(y);
   374 		writeInt(width);
   374         writeInt(width);
   375 		writeInt(height);
   375         writeInt(height);
   376 		writeInt(manipulation);
   376         writeInt(manipulation);
   377 		writeInt(format);
   377         writeInt(format);
   378 		writeRgb(rgbData);
   378         writeRgb(rgbData);
   379 		writeRgb(transparencyMask);
   379         writeRgb(transparencyMask);
   380 		raisePrimitiveFlag();
   380         raisePrimitiveFlag();
   381 	}
   381     }
   382 
   382 
   383 	void drawRGB(short[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha, int manipulation, int format) {
   383     void drawRGB(short[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha, int manipulation, int format) {
   384 		writeInt(OP_DRAWRGB_SHORT);
   384         writeInt(OP_DRAWRGB_SHORT);
   385 		writeInt(offset);
   385         writeInt(offset);
   386 		writeInt(scanlength);
   386         writeInt(scanlength);
   387 		writeInt(x);
   387         writeInt(x);
   388 		writeInt(y);
   388         writeInt(y);
   389 		writeInt(width);
   389         writeInt(width);
   390 		writeInt(height);
   390         writeInt(height);
   391 		writeInt(processAlpha? 1 : 0);
   391         writeInt(processAlpha? 1 : 0);
   392 		writeInt(manipulation);
   392         writeInt(manipulation);
   393 		writeInt(format);
   393         writeInt(format);
   394 		writeRgb(rgbData);
   394         writeRgb(rgbData);
   395 		raisePrimitiveFlag();
   395         raisePrimitiveFlag();
   396 	}
   396     }
   397 
   397 
   398 	void drawRoundRect (int x, int y, int width, int height, int arcWidth, int arcHeight) {
   398     void drawRoundRect (int x, int y, int width, int height, int arcWidth, int arcHeight) {
   399 		writeInt(OP_DRAWROUNDRECT);
   399         writeInt(OP_DRAWROUNDRECT);
   400 		writeInt(x);
   400         writeInt(x);
   401 		writeInt(y);
   401         writeInt(y);
   402 		writeInt(width);
   402         writeInt(width);
   403 		writeInt(height);
   403         writeInt(height);
   404 		writeInt(arcWidth);
   404         writeInt(arcWidth);
   405 		writeInt(arcHeight);
   405         writeInt(arcHeight);
   406 		raisePrimitiveFlag();
   406         raisePrimitiveFlag();
   407 	}
   407     }
   408 
   408 
   409 	void drawString(String string, int x, int y, int width, int height, int alignments, int flags, boolean isTransparent) {
   409     void drawString(String string, int x, int y, int width, int height, int alignments, int flags, boolean isTransparent) {
   410 		writeInt(OP_DRAWSTRING);
   410         writeInt(OP_DRAWSTRING);
   411 		writeStr(string);
   411         writeStr(string);
   412 		writeInt(string.length());
   412         writeInt(string.length());
   413 		writeInt(x);
   413         writeInt(x);
   414 		writeInt(y);
   414         writeInt(y);
   415 		writeInt(width);
   415         writeInt(width);
   416 		writeInt(height);
   416         writeInt(height);
   417 		writeInt(alignments);
   417         writeInt(alignments);
   418 		writeInt(flags);
   418         writeInt(flags);
   419 		writeInt(isTransparent? 1 : 0);
   419         writeInt(isTransparent? 1 : 0);
   420 		raisePrimitiveFlag();
   420         raisePrimitiveFlag();
   421 	}
   421     }
   422 
   422 
   423 	void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
   423     void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
   424 		writeInt(OP_FILLARC);
   424         writeInt(OP_FILLARC);
   425 		writeInt(x);
   425         writeInt(x);
   426 		writeInt(y);
   426         writeInt(y);
   427 		writeInt(width);
   427         writeInt(width);
   428 		writeInt(height);
   428         writeInt(height);
   429 		writeInt(startAngle);
   429         writeInt(startAngle);
   430 		writeInt(arcAngle);
   430         writeInt(arcAngle);
   431 		raisePrimitiveFlag();
   431         raisePrimitiveFlag();
   432 	}
   432     }
   433 
   433 
   434 	void fillGradientRect(int x, int y, int width, int height, boolean vertical, boolean swapColors) {
   434     void fillGradientRect(int x, int y, int width, int height, boolean vertical, boolean swapColors) {
   435 		writeInt(OP_FILLGRADIENTRECT);
   435         writeInt(OP_FILLGRADIENTRECT);
   436 		writeInt(x);
   436         writeInt(x);
   437 		writeInt(y);
   437         writeInt(y);
   438 		writeInt(width);
   438         writeInt(width);
   439 		writeInt(height);
   439         writeInt(height);
   440 		writeInt(vertical ? 1 : 0);
   440         writeInt(vertical ? 1 : 0);
   441 		writeInt(swapColors ? 1 : 0);
   441         writeInt(swapColors ? 1 : 0);
   442 		raisePrimitiveFlag();
   442         raisePrimitiveFlag();
   443 	}
   443     }
   444 
   444 
   445 	void fillEllipse (int x, int y, int width, int height) {
   445     void fillEllipse (int x, int y, int width, int height) {
   446 		writeInt(OP_FILLELLIPSE);
   446         writeInt(OP_FILLELLIPSE);
   447 		writeInt(x);
   447         writeInt(x);
   448 		writeInt(y);
   448         writeInt(y);
   449 		writeInt(width);
   449         writeInt(width);
   450 		writeInt(height);
   450         writeInt(height);
   451 		raisePrimitiveFlag();
   451         raisePrimitiveFlag();
   452 	}
   452     }
   453 
   453 
   454 	void fillPolygon (int[] pointArray) {
   454     void fillPolygon (int[] pointArray) {
   455 		writeInt(OP_FILLPOLYGON);
   455         writeInt(OP_FILLPOLYGON);
   456 		writeInt(pointArray.length);
   456         writeInt(pointArray.length);
   457 		for(int i = 0; i < pointArray.length; ++i) {
   457         for(int i = 0; i < pointArray.length; ++i) {
   458 			writeInt(pointArray[i]);
   458             writeInt(pointArray[i]);
   459 		}
   459         }
   460 		raisePrimitiveFlag();
   460         raisePrimitiveFlag();
   461 	}
   461     }
   462 
   462 
   463 	void fillRect (int x, int y, int width, int height) {
   463     void fillRect (int x, int y, int width, int height) {
   464 		writeInt(OP_FILLRECT);
   464         writeInt(OP_FILLRECT);
   465 		writeInt(x);
   465         writeInt(x);
   466 		writeInt(y);
   466         writeInt(y);
   467 		writeInt(width);
   467         writeInt(width);
   468 		writeInt(height);
   468         writeInt(height);
   469 		raisePrimitiveFlag();
   469         raisePrimitiveFlag();
   470 	}
   470     }
   471 
   471 
   472 	void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
   472     void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
   473 		writeInt(OP_FILLROUNDRECT);
   473         writeInt(OP_FILLROUNDRECT);
   474 		writeInt(x);
   474         writeInt(x);
   475 		writeInt(y);
   475         writeInt(y);
   476 		writeInt(width);
   476         writeInt(width);
   477 		writeInt(height);
   477         writeInt(height);
   478 		writeInt(arcWidth);
   478         writeInt(arcWidth);
   479 		writeInt(arcHeight);
   479         writeInt(arcHeight);
   480 		raisePrimitiveFlag();
   480         raisePrimitiveFlag();
   481 	}
   481     }
   482 
   482 
   483 	public void setBackgroundAlpha(int alpha) {
   483     public void setBackgroundAlpha(int alpha) {
   484 		writeInt(OP_SETBACKGROUNDALPHA);
   484         writeInt(OP_SETBACKGROUNDALPHA);
   485 		writeInt(alpha);
   485         writeInt(alpha);
   486 	}
   486     }
   487 
   487 
   488 	void setBackgroundColor(int argb, boolean updateAlpha) {
   488     void setBackgroundColor(int argb, boolean updateAlpha) {
   489 		writeInt(OP_SETBACKGROUNDCOLOR);
   489         writeInt(OP_SETBACKGROUNDCOLOR);
   490 		writeInt(argb);
   490         writeInt(argb);
   491 		writeInt(updateAlpha? 1 : 0);
   491         writeInt(updateAlpha? 1 : 0);
   492 	}
   492     }
   493 
   493 
   494 	void setBlendingMode(int mode) {
   494     void setBlendingMode(int mode) {
   495 		writeInt(OP_SETBLENDINGMODE);
   495         writeInt(OP_SETBLENDINGMODE);
   496 		writeInt(mode);
   496         writeInt(mode);
   497 	}
   497     }
   498 
   498 
   499 	void setClip(int x, int y, int width, int height, boolean intersects) {
   499     void setClip(int x, int y, int width, int height, boolean intersects) {
   500 		writeInt(OP_SETCLIP);
   500         writeInt(OP_SETCLIP);
   501 		writeInt(x);
   501         writeInt(x);
   502 		writeInt(y);
   502         writeInt(y);
   503 		writeInt(width);
   503         writeInt(width);
   504 		writeInt(height);
   504         writeInt(height);
   505 		writeInt(intersects? 1 : 0 );
   505         writeInt(intersects? 1 : 0 );
   506 	}
   506     }
   507 
   507 
   508 	void cancelClipping () {
   508     void cancelClipping () {
   509 		writeInt(OP_CANCELCLIPPING);
   509         writeInt(OP_CANCELCLIPPING);
   510 	}
   510     }
   511 
   511 
   512 	void setFont(int fontHandle) {
   512     void setFont(int fontHandle) {
   513 		writeInt(OP_SETFONT);
   513         writeInt(OP_SETFONT);
   514 		writeInt(fontHandle);
   514         writeInt(fontHandle);
   515 	}
   515     }
   516 
   516 
   517 	void setForegroundAlpha(int alpha) {
   517     void setForegroundAlpha(int alpha) {
   518 		writeInt(OP_SETFOREGROUNDALPHA);
   518         writeInt(OP_SETFOREGROUNDALPHA);
   519 		writeInt(alpha);
   519         writeInt(alpha);
   520 	}
   520     }
   521 
   521 
   522 	void setForegroundColor(int argb, boolean updateAlpha) {
   522     void setForegroundColor(int argb, boolean updateAlpha) {
   523 		writeInt(OP_SETFOREGROUNDCOLOR);
   523         writeInt(OP_SETFOREGROUNDCOLOR);
   524 		writeInt(argb);
   524         writeInt(argb);
   525 		writeInt(updateAlpha? 1 : 0);
   525         writeInt(updateAlpha? 1 : 0);
   526 	}
   526     }
   527 
   527 
   528 	void setStrokeStyle(int style) {
   528     void setStrokeStyle(int style) {
   529 		writeInt(OP_SETSTROKESTYLE);
   529         writeInt(OP_SETSTROKESTYLE);
   530 		writeInt(style);
   530         writeInt(style);
   531 	}
   531     }
   532 
   532 
   533 	void setStrokeWidth(int width) {
   533     void setStrokeWidth(int width) {
   534 		writeInt(OP_SETSTROKEWIDTH);
   534         writeInt(OP_SETSTROKEWIDTH);
   535 		writeInt(width);
   535         writeInt(width);
   536 	}
   536     }
   537 
   537 
   538 	void translate(int x, int y) {
   538     void translate(int x, int y) {
   539 		writeInt(OP_TRANSLATE);
   539         writeInt(OP_TRANSLATE);
   540 		writeInt(x);
   540         writeInt(x);
   541 		writeInt(y);
   541         writeInt(y);
   542 	}
   542     }
   543 
   543 
   544 	void scale(int x, int y) {
   544     void scale(int x, int y) {
   545 		writeInt(OP_SCALE);
   545         writeInt(OP_SCALE);
   546 		writeInt(x);
   546         writeInt(x);
   547 		writeInt(y);
   547         writeInt(y);
   548 	}
   548     }
   549 
   549 
   550 	void resetTransform() {
   550     void resetTransform() {
   551 		writeInt(OP_RESETTRANSFORM);
   551         writeInt(OP_RESETTRANSFORM);
   552 	}
   552     }
   553 
   553 
   554 	void copyArea(Image image, int x, int y) {
   554     void copyArea(Image image, int x, int y) {
   555 		writeInt(OP_COPYAREA1);
   555         writeInt(OP_COPYAREA1);
   556         writeInt(x);
   556         writeInt(x);
   557         writeInt(y);
   557         writeInt(y);
   558         // TODO does this need flushing on the image
   558         // TODO does this need flushing on the image
   559         images.addElement(new Image(image));
   559         images.addElement(new Image(image));
   560         raisePrimitiveFlag();
   560         raisePrimitiveFlag();
   561     }
   561     }
   562 
   562 
   563 	void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
   563     void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
   564         writeInt(OP_COPYAREA2);
   564         writeInt(OP_COPYAREA2);
   565         writeInt(srcX);
   565         writeInt(srcX);
   566         writeInt(srcY);
   566         writeInt(srcY);
   567         writeInt(width);
   567         writeInt(width);
   568         writeInt(height);
   568         writeInt(height);
   570         writeInt(destY);
   570         writeInt(destY);
   571         writeInt(paint? 1 : 0);
   571         writeInt(paint? 1 : 0);
   572         raisePrimitiveFlag();
   572         raisePrimitiveFlag();
   573     }
   573     }
   574 
   574 
   575 	// Unsupported operations
   575     // Unsupported operations
   576 	int getAdvancedCharacterWidth(char ch, boolean isAdvanced) {
   576     int getAdvancedCharacterWidth(char ch, boolean isAdvanced) {
   577 		reportNotSupported();
   577         reportNotSupported();
   578 		return 0;
   578         return 0;
   579 	}
   579     }
   580 
   580 
   581 	void getFontMetricsData(int[] data, int fontHandle) {
   581     void getFontMetricsData(int[] data, int fontHandle) {
   582 		reportNotSupported();
   582         reportNotSupported();
   583 	}
   583     }
   584 
   584 
   585 	int getBackgroundAlpha() {
   585     int getBackgroundAlpha() {
   586 		reportNotSupported();
   586         reportNotSupported();
   587 		return 0;
   587         return 0;
   588 	}
   588     }
   589 
   589 
   590 	int getBackgroundColor() {
   590     int getBackgroundColor() {
   591 		reportNotSupported();
   591         reportNotSupported();
   592 		return 0;
   592         return 0;
   593 	}
   593     }
   594 
   594 
   595 	int getBlendingMode() {
   595     int getBlendingMode() {
   596 		reportNotSupported();
   596         reportNotSupported();
   597 		return 0;
   597         return 0;
   598 	}
   598     }
   599 
   599 
   600 	void getClip(int[] clip) {
   600     void getClip(int[] clip) {
   601 		reportNotSupported();
   601         reportNotSupported();
   602 	}
   602     }
   603 
   603 
   604 	int getForegroundAlpha() {
   604     int getForegroundAlpha() {
   605 		reportNotSupported();
   605         reportNotSupported();
   606 		return 0;
   606         return 0;
   607 	}
   607     }
   608 
   608 
   609 	int getForegroundColor() {
   609     int getForegroundColor() {
   610 		reportNotSupported();
   610         reportNotSupported();
   611 		return 0;
   611         return 0;
   612 	}
   612     }
   613 
   613 
   614 	void getTextBoundingBox(int[] boundingBox, String string, int alignments, int flags, int rectX, int rectY, int rectWidth, int rectHeight) {
   614     void getTextBoundingBox(int[] boundingBox, String string, int alignments, int flags, int rectX, int rectY, int rectWidth, int rectHeight) {
   615 		reportNotSupported();
   615         reportNotSupported();
   616 	}
   616     }
   617 
   617 
   618 	int getStrokeWidth() {
   618     int getStrokeWidth() {
   619 		reportNotSupported();
   619         reportNotSupported();
   620 		return 0;
   620         return 0;
   621 	}
   621     }
   622 
   622 
   623 	int getStrokeStyle() {
   623     int getStrokeStyle() {
   624 		reportNotSupported();
   624         reportNotSupported();
   625 		return 0;
   625         return 0;
   626 	}
   626     }
   627 
   627 
   628 	int getTranslateX() {
   628     int getTranslateX() {
   629 		reportNotSupported();
   629         reportNotSupported();
   630 		return 0;
   630         return 0;
   631 	}
   631     }
   632 
   632 
   633 	int getTranslateY() {
   633     int getTranslateY() {
   634 		reportNotSupported();
   634         reportNotSupported();
   635 		return 0;
   635         return 0;
   636 	}
   636     }
   637 
   637 
   638 	boolean hasClipping() {
   638     boolean hasClipping() {
   639 		reportNotSupported();
   639         reportNotSupported();
   640 		return false;
   640         return false;
   641 	}
   641     }
   642 
   642 
   643 	void saveSettings() {
   643     void saveSettings() {
   644 		reportNotSupported();
   644         reportNotSupported();
   645 	}
   645     }
   646 
   646 
   647 	void restoreSettings() {
   647     void restoreSettings() {
   648 		reportNotSupported();
   648         reportNotSupported();
   649 	}
   649     }
   650 
   650 
   651 
   651 
   652 
   652 
   653 }
   653 }