Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TextureView/SurfaceView support #55

Open
Guardiola31337 opened this issue Feb 15, 2017 · 2 comments
Open

Add TextureView/SurfaceView support #55

Guardiola31337 opened this issue Feb 15, 2017 · 2 comments

Comments

@Guardiola31337
Copy link

We are working on adding screenshot testing to the Mapbox SDK Test App.
In order to try screenshot-tests-for-android I added a test (which takes a screenshot after a simple map gets loaded) in app-example-androidjunitrunner.

The problem is that I'm getting a screenshot with the part of the map transparent.
Screenshot:

com example screenshots mapboxsimplemapactivitytest_checksmapboxsimplemapwithclipped

Examining the code I found you're not taking into account views like TextureView or SurfaceView (we use them to paint maps).

Trying to add this enhancement (firstly with TextureView) I added some changes and got same screenshot 😕

com example screenshots mapboxsimplemapactivitytest_checksmapboxsimplemapwithclipped

Funny thing is if I remove the drawClippedView() call, I get the screenshot with map properly painted but (obviously) the rest of the views not (e.g. Mapbox logo). Even clearer checking another screenshot generated from other test (whole screenshot is transparent).
Screenshot:

com example screenshots mapboxsimplemapactivitytest_checksmapboxsimplemapwithoutclipped

Any thoughts on how to fix this?
Any info would help us adding this feature to the framework.

@tdrhq
Copy link
Contributor

tdrhq commented Apr 24, 2017

So, I'm not a TextureView/SurfaceView expert, but based on your description you seem to be on the right path, and I'd love to have the eventual fix pulled in.

In this particular case, it looks like the View is drawing over your TextureView, probably because you have a view behind the TextureView which in production will be drawn first, but in your code is drawn after the TextureView.. something like this

  • BackgroundView
    • TitleBar
    • TextureView
    • MapboxImage

The solution will be to draw the TextureView while drawing the rest of the views, which might be tricky (since it's the draw() that dispatches the draw() for the children). Perhaps a ScreenshotSafeTextureView that detects if it's running in a screenshot test and in which case just do the logic you showed inside of its onDraw() method?

@Guardiola31337
Copy link
Author

Hey 👋 @tdrhq

Revisiting this one, the solution you suggested wasn't feasible because subclasses of TextureView cannot do their own rendering with the Canvas object so I opted to create both Bitmaps and do a simple merge.
How does that sound? Do you see any drawbacks?

It still remains adding a way to get a Bitmap from SurfaceViews, but at least TextureViews are unblocked.

Happy to know what you think about #71

Thanks a lot!

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

No branches or pull requests

3 participants