diff --git a/NdkDrawing/README.md b/NdkDrawing/README.md index 2481019293a69d972207f3cb7fe00a30227c5b17..1c5dd8090d37fdd506a7f7b38354d6af04e6a8af 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 603847f154d1c37a713087093b136a009e662bc3..be463aed500e4c0a2f1e1d78c9cab5abd54571ee 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 19b2d1d0b868064df8c461ecdbbdbb5f6755b07f..3fb2e418f34d930a1da27e87e13bbbf2e637856f 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 640f4efe5cc97a212f4c9258e817ae601ab3a79c..631d825bd17cb1fad5d90a68fe156a605230d2c1 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 d608e6c452f2c69c1b8d558700b25884b4af49a4..475aab26e847f67f33d83e74bd7ba721af7547db 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 be794f48ccffc46278e76ce3493088a647b0d470..3370044c096f8eb0c868df55509a582ae5315c14 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 d2e27569b2eb8bf3c39bea18d284bd6e8e05b167..815b414a831107cacb9bd3f30841a511fd950e6e 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 742820410944709a2c1f36635ff89f68691a9fd7..5d8e7504c7a1cb4858d4b8c4a90c8fa710729ff1 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 6a16b81767ba83bfcd1d77f76378b14aab202547..c1c0d9ef70e342b2be50a9a6afebe540cf9116d6 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';