Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/egl_gbm_backend.cpp
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 143 | if (m_outputs.isEmpty()) { | |||
---|---|---|---|---|---|
145 | return false; | 145 | return false; | ||
146 | } | 146 | } | ||
147 | // set our first surface as the one for the abstract backend, just to make it happy | 147 | // set our first surface as the one for the abstract backend, just to make it happy | ||
148 | setSurface(m_outputs.first().eglSurface); | 148 | setSurface(m_outputs.first().eglSurface); | ||
149 | 149 | | |||
150 | return makeContextCurrent(m_outputs.first()); | 150 | return makeContextCurrent(m_outputs.first()); | ||
151 | } | 151 | } | ||
152 | 152 | | |||
153 | void EglGbmBackend::createOutput(DrmOutput *drmOutput) | 153 | bool EglGbmBackend::initOutput(Output &o, DrmOutput *drmOutput) | ||
romangg: Rename this function `resetOutput` and put the destroy surface logic from the lambda function… | |||||
154 | { | 154 | { | ||
155 | Output o; | | |||
156 | o.output = drmOutput; | 155 | o.output = drmOutput; | ||
157 | auto size = drmOutput->pixelSize(); | 156 | auto size = drmOutput->pixelSize(); | ||
158 | 157 | | |||
159 | o.gbmSurface = std::make_shared<GbmSurface>(m_backend->gbmDevice(), size.width(), size.height(), | 158 | o.gbmSurface = std::make_shared<GbmSurface>(m_backend->gbmDevice(), size.width(), size.height(), | ||
160 | GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); | 159 | GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); | ||
161 | if (!o.gbmSurface) { | 160 | if (!o.gbmSurface) { | ||
162 | qCCritical(KWIN_DRM) << "Create gbm surface failed"; | 161 | qCCritical(KWIN_DRM) << "Create gbm surface failed"; | ||
163 | return; | 162 | return false; | ||
164 | } | 163 | } | ||
165 | o.eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), (void *)(o.gbmSurface->surface()), nullptr); | 164 | o.eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(), (void *)(o.gbmSurface->surface()), nullptr); | ||
166 | if (o.eglSurface == EGL_NO_SURFACE) { | 165 | if (o.eglSurface == EGL_NO_SURFACE) { | ||
167 | qCCritical(KWIN_DRM) << "Create Window Surface failed"; | 166 | qCCritical(KWIN_DRM) << "Create Window Surface failed"; | ||
168 | o.gbmSurface.reset(); | 167 | o.gbmSurface.reset(); | ||
168 | return false; | ||||
169 | } | ||||
170 | return true; | ||||
171 | } | ||||
172 | | ||||
173 | void EglGbmBackend::createOutput(DrmOutput *drmOutput) | ||||
174 | { | ||||
175 | Output o; | ||||
176 | if (initOutput(o, drmOutput)) { | ||||
177 | connect(drmOutput, &DrmOutput::modeChanged, this, | ||||
178 | [drmOutput, this] { | ||||
179 | auto it = std::find_if(m_outputs.begin(), m_outputs.end(), | ||||
180 | [drmOutput] (const auto &o) { | ||||
181 | return o.output == drmOutput; | ||||
182 | } | ||||
183 | ); | ||||
184 | if (it == m_outputs.end()) { | ||||
169 | return; | 185 | return; | ||
170 | } | 186 | } | ||
187 | auto surface = it->gbmSurface; | ||||
188 | auto eglSurface = it->eglSurface; | ||||
189 | if (initOutput(*it, drmOutput)) { | ||||
190 | // new surface created, destroy old one | ||||
191 | if (eglSurface != EGL_NO_SURFACE) { | ||||
192 | eglDestroySurface(eglDisplay(), eglSurface); | ||||
193 | } | ||||
194 | } else { | ||||
195 | // new surface failed, go back to old | ||||
196 | it->gbmSurface = surface; | ||||
197 | it->eglSurface = eglSurface; | ||||
198 | } | ||||
199 | } | ||||
200 | ); | ||||
171 | m_outputs << o; | 201 | m_outputs << o; | ||
172 | } | 202 | } | ||
203 | } | ||||
173 | 204 | | |||
174 | bool EglGbmBackend::makeContextCurrent(const Output &output) | 205 | bool EglGbmBackend::makeContextCurrent(const Output &output) | ||
175 | { | 206 | { | ||
176 | const EGLSurface surface = output.eglSurface; | 207 | const EGLSurface surface = output.eglSurface; | ||
177 | if (surface == EGL_NO_SURFACE) { | 208 | if (surface == EGL_NO_SURFACE) { | ||
178 | return false; | 209 | return false; | ||
179 | } | 210 | } | ||
180 | if (eglMakeCurrent(eglDisplay(), surface, surface, context()) == EGL_FALSE) { | 211 | if (eglMakeCurrent(eglDisplay(), surface, surface, context()) == EGL_FALSE) { | ||
▲ Show 20 Lines • Show All 172 Lines • Show Last 20 Lines |
Rename this function resetOutput and put the destroy surface logic from the lambda function below in here? Would look cleaner I think.