forked from organicmaps/organicmaps
removed RenderQueueRoutine. renamed RenderQueue into TileRenderer
This commit is contained in:
parent
7d9aca64ab
commit
f0eb269363
4 changed files with 0 additions and 361 deletions
|
@ -1,249 +0,0 @@
|
|||
#include "../base/mutex.hpp"
|
||||
#include "../base/timer.hpp"
|
||||
#include "../base/logging.hpp"
|
||||
|
||||
#include "../std/bind.hpp"
|
||||
|
||||
#include "../yg/internal/opengl.hpp"
|
||||
#include "../yg/render_state.hpp"
|
||||
#include "../yg/rendercontext.hpp"
|
||||
#include "../yg/framebuffer.hpp"
|
||||
#include "../yg/renderbuffer.hpp"
|
||||
#include "../yg/resource_manager.hpp"
|
||||
#include "../yg/screen.hpp"
|
||||
#include "../yg/pen_info.hpp"
|
||||
#include "../yg/skin.hpp"
|
||||
#include "../yg/base_texture.hpp"
|
||||
#include "../yg/info_layer.hpp"
|
||||
|
||||
#include "../indexer/scales.hpp"
|
||||
|
||||
#include "events.hpp"
|
||||
#include "drawer_yg.hpp"
|
||||
#include "render_queue_routine.hpp"
|
||||
#include "render_queue.hpp"
|
||||
#include "tile.hpp"
|
||||
|
||||
RenderQueueRoutine::Command::Command(TRenderFn renderFn,
|
||||
Tiler::RectInfo const & rectInfo,
|
||||
size_t sequenceID,
|
||||
TCommandFinishedFn commandFinishedFn)
|
||||
: m_renderFn(renderFn),
|
||||
m_rectInfo(rectInfo),
|
||||
m_sequenceID(sequenceID),
|
||||
m_commandFinishedFn(commandFinishedFn)
|
||||
{}
|
||||
|
||||
RenderQueueRoutine::RenderQueueRoutine(string const & skinName,
|
||||
unsigned scaleEtalonSize,
|
||||
yg::Color const & bgColor,
|
||||
size_t threadNum,
|
||||
RenderQueue * renderQueue)
|
||||
: m_threadNum(threadNum),
|
||||
m_renderQueue(renderQueue)
|
||||
{
|
||||
m_skinName = skinName;
|
||||
m_visualScale = 0;
|
||||
m_scaleEtalonSize = scaleEtalonSize;
|
||||
m_bgColor = bgColor;
|
||||
}
|
||||
|
||||
bool RenderQueueRoutine::HasTile(Tiler::RectInfo const & rectInfo)
|
||||
{
|
||||
TileCache & tileCache = m_renderQueue->GetTileCache();
|
||||
tileCache.readLock();
|
||||
bool res = tileCache.hasTile(rectInfo);
|
||||
tileCache.readUnlock();
|
||||
return res;
|
||||
}
|
||||
|
||||
void RenderQueueRoutine::AddTile(Tiler::RectInfo const & rectInfo, Tile const & tile)
|
||||
{
|
||||
TileCache & tileCache = m_renderQueue->GetTileCache();
|
||||
tileCache.writeLock();
|
||||
if (tileCache.hasTile(rectInfo))
|
||||
tileCache.touchTile(rectInfo);
|
||||
else
|
||||
tileCache.addTile(rectInfo, TileCache::Entry(tile, m_resourceManager));
|
||||
tileCache.writeUnlock();
|
||||
}
|
||||
|
||||
void RenderQueueRoutine::Cancel()
|
||||
{
|
||||
IRoutine::Cancel();
|
||||
|
||||
threads::MutexGuard guard(m_mutex);
|
||||
|
||||
/// ...Or cancelling the current rendering command in progress.
|
||||
if (m_currentCommand != 0)
|
||||
m_currentCommand->m_paintEvent->setIsCancelled(true);
|
||||
}
|
||||
|
||||
void RenderQueueRoutine::Do()
|
||||
{
|
||||
m_renderContext->makeCurrent();
|
||||
|
||||
m_frameBuffer = make_shared_ptr(new yg::gl::FrameBuffer());
|
||||
|
||||
unsigned tileWidth = m_resourceManager->tileTextureWidth();
|
||||
unsigned tileHeight = m_resourceManager->tileTextureHeight();
|
||||
|
||||
shared_ptr<yg::gl::RenderBuffer> depthBuffer(new yg::gl::RenderBuffer(tileWidth, tileHeight, true));
|
||||
m_frameBuffer->setDepthBuffer(depthBuffer);
|
||||
|
||||
DrawerYG::params_t params;
|
||||
|
||||
params.m_resourceManager = m_resourceManager;
|
||||
params.m_frameBuffer = m_frameBuffer;
|
||||
params.m_glyphCacheID = m_resourceManager->renderThreadGlyphCacheID(m_threadNum);
|
||||
params.m_useOverlay = true;
|
||||
params.m_threadID = m_threadNum;
|
||||
/* params.m_isDebugging = true;
|
||||
params.m_drawPathes = false;
|
||||
params.m_drawAreas = false;
|
||||
params.m_drawTexts = false; */
|
||||
|
||||
m_threadDrawer = make_shared_ptr(new DrawerYG(m_skinName, params));
|
||||
m_threadDrawer->onSize(tileWidth, tileHeight);
|
||||
m_threadDrawer->SetVisualScale(m_visualScale);
|
||||
|
||||
ScreenBase frameScreen;
|
||||
/// leaving 1px border of fully transparent pixels for sews-free tile blitting.
|
||||
m2::RectI renderRect(1, 1, tileWidth - 1, tileWidth - 1);
|
||||
|
||||
frameScreen.OnSize(renderRect);
|
||||
|
||||
while (!IsCancelled())
|
||||
{
|
||||
{
|
||||
threads::MutexGuard guard(m_mutex);
|
||||
|
||||
m_currentCommand = m_renderQueue->RenderCommands().Front(true);
|
||||
|
||||
if (m_renderQueue->RenderCommands().IsCancelled())
|
||||
{
|
||||
m_renderQueue->FinishCommand();
|
||||
break;
|
||||
}
|
||||
|
||||
/// commands from the previous sequence are ignored
|
||||
if (m_currentCommand->m_sequenceID < m_renderQueue->CurrentSequence())
|
||||
continue;
|
||||
|
||||
if (HasTile(m_currentCommand->m_rectInfo))
|
||||
continue;
|
||||
|
||||
m_currentCommand->m_paintEvent = make_shared_ptr(new PaintEvent(m_threadDrawer));
|
||||
}
|
||||
|
||||
if (IsCancelled())
|
||||
{
|
||||
m_renderQueue->FinishCommand();
|
||||
break;
|
||||
}
|
||||
|
||||
my::Timer timer;
|
||||
|
||||
shared_ptr<yg::gl::BaseTexture> tileTarget;
|
||||
|
||||
tileTarget = m_resourceManager->renderTargets().Front(true);
|
||||
|
||||
if (m_resourceManager->renderTargets().IsCancelled())
|
||||
{
|
||||
m_renderQueue->FinishCommand();
|
||||
break;
|
||||
}
|
||||
|
||||
m_threadDrawer->screen()->setRenderTarget(tileTarget);
|
||||
|
||||
shared_ptr<yg::InfoLayer> tileInfoLayer(new yg::InfoLayer());
|
||||
|
||||
m_threadDrawer->screen()->setInfoLayer(tileInfoLayer);
|
||||
|
||||
m_threadDrawer->beginFrame();
|
||||
|
||||
m_threadDrawer->clear(yg::Color(m_bgColor.r, m_bgColor.g, m_bgColor.b, 0));
|
||||
m_threadDrawer->screen()->setClipRect(renderRect);
|
||||
m_threadDrawer->clear(m_bgColor);
|
||||
|
||||
frameScreen.SetFromRect(m_currentCommand->m_rectInfo.m_rect);
|
||||
|
||||
m2::RectD selectionRect;
|
||||
|
||||
double const inflationSize = 24 * m_visualScale;
|
||||
|
||||
//frameScreen.PtoG(m2::Inflate(m2::RectD(renderRect), inflationSize, inflationSize), selectionRect);
|
||||
frameScreen.PtoG(m2::RectD(renderRect), selectionRect);
|
||||
|
||||
m_currentCommand->m_renderFn(
|
||||
m_currentCommand->m_paintEvent,
|
||||
frameScreen,
|
||||
selectionRect,
|
||||
m_currentCommand->m_rectInfo.m_drawScale);
|
||||
|
||||
m_threadDrawer->endFrame();
|
||||
m_threadDrawer->screen()->resetInfoLayer();
|
||||
|
||||
double duration = timer.ElapsedSeconds();
|
||||
|
||||
TCommandFinishedFn fn;
|
||||
Tiler::RectInfo rectInfo;
|
||||
Tile tile;
|
||||
|
||||
if (!IsCancelled())
|
||||
{
|
||||
{
|
||||
threads::MutexGuard guard(m_mutex);
|
||||
|
||||
if (m_currentCommand->m_paintEvent->isCancelled())
|
||||
{
|
||||
m_renderQueue->FinishCommand();
|
||||
break;
|
||||
}
|
||||
|
||||
rectInfo = m_currentCommand->m_rectInfo;
|
||||
tile = Tile(tileTarget, tileInfoLayer, frameScreen, m_currentCommand->m_rectInfo, duration);
|
||||
AddTile(rectInfo, tile);
|
||||
|
||||
fn = m_currentCommand->m_commandFinishedFn;
|
||||
|
||||
m_currentCommand.reset();
|
||||
m_renderQueue->FinishCommand();
|
||||
}
|
||||
|
||||
fn(rectInfo, tile);
|
||||
}
|
||||
else
|
||||
m_renderQueue->FinishCommand();
|
||||
|
||||
}
|
||||
|
||||
// By VNG: We can't destroy render context in drawing thread.
|
||||
// Notify render context instead.
|
||||
m_renderContext->endThreadDrawing();
|
||||
}
|
||||
|
||||
void RenderQueueRoutine::InitializeGL(shared_ptr<yg::gl::RenderContext> const & renderContext,
|
||||
shared_ptr<yg::ResourceManager> const & resourceManager,
|
||||
double visualScale)
|
||||
{
|
||||
m_renderContext = renderContext;
|
||||
m_resourceManager = resourceManager;
|
||||
m_visualScale = visualScale;
|
||||
}
|
||||
|
||||
void RenderQueueRoutine::MemoryWarning()
|
||||
{
|
||||
m_threadDrawer->screen()->memoryWarning();
|
||||
}
|
||||
|
||||
void RenderQueueRoutine::EnterBackground()
|
||||
{
|
||||
m_threadDrawer->screen()->enterBackground();
|
||||
}
|
||||
|
||||
void RenderQueueRoutine::EnterForeground()
|
||||
{
|
||||
m_threadDrawer->screen()->enterForeground();
|
||||
}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "../base/thread.hpp"
|
||||
#include "../base/condition.hpp"
|
||||
#include "../base/commands_queue.hpp"
|
||||
#include "../geometry/rect2d.hpp"
|
||||
#include "../geometry/screenbase.hpp"
|
||||
#include "../std/list.hpp"
|
||||
#include "../std/function.hpp"
|
||||
#include "../yg/color.hpp"
|
||||
#include "tile_cache.hpp"
|
||||
#include "tiler.hpp"
|
||||
#include "render_policy.hpp"
|
||||
|
||||
class DrawerYG;
|
||||
|
||||
namespace threads
|
||||
{
|
||||
class Condition;
|
||||
}
|
||||
|
||||
class PaintEvent;
|
||||
class WindowHandle;
|
||||
class RenderQueue;
|
||||
|
||||
namespace yg
|
||||
{
|
||||
class ResourceManager;
|
||||
|
||||
|
||||
namespace gl
|
||||
{
|
||||
class RenderContext;
|
||||
class FrameBuffer;
|
||||
class RenderBuffer;
|
||||
class BaseTexture;
|
||||
class RenderState;
|
||||
class RenderState;
|
||||
class Screen;
|
||||
}
|
||||
}
|
||||
|
||||
class RenderQueueRoutine : public threads::IRoutine
|
||||
{
|
||||
public:
|
||||
|
||||
typedef RenderPolicy::TRenderFn TRenderFn;
|
||||
typedef function<void(Tiler::RectInfo const &, Tile const &)> TCommandFinishedFn;
|
||||
|
||||
/// Single tile rendering command
|
||||
struct Command
|
||||
{
|
||||
TRenderFn m_renderFn;
|
||||
Tiler::RectInfo m_rectInfo;
|
||||
shared_ptr<PaintEvent> m_paintEvent; //< paintEvent is set later after construction
|
||||
size_t m_sequenceID;
|
||||
TCommandFinishedFn m_commandFinishedFn;
|
||||
Command(TRenderFn renderFn,
|
||||
Tiler::RectInfo const & rectInfo,
|
||||
size_t sequenceID,
|
||||
TCommandFinishedFn commandFinishedFn);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
shared_ptr<yg::gl::RenderContext> m_renderContext;
|
||||
shared_ptr<yg::gl::FrameBuffer> m_frameBuffer;
|
||||
shared_ptr<DrawerYG> m_threadDrawer;
|
||||
|
||||
threads::Mutex m_mutex;
|
||||
shared_ptr<Command> m_currentCommand;
|
||||
|
||||
shared_ptr<yg::ResourceManager> m_resourceManager;
|
||||
|
||||
|
||||
double m_visualScale;
|
||||
string m_skinName;
|
||||
unsigned m_scaleEtalonSize;
|
||||
yg::Color m_bgColor;
|
||||
|
||||
size_t m_threadNum;
|
||||
|
||||
RenderQueue * m_renderQueue;
|
||||
|
||||
bool HasTile(Tiler::RectInfo const & rectInfo);
|
||||
void AddTile(Tiler::RectInfo const & rectInfo, Tile const & tile);
|
||||
|
||||
public:
|
||||
|
||||
RenderQueueRoutine(string const & skinName,
|
||||
unsigned scaleEtalonSize,
|
||||
yg::Color const & bgColor,
|
||||
size_t threadNum,
|
||||
RenderQueue * renderQueue);
|
||||
/// initialize GL rendering
|
||||
/// this function is called just before the thread starts.
|
||||
void InitializeGL(shared_ptr<yg::gl::RenderContext> const & renderContext,
|
||||
shared_ptr<yg::ResourceManager> const & resourceManager,
|
||||
double visualScale);
|
||||
/// This function should always be called from the main thread.
|
||||
void Cancel();
|
||||
/// Thread procedure
|
||||
void Do();
|
||||
/// add model rendering command to rendering queue
|
||||
void AddCommand(TRenderFn const & fn, Tiler::RectInfo const & rectInfo, size_t seqNumber);
|
||||
/// free all available memory
|
||||
void MemoryWarning();
|
||||
/// free all easily recreatable opengl resources and make sure that no opengl call will be made.
|
||||
void EnterBackground();
|
||||
/// recreate all necessary opengl resources and prepare to run in foreground.
|
||||
void EnterForeground();
|
||||
};
|
Loading…
Add table
Reference in a new issue