fbaff0b3e96cdaeb11486ce2d6809c9fa9737205
[harmattan/cameraplus] / lib / qtcamviewfinderrenderermeego.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef QT_CAM_VIEWFINDER_RENDERER_MEEGO_H
24 #define QT_CAM_VIEWFINDER_RENDERER_MEEGO_H
25
26 #include "qtcamviewfinderrenderer.h"
27 #include <QImage>
28 #include <QMutex>
29 #include <QMatrix4x4>
30 #include <GLES2/gl2.h>
31 #include <EGL/egl.h>
32
33 class QGLShaderProgram;
34
35 class QtCamViewfinderRendererMeeGo : public QtCamViewfinderRenderer {
36   Q_OBJECT
37
38 public:
39   Q_INVOKABLE QtCamViewfinderRendererMeeGo(QtCamConfig *config, QObject *parent = 0);
40
41   ~QtCamViewfinderRendererMeeGo();
42
43   virtual void paint(QPainter *painter);
44   virtual void resize(const QSizeF& size);
45   virtual void reset();
46   virtual GstElement *sinkElement();
47
48   QRectF renderArea();
49   QSizeF videoResolution();
50
51 private slots:
52   void setVideoSize(const QSizeF& size);
53
54 private:
55   static void frame_ready(GstElement *sink, int frame, QtCamViewfinderRendererMeeGo *r);
56   static void sink_notify(QtCamViewfinderRendererMeeGo *q, GObject *object, gboolean is_last_ref);
57   static void sink_caps_changed(GObject *obj, GParamSpec *pspec, QtCamViewfinderRendererMeeGo *q);
58
59   void calculateProjectionMatrix(const QRectF& rect);
60   void createProgram();
61   void paintFrame(QPainter *painter, int frame);
62   void calculateCoords();
63
64   QtCamConfig *m_conf;
65   GstElement *m_sink;
66   QMutex m_frameMutex;
67   int m_frame;
68   unsigned long m_id;
69   unsigned long m_notify;
70   bool m_needsInit;
71   QGLShaderProgram *m_program;
72   QMatrix4x4 m_projectionMatrix;
73   GLfloat m_vertexCoords[8];
74   GLfloat m_texCoords[8];
75   QSizeF m_size;
76   QSizeF m_videoSize;
77   QRectF m_renderArea;
78   EGLDisplay m_dpy;
79 };
80
81 #endif /* QT_CAM_VIEWFINDER_RENDERER_MEEGO_H */