diff --git a/android/filament-android/src/main/java/com/google/android/filament/Engine.java b/android/filament-android/src/main/java/com/google/android/filament/Engine.java index a858330eb4..aee4c2b34a 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/Engine.java +++ b/android/filament-android/src/main/java/com/google/android/filament/Engine.java @@ -654,7 +654,7 @@ public class Engine { */ @NonNull public SwapChain createSwapChain(@NonNull Object surface) { - return createSwapChain(surface, SwapChain.CONFIG_DEFAULT); + return createSwapChain(surface, SwapChainFlags.CONFIG_DEFAULT); } /** @@ -662,15 +662,15 @@ public class Engine { * * @param surface on Android, must be an instance of {@link android.view.Surface} * - * @param flags configuration flags, see {@link SwapChain} + * @param flags configuration flags, see {@link SwapChainFlags} * * @return a newly created {@link SwapChain} object * * @exception IllegalStateException can be thrown if the SwapChain couldn't be created * - * @see SwapChain#CONFIG_DEFAULT - * @see SwapChain#CONFIG_TRANSPARENT - * @see SwapChain#CONFIG_READABLE + * @see SwapChainFlags#CONFIG_DEFAULT + * @see SwapChainFlags#CONFIG_TRANSPARENT + * @see SwapChainFlags#CONFIG_READABLE * */ @NonNull @@ -688,21 +688,22 @@ public class Engine { * * @param width width of the rendering buffer * @param height height of the rendering buffer - * @param flags configuration flags, see {@link SwapChain} + * @param flags configuration flags, see {@link SwapChainFlags} * * @return a newly created {@link SwapChain} object * * @exception IllegalStateException can be thrown if the SwapChain couldn't be created * - * @see SwapChain#CONFIG_DEFAULT - * @see SwapChain#CONFIG_TRANSPARENT - * @see SwapChain#CONFIG_READABLE + * @see SwapChainFlags#CONFIG_DEFAULT + * @see SwapChainFlags#CONFIG_TRANSPARENT + * @see SwapChainFlags#CONFIG_READABLE * */ @NonNull public SwapChain createSwapChain(int width, int height, long flags) { if (width >= 0 && height >= 0) { - long nativeSwapChain = nCreateSwapChainHeadless(getNativeObject(), width, height, flags); + long nativeSwapChain = + nCreateSwapChainHeadless(getNativeObject(), width, height, flags); if (nativeSwapChain == 0) throw new IllegalStateException("Couldn't create SwapChain"); return new SwapChain(nativeSwapChain, null); } @@ -714,11 +715,12 @@ public class Engine { * * @param surface a properly initialized {@link NativeSurface} * - * @param flags configuration flags, see {@link SwapChain} + * @param flags configuration flags, see {@link SwapChainFlags} * * @return a newly created {@link SwapChain} object * - * @exception IllegalStateException can be thrown if the {@link SwapChain} couldn't be created + * @exception IllegalStateException can be thrown if the {@link SwapChainFlags} couldn't be + * created */ @NonNull public SwapChain createSwapChainFromNativeSurface(@NonNull NativeSurface surface, long flags) { diff --git a/android/filament-android/src/main/java/com/google/android/filament/SwapChain.java b/android/filament-android/src/main/java/com/google/android/filament/SwapChain.java index e3d1cf43aa..db47d21563 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/SwapChain.java +++ b/android/filament-android/src/main/java/com/google/android/filament/SwapChain.java @@ -68,72 +68,6 @@ public class SwapChain { private final Object mSurface; private long mNativeObject; - public static final long CONFIG_DEFAULT = 0x0; - - /** - * This flag indicates that the SwapChain must be allocated with an - * alpha-channel. - */ - public static final long CONFIG_TRANSPARENT = 0x1; - - /** - * This flag indicates that the SwapChain may be used as a source surface - * for reading back render results. This config must be set when creating - * any SwapChain that will be used as the source for a blit operation. - * - * @see Renderer#copyFrame - */ - public static final long CONFIG_READABLE = 0x2; - - /** - * Indicates that the native X11 window is an XCB window rather than an XLIB window. - * This is ignored on non-Linux platforms and in builds that support only one X11 API. - */ - public static final long CONFIG_ENABLE_XCB = 0x4; - - /** - * Indicates that the SwapChain must automatically perform linear to sRGB encoding. - * - * This flag is ignored if isSRGBSwapChainSupported() is false. - * - * When using this flag, post-processing should be disabled. - * - * @see SwapChain#isSRGBSwapChainSupported - * @see View#setPostProcessingEnabled - */ - public static final long CONFIG_SRGB_COLORSPACE = 0x10; - - /** - * Indicates that this SwapChain should allocate a stencil buffer in addition to a depth buffer. - * - * This flag is necessary when using View::setStencilBufferEnabled and rendering directly into - * the SwapChain (when post-processing is disabled). - * - * The specific format of the stencil buffer depends on platform support. The following pixel - * formats are tried, in order of preference: - * - * Depth only (without CONFIG_HAS_STENCIL_BUFFER): - * - DEPTH32F - * - DEPTH24 - * - * Depth + stencil (with CONFIG_HAS_STENCIL_BUFFER): - * - DEPTH32F_STENCIL8 - * - DEPTH24F_STENCIL8 - * - * Note that enabling the stencil buffer may hinder depth precision and should only be used if - * necessary. - * - * @see View#setStencilBufferEnabled - * @see View#setPostProcessingEnabled - */ - public static final long CONFIG_HAS_STENCIL_BUFFER = 0x20; - - /** - * The SwapChain contains protected content. Only supported when isProtectedContentSupported() - * is true. - */ - public static final long CONFIG_PROTECTED_CONTENT = 0x40; - SwapChain(long nativeSwapChain, Object surface) { mNativeObject = nativeSwapChain; mSurface = surface; @@ -145,17 +79,19 @@ public class SwapChain { * * @param engine A reference to the filament Engine * @return true if CONFIG_PROTECTED_CONTENT is supported, false otherwise. + * @see SwapChainFlags#CONFIG_PROTECTED_CONTENT */ public static boolean isProtectedContentSupported(@NonNull Engine engine) { return nIsProtectedContentSupported(engine.getNativeObject()); } /** - * Return whether createSwapChain supports the SWAP_CHAIN_CONFIG_SRGB_COLORSPACE flag. + * Return whether createSwapChain supports the CONFIG_SRGB_COLORSPACE flag. * The default implementation returns false. * * @param engine A reference to the filament Engine - * @return true if SWAP_CHAIN_CONFIG_SRGB_COLORSPACE is supported, false otherwise. + * @return true if CONFIG_SRGB_COLORSPACE is supported, false otherwise. + * @see SwapChainFlags#CONFIG_SRGB_COLORSPACE */ public static boolean isSRGBSwapChainSupported(@NonNull Engine engine) { return nIsSRGBSwapChainSupported(engine.getNativeObject()); diff --git a/android/filament-android/src/main/java/com/google/android/filament/SwapChainFlags.java b/android/filament-android/src/main/java/com/google/android/filament/SwapChainFlags.java new file mode 100644 index 0000000000..daef2dd15f --- /dev/null +++ b/android/filament-android/src/main/java/com/google/android/filament/SwapChainFlags.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.filament; + +// Note: SwapChainFlags is kept separate from SwapChain so that UiHelper does not need to depend +// on SwapChain. This allows clients to use UiHelper without requiring all of Filament's Java +// classes. + +/** + * Flags that a SwapChain can be created with to control behavior. + * + * @see Engine#createSwapChain + * @see Engine#createSwapChainFromNativeSurface + */ +public final class SwapChainFlags { + + public static final long CONFIG_DEFAULT = 0x0; + + /** + * This flag indicates that the SwapChain must be allocated with an + * alpha-channel. + */ + public static final long CONFIG_TRANSPARENT = 0x1; + + /** + * This flag indicates that the SwapChain may be used as a source surface + * for reading back render results. This config must be set when creating + * any SwapChain that will be used as the source for a blit operation. + * + * @see Renderer#copyFrame + */ + public static final long CONFIG_READABLE = 0x2; + + /** + * Indicates that the native X11 window is an XCB window rather than an XLIB window. + * This is ignored on non-Linux platforms and in builds that support only one X11 API. + */ + public static final long CONFIG_ENABLE_XCB = 0x4; + + /** + * Indicates that the SwapChain must automatically perform linear to sRGB encoding. + * + * This flag is ignored if isSRGBSwapChainSupported() is false. + * + * When using this flag, post-processing should be disabled. + * + * @see SwapChain#isSRGBSwapChainSupported + * @see View#setPostProcessingEnabled + */ + public static final long CONFIG_SRGB_COLORSPACE = 0x10; + + /** + * Indicates that this SwapChain should allocate a stencil buffer in addition to a depth buffer. + * + * This flag is necessary when using View::setStencilBufferEnabled and rendering directly into + * the SwapChain (when post-processing is disabled). + * + * The specific format of the stencil buffer depends on platform support. The following pixel + * formats are tried, in order of preference: + * + * Depth only (without CONFIG_HAS_STENCIL_BUFFER): + * - DEPTH32F + * - DEPTH24 + * + * Depth + stencil (with CONFIG_HAS_STENCIL_BUFFER): + * - DEPTH32F_STENCIL8 + * - DEPTH24F_STENCIL8 + * + * Note that enabling the stencil buffer may hinder depth precision and should only be used if + * necessary. + * + * @see View#setStencilBufferEnabled + * @see View#setPostProcessingEnabled + */ + public static final long CONFIG_HAS_STENCIL_BUFFER = 0x20; + + /** + * The SwapChain contains protected content. Only supported when isProtectedContentSupported() + * is true. + */ + public static final long CONFIG_PROTECTED_CONTENT = 0x40; +} + diff --git a/android/filament-android/src/main/java/com/google/android/filament/android/UiHelper.java b/android/filament-android/src/main/java/com/google/android/filament/android/UiHelper.java index 451c09a33b..4d6f3a140f 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/android/UiHelper.java +++ b/android/filament-android/src/main/java/com/google/android/filament/android/UiHelper.java @@ -27,7 +27,7 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.TextureView; -import com.google.android.filament.SwapChain; +import com.google.android.filament.SwapChainFlags; /** * UiHelper is a simple class that can manage either a SurfaceView, TextureView, or a SurfaceHolder @@ -538,7 +538,7 @@ public class UiHelper { * the options set on this UiHelper. */ public long getSwapChainFlags() { - return isOpaque() ? SwapChain.CONFIG_DEFAULT : SwapChain.CONFIG_TRANSPARENT; + return isOpaque() ? SwapChainFlags.CONFIG_DEFAULT : SwapChainFlags.CONFIG_TRANSPARENT; } /**