From 5b2ffd10e85af5860248ee761255721cb3675b40 Mon Sep 17 00:00:00 2001 From: Elvis Lee Date: Tue, 31 Jul 2012 18:46:14 +0900 Subject: Correct background's coordinates 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 --- examples/qwindow-compositor/qwindowcompositor.cpp | 33 ++++++++++++++++------- examples/qwindow-compositor/qwindowcompositor.h | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/examples/qwindow-compositor/qwindowcompositor.cpp b/examples/qwindow-compositor/qwindowcompositor.cpp index c30aba36c..b30c86d50 100644 --- a/examples/qwindow-compositor/qwindowcompositor.cpp +++ b/examples/qwindow-compositor/qwindowcompositor.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -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); diff --git a/examples/qwindow-compositor/qwindowcompositor.h b/examples/qwindow-compositor/qwindowcompositor.h index 2efc09593..ad1aae063 100644 --- a/examples/qwindow-compositor/qwindowcompositor.h +++ b/examples/qwindow-compositor/qwindowcompositor.h @@ -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(); -- cgit v1.2.3