-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(📹): add e2e tests for Platform Buffers and fix iOS implementation (…
- Loading branch information
1 parent
933a0e2
commit 9232b67
Showing
24 changed files
with
446 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
package/android/cpp/rnskia-android/AHardwareBufferUtils.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#if __ANDROID_API__ >= 26 | ||
|
||
#include "AHardwareBufferUtils.h" | ||
#include <android/hardware_buffer.h> | ||
|
||
namespace RNSkia { | ||
|
||
uint32_t GetBufferFormatFromSkColorType(SkColorType bufferFormat) { | ||
switch (bufferFormat) { | ||
case kRGBA_8888_SkColorType: | ||
return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM; | ||
case kRGB_888x_SkColorType: | ||
return AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM; | ||
case kRGBA_F16_SkColorType: | ||
return AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT; | ||
case kRGB_565_SkColorType: | ||
return AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM; | ||
case kRGBA_1010102_SkColorType: | ||
return AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM; | ||
#if __ANDROID_API__ >= 33 | ||
case kAlpha_8_SkColorType: | ||
return AHARDWAREBUFFER_FORMAT_R8_UNORM; | ||
#endif | ||
default: | ||
return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM; | ||
} | ||
} | ||
|
||
} // namespace RNSkia | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "include/core/SkColorType.h" | ||
|
||
#if __ANDROID_API__ >= 26 | ||
|
||
namespace RNSkia { | ||
|
||
uint32_t GetBufferFormatFromSkColorType(SkColorType bufferFormat); | ||
|
||
} // namespace RNSkia | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include <jsi/jsi.h> | ||
|
||
#include "JsiSkImage.h" | ||
|
||
namespace RNSkia { | ||
|
||
namespace jsi = facebook::jsi; | ||
|
||
/** | ||
Implementation of the ParagraphBuilderFactory for making ParagraphBuilder JSI | ||
object | ||
*/ | ||
class JsiPlatformBufferFactory : public JsiSkHostObject { | ||
public: | ||
JSI_HOST_FUNCTION(MakeFromImage) { | ||
auto image = JsiSkImage::fromValue(runtime, arguments[0]); | ||
image->makeNonTextureImage(); | ||
|
||
uint64_t pointer = getContext()->makePlatformBuffer(image); | ||
jsi::HostFunctionType deleteFunc = | ||
[=](jsi::Runtime &runtime, const jsi::Value &thisArg, | ||
const jsi::Value *args, size_t count) -> jsi::Value { | ||
getContext()->releasePlatformBuffer(pointer); | ||
return jsi::Value::undefined(); | ||
}; | ||
return jsi::BigInt::fromUint64(runtime, pointer); | ||
} | ||
|
||
JSI_HOST_FUNCTION(Release) { | ||
|
||
jsi::BigInt pointer = arguments[0].asBigInt(runtime); | ||
const uintptr_t platformBufferPointer = pointer.asUint64(runtime); | ||
|
||
getContext()->releasePlatformBuffer(platformBufferPointer); | ||
return jsi::Value::undefined(); | ||
} | ||
|
||
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiPlatformBufferFactory, Release), | ||
JSI_EXPORT_FUNC(JsiPlatformBufferFactory, MakeFromImage)) | ||
|
||
explicit JsiPlatformBufferFactory( | ||
std::shared_ptr<RNSkPlatformContext> context) | ||
: JsiSkHostObject(std::move(context)) {} | ||
}; | ||
|
||
} // namespace RNSkia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.