static int get_glyph_surface(bitmap_backend_data_t *data, glyph_id_t glyph_id, surface_t **result) { if (glyph_id >= data->glyph_count) return ENOENT; if (data->glyph_cache[glyph_id].surface != NULL) { *result = data->glyph_cache[glyph_id].surface; return EOK; } surface_t *raw_surface; int rc = data->decoder->load_glyph_surface(data->decoder_data, glyph_id, &raw_surface); if (rc != EOK) return rc; sysarg_t w; sysarg_t h; surface_get_resolution(raw_surface, &w, &h); if (!data->scale) { *result = raw_surface; return EOK; } source_t source; source_init(&source); source_set_texture(&source, raw_surface, PIXELMAP_EXTEND_TRANSPARENT_BLACK); transform_t transform; transform_identity(&transform); transform_translate(&transform, 0.5, 0.5); transform_scale(&transform, data->scale_ratio, data->scale_ratio); source_set_transform(&source, transform); surface_coord_t scaled_width = (data->scale_ratio * ((double) w) + 0.5); surface_coord_t scaled_height = (data->scale_ratio * ((double) h) + 0.5); surface_t *scaled_surface = surface_create(scaled_width, scaled_height, NULL, 0); if (!scaled_surface) { surface_destroy(raw_surface); return ENOMEM; } drawctx_t context; drawctx_init(&context, scaled_surface); drawctx_set_source(&context, &source); drawctx_transfer(&context, 0, 0, scaled_width, scaled_height); surface_destroy(raw_surface); data->glyph_cache[glyph_id].surface = scaled_surface; *result = scaled_surface; return EOK; }
static bool surface_attach(struct ctx *context, struct wlc_context *bound, struct wlc_surface *surface, struct wlc_buffer *buffer) { assert(context && bound && surface); struct wl_resource *wl_buffer; if (!buffer || !(wl_buffer = convert_to_wl_resource(buffer, "buffer"))) { surface_destroy(context, bound, surface); return true; } EGLint format; bool attached = false; struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(wl_buffer); if (shm_buffer) { attached = shm_attach(surface, buffer, shm_buffer); } else if (wlc_context_query_buffer(bound, (void*)wl_buffer, EGL_TEXTURE_FORMAT, &format)) { attached = egl_attach(context, bound, surface, buffer, format); } else { /* unknown buffer */ wlc_log(WLC_LOG_WARN, "Unknown buffer"); } if (attached) wlc_dlog(WLC_DBG_RENDER, "-> Attached surface (%" PRIuWLC ") with buffer of size (%ux%u)", convert_to_wlc_resource(surface), buffer->size.w, buffer->size.h); return attached; }
static void bb_release(void *backend_data) { bitmap_backend_data_t *data = (bitmap_backend_data_t *) backend_data; for (size_t i = 0; i < data->glyph_count; ++i) { if (data->glyph_cache[i].surface) { surface_destroy(data->glyph_cache[i].surface); } } free(data->glyph_cache); data->decoder->release(data->decoder_data); }
void tvh_destroy(tvh_object_t *tvh) { DEBUG("Destroying TVHPlayer"); opensles_destroy(tvh->ao); free(tvh->acs); free(tvh->ao); surface_destroy(tvh->vo); free(tvh->vcs); free(tvh->vo); pthread_mutex_destroy(&tvh->mutex); free(tvh); }
int main(int argc, char *argv[]) { int fd; /* fd to Erlang node */ unsigned char buf[BUFSIZE]; /* Buffer for incoming message */ ErlMessage emsg; /* Incoming message */ int c_node; /* C-Node number */ char cookie[EI_MAX_COOKIE_SIZE+1]; /* Shared cookie */ short creation; /* ?? */ char *erlang_node; /* Erlang node to connect to */ char *cookie_opt; /* Where to source our cookie */ char *cookie_data; /* Either the filename or literal cookie */ ETERM *fromp, *msgp, *fnp, *argp, *resp; int received, loop = 1; if (argc < 5) { quit_with_error("invalid_args"); } c_node = atoi(argv[1]); cookie_opt = argv[2]; cookie_data = argv[3]; creation = 0; erlang_node = argv[4]; erl_init(NULL, 0); get_cookie(cookie_opt, cookie_data, cookie); if (!erl_connect_init(c_node, cookie, creation)) { quit_with_error("erl_connect_init"); } if ((fd = erl_connect(erlang_node)) < 0) { quit_with_error("erl_connect"); } while (loop) { received = erl_receive_msg(fd, buf, BUFSIZE, &emsg); if (received == ERL_TICK) { /* ignore */ } else if (received == ERL_ERROR) { loop = 0; } else { if (emsg.type == ERL_REG_SEND) { fromp = erl_element(2, emsg.msg); msgp = erl_element(3, emsg.msg); fnp = erl_element(1, msgp); argp = erl_element(2, msgp); if (is_function(fnp, "stop")) { loop = 0; resp = erl_format("{c_node, ~i, ok}", c_node); } else if (is_function(fnp, "new_image_blank")) { resp = new_image_blank(argp, c_node); } else if (is_function(fnp, "write_to_png")) { resp = write_to_png(argp, c_node); } else if (is_function(fnp, "close_image")) { resp = close_image(argp, c_node); } else if (is_function(fnp, "save")) { resp = save(argp, c_node); } else if (is_function(fnp, "restore")) { resp = restore(argp, c_node); } else if (is_function(fnp, "set_line_width")) { resp = set_line_width(argp, c_node); } else if (is_function(fnp, "set_source_rgba")) { resp = set_source_rgba(argp, c_node); } else if (is_function(fnp, "set_operator")) { resp = set_operator(argp, c_node); } else if (is_function(fnp, "move_to")) { resp = move_to(argp, c_node); } else if (is_function(fnp, "line_to")) { resp = line_to(argp, c_node); } else if (is_function(fnp, "curve_to")) { resp = curve_to(argp, c_node); } else if (is_function(fnp, "rel_move_to")) { resp = rel_move_to(argp, c_node); } else if (is_function(fnp, "rel_line_to")) { resp = rel_line_to(argp, c_node); } else if (is_function(fnp, "rel_curve_to")) { resp = rel_curve_to(argp, c_node); } else if (is_function(fnp, "rectangle")) { resp = rectangle(argp, c_node); } else if (is_function(fnp, "arc")) { resp = arc(argp, c_node); } else if (is_function(fnp, "arc_negative")) { resp = arc_negative(argp, c_node); } else if (is_function(fnp, "close_path")) { resp = close_path(argp, c_node); } else if (is_function(fnp, "paint")) { resp = paint(argp, c_node); } else if (is_function(fnp, "fill")) { resp = fill(argp, c_node); } else if (is_function(fnp, "fill_preserve")) { resp = fill_preserve(argp, c_node); } else if (is_function(fnp, "stroke")) { resp = stroke(argp, c_node); } else if (is_function(fnp, "stroke_preserve")) { resp = stroke_preserve(argp, c_node); } else if (is_function(fnp, "translate")) { resp = translate(argp, c_node); } else if (is_function(fnp, "scale")) { resp = scale(argp, c_node); } else if (is_function(fnp, "rotate")) { resp = rotate(argp, c_node); } else if (is_function(fnp, "select_font")) { resp = select_font_face(argp, c_node); } else if (is_function(fnp, "set_font_size")) { resp = set_font_size(argp, c_node); } else if (is_function(fnp, "show_text")) { resp = show_text(argp, c_node); } else if (is_function(fnp, "text_extents")) { resp = text_extents(argp, c_node); } else if (is_function(fnp, "surface_create_from_png")) { resp = surface_create_from_png(argp, c_node); } else if (is_function(fnp, "surface_create_from_png_stream")) { resp = surface_create_from_png_stream(argp, c_node); } else if (is_function(fnp, "surface_get_width")) { resp = surface_get_width(argp, c_node); } else if (is_function(fnp, "surface_get_height")) { resp = surface_get_height(argp, c_node); } else if (is_function(fnp, "surface_destroy")) { resp = surface_destroy(argp, c_node); } else if (is_function(fnp, "set_source_surface")) { resp = set_source_surface(argp, c_node); } else if (is_function(fnp, "write_to_png_stream")) { resp = write_to_png_stream(argp, c_node); } else { resp = erl_format("{c_node, ~i, {error, '~s'}}", c_node, "unknown command"); } erl_send(fd, fromp, resp); erl_free_term(emsg.from); erl_free_term(emsg.msg); erl_free_term(fromp); erl_free_term(msgp); erl_free_term(fnp); erl_free_term(argp); erl_free_term(resp); } } } exit(EXIT_SUCCESS); }