| 228 | |
| 229 | |
| 230 | synchronized protected void render() { |
| 231 | if (canvas.isDisplayable() && |
| 232 | graphics.image != null) { |
| 233 | if (canvas.getBufferStrategy() == null) { |
| 234 | canvas.createBufferStrategy(2); |
| 235 | } |
| 236 | BufferStrategy strategy = canvas.getBufferStrategy(); |
| 237 | if (strategy != null) { |
| 238 | // Render single frame |
| 239 | do { |
| 240 | // The following loop ensures that the contents of the drawing buffer |
| 241 | // are consistent in case the underlying surface was recreated |
| 242 | do { |
| 243 | Graphics2D draw = (Graphics2D) strategy.getDrawGraphics(); |
| 244 | // draw to width/height, since this may be a 2x image |
| 245 | draw.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null); |
| 246 | draw.dispose(); |
| 247 | } while (strategy.contentsRestored()); |
| 248 | |
| 249 | // Display the buffer |
| 250 | strategy.show(); |
| 251 | |
| 252 | // Repeat the rendering if the drawing buffer was lost |
| 253 | } while (strategy.contentsLost()); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | |
| 259 | @Override |