From 4e54020fd37d86a7ebd65203c36727bb8e33760b Mon Sep 17 00:00:00 2001 From: sfchu Date: Fri, 12 Sep 2025 10:06:57 +0800 Subject: [PATCH] =?UTF-8?q?Drawing=E8=87=AA=E7=BB=98=E5=88=B6=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E6=8F=90=E5=8D=87=20=E6=9C=80=E4=BD=B3=E5=AE=9E?= =?UTF-8?q?=E8=B7=B5=E5=90=8C=E6=BA=90=E4=BB=A3=E7=A0=81=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NdkDrawing/README.md | 14 +++++------ NdkDrawing/README_EN.md | 13 +++++----- NdkDrawing/build-profile.json5 | 5 ++-- NdkDrawing/entry/build-profile.json5 | 5 ++-- .../main/ets/entryability/EntryAbility.ets | 12 ++++++--- .../entrybackupability/EntryBackupAbility.ets | 9 +++++-- NdkDrawing/entry/src/main/ets/pages/Index.ets | 25 +++++++++++++------ .../src/main/ets/view/GlassCoverView.ets | 25 ++++++++++++++++--- NdkDrawing/entry/src/main/ets/view/Index.ets | 15 +++++++++++ 9 files changed, 88 insertions(+), 35 deletions(-) diff --git a/NdkDrawing/README.md b/NdkDrawing/README.md index 24810192..1c5dd809 100644 --- a/NdkDrawing/README.md +++ b/NdkDrawing/README.md @@ -1,4 +1,5 @@ # **Drawing自绘制性能提升** + ## 介绍 Canvas画布组件是用来显示自绘内容的组件,它具有保留历史绘制内容、增量绘制的特点。Canvas有CanvasRenderingContext2D/OffscreenCanvasRenderingContext2D和DrawingRenderingContext两套API,应用使用两套绘制API绘制的内容都可以在绑定的Canvas组件上显示。其中CanvasRenderingContext2D按照W3C标准封装了Native Drawing接口,可以方便快速复用Web应用的绘制逻辑,因此非常适用于Web应用和游戏、快速原型设计、数据可视化、在线绘图板、教学工具或创意应用等场景。 @@ -22,13 +23,12 @@ Canvas画布组件是用来显示自绘内容的组件,它具有保留历史 ``` ## 相关权限 -无 - -## 约束与限制 -* 本示例仅支持标准系统上运行,支持设备:华为手机。 -* HarmonyOS系统:HarmonyOS NEXT Release及以上。 +不涉及 -* DevEco Studio版本:DevEco Studio NEXT Release及以上。 +## 约束与限制 -* HarmonyOS SDK版本:HarmonyOS NEXT Release SDK及以上。 \ No newline at end of file +1. 本示例仅支持标准系统上运行,支持设备:PC电脑。 +2. HarmonyOS系统:HarmonyOS 5.0.5 Release及以上。 +3. DevEco Studio版本:DevEco Studio 5.0.5 Release及以上。 +4. HarmonyOS SDK版本:HarmonyOS 5.0.5 Release SDK及以上。 \ No newline at end of file diff --git a/NdkDrawing/README_EN.md b/NdkDrawing/README_EN.md index 603847f1..be463aed 100644 --- a/NdkDrawing/README_EN.md +++ b/NdkDrawing/README_EN.md @@ -1,4 +1,5 @@ # **Drawing self drawing performance improvement** + ## Overview Canvas component is a component used to display self drawn content, which has the characteristics of preserving historical drawn content and incremental drawing. Canvas has two sets of APIs, CanvasRendering Context2D/Offscreen CanvasRendering Context2D and DrawingRendering Context2D. Content drawn by applications using both drawing APIs can be displayed on the bound Canvas component. CanvasRendering Context2D encapsulates the Native Drawing interface according to W3C standards, making it easy and fast to reuse the drawing logic of web applications. Therefore, it is very suitable for scenarios such as web applications and games, rapid prototyping, data visualization, online drawing boards, teaching tools, or creative applications. @@ -21,13 +22,11 @@ Canvas component is a component used to display self drawn content, which has th └──entry/src/main/resources // Application resources ``` ## Required Permissions + N/A ## Constraints -* This sample is supported only on Huawei phones running the standard system. - -* The HarmonyOS version must be HarmonyOS NEXT Release or later. - -* The DevEco Studio version must be DevEco Studio NEXT Release or later. - -* The HarmonyOS SDK version must be HarmonyOS NEXT Release SDK or later. +1. The sample is only supported on Huawei phones with standard systems. +2. The HarmonyOS version must be HarmonyOS 5.0.5 Release or later. +3. The DevEco Studio version must be DevEco Studio 5.0.5 Release or later. +4. The HarmonyOS SDK version must be HarmonyOS 5.0.5 Release SDK or later. diff --git a/NdkDrawing/build-profile.json5 b/NdkDrawing/build-profile.json5 index 19b2d1d0..3fb2e418 100644 --- a/NdkDrawing/build-profile.json5 +++ b/NdkDrawing/build-profile.json5 @@ -20,8 +20,9 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", - "runtimeOS": "HarmonyOS", + "compatibleSdkVersion": "5.0.5(17)", + "targetSdkVersion": "5.0.5(17)", + "runtimeOS": "HarmonyOS" } ], "buildModeSet": [ diff --git a/NdkDrawing/entry/build-profile.json5 b/NdkDrawing/entry/build-profile.json5 index 640f4efe..631d825b 100644 --- a/NdkDrawing/entry/build-profile.json5 +++ b/NdkDrawing/entry/build-profile.json5 @@ -21,8 +21,9 @@ "arguments": "", "cppFlags": "", "abiFilters": [ - "arm64-v8a","x86_64" - ], + "arm64-v8a", + "x86_64" + ] } }, "buildOptionSet": [ diff --git a/NdkDrawing/entry/src/main/ets/entryability/EntryAbility.ets b/NdkDrawing/entry/src/main/ets/entryability/EntryAbility.ets index d608e6c4..475aab26 100644 --- a/NdkDrawing/entry/src/main/ets/entryability/EntryAbility.ets +++ b/NdkDrawing/entry/src/main/ets/entryability/EntryAbility.ets @@ -18,6 +18,10 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; +const DOMAIN = 0x0000; +const TAG = 'EntryAbility'; +const FORMAT = '%{public}s'; + export default class EntryAbility extends UIAbility { windowClass: window.Window | undefined = undefined; isLayoutFullScreen = true; @@ -37,7 +41,7 @@ export default class EntryAbility extends UIAbility { windowStage.getMainWindow((err: BusinessError, data) => { const errCode: number = err.code; if (errCode) { - console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); + hilog.error(DOMAIN, TAG, FORMAT, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); return; } this.windowClass = data; @@ -45,13 +49,13 @@ export default class EntryAbility extends UIAbility { try { let promise = this.windowClass.setWindowLayoutFullScreen(isLayoutFullScreen); promise.then(() => { - console.info('Succeeded in setting the window layout to full-screen mode.'); + hilog.info(DOMAIN, TAG, FORMAT, 'Succeeded in setting the window layout to full-screen mode.'); }).catch((err: BusinessError) => { - console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, + hilog.error(DOMAIN, TAG, FORMAT, `Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`); }); } catch (exception) { - console.error(`Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, + hilog.error(DOMAIN, TAG, FORMAT, `Failed to set the window layout to full-screen mode. Cause code: ${exception.code}, message: ${exception.message}`); } this.windowClass.setSpecificSystemBarEnabled('navigationIndicator', false); diff --git a/NdkDrawing/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/NdkDrawing/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index be794f48..3370044c 100644 --- a/NdkDrawing/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/NdkDrawing/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -12,15 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { hilog } from '@kit.PerformanceAnalysisKit'; import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; +const DOMAIN = 0x0000; +const TAG = 'EntryBackupAbility'; +const FORMAT = '%{public}s'; + export default class EntryBackupAbility extends BackupExtensionAbility { async onBackup() { - hilog.info(0x0000, 'testTag', 'onBackup ok'); + hilog.info(DOMAIN, TAG, FORMAT, 'onBackup ok'); } async onRestore(bundleVersion: BundleVersion) { - hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + hilog.info(DOMAIN, TAG, FORMAT, `onRestore, bundleVersion: ${bundleVersion}`); } } \ No newline at end of file diff --git a/NdkDrawing/entry/src/main/ets/pages/Index.ets b/NdkDrawing/entry/src/main/ets/pages/Index.ets index d2e27569..815b414a 100644 --- a/NdkDrawing/entry/src/main/ets/pages/Index.ets +++ b/NdkDrawing/entry/src/main/ets/pages/Index.ets @@ -20,6 +20,7 @@ import { FrameNode, NodeController, RenderNode } from '@kit.ArkUI'; import { resourceManager } from '@kit.LocalizationKit'; import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; import { Context } from '@kit.AbilityKit'; import { image } from '@kit.ImageKit'; import testNapi from 'libndkDrawing.so'; @@ -27,17 +28,21 @@ import testNapi from 'libndkDrawing.so'; enum DrawType { NONE, PATH, TEXT, IMAGE }; const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +const DOMAIN = 0x0000; +const TAG = 'Index'; +const FORMAT = '%{public}s'; // [Start my_render_node] // entry\src\main\ets\pages\Index.ets // Define a RenderNode self-drawing RenderNode MyRenderNode, so as to draw with the interface of Native class MyRenderNode extends RenderNode { private drawType: DrawType = DrawType.NONE; - private pMap: image.PixelMap | undefined = undefined; // 背景图 + private pMap: image.PixelMap | undefined = undefined; // background image draw(context: DrawContext): void { - // Call the Native ondraw interface on the native side to draw, and pass in the background image this.pMap and the graphic drawing context as parameters - testNapi.nativeOnDraw(666, context, uiContext?.vp2px(this.size.width), uiContext?.vp2px(this.size.height), this.drawType, this.pMap); + // Call the Native onDraw interface on the native side to draw, and pass in the background image this.pMap and the graphic drawing context as parameters + testNapi.nativeOnDraw(666, context, uiContext?.vp2px(this.size.width), uiContext?.vp2px(this.size.height), + this.drawType, this.pMap); } // Set the drawing type @@ -93,18 +98,22 @@ struct Index { const context: Context = this.getUIContext().getHostContext()!; const resourceMgr: resourceManager.ResourceManager = context.resourceManager; resourceMgr.getRawFileContent('drawImage.jpg').then((fileData: Uint8Array) => { - console.info('success in getRawFileContent'); + hilog.info(DOMAIN, TAG, FORMAT, `success in getRawFileContent`); const buffer = fileData.buffer.slice(0); const imageSource: image.ImageSource = image.createImageSource(buffer); imageSource.createPixelMap().then((pMap: image.PixelMap) => { // Self-drawing rendering node background map newNode.setPixelMap(pMap); }).catch((err: BusinessError) => { - console.error(`fail to create PixelMap, err: ${err}`); + hilog.error(DOMAIN, TAG, FORMAT, `fail to create PixelMap, error code: ${err.code}, message: ${err.message}.`); }).catch((err: BusinessError) => { - console.error(`fail to getRawFileContent, err: ${err}`); - }) - }) + hilog.error(DOMAIN, TAG, FORMAT, + `fail to getRawFileContent, error code: ${err.code}, message: ${err.message}.`); + }); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, FORMAT, + `callback getRawFileContent failed, error code: ${err.code}, message: ${err.message}.`); + }); } build() { diff --git a/NdkDrawing/entry/src/main/ets/view/GlassCoverView.ets b/NdkDrawing/entry/src/main/ets/view/GlassCoverView.ets index 74282041..5d8e7504 100644 --- a/NdkDrawing/entry/src/main/ets/view/GlassCoverView.ets +++ b/NdkDrawing/entry/src/main/ets/view/GlassCoverView.ets @@ -1,5 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // [Start glass_cover_view] -import { hiTraceMeter } from '@kit.PerformanceAnalysisKit'; +import { hilog, hiTraceMeter } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0x0000; +const TAG = 'GlassCoverView'; +const FORMAT = '%{public}s'; /** * Glass cladding effect @@ -40,7 +59,7 @@ export default struct GlassCoverView { } // Hollow transparent circle hiTraceMeter.startTrace('slow', 1); - console.info('debug: slow start'); + hilog.info(DOMAIN, TAG, FORMAT, 'debug: slow start'); // Save drawing context canvas.save(); // Clears the specified pixel within the given rectangle @@ -58,7 +77,7 @@ export default struct GlassCoverView { canvas.fill(); // Restore the saved drawing context canvas.restore(); - console.info('debug: slow end'); + hilog.info(DOMAIN, TAG, FORMAT, 'debug: slow end'); hiTraceMeter.finishTrace('slow', 1); } diff --git a/NdkDrawing/entry/src/main/ets/view/Index.ets b/NdkDrawing/entry/src/main/ets/view/Index.ets index 6a16b817..c1c0d9ef 100644 --- a/NdkDrawing/entry/src/main/ets/view/Index.ets +++ b/NdkDrawing/entry/src/main/ets/view/Index.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // [Start index_view] import GlassCoverView from './GlassCoverView'; -- Gitee