Skip to content

Commit

Permalink
Rename some leftover PlatformBuffer to NativeBuffers (Shopify#2388)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy authored Apr 18, 2024
1 parent 2391306 commit c6df69c
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package/cpp/api/JsiSkImageFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class JsiSkImageFactory : public JsiSkHostObject {

JSI_HOST_FUNCTION(MakeImageFromNativeBuffer) {
jsi::BigInt pointer = arguments[0].asBigInt(runtime);
const uintptr_t platformBufferPointer = pointer.asUint64(runtime);
void *rawPointer = reinterpret_cast<void *>(platformBufferPointer);
const uintptr_t nativeBufferPointer = pointer.asUint64(runtime);
void *rawPointer = reinterpret_cast<void *>(nativeBufferPointer);
auto image = getContext()->makeImageFromNativeBuffer(rawPointer);
if (image == nullptr) {
throw std::runtime_error("Failed to convert PlatformBuffer to SkImage!");
throw std::runtime_error("Failed to convert NativeBuffer to SkImage!");
}
return jsi::Object::createFromHostObject(
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
Expand Down
2 changes: 1 addition & 1 deletion package/cpp/rnskia/RNSkPlatformContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RNSkPlatformContext {
* Creates an image from a native buffer.
* - On iOS, this is a `CVPixelBufferRef`
* - On Android, this is a `AHardwareBuffer*`
* @param buffer The native platform buffer.
* @param buffer The native buffer.
* @return sk_sp<SkImage>
*/
virtual sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) = 0;
Expand Down
2 changes: 1 addition & 1 deletion package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
if (image == nullptr) {
throw std::runtime_error(
"Failed to convert image to BGRA_8888 colortype! Only BGRA_8888 "
"PlatformBuffers are supported.");
"NativeBuffers are supported.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@
}
default:
[[unlikely]] {
throw std::runtime_error("Failed to convert PlatformBuffer to SkImage - "
"PlatformBuffer has unsupported PixelFormat! " +
throw std::runtime_error("Failed to convert NativeBuffer to SkImage - "
"NativeBuffer has unsupported PixelFormat! " +
std::to_string(static_cast<int>(format)));
}
}
Expand Down
4 changes: 2 additions & 2 deletions package/src/renderer/__tests__/e2e/NativeBuffer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const shouldNativeBufferTestRun = () => {
if (surface.OS !== "ios" && surface.OS !== "android") {
return false;
}
// Skip test on Fabric (it runs on API Level 21 which doesn't support platform buffers)
// Skip test on Fabric (it runs on API Level 21 which doesn't support native buffers)
if (surface.arch === "fabric" && surface.OS === "android") {
return false;
}
Expand Down Expand Up @@ -42,7 +42,7 @@ for (let j = 0; j < rgbaPixels.length; j += 4) {
}

describe("Native Buffers", () => {
it("On non supported platforms MakeImageFromPlatformBuffer() should throw", async () => {
it("On non supported platforms MakeImageFromNativeBuffer() should throw", async () => {
const { Skia: Sk } = setupSkia();
if (!shouldNativeBufferTestRun()) {
return;
Expand Down
6 changes: 3 additions & 3 deletions package/src/skia/types/Image/ImageFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ export interface ImageFactory {

/**
* Return an Image backed by a given native buffer.
* The platform buffer must be a valid owning reference.
* The native buffer must be a valid owning reference.
*
* For instance, this API is used by
* [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
* to render a Skia Camera preview.
*
* - On Android; This is an `AHardwareBuffer*`
* - On iOS, this is a `CVPixelBufferRef`
* @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
* @param nativeBuffer A strong `uintptr_t` pointer to the native buffer
* @throws Throws an error if the Image could not be created, for example when the given
* platform buffer is invalid.
* native buffer is invalid.
*/
MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;

Expand Down
4 changes: 2 additions & 2 deletions package/src/skia/types/NativeBuffer/NativeBufferFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface NativeBufferFactory {
*/
MakeFromImage: (image: SkImage) => NativeBuffer;
/**
* Release a platform buffer that was created with `MakeFromImage`.
* Release a native buffer that was created with `MakeFromImage`.
*/
Release: (platformBuffer: NativeBuffer) => void;
Release: (nativeBuffer: NativeBuffer) => void;
}
2 changes: 1 addition & 1 deletion package/src/skia/web/JsiSkNativeBufferFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class JsiSkNativeBufferFactory
return canvas;
}

Release(_platformBuffer: NativeBuffer) {
Release(_nativeBuffer: NativeBuffer) {
// it's a noop on Web
}
}

0 comments on commit c6df69c

Please sign in to comment.