mousebird-consulting-inc / WhirlyGlobe

WhirlyGlobe Development
Other
830 stars 255 forks source link

iPadOS 16 beta2 slow rendering #1546

Closed akovalov closed 2 years ago

akovalov commented 2 years ago

On iPadOS 15 (iPad 7 gen) full globe is rendered in 4s, but on iPadOS 16 beta 2 it is rendered in 14s. Please see video of the rendering process. https://user-images.githubusercontent.com/9693643/175298471-fb2841ad-1692-470d-bcc9-4a0a2e3d9eab.mov

I use the latest version of WhirlyGlobe from develop branch with a .mbtiles vector map file and here is the some code. Vector is converted to images because I didn't solve how to have different background color on globe and outside the globe.

        guard let mbTilesFetcher = MaplyMBTileFetcher(mbTiles: mbFileName),
              let tileInfo = mbTilesFetcher.tileInfo()
        else {
            return
        }

        let sampleParams = MaplySamplingParams()
        sampleParams.coordSys = MaplySphericalMercator(webStandard: ())
        if maplyVC is WhirlyGlobeViewController {
            sampleParams.coverPoles = true
            sampleParams.edgeMatching = true
        } else {
            sampleParams.coverPoles = false
            sampleParams.edgeMatching = false
        }
        sampleParams.minZoom = 1
        sampleParams.maxZoom = Int32(Constants.Map.maximumZoomLevel)
        sampleParams.singleLevel = true
        sampleParams.forceMinLevel = true
        sampleParams.minImportance = 1024.0 * 1024.0
        sampleParams.minImportanceTop = 0

        let styleSettings = MaplyVectorStyleSettings()
        styleSettings.baseDrawPriority = kMaplyImageLayerDrawPriorityDefault + 1000
        styleSettings.drawPriorityPerLevel = 100

        let styleFileName = "light_map_style"
        guard let styleJSON = Bundle.main.loadJSON(from: styleFileName),
              let style = MapboxVectorStyleSet(json: styleJSON, settings: styleSettings, viewC: maplyVC)
        else {
            return
        }

       if imageVectorHybrid {

            guard let imageLoader = MaplyQuadImageLoader(params: sampleParams, tileInfos: [tileInfo], viewC: maplyVC) else {
                return
            }
            imageLoader.setTileFetcher(mbTilesFetcher)
            imageLoader.baseDrawPriority = styleSettings.baseDrawPriority
            imageLoader.drawPriorityPerLevel = styleSettings.drawPriorityPerLevel
            self.imageLoader = imageLoader

            if backgroundAllPolys {

                let imageSize = CGSize(width: 512, height: 512)
                guard let offlineRender = MaplyRenderController(size: imageSize) else {
                    return
                }
                offlineRender.clearLights()
                self.offlineRender = offlineRender
                let imageStyleSettings = MaplyVectorStyleSettings(scale: UIScreen.main.scale)
                imageStyleSettings.baseDrawPriority = styleSettings.baseDrawPriority
                imageStyleSettings.arealShaderName = kMaplyShaderDefaultTriNoLighting

                guard var styleDictImage = try? JSONSerialization.jsonObject(with: styleJSON, options: []) as? [String: Any] else {
                    return
                }
                if let layers = styleDictImage["layers"] as? [[String: Any]] {
                    var newLayers = [ [String: Any] ]()
                    for layer in layers {
                        if let type = layer["type"] as? String {
                            if type == "background" || type == "fill" {
                                newLayers.append(layer)
                            }
                        }
                    }
                    styleDictImage["layers"] = newLayers
                }

                guard let styleSheetImage = MapboxVectorStyleSet(dict: styleDictImage,
                                                                 settings: imageStyleSettings,
                                                                 viewC: offlineRender) else {
                    return
                }

                self.styleSheetImage = styleSheetImage
            }

            guard var styleDictVector = try? JSONSerialization.jsonObject(with: styleJSON, options: []) as? [String: Any] else {
                return
            }

            if self.backgroundAllPolys {
                if let layers = styleDictVector["layers"] as? [[String: Any]] {
                    var newLayers = [ [String: Any] ]()
                    for layer in layers {
                        if let type = layer["type"] as? String {
                            if type != "background" && type != "fill" {
                                newLayers.append(layer)
                            }
                        }
                    }
                    styleDictVector["layers"] = newLayers
                }
            }

            if !(maplyVC is WhirlyGlobeViewController) {
                if let color = style.backgroundColor(forZoom: 0.0) {
                    maplyVC.clearColor = color
                }
            }

            if let offlineRender = offlineRender,
               let styleSheetImage = styleSheetImage {

                guard let mapboxInterp = MapboxVectorInterpreter(imageStyle: styleSheetImage, offlineRender: offlineRender, vectorStyle: style, viewC: maplyVC) else {
                    return
                }
                self.mapboxInterp = mapboxInterp

            } else {

                guard let mapboxInterp = MapboxVectorInterpreter(vectorStyle: style, viewC: maplyVC) else {
                    return
                }
                self.mapboxInterp = mapboxInterp
            }
            if let mapboxInterp = mapboxInterp {
                imageLoader.setInterpreter(mapboxInterp)
            }
       }

I've also checked loader without imageVectorHybrid like this:

            guard let interp = MapboxVectorInterpreter(vectorStyle: style, viewC: maplyVC) else {
                return
            }
            self.mapboxInterp = interp

            vectorLoader = MaplyQuadPagingLoader(
                params: sampleParams,
                tileInfo: tileInfo,
                loadInterp: interp,
                viewC: maplyVC)
            vectorLoader?.flipY = false
            vectorLoader?.setTileFetcher(mbTilesFetcher)

And on iPadOS 16 it takes 8s (much faster but still too long), please check the video https://user-images.githubusercontent.com/9693643/175299736-aee2f8b5-ac20-4ae2-a780-e8887b9e2918.mov

Tried AutoTester app (latest code from develop) on iPadOS 16 beta, but not sure what exactly to test in this case. Maybe you are aware of this issue already? Can I provide more specific details to find the issue? Let me know please if I am doing something wrong here and you have any suggestion.

Thank you!

mousebird commented 2 years ago

I'd make sure you're building your app in Release mode rather than Debug. If the problem persists, then I'd recommend looking at the AutoTester app to verify that it is, in fact, the OS version. Try using our vector tiles test case for comparison.

akovalov commented 2 years ago

Appeared, I had not the latest version from the develop branch. Updated to the latest code from develop and it seems working fine, the rendering speed is the same as on iOS 15. Sorry for disturbing.