Skip to content

Commit

Permalink
Renamed Surface methods following Skia
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Aug 8, 2023
1 parent 45447c2 commit 8c77272
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 123 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
22 changes: 11 additions & 11 deletions examples/scenes/src/BitmapImageScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}
Expand Down
22 changes: 11 additions & 11 deletions examples/scenes/src/BitmapScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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());
}
}
Expand All @@ -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());
}
}
Expand All @@ -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());
}
}
Expand All @@ -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));
}
}
Expand All @@ -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));
}
}
Expand All @@ -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));
}
}
Expand All @@ -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));
}
}
Expand All @@ -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));
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/scenes/src/CodecScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});
Expand All @@ -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();
Expand Down Expand Up @@ -131,15 +131,15 @@ 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));
}
}
});

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));
}
});
Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/src/ColorFiltersScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/src/FigmaScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions examples/scenes/src/ImageBenchScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
}

Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/src/ImageCodecsScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/src/ImageFiltersScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 9 additions & 9 deletions examples/scenes/src/ImagesScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/src/RuntimeEffectScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 8c77272

Please sign in to comment.