Thanks to visit codestin.com
Credit goes to github.com

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

Fix argument type in FlutterDesktopEngineGetTextureRegistrar #27522

Closed
wants to merge 4 commits into from

Conversation

knopp
Copy link
Member

@knopp knopp commented Jul 18, 2021

Fixes flutter/flutter#86617

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@stuartmorgan-g
Copy link
Contributor

Why are the unit tests compiling? It seems like this should have been caught immediately by the compiler.

@knopp
Copy link
Member Author

knopp commented Jul 18, 2021

They are both opaque pointers.

@stuartmorgan-g
Copy link
Contributor

Opaque pointers should be typesafe though; that's the whole point of the struct pointer construct over just making them typedefs for void*. Are they mis-declared somehow?

@knopp
Copy link
Member Author

knopp commented Jul 18, 2021

I checked, they are declared correctly. But I don't think that FlutterDesktopEngineGetTextureRegistrar is called anywhere in the tests, is it? It builds correctly because FlutterDesktopEngineGetTextureRegistrar is extern "C" so there's no mangling, it's just a pointer. As far as I can tell it's not called from anywhere and it's not exposed in the client wrapper, which is probably why the compiler doesn't complain.

@knopp
Copy link
Member Author

knopp commented Jul 18, 2021

Actually, I was wrong. Because the extern "C" declaration has wrong type, the implementation inside flutter_windows.cc is not extern "C" anymore, so it is mangled. I guess nobody has tried calling it yet.

@stuartmorgan-g
Copy link
Contributor

As far as I can tell it's not called from anywhere and it's not exposed in the client wrapper

Looks like I missed that this part wasn't tested when approving the PR, and I forgot that it wasn't exposed there. We should include testing in this PR, either directly of the C API, or by exposing it, so there's code compiled against it that would have caught this.

@knopp
Copy link
Member Author

knopp commented Jul 18, 2021

@stuartmorgan, I added FlutterEngine::GetTextureRegistrar so the compiler can now check the type.

@@ -62,6 +62,9 @@ class FlutterEngine : public PluginRegistry {
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin(
const std::string& plugin_name) override;

// Returns the texture registrar for this engine.
FlutterDesktopTextureRegistrarRef GetTextureRegistrar();
Copy link
Contributor

Choose a reason for hiding this comment

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

We should expose a wrapper, not the raw type. The only reason the plugin registrar is the raw type is that the use case for it is to pass to a plugin registration function, which is a C API (as it's a dll interface). This should be like the messenger or the view, where the wrapper vends a wrapper.

Copy link
Member Author

@knopp knopp Jul 18, 2021

Choose a reason for hiding this comment

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

I don't currently have time to write a wrapper for FlutterDesktopTextureRegistrar, nor do I think that should that be in scope of this PR. I can remove this from FlutterEngine and just call FlutterDesktopEngineGetTextureRegistrar somewhere, but I'm really not sure what the proper place for that would be. Any suggestion is appreciated.

Copy link
Contributor

Choose a reason for hiding this comment

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

A direct test would a test written against the C API directly. It doesn't look like there are any at the moment, but I don't remember if there's a reason doing that is problematic, or it was just never backfilled. It may just need some build plumbing to make it possible to launch the engine from a test (IIRC that was done for macOS, but I'm not sure if Linux and Windows have it.)

@cbracken I know you have a plan around doing some more testing of the desktop embeddings; is that part of that plan?

Copy link
Member Author

@knopp knopp Jul 19, 2021

Choose a reason for hiding this comment

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

The C api is currently tested indirectly through the client wrapper. Since there's no wrapper for texture registrar yet I added a test that just calls the C API. (TEST(FlutterEngineTest, GetTextureRegistrar))

Copy link
Member

Choose a reason for hiding this comment

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

@cbracken I know you have a plan around doing some more testing of the desktop embeddings; is that part of that plan?

That is indeed part of the plan. The person working on it has put that work on hold for the moment. You're correct that some progress was made on the macOS side of things. Filed flutter/flutter#87299 for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cbracken, is that something that should block this PR? It just fixes the method signature (otherwise it can't be called as the underlying implementation is not exported)

@knopp knopp force-pushed the win_engine_argument branch from efc8608 to bd5237c Compare July 19, 2021 23:27
@chinmaygarde
Copy link
Member

This should be good for another review pass.

@chinmaygarde
Copy link
Member

cc @stuartmorgan @cbracken Thoughts on another review?

FlutterDesktopEngineProperties properties;
memset(&properties, 0, sizeof(FlutterDesktopEngineProperties));
auto engine = FlutterDesktopEngineCreate(&properties);
auto texture_registrar = FlutterDesktopEngineGetTextureRegistrar(engine);
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't make sense for this test to be in client_wrapper. The purpose of the unit tests for client_wrapper are specifically to unit test the client_wrapper code, and this isn't doing that. We shouldn't put tests in places they don't belong as a workaround for not yet having the harness we should have for testing the C API surface.

Can't you write this test in the right place (a new unit test target that's part of the C API layer) by using the embedding API mock support that I added a while back to make it not need complex setup (stubbing out the underlying engine calls that would try to spin everything up)?

@chinmaygarde
Copy link
Member

@knopp Any updates to Stuart's comments?

@knopp
Copy link
Member Author

knopp commented Aug 26, 2021

@knopp Any updates to Stuart's comments?

Sorry, not yet, we talked about this on discord but I haven't had time yet to update the PR.

@chinmaygarde chinmaygarde added the Work in progress (WIP) Not ready (yet) for review! label Sep 9, 2021
@CaseyHillers CaseyHillers changed the base branch from master to main November 15, 2021 18:16
@godofredoc godofredoc changed the base branch from master to main November 24, 2021 07:25
@flutter-dashboard
Copy link

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

@Hixie
Copy link
Contributor

Hixie commented Mar 15, 2022

@knopp should we close this PR for now?

@knopp
Copy link
Member Author

knopp commented Mar 16, 2022

@Hixie, I currently don't have time to write the unit tests that @stuartmorgan requested, but the declaration is still wrong (and the symbol not exported). This is a trivial fix and it seems weird to block this on account of a missing unit test (which other parts of the API don't have either).

@Hixie
Copy link
Contributor

Hixie commented Mar 18, 2022

We shouldn't have landed the other parts of the API that don't have tests either.

@stuartmorgan-g
Copy link
Contributor

stuartmorgan-g commented Mar 18, 2022

We shouldn't have landed the other parts of the API that don't have tests either.

Agreed, as noted above

To add a bit more context about the history of testing in the Windows embedding: originally the desktop embeddings had ~no testing (for historical reasons; they were not originally part of Flutter). As they matured, we started filling in testing—although I certainly admit that I did not prioritize that as much as I should have. For Windows in particular, we reached a point where where:

  • As I refactored the prototype (originally pretty much one big file) into maintainable classes, I made sure those had unit test coverage
    • The goal was to have what was left in the C API layer implementation be a very thin wrapper around those implementation classes.
  • As we added new C++ wrappers, we ensured that they had unit test coverage.

That left a testing gap for the thin C layer, but because it was a thin layer, there wasn't a lot to test there, so the priority of setting up testing coverage of that specific was relatively low. (Especially since in almost all cases we did have compilation coverage that would have caught this issue, since we usually added the wrapper as part of the same PR that added the C API).

This PR demonstrates the problem with having no direct testing of that layer, and so—as with any other bug that we find that indicates a testing gap—we need to close that gap as part of the fix.

@chinmaygarde
Copy link
Member

Is any progress on this PR likely? Can we close it?

@stuartmorgan-g
Copy link
Contributor

@cbracken Could someone on the desktop team add the test here? It's a testing gap we already wanted to close, and this API is clearly broken, so it seems worth some investment on wiring up the test.

@cbracken
Copy link
Member

cbracken commented May 5, 2022

I'll take a look at adding the test. Agreed the change itself looks absolutely fine.

@cbracken
Copy link
Member

Picking this up now.

cbracken added a commit to cbracken/flutter_engine that referenced this pull request Aug 2, 2022
FlutterDesktopEngineGetTextureRegistrar is used to get the texture
registrar associated with an engine object and therefore should take a
FlutterDesktopEngineRef parameter.

This also adds an initial unit test for the public Windows C API used to
implement the C++ client wrapper. In order to fully test this API, we'll
want to support test fixtures similar to what we do in the embedder API
tests.

See: https://github.com/flutter/engine/blob/4cc5ad0b7e3c1fe9d19d2621559786ceac9302b7/shell/platform/embedder/BUILD.gn#L187-L319

This was initially identified and fixed by @knopp in:
flutter#27522

This patch replaces that one and adds the simplest possible unit test to
get it landed.

Fixes: flutter/flutter#86617
cbracken added a commit to cbracken/flutter_engine that referenced this pull request Aug 2, 2022
FlutterDesktopEngineGetTextureRegistrar is used to get the texture
registrar associated with an engine object and therefore should take a
FlutterDesktopEngineRef parameter.

This bug was initially identified and fixed by @knopp in:
flutter#27522

This patch replaces that one and adds the simplest possible unit test to
get it landed.

This also adds an initial unit test for the public Windows C API used to
implement the C++ client wrapper. In order to fully test this API, we'll
want to support test fixtures similar to what we do in the embedder API
tests. See: flutter/flutter#87299

Fixes: flutter/flutter#86617
cbracken added a commit to cbracken/flutter_engine that referenced this pull request Aug 2, 2022
FlutterDesktopEngineGetTextureRegistrar is used to get the texture
registrar associated with an engine object and therefore should take a
FlutterDesktopEngineRef parameter.

This bug was initially identified and fixed by @knopp in:
flutter#27522

This patch replaces that one and adds the simplest possible unit test to
get it landed.

This also adds an initial unit test for the public Windows C API used to
implement the C++ client wrapper. In order to fully test this API, we'll
want to support test fixtures similar to what we do in the embedder API
tests. See: flutter/flutter#87299

Fixes: flutter/flutter#86617
cbracken added a commit to cbracken/flutter_engine that referenced this pull request Aug 2, 2022
FlutterDesktopEngineGetTextureRegistrar is used to get the texture
registrar associated with an engine object and therefore should take a
FlutterDesktopEngineRef parameter.

This bug was initially identified and fixed by @knopp in:
flutter#27522

This patch replaces that one and adds the simplest possible unit test to
get it landed.

This also adds an initial unit test for the public Windows C API used to
implement the C++ client wrapper. In order to fully test this API, we'll
want to support test fixtures similar to what we do in the embedder API
tests. See: flutter/flutter#87299

Fixes: flutter/flutter#86617
cbracken added a commit that referenced this pull request Aug 3, 2022
FlutterDesktopEngineGetTextureRegistrar is used to get the texture
registrar associated with an engine object and therefore should take a
FlutterDesktopEngineRef parameter.

This bug was initially identified and fixed by @knopp in:
#27522

This patch replaces that one and adds the simplest possible unit test to
get it landed.

This also adds an initial unit test for the public Windows C API used to
implement the C++ client wrapper. In order to fully test this API, we'll
want to support test fixtures similar to what we do in the embedder API
tests. See: flutter/flutter#87299

Fixes: flutter/flutter#86617
@cbracken
Copy link
Member

cbracken commented Aug 3, 2022

Replaced by #27522; sorry for the delay in getting a test written. Was behind a few other things on my list :/

@cbracken cbracken closed this Aug 3, 2022
betrevisan pushed a commit to betrevisan/engine that referenced this pull request Aug 5, 2022
FlutterDesktopEngineGetTextureRegistrar is used to get the texture
registrar associated with an engine object and therefore should take a
FlutterDesktopEngineRef parameter.

This bug was initially identified and fixed by @knopp in:
flutter#27522

This patch replaces that one and adds the simplest possible unit test to
get it landed.

This also adds an initial unit test for the public Windows C API used to
implement the C++ client wrapper. In order to fully test this API, we'll
want to support test fixtures similar to what we do in the embedder API
tests. See: flutter/flutter#87299

Fixes: flutter/flutter#86617
emilyabest pushed a commit to emilyabest/engine that referenced this pull request Aug 12, 2022
FlutterDesktopEngineGetTextureRegistrar is used to get the texture
registrar associated with an engine object and therefore should take a
FlutterDesktopEngineRef parameter.

This bug was initially identified and fixed by @knopp in:
flutter#27522

This patch replaces that one and adds the simplest possible unit test to
get it landed.

This also adds an initial unit test for the public Windows C API used to
implement the C++ client wrapper. In order to fully test this API, we'll
want to support test fixtures similar to what we do in the embedder API
tests. See: flutter/flutter#87299

Fixes: flutter/flutter#86617
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FlutterDesktopEngineGetTextureRegistrar declaration has invalid argument
5 participants