Correct background's coordinates
authorElvis Lee <kwangwoong.lee@lge.com>
Tue, 31 Jul 2012 09:46:14 +0000 (18:46 +0900)
committerLaszlo Agocs <laszlo.p.agocs@nokia.com>
Tue, 31 Jul 2012 09:51:55 +0000 (11:51 +0200)
Background has been rendered from (0, 0), so it didn't reprensent
boundary of qwindowcompositor correctly when using -nofullscreen.
And make background'size equal to window size on constructing.

Change-Id: I2bcdc350c1e8ebccdb19c69211afecf5d59000ea
Reviewed-by: Laszlo Agocs <laszlo.p.agocs@nokia.com>
examples/qwindow-compositor/qwindowcompositor.cpp
examples/qwindow-compositor/qwindowcompositor.h

index c30aba3..b30c86d 100644 (file)
@@ -49,6 +49,7 @@
 #include <QPixmap>
 #include <QLinkedList>
 #include <QScreen>
+#include <QPainter>
 
 #include <QtCompositor/waylandinput.h>
 
@@ -66,7 +67,7 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window)
 
     m_textureCache = new QOpenGLTextureCache(m_window->context());
     m_textureBlitter = new TextureBlitter();
-    m_backgroundImage = QImage(QLatin1String(":/background.jpg"));
+    m_backgroundImage = makeBackgroundImage(QLatin1String(":/background.jpg"));
     m_renderScheduler.setSingleShot(true);
     connect(&m_renderScheduler,SIGNAL(timeout()),this,SLOT(render()));
 
@@ -87,6 +88,27 @@ QWindowCompositor::~QWindowCompositor()
     delete m_textureCache;
 }
 
+
+QImage QWindowCompositor::makeBackgroundImage(const QString &fileName)
+{
+    Q_ASSERT(m_window);
+
+    int width = m_window->width();
+    int height = m_window->height();
+    QImage baseImage(fileName);
+    QImage patternedBackground(width, height, baseImage.format());
+    QPainter painter(&patternedBackground);
+
+    QSize imageSize = baseImage.size();
+    for (int y = 0; y < height; y += imageSize.height()) {
+        for (int x = 0; x < width; x += imageSize.width()) {
+            painter.drawImage(x, y, baseImage);
+        }
+    }
+
+    return patternedBackground;
+}
+
 void QWindowCompositor::ensureKeyboardFocusSurface(WaylandSurface *oldSurface)
 {
     WaylandSurface *kbdFocus = defaultInputDevice()->keyboardFocus();
@@ -246,14 +268,7 @@ void QWindowCompositor::render()
 
     m_textureBlitter->bind();
     //Draw the background Image texture
-    int w = m_window->width();
-    int h = m_window->height();
-    QSize imageSize = m_backgroundImage.size();
-    for (int y = 0; y < h; y += imageSize.height()) {
-        for (int x = 0; x < w; x += imageSize.width()) {
-            m_textureBlitter->drawTexture(m_backgroundTexture,QRect(QPoint(x, y),imageSize),window()->size(), 0,true,true);
-        }
-    }
+    m_textureBlitter->drawTexture(m_backgroundTexture, window()->geometry(), window()->size(), 0, true, true);
 
     foreach (WaylandSurface *surface, m_surfaces) {
         GLuint texture = composeSurface(surface);
index 2efc095..ad1aae0 100644 (file)
@@ -80,6 +80,7 @@ protected:
     void changeCursor(const QImage &image, int hotspotX, int hotspotY);
 
     void ensureKeyboardFocusSurface(WaylandSurface *oldSurface);
+    QImage makeBackgroundImage(const QString &fileName);
 
 private slots:
     void sendExpose();