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