Skip to content

Commit 06f7176

Browse files
author
sebuntin
committed
ohos: Implement OHComposeNativePaint and enhance AdaptiveCanvas with native paint synchronization
1 parent 64268a2 commit 06f7176

File tree

28 files changed

+1642
-71
lines changed

28 files changed

+1642
-71
lines changed

compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/TextStringSimpleNode.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package androidx.compose.foundation.text.modifiers
1919
import androidx.compose.foundation.text.DefaultMinLines
2020
import androidx.compose.runtime.ComposeTabService
2121
import androidx.compose.runtime.EnableIOSParagraph
22+
import androidx.compose.runtime.EnableOHOSParagraph
2223
import androidx.compose.runtime.getValue
2324
import androidx.compose.runtime.mutableStateOf
2425
import androidx.compose.runtime.setValue
@@ -496,16 +497,16 @@ internal class TextStringSimpleNode(
496497
drawIntoCanvas { canvas ->
497498
var currentParagraphHashCode = 0
498499
// region Tencent Code
499-
if (drawInSkia || EnableIOSParagraph || platformTextDelegate == null) {
500+
if (drawInSkia || EnableIOSParagraph || EnableOHOSParagraph) {
500501
localCanvas = canvas
501502
} else {
502503
currentParagraphHashCode = paragraphHashCode()
503-
if (!platformTextDelegate.needRedrawText(
504+
if (platformTextDelegate?.needRedrawText(
504505
nativeCanvas = canvas,
505506
paragraphHashKey = currentParagraphHashCode,
506507
width = layoutCache.layoutSize.width,
507508
height = layoutCache.layoutSize.height
508-
)
509+
) == false
509510
) return
510511
ensureTextBitmap()
511512
}

compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/GlobalSwitch.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ expect val CurrentPlatform: PlatformType
2929
/** IOSParagraph开关 */
3030
var EnableIOSParagraph = false
3131

32+
/** OHOSParagraph开关 **/
33+
var EnableOHOSParagraph = false
34+
3235
var EnableSkiaBackedCanvasLog = false
3336

3437
var DeleteRedundantGraphicsLayer = false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
package = androidx.compose.ui.arkui.utils
2-
headers = arkui_utils_export.h canvas/oh_native_canvas_export.h
2+
headers = arkui_utils_export.h canvas/oh_native_canvas_export.h canvas/oh_native_enums.h

compose/ui/ui-arkui/src/ohosArm64Main/cinterop/arkui.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ headers = ace/xcomponent/native_interface_xcomponent.h native_interface_accessib
33
napi/common.h napi/native_api.h \
44
js_native_api_types.h js_native_api.h node_api.h node_api_types.h \
55
drawable_descriptor.h native_type.h native_node.h native_node_napi.h native_interface.h \
6-
ui_input_event.h native_gesture.h native_render.h
6+
ui_input_event.h native_gesture.h native_render.h \
7+
native_drawing/drawing_types.h native_drawing/drawing_shader_effect.h native_drawing/drawing_point.h native_drawing/drawing_error_code.h
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2024 Huawei Device Co., Ltd.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/**
17+
* @addtogroup Drawing
18+
* @{
19+
*
20+
* @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
21+
*
22+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
23+
*
24+
* @since 8
25+
* @version 1.0
26+
*/
27+
28+
/**
29+
* @file drawing_error_code.h
30+
*
31+
* @brief Declares functions related to the error code in the drawing module.
32+
*
33+
* @kit ArkGraphics2D
34+
* @library libnative_drawing.so
35+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
36+
* @since 12
37+
* @version 1.0
38+
*/
39+
40+
#ifndef C_INCLUDE_DRAWING_ERROR_CODE_H
41+
#define C_INCLUDE_DRAWING_ERROR_CODE_H
42+
43+
#ifdef __cplusplus
44+
extern "C" {
45+
#endif
46+
47+
/**
48+
* @brief Enumerates error codes of drawing.
49+
* @since 12
50+
*/
51+
typedef enum {
52+
/**
53+
* @error Operation completed successfully.
54+
*/
55+
OH_DRAWING_SUCCESS = 0,
56+
/**
57+
* @error Permission verification failed.
58+
*/
59+
OH_DRAWING_ERROR_NO_PERMISSION = 201,
60+
/**
61+
* @error Invalid input parameter. For example, the pointer in the parameter is a nullptr.
62+
*/
63+
OH_DRAWING_ERROR_INVALID_PARAMETER = 401,
64+
/**
65+
* @error The parameter is not in the valid range.
66+
*/
67+
OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE = 26200001,
68+
/**
69+
* @error mem allocate failed.
70+
* @since 13
71+
*/
72+
OH_DRAWING_ERROR_ALLOCATION_FAILED = 26200002,
73+
} OH_Drawing_ErrorCode;
74+
75+
/**
76+
* @brief Obtains the error code of the drawing module.
77+
*
78+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
79+
* @return Returns the error code.
80+
* @since 12
81+
* @version 1.0
82+
*/
83+
OH_Drawing_ErrorCode OH_Drawing_ErrorCodeGet();
84+
85+
/**
86+
* @brief Resets the error code of the drawing module to OH_DRAWING_SUCCESS.
87+
*
88+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
89+
* @since 18
90+
* @version 1.0
91+
*/
92+
void OH_Drawing_ErrorCodeReset(void);
93+
#ifdef __cplusplus
94+
}
95+
#endif
96+
/** @} */
97+
#endif
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (c) 2023 Huawei Device Co., Ltd.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/**
17+
* @addtogroup Drawing
18+
* @{
19+
*
20+
* @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
21+
*
22+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
23+
*
24+
* @since 11
25+
* @version 1.0
26+
*/
27+
28+
/**
29+
* @file drawing_point.h
30+
*
31+
* @brief Declares functions related to the <b>point</b> object in the drawing module.
32+
*
33+
* @kit ArkGraphics2D
34+
* @library libnative_drawing.so
35+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
36+
* @since 11
37+
* @version 1.0
38+
*/
39+
40+
#ifndef C_INCLUDE_DRAWING_POINT_H
41+
#define C_INCLUDE_DRAWING_POINT_H
42+
43+
#include "drawing_error_code.h"
44+
#include "drawing_types.h"
45+
46+
#ifdef __cplusplus
47+
extern "C" {
48+
#endif
49+
50+
/**
51+
* @brief Creates an <b>OH_Drawing_Point</b> object.
52+
*
53+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
54+
* @param x Indicates the x-axis coordinates of the point.
55+
* @param y Indicates the y-axis coordinates of the point.
56+
* @return Returns the pointer to the <b>OH_Drawing_Point</b> object created.
57+
* @since 11
58+
* @version 1.0
59+
*/
60+
OH_Drawing_Point* OH_Drawing_PointCreate(float x, float y);
61+
62+
/**
63+
* @brief Gets the x-axis coordinate of the point.
64+
*
65+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
66+
* @param point Indicates the pointer to an <b>OH_Drawing_Point</b> object.
67+
* @param x Indicates the x-axis coordinate of the point.
68+
* @return Returns the error code.
69+
* Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
70+
* Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if point or x is nullptr.
71+
* @since 12
72+
* @version 1.0
73+
*/
74+
OH_Drawing_ErrorCode OH_Drawing_PointGetX(const OH_Drawing_Point* point, float* x);
75+
76+
/**
77+
* @brief Gets the y-axis coordinate of the point.
78+
*
79+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
80+
* @param point Indicates the pointer to an <b>OH_Drawing_Point</b> object.
81+
* @param y Indicates the y-axis coordinate of the point.
82+
* @return Returns the error code.
83+
* Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
84+
* Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if point or y is nullptr.
85+
* @since 12
86+
* @version 1.0
87+
*/
88+
OH_Drawing_ErrorCode OH_Drawing_PointGetY(const OH_Drawing_Point* point, float* y);
89+
90+
/**
91+
* @brief Sets the x-axis and y-axis coordinates of the point.
92+
*
93+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
94+
* @param point Indicates the pointer to an <b>OH_Drawing_Point</b> object.
95+
* @param x Indicates the x-axis coordinate of the point.
96+
* @param y Indicates the y-axis coordinate of the point.
97+
* @return Returns the error code.
98+
* Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
99+
* Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if point is nullptr.
100+
* @since 12
101+
* @version 1.0
102+
*/
103+
OH_Drawing_ErrorCode OH_Drawing_PointSet(OH_Drawing_Point* point, float x, float y);
104+
105+
/**
106+
* @brief Destroys an <b>OH_Drawing_Point</b> object and reclaims the memory occupied by the object.
107+
*
108+
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
109+
* @param point Indicates the pointer to an <b>OH_Drawing_Point</b> object.
110+
* @since 11
111+
* @version 1.0
112+
*/
113+
void OH_Drawing_PointDestroy(OH_Drawing_Point* point);
114+
115+
#ifdef __cplusplus
116+
}
117+
#endif
118+
/** @} */
119+
#endif

0 commit comments

Comments
 (0)