static void resizor_draw(struct resizor *resizor) { cairo_surface_t *surface; cairo_t *cr; struct rectangle allocation; window_draw(resizor->window); window_get_child_allocation(resizor->window, &allocation); surface = window_get_surface(resizor->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_fill(cr); cairo_destroy(cr); cairo_surface_destroy(surface); window_flush(resizor->window); if (fabs(resizor->height.previous - resizor->height.target) > 0.1) { wl_display_frame_callback(display_get_display(resizor->display), frame_callback, resizor); } }
static void allocate_buffer(struct gears *gears) { EGLImageKHR image; struct rectangle allocation; window_draw(gears->window); gears->surface[gears->current] = window_get_surface(gears->window); #ifdef HAVE_CAIRO_EGL image = display_get_image_for_drm_surface(gears->display, gears->surface[gears->current]); #else /* XXX: hack to make Wayland compile, even if this example doesn't run */ die("gears cannot allocate buffer: it was compiled without cairo-gl\n"); return; #endif if (!eglMakeCurrent(gears->display, NULL, NULL, gears->context)) die("faile to make context current\n"); glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->color_rbo[gears->current]); glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, image); glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->depth_rbo); window_get_child_allocation(gears->window, &allocation); glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, allocation.width + 20 + 32, allocation.height + 60 + 32); }
static void draw_gears(struct gears *gears) { GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; struct rectangle window_allocation; struct rectangle allocation; window_draw(gears->window); window_get_child_allocation(gears->window, &allocation); window_get_allocation(gears->window, &window_allocation); display_acquire_window_surface(gears->d, gears->window, gears->context); glViewport(allocation.x, window_allocation.height - allocation.height - allocation.x, allocation.width, allocation.height); glScissor(allocation.x, window_allocation.height - allocation.height - allocation.y, allocation.width, allocation.height); glEnable(GL_SCISSOR_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0.0, 0.0, -50); glRotatef(view_rotx, 1.0, 0.0, 0.0); glRotatef(view_roty, 0.0, 1.0, 0.0); glRotatef(view_rotz, 0.0, 0.0, 1.0); glPushMatrix(); glTranslatef(-3.0, -2.0, 0.0); glRotatef(gears->angle, 0.0, 0.0, 1.0); glCallList(gears->gear_list[0]); glPopMatrix(); glPushMatrix(); glTranslatef(3.1, -2.0, 0.0); glRotatef(-2.0 * gears->angle - 9.0, 0.0, 0.0, 1.0); glCallList(gears->gear_list[1]); glPopMatrix(); glPushMatrix(); glTranslatef(-3.1, 4.2, 0.0); glRotatef(-2.0 * gears->angle - 25.0, 0.0, 0.0, 1.0); glCallList(gears->gear_list[2]); glPopMatrix(); glPopMatrix(); glFlush(); display_release(gears->d); window_flush(gears->window); }
static void image_draw(struct image *image) { struct rectangle allocation; GdkPixbuf *pb; cairo_t *cr; cairo_surface_t *surface; window_draw(image->window); window_get_child_allocation(image->window, &allocation); pb = gdk_pixbuf_new_from_file_at_size(image->filename, allocation.width, allocation.height, NULL); if (pb == NULL) return; surface = window_get_surface(image->window); cr = cairo_create(surface); window_get_child_allocation(image->window, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_push_group(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_paint(cr); set_source_pixbuf(cr, pb, 0, 0, allocation.width, allocation.height); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_paint(cr); g_object_unref(pb); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); window_flush(image->window); cairo_surface_destroy(surface); }
static void draw_gears(struct gears *gears) { GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; struct rectangle allocation; if (gears->surface[gears->current] == NULL) allocate_buffer(gears); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, gears->color_rbo[gears->current]); window_get_child_allocation(gears->window, &allocation); glViewport(allocation.x, allocation.y, allocation.width, allocation.height); glScissor(allocation.x, allocation.y, allocation.width, allocation.height); glEnable(GL_SCISSOR_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0.0, 0.0, -50); glRotatef(view_rotx, 1.0, 0.0, 0.0); glRotatef(view_roty, 0.0, 1.0, 0.0); glRotatef(view_rotz, 0.0, 0.0, 1.0); glPushMatrix(); glTranslatef(-3.0, -2.0, 0.0); glRotatef(gears->angle, 0.0, 0.0, 1.0); glCallList(gears->gear_list[0]); glPopMatrix(); glPushMatrix(); glTranslatef(3.1, -2.0, 0.0); glRotatef(-2.0 * gears->angle - 9.0, 0.0, 0.0, 1.0); glCallList(gears->gear_list[1]); glPopMatrix(); glPushMatrix(); glTranslatef(-3.1, 4.2, 0.0); glRotatef(-2.0 * gears->angle - 25.0, 0.0, 0.0, 1.0); glCallList(gears->gear_list[2]); glPopMatrix(); glPopMatrix(); glFlush(); window_set_surface(gears->window, gears->surface[gears->current]); window_flush(gears->window); }
static void keyboard_focus_handler(struct window *window, struct input *device, void *data) { struct gears *gears = data; struct rectangle allocation; window_get_child_allocation(gears->window, &allocation); resize_handler(window, allocation.width, allocation.height, gears); }