fix: metal issue on macos
This commit is contained in:
parent
befadf9e8f
commit
71e77ef3cf
2 changed files with 10 additions and 13 deletions
|
|
@ -65,7 +65,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
|
|
||||||
Uint8List mockPicture(int width, int height) {
|
Uint8List mockPicture(int width, int height) {
|
||||||
final pic = List.generate(width * height * 4, (index) {
|
final pic = List.generate(width * height * 4, (index) {
|
||||||
return (index + 1) % 4 == 0 ? 1 : random.nextInt(255);
|
return random.nextInt(255);
|
||||||
});
|
});
|
||||||
return Uint8List.fromList(pic);
|
return Uint8List.fromList(pic);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,22 +34,19 @@ public final class TextRgba: NSObject, FlutterTexture {
|
||||||
self.data = data.withUnsafeBytes { buffer in
|
self.data = data.withUnsafeBytes { buffer in
|
||||||
var pixelBufferCopy: CVPixelBuffer!
|
var pixelBufferCopy: CVPixelBuffer!
|
||||||
// macOS only support 32BGRA currently.
|
// macOS only support 32BGRA currently.
|
||||||
let result = CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, nil, &pixelBufferCopy)
|
let result = CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, [
|
||||||
|
kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_32BGRA,
|
||||||
|
kCVPixelBufferMetalCompatibilityKey: true,
|
||||||
|
kCVPixelBufferOpenGLCompatibilityKey: true
|
||||||
|
] as CFDictionary, &pixelBufferCopy)
|
||||||
guard result == kCVReturnSuccess else {
|
guard result == kCVReturnSuccess else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
CVPixelBufferLockBaseAddress(pixelBufferCopy, [])
|
CVPixelBufferLockBaseAddress(pixelBufferCopy, [])
|
||||||
defer {CVPixelBufferUnlockBaseAddress(pixelBufferCopy, [])}
|
let source = buffer.baseAddress!
|
||||||
var source = buffer.baseAddress!
|
let ptr = CVPixelBufferGetBaseAddress(pixelBufferCopy!)!
|
||||||
|
memcpy(ptr, source, data.count)
|
||||||
for plane in 0 ..< CVPixelBufferGetPlaneCount(pixelBufferCopy) {
|
CVPixelBufferUnlockBaseAddress(pixelBufferCopy, [])
|
||||||
let dest = CVPixelBufferGetBaseAddressOfPlane(pixelBufferCopy, plane)
|
|
||||||
let height = CVPixelBufferGetHeightOfPlane(pixelBufferCopy, plane)
|
|
||||||
let bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(pixelBufferCopy, plane)
|
|
||||||
let planceSize = height * bytesPerRow
|
|
||||||
memcpy(dest, source, planceSize)
|
|
||||||
source += planceSize
|
|
||||||
}
|
|
||||||
return pixelBufferCopy
|
return pixelBufferCopy
|
||||||
}
|
}
|
||||||
self.width = width
|
self.width = width
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue