Ultralight C API 1.3.0
Loading...
Searching...
No Matches
CAPI_Surface.h
Go to the documentation of this file.
1/******************************************************************************
2 * This file is a part of Ultralight, an ultra-portable web-browser engine. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2023 Ultralight, Inc. *
7 *****************************************************************************/
8#ifndef ULTRALIGHT_CAPI_SURFACE_H
9#define ULTRALIGHT_CAPI_SURFACE_H
10
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/******************************************************************************
18 * Surface
19 *****************************************************************************/
20
21///
22/// Width (in pixels).
23///
24ULExport unsigned int ulSurfaceGetWidth(ULSurface surface);
25
26///
27/// Height (in pixels).
28///
30
31///
32/// Number of bytes between rows (usually width * 4)
33///
35
36///
37/// Size in bytes.
38///
40
41///
42/// Lock the pixel buffer and get a pointer to the beginning of the data for reading/writing.
43///
44/// Native pixel format is premultiplied BGRA 32-bit (8 bits per channel).
45///
47
48///
49/// Unlock the pixel buffer.
50///
52
53///
54/// Resize the pixel buffer to a certain width and height (both in pixels).
55///
56/// This should never be called while pixels are locked.
57///
58ULExport void ulSurfaceResize(ULSurface surface, unsigned int width, unsigned int height);
59
60///
61/// Set the dirty bounds to a certain value.
62///
63/// This is called after the Renderer paints to an area of the pixel buffer. (The new value will be
64/// joined with the existing dirty_bounds())
65///
67
68///
69/// Get the dirty bounds.
70///
71/// This value can be used to determine which portion of the pixel buffer has been updated since the
72/// last call to ulSurfaceClearDirtyBounds().
73///
74/// The general algorithm to determine if a Surface needs display is:
75/// <pre>
76/// if (!ulIntRectIsEmpty(ulSurfaceGetDirtyBounds(surface))) {
77/// // Surface pixels are dirty and needs display.
78/// // Cast Surface to native Surface and use it here (pseudo code)
79/// DisplaySurface(surface);
80///
81/// // Once you're done, clear the dirty bounds:
82/// ulSurfaceClearDirtyBounds(surface);
83/// }
84/// </pre>
85///
87
88///
89/// Clear the dirty bounds.
90///
91/// You should call this after you're done displaying the Surface.
92///
94
95///
96/// Get the underlying user data pointer (this is only valid if you have set a custom surface
97/// implementation via ulPlatformSetSurfaceDefinition).
98///
99/// This will return nullptr if this surface is the default ULBitmapSurface.
100///
102
103/******************************************************************************
104 * BitmapSurface
105 *****************************************************************************/
106
107///
108/// Get the underlying Bitmap from the default Surface.
109///
110/// @note Do not call ulDestroyBitmap() on the returned value, it is owned by the surface.
111///
113
114/******************************************************************************
115 * Surface Definition
116 *****************************************************************************/
117
118///
119/// The callback invoked when a Surface is created.
120///
121/// @param width The width in pixels.
122/// @param height The height in pixels.
123///
124/// @return This callback should return a pointer to user-defined data for the instance. This user
125/// data pointer will be passed to all other callbacks when operating on the instance.
126///
127typedef void* (*ULSurfaceDefinitionCreateCallback)(unsigned int width, unsigned int height);
128
129///
130/// The callback invoked when a Surface is destroyed.
131///
132/// @param user_data User data pointer uniquely identifying the surface.
133///
134typedef void (*ULSurfaceDefinitionDestroyCallback)(void* user_data);
135
136///
137/// The callback invoked when a Surface's width (in pixels) is requested.
138///
139/// @param user_data User data pointer uniquely identifying the surface.
140///
141typedef unsigned int (*ULSurfaceDefinitionGetWidthCallback)(void* user_data);
142
143///
144/// The callback invoked when a Surface's height (in pixels) is requested.
145///
146/// @param user_data User data pointer uniquely identifying the surface.
147///
148typedef unsigned int (*ULSurfaceDefinitionGetHeightCallback)(void* user_data);
149
150///
151/// The callback invoked when a Surface's row bytes is requested.
152///
153/// @note This value is also known as "stride". Usually width * 4.
154///
155/// @param user_data User data pointer uniquely identifying the surface.
156///
157typedef unsigned int (*ULSurfaceDefinitionGetRowBytesCallback)(void* user_data);
158
159///
160/// The callback invoked when a Surface's size (in bytes) is requested.
161///
162/// @param user_data User data pointer uniquely identifying the surface.
163///
164typedef size_t (*ULSurfaceDefinitionGetSizeCallback)(void* user_data);
165
166///
167/// The callback invoked when a Surface's pixel buffer is requested to be locked for reading/writing
168/// (should return a pointer to locked bytes).
169///
170/// @param user_data User data pointer uniquely identifying the surface.
171///
172typedef void* (*ULSurfaceDefinitionLockPixelsCallback)(void* user_data);
173
174///
175/// The callback invoked when a Surface's pixel buffer is requested to be unlocked after previously
176/// being locked.
177///
178/// @param user_data User data pointer uniquely identifying the surface.
179///
180typedef void (*ULSurfaceDefinitionUnlockPixelsCallback)(void* user_data);
181
182///
183/// The callback invoked when a Surface is requested to be resized to a certain width/height.
184///
185/// @param user_data User data pointer uniquely identifying the surface.
186///
187/// @param width Width in pixels.
188///
189/// @param height Height in pixels.
190///
191typedef void (*ULSurfaceDefinitionResizeCallback)(void* user_data, unsigned int width,
192 unsigned int height);
193
194typedef struct {
205
206#ifdef __cplusplus
207} // extern "C"
208#endif
209
210#endif // ULTRALIGHT_CAPI_SURFACE_H
struct C_Surface * ULBitmapSurface
Definition CAPI_Defines.h:63
#define ULExport
Definition CAPI_Defines.h:27
struct C_Surface * ULSurface
Definition CAPI_Defines.h:62
struct C_Bitmap * ULBitmap
Definition CAPI_Defines.h:53
ULExport ULBitmap ulBitmapSurfaceGetBitmap(ULBitmapSurface surface)
Get the underlying Bitmap from the default Surface.
ULExport unsigned int ulSurfaceGetWidth(ULSurface surface)
Width (in pixels).
ULExport void ulSurfaceUnlockPixels(ULSurface surface)
Unlock the pixel buffer.
unsigned int(* ULSurfaceDefinitionGetRowBytesCallback)(void *user_data)
The callback invoked when a Surface's row bytes is requested.
Definition CAPI_Surface.h:157
ULExport void ulSurfaceResize(ULSurface surface, unsigned int width, unsigned int height)
Resize the pixel buffer to a certain width and height (both in pixels).
ULExport void * ulSurfaceLockPixels(ULSurface surface)
Lock the pixel buffer and get a pointer to the beginning of the data for reading/writing.
ULExport size_t ulSurfaceGetSize(ULSurface surface)
Size in bytes.
ULExport ULIntRect ulSurfaceGetDirtyBounds(ULSurface surface)
Get the dirty bounds.
ULExport unsigned int ulSurfaceGetRowBytes(ULSurface surface)
Number of bytes between rows (usually width * 4)
ULExport void ulSurfaceClearDirtyBounds(ULSurface surface)
Clear the dirty bounds.
ULExport unsigned int ulSurfaceGetHeight(ULSurface surface)
Height (in pixels).
void(* ULSurfaceDefinitionResizeCallback)(void *user_data, unsigned int width, unsigned int height)
The callback invoked when a Surface is requested to be resized to a certain width/height.
Definition CAPI_Surface.h:191
void *(* ULSurfaceDefinitionCreateCallback)(unsigned int width, unsigned int height)
The callback invoked when a Surface is created.
Definition CAPI_Surface.h:127
unsigned int(* ULSurfaceDefinitionGetWidthCallback)(void *user_data)
The callback invoked when a Surface's width (in pixels) is requested.
Definition CAPI_Surface.h:141
void(* ULSurfaceDefinitionDestroyCallback)(void *user_data)
The callback invoked when a Surface is destroyed.
Definition CAPI_Surface.h:134
ULExport void ulSurfaceSetDirtyBounds(ULSurface surface, ULIntRect bounds)
Set the dirty bounds to a certain value.
void(* ULSurfaceDefinitionUnlockPixelsCallback)(void *user_data)
The callback invoked when a Surface's pixel buffer is requested to be unlocked after previously being...
Definition CAPI_Surface.h:180
void *(* ULSurfaceDefinitionLockPixelsCallback)(void *user_data)
The callback invoked when a Surface's pixel buffer is requested to be locked for reading/writing (sho...
Definition CAPI_Surface.h:172
ULExport void * ulSurfaceGetUserData(ULSurface surface)
Get the underlying user data pointer (this is only valid if you have set a custom surface implementat...
size_t(* ULSurfaceDefinitionGetSizeCallback)(void *user_data)
The callback invoked when a Surface's size (in bytes) is requested.
Definition CAPI_Surface.h:164
unsigned int(* ULSurfaceDefinitionGetHeightCallback)(void *user_data)
The callback invoked when a Surface's height (in pixels) is requested.
Definition CAPI_Surface.h:148
Definition CAPI_Defines.h:242
Definition CAPI_Surface.h:194
ULSurfaceDefinitionGetSizeCallback get_size
Definition CAPI_Surface.h:200
ULSurfaceDefinitionGetRowBytesCallback get_row_bytes
Definition CAPI_Surface.h:199
ULSurfaceDefinitionUnlockPixelsCallback unlock_pixels
Definition CAPI_Surface.h:202
ULSurfaceDefinitionResizeCallback resize
Definition CAPI_Surface.h:203
ULSurfaceDefinitionLockPixelsCallback lock_pixels
Definition CAPI_Surface.h:201
ULSurfaceDefinitionGetWidthCallback get_width
Definition CAPI_Surface.h:197
ULSurfaceDefinitionDestroyCallback destroy
Definition CAPI_Surface.h:196
ULSurfaceDefinitionGetHeightCallback get_height
Definition CAPI_Surface.h:198
ULSurfaceDefinitionCreateCallback create
Definition CAPI_Surface.h:195