diff --git a/android/src/playn/android/AndroidGraphics.java b/android/src/playn/android/AndroidGraphics.java index 47369264..8621d770 100644 --- a/android/src/playn/android/AndroidGraphics.java +++ b/android/src/playn/android/AndroidGraphics.java @@ -158,7 +158,12 @@ public void onSurfaceLost () { @Override public Canvas createCanvas (float width, float height) { Scale scale = canvasScaleFunc.computeScale(width, height, scale()); - return createCanvasImpl(scale, scale.scaledCeil(width), scale.scaledCeil(height)); + return createCanvas(scale, scale.scaledCeil(width), scale.scaledCeil(height)); + } + + @Override public Canvas createCanvas(Scale scale, int pixelWidth, int pixelHeight) { + Bitmap bitmap = Bitmap.createBitmap(pixelWidth, pixelHeight, preferredBitmapConfig); + return new AndroidCanvas(this, new AndroidImage(this, scale, bitmap, "")); } @Override public Path createPath() { @@ -177,11 +182,6 @@ public void onSurfaceLost () { return AndroidTextLayout.layoutText(this, text, format, wrap); } - @Override protected Canvas createCanvasImpl(Scale scale, int pixelWidth, int pixelHeight) { - Bitmap bitmap = Bitmap.createBitmap(pixelWidth, pixelHeight, preferredBitmapConfig); - return new AndroidCanvas(this, new AndroidImage(this, scale, bitmap, "")); - } - AndroidFont resolveFont(Font font) { if (font == null) return AndroidFont.DEFAULT; Pair key = Pair.create(font.name, font.style); diff --git a/core/src/playn/core/Graphics.java b/core/src/playn/core/Graphics.java index 235be6e4..5f33007b 100644 --- a/core/src/playn/core/Graphics.java +++ b/core/src/playn/core/Graphics.java @@ -103,7 +103,7 @@ public void close () {} // disable normal dispose-on-close behavior * Creates a {@link Canvas} with the specified display unit size. */ public Canvas createCanvas (float width, float height) { - return createCanvasImpl(scale, scale.scaledCeil(width), scale.scaledCeil(height)); + return createCanvas(scale, scale.scaledCeil(width), scale.scaledCeil(height)); } /** See {@link #createCanvas(float,float)}. */ @@ -111,6 +111,14 @@ public Canvas createCanvas (IDimension size) { return createCanvas(size.width(), size.height()); } + /** + * Creates a {@link Canvas} at the specified scale and with the specified (pixel) width and + * height. Most callers should use {@link #createCanvas(float,float)} rather than this method, + * but if you have special needs, this gives you full control over the size of the canvas's + * underlying bitmap. + */ + public abstract Canvas createCanvas (Scale scale, int pixelWidth, int pixelHeight); + /** Creates a {@link Path} object. */ public abstract Path createPath (); @@ -174,13 +182,6 @@ protected Graphics (Platform plat, GL20 gl, Scale scale) { */ protected int defaultFramebuffer () { return 0; } - /** - * Creates a {@link Canvas} with the specified pixel size. Because this is used when scaling - * bitmaps for rendering into POT textures, we need to be precise about the pixel width and - * height. So make sure this code path uses these exact sizes to make the canvas backing buffer. - */ - protected abstract Canvas createCanvasImpl (Scale scale, int pixelWidth, int pixelHeight); - /** * Informs the graphics system that the main framebuffer scaled has changed. */ diff --git a/core/src/playn/core/Texture.java b/core/src/playn/core/Texture.java index 3aa6e075..f3af46e0 100644 --- a/core/src/playn/core/Texture.java +++ b/core/src/playn/core/Texture.java @@ -159,7 +159,7 @@ public void update (Image image) { int pixWidth = image.pixelWidth(), pixHeight = image.pixelHeight(); int potWidth = config.toTexWidth(pixWidth), potHeight = config.toTexWidth(pixHeight); if (potWidth != pixWidth || potHeight != pixHeight) { - Canvas scaled = gfx.createCanvasImpl(Scale.ONE, potWidth, potHeight); + Canvas scaled = gfx.createCanvas(Scale.ONE, potWidth, potHeight); scaled.draw(image, 0, 0, potWidth, potHeight); scaled.image.upload(gfx, this); scaled.close(); diff --git a/html/src/playn/html/HtmlGraphics.java b/html/src/playn/html/HtmlGraphics.java index 999b673f..9eba20ec 100644 --- a/html/src/playn/html/HtmlGraphics.java +++ b/html/src/playn/html/HtmlGraphics.java @@ -177,6 +177,13 @@ public void registerFontMetrics(String name, Font font, float lineHeight) { return screenSize; } + @Override public Canvas createCanvas(Scale scale, int pixelWidth, int pixelHeight) { + CanvasElement elem = Document.get().createCanvasElement(); + elem.setWidth(pixelWidth); + elem.setHeight(pixelHeight); + return new HtmlCanvas(this, new HtmlImage(this, scale, elem, "")); + } + @Override public Path createPath() { return new HtmlPath(); } @@ -193,13 +200,6 @@ public void registerFontMetrics(String name, Font font, float lineHeight) { return HtmlTextLayout.layoutText(this, dummyCtx, text, format, wrap); } - @Override protected Canvas createCanvasImpl(Scale scale, int pixelWidth, int pixelHeight) { - CanvasElement elem = Document.get().createCanvasElement(); - elem.setWidth(pixelWidth); - elem.setHeight(pixelHeight); - return new HtmlCanvas(this, new HtmlImage(this, scale, elem, "")); - } - static String cssColorString(int color) { double a = ((color >> 24) & 0xff) / 255.0; int r = (color >> 16) & 0xff; diff --git a/java-base/src/playn/java/JavaGraphics.java b/java-base/src/playn/java/JavaGraphics.java index 85067d83..07fe704e 100644 --- a/java-base/src/playn/java/JavaGraphics.java +++ b/java-base/src/playn/java/JavaGraphics.java @@ -80,6 +80,12 @@ public void registerFont (String name, java.awt.Font font) { */ public abstract void setSize (int width, int height, boolean fullscreen); + @Override public Canvas createCanvas (Scale scale, int pixelWidth, int pixelHeight) { + BufferedImage bitmap = new BufferedImage( + pixelWidth, pixelHeight, BufferedImage.TYPE_INT_ARGB_PRE); + return new JavaCanvas(this, new JavaImage(this, scale, bitmap, "")); + } + @Override public Path createPath() { return new JavaPath(); @@ -99,12 +105,6 @@ public Path createPath() { return JavaTextLayout.layoutText(this, text, format, wrap); } - @Override protected Canvas createCanvasImpl (Scale scale, int pixelWidth, int pixelHeight) { - BufferedImage bitmap = new BufferedImage( - pixelWidth, pixelHeight, BufferedImage.TYPE_INT_ARGB_PRE); - return new JavaCanvas(this, new JavaImage(this, scale, bitmap, "")); - } - java.awt.Font resolveFont(Font font) { java.awt.Font jfont = fonts.get(font.name); // if we don't have a custom font registered for this name, assume it's a platform font diff --git a/robovm/src/playn/robovm/RoboGraphics.java b/robovm/src/playn/robovm/RoboGraphics.java index a0d29e6f..73039f91 100644 --- a/robovm/src/playn/robovm/RoboGraphics.java +++ b/robovm/src/playn/robovm/RoboGraphics.java @@ -85,6 +85,11 @@ public RoboGraphics(Platform plat, RoboPlatform.Config config, CGRect bounds) { return screenSize; } + @Override public Canvas createCanvas (Scale scale, int pixelWidth, int pixelHeight) { + return new RoboCanvas(this, new RoboCanvasImage(this, scale, pixelWidth, pixelHeight, + config.interpolateCanvasDrawing)); + } + @Override public Path createPath() { return new RoboPath(); } @@ -105,11 +110,6 @@ public RoboGraphics(Platform plat, RoboPlatform.Config config, CGRect bounds) { @Override protected int defaultFramebuffer () { return defaultFramebuffer; } - @Override protected Canvas createCanvasImpl (Scale scale, int pixelWidth, int pixelHeight) { - return new RoboCanvas(this, new RoboCanvasImage(this, scale, pixelWidth, pixelHeight, - config.interpolateCanvasDrawing)); - } - static CGBitmapContext createCGBitmap(int width, int height) { return CGBitmapContext.create(width, height, 8, 4 * width, colorSpace, new CGBitmapInfo( CGImageAlphaInfo.PremultipliedLast.value()));