multivis.c revision 1068
463N/A * Sun Microsystems, Inc. 463N/A/* Copyright (c) 1990, 2011, Oracle and/or its affiliates. All rights reserved. 463N/A * Permission is hereby granted, free of charge, to any person obtaining a 463N/A * copy of this software and associated documentation files (the "Software"), 463N/A * to deal in the Software without restriction, including without limitation 463N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense, 463N/A * and/or sell copies of the Software, and to permit persons to whom the 463N/A * Software is furnished to do so, subject to the following conditions: 463N/A * The above copyright notice and this permission notice (including the next 463N/A * paragraph) shall be included in all copies or substantial portions of the 463N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 463N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 463N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 463N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 463N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 463N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 463N/A * DEALINGS IN THE SOFTWARE. static int mvNumVis;
/* Number of visuals in list */ static MVPel *
mvImg;
/* mvImg is what we compose the image rectangle in Root Space */ * Initialise the mvLib routines ... /* Initialise screen info */ * Create an Img.. Cleared to zeros. * returns 0 if failure, non-zero for success. * Note that it is the reponsibility of the caller * to verify that any resulting XGetImage will * be within the bounds of the screen. * i.e, x, y, wd, ht must be such that the rectangle * is fully within the bounds of the screen. * Reset the mvLib routines * Recursively walk the window tree. * Find windows that intersect the requested region. * Create a list of such windows in global winList. * Assumes winList was cleared beforehand. int px,
py;
/* parent's origin in root space */ int x, y;
/* Top left of requested rectangle in root space */ int wi,
hi;
/* size of requested rectangle */ /* compute top-left of image in root space */ /* We're interested ... */ /* Is it a Shaped Window ? Help ! */ if ((
wb == 0) || (
hb == 0) || (
wb >
2000) || (
hb >
2000)) {
/* Empty shape, ignore it */ /* Translate from relative parent's origin to this window's origin */ if (
isShaped) {
/* Compute effective bdg shape */ /* Find children, back to front */ * Returns 0 if no problems, * Returns 1 if depths differ * returns 2 if colormap or visinfo differ * NOTE that this chenge & the previous change are reprehensible hacks, * to let xmag work with pageview, and xcolor respectively. * Returns 0 if no problems, * Returns 1 if visinfo or depth differ * returns 2 if colormap only differ * Returns non-zero if the winList created by mvWalkTree * might potentially have windows of different Visuals * Traverse the window list front to back. Get the entire Image * from each window, but only Label a pixel in the Img once. * That is, once a pixel has been Labeled, any more fetches * from the same pixel position are discarded. Once all pixels * positions have been fetched, we're done. This will eliminate * windows that have nothing to contibute to the requested region, * but will nevertheless have the problem of the painters * algorithm, where more pixels were fetched from a * window than were essential. * Assumes that winList has been filled beforehand, and Img was cleared. /* For each pixel in the returned Image */ /* If the pixel hasn't been labelled before */ if (!
pPel->
colmap) {
/* pPel->colmap serves as a 'Label' */ /* label the pixel in the map with this window's cmap */ * If Pixel value can be discarded, this is where * you get the RGB value instead. * Call a routine like mvFindColorInColormap() with the pixel * value, and Colormap as parameters. * The 'Label', instead of pPel->colmap could be a scratch bit ? * But if its a full 32 bit pixel, and there are no * free bits, you need to hang in extra bits somewhere. * Maybe a bitmask associated with Img ? * Get all the colors from this window's colormap. * That's slightly complicated when we hit * a true color or direct color visual. * Assumes that a global list of colmaps is present, and * that the Colors field was NULLed beforehand. /* Allocate enough memory */ /* We have to create a composite pixel value */ for (i = 0; i < (
unsigned long)(
size);i++,
pCol++) {
/* Fill in the pixel values by hand */ for (i = 0; i < (
unsigned long)(
size);) {
* Given a VisualID, return a pointer to the VisualInfo structure. * Assumes that a global mvVlist for this screen has already * been created. Uses globals mvNumVis, and mvVlist. * Returns NULL if the vid is not matched. * Calculate a composite pixel value that indexes into all * three primaries . Assumes Composite Calcs have been performed * Calculate the offsets used to composite a pixel value for * the TrueColor & DirectColor cases * Assumes its called only on a True or DirectColor visual. /* Check if this has been done before */ /* These are the sizes of each primary map ... */ * Calculate number of 1 bits in mask * Classic hack not written by this author. y = (
mask >>
1) &0
33333333333;
y =
mask - y - ((y >>
1) & 0
33333333333);
return (((y + (y >>
3)) & 0
30707070707) % 0
77);
* Calculate the number of shifts till we hit the mask * find & creat a colmap struct for this cmap * Assumes that colMaps was cleared before the first time /* if we've seen this cmap before, return its struct colmap */ /* First time for this cmap, creat & link */ * Use pixel value at x, y as an index into * the colmap's list of Colors. * If the pixel value were not important, this would be called * in mvDoWindowsFrontToBack(), with the pixel value * and colmap as parameters, to get RGB values directly. /* Treat the pixel value as 3 separate indices, composite the color into scratch, return a pointer to scratch */ else {
/* This is simple */