diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2014-09-10 16:32:05 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2014-09-10 17:10:46 +0100 |
commit | d7d05136003d1d3adf74285ea1d52a60caaaf763 (patch) | |
tree | 816466be95d6ccb6822b8cadeedb30a1549f23f4 | |
parent | 3383fd7b229a9d78044231bfb5ccca256fe400a2 (diff) |
Re-factor ~inexcusible copy/paste coding away.
Change-Id: I2ad27cb09031dfadaa628939c191ccc5d88ecffe
-rw-r--r-- | chart2/source/view/charttypes/GL3DBarChart.cxx | 67 | ||||
-rw-r--r-- | chart2/source/view/inc/GL3DBarChart.hxx | 2 |
2 files changed, 32 insertions, 37 deletions
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index cd03a38b27ab..cc8ab34e9ff8 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -546,8 +546,7 @@ GL3DBarChart::~GL3DBarChart() mbRenderDie = true; } - if(mpRenderThread.is()) - mpRenderThread->join(); + joinRenderThread(); if(mbValidContext && mpWindow) mpWindow->setRenderer(NULL); @@ -776,30 +775,43 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer mpRenderer->SetScrollSpeed((float)(BAR_SIZE_X + BAR_DISTANCE_X) / (float)miScrollRate); mpRenderer->SetScrollDistance((float)(BAR_SIZE_X + BAR_DISTANCE_X)); } - Size aSize = mpWindow->GetSizePixel(); - mpWindow->getContext().setWinSize(aSize); - mpRenderThread = rtl::Reference<RenderThread>(new RenderBenchMarkThread(this)); - mpWindow->getContext().resetCurrent(); - mpRenderThread->launch(); + spawnRenderThread(new RenderBenchMarkThread(this)); } miDataUpdateCounter++; maHistoryCounter++; mbNeedsNewRender = true; } -void GL3DBarChart::update() +void GL3DBarChart::joinRenderThread() { - if (mbBenchMarkMode) - return; if(mpRenderThread.is()) + { + // FIXME: badly want to assert that we don't + // hold the mutex here ... but can't API-wise. mpRenderThread->join(); + } +} + +void GL3DBarChart::spawnRenderThread(RenderThread *pThread) +{ + joinRenderThread(); // not holding maMutex + + osl::MutexGuard aGuard(maMutex); + Size aSize = mpWindow->GetSizePixel(); mpWindow->getContext().setWinSize(aSize); - mpRenderThread = rtl::Reference<RenderThread>(new RenderOneFrameThread(this)); + mpRenderThread = rtl::Reference<RenderThread>(pThread); mpWindow->getContext().resetCurrent(); mpRenderThread->launch(); } +void GL3DBarChart::update() +{ + if (mbBenchMarkMode) + return; + spawnRenderThread(new RenderOneFrameThread(this)); +} + namespace { class PickingModeSetter @@ -839,15 +851,7 @@ void GL3DBarChart::moveToDefault() return; } - if(mpRenderThread.is()) - mpRenderThread->join(); - - osl::MutexGuard aGuard(maMutex); - Size aSize = mpWindow->GetSizePixel(); - mpWindow->getContext().setWinSize(aSize); - mpRenderThread = rtl::Reference<RenderThread>(new RenderAnimationThread(this, maCameraPosition, maDefaultCameraPosition, STEPS)); - mpWindow->getContext().resetCurrent(); - mpRenderThread->launch(); + spawnRenderThread(new RenderAnimationThread(this, maCameraPosition, maDefaultCameraPosition, STEPS)); /* * TODO: moggi: add to thread @@ -891,7 +895,7 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons) { PickingModeSetter aPickingModeSetter(mpRenderer.get()); update(); - mpRenderThread->join(); + joinRenderThread(); nId = mpRenderer->GetPixelColorFromPoint(rPos.X(), rPos.Y()); } // we need this update here to render one frame without picking mode being set @@ -916,11 +920,9 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons) glm::vec3 aTargetPosition = rBarInfo.maPos; aTargetPosition.z += 240; aTargetPosition.y += BAR_SIZE_Y / 2.0f; - Size aSize = mpWindow->GetSizePixel(); - mpWindow->getContext().setWinSize(aSize); - mpRenderThread = rtl::Reference<RenderThread>(new RenderAnimationThread(this, maCameraPosition, aTargetPosition, STEPS)); - mpWindow->getContext().resetCurrent(); - mpRenderThread->launch(); + + spawnRenderThread(new RenderAnimationThread(this, maCameraPosition, + aTargetPosition, STEPS)); /* * TODO: moggi: add to thread @@ -1002,17 +1004,8 @@ void GL3DBarChart::moveToCorner() return; } - if(mpRenderThread.is()) - mpRenderThread->join(); - - osl::MutexGuard aGuard(maMutex); - - Size aSize = mpWindow->GetSizePixel(); - mpWindow->getContext().setWinSize(aSize); - mpRenderThread = rtl::Reference<RenderThread>(new RenderAnimationThread(this, maCameraPosition, - getCornerPosition(mnCornerId), STEPS)); - mpWindow->getContext().resetCurrent(); - mpRenderThread->launch(); + spawnRenderThread(new RenderAnimationThread(this, maCameraPosition, + getCornerPosition(mnCornerId), STEPS)); // TODO: moggi: add to thread // maStepDirection = (glm::vec3(mnMaxX/2.0f, mnMaxY/2.0f, 0) - maCameraDirection)/ float(mnStepsTotal); diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx index 11d7eeb7aff7..6da88c120790 100644 --- a/chart2/source/view/inc/GL3DBarChart.hxx +++ b/chart2/source/view/inc/GL3DBarChart.hxx @@ -85,6 +85,8 @@ public: private: + void spawnRenderThread(RenderThread *pThread); + void joinRenderThread(); void moveToCorner(); void moveToDefault(); glm::vec3 getCornerPosition(sal_Int8 nCornerId); |