mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] libImpeller: Allow fetching OpenGL texture handle. (flutter/engine#55753)
Fixes https://github.com/flutter/flutter/issues/156359 cc @lyceel
This commit is contained in:
parent
b1c6343be2
commit
511ee36f3f
@ -544,7 +544,9 @@ ImpellerTexture ImpellerTextureCreateWithOpenGLTextureHandleNew(
|
||||
return nullptr;
|
||||
}
|
||||
texture->SetCoordinateSystem(TextureCoordinateSystem::kUploadFromHost);
|
||||
return Create<Texture>(std::move(texture)).Leak();
|
||||
return Create<Texture>(impeller::Context::BackendType::kOpenGLES,
|
||||
std::move(texture))
|
||||
.Leak();
|
||||
}
|
||||
|
||||
IMPELLER_EXTERN_C
|
||||
@ -557,6 +559,19 @@ void ImpellerTextureRelease(ImpellerTexture texture) {
|
||||
ObjectBase::SafeRelease(texture);
|
||||
}
|
||||
|
||||
IMPELLER_EXTERN_C
|
||||
uint64_t ImpellerTextureGetOpenGLHandle(ImpellerTexture texture) {
|
||||
auto interop_texture = GetPeer(texture);
|
||||
if (interop_texture->GetBackendType() !=
|
||||
impeller::Context::BackendType::kOpenGLES) {
|
||||
VALIDATION_LOG << "Can only fetch the texture handle of an OpenGL texture.";
|
||||
return 0u;
|
||||
}
|
||||
return TextureGLES::Cast(*interop_texture->GetTexture())
|
||||
.GetGLHandle()
|
||||
.value_or(0u);
|
||||
}
|
||||
|
||||
IMPELLER_EXTERN_C
|
||||
void ImpellerDisplayListRetain(ImpellerDisplayList display_list) {
|
||||
ObjectBase::SafeRetain(display_list);
|
||||
|
||||
@ -493,6 +493,10 @@ void ImpellerTextureRetain(ImpellerTexture IMPELLER_NULLABLE texture);
|
||||
IMPELLER_EXPORT
|
||||
void ImpellerTextureRelease(ImpellerTexture IMPELLER_NULLABLE texture);
|
||||
|
||||
IMPELLER_EXPORT
|
||||
uint64_t ImpellerTextureGetOpenGLHandle(
|
||||
ImpellerTexture IMPELLER_NONNULL texture);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Color Sources
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -165,6 +165,9 @@ TEST_P(InteropPlaygroundTest, CanCreateOpenGLImage) {
|
||||
external_texture //
|
||||
));
|
||||
ASSERT_TRUE(texture);
|
||||
|
||||
ASSERT_EQ(ImpellerTextureGetOpenGLHandle(texture.GetC()), external_texture);
|
||||
|
||||
auto builder =
|
||||
Adopt<DisplayListBuilder>(ImpellerDisplayListBuilderNew(nullptr));
|
||||
ImpellerPoint point = {100, 100};
|
||||
|
||||
@ -15,11 +15,13 @@ Texture::Texture(const Context& context, const TextureDescriptor& descriptor) {
|
||||
if (!texture || !texture->IsValid()) {
|
||||
return;
|
||||
}
|
||||
backend_ = context.GetContext()->GetBackendType();
|
||||
texture_ = std::move(texture);
|
||||
}
|
||||
|
||||
Texture::Texture(std::shared_ptr<impeller::Texture> texture)
|
||||
: texture_(std::move(texture)) {}
|
||||
Texture::Texture(impeller::Context::BackendType backend,
|
||||
std::shared_ptr<impeller::Texture> texture)
|
||||
: backend_(backend), texture_(std::move(texture)) {}
|
||||
|
||||
Texture::~Texture() = default;
|
||||
|
||||
@ -45,4 +47,12 @@ sk_sp<DlImageImpeller> Texture::MakeImage() const {
|
||||
return DlImageImpeller::Make(texture_);
|
||||
}
|
||||
|
||||
impeller::Context::BackendType Texture::GetBackendType() const {
|
||||
return backend_;
|
||||
}
|
||||
|
||||
const std::shared_ptr<impeller::Texture>& Texture::GetTexture() const {
|
||||
return texture_;
|
||||
}
|
||||
|
||||
} // namespace impeller::interop
|
||||
|
||||
@ -18,7 +18,8 @@ class Texture final
|
||||
public:
|
||||
explicit Texture(const Context& context, const TextureDescriptor& descriptor);
|
||||
|
||||
explicit Texture(std::shared_ptr<impeller::Texture> texture);
|
||||
explicit Texture(impeller::Context::BackendType backend,
|
||||
std::shared_ptr<impeller::Texture> texture);
|
||||
|
||||
~Texture() override;
|
||||
|
||||
@ -34,7 +35,13 @@ class Texture final
|
||||
|
||||
sk_sp<DlImageImpeller> MakeImage() const;
|
||||
|
||||
impeller::Context::BackendType GetBackendType() const;
|
||||
|
||||
const std::shared_ptr<impeller::Texture>& GetTexture() const;
|
||||
|
||||
private:
|
||||
impeller::Context::BackendType backend_ =
|
||||
impeller::Context::BackendType::kMetal;
|
||||
std::shared_ptr<impeller::Texture> texture_;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user