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

Several optimizations for Android Auto #806

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/OsmAndCore/Map/AtlasMapRenderer_Metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ namespace OsmAnd
/* Time elapsed for map layers stage */ \
FIELD_ACTION(float, elapsedTimeForMapLayersStage, "s"); \
\
/* Time elapsed for capturing terrain depth buffer */ \
FIELD_ACTION(float, elapsedTimeForTerrainDepthBufferCapture, "s"); \
\
/* Time elapsed for symbols stage */ \
FIELD_ACTION(float, elapsedTimeForSymbolsStage, "s"); \
FIELD_ACTION(float, elapsedTimeForPreparingSymbols, "s"); \
Expand Down
7 changes: 2 additions & 5 deletions include/OsmAndCore/Map/IMapRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,12 @@ namespace OsmAnd
virtual void setConfiguration(const std::shared_ptr<const MapRendererConfiguration>& configuration, bool forcedUpdate = false) = 0;

virtual bool isRenderingInitialized() const = 0;
virtual bool initializeRendering(bool renderTargetAvailable) = 0;
virtual bool initializeRendering(bool fresh = true) = 0;
virtual bool update(IMapRenderer_Metrics::Metric_update* const metric = nullptr) = 0;
virtual bool prepareFrame(IMapRenderer_Metrics::Metric_prepareFrame* const metric = nullptr) = 0;
virtual bool renderFrame(IMapRenderer_Metrics::Metric_renderFrame* const metric = nullptr) = 0;
virtual bool releaseRendering(bool gpuContextLost = false) = 0;

virtual bool attachToRenderTarget() = 0;
virtual bool isAttachedToRenderTarget() = 0;
virtual bool detachFromRenderTarget() = 0;

virtual bool isIdle() const = 0;
virtual QString getNotIdleReason() const = 0;

Expand Down Expand Up @@ -135,6 +131,7 @@ namespace OsmAnd

virtual bool setWindowSize(const PointI& windowSize, bool forcedUpdate = false) = 0;
virtual bool setViewport(const AreaI& viewport, bool forcedUpdate = false) = 0;
virtual bool setFlip(bool flip, bool forcedUpdate = false) = 0;
virtual bool setFieldOfView(const float fieldOfView, bool forcedUpdate = false) = 0;
virtual bool setVisibleDistance(const float visibleDistance, bool forcedUpdate = false) = 0;
virtual bool setDetailedDistance(const float detailedDistance, bool forcedUpdate = false) = 0;
Expand Down
3 changes: 3 additions & 0 deletions include/OsmAndCore/Map/MapRendererState.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace OsmAnd
Symbols_Configuration,
WindowSize,
Viewport,
Flip,
FieldOfView,
VisibleDistance,
DetailedDistance,
Expand Down Expand Up @@ -75,6 +76,7 @@ namespace OsmAnd

PointI windowSize;
AreaI viewport;
bool flip;
float fieldOfView;
float visibleDistance;
float detailedDistance;
Expand Down Expand Up @@ -134,6 +136,7 @@ namespace OsmAnd

PointI windowSize;
AreaI viewport;
bool flip;
float fieldOfView;
float visibleDistance;
float detailedDistance;
Expand Down
30 changes: 24 additions & 6 deletions src/Map/AtlasMapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ bool OsmAnd::AtlasMapRenderer::preInitializeRendering()
return true;
}

bool OsmAnd::AtlasMapRenderer::doInitializeRendering()
bool OsmAnd::AtlasMapRenderer::doInitializeRendering(bool reinitialize)
{
bool ok = MapRenderer::doInitializeRendering();
bool ok = MapRenderer::doInitializeRendering(reinitialize);
if (!ok)
return false;

Expand All @@ -200,28 +200,24 @@ bool OsmAnd::AtlasMapRenderer::doReleaseRendering(bool gpuContextLost)
{
if (!_skyStage->release(gpuContextLost))
ok = false;
_skyStage.reset();
}

if (_mapLayersStage)
{
if (!_mapLayersStage->release(gpuContextLost))
ok = false;
_mapLayersStage.reset();
}

if (_symbolsStage)
{
if (!_symbolsStage->release(gpuContextLost))
ok = false;
_symbolsStage.reset();
}

if (_debugStage)
{
if (!_debugStage->release(gpuContextLost))
ok = false;
_debugStage.reset();
}

if (!MapRenderer::doReleaseRendering(gpuContextLost))
Expand All @@ -230,6 +226,28 @@ bool OsmAnd::AtlasMapRenderer::doReleaseRendering(bool gpuContextLost)
return ok;
}

bool OsmAnd::AtlasMapRenderer::postReleaseRendering(bool gpuContextLost)
{
bool ok = true;

if (_skyStage)
_skyStage.reset();

if (_mapLayersStage)
_mapLayersStage.reset();

if (_symbolsStage)
_symbolsStage.reset();

if (_debugStage)
_debugStage.reset();

if (!MapRenderer::postReleaseRendering(gpuContextLost))
ok = false;

return ok;
}

int OsmAnd::AtlasMapRenderer::getTileSize3D() const
{
return TileSize3D;
Expand Down
3 changes: 2 additions & 1 deletion src/Map/AtlasMapRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ namespace OsmAnd

// Customization points:
bool preInitializeRendering() override;
bool doInitializeRendering() override;
bool doInitializeRendering(bool reinitialize) override;

bool prePrepareFrame() override;
bool postPrepareFrame() override;

bool doReleaseRendering(bool gpuContextLost) override;
bool postReleaseRendering(bool gpuContextLost) override;

// Stages:
std::shared_ptr<AtlasMapRendererSkyStage> _skyStage;
Expand Down
20 changes: 20 additions & 0 deletions src/Map/AtlasMapRendererSymbolsStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ OsmAnd::AtlasMapRendererSymbolsStage::AtlasMapRendererSymbolsStage(AtlasMapRende

OsmAnd::AtlasMapRendererSymbolsStage::~AtlasMapRendererSymbolsStage() = default;

bool OsmAnd::AtlasMapRendererSymbolsStage::release(bool gpuContextLost)
{
{
QWriteLocker scopedLocker(&_lastPreparedIntersectionsLock);

_lastPreparedIntersections.clear();
}

{
QWriteLocker scopedLocker(&_lastVisibleSymbolsLock);

_lastVisibleSymbols.clear();
}

_lastAcceptedMapSymbolsByOrder.clear();
denseSymbols.clear();
renderableSymbols.clear();
return true;
}

void OsmAnd::AtlasMapRendererSymbolsStage::prepare(AtlasMapRenderer_Metrics::Metric_renderFrame* const metric)
{
Stopwatch stopwatch(metric != nullptr);
Expand Down
2 changes: 2 additions & 0 deletions src/Map/AtlasMapRendererSymbolsStage.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ namespace OsmAnd
AtlasMapRendererSymbolsStage(AtlasMapRenderer* const renderer);
virtual ~AtlasMapRendererSymbolsStage();

bool release(bool gpuContextLost) override;

void queryLastPreparedSymbolsAt(
const PointI screenPoint,
QList<IMapRenderer::MapSymbolInformation>& outMapSymbols) const;
Expand Down
33 changes: 0 additions & 33 deletions src/Map/GPUAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "Logging.h"

OsmAnd::GPUAPI::GPUAPI()
: _isAttachedToRenderTarget(false)
{
}

Expand All @@ -26,11 +25,6 @@ OsmAnd::GPUAPI::~GPUAPI()
assert(resourcesRemaining == 0);
}

bool OsmAnd::GPUAPI::isAttachedToRenderTarget()
{
return _isAttachedToRenderTarget;
}

bool OsmAnd::GPUAPI::initialize()
{
return true;
Expand All @@ -46,35 +40,8 @@ bool OsmAnd::GPUAPI::elementIsVisible(int queryIndex)
return true;
}

bool OsmAnd::GPUAPI::attachToRenderTarget()
{
_isAttachedToRenderTarget = true;
return true;
}

bool OsmAnd::GPUAPI::detachFromRenderTarget(bool gpuContextLost)
{
if (!isAttachedToRenderTarget())
{
return false;
}

_isAttachedToRenderTarget = false;

return true;
}

bool OsmAnd::GPUAPI::release(bool gpuContextLost)
{
bool ok;

if (isAttachedToRenderTarget())
{
ok = detachFromRenderTarget(gpuContextLost);
if (!ok)
return false;
}

return true;
}

Expand Down
5 changes: 0 additions & 5 deletions src/Map/GPUAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ namespace OsmAnd
QAtomicInt _allocatedResourcesCounter;
#endif

bool _isAttachedToRenderTarget;
QHash< AtlasTypeId, std::shared_ptr<AtlasTexturesPool> > _atlasTexturesPools;
protected:
GPUAPI();
Expand All @@ -315,13 +314,9 @@ namespace OsmAnd
public:
virtual ~GPUAPI();

virtual bool isAttachedToRenderTarget();

virtual bool initialize() = 0;
virtual int checkElementVisibility(int queryIndex, float pointSize) = 0;
virtual bool elementIsVisible(int queryIndex) = 0;
virtual bool attachToRenderTarget() = 0;
virtual bool detachFromRenderTarget(bool gpuContextLost) = 0;
virtual bool release(bool gpuContextLost) = 0;

virtual bool uploadTiledDataToGPU(
Expand Down
Loading