ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.98 by sf-exg, Sat Oct 30 10:57:52 2010 UTC vs.
Revision 1.102 by sf-exg, Sun Oct 31 09:34:23 2010 UTC

108 h_scale = v_scale = 0; 108 h_scale = v_scale = 0;
109 h_align = v_align = 0; 109 h_align = v_align = 0;
110#endif 110#endif
111#ifdef ENABLE_TRANSPARENCY 111#ifdef ENABLE_TRANSPARENCY
112 shade = 100; 112 shade = 100;
113 recoded_root_pmap = None;
113#endif 114#endif
114 flags = 0; 115 flags = 0;
115 pixmap = None; 116 pixmap = None;
116 valid_since = invalid_since = 0; 117 valid_since = invalid_since = 0;
117 target = 0; 118 target = 0;
126#endif 127#endif
127 128
128#ifdef HAVE_PIXBUF 129#ifdef HAVE_PIXBUF
129 if (pixbuf) 130 if (pixbuf)
130 g_object_unref (pixbuf); 131 g_object_unref (pixbuf);
132#endif
133
134#ifdef ENABLE_TRANSPARENCY
135 if (recoded_root_pmap && target)
136 XFreePixmap (target->dpy, recoded_root_pmap);
131#endif 137#endif
132 138
133 if (pixmap && target) 139 if (pixmap && target)
134 XFreePixmap (target->dpy, pixmap); 140 XFreePixmap (target->dpy, pixmap);
135} 141}
729 return false; 735 return false;
730 736
731 if (!pixbuf) 737 if (!pixbuf)
732 return false; 738 return false;
733 739
734#if !XFT 740#if !XRENDER
735 if (background_flags) 741 if (background_flags)
736 return false; 742 return false;
737#endif 743#endif
738 744
739 GdkPixbuf *result; 745 GdkPixbuf *result;
856 dst_width, dst_height, 862 dst_width, dst_height,
857 XLIB_RGB_DITHER_NONE, 863 XLIB_RGB_DITHER_NONE,
858 0, 0); 864 0, 0);
859 } 865 }
860 866
861#if XFT 867#if XRENDER
862 if (background_flags) 868 if (background_flags)
863 { 869 {
864 Display *dpy = target->dpy; 870 Display *dpy = target->dpy;
865 XRenderPictureAttributes pa; 871 XRenderPictureAttributes pa;
866 872
867 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); 873 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual);
868 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 874 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
869 875
870 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 876 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
871 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 877 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
872 878
1000 if (v_blurRadius == 0 && h_blurRadius == 0) 1006 if (v_blurRadius == 0 && h_blurRadius == 0)
1001 flags &= ~blurNeeded; 1007 flags &= ~blurNeeded;
1002 else 1008 else
1003 flags |= blurNeeded; 1009 flags |= blurNeeded;
1004 1010
1005#if XFT 1011#if XRENDER
1006 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); 1012 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1007 if (filters) 1013 if (filters)
1008 { 1014 {
1009 for (int i = 0; i < filters->nfilter; i++) 1015 for (int i = 0; i < filters->nfilter; i++)
1010 if (!strcmp (filters->filter[i], FilterConvolution)) 1016 if (!strcmp (filters->filter[i], FilterConvolution))
1011 flags |= bgPixmap_t::blurServerSide; 1017 flags |= bgPixmap_t::blurServerSide;
1050 { 1056 {
1051 if (flags & bgPixmap_t::tintWholesome) 1057 if (flags & bgPixmap_t::tintWholesome)
1052 flags |= bgPixmap_t::tintServerSide; 1058 flags |= bgPixmap_t::tintServerSide;
1053 else 1059 else
1054 { 1060 {
1055#if XFT 1061#if XRENDER
1056 flags |= bgPixmap_t::tintServerSide; 1062 flags |= bgPixmap_t::tintServerSide;
1057#endif 1063#endif
1058 } 1064 }
1059 } 1065 }
1060 1066
1107 } 1113 }
1108 1114
1109 return false; 1115 return false;
1110} 1116}
1111 1117
1112#if XFT 1118#if XRENDER
1113static void 1119static void
1114get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 1120get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1115{ 1121{
1116 double sigma = radius / 2.0; 1122 double sigma = radius / 2.0;
1117 double scale = sqrt (2.0 * M_PI) * sigma; 1123 double scale = sqrt (2.0 * M_PI) * sigma;
1134 1140
1135bool 1141bool
1136bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1142bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1137{ 1143{
1138 bool ret = false; 1144 bool ret = false;
1139#if XFT 1145#if XRENDER
1140 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1146 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1141 double *kernel = (double *)malloc (size * sizeof (double)); 1147 double *kernel = (double *)malloc (size * sizeof (double));
1142 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1148 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1143 1149
1144 Display *dpy = target->dpy; 1150 Display *dpy = target->dpy;
1221 XFreeGC (dpy, gc); 1227 XFreeGC (dpy, gc);
1222 } 1228 }
1223 } 1229 }
1224 else 1230 else
1225 { 1231 {
1226# if XFT 1232# if XRENDER
1227 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1233 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1228 1234
1229 if (flags & tintSet) 1235 if (flags & tintSet)
1230 tint.get (c); 1236 tint.get (c);
1231 1237
1284 1290
1285 return ret; 1291 return ret;
1286} 1292}
1287 1293
1288/* make_transparency_pixmap() 1294/* make_transparency_pixmap()
1289 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1295 * Builds a pixmap of the same size as the terminal window that contains
1290 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1296 * the tiled portion of the root pixmap that is supposed to be covered by
1291 * our window. 1297 * our window.
1292 */ 1298 */
1293unsigned long 1299unsigned long
1294bgPixmap_t::make_transparency_pixmap () 1300bgPixmap_t::make_transparency_pixmap ()
1295{ 1301{
1299 return 0; 1305 return 0;
1300 1306
1301 /* root dimensions may change from call to call - but Display structure should 1307 /* root dimensions may change from call to call - but Display structure should
1302 * be always up-to-date, so let's use it : 1308 * be always up-to-date, so let's use it :
1303 */ 1309 */
1304 Window root = target->display->root;
1305 int screen = target->display->screen; 1310 int screen = target->display->screen;
1306 Display *dpy = target->dpy; 1311 Display *dpy = target->dpy;
1307 int root_width = DisplayWidth (dpy, screen); 1312 int root_width = DisplayWidth (dpy, screen);
1308 int root_height = DisplayHeight (dpy, screen); 1313 int root_height = DisplayHeight (dpy, screen);
1309 unsigned int root_pmap_width, root_pmap_height;
1310 int window_width = target->szHint.width; 1314 int window_width = target->szHint.width;
1311 int window_height = target->szHint.height; 1315 int window_height = target->szHint.height;
1312 int sx, sy; 1316 int sx, sy;
1313 XGCValues gcv; 1317 XGCValues gcv;
1314 GC gc; 1318 GC gc;
1318 /* check if we are outside of the visible part of the virtual screen : */ 1322 /* check if we are outside of the visible part of the virtual screen : */
1319 if (sx + window_width <= 0 || sy + window_height <= 0 1323 if (sx + window_width <= 0 || sy + window_height <= 0
1320 || sx >= root_width || sy >= root_height) 1324 || sx >= root_width || sy >= root_height)
1321 return 0; 1325 return 0;
1322 1326
1323 if (root_pixmap != None)
1324 {
1325 /* we want to validate the pixmap and get its size at the same time : */
1326 int junk;
1327 unsigned int ujunk;
1328 /* root pixmap may be bad - allow a error */
1329 target->allowedxerror = -1;
1330
1331 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk))
1332 root_pixmap = None;
1333
1334 target->allowedxerror = 0;
1335 }
1336
1337 if (root_pixmap == None) 1327 if (root_pixmap == None)
1338 return 0; 1328 return 0;
1339 1329
1340 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1330 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth);
1341 1331
1342 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1332 if (tiled_root_pmap == None) /* something really bad happened - abort */
1343 return 0; 1333 return 0;
1344 1334
1345 /* straightforward pixmap copy */ 1335 /* straightforward pixmap copy */
1349 while (sx < 0) sx += (int)root_width; 1339 while (sx < 0) sx += (int)root_width;
1350 while (sy < 0) sy += (int)root_height; 1340 while (sy < 0) sy += (int)root_height;
1351 1341
1352 gcv.ts_x_origin = -sx; 1342 gcv.ts_x_origin = -sx;
1353 gcv.ts_y_origin = -sy; 1343 gcv.ts_y_origin = -sy;
1354 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1344 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1355 1345
1356 if (gc) 1346 if (gc)
1357 { 1347 {
1358 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1348 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1359 result |= transpPmapTiled; 1349 result |= transpPmapTiled;
1364 { 1354 {
1365 if (!need_client_side_rendering ()) 1355 if (!need_client_side_rendering ())
1366 { 1356 {
1367 if (flags & (blurNeeded | blurServerSide)) 1357 if (flags & (blurNeeded | blurServerSide))
1368 { 1358 {
1369 if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1359 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1370 result |= transpPmapBlurred; 1360 result |= transpPmapBlurred;
1371 } 1361 }
1372 if (flags & (tintNeeded | tintServerSide)) 1362 if (flags & (tintNeeded | tintServerSide))
1373 { 1363 {
1374 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1364 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1375 result |= transpPmapTinted; 1365 result |= transpPmapTinted;
1376 } 1366 }
1377 } /* server side rendering completed */ 1367 } /* server side rendering completed */
1378 1368
1379 if (pixmap) 1369 if (pixmap)
1380 XFreePixmap (dpy, pixmap); 1370 XFreePixmap (dpy, pixmap);
1381 1371
1382 pixmap = tiled_root_pmap; 1372 pixmap = tiled_root_pmap;
1383 pmap_width = window_width; 1373 pmap_width = window_width;
1384 pmap_height = window_height; 1374 pmap_height = window_height;
1385 pmap_depth = root_depth; 1375 pmap_depth = target->depth;
1386 } 1376 }
1387 1377
1388 return result; 1378 return result;
1389} 1379}
1390 1380
1394 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1384 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1395 if (new_root_pixmap == None) 1385 if (new_root_pixmap == None)
1396 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1386 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1397 1387
1398 root_pixmap = new_root_pixmap; 1388 root_pixmap = new_root_pixmap;
1389
1390 unsigned int width, height;
1391 int depth = DefaultDepth (target->dpy, target->display->screen);
1392
1393 // validate root pixmap
1394 if (root_pixmap != None)
1395 {
1396 Window wdummy;
1397 int idummy;
1398 unsigned int udummy;
1399
1400 target->allowedxerror = -1;
1401
1402 if (!XGetGeometry (target->dpy, root_pixmap, &wdummy, &idummy, &idummy, &width, &height, &udummy, &udummy))
1403 root_pixmap = None;
1404
1405 target->allowedxerror = 0;
1406 }
1407
1408 if (root_pixmap != None && depth != target->depth)
1409 {
1410#if XRENDER
1411 Display *dpy = target->dpy;
1412 XRenderPictureAttributes pa;
1413
1414 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen));
1415 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1416
1417 if (recoded_root_pmap)
1418 XFreePixmap (dpy, recoded_root_pmap);
1419 recoded_root_pmap = XCreatePixmap (dpy, target->vt, width, height, target->depth);
1420 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1421 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1422
1423 if (src && dst)
1424 {
1425 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, width, height);
1426 root_pixmap = recoded_root_pmap;
1427 }
1428 else
1429 root_pixmap = None;
1430
1431 XRenderFreePicture (dpy, src);
1432 XRenderFreePicture (dpy, dst);
1433#else
1434 root_pixmap = None;
1435#endif
1436 }
1399} 1437}
1400# endif /* ENABLE_TRANSPARENCY */ 1438# endif /* ENABLE_TRANSPARENCY */
1401 1439
1402# ifndef HAVE_AFTERIMAGE 1440# ifndef HAVE_AFTERIMAGE
1403static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); 1441static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm);
1417 { 1455 {
1418 /* we need to re-generate transparency pixmap in that case ! */ 1456 /* we need to re-generate transparency pixmap in that case ! */
1419 background_flags = make_transparency_pixmap (); 1457 background_flags = make_transparency_pixmap ();
1420 if (background_flags == 0) 1458 if (background_flags == 0)
1421 return false; 1459 return false;
1422 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1460 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1423 && pmap_depth == target->depth)
1424 flags = flags & ~isInvalid; 1461 flags = flags & ~isInvalid;
1425 } 1462 }
1426# endif 1463# endif
1427 1464
1428# ifdef BG_IMAGE_FROM_FILE 1465# ifdef BG_IMAGE_FROM_FILE
1441 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1478 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1442 } 1479 }
1443 1480
1444 if (result) 1481 if (result)
1445 { 1482 {
1446# if !defined(HAVE_AFTERIMAGE) && !XFT 1483# if !defined(HAVE_AFTERIMAGE) && !XRENDER
1447 /* our own client-side tinting */ 1484 /* our own client-side tinting */
1448 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1449 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1450 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1485 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1451 { 1486 {
1452 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1487 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1453 if (flags & tintSet) 1488 if (flags & tintSet)
1454 tint.get (c); 1489 tint.get (c);
1458 1493
1459 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1494 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1460 1495
1461 if (gc) 1496 if (gc)
1462 { 1497 {
1463 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1464 {
1465 XFreePixmap (target->dpy, pixmap);
1466 pixmap = None;
1467 }
1468
1469 if (pixmap == None)
1470 {
1471 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1472 pmap_width = result->width;
1473 pmap_height = result->height;
1474 pmap_depth = target->depth;
1475 }
1476
1477 if (pmap_depth != result->depth)
1478 {
1479 /* Bad Match error will ensue ! stupid X !!!! */
1480 if (result->depth == 24 && pmap_depth == 32)
1481 result->depth = 32;
1482 else if (result->depth == 32 && pmap_depth == 24)
1483 result->depth = 24;
1484 else
1485 {
1486 /* TODO: implement image recoding */
1487 }
1488 }
1489
1490 if (pmap_depth == result->depth)
1491 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1498 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1492 1499
1493 XFreeGC (target->dpy, gc); 1500 XFreeGC (target->dpy, gc);
1494 flags = flags & ~isInvalid; 1501 flags = flags & ~isInvalid;
1495 } 1502 }
1496 1503
1518{ 1525{
1519 if (new_target) 1526 if (new_target)
1520 if (target != new_target) 1527 if (target != new_target)
1521 { 1528 {
1522 target = new_target; 1529 target = new_target;
1523# ifdef ENABLE_TRANSPARENCY
1524 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1525# endif
1526 return true; 1530 return true;
1527 } 1531 }
1528 1532
1529 return false; 1533 return false;
1530} 1534}
1583 } 1587 }
1584} 1588}
1585 1589
1586#endif /* HAVE_BG_PIXMAP */ 1590#endif /* HAVE_BG_PIXMAP */
1587 1591
1588#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1592#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER
1589/* taken from aterm-0.4.2 */ 1593/* taken from aterm-0.4.2 */
1590 1594
1591static void 1595static void
1592ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) 1596ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm)
1593{ 1597{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines