From aafca990921646aac1ae413ee8a46d32ebad3cdd Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Thu, 21 Nov 2024 15:31:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=96=E6=8E=A5=E7=BA=B9?= =?UTF-8?q?=E7=90=86=E5=86=85=E5=AD=98=E6=B3=84=E9=9C=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- .../ohos/EmbeddingNodeController.ets | 40 ++++++++++++++----- .../platform/PlatformViewsController.ets | 36 ++++++++++++----- .../ohos/ohos_external_texture_gl.cpp | 19 ++++++++- .../platform/ohos/ohos_external_texture_gl.h | 2 + 4 files changed, 74 insertions(+), 23 deletions(-) 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 a06563f14f..b41df1b44d 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 5c88466752..5c929c8418 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 8c8d58f72a..abc97658ee 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 a8b5de6629..0fb8dec9f1 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); -- Gitee