diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets index a06563f14f4cfe05125abfe315ad3b5c3a738864..b41df1b44d3daacae6530d285ddbcb01ee3ceba6 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets @@ -30,7 +30,8 @@ declare class nodeControllerParams { const TAG = 'EmbeddingNodeController' export class EmbeddingNodeController extends NodeController { - private rootNode: BuilderNode<[Params]> | undefined | null = null; + private rootNode : FrameNode | null = null; + private builderNode : BuilderNode<[Params]> | undefined | null = null; private wrappedBuilder: WrappedBuilder<[Params]> | null = null; private platformView: PlatformView | undefined = undefined; private embedId : string = ""; @@ -51,24 +52,25 @@ export class EmbeddingNodeController extends NodeController { this.direction = direction; } - makeNode(uiContext: UIContext): FrameNode | null{ - this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId, type: this.renderType}); + makeNode(uiContext: UIContext): FrameNode | null { + this.rootNode = new FrameNode(uiContext); + this.builderNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId, type: this.renderType }); if (this.wrappedBuilder) { - this.rootNode.build(this.wrappedBuilder, {direction: this.direction, platformView: this.platformView}); + this.builderNode.build(this.wrappedBuilder, { direction: this.direction, platformView: this.platformView }); } - return this.rootNode.getFrameNode(); + return this.builderNode.getFrameNode(); } - setBuilderNode(rootNode: BuilderNode | null): void{ - this.rootNode = rootNode; + setBuilderNode(builderNode: BuilderNode | null): void { + this.builderNode = builderNode; } - getBuilderNode(): BuilderNode<[Params]> | undefined | null{ - return this.rootNode; + getBuilderNode(): BuilderNode<[Params]> | undefined | null { + return this.builderNode; } updateNode(arg: Object): void { - this.rootNode?.update(arg); + this.builderNode?.update(arg); } getEmbedId() : string { return this.embedId; @@ -82,6 +84,22 @@ export class EmbeddingNodeController extends NodeController { } } + disposeFrameNode() { + if (this.rootNode !== null && this.builderNode !== null) { + this.rootNode.removeChild(this.builderNode?.getFrameNode()); + this.builderNode?.dispose(); + + this.rootNode.dispose(); + } + } + + removeBuilderNode() { + const rootRenderNode = this.rootNode!.getRenderNode(); + if (rootRenderNode !== null && this.builderNode !== null && this.builderNode?.getFrameNode() !== null) { + rootRenderNode.removeChild(this.builderNode!.getFrameNode()!.getRenderNode()); + } + } + postEvent(event: TouchEvent | undefined, isPx: boolean = false): boolean { if (event == undefined) { return false; @@ -117,6 +135,6 @@ export class EmbeddingNodeController extends NodeController { } } - return this.rootNode?.postTouchEvent(event) as boolean + return this.builderNode?.postTouchEvent(event) as boolean } } \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 5c8846675293cf38e8a15ef374a068d72ee073b0..5c929c84186bf8f3e27de4978f6e83107b079e9e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -142,21 +142,23 @@ export default class PlatformViewsController implements PlatformViewsAccessibili this.textureRegistry!.unregisterTexture(textureId); } - try { - platformView.dispose(); - } catch (err) { - Log.e(TAG, "Disposing platform view threw an exception", err); - } - let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; if (viewWrapper != null) { - this.viewIdWithNodeController.get(viewId)?.setDestroy(true) + this.viewIdWithNodeController.get(viewId)?.removeBuilderNode() + this.viewIdWithNodeController.get(viewId)?.disposeFrameNode() + this.viewIdWithNodeController.delete(viewId); if (this.flutterView) { let index = this.flutterView.getDVModel().children.indexOf(viewWrapper.getDvModel()!); this.flutterView.getDVModel().children.splice(index, 1); } this.viewWrappers.delete(viewId); } + + try { + platformView.dispose(); + } catch (err) { + Log.e(TAG, "Disposing platform view threw an exception", err); + } } setParams: (params: DVModelParameters, key: string, element: Any ) => void = (params: DVModelParameters, key: string, element: Any): void => { @@ -177,7 +179,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let viewWrapper = this.viewWrappers.get(request.viewId) let params: DVModelParameters | undefined = viewWrapper?.getDvModel()!.params - + this.setParams(params!, "width", physicalWidth); this.setParams(params!, "height", physicalHeight); @@ -480,9 +482,21 @@ export default class PlatformViewsController implements PlatformViewsAccessibili return; } } - + public render(surfaceId: number, platformView: PlatformView, width: number, height: number, left: number, top: number) { + + let wrapper = this.viewWrappers.get(surfaceId); + if (wrapper != null) { + let params: DVModelParameters | undefined = wrapper?.getDvModel()!.params + + this.setParams(params!, "width", width); + this.setParams(params!, "height", height); + this.setParams(params!, "left", left); + this.setParams(params!, "top", top); + return; + } + this.flutterView!.setSurfaceId(surfaceId.toString()); let wrappedBuilder: WrappedBuilder<[Params]> = platformView.getView(); this.flutterView?.setWrappedBuilder(wrappedBuilder); @@ -491,8 +505,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let nodeController = new EmbeddingNodeController(); nodeController.setRenderOption(platformView, surfaceId.toString(), NodeRenderType.RENDER_TYPE_TEXTURE, Direction.Auto); - - this.nodeControllers.push(nodeController); + this.viewIdWithNodeController.set(surfaceId, nodeController); let dvModel = createDVModelFromJson(new DVModelJson("NodeContainer", [], @@ -510,5 +523,6 @@ export default class PlatformViewsController implements PlatformViewsAccessibili viewWrapper.addDvModel(dvModel); this.viewWrappers.set(surfaceId, viewWrapper); this.flutterView?.getDVModel().children.push(viewWrapper.getDvModel()); + this.platformViews.set(surfaceId, platformView!); } } \ No newline at end of file diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 8c8d58f72aef821c8fb82f54d8dbb4dfe7eaa046..abc97658ee785a0382d568747922eca41f1fc418 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -44,6 +44,8 @@ constexpr uint32_t WHITE_COLOR = 0xFFFFFFFF; const SkScalar DEFAULT_MATRIX[] = {1, 0, 0, 0, -1, 1, 0, 0, 1}; const int UPDATE_FRAME_COUNT = 2; +std::map infoMap; + static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { switch (pixel_format) { @@ -159,6 +161,18 @@ void OHOSExternalTextureGL::Attach() } } +GrGLTextureInfo OHOSExternalTextureGL::GetGrGLTextureInfo() +{ + GrGLTextureInfo textureInfo; + if (infoMap.find(backGroundTextureName_) != infoMap.end()) { + textureInfo = infoMap[backGroundTextureName_]; + } else { + textureInfo = {GL_TEXTURE_EXTERNAL_OES, backGroundTextureName_, GL_RGBA8_OES}; + } + infoMap[backGroundTextureName_] = textureInfo; + return textureInfo; +} + void OHOSExternalTextureGL::Paint(PaintContext& context, const SkRect& bounds, bool freeze, @@ -185,7 +199,7 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, GrGLTextureInfo textureInfo; if (!freeze && !first_update_ && !isEmulator_ && !new_frame_ready_ && pixelMap_ == nullptr) { setBackground(bounds.width(), bounds.height()); - textureInfo = {GL_TEXTURE_EXTERNAL_OES, backGroundTextureName_, GL_RGBA8_OES}; + textureInfo = GetGrGLTextureInfo(); } else { textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_, GL_RGBA8_OES}; } @@ -305,6 +319,9 @@ void OHOSExternalTextureGL::Detach() } glDeleteTextures(1, &texture_name_); glDeleteTextures(1, &backGroundTextureName_); + if (backGroundTextureName_ != 0) { + infoMap.erase(backGroundTextureName_); + } } void OHOSExternalTextureGL::UpdateTransform(OH_NativeImage *image) diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index a8b5de66296fbfd2ed4523263c33073b41b64e6f..0fb8dec9f123d490906f8bb891adb96f3d3540f3 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -64,6 +64,8 @@ class OHOSExternalTextureGL : public flutter::Texture { void setBackground(int32_t width, int32_t height); + GrGLTextureInfo GetGrGLTextureInfo(); + void setTextureBufferSize(int32_t width, int32_t height); void DispatchPixelMap(NativePixelMap* pixelMap);