Flutter Engine
 
Loading...
Searching...
No Matches
image_external_texture_gl_skia.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 "flutter/third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
8#include "flutter/third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
9
10namespace flutter {
11
13 const std::shared_ptr<AndroidContextGLSkia>& context,
14 int64_t id,
15 const fml::jni::ScopedJavaGlobalRef<jobject>& image_texture_entry,
16 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade,
18 : ImageExternalTextureGL(id, image_texture_entry, jni_facade, lifecycle) {}
19
20void ImageExternalTextureGLSkia::Attach(PaintContext& context) {
22 // After this call state_ will be AttachmentState::kAttached and egl_image_
23 // will have been created if we still have an Image associated with us.
25 }
26}
27
28void ImageExternalTextureGLSkia::Detach() {
30}
31
32void ImageExternalTextureGLSkia::BindImageToTexture(
34 GLuint tex) {
35 if (!image.is_valid() || tex == 0) {
36 return;
37 }
38 glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
39 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
40 static_cast<GLeglImageOES>(image.get().image));
41}
42
43sk_sp<flutter::DlImage> ImageExternalTextureGLSkia::CreateDlImage(
44 PaintContext& context,
45 const SkRect& bounds,
46 std::optional<HardwareBufferKey> id,
47 impeller::UniqueEGLImageKHR&& egl_image) {
48 GLuint texture_name;
49 glGenTextures(1, &texture_name);
50 auto gl_texture = impeller::GLTexture{texture_name};
51 impeller::UniqueGLTexture unique_texture;
52 unique_texture.reset(gl_texture);
53
54 BindImageToTexture(egl_image, unique_texture.get().texture_name);
55 GrGLTextureInfo textureInfo = {
56 GL_TEXTURE_EXTERNAL_OES, unique_texture.get().texture_name, GL_RGBA8_OES};
57 auto backendTexture =
58 GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo);
59
60 gl_entries_[id.value_or(0)] = GlEntry{.egl_image = std::move(egl_image),
61 .texture = std::move(unique_texture)};
62 return DlImage::Make(SkImages::BorrowTextureFrom(
63 context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin,
64 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr));
65}
66
67} // namespace flutter
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
std::unordered_map< HardwareBufferKey, GlEntry > gl_entries_
void Attach(PaintContext &context) override
ImageExternalTextureGLSkia(const std::shared_ptr< AndroidContextGLSkia > &context, int64_t id, const fml::jni::ScopedJavaGlobalRef< jobject > &image_textury_entry, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade, ImageExternalTexture::ImageLifecycle lifecycle)
ImageLifecycle
Whether the last image should be reset when the context is destroyed.
void reset(const T &value=Traits::InvalidValue())
const T & get() const
FlutterVulkanImage * image
FlutterVulkanImageHandle image
Definition embedder.h:931
const uintptr_t id