std::shared_ptr<SkBitmap> OsmAnd::MapRasterLayerProvider_GPU_P::rasterize( const TileId tileId, const ZoomLevel zoom, const std::shared_ptr<const MapPrimitivesProvider::Data>& primitivesTile, MapRasterLayerProvider_Metrics::Metric_obtainData* const metric_, const IQueryController* const queryController) { #if OSMAND_PERFORMANCE_METRICS MapRasterLayerProvider_Metrics::Metric_obtainData localMetric; const auto metric = metric_ ? metric_ : &localMetric; #else const auto metric = metric_; #endif const Stopwatch totalStopwatch( #if OSMAND_PERFORMANCE_METRICS true #else metric != nullptr #endif // OSMAND_PERFORMANCE_METRICS ); //TODO: SkGpuDevice // Allocate rasterization target const auto tileSize = owner->getTileSize(); const std::shared_ptr<SkBitmap> rasterizationSurface(new SkBitmap()); rasterizationSurface->setConfig(SkBitmap::kARGB_8888_Config, tileSize, tileSize); if (!rasterizationSurface->allocPixels()) { LogPrintf(LogSeverityLevel::Error, "Failed to allocate buffer for ARGB8888 rasterization surface %dx%d", tileSize, tileSize); return nullptr; } SkBitmapDevice rasterizationTarget(*rasterizationSurface); // Create rasterization canvas SkCanvas canvas(&rasterizationTarget); // Perform actual rasterization if (!owner->fillBackground) canvas.clear(SK_ColorTRANSPARENT); _mapRasterizer->rasterize( Utilities::tileBoundingBox31(tileId, zoom), primitivesTile->primitivisedObjects, canvas, owner->fillBackground, nullptr, metric ? metric->findOrAddSubmetricOfType<MapRasterizer_Metrics::Metric_rasterize>().get() : nullptr, queryController); if (metric) metric->elapsedTime += totalStopwatch.elapsed(); #if OSMAND_PERFORMANCE_METRICS #if OSMAND_PERFORMANCE_METRICS <= 1 LogPrintf(LogSeverityLevel::Info, "%dx%d@%d rasterized on CPU in %fs", tileId.x, tileId.y, zoom, totalStopwatch.elapsed()); #else LogPrintf(LogSeverityLevel::Info, "%dx%d@%d rasterized on CPU in %fs:\n%s", tileId.x, tileId.y, zoom, totalStopwatch.elapsed(), qPrintable(metric ? metric->toString(QLatin1String("\t - ")) : QLatin1String("(null)"))); #endif // OSMAND_PERFORMANCE_METRICS <= 1 #endif // OSMAND_PERFORMANCE_METRICS return rasterizationSurface; }
bool OsmAnd::OfflineMapRasterTileProvider_GPU_P::obtainTile(const TileId& tileId, const ZoomLevel& zoom, std::shared_ptr<MapTile>& outTile) { // Get bounding box that covers this tile const auto tileBBox31 = Utilities::tileBoundingBox31(tileId, zoom); // Obtain OBF data interface const auto& dataInterface = owner->dataProvider->obfsCollection->obtainDataInterface(); // Get map objects from data proxy QList< std::shared_ptr<const Model::MapObject> > mapObjects; #if defined(_DEBUG) || defined(DEBUG) const auto dataRead_Begin = std::chrono::high_resolution_clock::now(); #endif bool basemapAvailable; MapFoundationType tileFoundation; dataInterface->obtainBasemapPresenceFlag(basemapAvailable, nullptr); dataInterface->obtainMapObjects(&mapObjects, &tileFoundation, tileBBox31, zoom, nullptr); #if defined(_DEBUG) || defined(DEBUG) const auto dataRead_End = std::chrono::high_resolution_clock::now(); const std::chrono::duration<float> dataRead_Elapsed = dataRead_End - dataRead_Begin; #endif #if defined(_DEBUG) || defined(DEBUG) const auto dataRasterization_Begin = std::chrono::high_resolution_clock::now(); #endif //TODO: SkGpuDevice // Allocate rasterization target auto rasterizationSurface = new SkBitmap(); rasterizationSurface->setConfig(SkBitmap::kARGB_8888_Config, outputTileSize, outputTileSize); if(!rasterizationSurface->allocPixels()) { delete rasterizationSurface; LogPrintf(LogSeverityLevel::Error, "Failed to allocate buffer for ARGB8888 rasterization surface %dx%d", outputTileSize, outputTileSize); return false; } SkBitmapDevice rasterizationTarget(*rasterizationSurface); // Create rasterization canvas SkCanvas canvas(&rasterizationTarget); // Perform actual rendering bool nothingToRasterize = false; RasterizerEnvironment rasterizerEnv(owner->dataProvider->mapStyle, basemapAvailable, density); RasterizerContext rasterizerContext; Rasterizer::prepareContext(rasterizerEnv, rasterizerContext, tileBBox31, zoom, outputTileSize, tileFoundation, mapObjects, OsmAnd::PointF(), ¬hingToRasterize, nullptr); if(!nothingToRasterize) Rasterizer::rasterizeMap(rasterizerEnv, rasterizerContext, true, canvas, nullptr); #if defined(_DEBUG) || defined(DEBUG) const auto dataRasterization_End = std::chrono::high_resolution_clock::now(); const std::chrono::duration<float> dataRasterization_Elapsed = dataRasterization_End - dataRasterization_Begin; if(!nothingToRasterize) { LogPrintf(LogSeverityLevel::Info, "%d map objects from %dx%d@%d: reading %fs, rasterization %fs", mapObjects.count(), tileId.x, tileId.y, zoom, dataRead_Elapsed.count(), dataRasterization_Elapsed.count()); } else { LogPrintf(LogSeverityLevel::Info, "%d map objects from %dx%d@%d: reading %fs, nothing to rasterize (%fs)", mapObjects.count(), tileId.x, tileId.y, zoom, dataRead_Elapsed.count(), dataRasterization_Elapsed.count()); } #endif // If there is no data to rasterize, tell that this tile is not available if(nothingToRasterize) { delete rasterizationSurface; outTile.reset(); return true; } // Or supply newly rasterized tile auto tile = new MapBitmapTile(rasterizationSurface, MapBitmapTile::AlphaChannelData::NotPresent); outTile.reset(tile); return true; }
bool OsmAnd::OfflineMapRasterTileProvider_Software_P::obtainTile(const TileId tileId, const ZoomLevel zoom, std::shared_ptr<const MapTile>& outTile, const IQueryController* const queryController) { // Obtain offline map data tile std::shared_ptr< const OfflineMapDataTile > dataTile; owner->dataProvider->obtainTile(tileId, zoom, dataTile); if (!dataTile) { outTile.reset(); return true; } #if OSMAND_PERFORMANCE_METRICS const auto dataRasterization_Begin = std::chrono::high_resolution_clock::now(); #endif // OSMAND_PERFORMANCE_METRICS // Allocate rasterization target auto rasterizationSurface = new SkBitmap(); rasterizationSurface->setConfig(SkBitmap::kARGB_8888_Config, outputTileSize, outputTileSize); if (!rasterizationSurface->allocPixels()) { delete rasterizationSurface; LogPrintf(LogSeverityLevel::Error, "Failed to allocate buffer for ARGB8888 rasterization surface %dx%d", outputTileSize, outputTileSize); return false; } SkBitmapDevice rasterizationTarget(*rasterizationSurface); // Create rasterization canvas SkCanvas canvas(&rasterizationTarget); // Perform actual rendering if (!dataTile->nothingToRasterize) { Rasterizer rasterizer(dataTile->rasterizerContext); rasterizer.rasterizeMap(canvas, true, nullptr, queryController); } #if OSMAND_PERFORMANCE_METRICS const auto dataRasterization_End = std::chrono::high_resolution_clock::now(); const std::chrono::duration<float> dataRasterization_Elapsed = dataRasterization_End - dataRasterization_Begin; if (!dataTile->nothingToRasterize) { LogPrintf(LogSeverityLevel::Info, "%d map objects in %dx%d@%d: rasterization %fs", dataTile->mapObjects.count(), tileId.x, tileId.y, zoom, dataRasterization_Elapsed.count()); } else { LogPrintf(LogSeverityLevel::Info, "%d map objects in %dx%d@%d: nothing to rasterize (%fs)", dataTile->mapObjects.count(), tileId.x, tileId.y, zoom, dataRasterization_Elapsed.count()); } #endif // OSMAND_PERFORMANCE_METRICS // If there is no data to rasterize, tell that this tile is not available if (dataTile->nothingToRasterize) { delete rasterizationSurface; outTile.reset(); return true; } // Or supply newly rasterized tile auto tile = new Tile(rasterizationSurface, dataTile); outTile.reset(tile); return true; }
bool OsmAnd::BinaryMapRasterBitmapTileProvider_GPU_P::obtainData( const TileId tileId, const ZoomLevel zoom, std::shared_ptr<MapTiledData>& outTiledData, BinaryMapRasterBitmapTileProvider_Metrics::Metric_obtainData* const metric_, const IQueryController* const queryController) { #if OSMAND_PERFORMANCE_METRICS BinaryMapRasterBitmapTileProvider_Metrics::Metric_obtainData localMetric; const auto metric = metric_ ? metric_ : &localMetric; #else const auto metric = metric_; #endif const Stopwatch totalStopwatch( #if OSMAND_PERFORMANCE_METRICS true #else metric != nullptr #endif // OSMAND_PERFORMANCE_METRICS ); // Obtain offline map primitives tile std::shared_ptr<MapTiledData> primitivesTile_; owner->primitivesProvider->obtainData(tileId, zoom, primitivesTile_); if (!primitivesTile_) { outTiledData.reset(); return true; } const auto primitivesTile = std::static_pointer_cast<BinaryMapPrimitivesTile>(primitivesTile_); //TODO: SkGpuDevice // Allocate rasterization target const auto tileSize = owner->getTileSize(); const std::shared_ptr<SkBitmap> rasterizationSurface(new SkBitmap()); rasterizationSurface->setConfig(SkBitmap::kARGB_8888_Config, tileSize, tileSize); if (!rasterizationSurface->allocPixels()) { LogPrintf(LogSeverityLevel::Error, "Failed to allocate buffer for ARGB8888 rasterization surface %dx%d", tileSize, tileSize); return false; } SkBitmapDevice rasterizationTarget(*rasterizationSurface); // Create rasterization canvas SkCanvas canvas(&rasterizationTarget); // Perform actual rendering if (!primitivesTile->primitivisedArea->isEmpty()) { _mapRasterizer->rasterize( primitivesTile->primitivisedArea, canvas, true, nullptr, metric ? &metric->rasterizeMetric : nullptr, queryController); } else { // If there is no data to rasterize, tell that this tile is not available outTiledData.reset(); return true; } // Or supply newly rasterized tile outTiledData.reset(new BinaryMapRasterizedTile( primitivesTile, rasterizationSurface, AlphaChannelData::NotPresent, owner->getTileDensityFactor(), tileId, zoom)); if (metric) metric->elapsedTime += totalStopwatch.elapsed(); #if OSMAND_PERFORMANCE_METRICS #if OSMAND_PERFORMANCE_METRICS <= 1 LogPrintf(LogSeverityLevel::Info, "%dx%d@%d rasterized on GPU in %fs", tileId.x, tileId.y, zoom, totalStopwatch.elapsed()); #else LogPrintf(LogSeverityLevel::Info, "%dx%d@%d rasterized on GPU in %fs:\n%s", tileId.x, tileId.y, zoom, totalStopwatch.elapsed(), qPrintable(metric ? metric->toString(QLatin1String("\t - ")) : QLatin1String("(null)"))); #endif // OSMAND_PERFORMANCE_METRICS <= 1 #endif // OSMAND_PERFORMANCE_METRICS return true; }