Skip to content

add BackendTexture and Image.adoptTextureFrom#1030

Merged
igordmn merged 10 commits intoJetBrains:masterfrom
MaapuH:master
Jul 2, 2025
Merged

add BackendTexture and Image.adoptTextureFrom#1030
igordmn merged 10 commits intoJetBrains:masterfrom
MaapuH:master

Conversation

@MaapuH
Copy link
Copy Markdown
Contributor

@MaapuH MaapuH commented Mar 1, 2025

New:

(related #1019)

  1. Adds bindings to GrBackendTextures::MakeGL
  2. Adds bindings to SkImages::AdoptTextureFrom
  3. Adds bindings to GrBackendTextures::GLTextureParametersModdified

Changes in build scripts:

(related #742)

  1. Add file paths treating if building on Windows machine
  2. Use "emcc.bat" instead of "emcc" if building on Windows machine, as described on Emscripten website

Use-case:

Allows skia to draw images, rendered externally on gpu.
Compose would benefit greatly, allowing to embed VideoPlayer or Browser without any friction or need to use Swing.

@MatkovIvan MatkovIvan requested a review from igordmn March 7, 2025 09:10
@MaapuH
Copy link
Copy Markdown
Contributor Author

MaapuH commented Mar 7, 2025

Besides already implemented above, at the moment I am working on these new bindings:
DirectContext.createBackendTexture() // this is common for all backends
DirectContext.deleteBackendTexture() // this is common for all backends

BackendTexture.backend // allows to check which backend is texture created on
BackendTexture.getGLInfo // allows to get id of the texture if the backend is GL, this we can use for external rendering

We can also getDirect3DInfo for DirectX backend, getMetalInfo for Metal, etc
These I'll be doing when I'm done with GL bindings

I will submit another PR when all the upcoming bindigs are implemented

@StageGuard
Copy link
Copy Markdown

Hi, Is any progress on it ?

Copy link
Copy Markdown
Collaborator

@igordmn igordmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for a long review.

It needs small corrections, and it is good to merge.

MaapuH added 3 commits June 21, 2025 13:22
- also changed native impl parameters for nativeJS BackendTexture.cc
- also changed native impl parameters for jvm BackendTexture.cc
2. fix little slip up from previous commit in gradle properties
@MaapuH
Copy link
Copy Markdown
Contributor Author

MaapuH commented Jun 21, 2025

Corrections applied!

@MaapuH MaapuH requested a review from igordmn June 21, 2025 11:54
SKIKO_EXPORT KNativePointer org_jetbrains_skia_BackendTexture__1nMakeGL
(KInt width, KInt height, KBoolean isMipmapped, KInt textureId, KInt target, KInt format) {
GrGLTextureInfo textureInfo;
textureInfo.fID = static_cast<GrGLuint>(textureId);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK WebGL textures have no ids, so emscripten provides the mapping for skia. This means that without registering a texture in the emscripten internal map it is not possible to adopt textures created outside skia (e.g. using js interop). Should we include a workaround for this to allow registering external webgl textures?
It probably should be done as a separate PR, just bringing this up as it would be useful for my use case (adopting textures created using js interop).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workaround looks like a code that should be called outside of Skia, not in Skia itself. Skia only provides an API which can be used, including requiring an id that can be obtained by the API you provided.

@igordmn igordmn merged commit ff5a113 into JetBrains:master Jul 2, 2025
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants