HarmonyOS鸿蒙Next系统使用flutter渲染不支持在插件层更新rgba数据吗?
HarmonyOS鸿蒙Next系统使用flutter渲染不支持在插件层更新rgba数据吗?
问题
在鸿蒙Next系统使用flutter 3.22版本,开发视频渲染插件,在flutter插件层接收到底层C++ 回调上来rgba图像数据,怎么更新到纹理上?
FlutterRenderer 没有更新rgba内存数据到纹理的接口,或者有其他方式更新内存数据到纹理上吗?
import image from '@ohos.multimedia.image';
import { BusinessError } from '@ohos.base';
import { SurfaceTextureEntry, TextureRegistry } from '../../../view/TextureRegistry';
import { FlutterAbility } from '../../ohos/FlutterAbility';
import FlutterNapi from '../FlutterNapi';
import Log from '../../../util/Log';
const TAG = "FlutterRenderer"
export class FlutterRenderer implements TextureRegistry {
private flutterNapi: FlutterNapi;
private static globalTextureId: number = 0;
constructor(flutterNapi: FlutterNapi) {
this.flutterNapi = flutterNapi;
}
getTextureId(): number {
let nextTextureId: number = FlutterRenderer.globalTextureId + 1;
FlutterRenderer.globalTextureId = FlutterRenderer.globalTextureId + 1;
Log.i(TAG, "getTextureId: " + nextTextureId)
return nextTextureId;
}
registerTexture(textureId: number): SurfaceTextureEntry {
let surfaceTextureRegistryEntry = new SurfaceTextureRegistryEntry(textureId);
let surfaceId = this.flutterNapi.registerTexture(textureId);
Log.i(TAG, "registerTexture, surfaceId=" + surfaceId);
surfaceTextureRegistryEntry.setSurfaceId(surfaceId);
let nativeWindowId = this.flutterNapi.getTextureNativeWindowId(textureId);
surfaceTextureRegistryEntry.setNativeWindowId(nativeWindowId);
return surfaceTextureRegistryEntry;
}
registerPixelMap(pixelMap: PixelMap): number {
let nextTextureId: number = this.getTextureId();
this.flutterNapi.registerPixelMap(nextTextureId, pixelMap);
return nextTextureId;
}
setTextureBackGroundPixelMap(textureId: number, pixelMap: PixelMap): void {
this.flutterNapi.setTextureBackGroundPixelMap(textureId, pixelMap);
}
setTextureBufferSize(textureId: number, width: number, height: number): void {
this.flutterNapi.setTextureBufferSize(textureId, width, height);
}
notifyTextureResizing(textureId: number, width: number, height: number): void {
this.flutterNapi.notifyTextureResizing(textureId, width, height);
}
setExternalNativeImage(textureId: number, native_image: number): boolean {
return this.flutterNapi.setExternalNativeImage(textureId, native_image);
}
resetExternalTexture(textureId: number, need_surfaceId: boolean): number {
return this.flutterNapi.resetExternalTexture(textureId, need_surfaceId);
}
unregisterTexture(textureId: number): void {
this.flutterNapi.unregisterTexture(textureId);
}
onTrimMemory(level: number) {
throw new Error('Method not implemented.');
}
}
export class SurfaceTextureRegistryEntry implements SurfaceTextureEntry {
private textureId: number = 0;
private surfaceId: number = 0;
private nativeWindowId: number = 0;
private released: boolean = false;
constructor(id: number) {
this.textureId = id;
}
getTextureId(): number {
return this.textureId;
}
getSurfaceId(): number {
return this.surfaceId;
}
getNativeWindowId(): number {
return this.nativeWindowId;
}
setSurfaceId(surfaceId: number): void {
this.surfaceId = surfaceId;
}
setNativeWindowId(nativeWindowId: number): void {
this.nativeWindowId = nativeWindowId;
}
release() {
throw new Error('Method not implemented.');
}
}
更多关于HarmonyOS鸿蒙Next系统使用flutter渲染不支持在插件层更新rgba数据吗?的实战教程也可以访问 https://www.itying.com/category-92-b0.html
在HarmonyOS鸿蒙Next系统中,Flutter引擎的插件层确实存在对RGBA数据更新的限制。当前架构下,Flutter的纹理和平台视图交互机制未开放底层RGBA数据的直接写入接口。鸿蒙的图形子系统采用自有合成管线,与Flutter的Skia渲染引擎存在数据通道差异,导致插件层无法像Android/iOS平台那样直接操作像素缓冲区。这属于架构层设计约束,需等待华为官方对Flutter鸿蒙适配层的后续更新。
更多关于HarmonyOS鸿蒙Next系统使用flutter渲染不支持在插件层更新rgba数据吗?的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
在HarmonyOS Next中使用Flutter 3.22进行视频渲染时,确实可以通过纹理方式处理RGBA数据。从代码来看,您需要利用FlutterNapi
提供的原生能力来实现纹理更新。
关键点:
- 使用
registerTexture
获取纹理ID后,可以通过setExternalNativeImage
方法更新纹理数据 - 对于RGBA数据,建议先在Native层转换为合适的图像格式(如PixelMap)
- 通过
SurfaceTextureEntry
获取的nativeWindowId可用于底层渲染
替代方案:
- 考虑使用
registerPixelMap
直接注册PixelMap格式数据 - 通过
setTextureBackGroundPixelMap
更新背景纹理
注意纹理生命周期管理,及时调用unregisterTexture
释放资源。具体实现需要结合您的C++层渲染逻辑,通过JNI/NAPI桥接数据。