-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1992 from Shopify/integration2
--------- Co-authored-by: William Candillon <[email protected]> Co-authored-by: gtbl2012 <[email protected]> Co-authored-by: Hans <[email protected]>
- Loading branch information
Showing
11 changed files
with
353 additions
and
15 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
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,41 @@ | ||
#pragma once | ||
|
||
#include "SkImage.h" | ||
#include <jsi/jsi.h> | ||
|
||
namespace RNSkia { | ||
|
||
namespace jsi = facebook::jsi; | ||
|
||
class RNSkTypedArray { | ||
public: | ||
static jsi::Value getTypedArray(jsi::Runtime &runtime, | ||
const jsi::Value &value, SkImageInfo &info) { | ||
auto reqSize = info.computeMinByteSize(); | ||
if (reqSize > 0) { | ||
if (value.isObject()) { | ||
auto typedArray = value.asObject(runtime); | ||
auto size = static_cast<size_t>( | ||
typedArray.getProperty(runtime, "byteLength").asNumber()); | ||
if (size >= reqSize) { | ||
return typedArray; | ||
} | ||
} else { | ||
if (info.colorType() == kRGBA_F32_SkColorType) { | ||
auto arrayCtor = | ||
runtime.global().getPropertyAsFunction(runtime, "Float32Array"); | ||
return arrayCtor.callAsConstructor(runtime, | ||
static_cast<double>(reqSize / 4)); | ||
} else { | ||
auto arrayCtor = | ||
runtime.global().getPropertyAsFunction(runtime, "Uint8Array"); | ||
return arrayCtor.callAsConstructor(runtime, | ||
static_cast<double>(reqSize)); | ||
} | ||
} | ||
} | ||
return jsi::Value::null(); | ||
} | ||
}; | ||
|
||
} // 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
Oops, something went wrong.