We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesGraphicsArkGraphics 2DC APIsHeader Filesdrawing_surface.h

drawing_surface.h

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

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

Expand
Name Description
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()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_GpuContext* gpuContext Pointer to an OH_Drawing_GpuContext object.
bool flag Whether the memory allocation is counted in the cache budget. true means yes; false otherwise.
OH_Drawing_Image_Info imageInfo Image information struct.

Returns

Expand
Type Description
OH_Drawing_Surface* Returns a pointer to the created OH_Drawing_Surface object.

OH_Drawing_SurfaceCreateOnScreen()

Phone16+PC/2in116+Tablet16+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_GpuContext* gpuContext

Pointer 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 imageInfo Image information struct.
void* window Pointer to the window object.

Returns

Expand
Type Description
OH_Drawing_Surface* Returns a pointer to the created OH_Drawing_Surface object.

OH_Drawing_SurfaceGetCanvas()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Surface* surface Pointer to an OH_Drawing_Surface object.

Returns

Expand
Type Description
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()

Phone16+PC/2in116+Tablet16+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Surface* surface Pointer 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

Expand
Type Description
OH_Drawing_ErrorCode

Returns 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()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
Collapse
Word wrap
Dark theme
Copy code
  1. 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

Expand
Name Description
OH_Drawing_Surface* surface Pointer to an OH_Drawing_Surface object.