javauis/lcdui_qt/src/javax/microedition/lcdui/Buffer.java
changeset 47 f40128debb5d
parent 35 85266cc22c7f
child 78 71ad690e91f5
equal deleted inserted replaced
35:85266cc22c7f 47:f40128debb5d
    54     final static int HOST_TYPE_IMAGE = 1;
    54     final static int HOST_TYPE_IMAGE = 1;
    55     final static int HOST_TYPE_CANVAS = 2;
    55     final static int HOST_TYPE_CANVAS = 2;
    56     final static int HOST_TYPE_CUSTOMITEM = 3;
    56     final static int HOST_TYPE_CUSTOMITEM = 3;
    57 
    57 
    58     // Flags for raising settings validation
    58     // Flags for raising settings validation
    59     private final static int NONE            = 0;
    59     // FORCE_SETTINGS Forces settings to validated also in case
    60     private final static int COLOR           = 1;
    60     // there's only one Graphics instance as client, normally 
    61     private final static int CLIP            = 2;
    61     // settings are not checked in such case
    62     private final static int FONT            = 4;
    62     final static int NONE            = 0;
    63     private final static int STROKESTYLE     = 8;
    63     final static int COLOR           = 1;
    64     private final static int COORS_TRANSLATION = 16;
    64     final static int CLIP            = 2;
       
    65     final static int FONT            = 4;
       
    66     final static int STROKESTYLE     = 8;
       
    67     final static int COORDS_TRANSLATION = 16; 
       
    68     final static int FORCE_SETTINGS    = 32; 
    65 
    69 
    66     // Graphics settings active in buffer
    70     // Graphics settings active in buffer
    67     // all values are comparable to those
    71     // all values are comparable to those
    68     // in Graphics except font which is stored
    72     // in Graphics except font which is stored
    69     // as handle instead of LCDUI Font
    73     // as handle instead of LCDUI Font
   105      * @param control The eSWT control associated with the target, or null if the host is Image
   109      * @param control The eSWT control associated with the target, or null if the host is Image
   106      * @return New buffer instance
   110      * @return New buffer instance
   107      */
   111      */
   108     static Buffer createInstance(Object host, Control control)
   112     static Buffer createInstance(Object host, Control control)
   109     {
   113     {
   110     	if(host instanceof Canvas) 
   114         if(host instanceof Canvas) 
   111     	{
   115         {
   112     		if(OS.windowServer == OS.WS_SYMBIAN_S60)
   116             if(OS.windowServer == OS.WS_SYMBIAN_S60)
   113     		{	
   117             {   
   114     		    return new CanvasBufferSymbian((Canvas) host, control);
   118                 return new CanvasBufferSymbian((Canvas) host, control);
   115     		}
   119             }
   116     		else if(OS.windowServer == OS.WS_X11)
   120             else if(OS.windowServer == OS.WS_X11)
   117     		{
   121             {
   118     			return new CanvasBufferLinux((Canvas) host, control);
   122                 return new CanvasBufferLinux((Canvas) host, control);
   119     		}
   123             }
   120   			return null;
   124             return null;
   121     	} 
   125         } 
   122     	else if(host instanceof CustomItem)
   126         else if(host instanceof CustomItem)
   123     	{
   127         {
   124     		if(OS.windowServer == OS.WS_SYMBIAN_S60)
   128             if(OS.windowServer == OS.WS_SYMBIAN_S60)
   125     		{	
   129             {   
   126     		    return new CustomItemBufferSymbian((CustomItem) host, control);
   130                 return new CustomItemBufferSymbian((CustomItem) host, control);
   127     		}
   131             }
   128     		else if(OS.windowServer == OS.WS_X11)
   132             else if(OS.windowServer == OS.WS_X11)
   129     		{
   133             {
   130     			return new CustomItemBufferLinux((CustomItem) host, control);
   134                 return new CustomItemBufferLinux((CustomItem) host, control);
   131     		}
   135             }
   132   			return null;
   136             return null;
   133     	} 
   137         } 
   134     	else if(host instanceof Image) 
   138         else if(host instanceof Image) 
   135     	{
   139         {
   136     	    return new ImageBuffer((Image) host);	
   140             return new ImageBuffer((Image) host);   
   137     	}
   141         }
   138     	return null;
   142         return null;
   139     }
   143     }
   140     
   144     
   141     /**
   145     /**
   142      * Initializes data, called once
   146      * Initializes data, called once
   143      */
   147      */
   152     }
   156     }
   153 
   157 
   154     /**
   158     /**
   155      * Defines the bounds of the host.
   159      * Defines the bounds of the host.
   156      * Bounds are used for restricting the rendering in
   160      * Bounds are used for restricting the rendering in
   157      * the area of the control that is being updated. With Images
   161      * the area of the control that is being updated. 
   158      * the bounds are not used.
       
   159      *
   162      *
   160      * @param crtl The Control of the host
   163      * @param crtl The Control of the host
   161      * @param clienArea The area of the control which can be drawn by Graphics
   164      * @param clienArea The area of the control which can be drawn by Graphics
   162      */
   165      */
   163     void setControlBounds(final Control control)
   166     void setControlBounds(final Control control)
   175         hostBounds.width = control.getBounds().width;
   178         hostBounds.width = control.getBounds().width;
   176         hostBounds.height = control.getBounds().height;
   179         hostBounds.height = control.getBounds().height;
   177     }
   180     }
   178 
   181 
   179     /**
   182     /**
       
   183      * Defines the bounds of the host.
       
   184      *
       
   185      * @param crtl The Control of the host
       
   186      * @param clienArea The area of the control which can be drawn by Graphics
       
   187      */
       
   188     void setImageBounds(int width, int height)
       
   189     {
       
   190         hostBounds.x = 0;
       
   191         hostBounds.y = 0;
       
   192         hostBounds.width = width;
       
   193         hostBounds.height = height;
       
   194     }
       
   195 
       
   196     /**
   180      * Prepares surface for a new frame and starts paint session. 
   197      * Prepares surface for a new frame and starts paint session. 
   181      * Must be called in UI thread (sync calls this automatically)
   198      * Must be called in UI thread (sync calls this automatically)
   182      * and at the start of new frame. The rectangle provided as 
   199      * and at the start of new frame. The rectangle provided as 
   183      * arguments are in control coordinates.
   200      * arguments are in control coordinates.
   184      * 
   201      * 
   187      * @param w The width of the area to be painted
   204      * @param w The width of the area to be painted
   188      * @param h The height of the area to be painted
   205      * @param h The height of the area to be painted
   189      */
   206      */
   190     void startFrame(int x, int y, int w, int h)
   207     void startFrame(int x, int y, int w, int h)
   191     {
   208     {
   192     	if(!isSurfaceSessionOpen)
   209         if(!isSurfaceSessionOpen)
   193     	{
   210         {
   194     	    beginPaint(x, y, w, h);
   211             beginPaint(x, y, w, h);
   195     	    isSurfaceSessionOpen = true;
   212             isSurfaceSessionOpen = true;
   196     	}
   213         }
   197     }
   214     }
   198     
   215     
   199     /**
   216     /**
   200      * Ends frame painting session. Must be called in UI thread and
   217      * Ends frame painting session. Must be called in UI thread and
   201      * at the end of the frame. BlitToDisplay calls this automatically.
   218      * at the end of the frame. BlitToDisplay calls this automatically.
   202      */
   219      */
   203     void endFrame()
   220     void endFrame()
   204     {
   221     {
   205     	if(isSurfaceSessionOpen)
   222         if(isSurfaceSessionOpen)
   206     	{
   223         {
   207     		endPaint();
   224             endPaint();
   208     	    isSurfaceSessionOpen = false;
   225             isSurfaceSessionOpen = false;
   209     	}
   226         }
   210     }
   227     }
   211     
   228     
   212     /**
   229     /**
   213      * Transfers the result of rendering to display.
   230      * Transfers the result of rendering to display.
   214      * @param gc The graphics context used for blit, may be null in some cases
   231      * @param gc The graphics context used for blit, may be null in some cases
   215      * @param widget The widget that is the target 
   232      * @param widget The widget that is the target 
   216      */
   233      */
   217     void blitToDisplay(GraphicsContext gc, Widget widget)
   234     void blitToDisplay(GraphicsContext gc, Widget widget)
   218     {
   235     {
   219   	    endFrame();
   236         endFrame();
   220     	blit(gc, widget);
   237         blit(gc, widget);
   221     }
   238     }
   222     
   239     
   223     /** 
   240     /** 
   224      * Prepares surface for painting, implemented by
   241      * Prepares surface for painting, implemented by
   225      * child implementation.
   242      * child implementation.
   284         clientCount++;
   301         clientCount++;
   285         // In case this is the first Graphics instance
   302         // In case this is the first Graphics instance
   286         // write the default values to the buffer
   303         // write the default values to the buffer
   287         if(clientCount == 1) 
   304         if(clientCount == 1) 
   288         {
   305         {
   289             writeDefaultValuesToBuffer();	
   306             writeDefaultValuesToBuffer();   
   290         }
   307         }
   291         return new Graphics(this, hostBounds );
   308         return new Graphics(this, hostBounds );
   292     }
   309     }
   293 
   310 
   294     /**
   311     /**
   297      * are created, sync has no effect. This variant always closes 
   314      * are created, sync has no effect. This variant always closes 
   298      * the surface session unconditionally
   315      * the surface session unconditionally
   299      */
   316      */
   300     void sync() 
   317     void sync() 
   301     {
   318     {
   302     	sync(true);
   319         sync(true);
   303     }
   320     }
   304     
   321     
   305     /**
   322     /**
   306      * Synchronizes this buffer with the actual target
   323      * Synchronizes this buffer with the actual target
   307      * must be called in UI thread. If no Graphics instances
   324      * must be called in UI thread. If no Graphics instances
   323         {
   340         {
   324             return;
   341             return;
   325         }
   342         }
   326         
   343         
   327         // Start surface session if not started yet
   344         // Start surface session if not started yet
   328        	startFrame(hostBounds.x, hostBounds.y , hostBounds.width , hostBounds.height);
   345         startFrame(hostBounds.x, hostBounds.y , hostBounds.width , hostBounds.height);
   329         
   346         
   330         doRelease();
   347         doRelease();
   331         bindToHost(gc);
   348         bindToHost(gc);
   332         gc.render(commandBuffer);
   349         gc.render(commandBuffer);
   333         doRelease();
   350         doRelease();
   363     /**
   380     /**
   364      * Disposes this instance
   381      * Disposes this instance
   365      */
   382      */
   366     void dispose()
   383     void dispose()
   367     {
   384     {
   368     	if(gc != null) 
   385         if(gc != null) 
   369     	{
   386         {
   370             doRelease();
   387             doRelease();
   371             gc.dispose();
   388             gc.dispose();
   372             gc = null;
   389             gc = null;
   373     	}
   390         }
   374         commandBuffer = null;
   391         commandBuffer = null;
   375     }
   392     }
   376 
   393 
   377     void copyArea(int x1, int y1, int width, int height, int x2, int y2, Graphics client)
   394     void copyArea(int x1, int y1, int width, int height, int x2, int y2, Graphics client)
   378     {
   395     {
   379         gc.copyArea(x1, y1, width, height, x2, y2);
   396         gc.copyArea(x1, y1, width, height, x2, y2);
   380     }
   397     }
   381 
   398 
   382     void fillRect(int x, int y, int w, int h, Graphics client)
   399     void fillRect(int x, int y, int w, int h, Graphics client)
   383     {
   400     {
   384         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client);
   401         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client);
   385         gc.fillRect(x, y, w, h);
   402         gc.fillRect(x, y, w, h);
   386     }
   403     }
   387 
   404 
   388     void fillRoundRect(int x, int y, int w, int h, int arcW, int arcH, Graphics client)
   405     void fillRoundRect(int x, int y, int w, int h, int arcW, int arcH, Graphics client)
   389     {
   406     {
   390         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client);
   407         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client);
   391         gc.fillRoundRect(x, y, w, h, arcW, arcH);
   408         gc.fillRoundRect(x, y, w, h, arcW, arcH);
   392     }
   409     }
   393 
   410 
   394     void fillArc(int x, int y, int w, int h, int startAngle, int arcAngle, Graphics client)
   411     void fillArc(int x, int y, int w, int h, int startAngle, int arcAngle, Graphics client)
   395     {
   412     {
   396         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client);
   413         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client);
   397         gc.fillArc(x, y, w, h, startAngle, arcAngle);
   414         gc.fillArc(x, y, w, h, startAngle, arcAngle);
   398     }
   415     }
   399 
   416 
   400     void fillTriangle(int[] points, Graphics client)
   417     void fillTriangle(int[] points, Graphics client)
   401     {
   418     {
   402         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client);
   419         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client);
   403         gc.fillPolygon(points);
   420         gc.fillPolygon(points);
   404     }
   421     }
   405 
   422 
   406     void setClip(int x, int y, int w, int h, Graphics client)
   423     void setClip(int x, int y, int w, int h, Graphics client)
   407     {
   424     {
   408         validateAndApplySettings(COORS_TRANSLATION, client);
   425         validateAndApplySettings(COORDS_TRANSLATION, client);
   409         // check if given clip is already active in buffer
   426         // check if given clip is already active in buffer
   410         if((bufferClip.x == x) && (bufferClip.y == y) &&
   427         if((bufferClip.x == x) && (bufferClip.y == y) &&
   411                 (bufferClip.width == w) && (bufferClip.height== h))
   428                 (bufferClip.width == w) && (bufferClip.height== h))
   412         {
   429         {
   413             return;
   430             return;
   418             gc.setClip(x, y, w, h, false);
   435             gc.setClip(x, y, w, h, false);
   419             return;
   436             return;
   420         }
   437         }
   421 
   438 
   422         // translate clip to display coordinates and apply
   439         // translate clip to display coordinates and apply
   423         Rectangle rect = clipToDisplayCoords(x, y, w, h);
   440         Rectangle rect = clipToWindowCoords(x, y, w, h);
   424         if(rect.isEmpty())
   441         if(rect.isEmpty())
   425         {
   442         {
   426             // check is buffer clip is already up to date
   443             // check is buffer clip is already up to date
   427             if(bufferClip.isEmpty())
   444             if(bufferClip.isEmpty())
   428             {
   445             {
   450             bufferClip.height = h;
   467             bufferClip.height = h;
   451         }
   468         }
   452         gc.setClip(rect.x, rect.y, rect.width, rect.height, false);
   469         gc.setClip(rect.x, rect.y, rect.width, rect.height, false);
   453     }
   470     }
   454 
   471 
       
   472     void setGraphicsDefaults(Graphics client)
       
   473     {
       
   474     	validateAndApplySettings((FONT|COLOR|STROKESTYLE|COORDS_TRANSLATION|FORCE_SETTINGS), client);
       
   475     }
       
   476     
   455     void setColor(int r, int g, int b, Graphics client)
   477     void setColor(int r, int g, int b, Graphics client)
   456     {
   478     {
   457         // check if given color is already active in buffer
   479         // check if given color is already active in buffer
   458         if(bufferColor == (Graphics.OPAQUE_ALPHA | (r << 16) | (g << 8) | b))
   480         if(bufferColor == (Graphics.OPAQUE_ALPHA | (r << 16) | (g << 8) | b))
   459         {
   481         {
   501         bufferTranslateY += yDelta;
   523         bufferTranslateY += yDelta;
   502     }
   524     }
   503 
   525 
   504     void drawLine(int xStart, int yStart, int xEnd, int yEnd, Graphics client)
   526     void drawLine(int xStart, int yStart, int xEnd, int yEnd, Graphics client)
   505     {
   527     {
   506         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client);
   528         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client);
   507         gc.drawLine(xStart, yStart, xEnd, yEnd);
   529         gc.drawLine(xStart, yStart, xEnd, yEnd);
   508     }
   530     }
   509 
   531 
   510     void drawRect(int x, int y, int w, int h, Graphics client)
   532     void drawRect(int x, int y, int w, int h, Graphics client)
   511     {
   533     {
   512         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client);
   534         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client);
   513         gc.drawRect(x, y, w, h);
   535         gc.drawRect(x, y, w, h);
   514     }
   536     }
   515 
   537 
   516     void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH, Graphics client)
   538     void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH, Graphics client)
   517     {
   539     {
   518         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client);
   540         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client);
   519         gc.drawRoundRect(x, y, w, h, arcW, arcH);
   541         gc.drawRoundRect(x, y, w, h, arcW, arcH);
   520     }
   542     }
   521 
   543 
   522     void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle, Graphics client)
   544     void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle, Graphics client)
   523     {
   545     {
   524         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client);
   546         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client);
   525         gc.drawArc(x, y, w, h, startAngle, arcAngle);
   547         gc.drawArc(x, y, w, h, startAngle, arcAngle);
   526     }
   548     }
   527 
   549 
   528     void drawString(String string, int x, int y, Graphics client)
   550     void drawString(String string, int x, int y, Graphics client)
   529     {
   551     {
   530         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|FONT), client);
   552         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|FONT), client);
   531         gc.drawString(string, x, y, true);
   553         gc.drawString(string, x, y, true);
   532     }
   554     }
   533 
   555 
   534     void drawImage(org.eclipse.swt.internal.qt.graphics.Image image, int x,int y, Graphics client)
   556     void drawImage(org.eclipse.swt.internal.qt.graphics.Image image, int x,int y, Graphics client)
   535     {
   557     {
   536         validateAndApplySettings((CLIP|COORS_TRANSLATION), client);
   558         validateAndApplySettings((CLIP|COORDS_TRANSLATION), client);
   537         gc.drawImage(image, x, y);
   559         gc.drawImage(image, x, y);
   538     }
   560     }
   539 
   561 
   540     void drawImage(org.eclipse.swt.internal.qt.graphics.Image image, int xDst, int yDst,
   562     void drawImage(org.eclipse.swt.internal.qt.graphics.Image image, int xDst, int yDst,
   541                    int wDst, int hDst, int xSrc, int ySrc, int wSrc, int hSrc,
   563                    int wDst, int hDst, int xSrc, int ySrc, int wSrc, int hSrc,
   542                    int transform, Graphics client)
   564                    int transform, Graphics client)
   543     {
   565     {
   544         validateAndApplySettings((CLIP|COORS_TRANSLATION), client);
   566         validateAndApplySettings((CLIP|COORDS_TRANSLATION), client);
   545         gc.drawImage(image, xDst, yDst, wDst, hDst, xSrc, ySrc, wSrc, hSrc, transform);
   567         gc.drawImage(image, xDst, yDst, wDst, hDst, xSrc, ySrc, wSrc, hSrc, transform);
   546     }
   568     }
   547 
   569 
   548     void drawRGB(int[] rgb,
   570     void drawRGB(int[] rgb,
   549                  int offset,
   571                  int offset,
   553                  int w,
   575                  int w,
   554                  int h,
   576                  int h,
   555                  boolean alpha,
   577                  boolean alpha,
   556                  Graphics client)
   578                  Graphics client)
   557     {
   579     {
   558         validateAndApplySettings((CLIP|COORS_TRANSLATION), client);
   580         validateAndApplySettings((CLIP|COORDS_TRANSLATION), client);
   559         gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha);
   581         gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha);
   560     }
   582     }
   561 
   583 
   562     void drawRGB(int[] rgb,
   584     void drawRGB(int[] rgb,
   563                  int offset,
   585                  int offset,
   568                  int h,
   590                  int h,
   569                  boolean alpha,
   591                  boolean alpha,
   570                  int manipulation,
   592                  int manipulation,
   571                  Graphics client)
   593                  Graphics client)
   572     {
   594     {
   573         validateAndApplySettings((CLIP|COORS_TRANSLATION), client);
   595         validateAndApplySettings((CLIP|COORDS_TRANSLATION), client);
   574         gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha, manipulation);
   596         gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha, manipulation);
   575     }
   597     }
   576 
   598 
   577     void drawRGB(byte[] rgb,
   599     void drawRGB(byte[] rgb,
   578                  byte[] transparencyMask,
   600                  byte[] transparencyMask,
   584                  int h,
   606                  int h,
   585                  int manipulation,
   607                  int manipulation,
   586                  int format,
   608                  int format,
   587                  Graphics client)
   609                  Graphics client)
   588     {
   610     {
   589         validateAndApplySettings((CLIP|COORS_TRANSLATION), client);
   611         validateAndApplySettings((CLIP|COORDS_TRANSLATION), client);
   590         gc.drawRGB(rgb, transparencyMask, offset, scanlength, x, y, w, h, manipulation, format);
   612         gc.drawRGB(rgb, transparencyMask, offset, scanlength, x, y, w, h, manipulation, format);
   591     }
   613     }
   592 
   614 
   593     void drawRGB(short[] rgb,
   615     void drawRGB(short[] rgb,
   594                  int offset,
   616                  int offset,
   600                  boolean alpha,
   622                  boolean alpha,
   601                  int manipulation,
   623                  int manipulation,
   602                  int format,
   624                  int format,
   603                  Graphics client)
   625                  Graphics client)
   604     {
   626     {
   605         validateAndApplySettings((CLIP|COORS_TRANSLATION), client);
   627         validateAndApplySettings((CLIP|COORDS_TRANSLATION), client);
   606         gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha, manipulation, format);
   628         gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha, manipulation, format);
   607     }
   629     }
   608 
   630 
   609     void drawPolygon(int[] points, Graphics client)
   631     void drawPolygon(int[] points, Graphics client)
   610     {
   632     {
   611         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client);
   633         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client);
   612         gc.drawPolygon(points);
   634         gc.drawPolygon(points);
   613     }
   635     }
   614 
   636 
   615     void fillPolygon(int[] points, Graphics client)
   637     void fillPolygon(int[] points, Graphics client)
   616     {
   638     {
   617         validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client);
   639         validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client);
   618         gc.fillPolygon(points);
   640         gc.fillPolygon(points);
   619     }
   641     }
   620 
   642 
   621     void setARGBColor(int argb, Graphics client)
   643     void setARGBColor(int argb, Graphics client)
   622     {
   644     {
   656     WindowSurface getWindowSurface()
   678     WindowSurface getWindowSurface()
   657     {
   679     {
   658         return null;
   680         return null;
   659     }
   681     }
   660     
   682     
   661     /**
   683     boolean containsDrawnPrimitives() {
   662      * Translates given rectangle to display/window surface coordinates
   684         boolean result = false;
       
   685         if(commandBuffer != null) {
       
   686             result = commandBuffer.containsDrawnPrimitives();
       
   687         }
       
   688         return result;
       
   689     }
       
   690     
       
   691     /**
       
   692      * Translates given rectangle to window surface coordinates
   663      * and outlines the clip inside the control bounds.
   693      * and outlines the clip inside the control bounds.
   664      *
   694      *
   665      * @param x The x-coordinate of the rectangle
   695      * @param x The x-coordinate of the rectangle
   666      * @param y The y-coordinate of the rectangle
   696      * @param y The y-coordinate of the rectangle
   667      * @param w The width of the rectangle
   697      * @param w The width of the rectangle
   668      * @param h The height of the rectangle
   698      * @param h The height of the rectangle
   669      *
   699      *
   670      */
   700      */
   671     private Rectangle clipToDisplayCoords(int x, int y, int w, int h)
   701     private Rectangle clipToWindowCoords(int x, int y, int w, int h)
   672     {
   702     {
   673         // Bottom-right corner of control bounds in window coordinates
   703         // Bottom-right corner of control bounds in window coordinates
   674         final int hostX2 = hostBounds.x + hostBounds.width;
   704         final int hostX2 = hostBounds.x + hostBounds.width;
   675         final int hostY2 = hostBounds.y + hostBounds.height;
   705         final int hostY2 = hostBounds.y + hostBounds.height;
   676         // clip in window coordinates
   706         // clip in window coordinates
   699         clipX2 = clipX2Dpy < hostBounds.x ? (clipX2 + (hostBounds.x - clipX1Dpy)) : clipX2;
   729         clipX2 = clipX2Dpy < hostBounds.x ? (clipX2 + (hostBounds.x - clipX1Dpy)) : clipX2;
   700         clipX2 = clipX2Dpy > hostX2 ? (clipX2 - (clipX1Dpy - hostX2)) : clipX2;
   730         clipX2 = clipX2Dpy > hostX2 ? (clipX2 - (clipX1Dpy - hostX2)) : clipX2;
   701         clipY2 = clipY2Dpy < hostBounds.y ? (clipY2 + (hostBounds.y - clipY1Dpy)) : clipY2;
   731         clipY2 = clipY2Dpy < hostBounds.y ? (clipY2 + (hostBounds.y - clipY1Dpy)) : clipY2;
   702         clipY2 = clipY2Dpy > hostY2 ? (clipY2 - (clipY1Dpy - hostY2)) : clipY2;
   732         clipY2 = clipY2Dpy > hostY2 ? (clipY2 - (clipY1Dpy - hostY2)) : clipY2;
   703 
   733 
   704         return new Rectangle(clipX1, clipY1, (clipX2 - clipX1) , (clipY1 - clipY2));
   734         return new Rectangle(clipX1, clipY1, (clipX2 - clipX1) , (clipY2 - clipY1));
   705     }
   735     }
   706 
   736 
   707     /**
   737     /**
   708      * Validates the current settings active in buffer against
   738      * Validates the current settings active in buffer against
   709      * caller settings and updated needed settings in buffer when
   739      * caller settings and updated needed settings in buffer when
   713      * @param flags The settings that need to be checked
   743      * @param flags The settings that need to be checked
   714      * @param client The Graphics instance that made the call
   744      * @param client The Graphics instance that made the call
   715      */
   745      */
   716     private void validateAndApplySettings(int flags, Graphics client)
   746     private void validateAndApplySettings(int flags, Graphics client)
   717     {
   747     {
   718         if(!clientChanged(client))
   748         if(!clientChanged(client) && (FORCE_SETTINGS & flags) == 0)
   719         {
   749         {
   720             return;
   750             return;
   721         }
   751         }
   722         if((COLOR & flags) != 0)
   752         if((COLOR & flags) != 0)
   723         {
   753         {
   734                     client.currentClip[1] != bufferClip.y &&
   764                     client.currentClip[1] != bufferClip.y &&
   735                     client.currentClip[2] != bufferClip.width &&
   765                     client.currentClip[2] != bufferClip.width &&
   736                     client.currentClip[3] != bufferClip.height)
   766                     client.currentClip[3] != bufferClip.height)
   737             {
   767             {
   738 
   768 
   739                 Rectangle rect = clipToDisplayCoords(client.currentClip[0], client.currentClip[1],
   769                 Rectangle rect = clipToWindowCoords(client.currentClip[0], client.currentClip[1],
   740                                                      client.currentClip[2], client.currentClip[3]);
   770                                                      client.currentClip[2], client.currentClip[3]);
   741                 gc.setClip(rect.x, rect.y, rect.width, rect.height, false);
   771                 gc.setClip(rect.x, rect.y, rect.width, rect.height, false);
   742                 bufferClip.x = client.currentClip[0];
   772                 bufferClip.x = client.currentClip[0];
   743                 bufferClip.y = client.currentClip[1];
   773                 bufferClip.y = client.currentClip[1];
   744                 bufferClip.width = client.currentClip[2];
   774                 bufferClip.width = client.currentClip[2];
   745                 bufferClip.height = client.currentClip[3];
   775                 bufferClip.height = client.currentClip[3];
   746             }
   776             }
   747         }
   777         }
   748         if((COORS_TRANSLATION & flags) != 0)
   778         if((COORDS_TRANSLATION & flags) != 0)
   749         {
   779         {
   750             if((bufferTranslateX != client.translateX) && (bufferTranslateY != client.translateY))
   780             if((bufferTranslateX != client.translateX) && (bufferTranslateY != client.translateY))
   751             {
   781             {
   752                 gc.translate((client.translateX - bufferTranslateX), (client.translateY - bufferTranslateY));
   782                 gc.translate((client.translateX - bufferTranslateX), (client.translateY - bufferTranslateY));
   753                 bufferTranslateX = client.translateX;
   783                 bufferTranslateX = client.translateX;
   813         }
   843         }
   814     }
   844     }
   815 
   845 
   816    /**
   846    /**
   817     * Writes Graphics default values to buffer
   847     * Writes Graphics default values to buffer
       
   848     * @param force If true defaults are written unconditionally to buffer, 
       
   849     *              otherwise only values that different than the ones in buffer
       
   850     *              are written
   818     */
   851     */
   819     private void writeDefaultValuesToBuffer()
   852     private void writeDefaultValuesToBuffer()
   820     {
   853     {
   821         int handle = Font.getESWTFont(defaultFont).handle;
   854         int handle = Font.getESWTFont(defaultFont).handle;
   822         gc.setFont(handle);
   855         gc.setFont(handle);