From a46a16738c0e8799b21b25eff789337c812d881b Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 12 Apr 2012 11:26:32 -0300 Subject: [PATCH] performance improvement, lock free render --- src/framework/CMakeLists.txt | 4 ---- src/framework/graphics/painter.cpp | 18 +++++++----------- src/framework/graphics/painter.h | 8 ++++---- src/framework/platform/x11window.cpp | 12 ++++++++++++ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 47844ed4..0cf5b562 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -94,10 +94,6 @@ IF(WIN32) ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/win32crashhandler.cpp) - IF(CRASH_HANDLER) - SET(ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} imagehlp) - ENDIF() - IF(WINDOWS_CONSOLE) MESSAGE(STATUS "Windows console: ON") ELSE() diff --git a/src/framework/graphics/painter.cpp b/src/framework/graphics/painter.cpp index 1ca8c4ad..7dcf68c9 100644 --- a/src/framework/graphics/painter.cpp +++ b/src/framework/graphics/painter.cpp @@ -35,6 +35,7 @@ void Painter::init() setColor(Color::white); setOpacity(1.0f); setCompositionMode(CompositionMode_Normal); + releaseCustomProgram(); m_drawTexturedProgram = PainterShaderProgramPtr(new PainterShaderProgram); m_drawTexturedProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader); @@ -53,7 +54,7 @@ void Painter::terminate() m_drawSolidColorProgram.reset(); } -void Painter::drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode) +void Painter::drawProgram(PainterShaderProgram *program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode) { if(coordsBuffer.getVertexCount() == 0) return; @@ -66,7 +67,7 @@ void Painter::drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer& void Painter::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture) { - PainterShaderProgramPtr& program = m_customProgram ? m_customProgram : m_drawTexturedProgram; + PainterShaderProgram *program = m_customProgram ? m_customProgram : m_drawTexturedProgram.get(); program->setTexture(texture); drawProgram(program, coordsBuffer); } @@ -78,7 +79,7 @@ void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture, cons m_coordsBuffer.clear(); m_coordsBuffer.addQuad(dest, src); - PainterShaderProgramPtr& program = m_customProgram ? m_customProgram : m_drawTexturedProgram; + PainterShaderProgram *program = m_customProgram ? m_customProgram : m_drawTexturedProgram.get(); program->setTexture(texture); drawProgram(program, m_coordsBuffer, PainterShaderProgram::TriangleStrip); } @@ -100,7 +101,7 @@ void Painter::drawFilledRect(const Rect& dest) m_coordsBuffer.clear(); m_coordsBuffer.addRect(dest); - drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram, m_coordsBuffer); + drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram.get(), m_coordsBuffer); } void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth) @@ -110,12 +111,7 @@ void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth) m_coordsBuffer.clear(); m_coordsBuffer.addBoudingRect(dest, innerLineWidth); - drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram, m_coordsBuffer); -} - -void Painter::setCustomProgram(const PainterShaderProgramPtr& program) -{ - m_customProgram = program; + drawProgram(m_customProgram ? m_customProgram : m_drawSolidColorProgram.get(), m_coordsBuffer); } void Painter::setCompositionMode(Painter::CompositionMode compositionMode) @@ -172,7 +168,7 @@ void Painter::saveAndResetState() void Painter::restoreSavedState() { - setCustomProgram(m_oldCustomProgram); + m_customProgram = m_oldCustomProgram; setColor(m_oldColor); setOpacity(m_oldOpacity); setCompositionMode(m_oldCompostionMode); diff --git a/src/framework/graphics/painter.h b/src/framework/graphics/painter.h index efdd0575..0ceb0133 100644 --- a/src/framework/graphics/painter.h +++ b/src/framework/graphics/painter.h @@ -43,7 +43,7 @@ public: void init(); void terminate(); - void drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode = PainterShaderProgram::Triangles); + void drawProgram(PainterShaderProgram *program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode = PainterShaderProgram::Triangles); void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture); void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src); void drawTexturedRect(const Rect& dest, const TexturePtr& texture) { drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize())); } @@ -61,7 +61,7 @@ public: Rect getClipRect() { return m_clipRect; } void resetClipRect() { setClipRect(Rect()); } - void setCustomProgram(const PainterShaderProgramPtr& program); + void setCustomProgram(const PainterShaderProgramPtr& program) { m_customProgram = program.get(); } void releaseCustomProgram() { m_customProgram = nullptr; } void setCompositionMode(CompositionMode compositionMode); void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); } @@ -75,7 +75,7 @@ public: private: PainterShaderProgramPtr m_drawTexturedProgram; PainterShaderProgramPtr m_drawSolidColorProgram; - PainterShaderProgramPtr m_customProgram; + PainterShaderProgram *m_customProgram; Matrix3 m_projectionMatrix; Color m_color; float m_opacity; @@ -83,7 +83,7 @@ private: CoordsBuffer m_coordsBuffer; Rect m_clipRect; - PainterShaderProgramPtr m_oldCustomProgram; + PainterShaderProgram *m_oldCustomProgram; Matrix3 m_oldProjectionMatrix; Color m_oldColor; float m_oldOpacity; diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index b08ef1a3..e72178ce 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -793,12 +793,24 @@ void X11Window::poll() void X11Window::swapBuffers() { +#if 0 + auto now = std::chrono::high_resolution_clock::now(); + auto gpuStart = now; + static decltype(now) cpuStart; + int cpu = std::chrono::duration_cast(now - cpuStart).count(); +#endif #ifndef OPENGL_ES2 glFinish(); glXSwapBuffers(m_display, m_window); #else eglSwapBuffers(m_eglDisplay, m_eglSurface); #endif +#if 0 + now = std::chrono::high_resolution_clock::now(); + int gpu = std::chrono::duration_cast(now - gpuStart).count(); + cpuStart = now; + dump << "cpu" << cpu << "gpu" << gpu; +#endif } void X11Window::showMouse()