javauis/lcdui_qt/src/javax/microedition/lcdui/Graphics.java
branchRCL_3
changeset 65 ae942d28ec0e
equal deleted inserted replaced
60:6c158198356e 65:ae942d28ec0e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 package javax.microedition.lcdui;
       
    18 
       
    19 
       
    20 import org.eclipse.swt.graphics.Internal_GfxPackageSupport;
       
    21 import org.eclipse.swt.graphics.Rectangle;
       
    22 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
       
    23 
       
    24 import org.eclipse.swt.internal.qt.graphics.FontUtils;
       
    25 
       
    26 import com.nokia.mid.ui.DirectGraphics;
       
    27 
       
    28 /**
       
    29  * Implementation of LCDUI <code>Graphics</code> class.
       
    30  */
       
    31 public class Graphics
       
    32 {
       
    33 
       
    34     /**
       
    35      * Constant for horizontal center alignment of the text.
       
    36      */
       
    37     public static final int HCENTER = 1;
       
    38 
       
    39     /**
       
    40      * Constant for vertical alignment of the image.
       
    41      */
       
    42     public static final int VCENTER = 2;
       
    43 
       
    44     /**
       
    45      * Constant for horizontal left alignment of the text.
       
    46      */
       
    47     public static final int LEFT = 4;
       
    48 
       
    49     /**
       
    50      * Constant for horizontal right alignment of the text.
       
    51      */
       
    52     public static final int RIGHT = 8;
       
    53 
       
    54     /**
       
    55      * Constant for vertical top alignment of the text.
       
    56      */
       
    57     public static final int TOP = 16;
       
    58 
       
    59     /**
       
    60      * Constant for vertical bottom alignment of the text.
       
    61      */
       
    62     public static final int BOTTOM = 32;
       
    63 
       
    64     /**
       
    65      * Constant for vertical baseline alignment of the text.
       
    66      */
       
    67     public static final int BASELINE = 64;
       
    68 
       
    69     /**
       
    70      * Constant for solid stroke style.
       
    71      */
       
    72     public static final int SOLID = 0;
       
    73 
       
    74     /**
       
    75      * Constant for dotted stroke style.
       
    76      */
       
    77     public static final int DOTTED = 1;
       
    78 
       
    79     static final int INVALID_STROKE_STYLE = -1;
       
    80 
       
    81     static final int RGB_MASK = 0x00FFFFFF;
       
    82 
       
    83     static final int OPAQUE_ALPHA = 0xff000000;
       
    84 
       
    85     static final int COMPONENT_MASK = 0xFF;
       
    86 
       
    87     /**
       
    88      * Constants for sync strategy
       
    89      */
       
    90     static final int SYNC_LEAVE_SURFACE_SESSION_CLOSED = 10;
       
    91     static final int SYNC_LEAVE_SURFACE_SESSION_OPEN = 11;
       
    92     
       
    93     // Set default sync strategy as closed
       
    94     private int syncStrategy = SYNC_LEAVE_SURFACE_SESSION_CLOSED; 
       
    95     
       
    96     private DirectGraphics directGraphics;
       
    97     private Buffer graphicsBuffer;
       
    98     
       
    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
       
   104     Font currentFont;
       
   105     int currentColor;
       
   106     int translateX;
       
   107     int translateY;
       
   108     int[] currentClip = new int[4];
       
   109     int currentStrokeStyle;
       
   110     
       
   111     private com.nokia.mj.impl.rt.support.Finalizer finalizer;
       
   112 
       
   113     //Constructor
       
   114     Graphics(Buffer buffer, Rectangle clipRect)
       
   115     {
       
   116         finalizer = ((finalizer != null) ? finalizer
       
   117                      : new com.nokia.mj.impl.rt.support.Finalizer()
       
   118         {
       
   119             public void finalizeImpl()
       
   120             {
       
   121                 if(finalizer != null)
       
   122                 {
       
   123                     finalizer = null;
       
   124                     if(!ESWTUIThreadRunner.isDisposed())
       
   125                     {
       
   126                         ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
   127                         {
       
   128                             public void run()
       
   129                             {
       
   130                                 dispose();
       
   131                             }
       
   132                         });
       
   133 
       
   134                     }
       
   135                 }
       
   136             }
       
   137         });
       
   138         currentClip[0] = clipRect.x;
       
   139         currentClip[1] = clipRect.y;
       
   140         currentClip[2] = clipRect.width;
       
   141         currentClip[3] = clipRect.height;
       
   142         setDefaultSettings();
       
   143         graphicsBuffer = buffer;
       
   144     }
       
   145 
       
   146 
       
   147 
       
   148     /**
       
   149      * Disposes objects with native counterparts
       
   150      */
       
   151     void dispose()
       
   152     {
       
   153         synchronized(graphicsBuffer)
       
   154         {
       
   155             graphicsBuffer.removeRef();
       
   156         }
       
   157     }
       
   158 
       
   159     /**
       
   160      * Resets Graphics state to initial.
       
   161      * Reset does not set the clip.
       
   162      */
       
   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() 
       
   176     {
       
   177         currentFont = Buffer.defaultFont;
       
   178         currentColor = Buffer.defaultColor;
       
   179         currentStrokeStyle = Buffer.defaultStrokeStyle;
       
   180         translateX = Buffer.defaultTranslateX;
       
   181         translateY = Buffer.defaultTranslateY;
       
   182     }
       
   183     
       
   184     /**
       
   185      * Cleans the Canvas background.
       
   186      */
       
   187     void cleanBackground(Rectangle area)
       
   188     {
       
   189         int savedColor = currentColor;
       
   190         setColor(255, 255, 255);
       
   191         fillRect(area.x, area.y, area.width, area.height);
       
   192         setColor(savedColor);
       
   193     }
       
   194 
       
   195     /**
       
   196      * Cleans the Canvas background.
       
   197      */
       
   198     void cleanBackground(int x, int y, int w, int h)
       
   199     {
       
   200         int savedColor = currentColor;
       
   201         setColor(255, 255, 255);
       
   202         fillRect(x, y, w, h);
       
   203         setColor(savedColor);
       
   204     }
       
   205 
       
   206     /**
       
   207      * Sets the sync strategy for this instance.
       
   208      * This affects on the behavior of the sync method of this class
       
   209      * which is called via LCDUIInvoker
       
   210      */
       
   211     void setSyncStrategy(int strategy)
       
   212     {
       
   213         if((strategy != SYNC_LEAVE_SURFACE_SESSION_CLOSED) && (strategy != SYNC_LEAVE_SURFACE_SESSION_OPEN)) 
       
   214         {
       
   215             throw new IllegalArgumentException("Internal: Invalid strategy value");
       
   216         }
       
   217         syncStrategy = strategy;
       
   218     }
       
   219 
       
   220     /**
       
   221      * Sets coordinate translation. Translations are cumulative.
       
   222      *
       
   223      * @param xDelta x-shift for coordinates.
       
   224      * @param yDelta y-shift for coordinates.
       
   225      */
       
   226     public void translate(int xDelta, int yDelta)
       
   227     {
       
   228         synchronized(graphicsBuffer)
       
   229         {
       
   230             graphicsBuffer.translate(xDelta, yDelta, this);
       
   231             translateX += xDelta;
       
   232             translateY += yDelta;
       
   233         }
       
   234     }
       
   235 
       
   236     /**
       
   237      * Returns current X-shift of coordinate translation.
       
   238      *
       
   239      * @return Current X-shift of coordinate translation.
       
   240      */
       
   241     public int getTranslateX()
       
   242     {
       
   243         synchronized(graphicsBuffer)
       
   244         {
       
   245             return translateX;
       
   246         }
       
   247     }
       
   248 
       
   249     /**
       
   250      * Returns current Y-shift of coordinate translation.
       
   251      *
       
   252      * @return current Y-shift of coordinate translation.
       
   253      */
       
   254     public int getTranslateY()
       
   255     {
       
   256         synchronized(graphicsBuffer)
       
   257         {
       
   258             return translateY;
       
   259         }
       
   260     }
       
   261 
       
   262     /**
       
   263      * Returns current color in 0x00RRGGBB format.
       
   264      *
       
   265      * @return Current color in 0x00RRGGBB format.
       
   266      */
       
   267     public int getColor()
       
   268     {
       
   269         synchronized(graphicsBuffer)
       
   270         {
       
   271             return (currentColor & RGB_MASK);
       
   272         }
       
   273     }
       
   274 
       
   275     /**
       
   276      * Returns red component of current color.
       
   277      *
       
   278      * @return Red component of current color in the range of 0-255.
       
   279      */
       
   280     public int getRedComponent()
       
   281     {
       
   282         synchronized(graphicsBuffer)
       
   283         {
       
   284             return (currentColor >> 16) & COMPONENT_MASK;
       
   285         }
       
   286     }
       
   287 
       
   288     /**
       
   289      * Returns green component of current color.
       
   290      *
       
   291      * @return Green component of current color in the range of 0-255.
       
   292      */
       
   293     public int getGreenComponent()
       
   294     {
       
   295         synchronized(graphicsBuffer)
       
   296         {
       
   297             return (currentColor >> 8) & COMPONENT_MASK;
       
   298         }
       
   299     }
       
   300 
       
   301     /**
       
   302      * Returns blue component of current color.
       
   303      *
       
   304      * @return Blue component of current color in the range of 0-255.
       
   305      */
       
   306     public int getBlueComponent()
       
   307     {
       
   308         synchronized(graphicsBuffer)
       
   309         {
       
   310             return currentColor & COMPONENT_MASK;
       
   311         }
       
   312     }
       
   313 
       
   314     /**
       
   315      * Returns current grayscale color.
       
   316      *
       
   317      * @return Returns current grayscale color in the range 0-255.
       
   318      */
       
   319     public int getGrayScale()
       
   320     {
       
   321         synchronized(graphicsBuffer)
       
   322         {
       
   323             return (getRedComponent() + getGreenComponent() + getBlueComponent()) / 3;
       
   324         }
       
   325     }
       
   326 
       
   327     /**
       
   328      * Sets the current color by color components for red, green and blue.
       
   329      *
       
   330      * @param r - red component of the color to be set.
       
   331      * @param g - green component of the color to be set.
       
   332      * @param b - blue component of the color to be set.
       
   333      */
       
   334     public void setColor(int r, int g, int b)
       
   335     {
       
   336         if(r < 0 || r > 255 ||
       
   337                 g < 0 || g > 255 ||
       
   338                 b < 0 || b > 255)
       
   339         {
       
   340             throw new IllegalArgumentException();
       
   341         }
       
   342         synchronized(graphicsBuffer)
       
   343         {
       
   344             graphicsBuffer.setColor(r, g, b, this);
       
   345             currentColor = (OPAQUE_ALPHA | (r << 16) | (g << 8) | b);
       
   346         }
       
   347 
       
   348     }
       
   349 
       
   350     /**
       
   351      * Sets the current color.
       
   352      *
       
   353      * @param RGB - color to be set in the form of 0x00RRGGBB.
       
   354      */
       
   355     public void setColor(int RGB)
       
   356     {
       
   357         int maskedRGB = RGB & RGB_MASK;
       
   358         final int r = maskedRGB >> 16;
       
   359         final int g = (maskedRGB >> 8) & COMPONENT_MASK;
       
   360         final int b = maskedRGB & COMPONENT_MASK;
       
   361         synchronized(graphicsBuffer)
       
   362         {
       
   363             graphicsBuffer.setColor(r, g, b, this);
       
   364             currentColor = (OPAQUE_ALPHA | maskedRGB);
       
   365         }
       
   366 
       
   367     }
       
   368 
       
   369     /**
       
   370      * Sets gray-scale color.
       
   371      *
       
   372      * @param val - gray-scale value to be set in the range of 0-255.
       
   373      */
       
   374     public void setGrayScale(int val)
       
   375     {
       
   376         if((val < 0) || (val > 255))
       
   377         {
       
   378             throw new IllegalArgumentException();
       
   379         }
       
   380         final int col = val & COMPONENT_MASK;
       
   381         synchronized(graphicsBuffer)
       
   382         {
       
   383             graphicsBuffer.setColor(col, col, col, this);
       
   384             currentColor = (OPAQUE_ALPHA | (col << 16) | (col << 8) | col);
       
   385         }
       
   386 
       
   387     }
       
   388 
       
   389     /**
       
   390      * Returns the current font.
       
   391      *
       
   392      * @return Current font.
       
   393      */
       
   394     public Font getFont()
       
   395     {
       
   396         synchronized(graphicsBuffer)
       
   397         {
       
   398             return currentFont;
       
   399         }
       
   400     }
       
   401 
       
   402     /**
       
   403      * Sets the font to be used for string rendering.
       
   404      *
       
   405      * @param newFont - the font to be used for string rendering.
       
   406      */
       
   407     public void setFont(Font newFont)
       
   408     {
       
   409         synchronized(graphicsBuffer)
       
   410         {
       
   411             if(newFont == null)
       
   412             {
       
   413                 newFont = Font.getDefaultFont();
       
   414             }
       
   415             graphicsBuffer.setFont(Font.getESWTFont(newFont).handle, this);
       
   416             currentFont = newFont;
       
   417         }
       
   418     }
       
   419 
       
   420     /**
       
   421      * Returns left bound of clip rectangle.
       
   422      *
       
   423      * @return Left bound of clip rectangle.
       
   424      */
       
   425     public int getClipX()
       
   426     {
       
   427         synchronized(graphicsBuffer)
       
   428         {
       
   429             return currentClip[0];
       
   430         }
       
   431     }
       
   432 
       
   433     /**
       
   434      * Returns top bound of clip rectangle.
       
   435      *
       
   436      * @return Top bound of clip rectangle.
       
   437      */
       
   438     public int getClipY()
       
   439     {
       
   440         synchronized(graphicsBuffer)
       
   441         {
       
   442             return currentClip[1];
       
   443         }
       
   444     }
       
   445 
       
   446     /**
       
   447      * Returns width of clip rectangle.
       
   448      *
       
   449      * @return Width of clip rectangle.
       
   450      */
       
   451     public int getClipWidth()
       
   452     {
       
   453         synchronized(graphicsBuffer)
       
   454         {
       
   455             return currentClip[2];
       
   456         }
       
   457     }
       
   458 
       
   459     /**
       
   460      * Returns height of clip rectangle.
       
   461      *
       
   462      * @return Height of clip rectangle.
       
   463      */
       
   464     public int getClipHeight()
       
   465     {
       
   466         synchronized(graphicsBuffer)
       
   467         {
       
   468             return currentClip[3];
       
   469         }
       
   470     }
       
   471 
       
   472     /**
       
   473      * Intersects current clip rectangle with the specified one.
       
   474      *
       
   475      * @param x - left bound of the clip rectangle to intersect with the
       
   476      *            current one.
       
   477      * @param y - top bound of the clip rectangle to intersect with the
       
   478      *            current one.
       
   479      * @param w - width of the clip rectangle to intersect with the current one.
       
   480      * @param h - height of the clip rectangle to intersect with the current
       
   481      *            one.
       
   482      */
       
   483     public void clipRect(int x, int y, int w, int h)
       
   484     {
       
   485         synchronized(graphicsBuffer)
       
   486         {
       
   487             final int cx2 = Math.min(currentClip[0] + currentClip[2], x + w);
       
   488             final int cy2 = Math.min(currentClip[1] + currentClip[3], y + h);
       
   489             // setting of clip to Java Graphics
       
   490             currentClip[0] = Math.max(x, currentClip[0]);
       
   491             currentClip[1] = Math.max(y, currentClip[1]);
       
   492             currentClip[2] = cx2 - currentClip[0];
       
   493             currentClip[3] = cy2 - currentClip[1];
       
   494             graphicsBuffer.setClip(currentClip[0], currentClip[1], currentClip[2], currentClip[3], this);
       
   495         }
       
   496     }
       
   497 
       
   498     /**
       
   499      * Sets the clip rectangle.
       
   500      *
       
   501      * @param x - left bound of the new clip rectangle.
       
   502      * @param y - top bound of the new clip rectangle.
       
   503      * @param w - width of the new clip rectangle.
       
   504      * @param h - height of the new clip rectangle.
       
   505      */
       
   506     public void setClip(int x, int y, int w, int h)
       
   507     {
       
   508         synchronized(graphicsBuffer)
       
   509         {
       
   510             currentClip[0] = x;
       
   511             currentClip[1] = y;
       
   512             currentClip[2] = w;
       
   513             currentClip[3] = h;
       
   514             graphicsBuffer.setClip(currentClip[0], currentClip[1], currentClip[2], currentClip[3], this);
       
   515         }
       
   516     }
       
   517 
       
   518     /**
       
   519      * Draws a line with current color and current stroke style.
       
   520      *
       
   521      * @param xStart - X-coordinate of line starting point.
       
   522      * @param yStart - Y-coordinate of line starting point.
       
   523      * @param xEnd - X-coordinate of line end point.
       
   524      * @param yEnd - Y-coordinate of line end point.
       
   525      */
       
   526     public void drawLine(int xStart, int yStart, int xEnd, int yEnd)
       
   527     {
       
   528         synchronized(graphicsBuffer)
       
   529         {
       
   530             graphicsBuffer.drawLine(xStart, yStart, xEnd, yEnd, this);
       
   531         }
       
   532     }
       
   533 
       
   534     /**
       
   535      * Fills a rectangle with current color.
       
   536      *
       
   537      * @param x - x coordinate of top left corner
       
   538      * @param y - y coordinate of top left corner
       
   539      * @param w - width of the rectangle
       
   540      * @param h - height of the rectangle
       
   541      */
       
   542     public void fillRect(int x, int y, int w, int h)
       
   543     {
       
   544         if((w < 0) || (h < 0))
       
   545         {
       
   546             return;
       
   547         }
       
   548         synchronized(graphicsBuffer)
       
   549         {
       
   550             graphicsBuffer.fillRect(x, y, w, h, this);
       
   551         }
       
   552     }
       
   553 
       
   554     /**
       
   555      * Draws a rectangle with specified color and stroke style.
       
   556      *
       
   557      * @param x - x coordinate of top left corner
       
   558      * @param y - y coordinate of top left corner
       
   559      * @param w - width of the rectangle
       
   560      * @param h - height of the rectangle
       
   561      */
       
   562     public void drawRect(int x, int y, int w, int h)
       
   563     {
       
   564         if((w < 0) || (h < 0))
       
   565         {
       
   566             return;
       
   567         }
       
   568         synchronized(graphicsBuffer)
       
   569         {
       
   570             graphicsBuffer.drawRect(x, y, w, h, this);
       
   571         }
       
   572     }
       
   573 
       
   574     /**
       
   575      * Draws a rounded rectangle with specified color and stroke style.
       
   576      *
       
   577      * @param x - x coordinate of top left corner
       
   578      * @param y - y coordinate of top left corner
       
   579      * @param w - width of the rectangle
       
   580      * @param h - height of the rectangle
       
   581      * @param arcW - arc width for corner rounding.
       
   582      * @param arcH - arc height for corner rounding.
       
   583      */
       
   584     public void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH)
       
   585     {
       
   586         if((w < 0) || (h < 0) || (arcW < 0) || (arcH < 0))
       
   587         {
       
   588             return;
       
   589         }
       
   590         synchronized(graphicsBuffer)
       
   591         {
       
   592             graphicsBuffer.drawRoundRect(x, y, w, h, arcW, arcH, this);
       
   593         }
       
   594     }
       
   595 
       
   596     /**
       
   597      * Fills a rounded rectangle with specified color.
       
   598      *
       
   599      * @param x - x coordinate of top left corner
       
   600      * @param y - y coordinate of top left corner
       
   601      * @param w - width of the rectangle
       
   602      * @param h - height of the rectangle
       
   603      * @param arcW - arc width for corner rounding.
       
   604      * @param arcH - arc height for corner rounding.
       
   605      */
       
   606     public void fillRoundRect(int x, int y, int w, int h, int arcW, int arcH)
       
   607     {
       
   608         if((w < 0) || (h < 0) || (arcW < 0) || (arcH < 0))
       
   609         {
       
   610             return;
       
   611         }
       
   612         synchronized(graphicsBuffer)
       
   613         {
       
   614             graphicsBuffer.fillRoundRect(x, y, w, h, arcW, arcH, this);
       
   615         }
       
   616     }
       
   617 
       
   618     /**
       
   619      * Fills an arc with specified color.
       
   620      *
       
   621      * @param x - X-coordinate of top left corner of the rectangle to contain
       
   622      *            the arc.
       
   623      * @param y - Y-coordinate of top left corner of the rectangle to contain
       
   624      *            the arc.
       
   625      * @param w - width of the rectangle to contain the arc.
       
   626      * @param h - height of the rectangle to contain the arc.
       
   627      * @param startAngle - starting angle of the arc in degrees.
       
   628      * @param arcAngle - angle to spread the arc in degrees.
       
   629      */
       
   630     public void fillArc(int x, int y, int w, int h, int startAngle, int arcAngle)
       
   631     {
       
   632         if((w < 0) || (h < 0))
       
   633         {
       
   634             return;
       
   635         }
       
   636         synchronized(graphicsBuffer)
       
   637         {
       
   638             graphicsBuffer.fillArc(x, y, w, h, startAngle, arcAngle, this);
       
   639         }
       
   640     }
       
   641 
       
   642     /**
       
   643      * Draws an arc with specified color and stroke style.
       
   644      *
       
   645      * @param x - X-coordinate of top left corner of the rectangle to contain
       
   646      *            the arc.
       
   647      * @param y - Y-coordinate of top left corner of the rectangle to contain
       
   648      *            the arc.
       
   649      * @param w - width of the rectangle to contain the arc.
       
   650      * @param h - height of the rectangle to contain the arc.
       
   651      * @param startAngle - starting angle of the arc in degrees.
       
   652      * @param arcAngle - angle to spread the arc in degrees.
       
   653      */
       
   654     public void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle)
       
   655     {
       
   656         if((w < 0) || (h < 0))
       
   657         {
       
   658             return;
       
   659         }
       
   660         synchronized(graphicsBuffer)
       
   661         {
       
   662             graphicsBuffer.drawArc(x, y, w, h, startAngle, arcAngle, this);
       
   663         }
       
   664     }
       
   665 
       
   666     /**
       
   667      * Draws a string with specified color and font.
       
   668      *
       
   669      * @param string - the string to draw.
       
   670      * @param xPos - X-coordinate of the anchor point.
       
   671      * @param yPos - Y-coordinate of the anchor point
       
   672      * @param anch - anchor, specifies the way to locate the text around the anchor
       
   673      *            point. May be the combination of Graphics.TOP,
       
   674      *            Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT,
       
   675      *            Graphics.RIGHT, Graphics.HCENTER.
       
   676      */
       
   677     public void drawString(String string, int xPos, int yPos, int anch)
       
   678     {
       
   679         if(string == null)
       
   680         {
       
   681             throw new NullPointerException(
       
   682                 MsgRepository.GRAPHICS_EXCEPTION_STRING_IS_NULL);
       
   683         }
       
   684 
       
   685         if(!checkTextAnchors(anch))
       
   686         {
       
   687             throw new IllegalArgumentException(
       
   688                 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR);
       
   689         }
       
   690 
       
   691         synchronized(graphicsBuffer)
       
   692         {
       
   693             final int alignments = GraphicsContext.ALIGNMENT_TOP | GraphicsContext.ALIGNMENT_LEFT;
       
   694             final int[] boundingBox = new int[4];
       
   695             final String localStr = string;
       
   696 
       
   697             ESWTUIThreadRunner.safeSyncExec(new Runnable()
       
   698             {
       
   699                 public void run()
       
   700                 {
       
   701                     FontUtils fu = new FontUtils(Font.getESWTFont(currentFont).handle);
       
   702                     fu.getBoundingRect(boundingBox, localStr);
       
   703                 }
       
   704             });
       
   705 
       
   706 
       
   707             // Arrange vertical alignments
       
   708             int y = yPos;
       
   709             if(isFlag(anch, Graphics.BOTTOM))
       
   710             {
       
   711                 y = yPos - boundingBox[GraphicsContext.RECT_HEIGHT];
       
   712             }
       
   713             if(isFlag(anch, Graphics.BASELINE))
       
   714             {
       
   715                 y = yPos - currentFont.getBaselinePosition();
       
   716             }
       
   717             // Arrange horizontal alignments
       
   718             int x = xPos;
       
   719             if(isFlag(anch, Graphics.RIGHT))
       
   720             {
       
   721                 x = xPos - boundingBox[GraphicsContext.RECT_WIDTH];
       
   722             }
       
   723             if(isFlag(anch, Graphics.HCENTER))
       
   724             {
       
   725                 x = xPos - boundingBox[GraphicsContext.RECT_WIDTH] / 2;
       
   726             }
       
   727 
       
   728             graphicsBuffer.drawString(localStr, x, y, this);
       
   729         }
       
   730     }
       
   731 
       
   732     private static boolean isFlag(int anchor, int flag)
       
   733     {
       
   734         return (anchor & flag) != 0;
       
   735     }
       
   736 
       
   737     /**
       
   738      * Draws a string with specified color and font.
       
   739      *
       
   740      * @param string - the string to draw.
       
   741      * @param offset - offset of substring in the string.
       
   742      * @param length - length of substring.
       
   743      * @param xPos - X-coordinate of the anchor point.
       
   744      * @param yPos - Y-coordinate of the anchor point
       
   745      * @param anch - anchor, specifies the way to locate the text around the
       
   746      *            anchor point. May be the combination of Graphics.TOP,
       
   747      *            Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT,
       
   748      *            Graphics.RIGHT, Graphics.HCENTER.
       
   749      */
       
   750     public void drawSubstring(java.lang.String string, int offset, int length,
       
   751                               int xPos, int yPos, int anch)
       
   752     {
       
   753         drawString(string.substring(offset, offset+length), xPos, yPos, anch);
       
   754     }
       
   755 
       
   756     /**
       
   757      * Draws a character with specified color and font.
       
   758      *
       
   759      * @param c - character to draw.
       
   760      * @param xPos - X-coordinate of the anchor point.
       
   761      * @param yPos - Y-coordinate of the anchor point
       
   762      * @param anch - anchor, specifies the way to locate the text around the
       
   763      *            anchor point. May be the combination of Graphics.TOP,
       
   764      *            Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT,
       
   765      *            Graphics.RIGHT, Graphics.HCENTER.
       
   766      */
       
   767     public void drawChar(char c, int xPos, int yPos, int anch)
       
   768     {
       
   769         drawString(String.valueOf(c), xPos, yPos, anch);
       
   770     }
       
   771 
       
   772     /**
       
   773      * Draws characters from array with specified color and font.
       
   774      *
       
   775      * @param ch -character array to draw.
       
   776      * @param offset - offset of the starting character in the array.
       
   777      * @param length - length of character sequence from the array to draw.
       
   778      * @param xPos - X-coordinate of the anchor point.
       
   779      * @param yPos - Y-coordinate of the anchor point
       
   780      * @param anch - anchor, specifies the way to locate the text around the
       
   781      *            anchor point. May be the combination of Graphics.TOP,
       
   782      *            Graphics.BOTTOM, Graphics.BASELINE, Graphics.LEFT,
       
   783      *            Graphics.RIGHT, Graphics.HCENTER.
       
   784      */
       
   785     public void drawChars(char[] ch, int offset, int length,
       
   786                           int xPos, int yPos, int anch)
       
   787     {
       
   788         if(ch == null)
       
   789         {
       
   790             throw new NullPointerException(
       
   791                 MsgRepository.GRAPHICS_EXCEPTION_ARRAY_IS_NULL);
       
   792         }
       
   793         String str = null;
       
   794         try
       
   795         {
       
   796             str = String.valueOf(ch, offset, length);
       
   797         }
       
   798         catch(Exception e)
       
   799         {
       
   800             throw new ArrayIndexOutOfBoundsException(
       
   801                 MsgRepository.GRAPHICS_EXCEPTION_ARRAY_OUT_OF_BOUNDS);
       
   802         }
       
   803 
       
   804         drawString(str, xPos, yPos, anch);
       
   805     }
       
   806 
       
   807     /**
       
   808      * Checks if anchors combination is valid.
       
   809      */
       
   810     private boolean checkTextAnchors(int anch)
       
   811     {
       
   812         boolean retVal = false;
       
   813 
       
   814         int vertMask = Graphics.TOP | Graphics.BASELINE | Graphics.BOTTOM;
       
   815         int horMask = Graphics.LEFT | Graphics.RIGHT | Graphics.HCENTER;
       
   816 
       
   817         if(anch == 0)
       
   818         {
       
   819             return true;
       
   820         }
       
   821 
       
   822         if((anch & ~(vertMask | horMask)) != 0)
       
   823         {
       
   824             return false;
       
   825         }
       
   826 
       
   827         int vertAchor = anch & vertMask;
       
   828         int horAchor = anch & horMask;
       
   829 
       
   830         if((vertAchor == Graphics.TOP)
       
   831                 || (vertAchor == Graphics.BASELINE)
       
   832                 || (vertAchor == Graphics.BOTTOM))
       
   833         {
       
   834             retVal = true;
       
   835         }
       
   836 
       
   837         if((horAchor == Graphics.LEFT)
       
   838                 || (vertAchor == Graphics.RIGHT)
       
   839                 || (vertAchor == Graphics.HCENTER))
       
   840         {
       
   841             retVal = true;
       
   842         }
       
   843 
       
   844         return retVal;
       
   845     }
       
   846 
       
   847     /**
       
   848      * Draw an Image to the graphical context.
       
   849      *
       
   850      * @param image - Image to be drawn.
       
   851      * @param xPos - X-coordinate of the anchor point.
       
   852      * @param yPos - Y-coordinate of the anchor point.
       
   853      * @param anch - anchor value.
       
   854      */
       
   855     public void drawImage(javax.microedition.lcdui.Image image, int xPos,
       
   856                           int yPos, int anch)
       
   857     {
       
   858 
       
   859         if(image == null)
       
   860         {
       
   861             throw new NullPointerException(
       
   862                 MsgRepository.IMAGE_EXCEPTION_IS_NULL);
       
   863         }
       
   864         if(!checkImageAnchors(anch))
       
   865         {
       
   866             throw new IllegalArgumentException(
       
   867                 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR);
       
   868         }
       
   869         synchronized(graphicsBuffer)
       
   870         {
       
   871             int y = yPos;
       
   872             if(isFlag(anch, Graphics.VCENTER))
       
   873             {
       
   874                 y = yPos - image.getHeight() / 2;
       
   875             }
       
   876             if(isFlag(anch, Graphics.BOTTOM))
       
   877             {
       
   878                 y = yPos - image.getHeight();
       
   879             }
       
   880 
       
   881             int x = xPos;
       
   882             if(isFlag(anch, Graphics.HCENTER))
       
   883             {
       
   884                 x = xPos - image.getWidth() / 2;
       
   885             }
       
   886             if(isFlag(anch, Graphics.RIGHT))
       
   887             {
       
   888                 x = xPos - image.getWidth();
       
   889             }
       
   890 
       
   891             synchronized(image.graphicsBuffer)
       
   892             {
       
   893                 final Image localLcduiImage = image;
       
   894                 final org.eclipse.swt.internal.qt.graphics.Image localCgfxImage = 
       
   895                     Internal_GfxPackageSupport.getImage(Image.getESWTImage(image));
       
   896                 final int localX = x;
       
   897                 final int localY = y;
       
   898                 final Graphics self = this;
       
   899                 
       
   900                 if(image.graphicsBuffer.containsDrawnPrimitives()) {
       
   901                     localLcduiImage.sync(true);
       
   902                 }
       
   903                 graphicsBuffer.drawImage(localCgfxImage, localX, localY, self);
       
   904             }
       
   905         }
       
   906     }
       
   907 
       
   908     /**
       
   909      * Checks if anchors combination is valid.
       
   910      */
       
   911     private boolean checkImageAnchors(int anch)
       
   912     {
       
   913         boolean retVal = false;
       
   914 
       
   915         int vertMask = Graphics.TOP | Graphics.VCENTER | Graphics.BOTTOM;
       
   916         int horMask = Graphics.LEFT | Graphics.RIGHT | Graphics.HCENTER;
       
   917 
       
   918         if(anch == 0)
       
   919         {
       
   920             return true;
       
   921         }
       
   922 
       
   923         if((anch & ~(vertMask | horMask)) != 0)
       
   924         {
       
   925             return false;
       
   926         }
       
   927 
       
   928         int vertAchor = anch & vertMask;
       
   929         int horAchor = anch & horMask;
       
   930 
       
   931         if((vertAchor == Graphics.TOP)
       
   932                 || (vertAchor == Graphics.VCENTER)
       
   933                 || (vertAchor == Graphics.BOTTOM))
       
   934         {
       
   935             retVal = true;
       
   936         }
       
   937 
       
   938         if((horAchor == Graphics.LEFT)
       
   939                 || (vertAchor == Graphics.RIGHT)
       
   940                 || (vertAchor == Graphics.HCENTER))
       
   941         {
       
   942             retVal = true;
       
   943         }
       
   944 
       
   945         return retVal;
       
   946     }
       
   947 
       
   948     /**
       
   949      * Sets the stroke style for drawing graphical primitives.
       
   950      *
       
   951      * @param newStyle - new style, valid values are Graphics.SOLID and
       
   952      *            Graphics.DOTTED.
       
   953      * @throws IllegalArgumentException if the new style value is invalid.
       
   954      */
       
   955     public void setStrokeStyle(int newStyle)
       
   956     {
       
   957         if(newStyle == currentStrokeStyle)
       
   958         {
       
   959             return;
       
   960         }
       
   961         synchronized(graphicsBuffer)
       
   962         {
       
   963             int styleToApply = mapStrokeStyle(newStyle);
       
   964             if(styleToApply == INVALID_STROKE_STYLE)
       
   965             {
       
   966                 throw new IllegalArgumentException(
       
   967                     MsgRepository.GRAPHICS_EXCEPTION_ILLEGAL_STROKE_STYLE);
       
   968             }
       
   969             graphicsBuffer.setStrokeStyle(styleToApply, newStyle, this);
       
   970             currentStrokeStyle = newStyle;
       
   971         }
       
   972     }
       
   973 
       
   974     /**
       
   975      * Returns current stroke style.
       
   976      *
       
   977      * @return Current stroke style.
       
   978      */
       
   979     public int getStrokeStyle()
       
   980     {
       
   981         synchronized(graphicsBuffer)
       
   982         {
       
   983             return currentStrokeStyle;
       
   984         }
       
   985     }
       
   986 
       
   987     /**
       
   988      * Returns the color that will be used if the specified color is requested.
       
   989      *
       
   990      * @param color - color to use in 0x00RRGGBB form.
       
   991      * @return Color that will be actually used in 0x00RRGGBB form.
       
   992      */
       
   993     public int getDisplayColor(int color)
       
   994     {
       
   995         return color & RGB_MASK;
       
   996     }
       
   997 
       
   998     /**
       
   999      * Renders 0xAARRGGBB pixels.
       
  1000      *
       
  1001      * @param rgb - array of ARGB values
       
  1002      * @param offset - index of the first value in the array.
       
  1003      * @param scanlength - relative distance in the array between. corresponding
       
  1004      *            pixels of consecutive rows.
       
  1005      * @param x - X-coordinate of the top-left corner of the rectangle to be
       
  1006      *            rendered.
       
  1007      * @param y - Y-coordinate of the top-left corner of the rectangle to be
       
  1008      *            rendered.
       
  1009      * @param w - width of the rectangle to be rendered.
       
  1010      * @param h - height of the rectangle to be rendered.
       
  1011      * @param alpha - true if alpha values should be rendered, false otherwise.
       
  1012      */
       
  1013     public void drawRGB(int[] rgb,
       
  1014                         int offset,
       
  1015                         int scanlength,
       
  1016                         int x,
       
  1017                         int y,
       
  1018                         int w,
       
  1019                         int h,
       
  1020                         boolean alpha)
       
  1021     {
       
  1022 
       
  1023         if(rgb == null)
       
  1024         {
       
  1025             throw new NullPointerException(
       
  1026                 MsgRepository.IMAGE_EXCEPTION_DATA_IS_NULL);
       
  1027         }
       
  1028         synchronized(graphicsBuffer)
       
  1029         {
       
  1030             graphicsBuffer.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha, this);
       
  1031         }
       
  1032     }
       
  1033 
       
  1034     /**
       
  1035      * Fills the specified triangle with current color.
       
  1036      *
       
  1037      * @param xPos1 - X-coordinate of first vertex.
       
  1038      * @param yPos1 - Y-coordinate of first vertex.
       
  1039      * @param xPos2 - X-coordinate of second vertex.
       
  1040      * @param yPos2 - Y-coordinate of second vertex.
       
  1041      * @param xPos3 - X-coordinate of third vertex.
       
  1042      * @param yPos3 - Y-coordinate of third vertex.
       
  1043      */
       
  1044     public void fillTriangle(int xPos1,
       
  1045                              int yPos1,
       
  1046                              int xPos2,
       
  1047                              int yPos2,
       
  1048                              int xPos3,
       
  1049                              int yPos3)
       
  1050     {
       
  1051         synchronized(graphicsBuffer)
       
  1052         {
       
  1053             final int[] points = {xPos1, yPos1, xPos2, yPos2, xPos3, yPos3};
       
  1054             graphicsBuffer.fillTriangle(points, this);
       
  1055         }
       
  1056     }
       
  1057 
       
  1058     /**
       
  1059      * Copies the specified area.
       
  1060      *
       
  1061      * @param xFrom - X-coordinate of the top-left corner of the region to copy.
       
  1062      * @param yFrom - Y-coordinate of the top-left corner of the region to copy.
       
  1063      * @param w - width of the region to copy.
       
  1064      * @param h - height of the region to copy.
       
  1065      * @param xTo - X-coordinate of the anchor point to copy region to.
       
  1066      * @param yTo - Y-coordinate of the anchor point to copy region to.
       
  1067      * @param anch - anchor point specification.
       
  1068      */
       
  1069     public void copyArea(int xFrom,
       
  1070                          int yFrom,
       
  1071                          int w,
       
  1072                          int h,
       
  1073                          int xTo,
       
  1074                          int yTo,
       
  1075                          int anch)
       
  1076     {
       
  1077 
       
  1078         if(graphicsBuffer.getHostType() != Buffer.HOST_TYPE_IMAGE)
       
  1079         {
       
  1080             // this Graphics belongs to a screen device.
       
  1081             throw new IllegalStateException(
       
  1082                 MsgRepository.GRAPHICS_EXCEPTION_DESTINATION_IS_SCREEN);
       
  1083         }
       
  1084         synchronized(graphicsBuffer)
       
  1085         {
       
  1086             Image image = (Image)graphicsBuffer.getHost();
       
  1087             if(!javax.microedition.lcdui.Image.validateRegion(image
       
  1088                     .getWidth(), image.getHeight(), xFrom, yFrom, w, h))
       
  1089             {
       
  1090                 throw new IllegalArgumentException(
       
  1091                     MsgRepository.IMAGE_EXCEPTION_INVALID_REGION);
       
  1092             }
       
  1093 
       
  1094             // Arrange vertical alignments
       
  1095             int destY = yTo;
       
  1096             if(isFlag(anch, Graphics.BOTTOM))
       
  1097             {
       
  1098                 destY = yTo - h;
       
  1099             }
       
  1100             if(isFlag(anch, Graphics.VCENTER))
       
  1101             {
       
  1102                 destY = yTo - h / 2;
       
  1103             }
       
  1104 
       
  1105             // Arrange horizontal alignments
       
  1106             int destX = xTo;
       
  1107             if(isFlag(anch, Graphics.RIGHT))
       
  1108             {
       
  1109                 destX = xTo - w;
       
  1110             }
       
  1111             if(isFlag(anch, Graphics.HCENTER))
       
  1112             {
       
  1113                 destX = xTo - w / 2;
       
  1114             }
       
  1115             graphicsBuffer.copyArea(xFrom, yFrom, w, h, destX, destY, this);
       
  1116         }
       
  1117     }
       
  1118 
       
  1119     /**
       
  1120      * Renders a portion of source image with possible transforms.
       
  1121      *
       
  1122      * @param srcImage - source Image
       
  1123      * @param xSrc - X-coordinate of the top-left corner of the rectangle in
       
  1124      *            source image.
       
  1125      * @param ySrc - Y-coordinate of the top-left corner of the rectangle in
       
  1126      *            source image.
       
  1127      * @param width - width of the rectangle in source image.
       
  1128      * @param height - height of the rectangle in source image.
       
  1129      * @param transform - transform to apply to the image before rendering.
       
  1130      * @param xDst - X-coordinate of the anchor point in destination.
       
  1131      * @param yDst - Y-coordinate of the anchor point in destination.
       
  1132      * @param anch - anchor point definition.
       
  1133      */
       
  1134     public void drawRegion(javax.microedition.lcdui.Image srcImage,
       
  1135                            int xSrc,
       
  1136                            int ySrc,
       
  1137                            int width,
       
  1138                            int height,
       
  1139                            int transform,
       
  1140                            int xDst,
       
  1141                            int yDst,
       
  1142                            int anch)
       
  1143     {
       
  1144 
       
  1145         if(srcImage == null)
       
  1146         {
       
  1147             throw new NullPointerException(
       
  1148                 MsgRepository.IMAGE_EXCEPTION_IS_NULL);
       
  1149         }
       
  1150         if(srcImage == graphicsBuffer.getHost())
       
  1151         {
       
  1152             throw new IllegalArgumentException(
       
  1153                 MsgRepository.GRAPHICS_EXCEPTION_SAME_SOURCE_AND_DESTINATION);
       
  1154         }
       
  1155         if(!javax.microedition.lcdui.Image.validateTransform(transform))
       
  1156         {
       
  1157             throw new IllegalArgumentException(
       
  1158                 MsgRepository.IMAGE_EXCEPTION_INVALID_TRANSFORM);
       
  1159         }
       
  1160         if(!checkImageAnchors(anch))
       
  1161         {
       
  1162             throw new IllegalArgumentException(
       
  1163                 MsgRepository.GRAPHICS_EXCEPTION_INVALID_ANCHOR);
       
  1164         }
       
  1165         if(!javax.microedition.lcdui.Image.validateRegion(srcImage.getWidth(),
       
  1166                 srcImage.getHeight(), xSrc, ySrc, width, height))
       
  1167         {
       
  1168             throw new IllegalArgumentException(
       
  1169                 MsgRepository.IMAGE_EXCEPTION_INVALID_REGION);
       
  1170         }
       
  1171         synchronized(graphicsBuffer)
       
  1172         {
       
  1173             // Arrange vertical alignments
       
  1174             int y = yDst;
       
  1175             if(isFlag(anch, Graphics.VCENTER))
       
  1176             {
       
  1177                 y = yDst - srcImage.getHeight() / 2;
       
  1178             }
       
  1179             if(isFlag(anch, Graphics.BOTTOM))
       
  1180             {
       
  1181                 y = yDst - srcImage.getHeight();
       
  1182             }
       
  1183 
       
  1184             // Arrange horizontal alignments
       
  1185             int x = xDst;
       
  1186             if(isFlag(anch, Graphics.HCENTER))
       
  1187             {
       
  1188                 x = xDst - srcImage.getWidth() / 2;
       
  1189             }
       
  1190             if(isFlag(anch, Graphics.RIGHT))
       
  1191             {
       
  1192                 x = xDst - srcImage.getWidth();
       
  1193             }
       
  1194             final int gcTransform = Image.getCgTransformValue(transform);
       
  1195             synchronized(srcImage.graphicsBuffer)
       
  1196             {
       
  1197                 final Image localLcduiSrcImage = srcImage;
       
  1198                 final org.eclipse.swt.internal.qt.graphics.Image localCgfxImage = 
       
  1199                     Internal_GfxPackageSupport.getImage(Image.getESWTImage(srcImage));
       
  1200                 final int localX = x;
       
  1201                 final int localY = y;
       
  1202                 final int localW = width;
       
  1203                 final int localH = height;
       
  1204                 final int localXSrc = xSrc;
       
  1205                 final int localYSrc = ySrc;
       
  1206                 final int localGcTransform = gcTransform;
       
  1207                 final Graphics self = this;
       
  1208                 if(srcImage.graphicsBuffer.containsDrawnPrimitives()) {
       
  1209                     localLcduiSrcImage.sync(true);
       
  1210                 }
       
  1211                 graphicsBuffer.drawImage(localCgfxImage,
       
  1212                     localX, localY, localW, localH, localXSrc, localYSrc, localW, localH, localGcTransform, self);
       
  1213             }
       
  1214         }
       
  1215     }
       
  1216 
       
  1217     /**
       
  1218      * Performs synchronization on the graphics buffer, i.e.
       
  1219      * the buffered draw commands are rasterized to the surface.
       
  1220      */
       
  1221     void sync()
       
  1222     {
       
  1223         synchronized(graphicsBuffer) 
       
  1224         {
       
  1225             if(syncStrategy == SYNC_LEAVE_SURFACE_SESSION_OPEN)
       
  1226             {
       
  1227                 // This instance is used only with paint callbacks, thus  
       
  1228                 // sync is called with the indication that surface paint  
       
  1229                 // session can be left open as it will be closed when the 
       
  1230                 // callback returns.
       
  1231                 graphicsBuffer.sync(false);
       
  1232             }
       
  1233             else 
       
  1234             {
       
  1235                 graphicsBuffer.sync(true);
       
  1236             } 
       
  1237         }
       
  1238     }
       
  1239     
       
  1240     
       
  1241     /**
       
  1242      * Return DirectGraphics associated with this instance.
       
  1243      */
       
  1244     DirectGraphics getDirectGraphics()
       
  1245     {
       
  1246         if(directGraphics == null)
       
  1247         {
       
  1248             directGraphics = new DirectGraphicsImpl(this);
       
  1249         }
       
  1250         return directGraphics;
       
  1251     }
       
  1252 
       
  1253     /**
       
  1254      * Getter for graphics buffer.
       
  1255      * @return The Buffer.
       
  1256      */
       
  1257     Buffer getGraphicsBuffer()
       
  1258     {
       
  1259         return graphicsBuffer;
       
  1260     }
       
  1261     
       
  1262     /**
       
  1263      * Maps stroke style constant from values used by
       
  1264      * Graphics to values defined in GraphicsContext
       
  1265      */
       
  1266     static int mapStrokeStyle(int strokeStyle)
       
  1267     {
       
  1268         if(strokeStyle == SOLID)
       
  1269         {
       
  1270             return GraphicsContext.STROKE_SOLID;
       
  1271         }
       
  1272         else if(strokeStyle == DOTTED)
       
  1273         {
       
  1274             return GraphicsContext.STROKE_DOT;
       
  1275         }
       
  1276         return INVALID_STROKE_STYLE;
       
  1277     }
       
  1278 
       
  1279     //
       
  1280     // Nokia UI API support
       
  1281     //
       
  1282     void drawRGB(int[] rgb, int offset, int scanlength, int x, int y, int w,
       
  1283                  int h, boolean processAlpha, int manipulation)
       
  1284     {
       
  1285         synchronized(graphicsBuffer)
       
  1286         {
       
  1287             graphicsBuffer.drawRGB(rgb, offset, scanlength, x, y, w, h, processAlpha, manipulation, this);
       
  1288         }
       
  1289     }
       
  1290 
       
  1291     void drawRGB(byte[] rgb, byte[] transparencyMask, int offset, int scanlength, int x, int y, int w,
       
  1292                  int h, int manipulation, int format)
       
  1293     {
       
  1294         synchronized(graphicsBuffer)
       
  1295         {
       
  1296             graphicsBuffer.drawRGB(rgb, transparencyMask, offset, scanlength, x, y, w, h, manipulation, format, this);
       
  1297         }
       
  1298     }
       
  1299 
       
  1300     void drawRGB(short[] rgb, int offset, int scanlength, int x, int y, int w,
       
  1301                  int h, boolean processAlpha, int manipulation, int format)
       
  1302     {
       
  1303         synchronized(graphicsBuffer)
       
  1304         {
       
  1305             graphicsBuffer.drawRGB(rgb, offset, scanlength, x, y, w, h, processAlpha, manipulation, format, this);
       
  1306         }
       
  1307     }
       
  1308 
       
  1309     void drawPolygon(int[] points)
       
  1310     {
       
  1311         synchronized(graphicsBuffer)
       
  1312         {
       
  1313             graphicsBuffer.drawPolygon(points, this);
       
  1314         }
       
  1315     }
       
  1316 
       
  1317     void fillPolygon(int[] points)
       
  1318     {
       
  1319         synchronized(graphicsBuffer)
       
  1320         {
       
  1321             graphicsBuffer.fillPolygon(points, this);
       
  1322         }
       
  1323     }
       
  1324 
       
  1325     void setARGBColor(int argb)
       
  1326     {
       
  1327         synchronized(graphicsBuffer)
       
  1328         {
       
  1329             graphicsBuffer.setARGBColor(argb, this);
       
  1330             currentColor = argb;
       
  1331         }
       
  1332 
       
  1333     }
       
  1334 
       
  1335 }