diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07633181..44a05b16 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,10 +120,10 @@ jobs: with: name: linux-x64-jars path: target - - uses: actions/download-artifact@v3 - with: - name: linux-arm64-jars - path: target + # - uses: actions/download-artifact@v3 + # with: + # name: linux-arm64-jars + # path: target - uses: actions/download-artifact@v3 with: name: windows-x64-jars diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bba316c..dec86cf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,14 @@ Changed: - `Image::makeRasterPixmap(Pixmap)` -> `makeRasterFromPixmap` - `Image::makeFromEncoded(byte[])` -> `makeDeferredFromEncodedBytes` - `Image::encodeToData` has been replaced with `EncoderJPEG`, `EncoderPNG`, `EncoderWEBP`, plus the encoding options +- `Surface::makeRasterDirect` -> `wrapPixels` +- `Surface::makeFromBackendRenderTarget` -> `wrapBackendRenderTarget` +- `Surface::makeFromMTKView` -> `wrapMTKView` + +Deprecated: + +- `Surface::makeRasterN32Premul` +- `EncodedImageFormat` Removed: diff --git a/examples/scenes/src/BitmapImageScene.java b/examples/scenes/src/BitmapImageScene.java index 2ce309c3..71952b9e 100644 --- a/examples/scenes/src/BitmapImageScene.java +++ b/examples/scenes/src/BitmapImageScene.java @@ -15,7 +15,7 @@ public class BitmapImageScene extends Scene { public BitmapImageScene() { try { - image = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/IMG_7098.jpeg")))); + image = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/IMG_7098.jpeg")))); } catch (IOException e) { throw new RuntimeException(e); } @@ -48,7 +48,7 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int try (var bitmap = new Bitmap();) { bitmap.allocPixels(ImageInfo.makeS32(400, 400, ColorAlphaType.OPAQUE)); image.readPixels(bitmap); - try (var image = Image.makeFromBitmap(bitmap.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(bitmap.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(0, 0, 200, 200)); } canvas.drawString("Image.readPixels", 0, 220, inter13, blackFill); @@ -59,7 +59,7 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int try (var bitmap = new Bitmap();) { bitmap.allocPixels(new ImageInfo(300, 300, ColorType.RGBA_8888, ColorAlphaType.OPAQUE)); image.readPixels(bitmap, 50, 50); - try (var image = Image.makeFromBitmap(bitmap.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(bitmap.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(25, 25, 150, 150)); } canvas.drawString("Image.readPixels(50, 50)", 0, 220, inter13, blackFill); @@ -75,7 +75,7 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int pixels = bitmap.readPixels(); pixelSorting(canvas, ByteBuffer.wrap(pixels), info); bitmap.installPixels(pixels); - try (var image = Image.makeFromBitmap(bitmap.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(bitmap.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(0, 0, 200, 200)); } canvas.drawString("Bitmap.readPixels/installPixels", 0, 220, inter13, blackFill); @@ -85,24 +85,24 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int // Bitmap peekPixels try (var bitmap = Bitmap.makeFromImage(image);) { pixelSorting(canvas, bitmap.peekPixels(), bitmap.getImageInfo()); - try (var image = Image.makeFromBitmap(bitmap.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(bitmap.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(0, 0, 200, 200)); } canvas.drawString("Bitmap.peekPixels", 0, 220, inter13, blackFill); advance(canvas, width); } - // Image.makeRaster - try (var imageFromPixels = Image.makeRaster(info, pixels, info.getMinRowBytes());) { + // Image.makeRasterFromBytes + try (var imageFromPixels = Image.makeRasterFromBytes(info, pixels, info.getMinRowBytes());) { canvas.drawImageRect(imageFromPixels, Rect.makeXYWH(0, 0, 200, 200)); - canvas.drawString("Image.makeRaster", 0, 220, inter13, blackFill); + canvas.drawString("Image.makeRasterFromBytes", 0, 220, inter13, blackFill); advance(canvas, width); } - // Image.makeRaster + Data - try (var imageFromData = Image.makeRaster(info, Data.makeFromBytes(pixels), info.getMinRowBytes());) { + // Image.makeRasterFromData + try (var imageFromData = Image.makeRasterFromData(info, Data.makeFromBytes(pixels), info.getMinRowBytes());) { canvas.drawImageRect(imageFromData, Rect.makeXYWH(0, 0, 200, 200)); - canvas.drawString("Image.makeRaster + Data", 0, 220, inter13, blackFill); + canvas.drawString("Image.makeRasterFromBytes + Data", 0, 220, inter13, blackFill); advance(canvas, width); } } diff --git a/examples/scenes/src/BitmapScene.java b/examples/scenes/src/BitmapScene.java index acf5bea2..98aa7cd5 100644 --- a/examples/scenes/src/BitmapScene.java +++ b/examples/scenes/src/BitmapScene.java @@ -41,7 +41,7 @@ private void drawGray(Canvas canvas, IRect target, float dpi) { try (Bitmap bitmap = new Bitmap();) { bitmap.allocPixels(new ImageInfo((int) (target.getWidth() * dpi), (int) (target.getHeight() * dpi), ColorType.GRAY_8, ColorAlphaType.OPAQUE)); if (canvas.readPixels(bitmap, (int) ((target.getLeft() - 10) * dpi), (int) ((target.getTop() - 10) * dpi))) { - try (Image image = Image.makeFromBitmap(bitmap.setImmutable())) { + try (Image image = Image.makeRasterFromBitmap(bitmap.setImmutable())) { canvas.drawImageRect(image, target.toRect()); } } @@ -108,7 +108,7 @@ private void drawBitmapCanvas(Canvas canvas, IRect target, float dpi) { .closePath(); canvas2.drawPath(path, stroke); - try (Image image = Image.makeFromBitmap(bitmap.setImmutable())) { + try (Image image = Image.makeRasterFromBitmap(bitmap.setImmutable())) { canvas.drawImageRect(image, target.toRect()); } } @@ -148,7 +148,7 @@ public void drawPixels(Canvas canvas, IRect target, IRect screen, float dpi) { bitmap.installPixels(dstInfo, pixels, rowBytes); bitmap.notifyPixelsChanged(); - try (var image = Image.makeFromBitmap(bitmap.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(bitmap.setImmutable());) { canvas.drawImageRect(image, inner.toRect()); } } @@ -167,7 +167,7 @@ public void drawSubset(Canvas canvas, IRect target, IRect screen, float dpi) { src.allocPixels(srcInfo); if (canvas.readPixels(src, (int) (target.getLeft() * dpi), (int) (target.getTop() * dpi))) { src.extractSubset(dst, Rect.makeXYWH(target.getWidth() / 4 * dpi, target.getHeight() / 4 * dpi, target.getWidth() / 2 * dpi, target.getHeight() / 2 * dpi).toIRect()); - try (var image = Image.makeFromBitmap(dst.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(dst.setImmutable());) { canvas.drawImageRect(image, target.toRect()); } } @@ -188,7 +188,7 @@ public void drawPixelRef(Canvas canvas, IRect target, IRect screen, float dpi) { var pixelRef = src.getPixelRef(); dst.setImageInfo(info.withWidthHeight((int) (target.getWidth() / 2 * dpi), (int) (target.getHeight() / 2 * dpi))); dst.setPixelRef(pixelRef, (int) (target.getWidth() / 4 * dpi), (int) (target.getHeight() / 4 * dpi)); - try (var image = Image.makeFromBitmap(dst.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(dst.setImmutable());) { canvas.drawImageRect(image, target.toRect()); } } @@ -212,12 +212,12 @@ public void drawAlpha(Canvas canvas, IRect target, IRect screen, float dpi) { int color = (alpha << 24) | (alpha << 16) | (0 << 8) | (255 - alpha); src.erase(color, IRect.makeXYWH(x, 0, 1, (int) (target.getHeight() / 2 * dpi))); } - try (var image = Image.makeFromBitmap(src.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(src.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(target.getLeft(), target.getTop(), target.getWidth(), target.getHeight() / 2)); } if (src.extractAlpha(dst)) { - try (var image = Image.makeFromBitmap(dst.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(dst.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(target.getLeft(), target.getTop() + target.getHeight() / 2, target.getWidth(), target.getHeight() / 2)); } } @@ -238,7 +238,7 @@ public void drawErase(Canvas canvas, IRect target, IRect screen, float dpi) { src.erase(red); var color = src.getColor4f((int) (w / 2 * dpi), (int) (h / 2 * dpi)); assert new Color4f(1, 0, 0).equals(color) : "Expected " + new Color4f(1, 0, 0) + ", got " + color; - try (var image = Image.makeFromBitmap(src.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(src.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(target.getLeft(), target.getTop(), w, h)); } } @@ -248,7 +248,7 @@ public void drawErase(Canvas canvas, IRect target, IRect screen, float dpi) { src.erase(red); var color = src.getColor4f((int) (w / 2 * dpi), (int) (h / 2 * dpi)); assert red.equals(color) : "Expected " + red + ", got " + color; - try (var image = Image.makeFromBitmap(src.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(src.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(target.getLeft() + w, target.getTop(), w, h)); } } @@ -258,7 +258,7 @@ public void drawErase(Canvas canvas, IRect target, IRect screen, float dpi) { src.erase(red, IRect.makeXYWH((int) (w / 4 * dpi), (int) (h / 4 * dpi), (int) (w / 2 * dpi), (int) (h / 2 * dpi))); var color = src.getColor4f((int) (w / 2 * dpi), (int) (h / 2 * dpi)); assert new Color4f(1, 0, 0).equals(color) : "Expected " + new Color4f(1, 0, 0) + ", got " + color; - try (var image = Image.makeFromBitmap(src.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(src.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(target.getLeft(), target.getTop() + h, w, h)); } } @@ -268,7 +268,7 @@ public void drawErase(Canvas canvas, IRect target, IRect screen, float dpi) { src.erase(red, IRect.makeXYWH((int) (w / 4 * dpi), (int) (h / 4 * dpi), (int) (w / 2 * dpi), (int) (h / 2 * dpi))); var color = src.getColor4f((int) (w / 2 * dpi), (int) (h / 2 * dpi)); assert red.equals(color) : "Expected " + red + ", got " + color; - try (var image = Image.makeFromBitmap(src.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(src.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(target.getLeft() + w, target.getTop() + h, w, h)); } } diff --git a/examples/scenes/src/CodecScene.java b/examples/scenes/src/CodecScene.java index 6a7aee92..169cada4 100644 --- a/examples/scenes/src/CodecScene.java +++ b/examples/scenes/src/CodecScene.java @@ -81,7 +81,7 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int }); } else { drawOne(canvas, width, label, () -> { - try (var image = Image.makeFromBitmap(bitmap);) { + try (var image = Image.makeRasterFromBitmap(bitmap);) { canvas.drawImageRect(image, Rect.makeXYWH(0, 0, columnW, rowH)); } }); @@ -100,7 +100,7 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int drawOne(canvas, width, label + "\n" + codec.getEncodedImageFormat(), () -> { canvas.save(); canvas.concat(origin.toMatrix(bitmapWidth, bitmapHeight)); - try (var image = Image.makeFromBitmap(bitmap);) { + try (var image = Image.makeRasterFromBitmap(bitmap);) { canvas.drawImageRect(image, Rect.makeXYWH(0, 0, codec.getWidth(), codec.getHeight())); } canvas.restore(); @@ -131,7 +131,7 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int try (var bitmap = new Bitmap()) { bitmap.allocPixels(codec.getImageInfo()); codec.readPixels(bitmap, finalFrame); - try (var image = Image.makeFromBitmap(bitmap.setImmutable());) { + try (var image = Image.makeRasterFromBitmap(bitmap.setImmutable());) { canvas.drawImageRect(image, Rect.makeXYWH(0, 0, columnW, rowH)); } } @@ -139,7 +139,7 @@ public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int drawOne(canvas, width, label + "\n" + codec.getEncodedImageFormat() + " + priorFrame", () -> { codec.readPixels(animation.bitmap, finalFrame, animation.prevFrame); - try (var image = Image.makeFromBitmap(animation.bitmap);) { + try (var image = Image.makeRasterFromBitmap(animation.bitmap);) { canvas.drawImageRect(image, Rect.makeXYWH(0, 0, columnW, rowH)); } }); diff --git a/examples/scenes/src/ColorFiltersScene.java b/examples/scenes/src/ColorFiltersScene.java index 347d81b0..b27a1e80 100644 --- a/examples/scenes/src/ColorFiltersScene.java +++ b/examples/scenes/src/ColorFiltersScene.java @@ -11,7 +11,7 @@ public class ColorFiltersScene extends Scene { public ColorFiltersScene() { try { - image = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/circus.jpg")))); + image = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/circus.jpg")))); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/examples/scenes/src/FigmaScene.java b/examples/scenes/src/FigmaScene.java index e44a8533..1377be08 100644 --- a/examples/scenes/src/FigmaScene.java +++ b/examples/scenes/src/FigmaScene.java @@ -56,7 +56,7 @@ public FigmaScene() { icons.put("Mask Fill", new Path().moveTo(16.75f, 13.24f).cubicTo(14.24f, 14.45f, 12.5f, 17.02f, 12.5f, 20).cubicTo(12.5f, 22.98f, 14.24f, 25.55f, 16.75f, 26.76f) .cubicTo(19.26f, 25.55f, 21, 22.98f, 21, 20).cubicTo(21, 17.02f, 19.26f, 14.45f, 16.75f, 13.24f)); icons.put("Union", new Path().moveTo(13, 12).lineTo(13, 23).lineTo(18, 23).lineTo(18, 28).lineTo(29, 28).lineTo(29, 17).lineTo(24, 17).lineTo(24, 12).closePath()); - avatar = Image.makeFromEncoded(Files.readAllBytes(java.nio.file.Path.of(file("images/IMG_5563.png")))); + avatar = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(java.nio.file.Path.of(file("images/IMG_5563.png")))); icons.put("Present", new Path().moveTo(15.5f, 15).lineTo(15.5f, 25).lineTo(23, 20).closePath()); icons.put("Layer Frame", new Path().moveTo(3.5f, 0.5f).lineTo(3.5f, 11.5f).moveTo(8.5f, 0.5f).lineTo(8.5f, 11.5f).moveTo(0.5f, 3.5f).lineTo(11.5f, 3.5f).moveTo(0.5f, 8.5f).lineTo(11.5f, 8.5f)); icons.put("Layer Image", new Path().addRRect(RRect.makeXYWH(0.5f, 0.5f, 11, 11, 1)).addCircle(8, 4, 1.5f).moveTo(0.5f, 8.5f).lineTo(3.5f, 5.5f).lineTo(9.5f, 11.5f)); diff --git a/examples/scenes/src/ImageBenchScene.java b/examples/scenes/src/ImageBenchScene.java index 42779cf0..2d81ce5d 100644 --- a/examples/scenes/src/ImageBenchScene.java +++ b/examples/scenes/src/ImageBenchScene.java @@ -16,9 +16,9 @@ public class ImageBenchScene extends Scene { public ImageBenchScene() throws IOException { sprites = new Image[14]; for (int i = 0; i < 14; ++i) { - sprites[i] = Image.makeFromEncoded(Files.readAllBytes(java.nio.file.Path.of(file("images/sprites/bunny" + i + ".png")))); + sprites[i] = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(java.nio.file.Path.of(file("images/sprites/bunny" + i + ".png")))); } - all = Image.makeFromEncoded(Files.readAllBytes(java.nio.file.Path.of(file("images/sprites/all.png")))); + all = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(java.nio.file.Path.of(file("images/sprites/all.png")))); _variants = new String[] {"One image", "14 images"}; } diff --git a/examples/scenes/src/ImageCodecsScene.java b/examples/scenes/src/ImageCodecsScene.java index 504f01f2..551ca374 100644 --- a/examples/scenes/src/ImageCodecsScene.java +++ b/examples/scenes/src/ImageCodecsScene.java @@ -13,7 +13,7 @@ public class ImageCodecsScene extends Scene { public void loadImage(String file) { try { var path = Path.of(file("images/codecs/" + file)); - images.add(new Pair(file, Image.makeFromEncoded(Files.readAllBytes(path)))); + images.add(new Pair(file, Image.makeDeferredFromEncodedBytes(Files.readAllBytes(path)))); } catch (IllegalArgumentException e) { images.add(new Pair(file, null)); } catch (IOException e) { diff --git a/examples/scenes/src/ImageFiltersScene.java b/examples/scenes/src/ImageFiltersScene.java index 6c4c0be5..926857b0 100644 --- a/examples/scenes/src/ImageFiltersScene.java +++ b/examples/scenes/src/ImageFiltersScene.java @@ -11,7 +11,7 @@ public class ImageFiltersScene extends Scene { public ImageFiltersScene() { try { - image = Image.makeFromEncoded(Files.readAllBytes(java.nio.file.Path.of(file("images/circus.jpg")))); + image = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(java.nio.file.Path.of(file("images/circus.jpg")))); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/examples/scenes/src/ImagesScene.java b/examples/scenes/src/ImagesScene.java index bff1e770..72776161 100644 --- a/examples/scenes/src/ImagesScene.java +++ b/examples/scenes/src/ImagesScene.java @@ -16,16 +16,16 @@ public class ImagesScene extends Scene { public ImagesScene() { try { - circus = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/circus.jpg")))); - circusCropped = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/circus.jpg")))); - cloud = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/cloud.png")))); - ducks = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/ducks.jpg")))); + circus = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/circus.jpg")))); + circusCropped = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/circus.jpg")))); + cloud = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/cloud.png")))); + ducks = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/ducks.jpg")))); tests = new Image[] { - Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/icc-v2-gbr.jpg")))), - Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/purple-displayprofile.png")))), - Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/wide-gamut.png")))), - Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/wide_gamut_yellow_224_224_64.jpeg")))), - Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/webkit_logo_p3.png")))), + Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/icc-v2-gbr.jpg")))), + Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/purple-displayprofile.png")))), + Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/wide-gamut.png")))), + Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/wide_gamut_yellow_224_224_64.jpeg")))), + Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/webkit_logo_p3.png")))), }; } catch (IOException e) { throw new RuntimeException(e); diff --git a/examples/scenes/src/RuntimeEffectScene.java b/examples/scenes/src/RuntimeEffectScene.java index 005c9f85..8bd7eb32 100644 --- a/examples/scenes/src/RuntimeEffectScene.java +++ b/examples/scenes/src/RuntimeEffectScene.java @@ -14,7 +14,7 @@ public class RuntimeEffectScene extends Scene { public RuntimeEffectScene() { try { - _texture = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/triangle.png")))); + _texture = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(Path.of(file("images/triangle.png")))); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/examples/scenes/src/ShadowsScene.java b/examples/scenes/src/ShadowsScene.java index 1918db01..1ba17563 100644 --- a/examples/scenes/src/ShadowsScene.java +++ b/examples/scenes/src/ShadowsScene.java @@ -12,9 +12,9 @@ public class ShadowsScene extends Scene { public ShadowsScene() { try { - figma = Image.makeFromEncoded(Files.readAllBytes(java.nio.file.Path.of(file("images/shadows/figma.png")))); - firefox = Image.makeFromEncoded(Files.readAllBytes(java.nio.file.Path.of(file("images/shadows/firefox.png")))); - safari = Image.makeFromEncoded(Files.readAllBytes(java.nio.file.Path.of(file("images/shadows/safari.png")))); + figma = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(java.nio.file.Path.of(file("images/shadows/figma.png")))); + firefox = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(java.nio.file.Path.of(file("images/shadows/firefox.png")))); + safari = Image.makeDeferredFromEncodedBytes(Files.readAllBytes(java.nio.file.Path.of(file("images/shadows/safari.png")))); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/examples/scenes/src/SwingScene.java b/examples/scenes/src/SwingScene.java index d312c383..a1194158 100644 --- a/examples/scenes/src/SwingScene.java +++ b/examples/scenes/src/SwingScene.java @@ -761,7 +761,7 @@ public Image skImage(java.awt.image.BufferedImage bi) { b.erase(color, IRect.makeXYWH(x, y, 1, 1)); } } - i = Image.makeFromBitmap(b); + i = Image.makeRasterFromBitmap(b); rasterCache.put(bi, i); return i; } diff --git a/platform/cc/Surface.cc b/platform/cc/Surface.cc index 0c6538db..af6d8531 100644 --- a/platform/cc/Surface.cc +++ b/platform/cc/Surface.cc @@ -5,7 +5,7 @@ #include "ganesh/SkSurfaceGanesh.h" #include "interop.hh" -extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nMakeRasterDirect +extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nWrapPixels (JNIEnv* env, jclass jclass, jint width, jint height, jint colorType, jint alphaType, jlong colorSpacePtr, jlong pixelsPtr, jlong rowBytes, @@ -27,7 +27,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nMake return reinterpret_cast(instance.release()); } -extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nMakeRasterDirectWithPixmap +extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nWrapPixelsPixmap (JNIEnv* env, jclass jclass, jlong pixmapPtr, jobject surfacePropsObj) { @@ -59,17 +59,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nMake return reinterpret_cast(instance.release()); } -extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nMakeRasterN32Premul - (JNIEnv* env, jclass jclass, jint width, jint height) { - SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height); - sk_sp surface = SkSurfaces::Raster( - imageInfo, - /* const SkSurfaceProps* */ nullptr - ); - return reinterpret_cast(surface.release()); -} - -extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nMakeFromBackendRenderTarget +extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nWrapBackendRenderTarget (JNIEnv* env, jclass jclass, jlong pContext, jlong pBackendRenderTarget, jint surfaceOrigin, jint colorType, jlong colorSpacePtr, jobject surfacePropsObj) { GrDirectContext* context = reinterpret_cast(static_cast(pContext)); GrBackendRenderTarget* backendRenderTarget = reinterpret_cast(static_cast(pBackendRenderTarget)); @@ -94,7 +84,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nMake #ifdef SK_METAL #include "ganesh/mtl/SkSurfaceMetal.h" -extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nMakeFromMTKView +extern "C" JNIEXPORT jlong JNICALL Java_io_github_humbleui_skija_Surface__1nWrapMTKView (JNIEnv* env, jclass jclass, jlong contextPtr, jlong mtkViewPtr, jint surfaceOrigin, jint sampleCount, jint colorType, jlong colorSpacePtr, jobject surfacePropsObj) { GrDirectContext* context = reinterpret_cast(static_cast(contextPtr)); GrMTLHandle* mtkView = reinterpret_cast(static_cast(mtkViewPtr)); diff --git a/shared/java/Surface.java b/shared/java/Surface.java index 24d954e2..4a5534a5 100644 --- a/shared/java/Surface.java +++ b/shared/java/Surface.java @@ -12,9 +12,14 @@ public class Surface extends RefCnt { @ApiStatus.Internal public final DirectContext _context; @ApiStatus.Internal public final BackendRenderTarget _renderTarget; - @NotNull @Contract("_ -> new") - public static Surface makeRasterDirect(@NotNull Pixmap pixmap) { - return makeRasterDirect(pixmap, null); + /** + * @deprecated - use {@link #wrapPixels(ImageInfo, long, long)} + */ + @Deprecated + public static Surface makeRasterDirect(@NotNull ImageInfo imageInfo, + long pixelsPtr, + long rowBytes) { + return wrapPixels(imageInfo, pixelsPtr, rowBytes, null); } /** @@ -40,27 +45,21 @@ public static Surface makeRasterDirect(@NotNull Pixmap pixmap) { * @return created Surface */ @NotNull @Contract("_, _, _ -> new") - public static Surface makeRasterDirect(@NotNull ImageInfo imageInfo, - long pixelsPtr, - long rowBytes) { - return makeRasterDirect(imageInfo, pixelsPtr, rowBytes, null); + public static Surface wrapPixels(@NotNull ImageInfo imageInfo, + long pixelsPtr, + long rowBytes) { + return wrapPixels(imageInfo, pixelsPtr, rowBytes, null); } - @NotNull @Contract("_, _ -> new") - public static Surface makeRasterDirect(@NotNull Pixmap pixmap, + /** + * @deprecated - use {@link #wrapPixels(ImageInfo, long, long, SurfaceProps)} + */ + @Deprecated + public static Surface makeRasterDirect(@NotNull ImageInfo imageInfo, + long pixelsPtr, + long rowBytes, @Nullable SurfaceProps surfaceProps) { - try { - assert pixmap != null : "Can’t makeRasterDirect with pixmap == null"; - Stats.onNativeCall(); - long ptr = _nMakeRasterDirectWithPixmap( - Native.getPtr(pixmap), surfaceProps - ); - if (ptr == 0) - throw new IllegalArgumentException(String.format("Failed Surface.makeRasterDirect(%s, %s)", pixmap, surfaceProps)); - return new Surface(ptr); - } finally { - ReferenceUtil.reachabilityFence(pixmap); - } + return wrapPixels(imageInfo, pixelsPtr, rowBytes, surfaceProps); } /** @@ -88,14 +87,14 @@ public static Surface makeRasterDirect(@NotNull Pixmap pixmap, * @return created Surface */ @NotNull @Contract("_, _, _, _ -> new") - public static Surface makeRasterDirect(@NotNull ImageInfo imageInfo, - long pixelsPtr, - long rowBytes, - @Nullable SurfaceProps surfaceProps) { + public static Surface wrapPixels(@NotNull ImageInfo imageInfo, + long pixelsPtr, + long rowBytes, + @Nullable SurfaceProps surfaceProps) { try { - assert imageInfo != null : "Can’t makeRasterDirect with imageInfo == null"; + assert imageInfo != null : "Can’t wrapPixels with imageInfo == null"; Stats.onNativeCall(); - long ptr = _nMakeRasterDirect( + long ptr = _nWrapPixels( imageInfo._width, imageInfo._height, imageInfo._colorInfo._colorType.ordinal(), @@ -104,14 +103,54 @@ public static Surface makeRasterDirect(@NotNull ImageInfo imageInfo, pixelsPtr, rowBytes, surfaceProps); - if (ptr == 0) - throw new IllegalArgumentException(String.format("Failed Surface.makeRasterDirect(%s, %d, %d, %s)", imageInfo, pixelsPtr, rowBytes, surfaceProps)); + if (ptr == 0) { + throw new IllegalArgumentException(String.format("Failed Surface.wrapPixels(%s, %d, %d, %s)", imageInfo, pixelsPtr, rowBytes, surfaceProps)); + } return new Surface(ptr); } finally { ReferenceUtil.reachabilityFence(imageInfo._colorInfo._colorSpace); } } + /** + * @deprecated - use {@link #wrapPixels(Pixmap)} + */ + @Deprecated + public static Surface makeRasterDirect(@NotNull Pixmap pixmap) { + return wrapPixels(pixmap, null); + } + + @NotNull @Contract("_ -> new") + public static Surface wrapPixels(@NotNull Pixmap pixmap) { + return wrapPixels(pixmap, null); + } + + + /** + * @deprecated - use {@link #wrapPixels(Pixmap, SurfaceProps)} + */ + @Deprecated + public static Surface makeRasterDirect(@NotNull Pixmap pixmap, + @Nullable SurfaceProps surfaceProps) { + return wrapPixels(pixmap, surfaceProps); + } + + @NotNull @Contract("_, _ -> new") + public static Surface wrapPixels(@NotNull Pixmap pixmap, + @Nullable SurfaceProps surfaceProps) { + try { + assert pixmap != null : "Can’t wrapPixels with pixmap == null"; + Stats.onNativeCall(); + long ptr = _nWrapPixelsPixmap(Native.getPtr(pixmap), surfaceProps); + if (ptr == 0) { + throw new IllegalArgumentException(String.format("Failed Surface.wrapPixels(%s, %s)", pixmap, surfaceProps)); + } + return new Surface(ptr); + } finally { + ReferenceUtil.reachabilityFence(pixmap); + } + } + /** *

Allocates raster Surface. Canvas returned by Surface draws directly into pixels. * Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times imageInfo.minRowBytes(). @@ -200,6 +239,18 @@ public static Surface makeRaster(@NotNull ImageInfo imageInfo, } } + /** + * @deprecated - use {@link #wrapBackendRenderTarget(DirectContext, BackendRenderTarget, SurfaceOrigin, SurfaceColorFormat, ColorSpace)} + */ + @Deprecated + public static Surface makeFromBackendRenderTarget(DirectContext context, + BackendRenderTarget rt, + SurfaceOrigin origin, + SurfaceColorFormat colorFormat, + ColorSpace colorSpace) { + return wrapBackendRenderTarget(context, rt, origin, colorFormat, colorSpace, null); + } + /** *

Wraps a GPU-backed buffer into {@link Surface}.

* @@ -220,13 +271,27 @@ public static Surface makeRaster(@NotNull ImageInfo imageInfo, * @see https://fiddle.skia.org/c/@Surface_MakeFromBackendTexture */ @NotNull - public static Surface makeFromBackendRenderTarget(@NotNull DirectContext context, - @NotNull BackendRenderTarget rt, - @NotNull SurfaceOrigin origin, - @NotNull SurfaceColorFormat colorFormat, - @Nullable ColorSpace colorSpace) { - return makeFromBackendRenderTarget(context, rt, origin, colorFormat, colorSpace, null); + public static Surface wrapBackendRenderTarget(@NotNull DirectContext context, + @NotNull BackendRenderTarget rt, + @NotNull SurfaceOrigin origin, + @NotNull SurfaceColorFormat colorFormat, + @Nullable ColorSpace colorSpace) { + return wrapBackendRenderTarget(context, rt, origin, colorFormat, colorSpace, null); } + + /** + * @deprecated - use {@link #wrapBackendRenderTarget(DirectContext, BackendRenderTarget, SurfaceOrigin, SurfaceColorFormat, ColorSpace, SurfaceProps)} + */ + @Deprecated + public static Surface makeFromBackendRenderTarget(DirectContext context, + BackendRenderTarget rt, + SurfaceOrigin origin, + SurfaceColorFormat colorFormat, + ColorSpace colorSpace, + SurfaceProps surfaceProps) { + return wrapBackendRenderTarget(context, rt, origin, colorFormat, colorSpace, surfaceProps); + } + /** *

Wraps a GPU-backed buffer into {@link Surface}.

* @@ -247,22 +312,23 @@ public static Surface makeFromBackendRenderTarget(@NotNull DirectContext context * @return Surface if all parameters are valid; otherwise, null * @see https://fiddle.skia.org/c/@Surface_MakeFromBackendTexture */ + @NotNull - public static Surface makeFromBackendRenderTarget(@NotNull DirectContext context, + public static Surface wrapBackendRenderTarget(@NotNull DirectContext context, @NotNull BackendRenderTarget rt, @NotNull SurfaceOrigin origin, @NotNull SurfaceColorFormat colorFormat, @Nullable ColorSpace colorSpace, @Nullable SurfaceProps surfaceProps) { try { - assert context != null : "Can’t makeFromBackendRenderTarget with context == null"; - assert rt != null : "Can’t makeFromBackendRenderTarget with rt == null"; - assert origin != null : "Can’t makeFromBackendRenderTarget with origin == null"; - assert colorFormat != null : "Can’t makeFromBackendRenderTarget with colorFormat == null"; + assert context != null : "Can’t wrapBackendRenderTarget with context == null"; + assert rt != null : "Can’t wrapBackendRenderTarget with rt == null"; + assert origin != null : "Can’t wrapBackendRenderTarget with origin == null"; + assert colorFormat != null : "Can’t wrapBackendRenderTarget with colorFormat == null"; Stats.onNativeCall(); - long ptr = _nMakeFromBackendRenderTarget(Native.getPtr(context), Native.getPtr(rt), origin.ordinal(), colorFormat.ordinal(), Native.getPtr(colorSpace), surfaceProps); + long ptr = _nWrapBackendRenderTarget(Native.getPtr(context), Native.getPtr(rt), origin.ordinal(), colorFormat.ordinal(), Native.getPtr(colorSpace), surfaceProps); if (ptr == 0) - throw new IllegalArgumentException(String.format("Failed Surface.makeFromBackendRenderTarget(%s, %s, %s, %s, %s)", context, rt, origin, colorFormat, colorSpace)); + throw new IllegalArgumentException(String.format("Failed Surface.wrapBackendRenderTarget(%s, %s, %s, %s, %s)", context, rt, origin, colorFormat, colorSpace)); return new Surface(ptr, context, rt); } finally { ReferenceUtil.reachabilityFence(context); @@ -271,7 +337,10 @@ public static Surface makeFromBackendRenderTarget(@NotNull DirectContext context } } - @NotNull + /** + * @deprecated - use {@link #wrapMTKView(DirectContext, long, SurfaceOrigin, int, SurfaceColorFormat, ColorSpace, SurfaceProps)} + */ + @Deprecated public static Surface makeFromMTKView(@NotNull DirectContext context, long mtkViewPtr, @NotNull SurfaceOrigin origin, @@ -279,14 +348,25 @@ public static Surface makeFromMTKView(@NotNull DirectContext context, @NotNull SurfaceColorFormat colorFormat, @Nullable ColorSpace colorSpace, @Nullable SurfaceProps surfaceProps) { + return wrapMTKView(context, mtkViewPtr, origin, sampleCount, colorFormat, colorSpace, surfaceProps); + } + + @NotNull + public static Surface wrapMTKView(@NotNull DirectContext context, + long mtkViewPtr, + @NotNull SurfaceOrigin origin, + int sampleCount, + @NotNull SurfaceColorFormat colorFormat, + @Nullable ColorSpace colorSpace, + @Nullable SurfaceProps surfaceProps) { try { - assert context != null : "Can’t makeFromBackendRenderTarget with context == null"; - assert origin != null : "Can’t makeFromBackendRenderTarget with origin == null"; - assert colorFormat != null : "Can’t makeFromBackendRenderTarget with colorFormat == null"; + assert context != null : "Can’t wrapMTKView with context == null"; + assert origin != null : "Can’t wrapMTKView with origin == null"; + assert colorFormat != null : "Can’t wrapMTKView with colorFormat == null"; Stats.onNativeCall(); - long ptr = _nMakeFromMTKView(Native.getPtr(context), mtkViewPtr, origin.ordinal(), sampleCount, colorFormat.ordinal(), Native.getPtr(colorSpace), surfaceProps); + long ptr = _nWrapMTKView(Native.getPtr(context), mtkViewPtr, origin.ordinal(), sampleCount, colorFormat.ordinal(), Native.getPtr(colorSpace), surfaceProps); if (ptr == 0) - throw new IllegalArgumentException(String.format("Failed Surface.makeFromMTKView(%s, %s, %s, %s, %s, %s)", context, mtkViewPtr, origin, colorFormat, colorSpace, surfaceProps)); + throw new IllegalArgumentException(String.format("Failed Surface.WrapMTKView(%s, %s, %s, %s, %s, %s)", context, mtkViewPtr, origin, colorFormat, colorSpace, surfaceProps)); return new Surface(ptr, context); } finally { ReferenceUtil.reachabilityFence(context); @@ -295,6 +375,8 @@ public static Surface makeFromMTKView(@NotNull DirectContext context, } /** + * @deprecated - use makeRaster(ImageInfo.makeN32Premul(width, height)) + * *

Allocates raster {@link Surface}.

* *

Canvas returned by Surface draws directly into pixels. Allocates and zeroes pixel memory. @@ -312,13 +394,9 @@ public static Surface makeFromMTKView(@NotNull DirectContext context, * @return Surface if all parameters are valid; otherwise, null * @see https://fiddle.skia.org/c/@Surface_MakeRasterN32Premul */ - @NotNull + @NotNull @Deprecated public static Surface makeRasterN32Premul(int width, int height) { - Stats.onNativeCall(); - long ptr = _nMakeRasterN32Premul(width, height); - if (ptr == 0) - throw new IllegalArgumentException(String.format("Failed Surface.makeRasterN32Premul(%d, %d)", width, height)); - return new Surface(ptr); + return makeRaster(ImageInfo.makeN32Premul(width, height)); } /** @@ -889,12 +967,11 @@ public Surface(long ptr, DirectContext context, BackendRenderTarget renderTarget _renderTarget = renderTarget; } - public static native long _nMakeRasterDirect(int width, int height, int colorType, int alphaType, long colorSpacePtr, long pixelsPtr, long rowBytes, SurfaceProps surfaceProps); - public static native long _nMakeRasterDirectWithPixmap(long pixmapPtr, SurfaceProps surfaceProps); + public static native long _nWrapPixels(int width, int height, int colorType, int alphaType, long colorSpacePtr, long pixelsPtr, long rowBytes, SurfaceProps surfaceProps); + public static native long _nWrapPixelsPixmap(long pixmapPtr, SurfaceProps surfaceProps); public static native long _nMakeRaster(int width, int height, int colorType, int alphaType, long colorSpacePtr, long rowBytes, SurfaceProps surfaceProps); - public static native long _nMakeRasterN32Premul(int width, int height); - public static native long _nMakeFromBackendRenderTarget(long pContext, long pBackendRenderTarget, int surfaceOrigin, int colorType, long colorSpacePtr, SurfaceProps surfaceProps); - public static native long _nMakeFromMTKView(long contextPtr, long mtkViewPtr, int surfaceOrigin, int sampleCount, int colorType, long colorSpacePtr, SurfaceProps surfaceProps); + public static native long _nWrapBackendRenderTarget(long pContext, long pBackendRenderTarget, int surfaceOrigin, int colorType, long colorSpacePtr, SurfaceProps surfaceProps); + public static native long _nWrapMTKView(long contextPtr, long mtkViewPtr, int surfaceOrigin, int sampleCount, int colorType, long colorSpacePtr, SurfaceProps surfaceProps); public static native long _nMakeRenderTarget(long contextPtr, boolean budgeted, int width, int height, int colorType, int alphaType, long colorSpacePtr, int sampleCount, int surfaceOrigin, SurfaceProps surfaceProps, boolean shouldCreateWithMips); public static native long _nMakeNull(int width, int height); public static native int _nGetWidth(long ptr);