You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 76aeb9e
Browse filesBrowse the repository at this point in the historyBrowse files
[android] Release fences and OpenGL ES intake for pushHardwareBuffer
Builds on "[android] F16/EDR compositing + direct-AHardwareBuffer
producer path", which added ImageTextureEntry.pushHardwareBuffer. It
also adds a surface dynamic range API. This commit is four independent
changes that upstream as separate pull requests; the split is described
at the end.
1. fml: copying a null JNI reference no longer needs a JVM
---------------------------------------------------------
SetNewLocalRef / SetNewGlobalRef return early when both the new and the
old object are null, instead of attaching the thread to the JVM first.
Besides avoiding a pointless attach, this lets native unit tests (which
have no JVM) construct objects that hold an empty Java reference.
2. Impeller: color transform for external (OES) textures
--------------------------------------------------------
tiled_texture_fill_external.frag gains the gamut matrix and sRGB encode
that texture_fill.frag already applies, so an F16 linear Display P3
external texture (an AHardwareBuffer bound through OpenGL ES) is
converted to the sRGB target instead of drawing too dark. The transform
is factored into a public GetTextureColorTransform(ColorSpace) shared by
TextureContents and TiledTextureContents (whose external path previously
used an identity).
3. Android: OpenGL ES intake and release fences for pushHardwareBuffer
-----------------------------------------------------------------------
Flutter renders with OpenGL ES in the emulator and on devices Impeller's
Vulkan backend rejects. ImageExternalTextureGL only read the Image slot,
which pushHardwareBuffer leaves empty, so such producers drew nothing.
It now takes pushed buffers like the Vulkan texture: the buffer's size,
F16 format and color space describe the texture, and the producer's
acquire fence is waited on by the GPU (EGL_ANDROID_native_fence_sync +
eglWaitSyncKHR), not the CPU.
The eventfd "release-ack" is replaced by release fences:
- ImageTextureEntry.setOnHardwareBufferReleasedListener /
OnHardwareBufferReleasedListener.onHardwareBufferReleased(ahbPtr,
fenceFd) report every push exactly once. A push that was never drawn
is released at once, on the superseding thread, with fence -1. A drawn
buffer is released when a later frame replaces it, after that frame
has been submitted (a task posted to the raster task runner), behind a
sync fence covering every draw of it, including more than one paint in
a frame.
- OpenGL ES: an EGL native fence; Vulkan: an exportable SYNC_FD
semaphore signalled by a submission on the graphics queue, which also
hands the image back to VK_QUEUE_FAMILY_FOREIGN_EXT (intake now
acquires it from there). When a device can't export a fence, the
release waits without blocking: the raster thread polls an EGL fence /
VkFence and releases with -1.
- No fences or callbacks for buffers pushed while no listener is set.
- Vulkan release objects are tracked by the texture's fence maker and
waited for at teardown (they no longer go through FenceWaiterVK, whose
AddFence destroys a pending fence once the waiter is terminating).
- The releaseAckFd overloads are removed; pushHardwareBuffer(long, int,
int) now takes a @ColorSpace. Listener exceptions are caught; the
finalizer never calls the listener.
4. Android: surface dynamic range API
-------------------------------------
FlutterRenderer.isSurfaceExtendedRange() and
add/removeSurfaceDynamicRangeListener(FlutterSurfaceDynamicRangeListener)
report whether the onscreen surface stores extended-range (F16) color:
true for an F16 Vulkan swapchain, false for OpenGL ES, the RGBA8 Vulkan
fallback, and no surface. Apps use it to stop requesting HDR headroom an
SDR surface would clip. PlatformViewAndroid reports it after the surface
is created or changed (AndroidSurface::IsExtendedRange) and reports
false when destroyed.
Tests
-----
- FlutterRendererTest / FlutterJNITest: release listener contract
(superseded, released, after-release pushes, color space,
wantsRelease, throwing listener) and dynamic-range state and
listeners.
- image_external_texture_unittests.cc: release bookkeeping on a raster
thread with a fake fence maker (after-frame release, several buffers
in one frame, re-pushed buffer, no listener, unexportable fence,
lifecycles).
- image_external_texture_gpu_unittests.cc (device): the OpenGL ES fence
maker against a real EGL context, and a Vulkan texture painted with
two real AHardwareBuffers releasing the first behind a fence that
signals.
- texture_contents_unittests.cc: GetTextureColorTransform for each color
space.
Splitting for upstream
----------------------
1. fml/platform/android/scoped_java_ref.cc
2. impeller/entity/** (texture_contents.{h,cc},
texture_contents_unittests.cc, tiled_texture_contents.cc,
shaders/tiled_texture_fill_external.frag, BUILD.gn)
3. shell/platform/android/image_external_texture*.{h,cc} (incl. both
new unittest files), io/flutter/view/TextureRegistry.java, the
ImageTextureRegistryEntry part of FlutterRenderer.java, the
releaseHardwareBuffer part of FlutterJNI.java,
FlutterRendererTest.java (release-listener tests)
4. android_surface*.{h,cc}, surface/android_surface.{h,cc},
platform_view_android.{h,cc},
FlutterSurfaceDynamicRangeListener.java, the dynamic-range parts of
FlutterRenderer.java, FlutterJNI.java and their tests
Shared by 3 and 4, split by hunk: jni/platform_view_android_jni.h,
platform_view_android_jni_impl.{h,cc}, jni/jni_mock.h,
android_shell_holder_unittests.cc, shell/platform/android/BUILD.gn.
Parts 3 and 4 depend on 1 only through the native unit tests; 3
depends on 2 for correct color on OpenGL ES. The formatting-only hunks
in code from the base commit (TextureRegistry/FlutterJNI Javadoc,
platform_view_android_jni_impl.cc, texture_contents.cc) belong with
that commit.
0 commit comments