-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[google_maps_flutter_android] Avoid redundant ground overlay image updates #12242
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,12 +85,16 @@ private void addGroundOverlay(@NonNull PlatformGroundOverlay platformGroundOverl | |
| groundOverlayOptionsBuilder, | ||
| assetManager, | ||
| density, | ||
| bitmapDescriptorFactoryWrapper); | ||
| bitmapDescriptorFactoryWrapper, | ||
| true); | ||
| GroundOverlayOptions options = groundOverlayOptionsBuilder.build(); | ||
| final GroundOverlay groundOverlay = googleMap.addGroundOverlay(options); | ||
| if (groundOverlay != null) { | ||
| GroundOverlayController groundOverlayController = | ||
| new GroundOverlayController(groundOverlay, platformGroundOverlay.getBounds() != null); | ||
| new GroundOverlayController( | ||
| groundOverlay, | ||
| platformGroundOverlay.getBounds() != null, | ||
| platformGroundOverlay.getImage()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does |
||
| groundOverlayIdToController.put(groundOverlayId, groundOverlayController); | ||
| googleMapsGroundOverlayIdToDartGroundOverlayId.put(groundOverlay.getId(), groundOverlayId); | ||
| } | ||
|
|
@@ -101,12 +105,18 @@ private void changeGroundOverlay(@NonNull PlatformGroundOverlay platformGroundOv | |
| GroundOverlayController groundOverlayController = | ||
| groundOverlayIdToController.get(groundOverlayId); | ||
| if (groundOverlayController != null) { | ||
| final PlatformBitmap image = platformGroundOverlay.getImage(); | ||
| final boolean imageChanged = !groundOverlayController.hasImage(image); | ||
| Convert.interpretGroundOverlayOptions( | ||
| platformGroundOverlay, | ||
| groundOverlayController, | ||
| assetManager, | ||
| density, | ||
| bitmapDescriptorFactoryWrapper); | ||
| bitmapDescriptorFactoryWrapper, | ||
| imageChanged); | ||
| if (imageChanged) { | ||
| groundOverlayController.setPlatformBitmap(image); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.spy; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import android.content.Context; | ||
|
|
@@ -46,6 +48,12 @@ public class GroundOverlaysControllerTest { | |
|
|
||
| @NonNull | ||
| private PlatformGroundOverlay createGroundOverlay(String overlayId, double transparency) { | ||
| return createGroundOverlay(overlayId, transparency, 100.0); | ||
| } | ||
|
|
||
| @NonNull | ||
| private PlatformGroundOverlay createGroundOverlay( | ||
| String overlayId, double transparency, double imageWidth) { | ||
| byte[] bmpData = Base64.decode(base64Image, Base64.DEFAULT); | ||
|
|
||
| return new PlatformGroundOverlay( | ||
|
|
@@ -55,7 +63,7 @@ private PlatformGroundOverlay createGroundOverlay(String overlayId, double trans | |
| bmpData, | ||
| PlatformMapBitmapScaling.AUTO, | ||
| /* imagePixelRatio */ 2.0, | ||
| /* width */ 100.0, /* height */ | ||
| /* width */ imageWidth, /* height */ | ||
| null)), | ||
| /* position */ null, | ||
| /* bounds */ null, | ||
|
|
@@ -107,9 +115,28 @@ public void controller_AddChangeAndRemoveGroundOverlay() { | |
| controller.changeGroundOverlays( | ||
| Collections.singletonList(createGroundOverlay(googleGroundOverlayId, newTransparency))); | ||
| Mockito.verify(groundOverlay, times(1)).setTransparency(newTransparency); | ||
| verify(bitmapDescriptorFactoryWrapper, times(1)).fromBitmap(any()); | ||
| verifyNoMoreInteractions(bitmapDescriptorFactoryWrapper); | ||
|
|
||
| controller.removeGroundOverlays(Collections.singletonList(googleGroundOverlayId)); | ||
|
|
||
| Mockito.verify(groundOverlay, times(1)).remove(); | ||
| } | ||
|
|
||
| @Test | ||
| public void controller_ChangeGroundOverlayUpdatesChangedImage() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm holding off on a full review until the questions from the earlier review are addressed, but as a quick additional note, a PR that is designed to avoid updates when the image hasn't changed should have a test for that scenario, in addition to testing that the update behavior didn't regress. |
||
| final GroundOverlay groundOverlay = mock(GroundOverlay.class); | ||
| final String groundOverlayId = "ground-overlay"; | ||
|
|
||
| when(groundOverlay.getId()).thenReturn("google-ground-overlay"); | ||
| when(googleMap.addGroundOverlay(any(GroundOverlayOptions.class))).thenReturn(groundOverlay); | ||
|
|
||
| controller.addGroundOverlays( | ||
| Collections.singletonList(createGroundOverlay(groundOverlayId, 0.1, 100.0))); | ||
| controller.changeGroundOverlays( | ||
| Collections.singletonList(createGroundOverlay(groundOverlayId, 0.1, 101.0))); | ||
|
|
||
| verify(bitmapDescriptorFactoryWrapper, times(2)).fromBitmap(any()); | ||
| verify(groundOverlay).setImage(mockBitmapDescriptor); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like the wrong scope to me for the interpretGroundOverlayOptions method to take the decision about if it should update the image instead of having. It looks like you have code that sometimes decides and sometimes you hardcode true. Can you talk to me a bit about what callers expect and what constraints you have?
Or maybe the sink should keep a record of the last image and diff? Either way I think understanding what layer shoudl be responsible for preventing duplicates is something i want more information about.