Flutter Engine
The 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
5#include "flutter/shell/platform/android/image_external_texture.h"
6
7#include <android/hardware_buffer_jni.h>
8#include <android/sensor.h>
9
10#include "flutter/fml/platform/android/jni_util.h"
11#include "flutter/impeller/toolkit/android/proc_table.h"
12#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
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 : Texture(id),
21 image_texture_entry_(image_texture_entry),
22 jni_facade_(jni_facade) {}
23
24// Implementing flutter::Texture.
26 const SkRect& bounds,
27 bool freeze,
28 const DlImageSampling sampling) {
30 return;
31 }
32 Attach(context);
33 const bool should_process_frame = !freeze;
34 if (should_process_frame) {
35 ProcessFrame(context, bounds);
36 }
37 if (dl_image_) {
38 context.canvas->DrawImageRect(
39 dl_image_, // image
40 SkRect::Make(dl_image_->bounds()), // source rect
41 bounds, // destination rect
42 sampling, // sampling
43 context.paint, // paint
45 );
46 } else {
47 FML_LOG(INFO) << "No DlImage available for ImageExternalTexture to paint.";
48 }
49}
50
51// Implementing flutter::Texture.
55
56// Implementing flutter::Texture.
58
59// Implementing flutter::ContextListener.
63
64// Implementing flutter::ContextListener.
73
76 FML_CHECK(env != nullptr);
77
78 // ImageTextureEntry.acquireLatestImage.
79 JavaLocalRef image_java =
80 jni_facade_->ImageProducerTextureEntryAcquireLatestImage(
82 return image_java;
83}
84
86 if (image.obj() == nullptr) {
87 return;
88 }
89 jni_facade_->ImageClose(JavaLocalRef(image));
90}
91
93 const fml::jni::JavaRef<jobject>& hardware_buffer) {
94 if (hardware_buffer.obj() == nullptr) {
95 return;
96 }
97 jni_facade_->HardwareBufferClose(JavaLocalRef(hardware_buffer));
98}
99
102 if (image.obj() == nullptr) {
103 return JavaLocalRef();
104 }
105 // Image.getHardwareBuffer.
106 return jni_facade_->ImageGetHardwareBuffer(JavaLocalRef(image));
107}
108
110 const fml::jni::JavaRef<jobject>& hardware_buffer) {
112 FML_CHECK(env != nullptr);
113 const auto& proc =
114 impeller::android::GetProcTable().AHardwareBuffer_fromHardwareBuffer;
115 return proc ? proc(env, hardware_buffer.obj()) : nullptr;
116}
117
118} // namespace flutter
struct AHardwareBuffer AHardwareBuffer
virtual void DrawImageRect(const sk_sp< DlImage > &image, const SkRect &src, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast)=0
SkIRect bounds() const
Definition dl_image.cc:31
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
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)
void Paint(PaintContext &context, const SkRect &bounds, bool freeze, const DlImageSampling sampling) override
fml::jni::ScopedJavaGlobalRef< jobject > image_texture_entry_
void Clear()
Remove all entires from the image cache.
Definition image_lru.cc:60
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
sk_sp< SkImage > image
Definition examples.cpp:29
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
Definition __init__.py:1
std::nullptr_t JavaLocalRef
JNIEnv * AttachCurrentThread()
Definition jni_util.cc:34
const ProcTable & GetProcTable()
Definition proc_table.cc:12
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
const uintptr_t id