From 365b57ace417431d4c8e971357e356fc692cae81 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Tue, 15 Jan 2013 15:55:39 +1000 Subject: [PATCH] Graphics snapshot system broken, added FrameBufferObject & PixelBuffer methods --- Graphs/gGraphView.cpp | 84 ++++++++++++++++++++++++++++++++++++++++- Graphs/gGraphView.h | 23 ++++++++--- daily.cpp | 14 ++++--- docs/release_notes.html | 19 ++-------- mainwindow.cpp | 22 ++++++++--- 5 files changed, 128 insertions(+), 34 deletions(-) diff --git a/Graphs/gGraphView.cpp b/Graphs/gGraphView.cpp index f5bcb9cf..2b5ad6f5 100644 --- a/Graphs/gGraphView.cpp +++ b/Graphs/gGraphView.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include "mainwindow.h" #include "Graphs/gYAxis.h" @@ -1770,11 +1772,79 @@ Layer * gGraph::getLineChart() return NULL; } +// QTBUG-24710 pixmaps might not be freeing properly.. +QPixmap gGraphView::pbRenderPixmap(int w,int h) +{ + QPixmap pm=QPixmap(); + QGLFormat pbufferFormat = format(); + QGLPixelBuffer pbuffer(w,h,pbufferFormat,this); + + if (pbuffer.isValid()) { + pbuffer.makeCurrent(); + resizeGL(w,h); + initializeGL(); + paintGL(); + QImage image=pbuffer.toImage(); + pm=QPixmap::fromImage(image); + pbuffer.doneCurrent(); + } + return pm; + +} + +//MW: ick globals, but I want a system wide framebuffer of decent proprotions.. +bool fbo_unsupported=false; +QGLFramebufferObject *fbo=NULL; +const int max_fbo_width=2048; +const int max_fbo_height=2048; + +QPixmap gGraphView::fboRenderPixmap(int w,int h) +{ + QPixmap pm=QPixmap(); + + if (fbo_unsupported) + return pm; + + + if ((w > max_fbo_width) || (h > max_fbo_height)) { + qWarning() << "gGraphView::fboRenderPixmap called with dimensiopns exceeding maximum frame buffer object size"; + return pm; + } + + if (!fbo) { + fbo=new QGLFramebufferObject(max_fbo_width,max_fbo_height,QGLFramebufferObject::NoAttachment); + } + + if (fbo && fbo->isValid()) { + makeCurrent(); + if (fbo->bind()) { + initializeGL(); + resizeGL(w,h); + paintGL(); + glFlush(); + //QImage img=grabFrameBuffer(true); + fbo->release(); + + // Copy just the section of the image (remember openGL draws from the bottom up) + pm=QPixmap::fromImage(fbo->toImage()).copy(0,max_fbo_height-h,w,h); + doneCurrent(); + } + } else { + delete fbo; + fbo=NULL; + fbo_unsupported=true; + } + + return pm; +} + QPixmap gGraph::renderPixmap(int w, int h, bool printing) { + QPixmap pm=QPixmap(); gGraphView *sg=mainwin->snapshotGraph(); - if (!sg) return QPixmap(); + if (!sg) + return QPixmap(); QFont * _defaultfont=defaultfont; QFont * _mediumfont=mediumfont; @@ -1815,8 +1885,18 @@ QPixmap gGraph::renderPixmap(int w, int h, bool printing) sg->setScaleY(1.0); - QPixmap pm=sg->renderPixmap(w,h,false); + //sg->makeCurrent(); + pm=sg->fboRenderPixmap(w,h); + if (pm.isNull()) { + // this one gives nags + pm=sg->renderPixmap(w,h,false); + } else if (pm.isNull()) { // not sure if this will work with printing + qDebug() << "Had to use PixelBuffer for snapshots\n"; + pm=sg->pbRenderPixmap(w,h); + } + + //sg->doneCurrent(); sg->trashGraphs(); m_graphview=tgv; diff --git a/Graphs/gGraphView.h b/Graphs/gGraphView.h index 3e1101b3..e3d5d6a7 100644 --- a/Graphs/gGraphView.h +++ b/Graphs/gGraphView.h @@ -955,7 +955,24 @@ public: //! \brief Trash all graph objects listed (without destroying Graph contents) void trashGraphs(); + + //! \brief Use a QGLFrameBufferObject to render to a pixmap + QPixmap fboRenderPixmap(int w,int h); + + //! \brief Use a QGLPixelBuffer to render to a pixmap + QPixmap pbRenderPixmap(int w,int h); + protected: + //! \brief Set up the OpenGL basics for the QGLWidget underneath + virtual void initializeGL(); + + //! \brief Resize the OpenGL ViewPort prior to redrawing + virtual void resizeGL(int width, int height); + + //! \brief The heart of the OpenGL drawing code + virtual void paintGL(); + + Day * m_day; //! \brief Calculates the sum of all graph heights @@ -964,17 +981,11 @@ protected: //! \brief Calculates the sum of all graph heights, taking scaling into consideration float scaleHeight(); - //! \brief Set up the OpenGL basics for the QGLWidget underneath - virtual void initializeGL(); - //! \brief The heart of the OpenGL drawing code - virtual void paintGL(); //! \brief Graph drawing routines, returns true if there weren't any graphs to draw bool renderGraphs(); - //! \brief Resize the OpenGL ViewPort prior to redrawing - virtual void resizeGL(int width, int height); //! \brief Update the OpenGL area when the screen is resized virtual void resizeEvent(QResizeEvent *); diff --git a/daily.cpp b/daily.cpp index 26582bee..f336db97 100644 --- a/daily.cpp +++ b/daily.cpp @@ -917,11 +917,15 @@ void Daily::Load(QDate date) GAHI->setShowTitle(false); QPixmap pixmap=GAHI->renderPixmap(150,150,false); - QByteArray byteArray; - QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray - buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); - html += "\n"; + if (!pixmap.isNull()) { + QByteArray byteArray; + QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray + buffer.open(QIODevice::WriteOnly); + pixmap.save(&buffer, "PNG"); + html += "\n"; + } else { + html += "Unable to display Pie Chart on this system\n"; + } } else { html += "\n"; } diff --git a/docs/release_notes.html b/docs/release_notes.html index 88b3ef73..2a8d4cf9 100644 --- a/docs/release_notes.html +++ b/docs/release_notes.html @@ -1,25 +1,14 @@ -

SleepyHead v0.9.2 BETA

+

SleepyHead v0.9.3 BETA

Release Notes

-

Hi There!

-

This is just a minor update, but it added some new functionality to the auto-updater.

+

Better late than never!

+

It's Bug fixing time. A huge shout out of appreciation to Rich Freeman for his help with this one.

New features & bugs fixes in this Update:
-
  • Auto-Updater test for Windows & Mac Platforms
  • -
  • Adds Total Leaks Overview chart for PRS1 Users.
  • -
  • Preliminary ZEO CSV Support, and simple SleepStage line graph
  • -
  • Fixes Overview AHI chart showing "No Data" on 0.00 days.
  • -
  • Fixes crash after using Preferences before importing first data.
  • -
  • Fixes first minute of Resp. Rate & Minute Vent calcs not showing data. (You will have to Data->Advanced->Purge CPAP Data and then reimport if you want this, as recalc won't do it)
  • -
  • Cursor up/down zoom did not take into account hidden graphs
  • +
  • Philips Respironics '60 series' support
  • -

    Would you like to help test breaky stuff?

    -

    Advanced users who are willing, can now help test future updates, so we can hopefully avoid unleashing unintentonally buggy versions on everyone else.

    -

    There is an option in General Preferences that tells the updater to look at potentially breaky experimental & test builds.

    -

    If your experiencing a specific bug or problem I might occasionally ask you to switch this setting on so I can deliver a custom fix for you to test.

    -

    Please always read the release notes carefully before accepting an update with experimental/test builds switched on.

    Sleep Well, and have fun!

    Mark Watkins (JediMark)

    diff --git a/mainwindow.cpp b/mainwindow.cpp index 4ff278a4..e3d9af52 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -241,7 +241,9 @@ void MainWindow::Startup() // profile is a global variable set in main after login PROFILE.LoadMachineData(); - SnapshotGraph=new gGraphView(this); //daily->graphView()); + SnapshotGraph=new gGraphView(this,daily->graphView()); + + SnapshotGraph->setFormat(daily->graphView()->format()); //SnapshotGraph->setMaximumSize(1024,512); //SnapshotGraph->setMinimumSize(1024,512); SnapshotGraph->hide(); @@ -1894,7 +1896,9 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date) } else { ebp=QPixmap(":/icons/smileyface.png"); } - painter.drawPixmap(virt_width-piesize,bounds.height(),piesize,piesize,ebp); + if (!ebp.isNull()) { + painter.drawPixmap(virt_width-piesize,bounds.height(),piesize,piesize,ebp); + } getDaily()->eventBreakdownPie()->setShowTitle(true); cpapinfo+="\n\n"; @@ -2117,6 +2121,7 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date) first=true; if (page > pages) break; + if (!printer->newPage()) { qWarning("failed in flushing page to disk, disk full?"); break; @@ -2155,14 +2160,19 @@ void MainWindow::PrintReport(gGraphView *gv,QString name, QDate date) int tmb=g->m_marginbottom; g->m_marginbottom=0; - //g->showTitle(false); - QPixmap pm=g->renderPixmap(virt_width,full_graph_height-normal_height,1);//fscale); - //g->showTitle(true); + //painter.beginNativePainting(); + //g->showTitle(false); + int hhh=full_graph_height-normal_height; + QPixmap pm(virt_width,hhh); //full_graph_height=g->renderPixmap(virt_width,full_graph_height-normal_height,1);//fscale); + //g->showTitle(true); + //painter.endNativePainting(); g->m_marginbottom=tmb; PROFILE.appearance->setAntiAliasing(aa_setting); - painter.drawPixmap(0,top,virt_width,full_graph_height-normal_height,pm); + if (!pm.isNull()) { + painter.drawPixmap(0,top,virt_width,full_graph_height-normal_height,pm); + } top+=full_graph_height; gcnt++;