add stride_align for onRgba (#6)

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-03-02 21:38:55 +08:00 • committed by GitHub
parent 1c79d8dd88
commit 044bb260d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 89 additions and 40 deletions

View file

@ -34,7 +34,7 @@ import CoreVideo
}
@objc public func markFrameAvaliable(data: Data, width: Int, height: Int) -> Bool {
@objc public func markFrameAvaliable(data: Data, width: Int, height: Int, stride_align: Int) -> Bool {
queue.sync {
self.data = data.withUnsafeBytes { buffer in
var pixelBufferCopy: CVPixelBuffer!
@ -42,7 +42,9 @@ import CoreVideo
let result = CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, [
kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_32BGRA,
kCVPixelBufferMetalCompatibilityKey: true,
kCVPixelBufferOpenGLCompatibilityKey: true
kCVPixelBufferOpenGLCompatibilityKey: true,
// https://developer.apple.com/forums/thread/712709
kCVPixelBufferBytesPerRowAlignmentKey: stride_align * 4
] as CFDictionary, &pixelBufferCopy)
guard result == kCVReturnSuccess else {
return nil

View file

@ -13,10 +13,10 @@ extern "C" {
#endif
/// Keep the same name with Windows.
void FlutterRgbaRendererPluginOnRgba(void* texture_rgba_ptr, const uint8_t* buffer, int width, int height) {
void FlutterRgbaRendererPluginOnRgba(void* texture_rgba_ptr, const uint8_t* buffer, int width, int height, int stride_align) {
TextRgba* texture_rgba = (__bridge TextRgba *)(texture_rgba_ptr);
NSData* data = [NSData dataWithBytesNoCopy:(void*)buffer length:width * height * 4 freeWhenDone:FALSE];
[texture_rgba markFrameAvaliableWithData:data width:width height:height];
NSData* data = [NSData dataWithBytesNoCopy:(void*)buffer length:((width + stride_align - 1) & ~(stride_align - 1)) * height * 4 freeWhenDone:FALSE];
[texture_rgba markFrameAvaliableWithData:data width:width height:height stride_align: stride_align];
}
#if __cplusplus

View file

@ -48,12 +48,13 @@ public class TextureRgbaRendererPlugin: NSObject, FlutterPlugin {
let key = args["key"] as! Int64
let data = args["data"] as! FlutterStandardTypedData
let height = args["height"] as! Int
let width = args["height"] as! Int
let width = args["width"] as! Int
let stride_align = args["stride_align"] as! Int
let textureRgba = renderer[key]
if (textureRgba == nil) {
result(false)
} else {
result(textureRgba!.markFrameAvaliable(data: data.data, width: width, height: height))
result(textureRgba!.markFrameAvaliable(data: data.data, width: width, height: height, stride_align: stride_align))
}
case "getTexturePtr":
let args = call.arguments as! Dictionary<String, Any?>