Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 80a93a0

Browse files
Reverts "[Impeller] A toolkit for managed handles to Android NDK vended objects. (#51334)" (#51457)
Reverts: #51334 Initiated by: matanlurey Reason for reverting: Broke engine post-submit, see https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8753367119442265873/+/u/test:_Android_Unit_Tests__API_28_/stdout. Original PR Author: chinmaygarde Reviewed By: {dnfield} This change reverts the following previous change: Only available on Android device API levels >= 29. Proc table is setup has versioning checks. All handles are type safe. Collection of handles takes into account cleanup tasks (like reparenting surface controls). The proc table contains code duplicated in ndk_helpers and I will remove that in favor of this in a subsequent patch. Part of #51213 being chopped up.
1 parent f086ec4 commit 80a93a0

37 files changed

+577
-1381
lines changed

BUILD.gn

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,8 @@ group("unittests") {
167167

168168
public_deps = []
169169
if (is_android) {
170-
public_deps += [
171-
"//flutter/impeller/toolkit/android:unittests",
172-
"//flutter/shell/platform/android:flutter_shell_native_unittests",
173-
]
170+
public_deps +=
171+
[ "//flutter/shell/platform/android:flutter_shell_native_unittests" ]
174172
}
175173

176174
if (is_ios) {

ci/builders/linux_android_emulator.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"ninja": {
3030
"config": "android_emulator_debug_x64",
3131
"targets": [
32-
"flutter/impeller/toolkit/android:unittests",
3332
"flutter/shell/platform/android:flutter_shell_native_unittests",
3433
"flutter/testing/scenario_app"
3534
]
@@ -121,7 +120,6 @@
121120
"ninja": {
122121
"config": "android_emulator_debug_x86",
123122
"targets": [
124-
"flutter/impeller/toolkit/android:unittests",
125123
"flutter/shell/platform/android:flutter_shell_native_unittests",
126124
"flutter/testing/scenario_app"
127125
]

ci/builders/linux_android_emulator_api_33.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"ninja": {
3030
"config": "android_debug_api33_x64",
3131
"targets": [
32-
"flutter/impeller/toolkit/android:unittests",
3332
"flutter/shell/platform/android:flutter_shell_native_unittests",
3433
"flutter/testing/scenario_app"
3534
]

ci/builders/linux_android_emulator_skia.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"ninja": {
3030
"config": "android_emulator_skia_debug_x64",
3131
"targets": [
32-
"flutter/impeller/toolkit/android:unittests",
3332
"flutter/shell/platform/android:flutter_shell_native_unittests",
3433
"flutter/testing/scenario_app"
3534
]

ci/licenses_golden/excluded_files

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
../../../flutter/fml/message_loop_task_queues_unittests.cc
102102
../../../flutter/fml/message_loop_unittests.cc
103103
../../../flutter/fml/paths_unittests.cc
104+
../../../flutter/fml/platform/android/ndk_helpers_unittests.cc
104105
../../../flutter/fml/platform/darwin/cf_utils_unittests.mm
105106
../../../flutter/fml/platform/darwin/scoped_nsobject_arc_unittests.mm
106107
../../../flutter/fml/platform/darwin/scoped_nsobject_unittests.mm
@@ -199,8 +200,6 @@
199200
../../../flutter/impeller/tessellator/dart/pubspec.lock
200201
../../../flutter/impeller/tessellator/dart/pubspec.yaml
201202
../../../flutter/impeller/tessellator/tessellator_unittests.cc
202-
../../../flutter/impeller/toolkit/android/README.md
203-
../../../flutter/impeller/toolkit/android/toolkit_android_unittests.cc
204203
../../../flutter/impeller/tools/build_metal_library.py
205204
../../../flutter/impeller/tools/check_licenses.py
206205
../../../flutter/impeller/tools/malioc_cores.py

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39364,6 +39364,8 @@ ORIGIN: ../../../flutter/fml/platform/android/jni_weak_ref.cc + ../../../flutter
3936439364
ORIGIN: ../../../flutter/fml/platform/android/jni_weak_ref.h + ../../../flutter/LICENSE
3936539365
ORIGIN: ../../../flutter/fml/platform/android/message_loop_android.cc + ../../../flutter/LICENSE
3936639366
ORIGIN: ../../../flutter/fml/platform/android/message_loop_android.h + ../../../flutter/LICENSE
39367+
ORIGIN: ../../../flutter/fml/platform/android/ndk_helpers.cc + ../../../flutter/LICENSE
39368+
ORIGIN: ../../../flutter/fml/platform/android/ndk_helpers.h + ../../../flutter/LICENSE
3936739369
ORIGIN: ../../../flutter/fml/platform/android/paths_android.cc + ../../../flutter/LICENSE
3936839370
ORIGIN: ../../../flutter/fml/platform/android/paths_android.h + ../../../flutter/LICENSE
3936939371
ORIGIN: ../../../flutter/fml/platform/android/scoped_java_ref.cc + ../../../flutter/LICENSE
@@ -40149,18 +40151,6 @@ ORIGIN: ../../../flutter/impeller/tessellator/c/tessellator.h + ../../../flutter
4014940151
ORIGIN: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart + ../../../flutter/LICENSE
4015040152
ORIGIN: ../../../flutter/impeller/tessellator/tessellator.cc + ../../../flutter/LICENSE
4015140153
ORIGIN: ../../../flutter/impeller/tessellator/tessellator.h + ../../../flutter/LICENSE
40152-
ORIGIN: ../../../flutter/impeller/toolkit/android/choreographer.cc + ../../../flutter/LICENSE
40153-
ORIGIN: ../../../flutter/impeller/toolkit/android/choreographer.h + ../../../flutter/LICENSE
40154-
ORIGIN: ../../../flutter/impeller/toolkit/android/hardware_buffer.cc + ../../../flutter/LICENSE
40155-
ORIGIN: ../../../flutter/impeller/toolkit/android/hardware_buffer.h + ../../../flutter/LICENSE
40156-
ORIGIN: ../../../flutter/impeller/toolkit/android/native_window.cc + ../../../flutter/LICENSE
40157-
ORIGIN: ../../../flutter/impeller/toolkit/android/native_window.h + ../../../flutter/LICENSE
40158-
ORIGIN: ../../../flutter/impeller/toolkit/android/proc_table.cc + ../../../flutter/LICENSE
40159-
ORIGIN: ../../../flutter/impeller/toolkit/android/proc_table.h + ../../../flutter/LICENSE
40160-
ORIGIN: ../../../flutter/impeller/toolkit/android/surface_control.cc + ../../../flutter/LICENSE
40161-
ORIGIN: ../../../flutter/impeller/toolkit/android/surface_control.h + ../../../flutter/LICENSE
40162-
ORIGIN: ../../../flutter/impeller/toolkit/android/surface_transaction.cc + ../../../flutter/LICENSE
40163-
ORIGIN: ../../../flutter/impeller/toolkit/android/surface_transaction.h + ../../../flutter/LICENSE
4016440154
ORIGIN: ../../../flutter/impeller/toolkit/egl/config.cc + ../../../flutter/LICENSE
4016540155
ORIGIN: ../../../flutter/impeller/toolkit/egl/config.h + ../../../flutter/LICENSE
4016640156
ORIGIN: ../../../flutter/impeller/toolkit/egl/context.cc + ../../../flutter/LICENSE
@@ -40884,7 +40874,6 @@ ORIGIN: ../../../flutter/shell/platform/android/flutter_main.h + ../../../flutte
4088440874
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture.h + ../../../flutter/LICENSE
4088540875
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl.cc + ../../../flutter/LICENSE
4088640876
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_gl.h + ../../../flutter/LICENSE
40887-
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk.cc + ../../../flutter/LICENSE
4088840877
ORIGIN: ../../../flutter/shell/platform/android/image_external_texture_vk.h + ../../../flutter/LICENSE
4088940878
ORIGIN: ../../../flutter/shell/platform/android/image_lru.cc + ../../../flutter/LICENSE
4089040879
ORIGIN: ../../../flutter/shell/platform/android/image_lru.h + ../../../flutter/LICENSE
@@ -42231,6 +42220,8 @@ FILE: ../../../flutter/fml/platform/android/jni_weak_ref.cc
4223142220
FILE: ../../../flutter/fml/platform/android/jni_weak_ref.h
4223242221
FILE: ../../../flutter/fml/platform/android/message_loop_android.cc
4223342222
FILE: ../../../flutter/fml/platform/android/message_loop_android.h
42223+
FILE: ../../../flutter/fml/platform/android/ndk_helpers.cc
42224+
FILE: ../../../flutter/fml/platform/android/ndk_helpers.h
4223442225
FILE: ../../../flutter/fml/platform/android/paths_android.cc
4223542226
FILE: ../../../flutter/fml/platform/android/paths_android.h
4223642227
FILE: ../../../flutter/fml/platform/android/scoped_java_ref.cc
@@ -43017,18 +43008,6 @@ FILE: ../../../flutter/impeller/tessellator/c/tessellator.h
4301743008
FILE: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart
4301843009
FILE: ../../../flutter/impeller/tessellator/tessellator.cc
4301943010
FILE: ../../../flutter/impeller/tessellator/tessellator.h
43020-
FILE: ../../../flutter/impeller/toolkit/android/choreographer.cc
43021-
FILE: ../../../flutter/impeller/toolkit/android/choreographer.h
43022-
FILE: ../../../flutter/impeller/toolkit/android/hardware_buffer.cc
43023-
FILE: ../../../flutter/impeller/toolkit/android/hardware_buffer.h
43024-
FILE: ../../../flutter/impeller/toolkit/android/native_window.cc
43025-
FILE: ../../../flutter/impeller/toolkit/android/native_window.h
43026-
FILE: ../../../flutter/impeller/toolkit/android/proc_table.cc
43027-
FILE: ../../../flutter/impeller/toolkit/android/proc_table.h
43028-
FILE: ../../../flutter/impeller/toolkit/android/surface_control.cc
43029-
FILE: ../../../flutter/impeller/toolkit/android/surface_control.h
43030-
FILE: ../../../flutter/impeller/toolkit/android/surface_transaction.cc
43031-
FILE: ../../../flutter/impeller/toolkit/android/surface_transaction.h
4303243011
FILE: ../../../flutter/impeller/toolkit/egl/config.cc
4303343012
FILE: ../../../flutter/impeller/toolkit/egl/config.h
4303443013
FILE: ../../../flutter/impeller/toolkit/egl/context.cc

fml/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ source_set("fml") {
188188
"platform/android/jni_weak_ref.h",
189189
"platform/android/message_loop_android.cc",
190190
"platform/android/message_loop_android.h",
191+
"platform/android/ndk_helpers.cc",
192+
"platform/android/ndk_helpers.h",
191193
"platform/android/paths_android.cc",
192194
"platform/android/paths_android.h",
193195
"platform/android/scoped_java_ref.cc",
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "fml/platform/android/ndk_helpers.h"
6+
7+
#include "fml/logging.h"
8+
#include "fml/native_library.h"
9+
10+
#include <android/hardware_buffer.h>
11+
#include <dlfcn.h>
12+
13+
namespace flutter {
14+
15+
namespace {
16+
17+
#define DECLARE_TYPES(ret, name, args) \
18+
typedef ret(*fp_##name) args; \
19+
ret(*_##name) args = nullptr
20+
21+
DECLARE_TYPES(int,
22+
AHardwareBuffer_allocate,
23+
(const AHardwareBuffer_Desc* desc, AHardwareBuffer** outBuffer));
24+
DECLARE_TYPES(int,
25+
AHardwareBuffer_isSupported,
26+
(const AHardwareBuffer_Desc* desc));
27+
DECLARE_TYPES(AHardwareBuffer*,
28+
AHardwareBuffer_fromHardwareBuffer,
29+
(JNIEnv * env, jobject hardwareBufferObj));
30+
DECLARE_TYPES(void, AHardwareBuffer_release, (AHardwareBuffer * buffer));
31+
DECLARE_TYPES(void,
32+
AHardwareBuffer_describe,
33+
(AHardwareBuffer * buffer, AHardwareBuffer_Desc* desc));
34+
DECLARE_TYPES(int,
35+
AHardwareBuffer_getId,
36+
(AHardwareBuffer * buffer, uint64_t* outId));
37+
38+
DECLARE_TYPES(bool, ATrace_isEnabled, (void));
39+
40+
DECLARE_TYPES(ASurfaceControl*,
41+
ASurfaceControl_createFromWindow,
42+
(ANativeWindow * parent, const char* debug_name));
43+
DECLARE_TYPES(void,
44+
ASurfaceControl_release,
45+
(ASurfaceControl * surface_control));
46+
DECLARE_TYPES(ASurfaceTransaction*, ASurfaceTransaction_create, (void));
47+
DECLARE_TYPES(void,
48+
ASurfaceTransaction_delete,
49+
(ASurfaceTransaction * surface_transaction));
50+
DECLARE_TYPES(void,
51+
ASurfaceTransaction_apply,
52+
(ASurfaceTransaction * surface_transaction));
53+
DECLARE_TYPES(void,
54+
ASurfaceTransaction_setBuffer,
55+
(ASurfaceTransaction * transaction,
56+
ASurfaceControl* surface_control,
57+
AHardwareBuffer* buffer,
58+
int acquire_fence_fd));
59+
60+
DECLARE_TYPES(AChoreographer*, AChoreographer_getInstance, (void));
61+
DECLARE_TYPES(void,
62+
AChoreographer_postFrameCallback,
63+
(AChoreographer * choreographer,
64+
AChoreographer_frameCallback callbackk,
65+
void* data));
66+
DECLARE_TYPES(void,
67+
AChoreographer_postFrameCallback64,
68+
(AChoreographer * choreographer,
69+
AChoreographer_frameCallback64 callbackk,
70+
void* data));
71+
72+
DECLARE_TYPES(EGLClientBuffer,
73+
eglGetNativeClientBufferANDROID,
74+
(AHardwareBuffer * buffer));
75+
76+
#undef DECLARE_TYPES
77+
78+
std::once_flag init_once;
79+
80+
void InitOnceCallback() {
81+
static fml::RefPtr<fml::NativeLibrary> android =
82+
fml::NativeLibrary::Create("libandroid.so");
83+
FML_CHECK(android.get() != nullptr);
84+
static fml::RefPtr<fml::NativeLibrary> egl =
85+
fml::NativeLibrary::Create("libEGL.so");
86+
FML_CHECK(egl.get() != nullptr);
87+
88+
#define LOOKUP(lib, func) \
89+
_##func = lib->ResolveFunction<fp_##func>(#func).value_or(nullptr)
90+
91+
LOOKUP(egl, eglGetNativeClientBufferANDROID);
92+
93+
LOOKUP(android, AHardwareBuffer_fromHardwareBuffer);
94+
LOOKUP(android, AHardwareBuffer_release);
95+
LOOKUP(android, AHardwareBuffer_getId);
96+
LOOKUP(android, AHardwareBuffer_describe);
97+
LOOKUP(android, AHardwareBuffer_allocate);
98+
LOOKUP(android, AHardwareBuffer_isSupported);
99+
LOOKUP(android, ATrace_isEnabled);
100+
LOOKUP(android, AChoreographer_getInstance);
101+
if (_AChoreographer_getInstance) {
102+
LOOKUP(android, AChoreographer_postFrameCallback64);
103+
// See discussion at
104+
// https://github.com/flutter/engine/pull/31859#discussion_r822072987
105+
// This method is not suitable for Flutter's use cases on 32 bit architectures,
106+
// and we should fall back to the Java based Choreographer.
107+
#if FML_ARCH_CPU_64_BITS
108+
if (!_AChoreographer_postFrameCallback64) {
109+
LOOKUP(android, AChoreographer_postFrameCallback);
110+
}
111+
#endif
112+
}
113+
114+
LOOKUP(android, ASurfaceControl_createFromWindow);
115+
LOOKUP(android, ASurfaceControl_release);
116+
LOOKUP(android, ASurfaceTransaction_apply);
117+
LOOKUP(android, ASurfaceTransaction_create);
118+
LOOKUP(android, ASurfaceTransaction_delete);
119+
LOOKUP(android, ASurfaceTransaction_setBuffer);
120+
#undef LOOKUP
121+
}
122+
123+
} // namespace
124+
125+
void NDKHelpers::Init() {
126+
std::call_once(init_once, InitOnceCallback);
127+
}
128+
129+
bool NDKHelpers::ATrace_isEnabled() {
130+
if (_ATrace_isEnabled) {
131+
return _ATrace_isEnabled();
132+
}
133+
return false;
134+
}
135+
136+
ChoreographerSupportStatus NDKHelpers::ChoreographerSupported() {
137+
if (_AChoreographer_postFrameCallback64) {
138+
return ChoreographerSupportStatus::kSupported64;
139+
}
140+
if (_AChoreographer_postFrameCallback) {
141+
return ChoreographerSupportStatus::kSupported32;
142+
}
143+
return ChoreographerSupportStatus::kUnsupported;
144+
}
145+
146+
AChoreographer* NDKHelpers::AChoreographer_getInstance() {
147+
FML_CHECK(_AChoreographer_getInstance);
148+
return _AChoreographer_getInstance();
149+
}
150+
151+
void NDKHelpers::AChoreographer_postFrameCallback(
152+
AChoreographer* choreographer,
153+
AChoreographer_frameCallback callback,
154+
void* data) {
155+
FML_CHECK(_AChoreographer_postFrameCallback);
156+
return _AChoreographer_postFrameCallback(choreographer, callback, data);
157+
}
158+
159+
void NDKHelpers::AChoreographer_postFrameCallback64(
160+
AChoreographer* choreographer,
161+
AChoreographer_frameCallback64 callback,
162+
void* data) {
163+
FML_CHECK(_AChoreographer_postFrameCallback64);
164+
return _AChoreographer_postFrameCallback64(choreographer, callback, data);
165+
}
166+
167+
bool NDKHelpers::HardwareBufferSupported() {
168+
const bool r = _AHardwareBuffer_fromHardwareBuffer != nullptr;
169+
return r;
170+
}
171+
172+
AHardwareBuffer* NDKHelpers::AHardwareBuffer_fromHardwareBuffer(
173+
JNIEnv* env,
174+
jobject hardwareBufferObj) {
175+
FML_CHECK(_AHardwareBuffer_fromHardwareBuffer != nullptr);
176+
return _AHardwareBuffer_fromHardwareBuffer(env, hardwareBufferObj);
177+
}
178+
179+
void NDKHelpers::AHardwareBuffer_release(AHardwareBuffer* buffer) {
180+
FML_CHECK(_AHardwareBuffer_release != nullptr);
181+
_AHardwareBuffer_release(buffer);
182+
}
183+
184+
void NDKHelpers::AHardwareBuffer_describe(AHardwareBuffer* buffer,
185+
AHardwareBuffer_Desc* desc) {
186+
FML_CHECK(_AHardwareBuffer_describe != nullptr);
187+
_AHardwareBuffer_describe(buffer, desc);
188+
}
189+
190+
std::optional<HardwareBufferKey> NDKHelpers::AHardwareBuffer_getId(
191+
AHardwareBuffer* buffer) {
192+
if (_AHardwareBuffer_getId == nullptr) {
193+
return std::nullopt;
194+
}
195+
HardwareBufferKey outId;
196+
int result = _AHardwareBuffer_getId(buffer, &outId);
197+
if (result == 0) {
198+
return outId;
199+
}
200+
return std::nullopt;
201+
}
202+
203+
EGLClientBuffer NDKHelpers::eglGetNativeClientBufferANDROID(
204+
AHardwareBuffer* buffer) {
205+
FML_CHECK(_eglGetNativeClientBufferANDROID != nullptr);
206+
return _eglGetNativeClientBufferANDROID(buffer);
207+
}
208+
209+
bool NDKHelpers::SurfaceControlAndTransactionSupported() {
210+
return _ASurfaceControl_createFromWindow && _ASurfaceControl_release &&
211+
_ASurfaceTransaction_create && _ASurfaceTransaction_apply &&
212+
_ASurfaceTransaction_delete && _ASurfaceTransaction_setBuffer;
213+
}
214+
215+
ASurfaceControl* NDKHelpers::ASurfaceControl_createFromWindow(
216+
ANativeWindow* parent,
217+
const char* debug_name) {
218+
FML_CHECK(_ASurfaceControl_createFromWindow);
219+
return _ASurfaceControl_createFromWindow(parent, debug_name);
220+
}
221+
222+
void NDKHelpers::ASurfaceControl_release(ASurfaceControl* surface_control) {
223+
FML_CHECK(_ASurfaceControl_release);
224+
return _ASurfaceControl_release(surface_control);
225+
}
226+
227+
ASurfaceTransaction* NDKHelpers::ASurfaceTransaction_create() {
228+
FML_CHECK(_ASurfaceTransaction_create);
229+
return _ASurfaceTransaction_create();
230+
}
231+
232+
void NDKHelpers::ASurfaceTransaction_delete(
233+
ASurfaceTransaction* surface_transaction) {
234+
FML_CHECK(_ASurfaceTransaction_delete);
235+
_ASurfaceTransaction_delete(surface_transaction);
236+
}
237+
238+
void NDKHelpers::ASurfaceTransaction_apply(
239+
ASurfaceTransaction* surface_transaction) {
240+
FML_CHECK(_ASurfaceTransaction_apply);
241+
_ASurfaceTransaction_apply(surface_transaction);
242+
}
243+
244+
void NDKHelpers::ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction,
245+
ASurfaceControl* surface_control,
246+
AHardwareBuffer* buffer,
247+
int acquire_fence_fd) {
248+
FML_CHECK(_ASurfaceTransaction_setBuffer);
249+
_ASurfaceTransaction_setBuffer(transaction, surface_control, buffer,
250+
acquire_fence_fd);
251+
}
252+
253+
int NDKHelpers::AHardwareBuffer_isSupported(const AHardwareBuffer_Desc* desc) {
254+
FML_CHECK(_AHardwareBuffer_isSupported);
255+
return _AHardwareBuffer_isSupported(desc);
256+
}
257+
258+
int NDKHelpers::AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc,
259+
AHardwareBuffer** outBuffer) {
260+
FML_CHECK(_AHardwareBuffer_allocate);
261+
return _AHardwareBuffer_allocate(desc, outBuffer);
262+
}
263+
264+
} // namespace flutter

0 commit comments

Comments
 (0)