Ultralight C API 1.4.0
|
User-defined pixel buffer surface.
#include <Ultralight/CAPI/CAPI_Surface.h>
The library uses this to store pixel data when rendering Views on the CPU (see ulViewIsAccelerated()).
You can provide the library with your own Surface implementation to reduce the latency of displaying pixels in your application (Views will be drawn directly to a block of memory controlled by you).
When a View is rendered on the CPU, you can retrieve the backing Surface via ulViewGetSurface().
A default Surface implementation, BitmapSurface, is automatically provided by the library when you call ulCreateRenderer() without defining a custom ULSurfaceDefinition.
You should cast the ULSurface to a ULBitmapSurface and call ulBitmapSurfaceGetBitmap() to access the underlying Bitmap.
To define your own implementation, you should implement the ULSurfaceDefinition callbacks, and then pass an instance of ULSurfaceDefinition containing your callbacks to ulPlatformSetSurfaceDefinition() before calling ulCreateRenderer().
Classes | |
struct | ULSurfaceDefinition |
User-defined surface interface. More... | |
Functions | |
ULExport unsigned int | ulSurfaceGetWidth (ULSurface surface) |
Width (in pixels). | |
ULExport unsigned int | ulSurfaceGetHeight (ULSurface surface) |
Height (in pixels). | |
ULExport unsigned int | ulSurfaceGetRowBytes (ULSurface surface) |
Number of bytes between rows (usually width * 4) | |
ULExport size_t | ulSurfaceGetSize (ULSurface surface) |
Size in bytes. | |
ULExport void * | ulSurfaceLockPixels (ULSurface surface) |
Lock the pixel buffer and get a pointer to the beginning of the data for reading/writing. | |
ULExport void | ulSurfaceUnlockPixels (ULSurface surface) |
Unlock the pixel buffer. | |
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 | ulSurfaceSetDirtyBounds (ULSurface surface, ULIntRect bounds) |
Set the dirty bounds to a certain value. | |
ULExport ULIntRect | ulSurfaceGetDirtyBounds (ULSurface surface) |
Get the dirty bounds. | |
ULExport void | ulSurfaceClearDirtyBounds (ULSurface surface) |
Clear the dirty bounds. | |
ULExport void * | ulSurfaceGetUserData (ULSurface surface) |
Get the underlying user data pointer (this is only valid if you have set a custom surface implementation via ulPlatformSetSurfaceDefinition). | |
ULExport ULBitmap | ulBitmapSurfaceGetBitmap (ULBitmapSurface surface) |
Get the underlying Bitmap from the default Surface. | |
Typedefs | |
typedef void *(* | ULSurfaceDefinitionCreateCallback) (unsigned int width, unsigned int height) |
The callback invoked when a Surface is created. | |
typedef void(* | ULSurfaceDefinitionDestroyCallback) (void *user_data) |
The callback invoked when a Surface is destroyed. | |
typedef unsigned int(* | ULSurfaceDefinitionGetWidthCallback) (void *user_data) |
The callback invoked when a Surface's width (in pixels) is requested. | |
typedef unsigned int(* | ULSurfaceDefinitionGetHeightCallback) (void *user_data) |
The callback invoked when a Surface's height (in pixels) is requested. | |
typedef unsigned int(* | ULSurfaceDefinitionGetRowBytesCallback) (void *user_data) |
The callback invoked when a Surface's row bytes is requested. | |
typedef size_t(* | ULSurfaceDefinitionGetSizeCallback) (void *user_data) |
The callback invoked when a Surface's size (in bytes) is requested. | |
typedef void *(* | ULSurfaceDefinitionLockPixelsCallback) (void *user_data) |
The callback invoked when a Surface's pixel buffer is requested to be locked for reading/writing (should return a pointer to locked bytes). | |
typedef void(* | ULSurfaceDefinitionUnlockPixelsCallback) (void *user_data) |
The callback invoked when a Surface's pixel buffer is requested to be unlocked after previously being locked. | |
typedef 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. | |
ULExport ULBitmap ulBitmapSurfaceGetBitmap | ( | ULBitmapSurface | surface | ) |
Get the underlying Bitmap from the default Surface.
Clear the dirty bounds.
You should call this after you're done displaying the Surface.
Get the dirty bounds.
This value can be used to determine which portion of the pixel buffer has been updated since the last call to ulSurfaceClearDirtyBounds().
The general algorithm to determine if a Surface needs display is:
if (!ulIntRectIsEmpty(ulSurfaceGetDirtyBounds(surface))) { // Surface pixels are dirty and needs display. // Cast Surface to native Surface and use it here (pseudo code) DisplaySurface(surface); // Once you're done, clear the dirty bounds: ulSurfaceClearDirtyBounds(surface); }
Number of bytes between rows (usually width * 4)
Get the underlying user data pointer (this is only valid if you have set a custom surface implementation via ulPlatformSetSurfaceDefinition).
This will return nullptr if this surface is the default ULBitmapSurface.
Lock the pixel buffer and get a pointer to the beginning of the data for reading/writing.
Native pixel format is premultiplied BGRA 32-bit (8 bits per channel).
Resize the pixel buffer to a certain width and height (both in pixels).
This should never be called while pixels are locked.
Set the dirty bounds to a certain value.
This is called after the Renderer paints to an area of the pixel buffer. (The new value will be joined with the existing dirty_bounds())
typedef void *(* ULSurfaceDefinitionCreateCallback) (unsigned int width, unsigned int height) |
The callback invoked when a Surface is created.
width | The width in pixels. |
height | The height in pixels. |
typedef void(* ULSurfaceDefinitionDestroyCallback) (void *user_data) |
The callback invoked when a Surface is destroyed.
user_data | User data pointer uniquely identifying the surface. |
typedef unsigned int(* ULSurfaceDefinitionGetHeightCallback) (void *user_data) |
The callback invoked when a Surface's height (in pixels) is requested.
user_data | User data pointer uniquely identifying the surface. |
typedef unsigned int(* ULSurfaceDefinitionGetRowBytesCallback) (void *user_data) |
The callback invoked when a Surface's row bytes is requested.
user_data | User data pointer uniquely identifying the surface. |
typedef size_t(* ULSurfaceDefinitionGetSizeCallback) (void *user_data) |
The callback invoked when a Surface's size (in bytes) is requested.
user_data | User data pointer uniquely identifying the surface. |
typedef unsigned int(* ULSurfaceDefinitionGetWidthCallback) (void *user_data) |
The callback invoked when a Surface's width (in pixels) is requested.
user_data | User data pointer uniquely identifying the surface. |
typedef void *(* ULSurfaceDefinitionLockPixelsCallback) (void *user_data) |
The callback invoked when a Surface's pixel buffer is requested to be locked for reading/writing (should return a pointer to locked bytes).
user_data | User data pointer uniquely identifying the surface. |
typedef 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.
user_data | User data pointer uniquely identifying the surface. |
width | Width in pixels. |
height | Height in pixels. |
typedef void(* ULSurfaceDefinitionUnlockPixelsCallback) (void *user_data) |
The callback invoked when a Surface's pixel buffer is requested to be unlocked after previously being locked.
user_data | User data pointer uniquely identifying the surface. |