Skip to content

Commit

Permalink
Duplicate the changes from the build folder that came through github …
Browse files Browse the repository at this point in the history
…so that it works on internal builds

Reviewed By: corporateshark

Differential Revision: D66310710

fbshipit-source-id: 39285a33d6a2ddff4ef9acbe70523856bee644e8
  • Loading branch information
francoiscoulombe authored and facebook-github-bot committed Nov 21, 2024
1 parent b36a432 commit 2385b6b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shell/android/java/com/facebook/igl/sample/SampleLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public static native void init(

public static native void setClearColorValue(float r, float g, float b, float a);

public static native boolean isSRGBTextureFormat(int textureFormat);

public static native void surfaceDestroyed(Surface surface);

public static class RenderSessionConfig {
Expand Down
33 changes: 33 additions & 0 deletions shell/android/java/com/facebook/igl/sample/SampleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import javax.microedition.khronos.opengles.GL10;

/// Simple view that sets up a GLES 2.0 rendering context
Expand All @@ -39,6 +40,9 @@ public SampleView(
// Set the view to be transluscent since we provide an alpha channel below.
this.getHolder().setFormat(PixelFormat.TRANSLUCENT);

setEGLWindowSurfaceFactory(
new SurfaceFactory(SampleLib.isSRGBTextureFormat(swapchainColorTextureFormat)));

setEGLConfigChooser(new ConfigChooser(backendVersion));

setRenderer(new Renderer(context, backendVersion, swapchainColorTextureFormat));
Expand Down Expand Up @@ -112,6 +116,35 @@ private static void checkEglError(String prompt, EGL10 egl) {
}
}

private static class SurfaceFactory implements GLSurfaceView.EGLWindowSurfaceFactory {
final int EGL_GL_COLORSPACE_KHR = 0x309D;
final int EGL_GL_COLORSPACE_SRGB_KHR = 0x3089;
final int EGL_GL_COLORSPACE_LINEAR_KHR = 0x308A;

private boolean mIsSRGBColorSpace;

SurfaceFactory(boolean isSRGB) {
mIsSRGBColorSpace = isSRGB;
}

@Override
public EGLSurface createWindowSurface(
EGL10 egl10, EGLDisplay eglDisplay, EGLConfig eglConfig, Object nativeWindow) {
int[] configAttribs = {
EGL_GL_COLORSPACE_KHR,
(mIsSRGBColorSpace ? EGL_GL_COLORSPACE_SRGB_KHR : EGL_GL_COLORSPACE_LINEAR_KHR),
EGL10.EGL_NONE
};

return egl10.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, configAttribs);
}

@Override
public void destroySurface(EGL10 egl10, EGLDisplay eglDisplay, EGLSurface eglSurface) {
egl10.eglDestroySurface(eglDisplay, eglSurface);
}
}

/// Config chooser: handles specifying the requirements for the EGL config and choosing the
// correct one.
private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser {
Expand Down

0 comments on commit 2385b6b

Please sign in to comment.