Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2317,8 +2317,6 @@ ORIGIN: ../../../flutter/shell/platform/android/android_egl_surface.h + ../../..
ORIGIN: ../../../flutter/shell/platform/android/android_environment_gl.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_environment_gl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_exports.lst + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_external_texture_gl.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_external_texture_gl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_image_generator.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_image_generator.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_shell_holder.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -2505,6 +2503,10 @@ ORIGIN: ../../../flutter/shell/platform/android/surface/android_surface_mock.cc
ORIGIN: ../../../flutter/shell/platform/android/surface/android_surface_mock.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/surface/snapshot_surface_producer.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/surface/snapshot_surface_producer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/vsync_waiter_android.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/vsync_waiter_android.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/common/accessibility_bridge.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -5043,8 +5045,6 @@ FILE: ../../../flutter/shell/platform/android/android_egl_surface.h
FILE: ../../../flutter/shell/platform/android/android_environment_gl.cc
FILE: ../../../flutter/shell/platform/android/android_environment_gl.h
FILE: ../../../flutter/shell/platform/android/android_exports.lst
FILE: ../../../flutter/shell/platform/android/android_external_texture_gl.cc
FILE: ../../../flutter/shell/platform/android/android_external_texture_gl.h
FILE: ../../../flutter/shell/platform/android/android_image_generator.cc
FILE: ../../../flutter/shell/platform/android/android_image_generator.h
FILE: ../../../flutter/shell/platform/android/android_shell_holder.cc
Expand Down Expand Up @@ -5243,6 +5243,10 @@ FILE: ../../../flutter/shell/platform/android/surface/android_surface_mock.cc
FILE: ../../../flutter/shell/platform/android/surface/android_surface_mock.h
FILE: ../../../flutter/shell/platform/android/surface/snapshot_surface_producer.cc
FILE: ../../../flutter/shell/platform/android/surface/snapshot_surface_producer.h
FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture.cc
FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture.h
FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl.cc
FILE: ../../../flutter/shell/platform/android/surface_texture_external_texture_gl.h
FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.cc
FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.h
FILE: ../../../flutter/shell/platform/common/accessibility_bridge.cc
Expand Down
6 changes: 4 additions & 2 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ source_set("flutter_shell_native_src") {
"android_egl_surface.h",
"android_environment_gl.cc",
"android_environment_gl.h",
"android_external_texture_gl.cc",
"android_external_texture_gl.h",
"android_shell_holder.cc",
"android_shell_holder.h",
"android_surface_gl_impeller.cc",
Expand Down Expand Up @@ -115,6 +113,10 @@ source_set("flutter_shell_native_src") {
"platform_view_android.h",
"platform_view_android_jni_impl.cc",
"platform_view_android_jni_impl.h",
"surface_texture_external_texture.cc",
"surface_texture_external_texture.h",
"surface_texture_external_texture_gl.cc",
"surface_texture_external_texture_gl.h",
"vsync_waiter_android.cc",
"vsync_waiter_android.h",
]
Expand Down
139 changes: 0 additions & 139 deletions shell/platform/android/android_external_texture_gl.cc

This file was deleted.

2 changes: 2 additions & 0 deletions shell/platform/android/hardware_buffer_external_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace flutter {

// External texture peered to a sequence of android.hardware.HardwareBuffers.
//
class HardwareBufferExternalTexture : public flutter::Texture {
public:
explicit HardwareBufferExternalTexture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void attachToGLContext(int texName) {
// This causes the texture to be in an uninitialized state.
// This should *not* be an issue once platform views are always rendered as TextureLayers
// since thread merging will be always disabled on Android.
// For more see: AndroidExternalTextureGL::OnGrContextCreated in
// android_external_texture_gl.cc, and
// For more see: SurfaceTextureExternalTextureGL::OnGrContextCreated in
// surface_texture_external_texture_gl.cc, and
// https://github.com/flutter/flutter/issues/98155
if (attached) {
surfaceTexture.detachFromGLContext();
Expand Down
22 changes: 16 additions & 6 deletions shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#include "flutter/shell/platform/android/android_context_gl_impeller.h"
#include "flutter/shell/platform/android/android_context_gl_skia.h"
#include "flutter/shell/platform/android/android_context_vulkan_impeller.h"
#include "flutter/shell/platform/android/android_external_texture_gl.h"
#include "flutter/shell/platform/android/android_surface_gl_impeller.h"
#include "flutter/shell/platform/android/android_surface_gl_skia.h"
#include "flutter/shell/platform/android/android_surface_software.h"
#include "flutter/shell/platform/android/hardware_buffer_external_texture_gl.h"
#include "flutter/shell/platform/android/hardware_buffer_external_texture_vk.h"
#include "flutter/shell/platform/android/surface_texture_external_texture_gl.h"
#if IMPELLER_ENABLE_VULKAN // b/258506856 for why this is behind an if
#include "flutter/shell/platform/android/android_surface_vulkan_impeller.h"
#include "flutter/shell/platform/android/hardware_buffer_external_texture_vk.h"
#endif
#include "flutter/shell/platform/android/context/android_context.h"
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
Expand Down Expand Up @@ -301,18 +301,28 @@ void PlatformViewAndroid::RegisterExternalTexture(
int64_t texture_id,
const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture) {
if (android_context_->RenderingApi() == AndroidRenderingAPI::kOpenGLES) {
RegisterTexture(std::make_shared<AndroidExternalTextureGL>(
texture_id, surface_texture, jni_facade_));
if (android_context_->GetImpellerContext()) {
// Impeller GLES.
RegisterTexture(std::make_shared<SurfaceTextureExternalTextureImpellerGL>(
std::static_pointer_cast<impeller::ContextGLES>(
android_context_->GetImpellerContext()),
texture_id, surface_texture, jni_facade_));
} else {
// Legacy GL.
RegisterTexture(std::make_shared<SurfaceTextureExternalTextureGL>(
texture_id, surface_texture, jni_facade_));
}
} else {
FML_LOG(INFO) << "Attempted to use a GL texture in a non GL context.";
FML_LOG(INFO) << "Attempted to use a SurfaceTextureExternalTexture with an "
"unsupported rendering API.";
}
}

void PlatformViewAndroid::RegisterImageTexture(
int64_t texture_id,
const fml::jni::ScopedJavaGlobalRef<jobject>& image_texture_entry) {
if (android_context_->RenderingApi() == AndroidRenderingAPI::kOpenGLES) {
if (android_context_->GetImpellerContext() != nullptr) {
if (android_context_->GetImpellerContext()) {
// Impeller GLES.
RegisterTexture(std::make_shared<HardwareBufferExternalTextureImpellerGL>(
std::static_pointer_cast<impeller::ContextGLES>(
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
#include "flutter/lib/ui/plugins/callback_cache.h"
#include "flutter/runtime/dart_service_isolate.h"
#include "flutter/shell/common/run_configuration.h"
#include "flutter/shell/platform/android/android_external_texture_gl.h"
#include "flutter/shell/platform/android/android_shell_holder.h"
#include "flutter/shell/platform/android/apk_asset_provider.h"
#include "flutter/shell/platform/android/flutter_main.h"
#include "flutter/shell/platform/android/hardware_buffer_external_texture_gl.h"
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
#include "flutter/shell/platform/android/platform_view_android.h"
#include "flutter/shell/platform/android/surface_texture_external_texture_gl.h"

#define ANDROID_SHELL_HOLDER \
(reinterpret_cast<AndroidShellHolder*>(shell_holder))
Expand Down
114 changes: 114 additions & 0 deletions shell/platform/android/surface_texture_external_texture.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// 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 "flutter/shell/platform/android/surface_texture_external_texture.h"

#include <GLES/glext.h>

#include <utility>

#include "flutter/display_list/effects/dl_color_source.h"
#include "third_party/skia/include/core/SkAlphaType.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkColorType.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
#include "third_party/skia/include/gpu/gl/GrGLTypes.h"

namespace flutter {

SurfaceTextureExternalTexture::SurfaceTextureExternalTexture(
int64_t id,
const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade)
: Texture(id),
jni_facade_(std::move(jni_facade)),
surface_texture_(surface_texture),
transform_(SkMatrix::I()) {}

SurfaceTextureExternalTexture::~SurfaceTextureExternalTexture() {}

void SurfaceTextureExternalTexture::OnGrContextCreated() {
state_ = AttachmentState::kUninitialized;
}

void SurfaceTextureExternalTexture::MarkNewFrameAvailable() {
new_frame_ready_ = true;
}

void SurfaceTextureExternalTexture::Paint(PaintContext& context,
const SkRect& bounds,
bool freeze,
const DlImageSampling sampling) {
if (state_ == AttachmentState::kDetached) {
return;
}
const bool should_process_frame =
(!freeze && new_frame_ready_) || dl_image_ == nullptr;
if (should_process_frame) {
ProcessFrame(context, bounds);
new_frame_ready_ = false;
}
FML_CHECK(state_ == AttachmentState::kAttached);

if (dl_image_) {
context.canvas->DrawImageRect(
dl_image_, // image
SkRect::Make(dl_image_->bounds()), // source rect
bounds, // destination rect
sampling, // sampling
context.paint, // paint
flutter::DlCanvas::SrcRectConstraint::kStrict // enforce edges
);
} else {
FML_LOG(ERROR) << "No DlImage available.";
}
}

void SurfaceTextureExternalTexture::OnGrContextDestroyed() {
if (state_ == AttachmentState::kAttached) {
Detach();
}
state_ = AttachmentState::kDetached;
}

void SurfaceTextureExternalTexture::OnTextureUnregistered() {}

void SurfaceTextureExternalTexture::Detach() {
jni_facade_->SurfaceTextureDetachFromGLContext(
fml::jni::ScopedJavaLocalRef<jobject>(surface_texture_));
dl_image_.reset();
}

void SurfaceTextureExternalTexture::Attach(int gl_tex_id) {
jni_facade_->SurfaceTextureAttachToGLContext(
fml::jni::ScopedJavaLocalRef<jobject>(surface_texture_), gl_tex_id);
state_ = AttachmentState::kAttached;
}

void SurfaceTextureExternalTexture::Update() {
jni_facade_->SurfaceTextureUpdateTexImage(
fml::jni::ScopedJavaLocalRef<jobject>(surface_texture_));

jni_facade_->SurfaceTextureGetTransformMatrix(
fml::jni::ScopedJavaLocalRef<jobject>(surface_texture_), transform_);

// Android's SurfaceTexture transform matrix works on texture coordinate
// lookups in the range 0.0-1.0, while Skia's Shader transform matrix works on
// the image itself, as if it were inscribed inside a clip rect.
// An Android transform that scales lookup by 0.5 (displaying 50% of the
// texture) is the same as a Skia transform by 2.0 (scaling 50% of the image
// outside of the virtual "clip rect"), so we invert the incoming matrix.
SkMatrix inverted;
if (!transform_.invert(&inverted)) {
FML_LOG(FATAL)
<< "Invalid (not invertable) SurfaceTexture transformation matrix";
}
transform_ = inverted;
}

} // namespace flutter
Loading