Guest
Public paste!

Clemens Eisserer

By: a guest | Jan 3rd, 2009 | Syntax: Java | Size: 1.51 KB | Hits: 40 | Expires: Never
Copy text to clipboard
  1. public static void main(String[] args) {
  2.         XRRenderQueue queue = new XRRenderQueue(false);
  3.         queue.socketTaken = true;
  4.  
  5.         while (true) {
  6.             long start = System.currentTimeMillis();
  7.             for (int i = 0; i < 1000000; i++) {
  8.                 // SunToolkit.awtLock();
  9.                 try {
  10.                     queue.XRenderRectangle((int) start, XRUtils.PictOpAdd, XRColor.FULL_ALPHA, i, i, i, i);
  11.                 } finally {
  12.                    //  SunToolkit.awtUnlock();
  13.                 }
  14.             }
  15.             long end = System.currentTimeMillis();
  16.             System.out.println("Took: " + (end - start));
  17.         }
  18.     }
  19.  
  20.  
  21. public  final void XRenderRectangle(int dst, byte op, XRColor color, int x, int y, int width, int height) {
  22.         prepareRequest(28);
  23.  
  24.         putRequestHeader(MAJOR_RENDER, FILL_RECTANGLES, 7);
  25.         buf.putByte(op);
  26.         buf.skip(3);
  27.         buf.putInt(dst);
  28.         color.writeToBuffer(buf);
  29.        
  30.         buf.putShort((short) x);
  31.         buf.putShort((short) (y));
  32.         buf.putShort((short) (width));
  33.         buf.putShort((short) (height));
  34.     }  
  35.  
  36.  public final RenderBuffer putByte(byte x) {
  37.         unsafe.putByte(curAddress, x);
  38.         curAddress += SIZEOF_BYTE;
  39.         return this;
  40.     }
  41.  
  42.     public final void prepareRequest(int opsize) {
  43.         if (buf.remaining() < opsize) {
  44.             flush(false);
  45.         }
  46.  
  47.         checkSocketAccess();
  48.         requestCount++;
  49.     }
  50.  
  51.     protected void checkSocketAccess() {
  52.         if (!socketTaken) {
  53.             flushThread.takeSocket();
  54.             socketTaken = true;
  55.         }
  56.     }
  57.  
  58.     public void flush(boolean sync) {
  59.         buf.clear();
  60.         requestCount = 0;
  61.     }
  62.  
  63.     public final void clear() {
  64.         curAddress = baseAddress;
  65.     }