~gerboland/qtubuntu/enable-debug-mode

« back to all changes in this revision

Viewing changes to src/ubuntumirclient/screen.cpp

  • Committer: Gerry Boland
  • Date: 2016-04-12 13:10:43 UTC
  • mfrom: (280.2.34 enable-debug-mode)
  • Revision ID: gerry.boland@canonical.com-20160412131043-t14zmcbheuxclmhr
Merge lp:~dandrader/qtubuntu/enable-debug-mode, he kindly fixed merging this with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2014 Canonical, Ltd.
 
2
 * Copyright (C) 2014-2015 Canonical, Ltd.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify it under
5
5
 * the terms of the GNU Lesser General Public License version 3, as published by
33
33
 
34
34
static const int kSwapInterval = 1;
35
35
 
36
 
#if !defined(QT_NO_DEBUG)
37
 
 
38
36
static const char *orientationToStr(Qt::ScreenOrientation orientation) {
39
37
    switch (orientation) {
40
38
        case Qt::PrimaryOrientation:
53
51
}
54
52
 
55
53
static void printEglConfig(EGLDisplay display, EGLConfig config) {
56
 
  DASSERT(display != EGL_NO_DISPLAY);
57
 
  DASSERT(config != nullptr);
58
 
  static const struct { const EGLint attrib; const char* name; } kAttribs[] = {
59
 
    { EGL_BUFFER_SIZE, "EGL_BUFFER_SIZE" },
60
 
    { EGL_ALPHA_SIZE, "EGL_ALPHA_SIZE" },
61
 
    { EGL_BLUE_SIZE, "EGL_BLUE_SIZE" },
62
 
    { EGL_GREEN_SIZE, "EGL_GREEN_SIZE" },
63
 
    { EGL_RED_SIZE, "EGL_RED_SIZE" },
64
 
    { EGL_DEPTH_SIZE, "EGL_DEPTH_SIZE" },
65
 
    { EGL_STENCIL_SIZE, "EGL_STENCIL_SIZE" },
66
 
    { EGL_CONFIG_CAVEAT, "EGL_CONFIG_CAVEAT" },
67
 
    { EGL_CONFIG_ID, "EGL_CONFIG_ID" },
68
 
    { EGL_LEVEL, "EGL_LEVEL" },
69
 
    { EGL_MAX_PBUFFER_HEIGHT, "EGL_MAX_PBUFFER_HEIGHT" },
70
 
    { EGL_MAX_PBUFFER_PIXELS, "EGL_MAX_PBUFFER_PIXELS" },
71
 
    { EGL_MAX_PBUFFER_WIDTH, "EGL_MAX_PBUFFER_WIDTH" },
72
 
    { EGL_NATIVE_RENDERABLE, "EGL_NATIVE_RENDERABLE" },
73
 
    { EGL_NATIVE_VISUAL_ID, "EGL_NATIVE_VISUAL_ID" },
74
 
    { EGL_NATIVE_VISUAL_TYPE, "EGL_NATIVE_VISUAL_TYPE" },
75
 
    { EGL_SAMPLES, "EGL_SAMPLES" },
76
 
    { EGL_SAMPLE_BUFFERS, "EGL_SAMPLE_BUFFERS" },
77
 
    { EGL_SURFACE_TYPE, "EGL_SURFACE_TYPE" },
78
 
    { EGL_TRANSPARENT_TYPE, "EGL_TRANSPARENT_TYPE" },
79
 
    { EGL_TRANSPARENT_BLUE_VALUE, "EGL_TRANSPARENT_BLUE_VALUE" },
80
 
    { EGL_TRANSPARENT_GREEN_VALUE, "EGL_TRANSPARENT_GREEN_VALUE" },
81
 
    { EGL_TRANSPARENT_RED_VALUE, "EGL_TRANSPARENT_RED_VALUE" },
82
 
    { EGL_BIND_TO_TEXTURE_RGB, "EGL_BIND_TO_TEXTURE_RGB" },
83
 
    { EGL_BIND_TO_TEXTURE_RGBA, "EGL_BIND_TO_TEXTURE_RGBA" },
84
 
    { EGL_MIN_SWAP_INTERVAL, "EGL_MIN_SWAP_INTERVAL" },
85
 
    { EGL_MAX_SWAP_INTERVAL, "EGL_MAX_SWAP_INTERVAL" },
86
 
    { -1, NULL }
87
 
  };
88
 
  const char* string = eglQueryString(display, EGL_VENDOR);
89
 
  LOG("EGL vendor: %s", string);
90
 
  string = eglQueryString(display, EGL_VERSION);
91
 
  LOG("EGL version: %s", string);
92
 
  string = eglQueryString(display, EGL_EXTENSIONS);
93
 
  LOG("EGL extensions: %s", string);
94
 
  LOG("EGL configuration attibutes:");
95
 
  for (int index = 0; kAttribs[index].attrib != -1; index++) {
96
 
    EGLint value;
97
 
    if (eglGetConfigAttrib(display, config, kAttribs[index].attrib, &value))
98
 
      LOG("  %s: %d", kAttribs[index].name, static_cast<int>(value));
99
 
  }
 
54
    Q_ASSERT(display != EGL_NO_DISPLAY);
 
55
    Q_ASSERT(config != nullptr);
 
56
 
 
57
    static const struct { const EGLint attrib; const char* name; } kAttribs[] = {
 
58
        { EGL_BUFFER_SIZE, "EGL_BUFFER_SIZE" },
 
59
        { EGL_ALPHA_SIZE, "EGL_ALPHA_SIZE" },
 
60
        { EGL_BLUE_SIZE, "EGL_BLUE_SIZE" },
 
61
        { EGL_GREEN_SIZE, "EGL_GREEN_SIZE" },
 
62
        { EGL_RED_SIZE, "EGL_RED_SIZE" },
 
63
        { EGL_DEPTH_SIZE, "EGL_DEPTH_SIZE" },
 
64
        { EGL_STENCIL_SIZE, "EGL_STENCIL_SIZE" },
 
65
        { EGL_CONFIG_CAVEAT, "EGL_CONFIG_CAVEAT" },
 
66
        { EGL_CONFIG_ID, "EGL_CONFIG_ID" },
 
67
        { EGL_LEVEL, "EGL_LEVEL" },
 
68
        { EGL_MAX_PBUFFER_HEIGHT, "EGL_MAX_PBUFFER_HEIGHT" },
 
69
        { EGL_MAX_PBUFFER_PIXELS, "EGL_MAX_PBUFFER_PIXELS" },
 
70
        { EGL_MAX_PBUFFER_WIDTH, "EGL_MAX_PBUFFER_WIDTH" },
 
71
        { EGL_NATIVE_RENDERABLE, "EGL_NATIVE_RENDERABLE" },
 
72
        { EGL_NATIVE_VISUAL_ID, "EGL_NATIVE_VISUAL_ID" },
 
73
        { EGL_NATIVE_VISUAL_TYPE, "EGL_NATIVE_VISUAL_TYPE" },
 
74
        { EGL_SAMPLES, "EGL_SAMPLES" },
 
75
        { EGL_SAMPLE_BUFFERS, "EGL_SAMPLE_BUFFERS" },
 
76
        { EGL_SURFACE_TYPE, "EGL_SURFACE_TYPE" },
 
77
        { EGL_TRANSPARENT_TYPE, "EGL_TRANSPARENT_TYPE" },
 
78
        { EGL_TRANSPARENT_BLUE_VALUE, "EGL_TRANSPARENT_BLUE_VALUE" },
 
79
        { EGL_TRANSPARENT_GREEN_VALUE, "EGL_TRANSPARENT_GREEN_VALUE" },
 
80
        { EGL_TRANSPARENT_RED_VALUE, "EGL_TRANSPARENT_RED_VALUE" },
 
81
        { EGL_BIND_TO_TEXTURE_RGB, "EGL_BIND_TO_TEXTURE_RGB" },
 
82
        { EGL_BIND_TO_TEXTURE_RGBA, "EGL_BIND_TO_TEXTURE_RGBA" },
 
83
        { EGL_MIN_SWAP_INTERVAL, "EGL_MIN_SWAP_INTERVAL" },
 
84
        { EGL_MAX_SWAP_INTERVAL, "EGL_MAX_SWAP_INTERVAL" },
 
85
        { -1, NULL }
 
86
    };
 
87
    const char* string = eglQueryString(display, EGL_VENDOR);
 
88
    qCDebug(ubuntumirclient, "EGL vendor: %s", string);
 
89
 
 
90
    string = eglQueryString(display, EGL_VERSION);
 
91
    qCDebug(ubuntumirclient, "EGL version: %s", string);
 
92
 
 
93
    string = eglQueryString(display, EGL_EXTENSIONS);
 
94
    qCDebug(ubuntumirclient, "EGL extensions: %s", string);
 
95
 
 
96
    qCDebug(ubuntumirclient, "EGL configuration attibutes:");
 
97
    for (int index = 0; kAttribs[index].attrib != -1; index++) {
 
98
        EGLint value;
 
99
        if (eglGetConfigAttrib(display, config, kAttribs[index].attrib, &value))
 
100
            qCDebug(ubuntumirclient, "  %s: %d", kAttribs[index].name, static_cast<int>(value));
 
101
    }
100
102
}
101
 
#endif
102
 
 
103
103
 
104
104
const QEvent::Type OrientationChangeEvent::mType =
105
105
        static_cast<QEvent::Type>(QEvent::registerEventType());
132
132
    , mSurfaceFormat()
133
133
    , mEglDisplay(EGL_NO_DISPLAY)
134
134
    , mEglConfig(nullptr)
 
135
    , mCursor(connection)
135
136
{
136
137
    // Initialize EGL.
137
138
    ASSERT(eglBindAPI(EGL_OPENGL_ES_API) == EGL_TRUE);
149
150
    mSurfaceFormat.setStencilBufferSize(8);
150
151
    if (!qEnvironmentVariableIsEmpty("QTUBUNTU_MULTISAMPLE")) {
151
152
        mSurfaceFormat.setSamples(4);
152
 
        DLOG("ubuntumirclient: setting MSAA to 4 samples");
 
153
        qCDebug(ubuntumirclient, "setting MSAA to 4 samples");
153
154
    }
154
155
#ifdef QTUBUNTU_USE_OPENGL
155
156
    mSurfaceFormat.setRenderableType(QSurfaceFormat::OpenGL);
158
159
#endif
159
160
    mEglConfig = q_configFromGLFormat(mEglDisplay, mSurfaceFormat, true);
160
161
 
161
 
    #if !defined(QT_NO_DEBUG)
162
 
    printEglConfig(mEglDisplay, mEglConfig);
163
 
    #endif
 
162
    if (ubuntumirclient().isDebugEnabled()) {
 
163
        printEglConfig(mEglDisplay, mEglConfig);
 
164
    }
164
165
 
165
166
    // Set vblank swap interval.
166
167
    int swapInterval = kSwapInterval;
171
172
        if (!ok)
172
173
            swapInterval = kSwapInterval;
173
174
    }
174
 
    DLOG("ubuntumirclient: setting swap interval to %d", swapInterval);
 
175
    qCDebug(ubuntumirclient, "setting swap interval to %d", swapInterval);
175
176
    eglSwapInterval(mEglDisplay, swapInterval);
176
177
 
177
178
    // Get screen resolution.
184
185
    ASSERT(displayOutput != nullptr);
185
186
 
186
187
    mOutputId = displayOutput->output_id;
 
188
 
 
189
    mPhysicalSize = QSizeF(displayOutput->physical_width_mm, displayOutput->physical_height_mm);
 
190
    qCDebug(ubuntumirclient, "screen physical size: %.2fx%.2f", mPhysicalSize.width(), mPhysicalSize.height());
 
191
 
187
192
    const MirDisplayMode *mode = &displayOutput->modes[displayOutput->current_mode];
188
193
    const int kScreenWidth = mode->horizontal_resolution;
189
194
    const int kScreenHeight = mode->vertical_resolution;
190
 
    DASSERT(kScreenWidth > 0 && kScreenHeight > 0);
 
195
    Q_ASSERT(kScreenWidth > 0 && kScreenHeight > 0);
191
196
 
192
 
    DLOG("ubuntumirclient: screen resolution: %dx%d", kScreenWidth, kScreenHeight);
 
197
    qCDebug(ubuntumirclient, "screen resolution: %dx%d", kScreenWidth, kScreenHeight);
193
198
 
194
199
    mGeometry = QRect(0, 0, kScreenWidth, kScreenHeight);
195
200
 
196
 
    DLOG("QUbuntuScreen::QUbuntuScreen (this=%p)", this);
197
 
 
198
201
    // Set the default orientation based on the initial screen dimmensions.
199
202
    mNativeOrientation = (mGeometry.width() >= mGeometry.height()) ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
200
203
 
208
211
}
209
212
 
210
213
void UbuntuScreen::customEvent(QEvent* event) {
211
 
    DASSERT(QThread::currentThread() == thread());
 
214
    Q_ASSERT(QThread::currentThread() == thread());
212
215
 
213
216
    OrientationChangeEvent* oReadingEvent = static_cast<OrientationChangeEvent*>(event);
214
217
    switch (oReadingEvent->mOrientation) {
233
236
            break;
234
237
        }
235
238
        default: {
236
 
            DLOG("UbuntuScreen::customEvent - Unknown orientation.");
 
239
            qCDebug(ubuntumirclient, "UbuntuScreen::customEvent - Unknown orientation.");
237
240
            return;
238
241
        }
239
242
    }
240
243
 
241
244
    // Raise the event signal so that client apps know the orientation changed
242
 
    DLOG("UbuntuScreen::customEvent - handling orientation change to %s", orientationToStr(mCurrentOrientation));
 
245
    qCDebug(ubuntumirclient, "UbuntuScreen::customEvent - handling orientation change to %s", orientationToStr(mCurrentOrientation));
243
246
    QWindowSystemInterface::handleScreenOrientationChange(screen(), mCurrentOrientation);
244
247
}
245
248
 
260
263
        mGeometry.setWidth(currGeometry.height());
261
264
        mGeometry.setHeight(currGeometry.width());
262
265
 
263
 
        DLOG("UbuntuScreen::handleWindowSurfaceResize - new screen geometry (w=%d, h=%d)",
 
266
        qCDebug(ubuntumirclient, "UbuntuScreen::handleWindowSurfaceResize - new screen geometry (w=%d, h=%d)",
264
267
            mGeometry.width(), mGeometry.height());
265
268
        QWindowSystemInterface::handleScreenGeometryChange(screen(),
266
269
                                                           mGeometry /* newGeometry */,
271
274
        } else {
272
275
            mCurrentOrientation = Qt::LandscapeOrientation;
273
276
        }
274
 
        DLOG("UbuntuScreen::handleWindowSurfaceResize - new orientation %s",orientationToStr(mCurrentOrientation));
 
277
        qCDebug(ubuntumirclient, "UbuntuScreen::handleWindowSurfaceResize - new orientation %s",orientationToStr(mCurrentOrientation));
275
278
        QWindowSystemInterface::handleScreenOrientationChange(screen(), mCurrentOrientation);
276
279
    }
277
280
}