docs
Loading...
Searching...
No Matches
CAPI_ImageSource.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5
6///
7/// @file CAPI_ImageSource.h
8///
9/// User-defined image source to display custom images on a web-page.
10///
11/// `#include <Ultralight/CAPI/CAPI_ImageSource.h>`
12///
13/// This API allows you to composite your own images into a web-page. This is useful for displaying
14/// in-game textures, external image assets, or other custom content.
15///
16/// ## ImageSource File Format
17///
18/// To use an ImageSource, you must first create an `.imgsrc` file containing a string identifying
19/// the image source. This string will be used to lookup the ImageSource from ImageSourceProvider
20/// when it is loaded on a web-page.
21///
22/// The file format is as follows:
23///
24/// ```
25/// IMGSRC-V1
26/// <identifier>
27/// ```
28///
29/// You can use the `.imgsrc` file anywhere in your web-page that typically accepts an image URL.
30/// For example:
31///
32/// ```html
33/// <img src="my_custom_image.imgsrc" />
34/// ```
35///
36/// ## Creating from a GPU Texture
37///
38/// To composite your own GPU texture on a web-page, you should first reserve a texture ID from
39/// ULGPUDriver::next_texture_id and then create an ImageSource from that texture ID. Next, you
40/// should register the ImageSource with ImageSourceProvider using the identifier from the `.imgsrc`
41/// file.
42///
43/// When the image element is drawn on the web-page, the library will draw geometry using the
44/// specified texture ID and UV coordinates. You should bind your own texture when the specified
45/// texture ID is used.
46///
47/// If the GPU renderer is not enabled for the View or pixel data is needed for other purposes, the
48/// library will sample the backing bitmap instead.
49///
50/// ## Creating from a Bitmap
51///
52/// To composite your own bitmap on a web-page, you should create an ImageSource from a Bitmap.
53/// Next, you should register the ImageSource with ImageSourceProvider using the identifier from
54/// the `.imgsrc` file.
55///
56/// When the image element is drawn on the web-page, the library will sample this bitmap directly.
57///
58/// ## Invalidating Images
59///
60/// If you modify the texture or bitmap after creating the ImageSource, you should call
61/// ulImageSourceInvalidate() to notify the library that the image should be redrawn.
62///
63#ifndef ULTRALIGHT_CAPI_IMAGESOURCE_H
64#define ULTRALIGHT_CAPI_IMAGESOURCE_H
65
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72/******************************************************************************
73 * ImageSource
74 *****************************************************************************/
75
76///
77/// Create an image source from a GPU texture with optional backing bitmap.
78///
79/// @param width The width of the image in pixels (used for layout).
80///
81/// @param height The height of the image in pixels (used for layout).
82///
83/// @param texture_id The GPU texture identifier to bind when drawing the quad for this image.
84/// This should be non-zero and obtained from ULGPUDriver::next_texture_id.
85///
86/// @param texture_uv The UV coordinates of the texture.
87///
88/// @param bitmap Optional backing bitmap for this image source. This is used when drawing
89/// the image using the CPU renderer or when pixel data is needed for other
90/// purposes. You should update this bitmap when the texture changes.
91///
92/// @return A new image source instance. You must call ulDestroyImageSource() when finished.
93///
94ULExport ULImageSource ulCreateImageSourceFromTexture(unsigned int width, unsigned int height,
95 unsigned int texture_id, ULRect texture_uv,
96 ULBitmap bitmap);
97
98///
99/// Create an image source from a bitmap.
100///
101/// @param bitmap The backing bitmap for this image source.
102///
103/// @return A new image source instance. You must call ulDestroyImageSource() when finished.
104///
106
107///
108/// Destroy an image source previously created with ulCreateImageSourceFromTexture() or
109/// ulCreateImageSourceFromBitmap().
110///
111/// @param image_source The image source to destroy.
112///
114
115///
116/// Invalidate the image source, notifying the library that the image has changed
117/// and should be redrawn.
118///
120
121///
122/// Get the width of the image source in pixels.
123///
125
126///
127/// Get the height of the image source in pixels.
128///
130
131///
132/// Get the GPU texture identifier for this image source.
133///
134/// @return The texture ID, or 0 if the image source was created from a bitmap.
135///
137
138///
139/// Get the UV coordinates of the texture for this image source.
140///
142
143///
144/// Get the backing bitmap for this image source.
145///
146/// @return The bitmap, or NULL if no bitmap was provided. Do not destroy the returned bitmap.
147/// It stays valid until the next call to ulImageSourceGetBitmap() on the same thread
148/// (for any image source), even if the image source is destroyed first.
149///
151
152/******************************************************************************
153 * ImageSourceProvider
154 *****************************************************************************/
155
156///
157/// Add an image source to the provider.
158///
159/// @param id The identifier of the image source.
160///
161/// @param image_source The image source to add.
162///
164
165///
166/// Remove an image source from the provider.
167///
168/// @param id The identifier of the image source.
169///
171
172///
173/// Get an image source from the provider by its identifier.
174///
175/// @param id The identifier of the image source.
176///
177/// @return The image source, or NULL if not found. Do not destroy the returned image source.
178/// It stays valid until the next call to ulImageSourceProviderGetImageSource() on the
179/// same thread, even if the image source is removed from the provider first.
180///
182
183#ifdef __cplusplus
184}
185#endif
186
187#endif // ULTRALIGHT_CAPI_IMAGESOURCE_H
unsigned int ulImageSourceGetWidth(ULImageSource image_source)
Get the width of the image source in pixels.
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.
void ulImageSourceInvalidate(ULImageSource image_source)
Invalidate the image source, notifying the library that the image has changed and should be redrawn.
void ulImageSourceProviderAddImageSource(ULString id, ULImageSource image_source)
Add an image source to the provider.
ULBitmap ulImageSourceGetBitmap(ULImageSource image_source)
Get the backing bitmap for this image source.
ULImageSource ulCreateImageSourceFromBitmap(ULBitmap bitmap)
Create an image source from a bitmap.
void ulDestroyImageSource(ULImageSource image_source)
Destroy an image source previously created with ulCreateImageSourceFromTexture() or ulCreateImageSour...
unsigned int ulImageSourceGetHeight(ULImageSource image_source)
Get the height of the image source in pixels.
ULRect ulImageSourceGetTextureUV(ULImageSource image_source)
Get the UV coordinates of the texture for this image source.
unsigned int ulImageSourceGetTextureId(ULImageSource image_source)
Get the GPU texture identifier for this image source.
ULImageSource ulImageSourceProviderGetImageSource(ULString id)
Get an image source from the provider by its identifier.
void ulImageSourceProviderRemoveImageSource(ULString id)
Remove an image source from the provider.
Various defines and utility functions for the C API.
struct C_ImageSource * ULImageSource
Opaque handle to an ImageSource object.
Definition CAPI_Defines.h:131
struct C_String * ULString
Opaque handle to a String object.
Definition CAPI_Defines.h:96
#define ULExport
Definition CAPI_Defines.h:42
struct C_Bitmap * ULBitmap
Opaque handle to a Bitmap object.
Definition CAPI_Defines.h:93
Float rectangle defined by left, top, right, and bottom coordinates.
Definition CAPI_Defines.h:538