Commit 4f264629 authored by Alexandre Lision's avatar Alexandre Lision Committed by gerrit2

images: cache default photo

It takes up to 40% of memory when app is loading
This image is now cached in a QHash with a key computed from the size
asked.

Change-Id: Iebb14e9c38dbd6e9057c9fbe5a366542fefffca5
Tuleap: #663
parent 88ee6cc1
......@@ -21,13 +21,14 @@
//Qt
#import <QSize>
#import <QtGui/qpixmap.h>
//Ring
#import <interfaces/pixmapmanipulatori.h>
#import <call.h>
class Person;
class QPixmap;
class QString;
namespace Interfaces {
......@@ -61,6 +62,8 @@ namespace Interfaces {
QPixmap drawDefaultUserPixmap(const QSize& size, bool displayPresence = false, bool isPresent = false);
CGImageRef resizeCGImage(CGImageRef image, const QSize& size);
QHash<QString, QPixmap> m_hDefaultUserPixmap;
/**
* Return a version of size destSize centered of the bigger photo
*/
......
......@@ -26,6 +26,7 @@
#import <QBuffer>
#import <QtGui/QColor>
#import <QtGui/QPainter>
#import <QHash>
#import <QtGui/QBitmap>
#import <QtWidgets/QApplication>
#import <QtGui/QImage>
......@@ -40,10 +41,7 @@
namespace Interfaces {
ImageManipulationDelegate::ImageManipulationDelegate()
{
}
ImageManipulationDelegate::ImageManipulationDelegate() {}
QVariant ImageManipulationDelegate::contactPhoto(Person* c, const QSize& size, bool displayPresence) {
const int radius = size.height() / 2;
......@@ -164,6 +162,12 @@ namespace Interfaces {
}
QPixmap ImageManipulationDelegate::drawDefaultUserPixmap(const QSize& size, bool displayPresence, bool isPresent) {
auto index = QStringLiteral("%1%2").arg(size.width()).arg(size.height());
if (m_hDefaultUserPixmap.contains(index)) {
return m_hDefaultUserPixmap.value(index);
}
// create the image somehow, load from file, draw into it...
auto sourceImgRef = CGImageSourceCreateWithData((__bridge CFDataRef)[[NSImage imageNamed:@"default_user_icon"] TIFFRepresentation], NULL);
auto imgRef = CGImageSourceCreateImageAtIndex(sourceImgRef, 0, NULL);
......@@ -171,6 +175,8 @@ namespace Interfaces {
CFRelease(sourceImgRef);
CFRelease(imgRef);
m_hDefaultUserPixmap.insert(index, finalpxm);
return finalpxm;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment