Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Flutter External Texture Based On Share Texture Underlying Share Con… #11276

Closed

Conversation

kaisa695275735
Copy link
Contributor

Currently, external textures are very differently on iOS (CoreVideo) and Android (GL_OES_EGL_image_external).
In China, Portrait beauty effects are basically a must-have for a camera tool. We process our video frame on the GPU to generate a texture to be rendered. If flutter needs to display this texture, it requires a GPU->CPU->GPU process, wasting performance.
So we need to process the CoreVideo pixel buffer using OpenGL and give Flutter that texture directly instead of the pixel buffer
So we added an interface to Get Flutter GLContext on our Flutter branch. Based on this modification, we implemented the Flutter plugins such as Album, Video Capture, Video Editor.
And those plugins has been used by hundreds of millions of users on the Xianyu APP to verify its effectiveness。
We hope we can merge this change back to the flutter master so that more develop can use our plugins to develop video App。

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@kaisa695275735
Copy link
Contributor Author

@googlebot
I signed it!

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments. This really badly needs a test of some sort - and ideally a benchmark. You could look at the tests in testing/scenarios_app and add some similar ones to what is there on the iOS side. The android side needs some work for testing unfortunately.

@kaisa695275735
Copy link
Contributor Author

kaisa695275735 commented Aug 28, 2019

@dnfield hello, we got an error when running format_and_dart_text:
License script got different results than expected for out/license_script_output/licenses_flutter.
and we tried to resolve it using the way
https://github.com/flutter/engine/tree/master/tools/licenses mentioned.

but we got an error on last step:
image

@dnfield
Copy link
Contributor

dnfield commented Aug 28, 2019

The license tool can't handle random temp files, .DS_Store in particular makes it nutty. Just delete the file.

You very likely just need to add the new files you created to the licneses_golden - there's an alphabetical list in there that you can just pull from and add to manually (just look for android_context_gl.h and add yours alphabetically next to it).

@dnfield
Copy link
Contributor

dnfield commented Aug 28, 2019

One other issue with this - it looks like @ lujunchen has not signed a CLA, but commits in here appear to have been authored by that user.

@kaisa695275735
Copy link
Contributor Author

kaisa695275735 commented Aug 28, 2019

One other issue with this - it looks like @ lujunchen has not signed a CLA, but commits in here appear to have been authored by that user.

YES, my mistake.
I use my company's username lujunchen(lujun.clj@alibaba-inc.com) on my commit.
So should i revert my changes and commit them again use my github account kaisa695275735(lujunchen.hit@gmail.com)?

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a few topical comments around the code. There isn't a working example of FlutterShareTexture (test or otherwise) and there is no docstrings for it, so it's a bit hard to reason about. Could you please add a test or a dependent PR that uses your change?

Generally speaking, the problem you are trying to address is a good one and something we should address. It's going to take a bit more polish on the PR to get a better understanding if we are attacking it the correct way.

#include "FlutterMacros.h"

NS_ASSUME_NONNULL_BEGIN

FLUTTER_EXPORT
@protocol FlutterShareTexture <NSObject>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add interface docstring.

#include "FlutterMacros.h"

NS_ASSUME_NONNULL_BEGIN

FLUTTER_EXPORT
@protocol FlutterShareTexture <NSObject>
/*
*copy OpenGL Texture directly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix docstring formatting and use complete English sentences.


namespace flutter {

class IOSExternalTextureShareContext : public flutter::Texture {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add class docstring.

IOSExternalTextureShareContext::IOSExternalTextureShareContext(
int64_t textureId,
NSObject<FlutterShareTexture>* externalTexture)
: Texture(textureId), external_texture_(externalTexture) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this have a retain on the external_texture_?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES, their are other issues about the crash caused by external texture.
#10326
Just as metioned by @chinmaygarde , having a retain here is not thread safe.
So we recommend users avoiding to release the external_texture_ object too early.

textureInfo.fTarget = GL_TEXTURE_2D;

GrBackendTexture backendTexture(bounds.width(), bounds.height(), GrMipMapped::kNo, textureInfo);
printf("paint test back\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray print statement.


EAGLSharegroup* PlatformViewIOS::GetGLShareGroup() {
if (ios_surface_.get() == NULL)
return NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return nullptr;

Add brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening a new pr is fine

OK , i've created a new pr, #11819 .
@gaaclarke @dnfield @chinmaygarde @gw280

@kaisa695275735
Copy link
Contributor Author

I've added a few topical comments around the code. There isn't a working example of FlutterShareTexture (test or otherwise) and there is no docstrings for it, so it's a bit hard to reason about. Could you please add a test or a dependent PR that uses your change?

Generally speaking, the problem you are trying to address is a good one and something we should address. It's going to take a bit more polish on the PR to get a better understanding if we are attacking it the correct way.

Yes, we are looking at the tests in testing/scenarios_app and trying to add some similar ones.

@kaisa695275735 kaisa695275735 deleted the external_texture_new branch August 30, 2019 02:45
@kaisa695275735
Copy link
Contributor Author

I've added a few topical comments around the code. There isn't a working example of FlutterShareTexture (test or otherwise) and there is no docstrings for it, so it's a bit hard to reason about. Could you please add a test or a dependent PR that uses your change?

Generally speaking, the problem you are trying to address is a good one and something we should address. It's going to take a bit more polish on the PR to get a better understanding if we are attacking it the correct way.

I'm very sorry that I accidentally deleted the external_texture_new branch, and result in the PR closed.
I don't know how can I reopen it, or should I commit a new PR ?

@dnfield
Copy link
Contributor

dnfield commented Aug 30, 2019

Opening a new pr is fine

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants