优化
This commit is contained in:
@@ -8,20 +8,8 @@ namespace YSG {
|
||||
static void notifyRenderTaskDone(PlotPrivate* data) {
|
||||
if(data->mActiveRenderTasks.fetch_sub(1, std::memory_order_acq_rel) == 1) data->mRenderTaskDone.notify_all();
|
||||
}
|
||||
void startAllRenderThread() {
|
||||
Global::instance()->startAllTimeThread();
|
||||
}
|
||||
|
||||
void Plot::bindRenderThread(const QString& threadName) {
|
||||
auto g = Global::instance();
|
||||
if (!g->mTimerThreadMap.contains(threadName)) {
|
||||
auto newThread = new TimerThread;
|
||||
g->mTimerThreadMap[threadName] = newThread;
|
||||
newThread->setObjectName(threadName);
|
||||
}
|
||||
TimerThread* thread = g->mTimerThreadMap[threadName];
|
||||
thread->mPlots.append(this);
|
||||
d->mTimerThread = thread;
|
||||
void startRenderScheduler() {
|
||||
Global::instance()->startRenderScheduler();
|
||||
}
|
||||
|
||||
Plot::Plot() {
|
||||
@@ -29,6 +17,7 @@ namespace YSG {
|
||||
setAttribute(Qt::WA_OpaquePaintEvent, true);
|
||||
setMouseTracking(true);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
Global::instance()->renderScheduler().registerPlot(this);
|
||||
}
|
||||
bool Plot::usePerformanceShower() {
|
||||
return d->mShower;
|
||||
@@ -48,7 +37,7 @@ namespace YSG {
|
||||
Plot::~Plot() {
|
||||
d->mDestroying.store(true, std::memory_order_release);
|
||||
d->mRenderEnabled.store(false, std::memory_order_release);
|
||||
if(d->mTimerThread) d->mTimerThread->removePlot(this);
|
||||
Global::instance()->renderScheduler().removePlot(this);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(d->mRenderTaskMutex);
|
||||
d->mRenderTaskDone.wait(lock, [this]() {
|
||||
@@ -70,11 +59,10 @@ namespace YSG {
|
||||
void Plot::startRender() const {
|
||||
if(d->mDestroying.load(std::memory_order_acquire)) return;
|
||||
d->mRenderEnabled.store(true, std::memory_order_release);
|
||||
if(!d->mTimerThread) return;
|
||||
Plot* self = const_cast<Plot*>(this);
|
||||
PlotPrivate* privateData = d;
|
||||
privateData->mActiveRenderTasks.fetch_add(1, std::memory_order_acq_rel);
|
||||
d->mTimerThread->post([self, privateData]() {
|
||||
Global::instance()->renderScheduler().post([self, privateData]() {
|
||||
PlotPrivate* d = self->d;
|
||||
if(!d->mDestroying.load(std::memory_order_acquire)) {
|
||||
if(d->mRenderTimer) {
|
||||
@@ -90,11 +78,10 @@ namespace YSG {
|
||||
void Plot::pauseRender() const {
|
||||
d->mRenderEnabled.store(false, std::memory_order_release);
|
||||
if(d->mDestroying.load(std::memory_order_acquire)) return;
|
||||
if(!d->mTimerThread) return;
|
||||
Plot* self = const_cast<Plot*>(this);
|
||||
PlotPrivate* privateData = d;
|
||||
privateData->mActiveRenderTasks.fetch_add(1, std::memory_order_acq_rel);
|
||||
d->mTimerThread->post([self, privateData]() {
|
||||
Global::instance()->renderScheduler().post([self, privateData]() {
|
||||
PlotPrivate* d = self->d;
|
||||
if(!d->mDestroying.load(std::memory_order_acquire)) {
|
||||
if(d->mRenderTimer) {
|
||||
@@ -127,10 +114,11 @@ namespace YSG {
|
||||
d->mPaintBufferAcquireMode.store(mode, std::memory_order_release);
|
||||
}
|
||||
void Plot::submitRender() {
|
||||
if(d->mTimerThread && d->mTimerThread->isRunning() && !d->mTimerThread->isSchedulerThread()) {
|
||||
RenderScheduler& scheduler = Global::instance()->renderScheduler();
|
||||
if(!scheduler.isSchedulerThread()) {
|
||||
PlotPrivate* privateData = d;
|
||||
privateData->mActiveRenderTasks.fetch_add(1, std::memory_order_acq_rel);
|
||||
d->mTimerThread->post([this, privateData]() {
|
||||
scheduler.post([this, privateData]() {
|
||||
if(!privateData->mDestroying.load(std::memory_order_acquire)) submitRender();
|
||||
notifyRenderTaskDone(privateData);
|
||||
});
|
||||
@@ -180,33 +168,26 @@ namespace YSG {
|
||||
RenderAble::ColorBuffer* color = colorLease.buffer;
|
||||
QColor background = d->mBackground;
|
||||
std::uint64_t version = pipeline.renderStateVersion;
|
||||
TimerThread* thread = d->mTimerThread;
|
||||
pipeline.jobState = RenderAble::JobState::Running;
|
||||
if(thread) {
|
||||
PlotPrivate* privateData = d;
|
||||
privateData->mActiveRenderTasks.fetch_add(1, std::memory_order_acq_rel);
|
||||
thread->postCpu([this, privateData, colorLease, color, renderSize, background, version, thread]() {
|
||||
if(privateData->mDestroying.load(std::memory_order_acquire)) {
|
||||
privateData->mPipeline.unmarkColor(colorLease);
|
||||
notifyRenderTaskDone(privateData);
|
||||
return;
|
||||
}
|
||||
renderColor(color, renderSize, background, version);
|
||||
PlotPrivate* privateData = d;
|
||||
privateData->mActiveRenderTasks.fetch_add(1, std::memory_order_acq_rel);
|
||||
scheduler.postCpu([this, privateData, colorLease, color, renderSize, background, version]() {
|
||||
if(privateData->mDestroying.load(std::memory_order_acquire)) {
|
||||
privateData->mPipeline.unmarkColor(colorLease);
|
||||
if(privateData->mDestroying.load(std::memory_order_acquire)) {
|
||||
notifyRenderTaskDone(privateData);
|
||||
return;
|
||||
}
|
||||
thread->post([this, privateData]() {
|
||||
if(!privateData->mDestroying.load(std::memory_order_acquire)) finishRender();
|
||||
notifyRenderTaskDone(privateData);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
notifyRenderTaskDone(privateData);
|
||||
return;
|
||||
}
|
||||
renderColor(color, renderSize, background, version);
|
||||
pipeline.unmarkColor(colorLease);
|
||||
finishRender();
|
||||
}
|
||||
privateData->mPipeline.unmarkColor(colorLease);
|
||||
if(privateData->mDestroying.load(std::memory_order_acquire)) {
|
||||
notifyRenderTaskDone(privateData);
|
||||
return;
|
||||
}
|
||||
Global::instance()->renderScheduler().post([this, privateData]() {
|
||||
if(!privateData->mDestroying.load(std::memory_order_acquire)) finishRender();
|
||||
notifyRenderTaskDone(privateData);
|
||||
});
|
||||
});
|
||||
}
|
||||
void Plot::finishRender() {
|
||||
if(d->mDestroying.load(std::memory_order_acquire)) return;
|
||||
@@ -270,10 +251,9 @@ namespace YSG {
|
||||
}
|
||||
void Plot::requestRender() {
|
||||
if(d->mDestroying.load(std::memory_order_acquire)) return;
|
||||
if(!d->mTimerThread) return;
|
||||
PlotPrivate* privateData = d;
|
||||
privateData->mActiveRenderTasks.fetch_add(1, std::memory_order_acq_rel);
|
||||
d->mTimerThread->post([this, privateData]() {
|
||||
Global::instance()->renderScheduler().post([this, privateData]() {
|
||||
if(!d->mDestroying.load(std::memory_order_acquire)) submitRender();
|
||||
notifyRenderTaskDone(privateData);
|
||||
});
|
||||
@@ -302,16 +282,12 @@ namespace YSG {
|
||||
QSize renderSize = e->size();
|
||||
d->mPendingRenderWidth.store(renderSize.width(), std::memory_order_release);
|
||||
d->mPendingRenderHeight.store(renderSize.height(), std::memory_order_release);
|
||||
if(d->mTimerThread && d->mTimerThread->isRunning()) {
|
||||
PlotPrivate* privateData = d;
|
||||
privateData->mActiveRenderTasks.fetch_add(1, std::memory_order_acq_rel);
|
||||
d->mTimerThread->post([privateData, renderSize]() {
|
||||
if(!privateData->mDestroying.load(std::memory_order_acquire)) privateData->mRenderSize = renderSize;
|
||||
notifyRenderTaskDone(privateData);
|
||||
});
|
||||
} else {
|
||||
d->mRenderSize = renderSize;
|
||||
}
|
||||
PlotPrivate* privateData = d;
|
||||
privateData->mActiveRenderTasks.fetch_add(1, std::memory_order_acq_rel);
|
||||
Global::instance()->renderScheduler().post([privateData, renderSize]() {
|
||||
if(!privateData->mDestroying.load(std::memory_order_acquire)) privateData->mRenderSize = renderSize;
|
||||
notifyRenderTaskDone(privateData);
|
||||
});
|
||||
if(mFirstResize) {
|
||||
for(Layer* layer : mLayerList) {
|
||||
for(RenderAble* able : layer->mRenderAbles) {
|
||||
|
||||
Reference in New Issue
Block a user