static void mech_surface_wayland_shm_push_update (MechSurface *surface, const cairo_region_t *region) { MechSurfaceWaylandSHM *shm_surface = (MechSurfaceWaylandSHM *) surface; MechSurfaceWaylandSHMPriv *priv = shm_surface->_priv; struct wl_surface *wl_surface; cairo_rectangle_int_t rect; BufferData *buffer; gint i; g_object_get (surface, "wl-surface", &wl_surface, NULL); buffer = priv->buffers[priv->cur_buffer]; if (wl_surface) { for (i = 0; i < cairo_region_num_rectangles (region); i++) { cairo_region_get_rectangle (region, i, &rect); wl_surface_damage (wl_surface, rect.x, rect.y, rect.width, rect.height); } wl_surface_attach (wl_surface, buffer->wl_buffer, priv->tx, priv->ty); priv->tx = priv->ty = 0; /* The current buffer is now acquired by the compositor */ buffer->released = FALSE; } MECH_SURFACE_CLASS (mech_surface_wayland_shm_parent_class)->push_update (surface, region); }
static void wayland_swap_buffers (ClutterStageWayland *stage_wayland) { ClutterBackend *backend = clutter_get_default_backend (); ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend); ClutterStageWaylandWaylandBuffer *buffer; buffer = stage_wayland->front_buffer; stage_wayland->front_buffer = stage_wayland->back_buffer; stage_wayland->back_buffer = buffer; wayland_damage_buffer(stage_wayland->front_buffer); wl_surface_attach (stage_wayland->wayland_surface, stage_wayland->front_buffer->wayland_buffer, /* 0,0 here is "relative to the old buffer," not absolute */ 0, 0); wl_surface_map_toplevel (stage_wayland->wayland_surface); stage_wayland->pending_swaps++; wl_display_frame_callback (backend_wayland->wayland_display, wayland_frame_callback, stage_wayland); _cogl_swap_buffers_notify (); }
static void redraw(void *data, struct wl_callback *callback, uint32_t time) { struct window *window = data; struct buffer *buffer; buffer = window_next_buffer(window); if (!buffer) { fprintf(stderr, !callback ? "Failed to create the first buffer.\n" : "Both buffers busy at redraw(). Server bug?\n"); abort(); } /* XXX: would be nice to draw something that changes here... */ wl_surface_attach(window->surface, buffer->buffer, 0, 0); wl_surface_damage(window->surface, 0, 0, window->width, window->height); if (callback) wl_callback_destroy(callback); window->callback = wl_surface_frame(window->surface); wl_callback_add_listener(window->callback, &frame_listener, window); wl_surface_commit(window->surface); buffer->busy = 1; }
void QWaylandWindow::attach(QWaylandBuffer *buffer) { mBuffer = buffer; if (mSurface) { wl_surface_attach(mSurface, buffer->buffer(),0,0); } }
static void pointer_handle_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t sx, wl_fixed_t sy) { struct display *display = data; struct wl_buffer *buffer; struct wl_cursor *cursor = display->default_cursor; struct wl_cursor_image *image; if (display->window->fullscreen) wl_pointer_set_cursor(pointer, serial, NULL, 0, 0); else if (cursor) { image = display->default_cursor->images[0]; buffer = wl_cursor_image_get_buffer(image); wl_pointer_set_cursor(pointer, serial, display->cursor_surface, image->hotspot_x, image->hotspot_y); wl_surface_attach(display->cursor_surface, buffer, 0, 0); wl_surface_damage(display->cursor_surface, 0, 0, image->width, image->height); wl_surface_commit(display->cursor_surface); } }
/* Swap the contents of a drawable to the screen */ static WSEGLError wseglSwapDrawable (WSEGLDrawableHandle _drawable, unsigned long data) { struct wl_egl_window *drawable = (struct wl_egl_window *) _drawable; struct wl_callback *callback; if (drawable->numFlipBuffers) { PVR2DPresentFlip(drawable->display->context, drawable->flipChain, drawable->backBuffers[drawable->currentBackBuffer], 0); } else if (drawable->display->display) { while (drawable->block_swap_buffers == 1) wl_display_iterate(drawable->display->display, WL_DISPLAY_READABLE); drawable->block_swap_buffers = 1; callback = wl_display_sync(drawable->display->display); wl_callback_add_listener(callback, &sync_listener, drawable); wl_buffer_damage(drawable->drmbuffers[drawable->currentBackBuffer], 0, 0, drawable->width, drawable->height); wl_surface_attach(drawable->surface, drawable->drmbuffers[drawable->currentBackBuffer], 0, 0); wl_surface_damage(drawable->surface, 0, 0, drawable->width, drawable->height); } else { PVR2DBLTINFO blit; memset(&blit, 0, sizeof(blit)); blit.CopyCode = PVR2DROPcopy; blit.BlitFlags = PVR2D_BLIT_DISABLE_ALL; blit.pSrcMemInfo = drawable->backBuffers[drawable->currentBackBuffer]; blit.SrcStride = drawable->strideBytes; blit.SrcX = 0; blit.SrcY = 0; blit.SizeX = drawable->width; blit.SizeY = drawable->height; blit.SrcFormat = wsegl2pvr2dformat(drawable->format); blit.pDstMemInfo = drawable->frontBufferPVRMEM; blit.DstStride = drawable->strideBytes; blit.DstX = 0; blit.DstY = 0; blit.DSizeX = drawable->width; blit.DSizeY = drawable->height; blit.DstFormat = wsegl2pvr2dformat(drawable->format); PVR2DBlt(drawable->display->context, &blit); PVR2DQueryBlitsComplete (drawable->display->context, drawable->frontBufferPVRMEM, 1); } drawable->currentBackBuffer = (drawable->currentBackBuffer + 1) % WAYLANDWSEGL_MAX_BACK_BUFFERS; return WSEGL_SUCCESS; }
/* must be called with the render lock */ static void render_last_buffer (GstWaylandSink * sink) { GstWlMeta *meta; struct wl_surface *surface; struct wl_callback *callback; meta = gst_buffer_get_wl_meta (sink->last_buffer); surface = gst_wl_window_get_wl_surface (sink->window); g_atomic_int_set (&sink->redraw_pending, TRUE); callback = wl_surface_frame (surface); wl_callback_add_listener (callback, &frame_callback_listener, sink); /* Here we essentially add a reference to the buffer. This represents * the fact that the compositor is using the buffer and it should * not return back to the pool and be reused until the compositor * releases it. The release is handled internally in the pool */ gst_wayland_compositor_acquire_buffer (meta->pool, sink->last_buffer); wl_surface_attach (surface, meta->wbuffer, 0, 0); wl_surface_damage (surface, 0, 0, sink->window->surface_width, sink->window->surface_height); wl_surface_commit (surface); wl_display_flush (sink->display->display); }
WL_EXPORT void wl_surface_attach_buffer(struct wl_surface *surface, struct wl_buffer *buffer) { return wl_surface_attach(surface, buffer->name, buffer->width, buffer->height, buffer->stride); }
struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface) { struct window *window = malloc(sizeof(struct window)); memset(window, 0, sizeof(struct window)); window->width = width; window->height = height; window->registry = registry; window->surface = wl_compositor_create_surface(registry->compositor); if (shell_surface) { window->shell_surface = wl_shell_get_shell_surface(registry->shell, window->surface); wl_shell_surface_add_listener(window->shell_surface, &surface_listener, window); wl_shell_surface_set_toplevel(window->shell_surface); } if (registry->pointer) { wl_pointer_add_listener(registry->pointer, &pointer_listener, window); } window->cursor.cursor_theme = wl_cursor_theme_load("default", 32, registry->shm); // TODO: let you customize this window->cursor.cursor = wl_cursor_theme_get_cursor(window->cursor.cursor_theme, "left_ptr"); window->cursor.surface = wl_compositor_create_surface(registry->compositor); struct wl_cursor_image *image = window->cursor.cursor->images[0]; struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image); wl_surface_attach(window->cursor.surface, cursor_buf, 0, 0); wl_surface_damage(window->cursor.surface, 0, 0, image->width, image->height); wl_surface_commit(window->cursor.surface); return window; }
static void setCursor(const char* name) { struct wl_buffer* buffer; struct wl_cursor* cursor; struct wl_cursor_image* image; struct wl_surface* surface = _glfw.wl.cursorSurface; cursor = wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme, name); if (!cursor) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Standard cursor not found"); return; } image = cursor->images[0]; if (!image) return; buffer = wl_cursor_image_get_buffer(image); if (!buffer) return; wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.pointerSerial, surface, image->hotspot_x, image->hotspot_y); wl_surface_attach(surface, buffer, 0, 0); wl_surface_damage(surface, 0, 0, image->width, image->height); wl_surface_commit(surface); }
static void redraw(void *data, struct wl_callback *callback, uint32_t time) { struct window *window = data; struct buffer *buffer; buffer = window_next_buffer(window); if (!buffer) { fprintf(stderr, !callback ? "Failed to create the first buffer.\n" : "Both buffers busy at redraw(). Server bug?\n"); abort(); } paint_pixels(buffer->shm_data, 20, window->width, window->height, time); wl_surface_attach(window->surface, buffer->buffer, 0, 0); wl_surface_damage(window->surface, 20, 20, window->width - 40, window->height - 40); if (callback) wl_callback_destroy(callback); window->callback = wl_surface_frame(window->surface); wl_callback_add_listener(window->callback, &frame_listener, window); wl_surface_commit(window->surface); buffer->busy = 1; }
void gst_wl_window_render (GstWlWindow * window, GstWlBuffer * buffer, const GstVideoInfo * info) { if (G_UNLIKELY (info)) { window->video_width = gst_util_uint64_scale_int_round (info->width, info->par_n, info->par_d); window->video_height = info->height; wl_subsurface_set_sync (window->video_subsurface); gst_wl_window_resize_video_surface (window, FALSE); gst_wl_window_set_opaque (window, info); } if (G_LIKELY (buffer)) gst_wl_buffer_attach (buffer, window->video_surface_wrapper); else wl_surface_attach (window->video_surface_wrapper, NULL, 0, 0); wl_surface_damage (window->video_surface_wrapper, 0, 0, window->video_rectangle.w, window->video_rectangle.h); wl_surface_commit (window->video_surface_wrapper); if (G_UNLIKELY (info)) { /* commit also the parent (area_surface) in order to change * the position of the video_subsurface */ wl_surface_damage (window->area_surface_wrapper, 0, 0, window->render_rectangle.w, window->render_rectangle.h); wl_surface_commit (window->area_surface_wrapper); wl_subsurface_set_desync (window->video_subsurface); } wl_display_flush (window->display->display); }
static void wl_callback_done(void* data, struct wl_callback* callback, uint32_t time) { wlfWindow* window = data; wlfBuffer* buffer; struct wl_shm_pool* shm_pool; void* shm_data; void* free_data; int fd; int fdt; if (!window->buffers[0].busy) buffer = &window->buffers[0]; else if (!window->buffers[1].busy) buffer = &window->buffers[1]; else return; if (!buffer->buffer) { fd = shm_open("/wlfreerdp_shm", O_CREAT | O_RDWR, 0666); fdt = ftruncate(fd, window->width * window->height * 4); if (fdt != 0) { WLog_ERR(TAG, "window_redraw: could not allocate memory"); close(fd); return; } shm_data = mmap(NULL, window->width * window->height * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (shm_data == MAP_FAILED) { WLog_ERR(TAG, "window_redraw: failed to memory map buffer"); close(fd); return; } shm_pool = wl_shm_create_pool(window->display->shm, fd, window->width * window->height * 4); buffer->buffer = wl_shm_pool_create_buffer(shm_pool, 0, window->width, window->height, window->width* 4, WL_SHM_FORMAT_XRGB8888); wl_buffer_add_listener(buffer->buffer, &wl_buffer_listener, buffer); wl_shm_pool_destroy(shm_pool); shm_unlink("/wlfreerdp_shm"); close(fd); free_data = buffer->shm_data; buffer->shm_data = shm_data; munmap(free_data, window->width * window->height * 4); } /* this is the real surface data */ memcpy(buffer->shm_data, (void*) window->data, window->width * window->height * 4); wl_surface_attach(window->surface, buffer->buffer, 0, 0); wl_surface_damage(window->surface, 0, 0, window->width, window->height); if (callback) wl_callback_destroy(callback); window->callback = wl_surface_frame(window->surface); wl_callback_add_listener(window->callback, &wl_callback_listener, window); wl_surface_commit(window->surface); buffer->busy = TRUE; }
void QWaylandWindow::attach(QWaylandBuffer *buffer) { mBuffer = buffer; if (window()->isVisible()) { wl_surface_attach(mSurface, mBuffer->buffer(),0,0); } }
void QWaylandWindow::newSurfaceCreated() { if (mBuffer) { wl_surface_attach(mSurface,mBuffer->buffer(),0,0); wl_surface_damage(mSurface, 0,0,mBuffer->size().width(),mBuffer->size().height()); } }
void setup() { wl_surface_attach(surface_, buffer_, 0, 0); wl_surface_damage(surface_, 0, 0, buffer_.width(), buffer_.height()); surface_.commit(); queueStep(boost::bind(&SurfacePointerTest::test, boost::ref(*this))); }
void WaylandNativeWindow::finishSwap() { int ret = 0; lock(); WaylandNativeWindowBuffer *wnb = queue.front(); if (!wnb) { wnb = m_lastBuffer; } else { queue.pop_front(); } assert(wnb); m_lastBuffer = wnb; wnb->busy = 1; ret = readQueue(false); if (this->frame_callback) { do { ret = readQueue(true); } while (this->frame_callback && ret != -1); } if (ret < 0) { HYBRIS_TRACE_END("wayland-platform", "queueBuffer_wait_for_frame_callback", "-%p", wnb); return; } if (wnb->wlbuffer == NULL) { wnb->wlbuffer_from_native_handle(m_android_wlegl, m_display, wl_queue); TRACE("%p add listener with %p inside", wnb, wnb->wlbuffer); wl_buffer_add_listener(wnb->wlbuffer, &wl_buffer_listener, this); wl_proxy_set_queue((struct wl_proxy *) wnb->wlbuffer, this->wl_queue); } if (m_swap_interval > 0) { this->frame_callback = wl_surface_frame(m_window->surface); wl_callback_add_listener(this->frame_callback, &frame_listener, this); wl_proxy_set_queue((struct wl_proxy *) this->frame_callback, this->wl_queue); } wl_surface_attach(m_window->surface, wnb->wlbuffer, 0, 0); wl_surface_damage(m_window->surface, 0, 0, wnb->width, wnb->height); wl_surface_commit(m_window->surface); // Some compositors, namely Weston, queue buffer release events instead // of sending them immediately. If a frame event is used, this should // not be a problem. Without a frame event, we need to send a sync // request to ensure that they get flushed. wl_callback_destroy(wl_display_sync(m_display)); wl_display_flush(m_display); fronted.push_back(wnb); m_window->attached_width = wnb->width; m_window->attached_height = wnb->height; m_damage_rects = NULL; m_damage_n_rects = 0; unlock(); }
static void _evas_swapper_buffer_put(Wl_Swapper *ws, Wl_Buffer *wb, Eina_Rectangle *rects, unsigned int count) { Eina_Rectangle *rect; LOGFN(__FILE__, __LINE__, __FUNCTION__); /* check for valid swapper */ if (!ws) return; /* make sure swapper has a surface */ if (!ws->surface) return; /* check for valid buffer */ if (!wb) return; /* make sure buffer has mapped data */ if ((!wb->data) || (!wb->buffer)) { /* call function to mmap buffer data */ /* if (!_evas_swapper_buffer_new(ws, wb)) */ return; } rect = eina_rectangle_new(0, 0, 0, 0); if ((rects) && (count > 0)) { unsigned int i = 0; for (i = 0; i < count; i++) eina_rectangle_union(rect, &rects[i]); } else { Eina_Rectangle r; r.x = 0; r.y = 0; r.w = wb->w; r.h = wb->h; eina_rectangle_union(rect, &r); } /* surface attach */ if (ws->buffer_sent != wb) { wl_surface_attach(ws->surface, wb->buffer, ws->dx, ws->dy); ws->dx = 0; ws->dy = 0; ws->buffer_sent = wb; } wl_surface_damage(ws->surface, rect->x, rect->y, rect->w, rect->h); /* surface commit */ wl_surface_commit(ws->surface); eina_rectangle_free(rect); }
static void create_window() { buffer = create_buffer(); wl_surface_attach(surface, buffer, 0, 0); //wl_surface_damage(surface, 0, 0, WIDTH, HEIGHT); wl_surface_commit(surface); }
void hello_bind_buffer(struct wl_buffer *buffer, struct wl_shell_surface *shell_surface) { struct wl_surface *surface; surface = wl_shell_surface_get_user_data(shell_surface); wl_surface_attach(surface, buffer, 0, 0); wl_surface_commit(surface); }
static void Prepare(vout_display_t *vd, picture_t *pic, subpicture_t *subpic, vlc_tick_t date) { VLC_UNUSED(date); vout_display_sys_t *sys = vd->sys; struct wl_display *display = sys->embed->display.wl; struct wl_surface *surface = sys->embed->handle.wl; struct picture_buffer_t *picbuf = pic->p_sys; if (picbuf->fd == -1) return; struct buffer_data *d = malloc(sizeof (*d)); if (unlikely(d == NULL)) return; d->picture = pic; d->counter = &sys->active_buffers; off_t offset = picbuf->offset; const size_t stride = pic->p->i_pitch; const size_t size = pic->p->i_lines * stride; struct wl_shm_pool *pool; struct wl_buffer *buf; pool = wl_shm_create_pool(sys->shm, picbuf->fd, offset + size); if (pool == NULL) { free(d); return; } if (sys->viewport == NULL) /* Poor man's crop */ offset += 4 * vd->fmt.i_x_offset + pic->p->i_pitch * vd->fmt.i_y_offset; buf = wl_shm_pool_create_buffer(pool, offset, vd->fmt.i_visible_width, vd->fmt.i_visible_height, stride, WL_SHM_FORMAT_XRGB8888); wl_shm_pool_destroy(pool); if (buf == NULL) { free(d); return; } picture_Hold(pic); wl_buffer_add_listener(buf, &buffer_cbs, d); wl_surface_attach(surface, buf, 0, 0); wl_surface_damage(surface, 0, 0, sys->display_width, sys->display_height); wl_display_flush(display); sys->active_buffers++; (void) subpic; }
int WaylandNativeWindow::postBuffer(ANativeWindowBuffer* buffer) { TRACE(""); WaylandNativeWindowBuffer *wnb = NULL; lock(); std::list<WaylandNativeWindowBuffer *>::iterator it = post_registered.begin(); for (; it != post_registered.end(); it++) { if ((*it)->other == buffer) { wnb = (*it); break; } } unlock(); if (!wnb) { wnb = new WaylandNativeWindowBuffer(buffer); wnb->common.incRef(&wnb->common); buffer->common.incRef(&buffer->common); } int ret = 0; lock(); wnb->busy = 1; ret = readQueue(false); unlock(); if (ret < 0) { return ret; } lock(); if (wnb->wlbuffer == NULL) { wnb->wlbuffer_from_native_handle(m_android_wlegl, m_display, wl_queue); TRACE("%p add listener with %p inside", wnb, wnb->wlbuffer); wl_buffer_add_listener(wnb->wlbuffer, &wl_buffer_listener, this); wl_proxy_set_queue((struct wl_proxy *) wnb->wlbuffer, this->wl_queue); post_registered.push_back(wnb); } TRACE("%p DAMAGE AREA: %dx%d", wnb, wnb->width, wnb->height); wl_surface_attach(m_window->surface, wnb->wlbuffer, 0, 0); wl_surface_damage(m_window->surface, 0, 0, wnb->width, wnb->height); wl_surface_commit(m_window->surface); wl_display_flush(m_display); posted.push_back(wnb); unlock(); return NO_ERROR; }
int window_render(struct window *window) { window->frame_cb = wl_surface_frame(window->surface); wl_callback_add_listener(window->frame_cb, &listener, window); wl_surface_damage(window->surface, 0, 0, window->buffer->width, window->buffer->height); wl_surface_attach(window->surface, window->buffer->buffer, 0, 0); wl_surface_commit(window->surface); return 1; }
int WaylandNativeWindow::queueBuffer(BaseNativeWindowBuffer* buffer, int fenceFd){ WaylandNativeWindowBuffer *backbuf = (WaylandNativeWindowBuffer *) buffer; int ret = 0; lock(); backbuf->busy = 2; unlock(); while (this->frame_callback && ret != -1) ret = wl_display_dispatch_queue(m_display, this->wl_queue); if (ret < 0) return ret; lock(); this->frame_callback = wl_surface_frame(m_window->surface); wl_callback_add_listener(this->frame_callback, &frame_listener, this); wl_proxy_set_queue((struct wl_proxy *) this->frame_callback, this->wl_queue); if (backbuf->wlbuffer == NULL) { struct wl_array ints; int *ints_data; struct android_wlegl_handle *wlegl_handle; buffer_handle_t handle; handle = backbuf->handle; wl_array_init(&ints); ints_data = (int*) wl_array_add(&ints, handle->numInts*sizeof(int)); memcpy(ints_data, handle->data + handle->numFds, handle->numInts*sizeof(int)); wlegl_handle = android_wlegl_create_handle(m_android_wlegl, handle->numFds, &ints); wl_array_release(&ints); for (int i = 0; i < handle->numFds; i++) { android_wlegl_handle_add_fd(wlegl_handle, handle->data[i]); } backbuf->wlbuffer = android_wlegl_create_buffer(m_android_wlegl, backbuf->width, backbuf->height, backbuf->stride, backbuf->format, backbuf->usage, wlegl_handle); android_wlegl_handle_destroy(wlegl_handle); backbuf->common.incRef(&backbuf->common); TRACE("Add listener for %p with %p inside", backbuf, backbuf->wlbuffer); wl_buffer_add_listener(backbuf->wlbuffer, &wl_buffer_listener, this); wl_proxy_set_queue((struct wl_proxy *) backbuf->wlbuffer, this->wl_queue); } wl_surface_attach(m_window->surface, backbuf->wlbuffer, 0, 0); wl_surface_damage(m_window->surface, 0, 0, backbuf->width, backbuf->height); wl_surface_commit(m_window->surface); fronted.push_back(backbuf); unlock(); return NO_ERROR; }
static void clutter_wayland_handle_pointer_enter (void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y) { ClutterInputDeviceWayland *device = data; ClutterStageCogl *stage_cogl; ClutterEvent *event; ClutterBackend *backend; ClutterBackendWayland *backend_wayland; stage_cogl = wl_surface_get_user_data (surface); device->pointer_focus = stage_cogl; _clutter_input_device_set_stage (CLUTTER_INPUT_DEVICE (device), stage_cogl->wrapper); event = clutter_event_new (CLUTTER_ENTER); event->crossing.stage = stage_cogl->wrapper; event->crossing.time = 0; /* ?! */ event->crossing.x = wl_fixed_to_double(x); event->crossing.y = wl_fixed_to_double(y); event->crossing.source = CLUTTER_ACTOR (stage_cogl->wrapper); event->crossing.device = CLUTTER_INPUT_DEVICE (device); device->x = event->crossing.x; device->y = event->crossing.y; _clutter_event_push (event, FALSE); /* Set the cursor to the cursor loaded at backend initialisation */ backend = clutter_get_default_backend (); backend_wayland = CLUTTER_BACKEND_WAYLAND (backend); wl_pointer_set_cursor (pointer, serial, backend_wayland->cursor_surface, backend_wayland->cursor_x, backend_wayland->cursor_y); wl_surface_attach (backend_wayland->cursor_surface, backend_wayland->cursor_buffer, 0, 0); wl_surface_damage (backend_wayland->cursor_surface, 0, 0, 32, /* XXX: FFS */ 32); wl_surface_commit (backend_wayland->cursor_surface); }
void QWaylandCursor::ensureSurface(const QSize &size) { if (!mBuffer || mBuffer->size() != size) { delete mBuffer; mBuffer = new QWaylandShmBuffer(mDisplay, size, QImage::Format_ARGB32); } if (!mSurface) mSurface = mDisplay->createSurface(0); wl_surface_attach(mSurface, mBuffer->buffer(), 0, 0); }
void QWaylandWindow::setVisible(bool visible) { if (visible) { if (mBuffer) wl_surface_attach(mSurface, mBuffer->buffer(), 0, 0); if (!mSentInitialResize) { QWindowSystemInterface::handleGeometryChange(window(), geometry()); QWindowSystemInterface::flushWindowSystemEvents(); mSentInitialResize = true; } QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size())); QWindowSystemInterface::flushWindowSystemEvents(); } else { QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size())); QWindowSystemInterface::flushWindowSystemEvents(); wl_surface_attach(mSurface, 0,0,0); damage(QRect(QPoint(0,0),geometry().size())); } }
static void _eventd_nd_cursor_set_image(EventdNdBackendContext *self, int i) { struct wl_buffer *buffer; struct wl_cursor_image *image; image = self->cursor.cursor->images[i]; self->cursor.image = image; buffer = wl_cursor_image_get_buffer(self->cursor.image); wl_surface_attach(self->cursor.surface, buffer, 0, 0); wl_surface_damage(self->cursor.surface, 0, 0, self->cursor.image->width, self->cursor.image->height); wl_surface_commit(self->cursor.surface); }
static void draw_initial_frame(struct wayland_output *output) { struct wayland_compositor *c = (struct wayland_compositor *) output->base.compositor; struct wl_shm *shm = c->parent.shm; struct wl_surface *surface = output->parent.surface; struct wl_shm_pool *pool; struct wl_buffer *buffer; int width, height, stride; int size; int fd; void *data; width = output->mode.width + c->border.left + c->border.right; height = output->mode.height + c->border.top + c->border.bottom; stride = width * 4; size = height * stride; fd = os_create_anonymous_file(size); if (fd < 0) { perror("os_create_anonymous_file"); return; } data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (data == MAP_FAILED) { perror("mmap"); close(fd); return; } pool = wl_shm_create_pool(shm, fd, size); buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, WL_SHM_FORMAT_ARGB8888); wl_buffer_add_listener(buffer, &buffer_listener, buffer); wl_shm_pool_destroy(pool); close(fd); memset(data, 0, size); wl_surface_attach(surface, buffer, 0, 0); /* We only need to damage some part, as its only transparant * pixels anyway. */ wl_surface_damage(surface, 0, 0, 1, 1); }
void render_frame(struct swaynag *swaynag) { if (!swaynag->run_display) { return; } cairo_surface_t *recorder = cairo_recording_surface_create( CAIRO_CONTENT_COLOR_ALPHA, NULL); cairo_t *cairo = cairo_create(recorder); cairo_save(cairo); cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR); cairo_paint(cairo); cairo_restore(cairo); uint32_t height = render_to_cairo(cairo, swaynag); if (height != swaynag->height) { zwlr_layer_surface_v1_set_size(swaynag->layer_surface, 0, height); zwlr_layer_surface_v1_set_exclusive_zone(swaynag->layer_surface, height); wl_surface_commit(swaynag->surface); wl_display_roundtrip(swaynag->display); } else { swaynag->current_buffer = get_next_buffer(swaynag->shm, swaynag->buffers, swaynag->width * swaynag->scale, swaynag->height * swaynag->scale); if (!swaynag->current_buffer) { sway_log(SWAY_DEBUG, "Failed to get buffer. Skipping frame."); goto cleanup; } cairo_t *shm = swaynag->current_buffer->cairo; cairo_save(shm); cairo_set_operator(shm, CAIRO_OPERATOR_CLEAR); cairo_paint(shm); cairo_restore(shm); cairo_set_source_surface(shm, recorder, 0.0, 0.0); cairo_paint(shm); wl_surface_set_buffer_scale(swaynag->surface, swaynag->scale); wl_surface_attach(swaynag->surface, swaynag->current_buffer->buffer, 0, 0); wl_surface_damage(swaynag->surface, 0, 0, swaynag->width, swaynag->height); wl_surface_commit(swaynag->surface); wl_display_roundtrip(swaynag->display); } cleanup: cairo_surface_destroy(recorder); cairo_destroy(cairo); }