~artmello/gallery-app/gallery-app-convergence_fullscreen

« back to all changes in this revision

Viewing changes to src/medialoader/gallery-standard-image-provider.h

  • Committer: Sergio Schvezov
  • Date: 2014-01-11 21:59:30 UTC
  • mto: (904.1.3 gallery-app-click)
  • mto: This revision was merged to the branch mainline in revision 919.
  • Revision ID: sergio.schvezov@canonical.com-20140111215930-p1qkqp19n3ikwwvy
Adding script to easily build click package

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 * Lucas Beeler <lucas@yorba.org>
 
18
 * Jim Nelson <jim@yorba.org>
 
19
*/
 
20
 
 
21
#ifndef GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_
 
22
#define GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_
 
23
 
 
24
// util
 
25
#include "orientation.h"
 
26
 
 
27
#include <QFileInfo>
 
28
#include <QImage>
 
29
#include <QMap>
 
30
#include <QMutex>
 
31
#include <QObject>
 
32
#include <QQuickImageProvider>
 
33
#include <QSize>
 
34
#include <QString>
 
35
#include <QUrl>
 
36
 
 
37
class PreviewManager;
 
38
 
 
39
/*!
 
40
 * Gallery uses a custom image provider for three reasons:
 
41
 *
 
42
 * 1. QML's image loader does not respect EXIF orientation.  This provider will
 
43
 *    rotate and mirror the image as necessary.
 
44
 *
 
45
 * 2. QML's image caching appears to be directly related to image size (scaling)
 
46
 *    which leads to thrashing when animating a thumbnail or loading images at
 
47
 *    various sizes (such as in the album viewer versus the photo viewer).
 
48
 *    The strategy here is to cache the largest requested size of the image
 
49
 *    and allow QML to downscale it as necessary.  This minimizes expensive
 
50
 *    JPEG load-and-decodes.
 
51
 *
 
52
 * 3. Logging (enabled with --log-image-loading) allows for monitoring of
 
53
 *    all image I/O, useful when debugging and optimizing.
 
54
 */
 
55
class GalleryStandardImageProvider : public QObject, public QQuickImageProvider
 
56
{
 
57
    Q_OBJECT
 
58
 
 
59
public:
 
60
    static const char* PROVIDER_ID;
 
61
    static const char* PROVIDER_ID_SCHEME;
 
62
 
 
63
    static const char* REVISION_PARAM_NAME;
 
64
    static const char* ORIENTATION_PARAM_NAME;
 
65
 
 
66
    static const char* SIZE_KEY;
 
67
 
 
68
    GalleryStandardImageProvider();
 
69
    virtual ~GalleryStandardImageProvider();
 
70
 
 
71
    static QUrl toURL(const QFileInfo& file);
 
72
 
 
73
    virtual QImage requestImage(const QString& id, QSize* size,
 
74
                                const QSize& requestedSize);
 
75
 
 
76
    void setPreviewManager(PreviewManager* previewManager);
 
77
    void setLogging(bool enableLogging);
 
78
    void setMaxLoadResolution(int resolution);
 
79
 
 
80
private:
 
81
    class CachedImage {
 
82
    public:
 
83
        const QString id;
 
84
        const QUrl uri;
 
85
        const QString file;
 
86
        QMutex imageMutex;
 
87
 
 
88
        // these fields should only be accessed when imageMutex_ is locked
 
89
        bool hasOrientation;
 
90
        QImage image;
 
91
        QSize fullSize;
 
92
        Orientation orientation;
 
93
 
 
94
        // the following should only be accessed when cacheMutex_ is locked; the
 
95
        // counter controls removing a CachedImage entry from the cache table
 
96
        int inUseCount;
 
97
        uint byteCount;
 
98
 
 
99
        CachedImage(const QString& fileId, const QString& filename);
 
100
 
 
101
        void storeImage(const QImage& newImage, const QSize& newFullSize,
 
102
                        Orientation newOrientation);
 
103
        bool isFullSized() const;
 
104
        bool isReady() const;
 
105
        bool isCacheHit(const QSize& requestedSize) const;
 
106
    };
 
107
 
 
108
    QMap<QString, CachedImage*> m_cache;
 
109
    QList<QString> m_fifo;
 
110
    QMutex m_cacheMutex;
 
111
    long m_cachedBytes;
 
112
    PreviewManager* m_previewManager;
 
113
    bool m_logImageLoading;
 
114
    int m_maxLoadResolution;
 
115
 
 
116
    static QSize orientSize(const QSize& size, Orientation orientation);
 
117
 
 
118
    CachedImage* claimCachedImageEntry(const QString& id, QString& loggingStr);
 
119
 
 
120
    QImage fetchCachedImage(CachedImage* cachedImage, const QSize& requestedSize,
 
121
                              uint* bytesLoaded, QString& loggingStr);
 
122
 
 
123
    void releaseCachedImageEntry(CachedImage* cachedImage, uint bytesLoaded,
 
124
                                    long* currentCachedBytes, int* currentCacheEntries);
 
125
 
 
126
    QString idToFile(const QString& id) const;
 
127
 
 
128
    //Allow our test access to private variables.
 
129
    friend class tst_GalleryStandardImageProvider;
 
130
};
 
131
 
 
132
#endif // GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_