sclass VolatileImageSurfaceDemo is Swingable {
  new Timings timings;
  JLabel lblTimings = jlabel();
  JVolatileImageSurface surface;
  
  settable Renderable renderable = (g, w, h) -> {
    time("background", -> {
      g.setColor(Color.green);
      g.fillRect(0, 0, w, h);
    });
    time("circle", ->
      fillCircle(g, w/2, h/2, w/4, Color.blue));
  };
  
  visualize {
    surface = new JVolatileImageSurface(renderable);

    awtDoEvery(lblTimings, 1.0, -> lblTimings.setText(timings.toStringSingleLine()));
    
   JCheckBox cbVolatileMode = jCheckBox(true, "Use volatile image", b -> surface.setVolatileMode(b));
   
   ret northCenterAndSouthWithMargin(
     jcenteredline(cbVolatileMode),
     surface,
     lblTimings);
  }
  
  void time(S name, Runnable r) {
    S mode = surface.volatileMode() ? " [vol]" : "";
    timings.time(name + mode, r);
  }
}