Flutter Engine
 
Loading...
Searching...
No Matches
image_external_texture.cc
Go to the documentation of this file.
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
6
7#include <android/hardware_buffer_jni.h>
8#include <android/sensor.h>
9
13
14namespace flutter {
15
17 int64_t id,
18 const fml::jni::ScopedJavaGlobalRef<jobject>& image_texture_entry,
19 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
20 ImageLifecycle lifecycle)
21 : Texture(id),
22 image_texture_entry_(image_texture_entry),
23 jni_facade_(jni_facade),
24 texture_lifecycle_(lifecycle) {}
25
27
28// Implementing flutter::Texture.
29void ImageExternalTexture::Paint(PaintContext& context,
30 const DlRect& bounds,
31 bool freeze,
32 const DlImageSampling sampling) {
34 return;
35 }
36 Attach(context);
37 const bool should_process_frame = !freeze;
38 if (should_process_frame) {
39 ProcessFrame(context, ToSkRect(bounds));
40 }
41 if (dl_image_) {
42 context.canvas->DrawImageRect(
43 dl_image_, // image
44 DlRect::Make(dl_image_->GetBounds()), // source rect
45 bounds, // destination rect
46 sampling, // sampling
47 context.paint, // paint
49 );
50 } else {
51 FML_LOG(INFO) << "No DlImage available for ImageExternalTexture to paint.";
52 }
53}
54
55// Implementing flutter::Texture.
56void ImageExternalTexture::MarkNewFrameAvailable() {
57 // NOOP.
58}
59
60// Implementing flutter::Texture.
61void ImageExternalTexture::OnTextureUnregistered() {}
62
63// Implementing flutter::ContextListener.
64void ImageExternalTexture::OnGrContextCreated() {
66}
67
68// Implementing flutter::ContextListener.
69void ImageExternalTexture::OnGrContextDestroyed() {
71 switch (texture_lifecycle_) {
73 dl_image_.reset();
75 } break;
77 // Intentionally do nothing.
78 ///
79 // If we reset the image, we are not able to re-acquire it, but the
80 // producer of the image will not know to reproduce it, resulting in a
81 // blank image. See https://github.com/flutter/flutter/issues/163561.
82 break;
83 }
84 Detach();
85 }
87}
88
90 JNIEnv* env = fml::jni::AttachCurrentThread();
91 FML_CHECK(env != nullptr);
92
93 // ImageTextureEntry.acquireLatestImage.
94 JavaLocalRef image_java =
95 jni_facade_->ImageProducerTextureEntryAcquireLatestImage(
97 return image_java;
98}
99
101 if (image.obj() == nullptr) {
102 return;
103 }
104 jni_facade_->ImageClose(JavaLocalRef(image));
105}
106
108 const fml::jni::JavaRef<jobject>& hardware_buffer) {
109 if (hardware_buffer.obj() == nullptr) {
110 return;
111 }
112 jni_facade_->HardwareBufferClose(JavaLocalRef(hardware_buffer));
113}
114
117 if (image.obj() == nullptr) {
118 return JavaLocalRef();
119 }
120 // Image.getHardwareBuffer.
121 return jni_facade_->ImageGetHardwareBuffer(JavaLocalRef(image));
122}
123
125 const fml::jni::JavaRef<jobject>& hardware_buffer) {
126 JNIEnv* env = fml::jni::AttachCurrentThread();
127 FML_CHECK(env != nullptr);
128 const auto& proc =
129 impeller::android::GetProcTable().AHardwareBuffer_fromHardwareBuffer;
130 return proc ? proc(env, hardware_buffer.obj()) : nullptr;
131}
132
133} // namespace flutter
virtual void DrawImageRect(const sk_sp< DlImage > &image, const DlRect &src, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast)=0
AHardwareBuffer * AHardwareBufferFor(const fml::jni::JavaRef< jobject > &hardware_buffer)
JavaLocalRef HardwareBufferFor(const fml::jni::JavaRef< jobject > &image)
virtual void ProcessFrame(PaintContext &context, const SkRect &bounds)=0
Subclasses override this method to bind the latest representation of the hardware buffer wrapped by t...
void CloseHardwareBuffer(const fml::jni::JavaRef< jobject > &hardware_buffer)
sk_sp< flutter::DlImage > dl_image_
void CloseImage(const fml::jni::JavaRef< jobject > &image)
virtual void Attach(PaintContext &context)=0
std::shared_ptr< PlatformViewAndroidJNI > jni_facade_
ImageExternalTexture(int64_t id, const fml::jni::ScopedJavaGlobalRef< jobject > &image_texture_entry, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, ImageLifecycle lifecycle)
fml::jni::ScopedJavaGlobalRef< jobject > image_texture_entry_
ImageLifecycle
Whether the last image should be reset when the context is destroyed.
void Clear()
Remove all entires from the image cache.
Definition image_lru.cc:60
FlutterVulkanImage * image
#define FML_LOG(severity)
Definition logging.h:101
#define FML_CHECK(condition)
Definition logging.h:104
std::nullptr_t JavaLocalRef
const SkRect & ToSkRect(const DlRect &rect)
JNIEnv * AttachCurrentThread()
Definition jni_util.cc:34
const ProcTable & GetProcTable()
Definition proc_table.cc:12
DlCanvas * canvas
Definition layer.h:92
static constexpr std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make(const TRect< U > &rect)
Definition rect.h:157
const uintptr_t id