Skip to content

Commit

Permalink
Revert "[Impeller] A toolkit for managed handles to Android NDK vende…
Browse files Browse the repository at this point in the history
…d objects. (#51334)"

This reverts commit f086ec4.
  • Loading branch information
auto-submit[bot] committed Mar 15, 2024
1 parent f086ec4 commit 3464f71
Show file tree
Hide file tree
Showing 37 changed files with 577 additions and 1,381 deletions.
6 changes: 2 additions & 4 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,8 @@ group("unittests") {

public_deps = []
if (is_android) {
public_deps += [
"//flutter/impeller/toolkit/android:unittests",
"//flutter/shell/platform/android:flutter_shell_native_unittests",
]
public_deps +=
[ "//flutter/shell/platform/android:flutter_shell_native_unittests" ]
}

if (is_ios) {
Expand Down
2 changes: 0 additions & 2 deletions ci/builders/linux_android_emulator.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"ninja": {
"config": "android_emulator_debug_x64",
"targets": [
"flutter/impeller/toolkit/android:unittests",
"flutter/shell/platform/android:flutter_shell_native_unittests",
"flutter/testing/scenario_app"
]
Expand Down Expand Up @@ -121,7 +120,6 @@
"ninja": {
"config": "android_emulator_debug_x86",
"targets": [
"flutter/impeller/toolkit/android:unittests",
"flutter/shell/platform/android:flutter_shell_native_unittests",
"flutter/testing/scenario_app"
]
Expand Down
1 change: 0 additions & 1 deletion ci/builders/linux_android_emulator_api_33.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"ninja": {
"config": "android_debug_api33_x64",
"targets": [
"flutter/impeller/toolkit/android:unittests",
"flutter/shell/platform/android:flutter_shell_native_unittests",
"flutter/testing/scenario_app"
]
Expand Down
1 change: 0 additions & 1 deletion ci/builders/linux_android_emulator_skia.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"ninja": {
"config": "android_emulator_skia_debug_x64",
"targets": [
"flutter/impeller/toolkit/android:unittests",
"flutter/shell/platform/android:flutter_shell_native_unittests",
"flutter/testing/scenario_app"
]
Expand Down
3 changes: 1 addition & 2 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
../../../flutter/fml/message_loop_task_queues_unittests.cc
../../../flutter/fml/message_loop_unittests.cc
../../../flutter/fml/paths_unittests.cc
../../../flutter/fml/platform/android/ndk_helpers_unittests.cc
../../../flutter/fml/platform/darwin/cf_utils_unittests.mm
../../../flutter/fml/platform/darwin/scoped_nsobject_arc_unittests.mm
../../../flutter/fml/platform/darwin/scoped_nsobject_unittests.mm
Expand Down Expand Up @@ -199,8 +200,6 @@
../../../flutter/impeller/tessellator/dart/pubspec.lock
../../../flutter/impeller/tessellator/dart/pubspec.yaml
../../../flutter/impeller/tessellator/tessellator_unittests.cc
../../../flutter/impeller/toolkit/android/README.md
../../../flutter/impeller/toolkit/android/toolkit_android_unittests.cc
../../../flutter/impeller/tools/build_metal_library.py
../../../flutter/impeller/tools/check_licenses.py
../../../flutter/impeller/tools/malioc_cores.py
Expand Down
29 changes: 4 additions & 25 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -39364,6 +39364,8 @@ ORIGIN: ../../../flutter/fml/platform/android/jni_weak_ref.cc + ../../../flutter
ORIGIN: ../../../flutter/fml/platform/android/jni_weak_ref.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/android/message_loop_android.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/android/message_loop_android.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/android/ndk_helpers.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/android/ndk_helpers.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/android/paths_android.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/android/paths_android.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/android/scoped_java_ref.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -40149,18 +40151,6 @@ ORIGIN: ../../../flutter/impeller/tessellator/c/tessellator.h + ../../../flutter
ORIGIN: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/tessellator/tessellator.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/tessellator/tessellator.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/choreographer.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/choreographer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/hardware_buffer.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/hardware_buffer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/native_window.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/native_window.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/proc_table.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/proc_table.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/surface_control.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/surface_control.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/surface_transaction.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/android/surface_transaction.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/egl/config.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/egl/config.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/toolkit/egl/context.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -40884,7 +40874,6 @@ ORIGIN: ../../../flutter/shell/platform/android/flutter_main.h + ../../../flutte
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/image_lru.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/image_lru.h + ../../../flutter/LICENSE
Expand Down Expand Up @@ -42231,6 +42220,8 @@ FILE: ../../../flutter/fml/platform/android/jni_weak_ref.cc
FILE: ../../../flutter/fml/platform/android/jni_weak_ref.h
FILE: ../../../flutter/fml/platform/android/message_loop_android.cc
FILE: ../../../flutter/fml/platform/android/message_loop_android.h
FILE: ../../../flutter/fml/platform/android/ndk_helpers.cc
FILE: ../../../flutter/fml/platform/android/ndk_helpers.h
FILE: ../../../flutter/fml/platform/android/paths_android.cc
FILE: ../../../flutter/fml/platform/android/paths_android.h
FILE: ../../../flutter/fml/platform/android/scoped_java_ref.cc
Expand Down Expand Up @@ -43017,18 +43008,6 @@ FILE: ../../../flutter/impeller/tessellator/c/tessellator.h
FILE: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart
FILE: ../../../flutter/impeller/tessellator/tessellator.cc
FILE: ../../../flutter/impeller/tessellator/tessellator.h
FILE: ../../../flutter/impeller/toolkit/android/choreographer.cc
FILE: ../../../flutter/impeller/toolkit/android/choreographer.h
FILE: ../../../flutter/impeller/toolkit/android/hardware_buffer.cc
FILE: ../../../flutter/impeller/toolkit/android/hardware_buffer.h
FILE: ../../../flutter/impeller/toolkit/android/native_window.cc
FILE: ../../../flutter/impeller/toolkit/android/native_window.h
FILE: ../../../flutter/impeller/toolkit/android/proc_table.cc
FILE: ../../../flutter/impeller/toolkit/android/proc_table.h
FILE: ../../../flutter/impeller/toolkit/android/surface_control.cc
FILE: ../../../flutter/impeller/toolkit/android/surface_control.h
FILE: ../../../flutter/impeller/toolkit/android/surface_transaction.cc
FILE: ../../../flutter/impeller/toolkit/android/surface_transaction.h
FILE: ../../../flutter/impeller/toolkit/egl/config.cc
FILE: ../../../flutter/impeller/toolkit/egl/config.h
FILE: ../../../flutter/impeller/toolkit/egl/context.cc
Expand Down
2 changes: 2 additions & 0 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ source_set("fml") {
"platform/android/jni_weak_ref.h",
"platform/android/message_loop_android.cc",
"platform/android/message_loop_android.h",
"platform/android/ndk_helpers.cc",
"platform/android/ndk_helpers.h",
"platform/android/paths_android.cc",
"platform/android/paths_android.h",
"platform/android/scoped_java_ref.cc",
Expand Down
264 changes: 264 additions & 0 deletions fml/platform/android/ndk_helpers.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "fml/platform/android/ndk_helpers.h"

#include "fml/logging.h"
#include "fml/native_library.h"

#include <android/hardware_buffer.h>
#include <dlfcn.h>

namespace flutter {

namespace {

#define DECLARE_TYPES(ret, name, args) \
typedef ret(*fp_##name) args; \
ret(*_##name) args = nullptr

DECLARE_TYPES(int,
AHardwareBuffer_allocate,
(const AHardwareBuffer_Desc* desc, AHardwareBuffer** outBuffer));
DECLARE_TYPES(int,
AHardwareBuffer_isSupported,
(const AHardwareBuffer_Desc* desc));
DECLARE_TYPES(AHardwareBuffer*,
AHardwareBuffer_fromHardwareBuffer,
(JNIEnv * env, jobject hardwareBufferObj));
DECLARE_TYPES(void, AHardwareBuffer_release, (AHardwareBuffer * buffer));
DECLARE_TYPES(void,
AHardwareBuffer_describe,
(AHardwareBuffer * buffer, AHardwareBuffer_Desc* desc));
DECLARE_TYPES(int,
AHardwareBuffer_getId,
(AHardwareBuffer * buffer, uint64_t* outId));

DECLARE_TYPES(bool, ATrace_isEnabled, (void));

DECLARE_TYPES(ASurfaceControl*,
ASurfaceControl_createFromWindow,
(ANativeWindow * parent, const char* debug_name));
DECLARE_TYPES(void,
ASurfaceControl_release,
(ASurfaceControl * surface_control));
DECLARE_TYPES(ASurfaceTransaction*, ASurfaceTransaction_create, (void));
DECLARE_TYPES(void,
ASurfaceTransaction_delete,
(ASurfaceTransaction * surface_transaction));
DECLARE_TYPES(void,
ASurfaceTransaction_apply,
(ASurfaceTransaction * surface_transaction));
DECLARE_TYPES(void,
ASurfaceTransaction_setBuffer,
(ASurfaceTransaction * transaction,
ASurfaceControl* surface_control,
AHardwareBuffer* buffer,
int acquire_fence_fd));

DECLARE_TYPES(AChoreographer*, AChoreographer_getInstance, (void));
DECLARE_TYPES(void,
AChoreographer_postFrameCallback,
(AChoreographer * choreographer,
AChoreographer_frameCallback callbackk,
void* data));
DECLARE_TYPES(void,
AChoreographer_postFrameCallback64,
(AChoreographer * choreographer,
AChoreographer_frameCallback64 callbackk,
void* data));

DECLARE_TYPES(EGLClientBuffer,
eglGetNativeClientBufferANDROID,
(AHardwareBuffer * buffer));

#undef DECLARE_TYPES

std::once_flag init_once;

void InitOnceCallback() {
static fml::RefPtr<fml::NativeLibrary> android =
fml::NativeLibrary::Create("libandroid.so");
FML_CHECK(android.get() != nullptr);
static fml::RefPtr<fml::NativeLibrary> egl =
fml::NativeLibrary::Create("libEGL.so");
FML_CHECK(egl.get() != nullptr);

#define LOOKUP(lib, func) \
_##func = lib->ResolveFunction<fp_##func>(#func).value_or(nullptr)

LOOKUP(egl, eglGetNativeClientBufferANDROID);

LOOKUP(android, AHardwareBuffer_fromHardwareBuffer);
LOOKUP(android, AHardwareBuffer_release);
LOOKUP(android, AHardwareBuffer_getId);
LOOKUP(android, AHardwareBuffer_describe);
LOOKUP(android, AHardwareBuffer_allocate);
LOOKUP(android, AHardwareBuffer_isSupported);
LOOKUP(android, ATrace_isEnabled);
LOOKUP(android, AChoreographer_getInstance);
if (_AChoreographer_getInstance) {
LOOKUP(android, AChoreographer_postFrameCallback64);
// See discussion at
// https://github.com/flutter/engine/pull/31859#discussion_r822072987
// This method is not suitable for Flutter's use cases on 32 bit architectures,
// and we should fall back to the Java based Choreographer.
#if FML_ARCH_CPU_64_BITS
if (!_AChoreographer_postFrameCallback64) {
LOOKUP(android, AChoreographer_postFrameCallback);
}
#endif
}

LOOKUP(android, ASurfaceControl_createFromWindow);
LOOKUP(android, ASurfaceControl_release);
LOOKUP(android, ASurfaceTransaction_apply);
LOOKUP(android, ASurfaceTransaction_create);
LOOKUP(android, ASurfaceTransaction_delete);
LOOKUP(android, ASurfaceTransaction_setBuffer);
#undef LOOKUP
}

} // namespace

void NDKHelpers::Init() {
std::call_once(init_once, InitOnceCallback);
}

bool NDKHelpers::ATrace_isEnabled() {
if (_ATrace_isEnabled) {
return _ATrace_isEnabled();
}
return false;
}

ChoreographerSupportStatus NDKHelpers::ChoreographerSupported() {
if (_AChoreographer_postFrameCallback64) {
return ChoreographerSupportStatus::kSupported64;
}
if (_AChoreographer_postFrameCallback) {
return ChoreographerSupportStatus::kSupported32;
}
return ChoreographerSupportStatus::kUnsupported;
}

AChoreographer* NDKHelpers::AChoreographer_getInstance() {
FML_CHECK(_AChoreographer_getInstance);
return _AChoreographer_getInstance();
}

void NDKHelpers::AChoreographer_postFrameCallback(
AChoreographer* choreographer,
AChoreographer_frameCallback callback,
void* data) {
FML_CHECK(_AChoreographer_postFrameCallback);
return _AChoreographer_postFrameCallback(choreographer, callback, data);
}

void NDKHelpers::AChoreographer_postFrameCallback64(
AChoreographer* choreographer,
AChoreographer_frameCallback64 callback,
void* data) {
FML_CHECK(_AChoreographer_postFrameCallback64);
return _AChoreographer_postFrameCallback64(choreographer, callback, data);
}

bool NDKHelpers::HardwareBufferSupported() {
const bool r = _AHardwareBuffer_fromHardwareBuffer != nullptr;
return r;
}

AHardwareBuffer* NDKHelpers::AHardwareBuffer_fromHardwareBuffer(
JNIEnv* env,
jobject hardwareBufferObj) {
FML_CHECK(_AHardwareBuffer_fromHardwareBuffer != nullptr);
return _AHardwareBuffer_fromHardwareBuffer(env, hardwareBufferObj);
}

void NDKHelpers::AHardwareBuffer_release(AHardwareBuffer* buffer) {
FML_CHECK(_AHardwareBuffer_release != nullptr);
_AHardwareBuffer_release(buffer);
}

void NDKHelpers::AHardwareBuffer_describe(AHardwareBuffer* buffer,
AHardwareBuffer_Desc* desc) {
FML_CHECK(_AHardwareBuffer_describe != nullptr);
_AHardwareBuffer_describe(buffer, desc);
}

std::optional<HardwareBufferKey> NDKHelpers::AHardwareBuffer_getId(
AHardwareBuffer* buffer) {
if (_AHardwareBuffer_getId == nullptr) {
return std::nullopt;
}
HardwareBufferKey outId;
int result = _AHardwareBuffer_getId(buffer, &outId);
if (result == 0) {
return outId;
}
return std::nullopt;
}

EGLClientBuffer NDKHelpers::eglGetNativeClientBufferANDROID(
AHardwareBuffer* buffer) {
FML_CHECK(_eglGetNativeClientBufferANDROID != nullptr);
return _eglGetNativeClientBufferANDROID(buffer);
}

bool NDKHelpers::SurfaceControlAndTransactionSupported() {
return _ASurfaceControl_createFromWindow && _ASurfaceControl_release &&
_ASurfaceTransaction_create && _ASurfaceTransaction_apply &&
_ASurfaceTransaction_delete && _ASurfaceTransaction_setBuffer;
}

ASurfaceControl* NDKHelpers::ASurfaceControl_createFromWindow(
ANativeWindow* parent,
const char* debug_name) {
FML_CHECK(_ASurfaceControl_createFromWindow);
return _ASurfaceControl_createFromWindow(parent, debug_name);
}

void NDKHelpers::ASurfaceControl_release(ASurfaceControl* surface_control) {
FML_CHECK(_ASurfaceControl_release);
return _ASurfaceControl_release(surface_control);
}

ASurfaceTransaction* NDKHelpers::ASurfaceTransaction_create() {
FML_CHECK(_ASurfaceTransaction_create);
return _ASurfaceTransaction_create();
}

void NDKHelpers::ASurfaceTransaction_delete(
ASurfaceTransaction* surface_transaction) {
FML_CHECK(_ASurfaceTransaction_delete);
_ASurfaceTransaction_delete(surface_transaction);
}

void NDKHelpers::ASurfaceTransaction_apply(
ASurfaceTransaction* surface_transaction) {
FML_CHECK(_ASurfaceTransaction_apply);
_ASurfaceTransaction_apply(surface_transaction);
}

void NDKHelpers::ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction,
ASurfaceControl* surface_control,
AHardwareBuffer* buffer,
int acquire_fence_fd) {
FML_CHECK(_ASurfaceTransaction_setBuffer);
_ASurfaceTransaction_setBuffer(transaction, surface_control, buffer,
acquire_fence_fd);
}

int NDKHelpers::AHardwareBuffer_isSupported(const AHardwareBuffer_Desc* desc) {
FML_CHECK(_AHardwareBuffer_isSupported);
return _AHardwareBuffer_isSupported(desc);
}

int NDKHelpers::AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc,
AHardwareBuffer** outBuffer) {
FML_CHECK(_AHardwareBuffer_allocate);
return _AHardwareBuffer_allocate(desc, outBuffer);
}

} // namespace flutter
Loading

0 comments on commit 3464f71

Please sign in to comment.