Commit 3f5a8a44 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

MIDP 2 does not preserve the GameCanvas buffer; Add fill color for canvases.

parent 1fd28e04
Pipeline #89963 passed with stages
in 5 minutes and 58 seconds
......@@ -25,12 +25,10 @@ public final class DoubleBuffer
.getGraphics());
/** The off-screen buffer. */
private final SingleBuffer _offScreen =
new SingleBuffer();
private final SingleBuffer _offScreen;
/** The on-screen buffer. */
private final SingleBuffer _onScreen =
new SingleBuffer();
private final SingleBuffer _onScreen;
/** The last used width. */
private volatile int _lastWidth =
......@@ -40,6 +38,29 @@ public final class DoubleBuffer
private volatile int _lastHeight =
-1;
/**
* Initializes the double buffer.
*
* @param __resizeFillColor The color to set when resizing, this is to
* prevent skewed graphics from appearing.
* @since 2022/02/25
*/
public DoubleBuffer(int __resizeFillColor)
{
this._offScreen = new SingleBuffer(__resizeFillColor);
this._onScreen = new SingleBuffer(0);
}
/**
* Clears the off-screen buffer.
*
* @since 2022/02/25
*/
public void clear()
{
this._offScreen.clear();
}
/**
* Flushes the off-screen buffer to be on-screen.
*
......
......@@ -279,9 +279,9 @@ public final class ProxyGraphics
* @since 2022/02/25
*/
@Override
public void fillRect(int __a, int __b, int __c, int __d)
public void fillRect(int __x, int __y, int __w, int __h)
{
this.__graphics().fillRect(__a, __b, __c, __d);
this.__graphics().fillRect(__x, __y, __w, __h);
}
/**
......
......@@ -9,7 +9,6 @@
package cc.squirreljme.runtime.lcdui.gfx;
import cc.squirreljme.jvm.mle.constants.UIPixelFormat;
import cc.squirreljme.runtime.cldc.debug.Debugging;
import cc.squirreljme.runtime.lcdui.mle.PencilGraphics;
import java.util.Arrays;
import javax.microedition.lcdui.Graphics;
......@@ -21,6 +20,9 @@ import javax.microedition.lcdui.Graphics;
*/
public final class SingleBuffer
{
/** The color to fill with on resizes. */
private final int fillColor;
/** Available pixels. */
private volatile int[] _pixels =
new int[1];
......@@ -33,6 +35,27 @@ public final class SingleBuffer
private volatile int _height =
1;
/**
* Initializes the single buffer.
*
* @param __resizeFillColor The color to fill with when resizing.
* @since 2022/02/25
*/
public SingleBuffer(int __resizeFillColor)
{
this.fillColor = __resizeFillColor;
}
/**
* Clears the buffer to the fill color.
*
* @since 2022/02/25
*/
public void clear()
{
Arrays.fill(this._pixels, this.fillColor);
}
/**
* Copies from the source buffer.
*
......@@ -95,7 +118,12 @@ public final class SingleBuffer
int currentLimit = pixels.length;
int wantedArea = __width * __height;
if (wantedArea > currentLimit)
this._pixels = (pixels = Arrays.copyOf(pixels, wantedArea));
{
this._pixels = (pixels = new int[wantedArea]);
// Fill resized area accordingly
Arrays.fill(pixels, this.fillColor);
}
// Set new parameters
this._width = __width;
......
......@@ -51,7 +51,7 @@ public abstract class GameCanvas
/** The double buffered image. */
private final DoubleBuffer _doubleBuffer =
new DoubleBuffer();
new DoubleBuffer(0xFFFFFFFF);
/**
* Initializes the game canvas.
......@@ -64,7 +64,7 @@ public abstract class GameCanvas
*/
protected GameCanvas(boolean __suppressGameKeys)
{
this(__suppressGameKeys, true);
this(__suppressGameKeys, false);
}
/**
......@@ -171,7 +171,12 @@ public abstract class GameCanvas
private void __flip()
{
// Flush off-screen to on-screen
this._doubleBuffer.flush();
DoubleBuffer doubleBuffer = this._doubleBuffer;
doubleBuffer.flush();
// If we are not preserving the buffer, clear to white
if (!this._preserveBuffer)
doubleBuffer.clear();
// Signal and wait for refresh
super.repaint(0, 0, this.getWidth(), this.getHeight());
......
......@@ -25,7 +25,7 @@ final class __MIDPCanvas__
/** Double buffered image for drawing operations. */
final DoubleBuffer _doubleBuffer =
new DoubleBuffer();
new DoubleBuffer(0xFFFFFFFF);
/**
* Initializes the base canvas.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment