void SoftwareRendererImp::draw_svg( SVG& svg ) { // set top level transformation transformation = canvas_to_screen; //allocate array for new target size_t super_w, super_h, super_size; super_w = this->target_w * sample_rate; super_h = this->target_h * sample_rate; unsigned char* old_buf = this->render_target; unsigned char* super_buf = new unsigned char [super_w * super_h * 4]; set_render_target( super_buf, super_w, super_h ); clear_target(); /* printf("before rendering:\n"); for (size_t i = 0; i < super_w * super_h; i++ ) { if (super_buf[i] != 255) { printf("super_buf[%zu] = %u\n", i, super_buf[i]); } } */ // draw all elements for ( size_t i = 0; i < svg.elements.size(); ++i ) { transformation = canvas_to_screen; draw_element(svg.elements[i]); } // draw canvas outline Vector2D a = transform(Vector2D( 0 , 0 )); a.x--; a.y++; Vector2D b = transform(Vector2D(svg.width, 0 )); b.x++; b.y++; Vector2D c = transform(Vector2D( 0 ,svg.height)); c.x--; c.y--; Vector2D d = transform(Vector2D(svg.width,svg.height)); d.x++; d.y--; rasterize_line(a.x, a.y, b.x, b.y, Color::Black); rasterize_line(a.x, a.y, c.x, c.y, Color::Black); rasterize_line(d.x, d.y, b.x, b.y, Color::Black); rasterize_line(d.x, d.y, c.x, c.y, Color::Black); this->sample_buffer = super_buf; /* printf("after rendering:\n"); for (size_t i = 0; i < super_w * super_h; i++ ) { if (super_buf[i] != 255) { printf("super_buf[%zu] = %u\n", i, super_buf[i]); } } */ set_render_target( old_buf, super_w / sample_rate, super_h / sample_rate); clear_target(); // resolve and send to render target resolve(); }
/* Register a function to handle a stream_interface as a standalone task. The * new task itself is returned and is assigned as si->owner. The stream_interface * pointer will be pointed to by the task's context. The handler can be detached * by using stream_int_unregister_handler(). * FIXME: the code should be updated to ensure that we don't change si->owner * anymore as this is not needed. However, process_session still relies on it. */ struct task *stream_int_register_handler_task(struct stream_interface *si, struct task *(*fct)(struct task *)) { struct task *t; DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", fct, si, si->owner); si->update = stream_int_update; si->shutr = stream_int_shutr; si->shutw = stream_int_shutw; si->chk_rcv = stream_int_chk_rcv; si->chk_snd = stream_int_chk_snd; si->connect = NULL; clear_target(&si->target); si->release = NULL; si->flags |= SI_FL_WAIT_DATA; t = task_new(); si->owner = t; if (!t) return t; set_target_task(&si->target, t); t->process = fct; t->context = si; task_wakeup(si->owner, TASK_WOKEN_INIT); return t; }
/* Unregister a stream interface handler. This must be called by the handler task * itself when it detects that it is in the SI_ST_DIS state. This function can * both detach standalone handlers and embedded handlers. */ void stream_int_unregister_handler(struct stream_interface *si) { if (si->target.type == TARG_TYPE_TASK) { /* external handler : kill the task */ task_delete(si->target.ptr.t); task_free(si->target.ptr.t); } si->release = NULL; si->owner = NULL; clear_target(&si->target); }
/* * Name: averify * Description: This function verifies and (if fix > 0) fixes the attributes * of the file at the path provided. * Arguments: fix - 0 - do not fix entries, 1 - fix entries * ftype - single character "type" the entry is supposed to be * path - path to file * ainfo - attribute info structure representing the attributes * the entry is supposed to be * NOTE: attributes are links and permissions * Possible return values: * - 0 = successful * - VE_EXIST = path name does not exist * - VE_FTYPE = path file type is not recognized, is not supported, * or is not what was expected * - VE_ATTR = path mode/group/user is not what was expected * - VE_CONT = mod time/link target/major/minor/size/file system type/current * directory is not what was expected * - VE_FAIL = utime/target directory/link/stat/symlink/mknod/chmod/statvfs/ * chown failed */ int averify(int fix, char *ftype, char *path, struct ainfo *ainfo) { struct group *grp; /* group entry buffer */ struct passwd *pwd; int n; int setval; int uid, gid; int dochown; int retcode; int statError = 0; int targ_is_dir = 0; /* replacing a directory */ char myftype; char buf[PATH_MAX]; ino_t my_ino; dev_t my_dev; char cwd[MAXPATHLEN]; char *cd; char *c; setval = (*ftype == '?'); retcode = 0; reperr(NULL); if (get_disable_attribute_check()) { return (0); } if (*ftype == 'l') { if (stat(path, &status) < 0) { retcode = VE_EXIST; reperr(pkg_gt(ERR_EXIST)); } my_ino = status.st_ino; my_dev = status.st_dev; /* Get copy of the current working directory */ if (getcwd(cwd, MAXPATHLEN) == NULL) { reperr(pkg_gt(ERR_GETWD)); return (VE_FAIL); } /* * Change to the directory in which the hard * link is to be created. */ cd = strdup(path); c = strrchr(cd, '/'); if (c) { /* bugid 4247895 */ if (strcmp(cd, c) == 0) (void) strcpy(cd, "/"); else *c = NULL; if (chdir(cd) != 0) { reperr(pkg_gt(ERR_CHDIR), cd); return (VE_FAIL); } } free(cd); if (retcode || (status.st_nlink < 2) || (stat(ainfo->local, &status) < 0) || (my_dev != status.st_dev) || (my_ino != status.st_ino)) { if (fix) { /* * Don't want to do a hard link to a * directory. */ if (!isdir(ainfo->local)) { (void) chdir(cwd); reperr(pkg_gt(ERR_LINKISDIR), ainfo->local); return (VE_FAIL); } /* Now do the link. */ if (!clear_target(path, ftype, targ_is_dir)) return (VE_FAIL); if (link(ainfo->local, path)) { (void) chdir(cwd); reperr(pkg_gt(ERR_LINKFAIL), ainfo->local); return (VE_FAIL); } retcode = 0; } else { /* Go back to previous working directory */ if (chdir(cwd) != 0) reperr(pkg_gt(ERR_CHDIR), cwd); reperr(pkg_gt(ERR_LINK), ainfo->local); return (VE_CONT); } } /* Go back to previous working directory */ if (chdir(cwd) != 0) { reperr(pkg_gt(ERR_CHDIR), cwd); return (VE_CONT); } return (retcode); } retcode = 0; /* If we are to process symlinks the old way then we follow the link */ if (nonABI_symlinks()) { if ((*ftype == 's') ? lstat(path, &status) : stat(path, &status)) { reperr(pkg_gt(ERR_EXIST)); retcode = VE_EXIST; myftype = '?'; statError++; } /* If not then we inspect the target of the link */ } else { if ((n = lstat(path, &status)) == -1) { reperr(pkg_gt(ERR_EXIST)); retcode = VE_EXIST; myftype = '?'; statError++; } } if (!statError) { /* determining actual type of existing object */ switch (status.st_mode & S_IFMT) { case S_IFLNK: myftype = 's'; break; case S_IFIFO: myftype = 'p'; break; case S_IFCHR: myftype = 'c'; break; case S_IFDIR: myftype = 'd'; targ_is_dir = 1; break; case S_IFBLK: myftype = 'b'; break; case S_IFREG: case 0: myftype = 'f'; break; case S_IFDOOR: myftype = 'D'; break; default: reperr(pkg_gt(ERR_UNKNOWN)); return (VE_FTYPE); } } if (setval) { /* * Check to make sure that a package or an installf that uses * wild cards '?' to assume the ftype of an object on the * system is not assuming a door ftype. Doors are not supported * but should be ignored. */ if (myftype == 'D') { reperr(pkg_gt(ERR_FTYPED), path); retcode = VE_FTYPE; return (VE_FTYPE); } else { *ftype = myftype; } } else if (!retcode && (*ftype != myftype) && ((myftype != 'f') || !strchr("ilev", *ftype)) && ((myftype != 'd') || (*ftype != 'x'))) { reperr(pkg_gt(ERR_FTYPE), *ftype, myftype); retcode = VE_FTYPE; } if (!retcode && (*ftype == 's')) { /* make sure that symbolic link is correct */ n = readlink(path, buf, PATH_MAX); if (n < 0) { reperr(pkg_gt(ERR_SLINK), ainfo->local); retcode = VE_CONT; } else if (ainfo->local != NULL) { buf[n] = '\0'; if (strcmp(buf, ainfo->local)) { reperr(pkg_gt(ERR_SLINK), ainfo->local); retcode = VE_CONT; } } else if (ainfo->local == NULL) { /* * Since a sym link target exists, insert it * into the ainfo structure */ buf[n] = '\0'; ainfo->local = strdup(buf); } } if (retcode) { /* The path doesn't exist or is different than it should be. */ if (fix) { /* * Clear the way for the write. If it won't clear, * there's nothing we can do. */ if (!clear_target(path, ftype, targ_is_dir)) return (VE_FAIL); if ((*ftype == 'd') || (*ftype == 'x')) { char *pt, *p; /* Try to make it the easy way */ if (mkdir(path, ainfo->mode)) { /* * Failing that, walk through the * parent directories creating * whatever is needed. */ p = strdup(path); pt = (*p == '/') ? p+1 : p; do { if (pt = strchr(pt, '/')) *pt = '\0'; if (access(p, 0) && mkdir(p, ainfo->mode)) break; if (pt) *pt++ = '/'; } while (pt); free(p); } if (stat(path, &status) < 0) { reperr(pkg_gt(ERR_DIRFAIL)); return (VE_FAIL); } } else if (*ftype == 's') { if (symlink(ainfo->local, path)) { reperr(pkg_gt(ERR_SLINKFAIL), ainfo->local); return (VE_FAIL); } } else if (*ftype == 'c') { int wilddevno = 0; /* * The next three if's support 2.4 and older * packages that use "?" as device numbers. * This should be considered for removal by * release 2.7 or so. */ if (ainfo->major == BADMAJOR) { ainfo->major = 0; wilddevno = 1; } if (ainfo->minor == BADMINOR) { ainfo->minor = 0; wilddevno = 1; } if (wilddevno) { wilddevno = 0; logerr(MSG_WLDDEVNO, path, ainfo->major, ainfo->minor); } if (mknod(path, ainfo->mode | S_IFCHR, makedev(ainfo->major, ainfo->minor)) || (stat(path, &status) < 0)) { reperr(pkg_gt(ERR_CDEVFAIL)); return (VE_FAIL); } } else if (*ftype == 'b') { int wilddevno = 0; /* * The next three if's support 2.4 and older * packages that use "?" as device numbers. * This should be considered for removal by * release 2.7 or so. */ if (ainfo->major == BADMAJOR) { ainfo->major = 0; wilddevno = 1; } if (ainfo->minor == BADMINOR) { ainfo->minor = 0; wilddevno = 1; } if (wilddevno) { wilddevno = 0; logerr(MSG_WLDDEVNO, path, ainfo->major, ainfo->minor); } if (mknod(path, ainfo->mode | S_IFBLK, makedev(ainfo->major, ainfo->minor)) || (stat(path, &status) < 0)) { reperr(pkg_gt(ERR_BDEVFAIL)); return (VE_FAIL); } } else if (*ftype == 'p') { if (mknod(path, ainfo->mode | S_IFIFO, NULL) || (stat(path, &status) < 0)) { reperr(pkg_gt(ERR_PIPEFAIL)); return (VE_FAIL); } } else return (retcode); } else return (retcode); } if (*ftype == 's') return (0); /* don't check anything else */ if (*ftype == 'i') return (0); /* don't check anything else */ retcode = 0; if ((myftype == 'c') || (myftype == 'b')) { if (setval || (ainfo->major == BADMAJOR)) ainfo->major = major(status.st_rdev); if (setval || (ainfo->minor == BADMINOR)) ainfo->minor = minor(status.st_rdev); /* check major & minor */ if (status.st_rdev != makedev(ainfo->major, ainfo->minor)) { reperr(pkg_gt(ERR_MAJMIN), ainfo->major, ainfo->minor, major(status.st_rdev), minor(status.st_rdev)); retcode = VE_CONT; } } /* compare specified mode w/ actual mode excluding sticky bit */ if (setval || (ainfo->mode == BADMODE) || (ainfo->mode == WILDCARD)) ainfo->mode = status.st_mode & 07777; else if ((ainfo->mode & 06777) != (status.st_mode & 06777)) { if (fix) { if ((ainfo->mode == BADMODE) || (chmod(path, ainfo->mode) < 0)) retcode = VE_FAIL; } else { reperr(pkg_gt(ERR_PERM), ainfo->mode, status.st_mode & 07777); if (!retcode) retcode = VE_ATTR; } } dochown = 0; /* get group entry for specified group */ if (setval || strcmp(ainfo->group, BADGROUP) == 0) { grp = cgrgid(status.st_gid); if (grp) (void) strcpy(ainfo->group, grp->gr_name); else { if (!retcode) retcode = VE_ATTR; reperr(pkg_gt(ERR_BADGRPID), status.st_gid); } gid = status.st_gid; } else if ((grp = cgrnam(ainfo->group)) == NULL) { reperr(pkg_gt(ERR_BADGRPNM), ainfo->group); if (!retcode) retcode = VE_ATTR; } else if ((gid = grp->gr_gid) != status.st_gid) { if (fix) { /* save specified GID */ gid = grp->gr_gid; dochown++; } else { if ((grp = cgrgid((int)status.st_gid)) == (struct group *)NULL) { reperr(pkg_gt(ERR_GROUP), ainfo->group, "(null)"); } else { reperr(pkg_gt(ERR_GROUP), ainfo->group, grp->gr_name); } if (!retcode) retcode = VE_ATTR; } } /* get password entry for specified owner */ if (setval || strcmp(ainfo->owner, BADOWNER) == 0) { pwd = cpwuid((int)status.st_uid); if (pwd) (void) strcpy(ainfo->owner, pwd->pw_name); else { if (!retcode) retcode = VE_ATTR; reperr(pkg_gt(ERR_BADUSRID), status.st_uid); } uid = status.st_uid; } else if ((pwd = cpwnam(ainfo->owner)) == NULL) { /* UID does not exist in password file */ reperr(pkg_gt(ERR_BADUSRNM), ainfo->owner); if (!retcode) retcode = VE_ATTR; } else if ((uid = pwd->pw_uid) != status.st_uid) { /* get owner name for actual UID */ if (fix) { uid = pwd->pw_uid; dochown++; } else { pwd = cpwuid((int)status.st_uid); if (pwd == NULL) reperr(pkg_gt(ERR_BADUSRID), (int)status.st_uid); else reperr(pkg_gt(ERR_OWNER), ainfo->owner, pwd->pw_name); if (!retcode) retcode = VE_ATTR; } } if (statvfs(path, &vfsstatus) < 0) { reperr(pkg_gt(ERR_EXIST)); retcode = VE_FAIL; } else { if (dochown) { /* pcfs doesn't support file ownership */ if (strcmp(vfsstatus.f_basetype, "pcfs") != 0 && chown(path, uid, gid) < 0) { retcode = VE_FAIL; /* chown failed */ } } } if (retcode == VE_FAIL) reperr(pkg_gt(ERR_ATTRFAIL)); return (retcode); }