Loading...
Searching...
No Matches
CAPI_ImageSource.h
Go to the documentation of this file.
1/**************************************************************************************************
2 * This file is a part of Ultralight. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2024 Ultralight, Inc. *
7 **************************************************************************************************/
8
9///
10/// @file CAPI_ImageSource.h
11///
12/// User-defined image source to display custom images on a web-page.
13///
14/// `#include <Ultralight/CAPI/CAPI_ImageSource.h>`
15///
16/// This API allows you to composite your own images into a web-page. This is useful for displaying
17/// in-game textures, external image assets, or other custom content.
18///
19/// ## ImageSource File Format
20///
21/// To use an ImageSource, you must first create an `.imgsrc` file containing a string identifying
22/// the image source. This string will be used to lookup the ImageSource from ImageSourceProvider
23/// when it is loaded on a web-page.
24///
25/// The file format is as follows:
26///
27/// ```
28/// IMGSRC-V1
29/// <identifier>
30/// ```
31///
32/// You can use the `.imgsrc` file anywhere in your web-page that typically accepts an image URL.
33/// For example:
34///
35/// ```html
36/// <img src="my_custom_image.imgsrc" />
37/// ```
38///
39/// ## Creating from a GPU Texture
40///
41/// To composite your own GPU texture on a web-page, you should first reserve a texture ID from
42/// ULGPUDriver::next_texture_id and then create an ImageSource from that texture ID. Next, you
43/// should register the ImageSource with ImageSourceProvider using the identifier from the `.imgsrc`
44/// file.
45///
46/// When the image element is drawn on the web-page, the library will draw geometry using the
47/// specified texture ID and UV coordinates. You should bind your own texture when the specified
48/// texture ID is used.
49///
50/// If the GPU renderer is not enabled for the View or pixel data is needed for other purposes, the
51/// library will sample the backing bitmap instead.
52///
53/// ## Creating from a Bitmap
54///
55/// To composite your own bitmap on a web-page, you should create an ImageSource from a Bitmap.
56/// Next, you should register the ImageSource with ImageSourceProvider using the identifier from
57/// the `.imgsrc` file.
58///
59/// When the image element is drawn on the web-page, the library will sample this bitmap directly.
60///
61/// ## Invalidating Images
62///
63/// If you modify the texture or bitmap after creating the ImageSource, you should call
64/// ulImageSourceInvalidate() to notify the library that the image should be redrawn.
65///
66#ifndef ULTRALIGHT_CAPI_IMAGESOURCE_H
67#define ULTRALIGHT_CAPI_IMAGESOURCE_H
68
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75/******************************************************************************
76 * ImageSource
77 *****************************************************************************/
78
79///
80/// Create an image source from a GPU texture with optional backing bitmap.
81///
82/// @param width The width of the image in pixels (used for layout).
83///
84/// @param height The height of the image in pixels (used for layout).
85///
86/// @param texture_id The GPU texture identifier to bind when drawing the quad for this image.
87/// This should be non-zero and obtained from ULGPUDriver::next_texture_id.
88///
89/// @param texture_uv The UV coordinates of the texture.
90///
91/// @param bitmap Optional backing bitmap for this image source. This is used when drawing
92/// the image using the CPU renderer or when pixel data is needed for other
93/// purposes. You should update this bitmap when the texture changes.
94///
95/// @return A new image source instance.
96///
97ULExport ULImageSource ulCreateImageSourceFromTexture(unsigned int width, unsigned int height,
98 unsigned int texture_id, ULRect texture_uv,
99 ULBitmap bitmap);
100
101///
102/// Create an image source from a bitmap.
103///
104/// @param bitmap The backing bitmap for this image source.
105///
106/// @return A new image source instance.
107///
109
110///
111/// Destroy an image source.
112///
113/// @param image_source The image source to destroy.
114///
116
117///
118/// Invalidate the image source, notifying the library that the image has changed
119/// and should be redrawn.
120///
122
123/******************************************************************************
124 * ImageSourceProvider
125 *****************************************************************************/
126
127///
128/// Add an image source to the provider.
129///
130/// @param id The identifier of the image source.
131///
132/// @param image_source The image source to add.
133///
135
136///
137/// Remove an image source from the provider.
138///
139/// @param id The identifier of the image source.
140///
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif // ULTRALIGHT_CAPI_IMAGESOURCE_H
Various defines and utility functions for the C API.
struct C_ImageSource * ULImageSource
Definition CAPI_Defines.h:76
struct C_String * ULString
Definition CAPI_Defines.h:65
#define ULExport
Definition CAPI_Defines.h:38
struct C_Bitmap * ULBitmap
Definition CAPI_Defines.h:64
ULExport ULImageSource ulCreateImageSourceFromTexture(unsigned int width, unsigned int height, unsigned int texture_id, ULRect texture_uv, ULBitmap bitmap)
Create an image source from a GPU texture with optional backing bitmap.
ULExport ULImageSource ulCreateImageSourceFromBitmap(ULBitmap bitmap)
Create an image source from a bitmap.
ULExport void ulDestroyImageSource(ULImageSource image_source)
Destroy an image source.
ULExport void ulImageSourceInvalidate(ULImageSource image_source)
Invalidate the image source, notifying the library that the image has changed and should be redrawn.
ULExport void ulImageSourceProviderRemoveImageSource(ULString id)
Remove an image source from the provider.
ULExport void ulImageSourceProviderAddImageSource(ULString id, ULImageSource image_source)
Add an image source to the provider.
Definition CAPI_Defines.h:250