refactored RenderPolicies to eliminate a lot of duplicate code.

This commit is contained in:
rachytski 2012-03-14 00:02:00 +04:00 committed by Alex Zolotarev
parent 1a74b88de4
commit a4b3c14a7e
20 changed files with 646 additions and 822 deletions

View file

@ -1,149 +1,149 @@
#include "../base/SRC_FIRST.hpp"
#include "basic_render_policy.hpp"
#include "events.hpp"
#include "queued_renderer.hpp"
#include "render_queue.hpp"
#include "drawer_yg.hpp"
#include "window_handle.hpp"
#include "../yg/info_layer.hpp"
#include "../yg/internal/opengl.hpp"
#include "../yg/skin.hpp"
#include "events.hpp"
#include "../indexer/scales.hpp"
#include "../geometry/screenbase.hpp"
#include "../yg/render_state.hpp"
#include "../platform/platform.hpp"
#include "../geometry/transformations.hpp"
BasicRenderPolicy::BasicRenderPolicy(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, false, 1)
BasicRenderPolicy::BasicRenderPolicy(shared_ptr<yg::gl::RenderContext> const & primaryRC,
bool doSupportRotation,
size_t idCacheSize,
shared_ptr<QueuedRenderer> const & queuedRenderer)
: RenderPolicy(primaryRC, doSupportRotation, idCacheSize),
m_QueuedRenderer(queuedRenderer),
m_DoAddCommand(true)
{
yg::ResourceManager::Params rmp = rmParams;
}
rmp.selectTexRTFormat();
void BasicRenderPolicy::SetRenderFn(TRenderFn renderFn)
{
RenderPolicy::SetRenderFn(renderFn);
m_RenderQueue->initializeGL(m_primaryRC, m_resourceManager);
}
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(50000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
sizeof(unsigned short),
15,
false,
true,
1,
"primaryStorage",
false,
false);
void BasicRenderPolicy::SetEmptyModelFn(TEmptyModelFn const & checkFn)
{
m_RenderQueue->SetEmptyModelFn(checkFn);
}
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
sizeof(unsigned short),
100,
false,
true,
1,
"smallStorage",
false,
false);
m2::RectI const BasicRenderPolicy::OnSize(int w, int h)
{
RenderPolicy::OnSize(w, h);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
sizeof(unsigned short),
50,
true,
true,
1,
"blitStorage",
false,
false);
m_RenderQueue->OnSize(w, h);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
10,
rmp.m_texFormat,
true,
true,
true,
1,
"primaryTexture",
false,
false);
m2::PointU pt = m_RenderQueue->renderState().coordSystemShift();
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
5,
rmp.m_texFormat,
true,
true,
true,
1,
"fontTexture",
false,
false);
return m2::RectI(pt.x, pt.y, pt.x + w, pt.y + h);
}
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
1,
0);
void BasicRenderPolicy::BeginFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s)
{
if (m_QueuedRenderer)
m_QueuedRenderer->BeginFrame();
}
void BasicRenderPolicy::EndFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s)
{
m_RenderQueue->renderState().m_mutex->Unlock();
rmp.m_useSingleThreadedOGL = false;
rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported;
m_resourceManager.reset(new yg::ResourceManager(rmp));
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);
m_resourceManager->addFonts(fonts);
DrawerYG::params_t p;
p.m_frameBuffer = make_shared_ptr(new yg::gl::FrameBuffer(useDefaultFB));
p.m_resourceManager = m_resourceManager;
p.m_dynamicPagesCount = 2;
p.m_textPagesCount = 2;
p.m_glyphCacheID = m_resourceManager->guiThreadGlyphCacheID();
p.m_skinName = GetPlatform().SkinName();
p.m_visualScale = GetPlatform().VisualScale();
p.m_isSynchronized = true;
m_drawer.reset(new DrawerYG(p));
m_windowHandle.reset(new WindowHandle());
m_windowHandle->setUpdatesEnabled(false);
m_windowHandle->setRenderPolicy(this);
m_windowHandle->setVideoTimer(videoTimer);
m_windowHandle->setRenderContext(primaryRC);
if (m_QueuedRenderer)
m_QueuedRenderer->EndFrame();
}
void BasicRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s)
{
int scaleEtalonSize = GetPlatform().ScaleEtalonSize();
if (m_QueuedRenderer)
{
m_QueuedRenderer->DrawFrame();
m_resourceManager->updatePoolState();
}
m2::RectD glbRect;
m2::PointD const pxCenter = s.PixelRect().Center();
s.PtoG(m2::RectD(pxCenter - m2::PointD(scaleEtalonSize / 2, scaleEtalonSize / 2),
pxCenter + m2::PointD(scaleEtalonSize / 2, scaleEtalonSize / 2)),
glbRect);
bool doForceUpdate = DoForceUpdate();
bool doIntersectInvalidRect = s.GlobalRect().IsIntersect(GetInvalidRect());
shared_ptr<yg::InfoLayer> infoLayer(new yg::InfoLayer());
m_RenderQueue->renderStatePtr()->m_doRepaintAll = doForceUpdate;
e->drawer()->screen()->setInfoLayer(infoLayer);
if (m_DoAddCommand)
{
if (s != m_RenderQueue->renderState().m_actualScreen)
m_RenderQueue->AddCommand(m_renderFn, s);
else
if (doForceUpdate && doIntersectInvalidRect)
m_RenderQueue->AddCommand(m_renderFn, s);
}
e->drawer()->screen()->beginFrame();
SetForceUpdate(false);
DrawerYG * pDrawer = e->drawer();
e->drawer()->beginFrame();
e->drawer()->screen()->clear(m_bgColor);
m_renderFn(e, s, s.ClipRect(), s.ClipRect(), scales::GetScaleLevel(glbRect), false);
m_RenderQueue->renderState().m_mutex->Lock();
infoLayer->draw(e->drawer()->screen().get(), math::Identity<double, 3>());
e->drawer()->screen()->resetInfoLayer();
if (m_RenderQueue->renderState().m_actualTarget.get() != 0)
{
m2::PointD const ptShift = m_RenderQueue->renderState().coordSystemShift(false);
e->drawer()->screen()->endFrame();
math::Matrix<double, 3, 3> m = m_RenderQueue->renderState().m_actualScreen.PtoGMatrix() * s.GtoPMatrix();
m = math::Shift(m, -ptShift);
pDrawer->screen()->blit(m_RenderQueue->renderState().m_actualTarget, m);
}
e->drawer()->endFrame();
}
void BasicRenderPolicy::StartDrag()
{
m_DoAddCommand = false;
RenderPolicy::StartDrag();
}
void BasicRenderPolicy::StopDrag()
{
m_DoAddCommand = true;
RenderPolicy::StopDrag();
}
void BasicRenderPolicy::StartScale()
{
m_DoAddCommand = false;
RenderPolicy::StartScale();
}
void BasicRenderPolicy::StopScale()
{
m_DoAddCommand = true;
RenderPolicy::StartScale();
}
bool BasicRenderPolicy::IsEmptyModel() const
{
return m_RenderQueue->renderStatePtr()->m_isEmptyModelActual;
}
RenderQueue & BasicRenderPolicy::GetRenderQueue()
{
return *m_RenderQueue.get();
}
bool BasicRenderPolicy::NeedRedraw() const
{
if (RenderPolicy::NeedRedraw())
return true;
if (m_QueuedRenderer && m_QueuedRenderer->NeedRedraw())
return true;
return false;
}

View file

@ -1,18 +1,51 @@
#pragma once
#include "../std/shared_ptr.hpp"
#include "render_policy.hpp"
#include "drawer_yg.hpp"
class VideoTimer;
class QueuedRenderer;
class RenderQueue;
/// This is a base class for both multithreaded and singlethreaded rendering policies
/// that uses a double buffering scheme.
/// primary OpenGL thread only blits frontBuffer(RenderState::actualTarget),
/// while another thread renders scene on the backBuffer and swaps it
/// with frontBuffer periodically
class BasicRenderPolicy : public RenderPolicy
{
public:
BasicRenderPolicy(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
protected:
void DrawFrame(shared_ptr<PaintEvent> const & paintEvent,
ScreenBase const & screenBase);
shared_ptr<QueuedRenderer> m_QueuedRenderer;
shared_ptr<RenderQueue> m_RenderQueue;
bool m_DoAddCommand;
public:
BasicRenderPolicy(shared_ptr<yg::gl::RenderContext> const & primaryRC,
bool doSupportRotation,
size_t idCacheSize,
shared_ptr<QueuedRenderer> const & queuedRenderer = shared_ptr<QueuedRenderer>());
void BeginFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s);
void DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s);
void EndFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s);
m2::RectI const OnSize(int w, int h);
void StartDrag();
void StopDrag();
void StartScale();
void StopScale();
bool IsEmptyModel() const;
RenderQueue & GetRenderQueue();
void SetRenderFn(TRenderFn renderFn);
void SetEmptyModelFn(TEmptyModelFn const & checkFn);
bool NeedRedraw() const;
};

View file

@ -0,0 +1,151 @@
#include "basic_tiling_render_policy.hpp"
#include "../indexer/scales.hpp"
#include "tile_renderer.hpp"
#include "coverage_generator.hpp"
#include "screen_coverage.hpp"
#include "queued_renderer.hpp"
BasicTilingRenderPolicy::BasicTilingRenderPolicy(shared_ptr<yg::gl::RenderContext> const & primaryRC,
bool doSupportRotation,
size_t idCacheSize,
shared_ptr<QueuedRenderer> const & queuedRenderer)
: RenderPolicy(primaryRC, doSupportRotation, idCacheSize),
m_QueuedRenderer(queuedRenderer),
m_DrawScale(0),
m_IsEmptyModel(false),
m_DoRecreateCoverage(false)
{
}
void BasicTilingRenderPolicy::BeginFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s)
{
if (m_QueuedRenderer)
m_QueuedRenderer->BeginFrame();
}
void BasicTilingRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s)
{
if (m_QueuedRenderer)
{
m_QueuedRenderer->DrawFrame();
m_resourceManager->updatePoolState();
}
/// checking, whether we should add the CoverScreen command
bool doForceUpdate = DoForceUpdate();
bool doIntersectInvalidRect = GetInvalidRect().IsIntersect(s.GlobalRect());
if (doForceUpdate)
m_CoverageGenerator->InvalidateTiles(GetInvalidRect(), scales::GetUpperWorldScale() + 1);
m_CoverageGenerator->AddCoverScreenTask(s,
m_DoRecreateCoverage || (doForceUpdate && doIntersectInvalidRect));
SetForceUpdate(false);
m_DoRecreateCoverage = false;
/// rendering current coverage
DrawerYG * pDrawer = e->drawer();
pDrawer->beginFrame();
pDrawer->screen()->clear(m_bgColor);
m_CoverageGenerator->Mutex().Lock();
ScreenCoverage * curCvg = &m_CoverageGenerator->CurrentCoverage();
curCvg->Draw(pDrawer->screen().get(), s);
m_DrawScale = curCvg->GetDrawScale();
if (!curCvg->IsEmptyDrawingCoverage() || !curCvg->IsPartialCoverage())
m_IsEmptyModel = curCvg->IsEmptyDrawingCoverage();
pDrawer->endFrame();
}
void BasicTilingRenderPolicy::EndFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s)
{
ScreenCoverage * curCvg = &m_CoverageGenerator->CurrentCoverage();
curCvg->EndFrame(e->drawer()->screen().get());
m_CoverageGenerator->Mutex().Unlock();
if (m_QueuedRenderer)
m_QueuedRenderer->EndFrame();
}
TileRenderer & BasicTilingRenderPolicy::GetTileRenderer()
{
return *m_TileRenderer.get();
}
void BasicTilingRenderPolicy::StartScale()
{
m_TileRenderer->SetIsPaused(true);
m_TileRenderer->CancelCommands();
}
void BasicTilingRenderPolicy::StopScale()
{
m_TileRenderer->SetIsPaused(false);
m_DoRecreateCoverage = true;
RenderPolicy::StopScale();
}
void BasicTilingRenderPolicy::StartDrag()
{
m_TileRenderer->SetIsPaused(true);
m_TileRenderer->CancelCommands();
}
void BasicTilingRenderPolicy::StopDrag()
{
m_TileRenderer->SetIsPaused(false);
m_DoRecreateCoverage = true;
RenderPolicy::StopDrag();
}
void BasicTilingRenderPolicy::StartRotate(double a, double timeInSec)
{
m_TileRenderer->SetIsPaused(true);
m_TileRenderer->CancelCommands();
}
void BasicTilingRenderPolicy::StopRotate(double a, double timeInSec)
{
m_TileRenderer->SetIsPaused(false);
m_DoRecreateCoverage = true;
RenderPolicy::StopRotate(a, timeInSec);
}
bool BasicTilingRenderPolicy::IsTiling() const
{
return true;
}
int BasicTilingRenderPolicy::GetDrawScale(ScreenBase const & s) const
{
return m_DrawScale;
}
bool BasicTilingRenderPolicy::IsEmptyModel() const
{
return m_IsEmptyModel;
}
bool BasicTilingRenderPolicy::NeedRedraw() const
{
if (RenderPolicy::NeedRedraw())
return true;
if (m_QueuedRenderer && m_QueuedRenderer->NeedRedraw())
return true;
return false;
}

View file

@ -0,0 +1,61 @@
#pragma once
#include "render_policy.hpp"
#include "../std/shared_ptr.hpp"
#include "../yg/info_layer.hpp"
class TileRenderer;
class CoverageGenerator;
class QueuedRenderer;
/// This is a base class for a single-threaded and multi-threaded versions of render policies
/// which uses tiles to present a scene.
/// This policies use ScreenCoverage objects to hold all the information, need to render the model
/// at the specified ScreenBase(tiles, texts, symbols, e.t.c)
/// At any moment of time there are a currentCoverage that are drawn in DrawFrame method.
/// There are threads that are responsible for composing new ScreenCoverage from already drawn tiles,
/// and drawing tiles if needed.
/// Once the more recent ScreenCoverage are composed it became a currentCoverage.
class BasicTilingRenderPolicy : public RenderPolicy
{
protected:
shared_ptr<QueuedRenderer> m_QueuedRenderer;
shared_ptr<TileRenderer> m_TileRenderer;
shared_ptr<CoverageGenerator> m_CoverageGenerator;
ScreenBase m_CurrentScreen;
int m_DrawScale;
bool m_IsEmptyModel;
bool m_DoRecreateCoverage;
protected:
TileRenderer & GetTileRenderer();
public:
BasicTilingRenderPolicy(shared_ptr<yg::gl::RenderContext> const & primaryRC,
bool doSupportRotation,
size_t idCacheSize,
shared_ptr<QueuedRenderer> const & queuedRenderer = shared_ptr<QueuedRenderer>());
void BeginFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
void DrawFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
void EndFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
virtual void StartScale();
virtual void StopScale();
virtual void StartDrag();
virtual void StopDrag();
virtual void StartRotate(double a, double timeInSec);
virtual void StopRotate(double a, double timeInSec);
bool NeedRedraw() const;
bool IsTiling() const;
bool IsEmptyModel() const;
int GetDrawScale(ScreenBase const & s) const;
};

View file

@ -2,6 +2,8 @@
#include "benchmark_render_policy_mt.hpp"
#include "render_queue.hpp"
#include "../base/logging.hpp"
BenchmarkRenderPolicyMT::BenchmarkRenderPolicyMT(VideoTimer * videoTimer,

View file

@ -1,5 +1,6 @@
#include "../base/SRC_FIRST.hpp"
#include "benchmark_tiling_render_policy_mt.hpp"
#include "tile_renderer.hpp"
BenchmarkTilingRenderPolicyMT::BenchmarkTilingRenderPolicyMT(
VideoTimer * videoTimer,

View file

@ -35,16 +35,18 @@ HEADERS += \
tile.hpp \
tile_cache.hpp \
screen_coverage.hpp \
render_policy_mt.hpp \
basic_render_policy.hpp \
render_queue.hpp \
render_queue_routine.hpp \
benchmark_render_policy_mt.hpp \
ruler.hpp \
measurement_utils.hpp \
basic_render_policy.hpp \
simple_render_policy.hpp \
proto_to_yg_styles.hpp \
test_render_policy.hpp \
queued_render_policy.hpp \
queued_renderer.hpp \
basic_tiling_render_policy.hpp \
render_policy_mt.hpp \
bookmark.hpp
SOURCES += \
@ -69,18 +71,20 @@ SOURCES += \
tile_cache.cpp \
tile.cpp \
screen_coverage.cpp \
render_policy_mt.cpp \
basic_render_policy.cpp \
render_queue_routine.cpp \
render_queue.cpp \
benchmark_render_policy_mt.cpp \
ruler.cpp \
measurement_utils.cpp \
window_handle.cpp \
basic_render_policy.cpp \
simple_render_policy.cpp \
proto_to_yg_styles.cpp \
test_render_policy.cpp \
queued_render_policy.cpp \
events.cpp
queued_renderer.cpp \
events.cpp \
basic_tiling_render_policy.cpp \
render_policy_mt.cpp
!iphone*:!bada*:!android* {
HEADERS += qgl_render_context.hpp

View file

@ -1,19 +1,14 @@
#include "queued_render_policy.hpp"
#include "events.hpp"
#include "queued_renderer.hpp"
#include "../yg/internal/opengl.hpp"
QueuedRenderPolicy::QueuedRenderPolicy(int pipelinesCount,
shared_ptr<yg::gl::RenderContext> const & primaryRC,
bool doSupportsRotation,
size_t idCacheSize)
: RenderPolicy(primaryRC, doSupportsRotation, idCacheSize)
QueuedRenderer::QueuedRenderer(int pipelinesCount)
{
m_Pipelines = new PacketsPipeline[pipelinesCount];
m_PipelinesCount = pipelinesCount;
m_CurrentPipeline = 0;
}
QueuedRenderPolicy::~QueuedRenderPolicy()
QueuedRenderer::~QueuedRenderer()
{
/* for (unsigned i = 0; i < m_PipelinesCount; ++i)
CancelQueuedCommands(i);*/
@ -23,11 +18,8 @@ QueuedRenderPolicy::~QueuedRenderPolicy()
LOG(LINFO, ("deleted QueuedRenderPolicy"));
}
bool QueuedRenderPolicy::NeedRedraw() const
bool QueuedRenderer::NeedRedraw() const
{
if (RenderPolicy::NeedRedraw())
return true;
for (unsigned i = 0; i < m_PipelinesCount; ++i)
if (!m_Pipelines[i].m_Queue.empty())
return true;
@ -35,22 +27,20 @@ bool QueuedRenderPolicy::NeedRedraw() const
return false;
}
void QueuedRenderPolicy::BeginFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s)
void QueuedRenderer::BeginFrame()
{
m_IsDebugging = false;
if (m_IsDebugging)
LOG(LINFO, ("-------BeginFrame-------"));
base_t::BeginFrame(ev, s);
}
void QueuedRenderPolicy::EndFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s)
void QueuedRenderer::EndFrame()
{
base_t::EndFrame(ev, s);
if (m_IsDebugging)
LOG(LINFO, ("-------EndFrame-------"));
}
void QueuedRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s)
void QueuedRenderer::DrawFrame()
{
/// cyclically checking pipelines starting from m_CurrentPipeline
for (unsigned i = 0; i < m_PipelinesCount; ++i)
@ -64,11 +54,9 @@ void QueuedRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & ev, ScreenBase
break;
}
}
m_resourceManager->updatePoolState();
}
bool QueuedRenderPolicy::RenderQueuedCommands(int pipelineNum)
bool QueuedRenderer::RenderQueuedCommands(int pipelineNum)
{
/// logging only calls that is made while rendering tiles.
// if ((pipelineNum == 0) && (m_IsDebugging))
@ -79,7 +67,7 @@ bool QueuedRenderPolicy::RenderQueuedCommands(int pipelineNum)
unsigned cmdProcessed = 0;
m_Pipelines[pipelineNum].m_Queue.processList(bind(&QueuedRenderPolicy::PacketsPipeline::FillFrameCommands, &m_Pipelines[pipelineNum], _1, 1));
m_Pipelines[pipelineNum].m_Queue.processList(bind(&QueuedRenderer::PacketsPipeline::FillFrameCommands, &m_Pipelines[pipelineNum], _1, 1));
cmdProcessed = m_Pipelines[pipelineNum].m_FrameCommands.size();
@ -126,7 +114,7 @@ bool QueuedRenderPolicy::RenderQueuedCommands(int pipelineNum)
// yg::gl::g_doLogOGLCalls = false;
}
void QueuedRenderPolicy::PacketsPipeline::FillFrameCommands(list<yg::gl::Packet> & renderQueue, int maxFrames)
void QueuedRenderer::PacketsPipeline::FillFrameCommands(list<yg::gl::Packet> & renderQueue, int maxFrames)
{
m_FrameCommands.clear();
@ -180,12 +168,12 @@ void QueuedRenderPolicy::PacketsPipeline::FillFrameCommands(list<yg::gl::Packet>
}
}
void QueuedRenderPolicy::CopyQueuedCommands(list<yg::gl::Packet> &l, list<yg::gl::Packet> &r)
void QueuedRenderer::CopyQueuedCommands(list<yg::gl::Packet> &l, list<yg::gl::Packet> &r)
{
swap(l, r);
}
void QueuedRenderPolicy::CancelQueuedCommands(int pipelineNum)
void QueuedRenderer::CancelQueuedCommands(int pipelineNum)
{
if (m_IsDebugging)
LOG(LINFO, ("cancelling packetsQueue for pipeline", pipelineNum));
@ -194,7 +182,7 @@ void QueuedRenderPolicy::CancelQueuedCommands(int pipelineNum)
list<yg::gl::Packet> l;
m_Pipelines[pipelineNum].m_Queue.processList(bind(&QueuedRenderPolicy::CopyQueuedCommands, this, _1, ref(l)));
m_Pipelines[pipelineNum].m_Queue.processList(bind(&QueuedRenderer::CopyQueuedCommands, this, _1, ref(l)));
for (list<yg::gl::Packet>::iterator it = l.begin(); it != l.end(); ++it)
{
@ -205,12 +193,12 @@ void QueuedRenderPolicy::CancelQueuedCommands(int pipelineNum)
}
}
yg::gl::PacketsQueue * QueuedRenderPolicy::GetPacketsQueue(int pipelineNum)
yg::gl::PacketsQueue * QueuedRenderer::GetPacketsQueue(int pipelineNum)
{
return &m_Pipelines[pipelineNum].m_Queue;
}
void QueuedRenderPolicy::PrepareQueueCancellation(int pipelineNum)
void QueuedRenderer::PrepareQueueCancellation(int pipelineNum)
{
m_Pipelines[pipelineNum].m_Queue.cancelFences();
}

View file

@ -1,17 +1,14 @@
#pragma once
#include "render_policy.hpp"
#include "../base/threaded_list.hpp"
#include "../yg/renderer.hpp"
/// base class for policy used on the devices that do not support
/// OpenGL context sharing.
class QueuedRenderPolicy : public RenderPolicy
/// Mixture-class for rendering policies, used on the
/// devices that do not support OpenGL context sharing
class QueuedRenderer
{
private:
typedef RenderPolicy base_t;
/// separate pipeline for packets, collected on the single thread.
/// although it's possible to collect all the packet from all threads
/// into single queue it's better to separate them for finer optimization
@ -41,7 +38,10 @@ private:
bool m_IsDebugging;
protected:
public:
QueuedRenderer(int pipelinesCount);
~QueuedRenderer();
void CopyQueuedCommands(list<yg::gl::Packet> & l, list<yg::gl::Packet> & r);
@ -49,18 +49,9 @@ protected:
void CancelQueuedCommands(int pipelineNum);
void PrepareQueueCancellation(int pipelineNum);
public:
QueuedRenderPolicy(int pipelinesCount,
shared_ptr<yg::gl::RenderContext> const & primaryRC,
bool doSupportsRotation,
size_t idCacheSize);
~QueuedRenderPolicy();
void BeginFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
void DrawFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
void EndFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
void BeginFrame();
void DrawFrame();
void EndFrame();
bool NeedRedraw() const;

View file

@ -4,6 +4,7 @@
#include "../indexer/drawing_rules.hpp"
#include "window_handle.hpp"
#include "test_render_policy.hpp"
#include "basic_render_policy.hpp"
#include "render_policy_st.hpp"

View file

@ -1,24 +1,17 @@
#include "../base/SRC_FIRST.hpp"
#include "render_policy_mt.hpp"
#include "events.hpp"
#include "drawer_yg.hpp"
#include "window_handle.hpp"
#include "../yg/render_state.hpp"
#include "../yg/internal/opengl.hpp"
#include "../geometry/transformations.hpp"
#include "../base/mutex.hpp"
#include "../platform/platform.hpp"
#include "window_handle.hpp"
#include "render_queue.hpp"
RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, false, 1),
m_DoAddCommand(true)
: BasicRenderPolicy(primaryRC, false, 1)
{
yg::ResourceManager::Params rmp = rmParams;
@ -147,7 +140,7 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
m_windowHandle->setVideoTimer(videoTimer);
m_windowHandle->setRenderContext(primaryRC);
m_renderQueue.reset(new RenderQueue(GetPlatform().SkinName(),
m_RenderQueue.reset(new RenderQueue(GetPlatform().SkinName(),
false,
true,
0.1,
@ -156,114 +149,5 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
GetPlatform().VisualScale(),
m_bgColor));
m_renderQueue->AddWindowHandle(m_windowHandle);
}
void RenderPolicyMT::SetRenderFn(TRenderFn renderFn)
{
RenderPolicy::SetRenderFn(renderFn);
m_renderQueue->initializeGL(m_primaryRC, m_resourceManager);
}
void RenderPolicyMT::SetEmptyModelFn(TEmptyModelFn const & checkFn)
{
m_renderQueue->SetEmptyModelFn(checkFn);
}
m2::RectI const RenderPolicyMT::OnSize(int w, int h)
{
RenderPolicy::OnSize(w, h);
m_renderQueue->OnSize(w, h);
m2::PointU pt = m_renderQueue->renderState().coordSystemShift();
return m2::RectI(pt.x, pt.y, pt.x + w, pt.y + h);
}
void RenderPolicyMT::BeginFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s)
{
}
void RenderPolicyMT::EndFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s)
{
m_renderQueue->renderState().m_mutex->Unlock();
}
void RenderPolicyMT::DrawFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s)
{
m_resourceManager->updatePoolState();
bool doForceUpdate = DoForceUpdate();
bool doIntersectInvalidRect = s.GlobalRect().IsIntersect(GetInvalidRect());
m_renderQueue->renderStatePtr()->m_doRepaintAll = doForceUpdate;
if (m_DoAddCommand)
{
if (s != m_renderQueue->renderState().m_actualScreen)
m_renderQueue->AddCommand(m_renderFn, s);
else
if (doForceUpdate && doIntersectInvalidRect)
m_renderQueue->AddCommand(m_renderFn, s);
}
SetForceUpdate(false);
DrawerYG * pDrawer = e->drawer();
m_renderQueue->renderState().m_mutex->Lock();
e->drawer()->beginFrame();
e->drawer()->screen()->clear(m_bgColor);
if (m_renderQueue->renderState().m_actualTarget.get() != 0)
{
m2::PointD const ptShift = m_renderQueue->renderState().coordSystemShift(false);
math::Matrix<double, 3, 3> m = m_renderQueue->renderState().m_actualScreen.PtoGMatrix() * s.GtoPMatrix();
m = math::Shift(m, -ptShift);
pDrawer->screen()->blit(m_renderQueue->renderState().m_actualTarget, m);
}
e->drawer()->endFrame();
}
void RenderPolicyMT::StartDrag()
{
m_DoAddCommand = false;
RenderPolicy::StartDrag();
}
void RenderPolicyMT::StopDrag()
{
m_DoAddCommand = true;
RenderPolicy::StopDrag();
}
void RenderPolicyMT::StartScale()
{
m_DoAddCommand = false;
RenderPolicy::StartScale();
}
void RenderPolicyMT::StopScale()
{
m_DoAddCommand = true;
RenderPolicy::StartScale();
}
bool RenderPolicyMT::IsEmptyModel() const
{
return m_renderQueue->renderStatePtr()->m_isEmptyModelActual;
}
RenderQueue & RenderPolicyMT::GetRenderQueue()
{
return *m_renderQueue.get();
m_RenderQueue->AddWindowHandle(m_windowHandle);
}

View file

@ -1,22 +1,9 @@
#pragma once
#include "render_policy.hpp"
#include "render_queue.hpp"
#include "drawer_yg.hpp"
#include "basic_render_policy.hpp"
#include "../geometry/point2d.hpp"
#include "../std/scoped_ptr.hpp"
class WindowHandle;
class VideoTimer;
class RenderPolicyMT : public RenderPolicy
class RenderPolicyMT : public BasicRenderPolicy
{
protected:
scoped_ptr<RenderQueue> m_renderQueue;
bool m_DoAddCommand;
public:
RenderPolicyMT(VideoTimer * videoTimer,
@ -24,27 +11,5 @@ public:
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void BeginFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s);
void DrawFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s);
void EndFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s);
m2::RectI const OnSize(int w, int h);
void StartDrag();
void StopDrag();
void StartScale();
void StopScale();
bool IsEmptyModel() const;
RenderQueue & GetRenderQueue();
void SetRenderFn(TRenderFn renderFn);
void SetEmptyModelFn(TEmptyModelFn const & checkFn);
};

View file

@ -1,25 +1,18 @@
#include "render_policy_st.hpp"
#include "events.hpp"
#include "window_handle.hpp"
#include "drawer_yg.hpp"
#include "render_queue.hpp"
#include "../yg/internal/opengl.hpp"
#include "../yg/render_state.hpp"
#include "../yg/base_texture.hpp"
#include "../geometry/transformations.hpp"
#include "../platform/platform.hpp"
#include "../std/bind.hpp"
#include "../yg/internal/opengl.hpp"
#include "queued_renderer.hpp"
#include "window_handle.hpp"
#include "render_queue.hpp"
RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: QueuedRenderPolicy(1, primaryRC, false, 1),
m_DoAddCommand(true)
: BasicRenderPolicy(primaryRC, false, 1, make_shared_ptr(new QueuedRenderer(1)))
{
yg::ResourceManager::Params rmp = rmParams;
@ -151,8 +144,8 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
m_windowHandle->setVideoTimer(videoTimer);
m_windowHandle->setRenderContext(primaryRC);
m_renderQueue.reset();
m_renderQueue.reset(new RenderQueue(GetPlatform().SkinName(),
m_RenderQueue.reset();
m_RenderQueue.reset(new RenderQueue(GetPlatform().SkinName(),
false,
false,
0.1,
@ -161,122 +154,20 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
GetPlatform().VisualScale(),
m_bgColor));
m_renderQueue->AddWindowHandle(m_windowHandle);
m_RenderQueue->AddWindowHandle(m_windowHandle);
m_renderQueue->SetGLQueue(GetPacketsQueue(0));
}
void RenderPolicyST::SetRenderFn(TRenderFn renderFn)
{
QueuedRenderPolicy::SetRenderFn(renderFn);
m_renderQueue->initializeGL(m_primaryRC, m_resourceManager);
}
void RenderPolicyST::SetEmptyModelFn(TEmptyModelFn const & checkFn)
{
m_renderQueue->SetEmptyModelFn(checkFn);
m_RenderQueue->SetGLQueue(m_QueuedRenderer->GetPacketsQueue(0));
}
RenderPolicyST::~RenderPolicyST()
{
LOG(LINFO, ("destroying RenderPolicyST"));
base_t::CancelQueuedCommands(0);
m_QueuedRenderer->CancelQueuedCommands(0);
LOG(LINFO, ("shutting down renderQueue"));
m_renderQueue.reset();
m_RenderQueue.reset();
LOG(LINFO, ("PartialRenderPolicy destroyed"));
}
void RenderPolicyST::DrawFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s)
{
base_t::DrawFrame(e, s);
/// blitting actualTarget
bool doForceUpdate = DoForceUpdate();
bool doIntersectInvalidRect = s.GlobalRect().IsIntersect(GetInvalidRect());
m_renderQueue->renderStatePtr()->m_doRepaintAll = doForceUpdate;
if (m_DoAddCommand)
{
if (s != m_renderQueue->renderState().m_actualScreen)
m_renderQueue->AddCommand(m_renderFn, s);
else
if (doForceUpdate && doIntersectInvalidRect)
m_renderQueue->AddCommand(m_renderFn, s);
}
SetForceUpdate(false);
DrawerYG * pDrawer = e->drawer();
pDrawer->beginFrame();
e->drawer()->screen()->clear(m_bgColor);
m_renderQueue->renderState().m_mutex->Lock();
if (m_renderQueue->renderState().m_actualTarget.get() != 0)
{
m2::PointD const ptShift = m_renderQueue->renderState().coordSystemShift(false);
math::Matrix<double, 3, 3> m = m_renderQueue->renderState().m_actualScreen.PtoGMatrix() * s.GtoPMatrix();
m = math::Shift(m, -ptShift);
pDrawer->screen()->blit(m_renderQueue->renderState().m_actualTarget, m);
}
pDrawer->endFrame();
}
void RenderPolicyST::EndFrame(shared_ptr<PaintEvent> const & ev,
ScreenBase const & s)
{
m_renderQueue->renderState().m_mutex->Unlock();
base_t::EndFrame(ev, s);
}
bool RenderPolicyST::IsEmptyModel() const
{
return m_renderQueue->renderState().m_isEmptyModelActual;
}
m2::RectI const RenderPolicyST::OnSize(int w, int h)
{
QueuedRenderPolicy::OnSize(w, h);
m_renderQueue->OnSize(w, h);
m2::PointU pt = m_renderQueue->renderState().coordSystemShift();
return m2::RectI(pt.x, pt.y, pt.x + w, pt.y + h);
}
void RenderPolicyST::StartDrag()
{
m_DoAddCommand = false;
base_t::StartDrag();
}
void RenderPolicyST::StopDrag()
{
m_DoAddCommand = true;
base_t::StopDrag();
}
void RenderPolicyST::StartScale()
{
m_DoAddCommand = false;
base_t::StartScale();
}
void RenderPolicyST::StopScale()
{
m_DoAddCommand = true;
base_t::StartScale();
}

View file

@ -1,50 +1,14 @@
#pragma once
#include "queued_render_policy.hpp"
#include "../yg/screen.hpp"
#include "../base/threaded_list.hpp"
#include "../std/scoped_ptr.hpp"
#include "basic_render_policy.hpp"
class RenderQueue;
class WindowHandle;
class RenderPolicyST : public QueuedRenderPolicy
class RenderPolicyST : public BasicRenderPolicy
{
private:
typedef QueuedRenderPolicy base_t;
scoped_ptr<RenderQueue> m_renderQueue;
bool m_DoAddCommand;
bool m_DoSynchronize;
public:
RenderPolicyST(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
~RenderPolicyST();
void DrawFrame(shared_ptr<PaintEvent> const & paintEvent,
ScreenBase const & screenBase);
void EndFrame(shared_ptr<PaintEvent> const & paintEvent,
ScreenBase const & screenBase);
m2::RectI const OnSize(int w, int h);
bool IsEmptyModel() const;
void StartDrag();
void StopDrag();
void StartScale();
void StopScale();
RenderQueue & GetRenderQueue();
void SetRenderFn(TRenderFn renderFn);
void SetEmptyModelFn(TEmptyModelFn const & checkFn);
};

View file

@ -0,0 +1,147 @@
#include "simple_render_policy.hpp"
#include "events.hpp"
#include "drawer_yg.hpp"
#include "window_handle.hpp"
#include "../yg/info_layer.hpp"
#include "../yg/internal/opengl.hpp"
#include "../yg/skin.hpp"
#include "../indexer/scales.hpp"
#include "../geometry/screenbase.hpp"
#include "../platform/platform.hpp"
SimpleRenderPolicy::SimpleRenderPolicy(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, false, 1)
{
yg::ResourceManager::Params rmp = rmParams;
rmp.selectTexRTFormat();
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(50000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
sizeof(unsigned short),
15,
false,
true,
1,
"primaryStorage",
false,
false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
sizeof(unsigned short),
100,
false,
true,
1,
"smallStorage",
false,
false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
sizeof(unsigned short),
50,
true,
true,
1,
"blitStorage",
false,
false);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
10,
rmp.m_texFormat,
true,
true,
true,
1,
"primaryTexture",
false,
false);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
5,
rmp.m_texFormat,
true,
true,
true,
1,
"fontTexture",
false,
false);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
1,
0);
rmp.m_useSingleThreadedOGL = false;
rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported;
m_resourceManager.reset(new yg::ResourceManager(rmp));
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);
m_resourceManager->addFonts(fonts);
DrawerYG::params_t p;
p.m_frameBuffer = make_shared_ptr(new yg::gl::FrameBuffer(useDefaultFB));
p.m_resourceManager = m_resourceManager;
p.m_dynamicPagesCount = 2;
p.m_textPagesCount = 2;
p.m_glyphCacheID = m_resourceManager->guiThreadGlyphCacheID();
p.m_skinName = GetPlatform().SkinName();
p.m_visualScale = GetPlatform().VisualScale();
p.m_isSynchronized = true;
m_drawer.reset(new DrawerYG(p));
m_windowHandle.reset(new WindowHandle());
m_windowHandle->setUpdatesEnabled(false);
m_windowHandle->setRenderPolicy(this);
m_windowHandle->setVideoTimer(videoTimer);
m_windowHandle->setRenderContext(primaryRC);
}
void SimpleRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
ScreenBase const & s)
{
int scaleEtalonSize = GetPlatform().ScaleEtalonSize();
m2::RectD glbRect;
m2::PointD const pxCenter = s.PixelRect().Center();
s.PtoG(m2::RectD(pxCenter - m2::PointD(scaleEtalonSize / 2, scaleEtalonSize / 2),
pxCenter + m2::PointD(scaleEtalonSize / 2, scaleEtalonSize / 2)),
glbRect);
shared_ptr<yg::InfoLayer> infoLayer(new yg::InfoLayer());
e->drawer()->screen()->setInfoLayer(infoLayer);
e->drawer()->screen()->beginFrame();
e->drawer()->screen()->clear(m_bgColor);
m_renderFn(e, s, s.ClipRect(), s.ClipRect(), scales::GetScaleLevel(glbRect), false);
infoLayer->draw(e->drawer()->screen().get(), math::Identity<double, 3>());
e->drawer()->screen()->resetInfoLayer();
e->drawer()->screen()->endFrame();
}

View file

@ -0,0 +1,15 @@
#pragma once
#include "render_policy.hpp"
class SimpleRenderPolicy : public RenderPolicy
{
public:
SimpleRenderPolicy(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void DrawFrame(shared_ptr<PaintEvent> const & paintEvent,
ScreenBase const & screenBase);
};

View file

@ -1,24 +1,20 @@
#include "../base/SRC_FIRST.hpp"
#include "tiling_render_policy_mt.hpp"
#include "../platform/platform.hpp"
#include "../std/bind.hpp"
#include "../geometry/screenbase.hpp"
#include "../yg/base_texture.hpp"
#include "../yg/internal/opengl.hpp"
#include "drawer_yg.hpp"
#include "events.hpp"
#include "tiling_render_policy_mt.hpp"
#include "window_handle.hpp"
#include "screen_coverage.hpp"
#include "tile_renderer.hpp"
#include "coverage_generator.hpp"
TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, false, GetPlatform().CpuCores())
: BasicTilingRenderPolicy(primaryRC,
false,
GetPlatform().CpuCores())
{
yg::ResourceManager::Params rmp = rmParams;
@ -151,13 +147,20 @@ TilingRenderPolicyMT::~TilingRenderPolicyMT()
{
LOG(LINFO, ("cancelling ResourceManager"));
m_resourceManager->cancel();
m_CoverageGenerator.reset();
m_TileRenderer->ClearCommands();
m_TileRenderer->SetSequenceID(numeric_limits<int>::max());
m_TileRenderer->CancelCommands();
m_TileRenderer->WaitForEmptyAndFinished();
m_TileRenderer.reset();
}
void TilingRenderPolicyMT::SetRenderFn(TRenderFn renderFn)
{
RenderPolicy::SetRenderFn(renderFn);
m_tileRenderer.reset(new TileRenderer(GetPlatform().SkinName(),
m_TileRenderer.reset(new TileRenderer(GetPlatform().SkinName(),
GetPlatform().MaxTilesCount(),
GetPlatform().CpuCores(),
m_bgColor,
@ -167,66 +170,9 @@ void TilingRenderPolicyMT::SetRenderFn(TRenderFn renderFn)
GetPlatform().VisualScale(),
0));
m_coverageGenerator.reset(new CoverageGenerator(m_tileRenderer.get(),
m_CoverageGenerator.reset(new CoverageGenerator(m_TileRenderer.get(),
m_windowHandle,
m_primaryRC,
m_resourceManager,
0));
}
void TilingRenderPolicyMT::BeginFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s)
{
}
void TilingRenderPolicyMT::EndFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s)
{
ScreenCoverage * curCvg = &m_coverageGenerator->CurrentCoverage();
curCvg->EndFrame(e->drawer()->screen().get());
m_coverageGenerator->Mutex().Unlock();
}
void TilingRenderPolicyMT::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & currentScreen)
{
DrawerYG * pDrawer = e->drawer();
pDrawer->beginFrame();
pDrawer->screen()->clear(m_bgColor);
m_coverageGenerator->AddCoverScreenTask(currentScreen, false);
m_coverageGenerator->Mutex().Lock();
ScreenCoverage * curCvg = &m_coverageGenerator->CurrentCoverage();
curCvg->Draw(pDrawer->screen().get(), currentScreen);
m_drawScale = curCvg->GetDrawScale();
pDrawer->endFrame();
}
int TilingRenderPolicyMT::GetDrawScale(ScreenBase const & s) const
{
return m_drawScale;
}
TileRenderer & TilingRenderPolicyMT::GetTileRenderer()
{
return *m_tileRenderer.get();
}
void TilingRenderPolicyMT::StartScale()
{
m_isScaling = true;
}
void TilingRenderPolicyMT::StopScale()
{
m_isScaling = false;
}
bool TilingRenderPolicyMT::IsTiling() const
{
return true;
}

View file

@ -1,13 +1,6 @@
#pragma once
#include "render_policy.hpp"
#include "tile_renderer.hpp"
#include "coverage_generator.hpp"
#include "tiler.hpp"
#include "screen_coverage.hpp"
#include "../yg/info_layer.hpp"
#include "../std/scoped_ptr.hpp"
#include "basic_tiling_render_policy.hpp"
namespace yg
{
@ -20,24 +13,8 @@ namespace yg
class WindowHandle;
class TilingRenderPolicyMT : public RenderPolicy
class TilingRenderPolicyMT : public BasicTilingRenderPolicy
{
private:
scoped_ptr<TileRenderer> m_tileRenderer;
scoped_ptr<CoverageGenerator> m_coverageGenerator;
ScreenBase m_currentScreen;
bool m_isScaling;
int m_drawScale;
protected:
TileRenderer & GetTileRenderer();
public:
TilingRenderPolicyMT(VideoTimer * videoTimer,
@ -47,15 +24,5 @@ public:
~TilingRenderPolicyMT();
void BeginFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
void DrawFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
void EndFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
virtual void StartScale();
virtual void StopScale();
bool IsTiling() const;
int GetDrawScale(ScreenBase const & ) const;
void SetRenderFn(TRenderFn renderFn);
};

View file

@ -1,41 +1,22 @@
#include "../base/SRC_FIRST.hpp"
#include "tiling_render_policy_st.hpp"
#include "drawer_yg.hpp"
#include "../platform/platform.hpp"
#include "../yg/internal/opengl.hpp"
#include "window_handle.hpp"
#include "events.hpp"
#include "screen_coverage.hpp"
#include "../indexer/scales.hpp"
#include "../yg/framebuffer.hpp"
#include "../yg/renderbuffer.hpp"
#include "../yg/resource_manager.hpp"
#include "../yg/base_texture.hpp"
#include "../yg/internal/opengl.hpp"
#include "../platform/platform.hpp"
#include "../base/SRC_FIRST.hpp"
#include "../platform/platform.hpp"
#include "../std/bind.hpp"
#include "../geometry/screenbase.hpp"
#include "../yg/base_texture.hpp"
#include "../yg/internal/opengl.hpp"
#include "queued_renderer.hpp"
#include "tile_renderer.hpp"
#include "coverage_generator.hpp"
TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
bool useDefaultFB,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: QueuedRenderPolicy(GetPlatform().CpuCores() + 1, primaryRC, false, GetPlatform().CpuCores()),
m_drawScale(0),
m_isEmptyModel(false),
m_doRecreateCoverage(false)
: BasicTilingRenderPolicy(primaryRC,
false,
GetPlatform().CpuCores(),
make_shared_ptr(new QueuedRenderer(GetPlatform().CpuCores() + 1)))
{
yg::ResourceManager::Params rmp = rmParams;
@ -89,8 +70,8 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
false,
false);
rmp.m_styleCacheTexturesParams = yg::ResourceManager::TexturePoolParams(1024,
512,
rmp.m_styleCacheTexturesParams = yg::ResourceManager::TexturePoolParams(512,
512 * int(ceil(GetPlatform().VisualScale())),
2,
rmp.m_texFormat,
true,
@ -184,41 +165,39 @@ TilingRenderPolicyST::~TilingRenderPolicyST()
LOG(LINFO, ("deleting TilingRenderPolicyST"));
base_t::CancelQueuedCommands(GetPlatform().CpuCores());
m_QueuedRenderer->CancelQueuedCommands(GetPlatform().CpuCores());
LOG(LINFO, ("reseting coverageGenerator"));
m_coverageGenerator.reset();
m_CoverageGenerator.reset();
/// firstly stop all rendering commands in progress and collect all commands into queues
for (unsigned i = 0; i < GetPlatform().CpuCores(); ++i)
base_t::PrepareQueueCancellation(i);
m_QueuedRenderer->PrepareQueueCancellation(i);
m_tileRenderer->ClearCommands();
m_tileRenderer->SetSequenceID(numeric_limits<int>::max());
m_tileRenderer->CancelCommands();
m_tileRenderer->WaitForEmptyAndFinished();
m_TileRenderer->ClearCommands();
m_TileRenderer->SetSequenceID(numeric_limits<int>::max());
m_TileRenderer->CancelCommands();
m_TileRenderer->WaitForEmptyAndFinished();
/// now we should cancell all collected commands
/// now we should cancel all collected commands
for (unsigned i = 0; i < GetPlatform().CpuCores(); ++i)
base_t::CancelQueuedCommands(i);
m_QueuedRenderer->CancelQueuedCommands(i);
LOG(LINFO, ("reseting tileRenderer"));
m_tileRenderer.reset();
m_TileRenderer.reset();
LOG(LINFO, ("done reseting tileRenderer"));
}
void TilingRenderPolicyST::SetRenderFn(TRenderFn renderFn)
{
RenderPolicy::SetRenderFn(renderFn);
yg::gl::PacketsQueue ** queues = new yg::gl::PacketsQueue*[GetPlatform().CpuCores()];
for (unsigned i = 0; i < GetPlatform().CpuCores(); ++i)
queues[i] = base_t::GetPacketsQueue(i);
queues[i] = m_QueuedRenderer->GetPacketsQueue(i);
m_tileRenderer.reset(new TileRenderer(GetPlatform().SkinName(),
m_TileRenderer.reset(new TileRenderer(GetPlatform().SkinName(),
m_maxTilesCount,
GetPlatform().CpuCores(),
m_bgColor,
@ -230,125 +209,13 @@ void TilingRenderPolicyST::SetRenderFn(TRenderFn renderFn)
delete [] queues;
m_coverageGenerator.reset(new CoverageGenerator(m_tileRenderer.get(),
m_CoverageGenerator.reset(new CoverageGenerator(m_TileRenderer.get(),
m_windowHandle,
m_primaryRC,
m_resourceManager,
base_t::GetPacketsQueue(GetPlatform().CpuCores())
m_QueuedRenderer->GetPacketsQueue(GetPlatform().CpuCores())
));
}
void TilingRenderPolicyST::EndFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s)
{
ScreenCoverage * curCvg = &m_coverageGenerator->CurrentCoverage();
curCvg->EndFrame(e->drawer()->screen().get());
m_coverageGenerator->Mutex().Unlock();
base_t::EndFrame(e, s);
}
void TilingRenderPolicyST::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & currentScreen)
{
base_t::DrawFrame(e, currentScreen);
// yg::gl::g_doLogOGLCalls = true;
DrawerYG * pDrawer = e->drawer();
pDrawer->beginFrame();
pDrawer->screen()->clear(m_bgColor);
bool doForceUpdate = DoForceUpdate();
bool doIntersectInvalidRect = GetInvalidRect().IsIntersect(currentScreen.GlobalRect());
if (doForceUpdate)
m_coverageGenerator->InvalidateTiles(GetInvalidRect(), scales::GetUpperWorldScale() + 1);
m_coverageGenerator->AddCoverScreenTask(currentScreen,
m_doRecreateCoverage || (doForceUpdate && doIntersectInvalidRect));
SetForceUpdate(false);
m_doRecreateCoverage = false;
m_coverageGenerator->Mutex().Lock();
ScreenCoverage * curCvg = &m_coverageGenerator->CurrentCoverage();
curCvg->Draw(pDrawer->screen().get(), currentScreen);
m_drawScale = curCvg->GetDrawScale();
if (!curCvg->IsEmptyDrawingCoverage() || !curCvg->IsPartialCoverage())
m_isEmptyModel = curCvg->IsEmptyDrawingCoverage();
pDrawer->endFrame();
// yg::gl::g_doLogOGLCalls = false;
m_resourceManager->updatePoolState();
}
int TilingRenderPolicyST::GetDrawScale(ScreenBase const & s) const
{
return m_drawScale;
}
TileRenderer & TilingRenderPolicyST::GetTileRenderer()
{
return *m_tileRenderer.get();
}
void TilingRenderPolicyST::StartScale()
{
m_isScaling = true;
m_tileRenderer->SetIsPaused(true);
m_tileRenderer->CancelCommands();
}
void TilingRenderPolicyST::StopScale()
{
m_isScaling = false;
m_tileRenderer->SetIsPaused(false);
m_doRecreateCoverage = true;
RenderPolicy::StopScale();
}
void TilingRenderPolicyST::StartDrag()
{
m_tileRenderer->SetIsPaused(true);
m_tileRenderer->CancelCommands();
}
void TilingRenderPolicyST::StopDrag()
{
m_tileRenderer->SetIsPaused(false);
m_doRecreateCoverage = true;
RenderPolicy::StopDrag();
}
void TilingRenderPolicyST::StartRotate(double a, double timeInSec)
{
m_tileRenderer->SetIsPaused(true);
m_tileRenderer->CancelCommands();
}
void TilingRenderPolicyST::StopRotate(double a, double timeInSec)
{
m_tileRenderer->SetIsPaused(false);
m_doRecreateCoverage = true;
RenderPolicy::StopRotate(a, timeInSec);
}
bool TilingRenderPolicyST::IsTiling() const
{
return true;
}
bool TilingRenderPolicyST::IsEmptyModel() const
{
return m_isEmptyModel;
}

View file

@ -1,51 +1,13 @@
#pragma once
#include "queued_render_policy.hpp"
#include "tile_renderer.hpp"
#include "coverage_generator.hpp"
#include "tiler.hpp"
#include "screen_coverage.hpp"
#include "render_policy.hpp"
#include "basic_tiling_render_policy.hpp"
#include "../yg/info_layer.hpp"
#include "../std/scoped_ptr.hpp"
namespace yg
{
namespace gl
{
class Screen;
class RenderContext;
}
class ResourceManager;
}
class WindowHandle;
class TilingRenderPolicyST : public QueuedRenderPolicy
class TilingRenderPolicyST : public BasicTilingRenderPolicy
{
private:
typedef QueuedRenderPolicy base_t;
scoped_ptr<TileRenderer> m_tileRenderer;
scoped_ptr<CoverageGenerator> m_coverageGenerator;
ScreenBase m_currentScreen;
bool m_isScaling;
int m_maxTilesCount;
int m_drawScale;
bool m_isEmptyModel;
bool m_doRecreateCoverage;
protected:
TileRenderer & GetTileRenderer();
public:
TilingRenderPolicyST(VideoTimer * videoTimer,
@ -55,21 +17,5 @@ public:
~TilingRenderPolicyST();
void DrawFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
void EndFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);
virtual void StartScale();
virtual void StopScale();
virtual void StartDrag();
virtual void StopDrag();
virtual void StartRotate(double a, double timeInSec);
virtual void StopRotate(double a, double timeInSec);
bool IsTiling() const;
bool IsEmptyModel() const;
int GetDrawScale(ScreenBase const & s) const;
void SetRenderFn(TRenderFn renderFn);
};