226void QWaylandSurfacePrivate::surface_commit(Resource *)
228 Q_Q(QWaylandSurface);
231 QSize oldBufferSize = bufferSize;
232 QRectF oldSourceGeometry = sourceGeometry;
233 QSize oldDestinationSize = destinationSize;
234 bool oldHasContent = hasContent;
235 int oldBufferScale = bufferScale;
236 Qt::ScreenOrientation oldContentOrientation = contentOrientation;
239 if (pending.buffer.hasBuffer() || pending.newlyAttached)
240 bufferRef = pending.buffer;
241 contentOrientation = pending.contentOrientation;
242 bufferScale = pending.bufferScale;
243 bufferSize = bufferRef.size();
244 QSize surfaceSize = bufferSize / bufferScale;
245 sourceGeometry = !pending.sourceGeometry.isValid() ? QRect(QPoint(), surfaceSize) : pending.sourceGeometry;
246 destinationSize = pending.destinationSize.isEmpty() ? sourceGeometry.size().toSize() : pending.destinationSize;
247 QRect destinationRect(QPoint(), destinationSize);
249 damage = pending.surfaceDamage.intersected(destinationRect);
250 if (!pending.bufferDamage.isNull()) {
251 if (bufferScale == 1) {
252 damage |= pending.bufferDamage.intersected(destinationRect);
256 auto xform = [](
const QRect &r,
int scale) -> QRect {
258 QPoint{ r.x() / scale, r.y() / scale },
259 QPoint{ (r.right() + scale - 1) / scale, (r.bottom() + scale - 1) / scale }
263 for (
const QRect &r : pending.bufferDamage)
264 damage |= xform(r, bufferScale).intersected(destinationRect);
267 hasContent = bufferRef.hasContent();
268 frameCallbacks << pendingFrameCallbacks;
269 inputRegion = pending.inputRegion.intersected(destinationRect);
270 opaqueRegion = pending.opaqueRegion.intersected(destinationRect);
271 bool becameOpaque = opaqueRegion.boundingRect().contains(destinationRect);
272 if (becameOpaque != isOpaque) {
273 isOpaque = becameOpaque;
274 emit q->isOpaqueChanged();
277 QPoint offsetForNextFrame = pending.offset;
280 viewport->checkCommittedState();
283 pending.buffer = QWaylandBufferRef();
284 pending.offset = QPoint();
285 pending.newlyAttached =
false;
286 pending.bufferDamage = QRegion();
287 pending.surfaceDamage = QRegion();
288 pendingFrameCallbacks.clear();
291 if (
auto *buffer = bufferRef.buffer())
292 buffer->setCommitted(damage);
293 for (
auto *view : std::as_const(views))
294 view->bufferCommitted(bufferRef, damage);
300 emit q->damaged(damage);
302 if (oldContentOrientation != contentOrientation)
303 emit q->contentOrientationChanged();
305 if (oldBufferSize != bufferSize)
306 emit q->bufferSizeChanged();
308 if (oldBufferScale != bufferScale)
309 emit q->bufferScaleChanged();
311 if (oldDestinationSize != destinationSize)
312 emit q->destinationSizeChanged();
314 if (oldSourceGeometry != sourceGeometry)
315 emit q->sourceGeometryChanged();
317 if (oldHasContent != hasContent)
318 emit q->hasContentChanged();
320 if (!offsetForNextFrame.isNull())
321 emit q->offsetForNextFrame(offsetForNextFrame);
326void QWaylandSurfacePrivate::surface_set_buffer_transform(Resource *resource, int32_t orientation)
328 Q_Q(QWaylandSurface);
329 QScreen *screen =
nullptr;
330 if (
auto *view = q->primaryView()) {
331 if (
auto *output = view->output()) {
332 if (
auto *window = output->window())
333 screen = window->screen();
336 if (screen ==
nullptr)
337 screen = QGuiApplication::primaryScreen();
338 Qt::ScreenOrientation newContentOrientation = screen->primaryOrientation();
339 bool isPortrait = newContentOrientation == Qt::PortraitOrientation;
340 switch (orientation) {
341 case WL_OUTPUT_TRANSFORM_90:
342 newContentOrientation = isPortrait ? Qt::InvertedLandscapeOrientation : Qt::PortraitOrientation;
344 case WL_OUTPUT_TRANSFORM_180:
345 newContentOrientation = isPortrait ? Qt::InvertedPortraitOrientation : Qt::InvertedLandscapeOrientation;
347 case WL_OUTPUT_TRANSFORM_270:
348 newContentOrientation = isPortrait ? Qt::LandscapeOrientation : Qt::InvertedPortraitOrientation;
350 case WL_OUTPUT_TRANSFORM_NORMAL:
351 newContentOrientation = Qt::PrimaryOrientation;
355 case WL_OUTPUT_TRANSFORM_FLIPPED:
356 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
357 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
358 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
362 wl_resource_post_error(resource->handle, WL_SURFACE_ERROR_INVALID_TRANSFORM,
363 "invalid buffer transform");
366 pending.contentOrientation = newContentOrientation;