#1164 Active rendering

Akcelisto Fri 30 Jul 2010

In swing there is active rendering.

using [java]java.awt::Canvas
using [java]java.awt::Graphics2D
using [java]java.awt::Toolkit
using [java]java.awt::Color
using [java]java.awt.image::BufferStrategy
using [java]javax.swing::JFrame
using [java]javax.swing::WindowConstants
using [java]java.lang::Thread
using [java]java.lang::System
using concurrent::Actor

class ActiveRendering{
  private BufferStrategy bStrategy
  private Graphics2D g

  new make(){
    System.setProperty("sun.java2d.translaccel", "true")
    System.setProperty("sun.java2d.ddforcevram", "true")
    System.setProperty("sun.java2d.opengl", "true")

    frm := JFrame()
    frm.setIgnoreRepaint(true)
    frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)

    canvas := Canvas()
    frm.add(canvas)
    canvas.setSize(120,120)
    frm.pack
    frm.setVisible(true)

    canvas.createBufferStrategy(2)
    bStrategy = canvas.getBufferStrategy
    g = bStrategy.getDrawGraphics
  }

  Void start(){
    Thread(|->|{
      while(true){
        g = bStrategy.getDrawGraphics
        // here work with g
        g.fillRect(0,0,120,120)
        g.setColor(Color.WHITE)
        g.fillRect(10,10,100,100)
        // ...
        bStrategy.show
        Toolkit.getDefaultToolkit.sync
        Actor.sleep(200ms)
      }
    }).start
    Actor.sleep(Duration.maxVal)
  }
  static Void main(){
    ActiveRendering().start
  }
}

But in fwt active rendering is not available... :(

brian Fri 30 Jul 2010

I think some of that is covered in #1156 with the ability to use buffered images as a graphics context.

I am not sure if SWT provides some of the hooks into hardware acceleration that Swing does. Although like everything with Swing, my experience with those features in Swing have not left a very good impression. In production we always had to turn that stuff off because it was so buggy.

Login or Signup to reply.