7#if defined(__ANDROID__)
8#include <sys/system_properties.h>
27bool ShouldClearContextBetweenFrames() {
28#if defined(__ANDROID__)
29 char sdk_value[PROP_VALUE_MAX];
31 if (__system_property_get(
"ro.build.version.sdk", sdk_value) > 0) {
32 sdk_version = atoi(sdk_value);
34 if (sdk_version == 0 || sdk_version > 29) {
38 auto is_bad_platform = [](
const char*
name) ->
bool {
39 char value[PROP_VALUE_MAX];
40 if (__system_property_get(
name, value) > 0) {
41 std::string_view platform(value);
42 if (platform.starts_with(
"mt6762") || platform.starts_with(
"mt6765") ||
43 platform.starts_with(
"MT6762") || platform.starts_with(
"MT6765")) {
50 return is_bad_platform(
"ro.board.platform") ||
51 is_bad_platform(
"ro.vendor.mediatek.platform");
57class AndroidSwitchableGLContextImpeller :
public SwitchableGLContext {
59 explicit AndroidSwitchableGLContextImpeller(
60 const std::shared_ptr<AndroidContextGLImpeller>& android_context)
61 : android_context_(android_context) {}
63 bool SetCurrent()
override {
return true; }
65 bool RemoveCurrent()
override {
66 if (
auto context = android_context_.lock()) {
67 return context->OnscreenContextClearCurrent();
73 std::weak_ptr<AndroidContextGLImpeller> android_context_;
79 const std::shared_ptr<AndroidContextGLImpeller>& android_context)
80 : android_context_(android_context) {
81 offscreen_surface_ = android_context_->CreateOffscreenSurface();
83 if (!offscreen_surface_) {
84 FML_DLOG(ERROR) <<
"Could not create offscreen surface.";
102 GrDirectContext* gr_context) {
103 auto surface = std::make_unique<GPUSurfaceGLImpeller>(
105 android_context_->GetImpellerContext(),
117 onscreen_surface_.reset();
124 return RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent();
129 if (!offscreen_surface_) {
132 return android_context_->ResourceContextMakeCurrent(offscreen_surface_.get());
137 return android_context_->ResourceContextClearCurrent();
143 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
144 native_window_ = std::move(
window);
145 return RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent();
150 if (!onscreen_surface_ || !onscreen_surface_->IsValid()) {
151 onscreen_surface_ = android_context_->CreateOffscreenSurface();
152 if (!onscreen_surface_) {
153 FML_DLOG(ERROR) <<
"Could not create offscreen surface for snapshot.";
159 if (!android_context_->OnscreenContextMakeCurrent(onscreen_surface_.get())) {
160 FML_DLOG(ERROR) <<
"Could not make snapshot surface current.";
163 return std::make_unique<GPUSurfaceGLImpeller>(
165 android_context_->GetImpellerContext(),
171std::shared_ptr<impeller::Context>
173 return android_context_->GetImpellerContext();
177std::unique_ptr<GLContextResult>
179 bool success = OnGLContextMakeCurrent();
181 return std::make_unique<GLContextDefaultResult>(
false);
183 if (!should_clear_context_between_frames_.has_value()) {
184 should_clear_context_between_frames_ = ShouldClearContextBetweenFrames();
186 if (should_clear_context_between_frames_.value()) {
187 return std::make_unique<GLContextSwitch>(
188 std::make_unique<AndroidSwitchableGLContextImpeller>(android_context_));
190 return std::make_unique<GLContextDefaultResult>(
true);
193bool AndroidSurfaceGLImpeller::OnGLContextMakeCurrent() {
194 if (!onscreen_surface_) {
198 return android_context_->OnscreenContextMakeCurrent(onscreen_surface_.get());
203 if (!onscreen_surface_) {
207 return android_context_->OnscreenContextClearCurrent();
215 info.supports_partial_repaint =
false;
221 const std::optional<DlIRect>& region) {
230 if (!onscreen_surface_) {
233 return onscreen_surface_->Present();
249bool AndroidSurfaceGLImpeller::
250 RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent() {
252 if (!native_window_) {
255 onscreen_surface_.reset();
256 auto onscreen_surface =
257 android_context_->CreateOnscreenSurface(native_window_->handle());
258 if (!onscreen_surface) {
259 FML_DLOG(ERROR) <<
"Could not create onscreen surface.";
262 onscreen_surface_ = std::move(onscreen_surface);
263 return OnGLContextMakeCurrent();
SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const override
bool ResourceContextMakeCurrent() override
bool ResourceContextClearCurrent() override
void TeardownOnScreenContext() override
bool SetNativeWindow(fml::RefPtr< AndroidNativeWindow > window, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade) override
sk_sp< const GrGLInterface > GetGLInterface() const override
bool GLContextClearCurrent() override
bool GLContextPresent(const GLPresentInfo &present_info) override
AndroidSurfaceGLImpeller(const std::shared_ptr< AndroidContextGLImpeller > &android_context)
void GLContextSetDamageRegion(const std::optional< DlIRect > ®ion) override
~AndroidSurfaceGLImpeller() override
GLFBOInfo GLContextFBO(GLFrameInfo frame_info) const override
bool IsValid() const override
std::shared_ptr< impeller::Context > GetImpellerContext() override
std::unique_ptr< GLContextResult > GLContextMakeCurrent() override
std::unique_ptr< Surface > CreateSnapshotSurface() override
std::unique_ptr< Surface > CreateGPUSurface(GrDirectContext *gr_context) override
bool OnScreenSurfaceResize(const DlISize &size) override
#define FML_DLOG(severity)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library name
std::shared_ptr< ContextGLES > context