From f7643e8cee890bbe88b46e98e4cad8bed7d043ea Mon Sep 17 00:00:00 2001 From: yzj688 Date: Mon, 25 Mar 2024 20:08:10 +0800 Subject: [PATCH] =?UTF-8?q?Drawing=20GPU=20=E7=BB=98=E5=88=B6=E9=9C=80?= =?UTF-8?q?=E6=B1=82=20Signed-off-by:=20yzj688=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphic/graphic_2d/native_drawing/BUILD.gn | 4 + .../native_drawing/drawing_gpu_context.h | 82 ++++++++++++++++++ .../native_drawing/drawing_surface.h | 86 +++++++++++++++++++ .../graphic_2d/native_drawing/drawing_types.h | 16 ++++ .../native_drawing/libnative_drawing.ndk.json | 20 +++++ 5 files changed, 208 insertions(+) create mode 100644 graphic/graphic_2d/native_drawing/drawing_gpu_context.h create mode 100644 graphic/graphic_2d/native_drawing/drawing_surface.h diff --git a/graphic/graphic_2d/native_drawing/BUILD.gn b/graphic/graphic_2d/native_drawing/BUILD.gn index 493714389..da552bd01 100644 --- a/graphic/graphic_2d/native_drawing/BUILD.gn +++ b/graphic/graphic_2d/native_drawing/BUILD.gn @@ -26,6 +26,7 @@ ohos_ndk_headers("native_drawing_header") { "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_filter.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_font.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_font_collection.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_gpu_context.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_image.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_mask_filter.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_matrix.h", @@ -41,6 +42,7 @@ ohos_ndk_headers("native_drawing_header") { "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_round_rect.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_sampling_options.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_shader_effect.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_surface.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_blob.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_declaration.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_typography.h", @@ -64,6 +66,7 @@ ohos_ndk_library("libnative_drawing_ndk") { "native_drawing/drawing_filter.h", "native_drawing/drawing_font.h", "native_drawing/drawing_font_collection.h", + "native_drawing/drawing_gpu_context.h", "native_drawing/drawing_mask_filter.h", "native_drawing/drawing_matrix.h", "native_drawing/drawing_memory_stream.h", @@ -79,6 +82,7 @@ ohos_ndk_library("libnative_drawing_ndk") { "native_drawing/drawing_image.h", "native_drawing/drawing_sampling_options.h", "native_drawing/drawing_shader_effect.h", + "native_drawing/drawing_surface.h", "native_drawing/drawing_text_blob.h", "native_drawing/drawing_text_declaration.h", "native_drawing/drawing_text_typography.h", diff --git a/graphic/graphic_2d/native_drawing/drawing_gpu_context.h b/graphic/graphic_2d/native_drawing/drawing_gpu_context.h new file mode 100644 index 000000000..c0f1d3cfe --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_gpu_context.h @@ -0,0 +1,82 @@ +/* + * 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. + */ + +#ifndef C_INCLUDE_DRAWING_GPU_CONTEXT_H +#define C_INCLUDE_DRAWING_GPU_CONTEXT_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 8 + * @version 1.0 + */ + +/** + * @file drawing_gpu_context.h + * + * @brief Declares functions related to the OH_Drawing_GpuContext object in the drawing module. + * + * @since 12 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines the options about GPU context. + * + * @since 12 + * @version 1.0 + */ +typedef struct { + /** If true this allows path mask textures to be cached */ + bool allowPathMaskCaching; +} OH_Drawing_GpuContextOptions; + +/** + * @brief Creates an OH_Drawing_GpuContext object, whose GPU backend context is GL. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_GpuContextOptions Indicates the GPU context options. + * @return Returns the pointer to the OH_Drawing_GpuContext object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_GpuContext* OH_Drawing_GpuContextCreateFromGL(OH_Drawing_GpuContextOptions); + +/** + * @brief Destroys an OH_Drawing_GpuContext object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_GpuContext Indicates the pointer to an OH_Drawing_GpuContext object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_GpuContextDestroy(OH_Drawing_GpuContext*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif \ No newline at end of file diff --git a/graphic/graphic_2d/native_drawing/drawing_surface.h b/graphic/graphic_2d/native_drawing/drawing_surface.h new file mode 100644 index 000000000..fd685a8e4 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_surface.h @@ -0,0 +1,86 @@ +/* + * 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. + */ + +#ifndef C_INCLUDE_DRAWING_GPU_SURFACE_H +#define C_INCLUDE_DRAWING_GPU_SURFACE_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 8 + * @version 1.0 + */ + +/** + * @file drawing_surface.h + * + * @brief Declares functions related to the OH_Drawing_Surface object in the drawing module. + * + * @since 12 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_Surface object on GPU indicated by context. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_GpuContext Indicates the pointer to an OH_Drawing_GpuContext object. + * @param bool Indicates whether an allocation should count against a cache budget. + * @param OH_Drawing_Image_Info Indicates the image info. + * @return Returns the pointer to the OH_Drawing_Surface object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Surface* OH_Drawing_SurfaceCreateFromGpuContext( + OH_Drawing_GpuContext*, bool, OH_Drawing_Image_Info); + +/** + * @brief Gets the canvas that draws into surface. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Surface Indicates the pointer to an OH_Drawing_Surface object. + * @return Returns the pointer to the OH_Drawing_Canvas object. The returned pointer does not need to be managed + * by the caller. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Canvas* OH_Drawing_SurfaceGetCanvas(OH_Drawing_Surface*); + +/** + * @brief Destroys an OH_Drawing_Surface object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Surface Indicates the pointer to an OH_Drawing_Surface object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_SurfaceDestroy(OH_Drawing_Surface*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif \ No newline at end of file diff --git a/graphic/graphic_2d/native_drawing/drawing_types.h b/graphic/graphic_2d/native_drawing/drawing_types.h index f4f7db452..b19e7775c 100644 --- a/graphic/graphic_2d/native_drawing/drawing_types.h +++ b/graphic/graphic_2d/native_drawing/drawing_types.h @@ -261,6 +261,22 @@ typedef struct OH_Drawing_SamplingOptions OH_Drawing_SamplingOptions; */ typedef struct OH_Drawing_TextBlobBuilder OH_Drawing_TextBlobBuilder; +/** + * @brief Defines a GPU context, which is used to describe the GPU backend context. + * + * @since 12 + * @version 1.0 + */ +typedef struct OH_Drawing_GpuContext OH_Drawing_GpuContext; + +/** + * @brief Defines a surface, which is used to manage the pixels that a canvas draws into. + * + * @since 12 + * @version 1.0 + */ +typedef struct OH_Drawing_Surface OH_Drawing_Surface; + /** * @brief Enumerates storage formats of bitmap pixels. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index c9e077bd6..f484c0cb1 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -138,6 +138,14 @@ { "name": "OH_Drawing_FontSetTypeface" }, { "name": "OH_Drawing_FontGetMetrics" }, { "name": "OH_Drawing_FontGetTypeface" }, + { + "first_introduced": "12", + "name": "OH_Drawing_GpuContextCreateFromGL" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_GpuContextDestroy" + }, { "name": "OH_Drawing_MaskFilterCreateBlur" }, { "name": "OH_Drawing_MaskFilterDestroy" }, { "name": "OH_Drawing_MatrixCreate" }, @@ -388,6 +396,18 @@ "name": "OH_Drawing_ShaderEffectCreateImageShader" }, { "name": "OH_Drawing_ShaderEffectDestroy" }, + { + "first_introduced": "12", + "name": "OH_Drawing_SurfaceCreateFromGpuContext" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_SurfaceGetCanvas" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_SurfaceDestroy" + }, { "name": "OH_Drawing_TextBlobCreateFromText" }, { "name": "OH_Drawing_TextBlobCreateFromPosText" }, { "name": "OH_Drawing_TextBlobCreateFromString" }, -- Gitee