screenshot-tests-for-android icon indicating copy to clipboard operation
screenshot-tests-for-android copied to clipboard

Add TextureView/SurfaceView support

Open Guardiola31337 opened this issue 8 years ago • 2 comments

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.

Guardiola31337 avatar Feb 15 '17 16:02 Guardiola31337

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?

tdrhq avatar Apr 24 '17 18:04 tdrhq

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!

Guardiola31337 avatar Jun 16 '17 15:06 Guardiola31337