From 49440f6e14c941f6656bb5011b6bdf507710ef71 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 31 May 2017 17:27:47 -0700 Subject: [PATCH] Allow switching to the software rendering backend on Android. (flutter/engine#3719) * Enable software rendering backend on android. Add "enable-software-rendering" flag. * Fix variable naming and threading. --- engine/src/flutter/common/settings.h | 1 + engine/src/flutter/shell/common/shell.cc | 6 +- engine/src/flutter/shell/common/switches.h | 5 + .../flutter/shell/platform/android/BUILD.gn | 2 + .../shell/platform/android/android_surface.h | 5 + .../platform/android/android_surface_gl.cc | 3 + .../platform/android/android_surface_gl.h | 4 + .../android/android_surface_software.cc | 119 ++++++++++++++++++ .../android/android_surface_software.h | 55 ++++++++ .../android/android_surface_vulkan.cc | 3 + .../platform/android/android_surface_vulkan.h | 4 + .../android/io/flutter/view/FlutterView.java | 31 ++++- .../platform/android/platform_view_android.cc | 60 +++++---- .../platform/android/platform_view_android.h | 2 + .../android/platform_view_android_jni.cc | 35 +++++- .../android/platform_view_android_jni.h | 6 + 16 files changed, 311 insertions(+), 30 deletions(-) create mode 100644 engine/src/flutter/shell/platform/android/android_surface_software.cc create mode 100644 engine/src/flutter/shell/platform/android/android_surface_software.h diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 690abce3f8..8fd9de59d9 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -26,6 +26,7 @@ struct Settings { bool enable_dart_profiling = false; bool use_test_fonts = false; bool dart_non_checked_mode = false; + bool enable_software_rendering = false; std::string aot_snapshot_path; std::string aot_vm_snapshot_data_filename; std::string aot_vm_snapshot_instr_filename; diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 7899745ca8..21eb3c916f 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -136,8 +136,7 @@ void Shell::InitStandalone(ftl::CommandLine command_line, } } - settings.ipv6 = - command_line.HasOption(FlagForSwitch(Switch::IPv6)); + settings.ipv6 = command_line.HasOption(FlagForSwitch(Switch::IPv6)); settings.start_paused = command_line.HasOption(FlagForSwitch(Switch::StartPaused)); @@ -145,6 +144,9 @@ void Shell::InitStandalone(ftl::CommandLine command_line, settings.enable_dart_profiling = command_line.HasOption(FlagForSwitch(Switch::EnableDartProfiling)); + settings.enable_software_rendering = + command_line.HasOption(FlagForSwitch(Switch::EnableSoftwareRendering)); + settings.endless_trace_buffer = command_line.HasOption(FlagForSwitch(Switch::EndlessTraceBuffer)); diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index d4d76b181a..fe68fe13d6 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -58,6 +58,11 @@ DEF_SWITCH(EndlessTraceBuffer, "This is useful when very old events need to viewed. For example, " "during application launch. Memory usage will continue to grow " "indefinitely however.") +DEF_SWITCH(EnableSoftwareRendering, + "enable-software-rendering", + "Enable rendering using the Skia software backend. This is useful" + "when testing Flutter on emulators. By default, Flutter will" + "attempt to either use OpenGL or Vulkan.") DEF_SWITCH(FLX, "flx", "Specify the the FLX path.") DEF_SWITCH(Help, "help", "Display this help text.") DEF_SWITCH(LogTag, "log-tag", "Tag associated with log messages.") diff --git a/engine/src/flutter/shell/platform/android/BUILD.gn b/engine/src/flutter/shell/platform/android/BUILD.gn index ce41887ff0..05cf6e1615 100644 --- a/engine/src/flutter/shell/platform/android/BUILD.gn +++ b/engine/src/flutter/shell/platform/android/BUILD.gn @@ -23,6 +23,8 @@ shared_library("flutter_shell_native") { "android_surface.h", "android_surface_gl.cc", "android_surface_gl.h", + "android_surface_software.h", + "android_surface_software.cc", "flutter_main.cc", "flutter_main.h", "library_loader.cc", diff --git a/engine/src/flutter/shell/platform/android/android_surface.h b/engine/src/flutter/shell/platform/android/android_surface.h index bab30b3aaa..23218b94d8 100644 --- a/engine/src/flutter/shell/platform/android/android_surface.h +++ b/engine/src/flutter/shell/platform/android/android_surface.h @@ -7,6 +7,8 @@ #include +#include "flutter/fml/platform/android/jni_util.h" +#include "flutter/fml/platform/android/jni_weak_ref.h" #include "flutter/shell/common/platform_view.h" #include "flutter/shell/common/surface.h" #include "flutter/shell/platform/android/android_native_window.h" @@ -33,6 +35,9 @@ class AndroidSurface { virtual bool SetNativeWindow(ftl::RefPtr window, PlatformView::SurfaceConfig config = {}) = 0; + + virtual void SetFlutterView( + const fml::jni::JavaObjectWeakGlobalRef& flutter_view) = 0; }; } // namespace shell diff --git a/engine/src/flutter/shell/platform/android/android_surface_gl.cc b/engine/src/flutter/shell/platform/android/android_surface_gl.cc index 0df1516852..9e86824f46 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_gl.cc +++ b/engine/src/flutter/shell/platform/android/android_surface_gl.cc @@ -149,4 +149,7 @@ intptr_t AndroidSurfaceGL::GLContextFBO() const { return 0; } +void AndroidSurfaceGL::SetFlutterView( + const fml::jni::JavaObjectWeakGlobalRef& flutter_view) {} + } // namespace shell diff --git a/engine/src/flutter/shell/platform/android/android_surface_gl.h b/engine/src/flutter/shell/platform/android/android_surface_gl.h index 9dd1e174b4..21a5768db7 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_gl.h +++ b/engine/src/flutter/shell/platform/android/android_surface_gl.h @@ -5,6 +5,7 @@ #ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_GL_H_ #define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_GL_H_ +#include #include #include "flutter/shell/gpu/gpu_surface_gl.h" @@ -46,6 +47,9 @@ class AndroidSurfaceGL : public GPUSurfaceGLDelegate, public AndroidSurface { intptr_t GLContextFBO() const override; + void SetFlutterView( + const fml::jni::JavaObjectWeakGlobalRef& flutter_view) override; + private: ftl::RefPtr onscreen_context_; ftl::RefPtr offscreen_context_; diff --git a/engine/src/flutter/shell/platform/android/android_surface_software.cc b/engine/src/flutter/shell/platform/android/android_surface_software.cc new file mode 100644 index 0000000000..7d0a213590 --- /dev/null +++ b/engine/src/flutter/shell/platform/android/android_surface_software.cc @@ -0,0 +1,119 @@ +// Copyright 2017 The Chromium 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 "flutter/shell/platform/android/android_surface_software.h" +#include "flutter/common/threads.h" +#include "flutter/fml/platform/android/jni_weak_ref.h" +#include "flutter/fml/platform/android/scoped_java_ref.h" +#include "flutter/shell/platform/android/platform_view_android_jni.h" + +#include +#include + +#include "flutter/fml/trace_event.h" +#include "lib/ftl/logging.h" + +namespace shell { + +AndroidSurfaceSoftware::AndroidSurfaceSoftware() : AndroidSurface() {} + +AndroidSurfaceSoftware::~AndroidSurfaceSoftware() = default; + +bool AndroidSurfaceSoftware::IsValid() const { + return true; +} + +bool AndroidSurfaceSoftware::ResourceContextMakeCurrent() { + // Resource Context always not available on software backend. + return false; +} + +std::unique_ptr AndroidSurfaceSoftware::CreateGPUSurface() { + if (!IsValid()) { + return nullptr; + } + + auto surface = std::make_unique(this); + + if (!surface->IsValid()) { + return nullptr; + } + + return surface; +} + +sk_sp AndroidSurfaceSoftware::AcquireBackingStore( + const SkISize& size) { + TRACE_EVENT0("flutter", "AndroidSurfaceSoftware::AcquireBackingStore"); + if (!IsValid()) { + return nullptr; + } + + if (sk_surface_ != nullptr && + SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) { + // The old and new surface sizes are the same. Nothing to do here. + return sk_surface_; + } + + sk_surface_ = SkSurface::MakeRasterN32Premul( + size.fWidth, size.fHeight, nullptr /* SkSurfaceProps as out */); + return sk_surface_; +} + +bool AndroidSurfaceSoftware::PresentBackingStore( + sk_sp backing_store) { + TRACE_EVENT0("flutter", "AndroidSurfaceSoftware::PresentBackingStore"); + if (!IsValid() || backing_store == nullptr) { + return false; + } + + SkPixmap pixmap; + if (!backing_store->peekPixels(&pixmap)) { + return false; + } + + // Some basic sanity checking. + uint64_t expected_pixmap_data_size = pixmap.width() * pixmap.height() * 4; + + if (expected_pixmap_data_size != pixmap.getSize64()) { + return false; + } + + // Pass the sk_surface buffer to the android FlutterView. + JNIEnv* env = fml::jni::AttachCurrentThread(); + + // Buffer will be copied into a Bitmap Java-side. + fml::jni::ScopedJavaLocalRef direct_buffer( + env, + env->NewDirectByteBuffer(pixmap.writable_addr(), pixmap.getSize64())); + + FlutterViewUpdateSoftwareBuffer(env, flutter_view_.get(env).obj(), + direct_buffer.obj(), pixmap.width(), + pixmap.height()); + + return true; +} + +void AndroidSurfaceSoftware::TeardownOnScreenContext() {} + +SkISize AndroidSurfaceSoftware::OnScreenSurfaceSize() const { + return SkISize(); +} + +bool AndroidSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) const { + return true; +} + +bool AndroidSurfaceSoftware::SetNativeWindow( + ftl::RefPtr window, + PlatformView::SurfaceConfig config) { + return true; +} + +void AndroidSurfaceSoftware::SetFlutterView( + const fml::jni::JavaObjectWeakGlobalRef& flutter_view) { + flutter_view_ = flutter_view; +} + +} // namespace shell diff --git a/engine/src/flutter/shell/platform/android/android_surface_software.h b/engine/src/flutter/shell/platform/android/android_surface_software.h new file mode 100644 index 0000000000..0971e68a4a --- /dev/null +++ b/engine/src/flutter/shell/platform/android/android_surface_software.h @@ -0,0 +1,55 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_SOFTWARE_H_ +#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_SOFTWARE_H_ + +#include "flutter/fml/platform/android/jni_weak_ref.h" +#include "flutter/fml/platform/android/scoped_java_ref.h" +#include "flutter/shell/gpu/gpu_surface_software.h" +#include "flutter/shell/platform/android/android_surface.h" +#include "lib/ftl/macros.h" + +namespace shell { + +class AndroidSurfaceSoftware : public AndroidSurface, + public GPUSurfaceSoftwareDelegate { + public: + AndroidSurfaceSoftware(); + + ~AndroidSurfaceSoftware() override; + + bool IsValid() const override; + + bool ResourceContextMakeCurrent() override; + + std::unique_ptr CreateGPUSurface() override; + + sk_sp AcquireBackingStore(const SkISize& size) override; + + bool PresentBackingStore(sk_sp backing_store) override; + + void TeardownOnScreenContext() override; + + SkISize OnScreenSurfaceSize() const override; + + bool OnScreenSurfaceResize(const SkISize& size) const override; + + bool SetNativeWindow(ftl::RefPtr window, + PlatformView::SurfaceConfig config) override; + + void SetFlutterView( + const fml::jni::JavaObjectWeakGlobalRef& flutter_view) override; + + private: + sk_sp sk_surface_; + + fml::jni::JavaObjectWeakGlobalRef flutter_view_; + + FTL_DISALLOW_COPY_AND_ASSIGN(AndroidSurfaceSoftware); +}; + +} // namespace shell + +#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_SOFTWARE_H_ diff --git a/engine/src/flutter/shell/platform/android/android_surface_vulkan.cc b/engine/src/flutter/shell/platform/android/android_surface_vulkan.cc index ad2b297c3a..9b5b7d56dd 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_vulkan.cc +++ b/engine/src/flutter/shell/platform/android/android_surface_vulkan.cc @@ -68,6 +68,9 @@ bool AndroidSurfaceVulkan::ResourceContextMakeCurrent() { return false; } +void AndroidSurfaceVulkan::SetFlutterView( + const fml::jni::JavaObjectWeakGlobalRef& flutter_view) {} + bool AndroidSurfaceVulkan::SetNativeWindow( ftl::RefPtr window, PlatformView::SurfaceConfig config) { diff --git a/engine/src/flutter/shell/platform/android/android_surface_vulkan.h b/engine/src/flutter/shell/platform/android/android_surface_vulkan.h index c041b63485..444636ca94 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_vulkan.h +++ b/engine/src/flutter/shell/platform/android/android_surface_vulkan.h @@ -5,6 +5,7 @@ #ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_VULKAN_H_ #define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_SURFACE_VULKAN_H_ +#include #include #include "flutter/shell/platform/android/android_native_window.h" #include "flutter/shell/platform/android/android_surface.h" @@ -34,6 +35,9 @@ class AndroidSurfaceVulkan : public AndroidSurface { bool SetNativeWindow(ftl::RefPtr window, PlatformView::SurfaceConfig config) override; + void SetFlutterView( + const fml::jni::JavaObjectWeakGlobalRef& flutter_view) override; + private: ftl::RefPtr proc_table_; ftl::RefPtr native_window_; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index e36b75e786..aa2af85b7a 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -13,6 +13,9 @@ import android.content.pm.ApplicationInfo; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Rect; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Matrix; import android.os.Build; import android.util.AttributeSet; import android.util.Log; @@ -81,6 +84,9 @@ public class FlutterView extends SurfaceView private final BroadcastReceiver mDiscoveryReceiver; private final List mActivityLifecycleListeners; private long mNativePlatformView; + private boolean mIsSoftwareRenderingEnabled = false; // using the software renderer or not + + private volatile Bitmap mSoftwareRenderingBitmap; public FlutterView(Context context) { this(context, null); @@ -89,6 +95,8 @@ public class FlutterView extends SurfaceView public FlutterView(Context context, AttributeSet attrs) { super(context, attrs); + mIsSoftwareRenderingEnabled = nativeGetIsSoftwareRenderingEnabled(); + mMetrics = new ViewportMetrics(); mMetrics.devicePixelRatio = context.getResources().getDisplayMetrics().density; setFocusable(true); @@ -198,6 +206,21 @@ public class FlutterView extends SurfaceView return super.onKeyDown(keyCode, event); } + @Override + protected void onDraw(Canvas canvas) { + if (mSoftwareRenderingBitmap != null) { + canvas.drawBitmap(mSoftwareRenderingBitmap, new Matrix(), new Paint()); + } + } + + // This method will be called on the GPU Thread. + public void updateSoftwareBuffer(ByteBuffer buffer, int width, int height) { + Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + newBitmap.copyPixelsFromBuffer(buffer); + mSoftwareRenderingBitmap = newBitmap; + postInvalidate(); + } + public void addActivityLifecycleListener(ActivityLifecycleListener listener) { mActivityLifecycleListeners.add(listener); } @@ -593,6 +616,8 @@ public class FlutterView extends SurfaceView private static native void nativeInvokePlatformMessageEmptyResponseCallback( long nativePlatformViewAndroid, int responseId); + private static native boolean nativeGetIsSoftwareRenderingEnabled(); + private void updateViewportMetrics() { nativeSetViewportMetrics(mNativePlatformView, mMetrics.devicePixelRatio, @@ -697,7 +722,11 @@ public class FlutterView extends SurfaceView } private void resetWillNotDraw() { - setWillNotDraw(!(mAccessibilityEnabled || mTouchExplorationEnabled)); + if (!mIsSoftwareRenderingEnabled) { + setWillNotDraw(!(mAccessibilityEnabled || mTouchExplorationEnabled)); + } else { + setWillNotDraw(false); + } } @Override diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.cc b/engine/src/flutter/shell/platform/android/platform_view_android.cc index 17473e596f..3d4d85272e 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android.cc @@ -11,12 +11,14 @@ #include +#include "flutter/common/settings.h" #include "flutter/common/threads.h" #include "flutter/fml/platform/android/jni_util.h" #include "flutter/fml/platform/android/scoped_java_ref.h" #include "flutter/runtime/dart_service_isolate.h" #include "flutter/shell/gpu/gpu_rasterizer.h" #include "flutter/shell/platform/android/android_surface_gl.h" +#include "flutter/shell/platform/android/android_surface_software.h" #include "flutter/shell/platform/android/platform_view_android_jni.h" #include "flutter/shell/platform/android/vsync_waiter_android.h" #include "lib/ftl/functional/make_copyable.h" @@ -45,13 +47,12 @@ class PlatformMessageResponseAndroid : public blink::PlatformMessageResponse { void CompleteEmpty() override { ftl::RefPtr self(this); - blink::Threads::Platform()->PostTask( - ftl::MakeCopyable([ self ]() mutable { - if (!self->view_) - return; - static_cast(self->view_.get()) - ->HandlePlatformMessageEmptyResponse(self->response_id_); - })); + blink::Threads::Platform()->PostTask(ftl::MakeCopyable([self]() mutable { + if (!self->view_) + return; + static_cast(self->view_.get()) + ->HandlePlatformMessageEmptyResponse(self->response_id_); + })); } private: @@ -85,7 +86,19 @@ static std::unique_ptr InitializePlatformSurfaceVulkan() { #endif // SHELL_ENABLE_VULKAN } +static std::unique_ptr InitializePlatformSurfaceSoftware() { + auto surface = std::make_unique(); + return surface->IsValid() ? std::move(surface) : nullptr; +} + static std::unique_ptr InitializePlatformSurface() { + if (blink::Settings::Get().enable_software_rendering) { + if (auto surface = InitializePlatformSurfaceSoftware()) { + FTL_DLOG(INFO) << "Software surface initialized."; + return surface; + } + } + if (auto surface = InitializePlatformSurfaceVulkan()) { FTL_DLOG(INFO) << "Vulkan surface initialized."; return surface; @@ -252,8 +265,8 @@ void PlatformViewAndroid::DispatchEmptyPlatformMessage(JNIEnv* env, } PlatformView::DispatchPlatformMessage( - ftl::MakeRefCounted( - std::move(name), std::move(response))); + ftl::MakeRefCounted(std::move(name), + std::move(response))); } void PlatformViewAndroid::DispatchPointerDataPacket(JNIEnv* env, @@ -281,9 +294,9 @@ void PlatformViewAndroid::InvokePlatformMessageResponseCallback( if (it == pending_responses_.end()) return; uint8_t* response_data = - static_cast(env->GetDirectBufferAddress(java_response_data)); - std::vector response = std::vector(response_data, - response_data + java_response_position); + static_cast(env->GetDirectBufferAddress(java_response_data)); + std::vector response = std::vector( + response_data, response_data + java_response_position); auto message_response = std::move(it->second); pending_responses_.erase(it); message_response->Complete(std::move(response)); @@ -316,22 +329,22 @@ void PlatformViewAndroid::HandlePlatformMessage( } auto java_channel = fml::jni::StringToJavaString(env, message->channel()); if (message->hasData()) { - fml::jni::ScopedJavaLocalRef message_array(env, - env->NewByteArray(message->data().size())); + fml::jni::ScopedJavaLocalRef message_array( + env, env->NewByteArray(message->data().size())); env->SetByteArrayRegion( message_array.obj(), 0, message->data().size(), reinterpret_cast(message->data().data())); message = nullptr; // This call can re-enter in InvokePlatformMessageXxxResponseCallback. - FlutterViewHandlePlatformMessage( - env, view.obj(), java_channel.obj(), message_array.obj(), response_id); + FlutterViewHandlePlatformMessage(env, view.obj(), java_channel.obj(), + message_array.obj(), response_id); } else { message = nullptr; // This call can re-enter in InvokePlatformMessageXxxResponseCallback. - FlutterViewHandlePlatformMessage( - env, view.obj(), java_channel.obj(), nullptr, response_id); + FlutterViewHandlePlatformMessage(env, view.obj(), java_channel.obj(), + nullptr, response_id); } } @@ -344,8 +357,8 @@ void PlatformViewAndroid::HandlePlatformMessageResponse( if (view.is_null()) return; - fml::jni::ScopedJavaLocalRef data_array(env, - env->NewByteArray(data.size())); + fml::jni::ScopedJavaLocalRef data_array( + env, env->NewByteArray(data.size())); env->SetByteArrayRegion(data_array.obj(), 0, data.size(), reinterpret_cast(data.data())); @@ -353,8 +366,7 @@ void PlatformViewAndroid::HandlePlatformMessageResponse( data_array.obj()); } -void PlatformViewAndroid::HandlePlatformMessageEmptyResponse( - int response_id) { +void PlatformViewAndroid::HandlePlatformMessageEmptyResponse(int response_id) { JNIEnv* env = fml::jni::AttachCurrentThread(); fml::jni::ScopedJavaLocalRef view = flutter_view_.get(env); @@ -433,8 +445,8 @@ void PlatformViewAndroid::UpdateSemantics( buffer_int32[position++] = child; } - fml::jni::ScopedJavaLocalRef direct_buffer(env, - env->NewDirectByteBuffer(buffer.data(), buffer.size())); + fml::jni::ScopedJavaLocalRef direct_buffer( + env, env->NewDirectByteBuffer(buffer.data(), buffer.size())); FlutterViewUpdateSemantics( env, view.obj(), direct_buffer.obj(), diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.h b/engine/src/flutter/shell/platform/android/platform_view_android.h index 0f4e89cf4f..fbc8f8d9c2 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.h +++ b/engine/src/flutter/shell/platform/android/platform_view_android.h @@ -97,8 +97,10 @@ class PlatformViewAndroid : public PlatformView { void set_flutter_view(const fml::jni::JavaObjectWeakGlobalRef& flutter_view) { flutter_view_ = flutter_view; + android_surface_->SetFlutterView(flutter_view); } + private: const std::unique_ptr android_surface_; fml::jni::JavaObjectWeakGlobalRef flutter_view_; diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc index 60b1e85950..270bbdf815 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "flutter/shell/platform/android/platform_view_android_jni.h" +#include "flutter/common/settings.h" #include "flutter/fml/platform/android/jni_util.h" #include "flutter/fml/platform/android/jni_weak_ref.h" #include "flutter/fml/platform/android/scoped_java_ref.h" @@ -48,6 +49,17 @@ void FlutterViewUpdateSemantics(JNIEnv* env, FTL_CHECK(env->ExceptionCheck() == JNI_FALSE); } +static jmethodID g_handle_platform_update_software_buffer = nullptr; +void FlutterViewUpdateSoftwareBuffer(JNIEnv* env, + jobject obj, + jobject buffer, + jint width, + jint height) { + env->CallVoidMethod(obj, g_handle_platform_update_software_buffer, buffer, + width, height); + FTL_CHECK(env->ExceptionCheck() == JNI_FALSE); +} + // Called By Java static jlong Attach(JNIEnv* env, jclass clazz, jobject flutterView) { @@ -179,6 +191,10 @@ static void SetSemanticsEnabled(JNIEnv* env, return PLATFORM_VIEW->SetSemanticsEnabled(enabled); } +static jboolean GetIsSoftwareRendering(JNIEnv* env, jobject jcaller) { + return blink::Settings::Get().enable_software_rendering; +} + static void InvokePlatformMessageResponseCallback(JNIEnv* env, jobject jcaller, jlong platform_view, @@ -193,8 +209,8 @@ static void InvokePlatformMessageEmptyResponseCallback(JNIEnv* env, jobject jcaller, jlong platform_view, jint responseId) { - return PLATFORM_VIEW->InvokePlatformMessageEmptyResponseCallback( - env, responseId); + return PLATFORM_VIEW->InvokePlatformMessageEmptyResponseCallback(env, + responseId); } bool PlatformViewAndroid::Register(JNIEnv* env) { @@ -269,7 +285,8 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { { .name = "nativeDispatchEmptyPlatformMessage", .signature = "(JLjava/lang/String;I)V", - .fnPtr = reinterpret_cast(&shell::DispatchEmptyPlatformMessage), + .fnPtr = + reinterpret_cast(&shell::DispatchEmptyPlatformMessage), }, { .name = "nativeDispatchPointerDataPacket", @@ -298,6 +315,11 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { .fnPtr = reinterpret_cast( &shell::InvokePlatformMessageEmptyResponseCallback), }, + { + .name = "nativeGetIsSoftwareRenderingEnabled", + .signature = "()Z", + .fnPtr = reinterpret_cast(&shell::GetIsSoftwareRendering), + }, }; if (env->RegisterNatives(g_flutter_view_class->obj(), methods, @@ -328,6 +350,13 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { return false; } + g_handle_platform_update_software_buffer = + env->GetMethodID(g_flutter_view_class->obj(), "updateSoftwareBuffer", + "(Ljava/nio/ByteBuffer;II)V"); + + if (g_handle_platform_update_software_buffer == nullptr) { + return false; + } return true; } diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_jni.h b/engine/src/flutter/shell/platform/android/platform_view_android_jni.h index 1bdfec3274..a4019a55f6 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_jni.h +++ b/engine/src/flutter/shell/platform/android/platform_view_android_jni.h @@ -27,6 +27,12 @@ void FlutterViewUpdateSemantics(JNIEnv* env, jobject buffer, jobjectArray strings); +void FlutterViewUpdateSoftwareBuffer(JNIEnv* env, + jobject obj, + jobject buffer, + jint width, + jint height); + } // namespace shell #endif // FLUTTER_SHELL_PLATFORM_ANDROID_PLATFORM_VIEW_ANDROID_JNI_H_