📄 pw_cms.c
字号:
/* Would make static if weren't worried about breaking someones program */pw_setgrnd( pw, first, last, frred, frgreen, frblue, bkred, bkgreen, bkblue) struct pixwin *pw; int first, last; unsigned char frred, frgreen, frblue, bkred, bkgreen, bkblue;{ unsigned char red[256], green[256], blue[256]; struct colormapseg cms; (void)pw_getcmsdata(pw, &cms, NO_PLANE_PTR); (void)pw_getcolormap( pw, 0, cms.cms_size, red, green, blue); red[first] = bkred; green[first] = bkgreen; blue[first] = bkblue; red[last] = frred; green[last] = frgreen; blue[last] = frblue; (void)pw_putcolormap( pw, 0, cms.cms_size, red, green, blue);}/* Referenced from pw_access.c */pw_initcms(pw) register Pixwin *pw;{ extern int pw_damaged(); u_char red[256], green[256], blue[256]; struct colormapseg cms; struct cms_map map; int new_planes; int original_plane_group, new_plane_group; int new_window; register int i; /* * Choose the initial colormap segment */ /* Set up default cms, but don't do anything to pw yet */ (void)pw_initdefaultcms(pw); /* Determine current window cms state */ (void)pw_getcmsdata(pw, &cms, NO_PLANE_PTR); /* The name indicates whether or not the cms has been set yet */ if (cms.cms_name[0] == '\0') { /* * The cms for this window hasn't been set yet. * So, initialize it to the default cms for this process. */ map.cm_red = red; map.cm_green = green; map.cm_blue = blue; cms.cms_size = 256; (void)pw_getdefaultcms(&cms, &map); /* Set the name in the pixwin */ (void)strncpy(pw->pw_cmsname, cms.cms_name, CMS_NAMESIZE); /* * Will prepare surface because first pixwin on window. * Is guaranteed to cover window because can't be region. */ new_window = 1; } else { /* Set the name in the pixwin (pw_getcolormap needs name set) */ (void)strncpy(pw->pw_cmsname, cms.cms_name, CMS_NAMESIZE); /* Initialize pixwin with existing cms */ (void)pw_getcolormap(pw, 0, cms.cms_size, red, green, blue); /* Wouldn't prepare surface because 1st pixwin did */ new_window = 0; } /* * Choose the initial plane group */ if (!pw_global_groups_available_set) { win_get_plane_groups_available(pw->pw_windowfd, pw->pw_pixrect, &pw_global_groups_available); pw_global_groups_available_set = 1; } /* Find out 'user' preference if not explicitly set by program */ if (!pw_plane_group_preference_set) pw_read_plane_group_preference(pw); /* Find out available planes from pixrect */ (void) pr_available_plane_groups(pw->pw_pixrect, PIX_MAX_PLANE_GROUPS, pw->pw_clipdata->pwcd_plane_groups_available); /* Restrict available planes */ for (i = 0; i < WIN_MAX_PLANE_GROUPS; i++) { if (pw->pw_clipdata->pwcd_plane_groups_available[i] && !pw_global_groups_available.plane_groups_available[i]) pw->pw_clipdata->pwcd_plane_groups_available[i] = 0; } /* Use existing plane group if already set */ if (!new_window) /* Use existing plane group */ original_plane_group = new_plane_group = win_get_plane_group(pw->pw_windowfd, pw->pw_pixrect); else { /* * The plane group for this window hasn't been set yet. * So, initialize it based on default cms name, user * preference and availability. */ new_plane_group = pw_choose_prefered_plane_group(pw, &original_plane_group); } /* * Set the initial plane group */ if (original_plane_group != new_plane_group) /* Tell kernel about this window's choice of plane group */ win_set_plane_group(pw->pw_windowfd, new_plane_group); /* Put plane group in pixrect (this may be redundant) */ pw_set_plane_group(pw, new_plane_group); /* * Set the pixrect planes attribute. We always choose the full * planes available to a given cms size. This is because the * planes attribute is associated with a pixrect, not the entire * window. */ /* Restrict planes */ if (pw->pw_clipdata->pwcd_flags & PWCD_COLOR24) new_planes = PIX_ALL_PLANES; else if (pw->pw_clipdata->pwcd_flags & PWCD_SET_CMAP_SIZE) { /* * set the mask to one less than the next power of 2 greater or * equal than the size of the cmap */ int mask; for (mask = 1; mask <= cms.cms_size; mask <<= 1); new_planes = mask - 1; } else new_planes = cms.cms_size - 1; /* * Put planes in pixrect for enabling of used planes. * This plane data will be propogated to rest of pixrect * when do pw_exposed (below). */#ifdef planes_fully_implemented pr_putattributes(pw->pw_pixrect, &new_planes);#else (void)pw_full_putattributes(pw->pw_pixrect, &new_planes);#endif planes_fully_implemented /* * Set the initial colormap segment */ /* Set the cms (planes and colormap) */ (void)pw_putcolormap(pw, 0, cms.cms_size, red, green, blue); /* See if reinitializing the cms */ if (pw->pw_clipops->pwco_getclipping == pw_damaged) { /* Propagate plane related changes to all pixrects */ pw_set_planes_directly(pw, new_plane_group, new_planes); /* Assume being called from pw_preparesurface */ return; } /* Figure new clipping (initial getclipping op was nop) */ (void)pw_exposed(pw); /* * Prepare surface if first time opening pixwin on this window. * Previous attempts to call pw_preparesurface have been no-ops * because the clipping was null. RECT_NULL forces entire * visible area. */ if (new_window) (void)pw_preparesurface_full(pw, RECT_NULL, 1);}static voidpw_read_plane_group_preference(pw) Pixwin *pw;{ register char *en_str; char *getenv(); char *available_plane_groups = pw_global_groups_available.plane_groups_available; en_str=getenv("PW_PLANES"); if (en_str == NULL) goto Default; else if ((strcmp(en_str, "OVERLAY") == 0) || (strcmp(en_str, "BW") == 0)) pw_plane_group_preference = PIXPG_OVERLAY; else if ((strcmp(en_str, "COLOR") == 0) || (strcmp(en_str, "8BIT") == 0)) pw_plane_group_preference = PIXPG_8BIT_COLOR; else {Default: /* * Default based on available planes. Change order here * to affect entire systems color preference. * Current setup prefers the overlay plane. */ if (available_plane_groups[PIXPG_8BIT_COLOR]) pw_plane_group_preference = PIXPG_8BIT_COLOR;#ifndef PRE_IBIS else if (available_plane_groups[PIXPG_24BIT_COLOR]) pw_plane_group_preference = PIXPG_24BIT_COLOR;#endif else if (available_plane_groups[PIXPG_OVERLAY]) pw_plane_group_preference = PIXPG_OVERLAY; else if (pw->pw_pixrect->pr_depth == 1) pw_plane_group_preference = PIXPG_MONO; else pw_plane_group_preference = PIXPG_8BIT_COLOR; /* NOTE: ADD HERE WHEN HAVE NEW PLANE GROUP */ } /* NOTE: ADD HERE WHEN HAVE NEW PLANE GROUP */ pw_plane_group_preference_set = 1;}/* * The plane group for this window hasn't been set yet. * So, initialize it based on default cms name, user * preference and availability. */static intpw_choose_prefered_plane_group(pw, original_plane_group) Pixwin *pw; int *original_plane_group;{ char *plane_groups_available = pw->pw_clipdata->pwcd_plane_groups_available; int new_plane_group; *original_plane_group = pr_get_plane_group(pw->pw_pixrect);#ifdef notdef /* Use overlay plane for monochrome cms (if overlay is available) */ if ((strncmp(pw->pw_cmsname, CMS_MONOCHROME, CMS_NAMESIZE) == 0) && (plane_groups_available[PIXPG_OVERLAY])) new_plane_group = PIXPG_OVERLAY; /* * NOTE: ADD HERE WHEN HAVE NEW PLANE GROUP THAT HAS A STRONG * AFFINITY FOR A PARTICULAR CMS (like "monochrome"). */ /* See if want to make plane group the prefered group */ else#endif notdef#ifndef PRE_IBIS if (pw->pw_clipdata->pwcd_flags & PWCD_COLOR24) new_plane_group = PIXPG_24BIT_COLOR; else if (plane_groups_available[pw_plane_group_preference])#else PRE_IBIS if (plane_groups_available[pw_plane_group_preference])#endif else PRE_IBIS new_plane_group = pw_plane_group_preference; else new_plane_group = *original_plane_group; return (new_plane_group);}/* Would make static if weren't worried about breaking someones program */pw_initdefaultcms(pw) struct pixwin *pw;{ struct screen screen; register struct singlecolor *bkgnd; register struct singlecolor *frgnd; struct singlecolor *tmpgnd; if (pw_defaultcms.cms_size != 0) return; /* Initialize to monochrome cms. */ pw_defaultcms.cms_size = CMS_MONOCHROMESIZE; pw_defaultcms.cms_addr = 0; (void)strncpy(pw_defaultcms.cms_name, CMS_MONOCHROME, CMS_NAMESIZE); /* Adjust notion of foreground and background to match screen's. */ (void)win_screenget(pw->pw_clipdata->pwcd_windowfd, &screen); bkgnd = &screen.scr_background; frgnd = &screen.scr_foreground; if (screen.scr_flags & SCR_SWITCHBKGRDFRGRD) { tmpgnd = bkgnd; bkgnd = frgnd; frgnd = tmpgnd; } pw_defaultmap.cm_red[BLACK] = frgnd->red; pw_defaultmap.cm_green[BLACK] = frgnd->green; pw_defaultmap.cm_blue[BLACK] = frgnd->blue; pw_defaultmap.cm_red[WHITE] = bkgnd->red; pw_defaultmap.cm_green[WHITE] = bkgnd->green; pw_defaultmap.cm_blue[WHITE] = bkgnd->blue;}/* * Special fullscreen access routines: *//* * Anyone calling these fullscreen_pw_* routines is assumed to have * done a fullscreen_init, is using the fullscreen pixwin during * this call, hasn't done any prepare surface under these bits, * and should be using a PIX_NOT(PIX_DST) operation. Also, pw_lock * should not have been called before using these operations. */fullscreen_pw_vector(pw, x0, y0, x1, y1, op, cms_index) register struct pixwin *pw; int op; register int x0, y0, x1, y1; int cms_index;{ int original_planes, original_plane_group; int current_plane_group; int left, top; int writestate; extern struct rect *pw_fullscreen_dbl_rect; /* if dbl buf active and intersects this line: do nothing */ if (pw_dbl_intersects_vector(pw, x0, y0, x1, y1)) return; /* if dbl buffering is active ensure to write on both planes */ if (pw_fullscreen_dbl_rect){ writestate = pr_dbl_get(pw->pw_pixrect, PR_DBL_WRITE); pr_dbl_set(pw->pw_pixrect, PR_DBL_WRITE, PR_DBL_BOTH, 0); } /* Draw vector in current plane group */ (void)pw_vector(pw, x0, y0, x1, y1, op, cms_index); /* Set up pw to draw in another plane group */ left = min(x0, x1); top = min(y0, y1); fullscreen_pw_start_plane_group_loop(pw, &original_planes, &original_plane_group, ¤t_plane_group); /* Draw in each applicable plane group */ while (fullscreen_pw_next_plane_group(pw, left, top, max(x0, x1)+1-left, max(y0, y1)+1-top, ¤t_plane_group, original_plane_group)) { /* Draw vector in alternate plane group */ (void)pw_vector(pw, x0, y0, x1, y1, op, cms_index); /* Undo what fullscreen_pw_next_plane_group did */ fullscreen_pw_finish_plane_group(pw, ¤t_plane_group, original_planes, original_plane_group); } if (pw_fullscreen_dbl_rect){ pr_dbl_set(pw->pw_pixrect, PR_DBL_WRITE, writestate, 0); } return;}fullscreen_pw_write(pw, xw, yw, width, height, op, pr, xr, yr) register Pixwin *pw; int op, xw, yw, width, height; struct pixrect *pr; int xr, yr;{ int original_planes, original_plane_group; int current_plane_group; int writestate; extern struct rect *pw_fullscreen_dbl_rect; /* if dbl buf active and intersects this region: do nothing */ if (pw_dbl_intersects_region(pw, xw, yw, width, height)) return; /* if dbl buffering is active ensure to write on both planes */ if (pw_fullscreen_dbl_rect){ writestate = pr_dbl_get(pw->pw_pixrect, PR_DBL_WRITE); pr_dbl_set(pw->pw_pixrect, PR_DBL_WRITE, PR_DBL_BOTH, 0); } fullscreen_pw_start_plane_group_loop(pw, &original_planes, &original_plane_group, ¤t_plane_group); /* Draw in each applicable plane group */ while (fullscreen_pw_next_plane_group(pw, xw, yw, width, height, ¤t_plane_group, original_plane_group)) { /* Do rop in alternate plane group */ (void)pw_write(pw, xw, yw, width, height, op, pr, xr, yr); /* Undo what fullscreen_pw_next_plane_group did */ fullscreen_pw_finish_plane_group(pw, ¤t_plane_group, original_planes, original_plane_group); } if (pw_fullscreen_dbl_rect){ pr_dbl_set(pw->pw_pixrect, PR_DBL_WRITE, writestate, 0); } return;}#ifndef PRE_FLAMINGOstatic voidfullscreen_pw_start_plane_group_loop(pw, original_planes, original_plane_group, current_plane_group) register Pixwin *pw; int *original_planes, *original_plane_group, *current_plane_group;{ /* Remember current planes */ (void)pr_getattributes(pw->pw_pixrect, original_planes); /* Remember current plane group */ *original_plane_group = pw->pw_clipdata->pwcd_plane_group; /* Start with first plane group */ *current_plane_group = 1;}static intfullscreen_pw_next_plane_group(pw, left, top, width, height, current_plane_group, original_plane_group) register Pixwin *pw; int left, top, width, height; int *current_plane_group, original_plane_group;{ char *available_plane_group = pw->pw_clipdata->pwcd_plane_groups_available; Rect rdest; /* Find next interesting plane group */ while (*current_plane_group < PIX_MAX_PLANE_GROUPS && (!available_plane_group[*current_plane_group] || *current_plane_group == PIXPG_OVERLAY_ENABLE || ((*current_plane_group == PIXPG_VIDEO_ENABLE) && !available_plane_group[PIXPG_VIDEO]) || *current_plane_group == PIXPG_VIDEO || *current_plane_group == PIXPG_WID|| *current_plane_group == PIXPG_CURSOR_ENABLE || *current_plane_group == PIXPG_CURSOR)) *current_plane_group += 1; if (*current_plane_group >= PIX_MAX_PLANE_GROUPS) return (0); if (*current_plane_group != original_plane_group) { /* Adjust operation's offset because didn't go thru macro */ left = PW_X_OFFSET(pw, left); top = PW_Y_OFFSET(pw, top); /* * Set new plane group temporarily so that cursor lifting is * done on the new plane group. */ pr_set_planes(pw->pw_pixrect, *current_plane_group, PIX_ALL_PLANES); /* * Lock pixwin so that clipping change doesn't blitz temporary * plane group changes. */ PW_SETUP(pw, rdest, Continue, left, top, width, height);Continue: /* * Set all pixrects to operate in all planes of given plane group. */ pw_set_planes_directly(pw, *current_plane_group, PIX_ALL_PLANES); } return (1);}#endifstatic voidfullscreen_pw_finish_plane_group(pw, current_plane_group, original_planes, original_plane_group) register Pixwin *pw; int *current_plane_group, original_planes, original_plane_group;{ if (*current_plane_group != original_plane_group) { /* Reset plane group accessing */ pw_set_planes_directly(pw, original_plane_group, original_planes); /* Unlock pixwin (was locked in fullscreen_pw_next_plane_group)*/ (void)pw_unlock(pw); /* * Set plane group back to original so that cursor lifting is * done on the original plane group (was set to new plane * group in fullscreen_pw_start_other_plane_group). */ pr_set_planes(pw->pw_pixrect, original_plane_group, original_planes); } *current_plane_group += 1;}static intfullscreen_pw_start_other_plane_group(pw, left, top, width, height, original_planes, original_plane_group) register Pixwin *pw; int left, top, width, height; int *original_planes, *original_plane_group;{ char *available_plane_group = pw->pw_clipdata->pwcd_plane_groups_available; Rect rdest; int new_plane_group; /* Adjust operation's offset because didn't go thru macro */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -