MCPcopy Index your code
hub / github.com/benfry/processing4 / beginDraw

Method beginDraw

core/src/processing/awt/PGraphicsJava2D.java:308–387  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

306
307
308 @Override
309 public void beginDraw() {
310 g2 = checkImage();
311
312 // Calling getGraphics() seems to nuke several settings.
313 // It seems to be re-creating a new Graphics2D object each time.
314 // https://github.com/processing/processing/issues/3331
315 if (strokeObject != null) {
316 g2.setStroke(strokeObject);
317 }
318 // https://github.com/processing/processing/issues/2617
319 if (textFont != null) {
320 Font fontObject = (Font) textFont.getNative();
321 if (fontObject != null) {
322 g2.setFont(fontObject);
323 }
324 }
325 // https://github.com/processing/processing/issues/4019
326 if (blendMode != 0) {
327 blendMode(blendMode);
328 }
329 handleSmooth();
330
331 /*
332 // NOTE: Calling image.getGraphics() will create a new Graphics context,
333 // even if it's for the same image that's already had a context created.
334 // Seems like a speed/memory issue, and also requires that all smoothing,
335 // stroke, font and other props be reset. Can't find a good answer about
336 // whether getGraphics() and dispose() on each frame is 1) better practice
337 // and 2) minimal overhead, however. Instinct suggests #1 may be true,
338 // but #2 seems a problem.
339 if (primarySurface && !useOffscreen) {
340 GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
341 if (false) {
342 if (image == null || ((VolatileImage) image).validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
343 image = gc.createCompatibleVolatileImage(width, height);
344 g2 = (Graphics2D) image.getGraphics();
345 reapplySettings = true;
346 }
347 } else {
348 if (image == null) {
349 image = gc.createCompatibleImage(width, height);
350 PApplet.debug("created new image, type is " + image);
351 g2 = (Graphics2D) image.getGraphics();
352 reapplySettings = true;
353 }
354 }
355 }
356
357 if (useCanvas && primarySurface) {
358 if (parent.frameCount == 0) {
359 canvas.createBufferStrategy(2);
360 strategy = canvas.getBufferStrategy();
361 PApplet.debug("PGraphicsJava2D.beginDraw() strategy is " + strategy);
362 BufferCapabilities caps = strategy.getCapabilities();
363 caps = strategy.getCapabilities();
364 PApplet.debug("PGraphicsJava2D.beginDraw() caps are " +
365 " flipping: " + caps.isPageFlipping() +

Callers 1

svgToImageMethod · 0.95

Calls 7

checkImageMethod · 0.95
handleSmoothMethod · 0.95
resetMatrixMethod · 0.95
getNativeMethod · 0.65
setStrokeMethod · 0.45
blendModeMethod · 0.45
checkSettingsMethod · 0.45

Tested by

no test coverage detected