Class DmabufTextureBuilder
- All Implemented Interfaces:
Proxy
Texture objects from DMA buffers.
DMA buffers are commonly called **_dma-bufs_**.
DMA buffers are a feature of the Linux kernel to enable efficient buffer and memory sharing between hardware such as codecs, GPUs, displays, cameras and the kernel drivers controlling them. For example, a decoder may want its output to be directly shared with the display server for rendering without a copy.
Any device driver which participates in DMA buffer sharing, can do so as either the exporter or importer of buffers (or both).
The memory that is shared via DMA buffers is usually stored in non-system memory (maybe in device's local memory or something else not directly accessible by the CPU), and accessing this memory from the CPU may have higher-than-usual overhead.
In particular for graphics data, it is not uncommon that data consists of multiple separate blocks of memory, for example one block for each of the red, green and blue channels. These blocks are called **_planes_**. DMA buffers can have up to four planes. Even if the memory is a single block, the data can be organized in multiple planes, by specifying offsets from the beginning of the data.
DMA buffers are exposed to user-space as file descriptors allowing to pass them between processes. If a DMA buffer has multiple planes, there is one file descriptor per plane.
The format of the data (for graphics data, essentially its colorspace) is described
by a 32-bit integer. These format identifiers are defined in the header file drm_fourcc.h
and commonly referred to as _fourcc_ values, since they are identified by 4 ASCII
characters. Additionally, each DMA buffer has a **_modifier_**, which is a 64-bit integer
that describes driver-specific details of the memory layout, such as tiling or compression.
For historical reasons, some producers of dma-bufs don't provide an explicit modifier, but
instead return DMA_FORMAT_MOD_INVALID to indicate that their modifier is **_implicit_**.
GTK tries to accommodate this situation by accepting DMA_FORMAT_MOD_INVALID as modifier.
The operation of GdkDmabufTextureBuilder is quite simple: Create a texture builder,
set all the necessary properties, and then call build(java.lang.foreign.MemorySegment)
to create the new texture.
The required properties for a dma-buf texture are
- The width and height in pixels
- The
fourcccode andmodifierwhich identify the format and memory layout of the dma-buf
- The file descriptor, offset and stride for each of the planes
GdkDmabufTextureBuilder can be used for quick one-shot construction of
textures as well as kept around and reused to construct multiple textures.
For further information, see
- The Linux kernel documentation
- The header file drm_fourcc.h
- Since:
- 4.14
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DmabufTextureBuilder.DmabufTextureBuilder(MemorySegment address) Create a DmabufTextureBuilder proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected DmabufTextureBuilderasParent()Returns this instance as if it were its parent type.@Nullable Texturebuild(@Nullable MemorySegment data) Builds a newGdkTexturewith the values set up in the builder.static DmabufTextureBuilder.Builder<? extends DmabufTextureBuilder.Builder> builder()ADmabufTextureBuilder.Builderobject constructs aDmabufTextureBuilderwith the specified properties.@Nullable ColorStateGets the color state previously set via gdk_dmabuf_texture_builder_set_color_state().Returns the display that this texture builder is associated with.intgetFd(int plane) Gets the file descriptor for a plane.intGets the format previously set via gdk_dmabuf_texture_builder_set_fourcc() or 0 if the format wasn't set.intGets the height previously set via gdk_dmabuf_texture_builder_set_height() or 0 if the height wasn't set.longGets the modifier value.intGets the number of planes.intgetOffset(int plane) Gets the offset value for a plane.booleanWhether the data is premultiplied.intgetStride(int plane) Gets the stride value for a plane.static @Nullable TypegetType()Get the GType of the DmabufTextureBuilder class@Nullable org.freedesktop.cairo.RegionGets the region previously set via gdk_dmabuf_texture_builder_set_update_region() ornullif none was set.@Nullable TextureGets the texture previously set via gdk_dmabuf_texture_builder_set_update_texture() ornullif none was set.intgetWidth()Gets the width previously set via gdk_dmabuf_texture_builder_set_width() or 0 if the width wasn't set.voidsetColorState(@Nullable ColorState colorState) Sets the color state for the texture.voidsetDisplay(Display display) Sets the display that this texture builder is associated with.voidsetFd(int plane, int fd) Sets the file descriptor for a plane.voidsetFourcc(int fourcc) Sets the format of the texture.voidsetHeight(int height) Sets the height of the texture.voidsetModifier(long modifier) Sets the modifier.voidsetNPlanes(int nPlanes) Sets the number of planes of the texture.voidsetOffset(int plane, int offset) Sets the offset for a plane.voidsetPremultiplied(boolean premultiplied) Sets whether the data is premultiplied.voidsetStride(int plane, int stride) Sets the stride for a plane.voidsetUpdateRegion(@Nullable org.freedesktop.cairo.Region region) Sets the region to be updated by this texture.voidsetUpdateTexture(@Nullable Texture texture) Sets the texture to be updated by this texture.voidsetWidth(int width) Sets the width of the texture.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
DmabufTextureBuilder
Create a DmabufTextureBuilder proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
DmabufTextureBuilder
public DmabufTextureBuilder()Creates a new DmabufTextureBuilder.
-
-
Method Details
-
getType
Get the GType of the DmabufTextureBuilder class- Returns:
- the GType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
build
Builds a newGdkTexturewith the values set up in the builder.It is a programming error to call this function if any mandatory property has not been set.
Not all formats defined in the
drm_fourcc.hheader are supported. You can useDisplay.getDmabufFormats()to get a list of supported formats. If the format is not supported by GTK,nullwill be returned anderrorwill be set.The
destroyfunction gets called when the returned texture gets released.It is the responsibility of the caller to keep the file descriptors for the planes open until the created texture is no longer used, and close them afterwards (possibly using the
destroynotify).It is possible to call this function multiple times to create multiple textures, possibly with changing properties in between.
- Parameters:
data- user data to pass to the destroy function- Returns:
- a newly built
GdkTextureorNULLif the format is not supported - Throws:
GErrorException- seeGError- Since:
- 4.14
-
getColorState
Gets the color state previously set via gdk_dmabuf_texture_builder_set_color_state().- Returns:
- the color state
- Since:
- 4.16
-
getDisplay
Returns the display that this texture builder is associated with.- Returns:
- the display
- Since:
- 4.14
-
getFd
public int getFd(int plane) Gets the file descriptor for a plane.- Parameters:
plane- the plane to get the fd for- Returns:
- the file descriptor
- Since:
- 4.14
-
getFourcc
public int getFourcc()Gets the format previously set via gdk_dmabuf_texture_builder_set_fourcc() or 0 if the format wasn't set.The format is specified as a fourcc code.
- Returns:
- The format
- Since:
- 4.14
-
getHeight
public int getHeight()Gets the height previously set via gdk_dmabuf_texture_builder_set_height() or 0 if the height wasn't set.- Returns:
- The height
- Since:
- 4.14
-
getModifier
public long getModifier()Gets the modifier value.- Returns:
- the modifier
- Since:
- 4.14
-
getNPlanes
public int getNPlanes()Gets the number of planes.- Returns:
- The number of planes
- Since:
- 4.14
-
getOffset
public int getOffset(int plane) Gets the offset value for a plane.- Parameters:
plane- the plane to get the offset for- Returns:
- the offset
- Since:
- 4.14
-
getPremultiplied
public boolean getPremultiplied()Whether the data is premultiplied.- Returns:
- whether the data is premultiplied
- Since:
- 4.14
-
getStride
public int getStride(int plane) Gets the stride value for a plane.- Parameters:
plane- the plane to get the stride for- Returns:
- the stride
- Since:
- 4.14
-
getUpdateRegion
public @Nullable org.freedesktop.cairo.Region getUpdateRegion()Gets the region previously set via gdk_dmabuf_texture_builder_set_update_region() ornullif none was set.- Returns:
- The region
- Since:
- 4.14
-
getUpdateTexture
Gets the texture previously set via gdk_dmabuf_texture_builder_set_update_texture() ornullif none was set.- Returns:
- The texture
- Since:
- 4.14
-
getWidth
public int getWidth()Gets the width previously set via gdk_dmabuf_texture_builder_set_width() or 0 if the width wasn't set.- Returns:
- The width
- Since:
- 4.14
-
setColorState
Sets the color state for the texture.By default, the colorstate is
NULL. In that case, GTK will choose the correct colorstate based on the format. If you don't know what colorstates are, this is probably the right thing.- Parameters:
colorState- aGdkColorStateorNULLto unset the colorstate.- Since:
- 4.16
-
setDisplay
Sets the display that this texture builder is associated with.The display is used to determine the supported dma-buf formats.
- Parameters:
display- the display- Since:
- 4.14
-
setFd
public void setFd(int plane, int fd) Sets the file descriptor for a plane.- Parameters:
plane- the plane to set the fd forfd- the file descriptor- Since:
- 4.14
-
setFourcc
public void setFourcc(int fourcc) Sets the format of the texture.The format is specified as a fourcc code.
The format must be set before calling
build(java.lang.foreign.MemorySegment).- Parameters:
fourcc- the texture's format or 0 to unset- Since:
- 4.14
-
setHeight
public void setHeight(int height) Sets the height of the texture.The height must be set before calling
build(java.lang.foreign.MemorySegment).- Parameters:
height- the texture's height or 0 to unset- Since:
- 4.14
-
setModifier
public void setModifier(long modifier) Sets the modifier.- Parameters:
modifier- the modifier value- Since:
- 4.14
-
setNPlanes
public void setNPlanes(int nPlanes) Sets the number of planes of the texture.- Parameters:
nPlanes- the number of planes- Since:
- 4.14
-
setOffset
public void setOffset(int plane, int offset) Sets the offset for a plane.- Parameters:
plane- the plane to set the offset foroffset- the offset value- Since:
- 4.14
-
setPremultiplied
public void setPremultiplied(boolean premultiplied) Sets whether the data is premultiplied.Unless otherwise specified, all formats including alpha channels are assumed to be premultiplied.
- Parameters:
premultiplied- whether the data is premultiplied- Since:
- 4.14
-
setStride
public void setStride(int plane, int stride) Sets the stride for a plane.The stride must be set for all planes before calling
build(java.lang.foreign.MemorySegment).- Parameters:
plane- the plane to set the stride forstride- the stride value- Since:
- 4.14
-
setUpdateRegion
public void setUpdateRegion(@Nullable org.freedesktop.cairo.Region region) Sets the region to be updated by this texture. Together withGdk.DmabufTextureBuilder:update-texturethis describes an update of a previous texture.When rendering animations of large textures, it is possible that consecutive textures are only updating contents in parts of the texture. It is then possible to describe this update via these two properties, so that GTK can avoid rerendering parts that did not change.
An example would be a screen recording where only the mouse pointer moves.
- Parameters:
region- the region to update- Since:
- 4.14
-
setUpdateTexture
Sets the texture to be updated by this texture. SeesetUpdateRegion(org.freedesktop.cairo.Region)for an explanation.- Parameters:
texture- the texture to update- Since:
- 4.14
-
setWidth
public void setWidth(int width) Sets the width of the texture.The width must be set before calling
build(java.lang.foreign.MemorySegment).- Parameters:
width- The texture's width or 0 to unset- Since:
- 4.14
-
builder
ADmabufTextureBuilder.Builderobject constructs aDmabufTextureBuilderwith the specified properties. Use the variousset...()methods to set properties, and finish construction withDmabufTextureBuilder.Builder.build().- Returns:
- the builder object
-