openharmony 鸿蒙 capi-drawing-surface-h

2026-08-25 浏览 (1)

drawing_surface.h

Overview

This file declares the functions related to the surface in the drawing module, including creating, destroying, and using the surface.

File to include: <native_drawing/drawing_surface.h>

Library: libnative_drawing.so

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Related module: Drawing

Summary

Functions

NameDescription
OH_Drawing_Surface* OH_Drawing_SurfaceCreateFromGpuContext(OH_Drawing_GpuContext* gpuContext, bool flag, OH_Drawing_Image_Info imageInfo)Creates an OH_Drawing_Surface object using the GPU context to manage the content drawn on the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If gpuContext is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_Surface* OH_Drawing_SurfaceCreateOnScreen(OH_Drawing_GpuContext* gpuContext, OH_Drawing_Image_Info imageInfo, void* window)Creates an OH_Drawing_Surface object bound to the window using the GPU context to manage the content drawn on the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
OH_DRAWING_ERROR_INVALID_PARAMETER if gpuContext or window is NULL.
OH_Drawing_Canvas* OH_Drawing_SurfaceGetCanvas(OH_Drawing_Surface* surface)Obtains a canvas from an OH_Drawing_Surface object.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If surface is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_ErrorCode OH_Drawing_SurfaceFlush(OH_Drawing_Surface* surface)Pushes the drawing content from an OH_Drawing_Surface object to the GPU for rendering.
void OH_Drawing_SurfaceDestroy(OH_Drawing_Surface* surface)Destroys an OH_Drawing_Surface object and reclaims the memory occupied.

Function Description

OH_Drawing_SurfaceCreateFromGpuContext()

OH_Drawing_Surface* OH_Drawing_SurfaceCreateFromGpuContext(OH_Drawing_GpuContext* gpuContext, bool flag, OH_Drawing_Image_Info imageInfo)

Description

Creates an OH_Drawing_Surface object using the GPU context to manage the content drawn on the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If gpuContext is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_GpuContext* gpuContextPointer to an OH_Drawing_GpuContext object.
bool flagWhether the memory allocation is counted in the cache budget. true means yes; false otherwise.
OH_Drawing_Image_Info imageInfoImage information struct.

Returns

TypeDescription
OH_Drawing_Surface*Returns a pointer to the created OH_Drawing_Surface object.

OH_Drawing_SurfaceCreateOnScreen()

OH_Drawing_Surface* OH_Drawing_SurfaceCreateOnScreen(OH_Drawing_GpuContext* gpuContext, OH_Drawing_Image_Info imageInfo, void* window)

Description

Creates an OH_Drawing_Surface object bound to the window using the GPU context to manage the content drawn on the canvas.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
OH_DRAWING_ERROR_INVALID_PARAMETER if gpuContext or window is NULL.
The width and height of imageInfo must be the same as those of window.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 16

Parameters

NameDescription
OH_Drawing_GpuContext* gpuContextPointer to an OH_Drawing_GpuContext object.
This object must be created by OH_Drawing_GpuContextCreate. Otherwise, the OH_Drawing_Surface object fails to be created.
OH_Drawing_Image_Info imageInfoImage information struct.
void* windowPointer to the window object.

Returns

TypeDescription
OH_Drawing_Surface*Returns a pointer to the created OH_Drawing_Surface object.

OH_Drawing_SurfaceGetCanvas()

OH_Drawing_Canvas* OH_Drawing_SurfaceGetCanvas(OH_Drawing_Surface* surface)

Description

Obtains a canvas from an OH_Drawing_Surface object.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If surface is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Surface* surfacePointer to an OH_Drawing_Surface object.

Returns

TypeDescription
OH_Drawing_Canvas*Returns a pointer to the created OH_Drawing_Canvas object. The pointer returned does not need to be managed by the caller.

OH_Drawing_SurfaceFlush()

OH_Drawing_ErrorCode OH_Drawing_SurfaceFlush(OH_Drawing_Surface* surface)

Description

Pushes the drawing content from an OH_Drawing_Surface object to the GPU for rendering.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 16

Parameters

NameDescription
OH_Drawing_Surface* surfacePointer to the created OH_Drawing_Surface object. This object must be created by calling OH_Drawing_SurfaceCreateOnScreen. Otherwise, calling the current API has no effect.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if surface is NULL.

OH_Drawing_SurfaceDestroy()

void OH_Drawing_SurfaceDestroy(OH_Drawing_Surface* surface)

Description

Destroys an OH_Drawing_Surface object and reclaims the memory occupied.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Surface* surfacePointer to an OH_Drawing_Surface object.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-drawing-gpu-context-h

openharmony 鸿蒙 capi-drawing-nativepixelmap-

openharmony 鸿蒙 capi-nativevsync-oh-nativevsync-expectedraterange

openharmony 鸿蒙 capi-drawing-oh-drawing-brush

openharmony 鸿蒙 capi-drawing-oh-drawing-image-info

openharmony 鸿蒙 capi-drawing-text-linetypography-h

openharmony 鸿蒙 capi-oh-nativeimage-oh-nativeimage

openharmony 鸿蒙 capi-drawing-typeface-h

openharmony 鸿蒙 capi-drawing-brush-h

openharmony 鸿蒙 capi-nativewindow

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/FdQZHi2Z