OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "window_manager/x11/real_x_connection.h" | 5 #include "window_manager/x11/real_x_connection.h" |
6 | 6 |
7 extern "C" { | 7 extern "C" { |
8 #include <xcb/composite.h> | 8 #include <xcb/composite.h> |
9 #include <xcb/damage.h> | 9 #include <xcb/damage.h> |
10 #include <xcb/randr.h> | 10 #include <xcb/randr.h> |
11 #include <xcb/shape.h> | 11 #include <xcb/shape.h> |
12 #include <xcb/sync.h> | 12 #include <xcb/sync.h> |
13 #include <xcb/xfixes.h> | 13 #include <xcb/xfixes.h> |
14 #include <X11/extensions/shape.h> | 14 #include <X11/extensions/shape.h> |
15 #include <X11/extensions/sync.h> | 15 #include <X11/extensions/sync.h> |
16 #include <X11/extensions/Xcomposite.h> | 16 #include <X11/extensions/Xcomposite.h> |
17 #include <X11/extensions/Xdamage.h> | 17 #include <X11/extensions/Xdamage.h> |
| 18 #include <X11/extensions/Xrender.h> |
18 #include <X11/Xatom.h> | 19 #include <X11/Xatom.h> |
19 #include <X11/Xlib-xcb.h> | 20 #include <X11/Xlib-xcb.h> |
20 #include <X11/Xutil.h> | 21 #include <X11/Xutil.h> |
21 #include <X11/XKBlib.h> | 22 #include <X11/XKBlib.h> |
22 } | 23 } |
23 | 24 |
24 #include "base/string_util.h" | 25 #include "base/string_util.h" |
25 #include "window_manager/geometry.h" | 26 #include "window_manager/geometry.h" |
26 #include "window_manager/util.h" | 27 #include "window_manager/util.h" |
27 #include "window_manager/x11/x_connection_internal.h" | 28 #include "window_manager/x11/x_connection_internal.h" |
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 xcb_query_pointer_reply(xcb_conn_, cookie, &error)); | 1338 xcb_query_pointer_reply(xcb_conn_, cookie, &error)); |
1338 scoped_ptr_malloc<xcb_generic_error_t> scoped_error(error); | 1339 scoped_ptr_malloc<xcb_generic_error_t> scoped_error(error); |
1339 if (error || !reply.get()) { | 1340 if (error || !reply.get()) { |
1340 LOG(WARNING) << "Querying pointer position failed"; | 1341 LOG(WARNING) << "Querying pointer position failed"; |
1341 return false; | 1342 return false; |
1342 } | 1343 } |
1343 absolute_pos_out->reset(reply->root_x, reply->root_y); | 1344 absolute_pos_out->reset(reply->root_x, reply->root_y); |
1344 return true; | 1345 return true; |
1345 } | 1346 } |
1346 | 1347 |
| 1348 bool RealXConnection::RenderQueryExtension() { |
| 1349 int render_event, render_error; |
| 1350 return XRenderQueryExtension(display_, &render_event, &render_error); |
| 1351 } |
| 1352 |
| 1353 XPicture RealXConnection::RenderCreatePicture(XDrawable drawable, int depth) { |
| 1354 XRenderPictFormat *format; |
| 1355 XRenderPictureAttributes pa; |
| 1356 |
| 1357 format = XRenderFindStandardFormat( |
| 1358 display_, |
| 1359 depth == 24 ? PictStandardRGB24 : PictStandardARGB32); |
| 1360 pa.repeat = True; |
| 1361 XPicture r = XRenderCreatePicture(display_, drawable, format, CPRepeat, &pa); |
| 1362 return r; |
| 1363 } |
| 1364 |
| 1365 XPixmap RealXConnection::CreatePixmapFromContainer( |
| 1366 const ImageContainer& container) { |
| 1367 Size size = container.size(); |
| 1368 int data_size = size.width * size.height * 4; |
| 1369 |
| 1370 // XDestroyImage will free() this. |
| 1371 char* pixmap_data = static_cast<char*>(malloc(data_size)); |
| 1372 |
| 1373 // Premultiply the RGB channels. |
| 1374 memcpy(pixmap_data, container.data(), data_size); |
| 1375 for (int i = 0; i < size.width * size.height; i++) { |
| 1376 pixmap_data[i*4+0] = pixmap_data[i*4+0] * pixmap_data[i*4+3] / 255; |
| 1377 pixmap_data[i*4+1] = pixmap_data[i*4+1] * pixmap_data[i*4+3] / 255; |
| 1378 pixmap_data[i*4+2] = pixmap_data[i*4+2] * pixmap_data[i*4+3] / 255; |
| 1379 } |
| 1380 |
| 1381 XPixmap pixmap = XCreatePixmap(display_, root_, size.width, size.height, 32); |
| 1382 |
| 1383 XImage* image = XCreateImage( |
| 1384 display_, |
| 1385 DefaultVisual(display_, DefaultScreen(display_)), |
| 1386 32, // depth |
| 1387 ZPixmap, |
| 1388 0, // offset |
| 1389 pixmap_data, |
| 1390 size.width, size.height, |
| 1391 32, // bitmap_pad |
| 1392 0); // bytes_per_line |
| 1393 |
| 1394 GC gc = XCreateGC(display_, pixmap, 0, NULL); |
| 1395 if (!gc) { |
| 1396 XDestroyImage(image); |
| 1397 XFreePixmap(display_, pixmap); |
| 1398 return None; |
| 1399 } |
| 1400 |
| 1401 XPutImage(display_, |
| 1402 pixmap, |
| 1403 gc, |
| 1404 image, |
| 1405 0, 0, // src x,y |
| 1406 0, 0, // dst x,y |
| 1407 size.width, size.height); |
| 1408 XDestroyImage(image); |
| 1409 |
| 1410 XFreeGC(display_, gc); |
| 1411 |
| 1412 return pixmap; |
| 1413 } |
| 1414 |
| 1415 void RealXConnection::RenderComposite(bool blend, |
| 1416 XPicture src, |
| 1417 XPicture mask, |
| 1418 XPicture dst, |
| 1419 const Point& srcpos, |
| 1420 const Point& maskpos, |
| 1421 const Matrix4& transform, |
| 1422 const Size& size) { |
| 1423 Point dstpos(transform[3][0], transform[3][1]); |
| 1424 |
| 1425 // Don't use transform/filtering all the time, |
| 1426 // there are performance implications in doing so. |
| 1427 if (size != Size(transform[0][0], transform[1][1])) { |
| 1428 XTransform xform = {{{XDoubleToFixed(size.width/float(transform[0][0])), |
| 1429 XDoubleToFixed(transform[1][0]), |
| 1430 XDoubleToFixed(transform[2][0])}, |
| 1431 {XDoubleToFixed(transform[0][1]), |
| 1432 XDoubleToFixed(size.height/float(transform[1][1])), |
| 1433 XDoubleToFixed(transform[2][1])}, |
| 1434 {XDoubleToFixed(0.0), |
| 1435 XDoubleToFixed(0.0), |
| 1436 XDoubleToFixed(1.0)}}}; |
| 1437 XRenderSetPictureTransform(display_, src, &xform); |
| 1438 XRenderSetPictureFilter(display_, src, FilterBilinear, 0, 0); |
| 1439 } |
| 1440 |
| 1441 int op = blend ? PictOpOver : PictOpSrc; |
| 1442 XRenderComposite(display_, |
| 1443 op, |
| 1444 src, |
| 1445 mask, |
| 1446 dst, |
| 1447 static_cast<int>(srcpos.x), static_cast<int>(srcpos.y), |
| 1448 static_cast<int>(maskpos.x), static_cast<int>(maskpos.y), |
| 1449 static_cast<int>(dstpos.x), static_cast<int>(dstpos.y), |
| 1450 static_cast<int>(transform[0][0]), |
| 1451 static_cast<int>(transform[1][1])); |
| 1452 } |
| 1453 |
| 1454 bool RealXConnection::RenderFreePicture(XPicture pict) { |
| 1455 XRenderFreePicture(display_, pict); |
| 1456 return true; |
| 1457 } |
| 1458 |
| 1459 void RealXConnection::RenderFillRectangle(XPicture dst, |
| 1460 float red, |
| 1461 float green, |
| 1462 float blue, |
| 1463 const Point& pos, |
| 1464 const Size& size) { |
| 1465 XRenderColor c; |
| 1466 |
| 1467 c.red = red * 0xffff; |
| 1468 c.green = green * 0xffff; |
| 1469 c.blue = blue * 0xffff; |
| 1470 c.alpha = 0xffff; |
| 1471 XRenderFillRectangle(display_, |
| 1472 PictOpSrc, |
| 1473 dst, |
| 1474 &c, |
| 1475 pos.x, pos.y, |
| 1476 size.width, size.height); |
| 1477 } |
| 1478 |
1347 void RealXConnection::Free(void* item) { | 1479 void RealXConnection::Free(void* item) { |
1348 XFree(item); | 1480 XFree(item); |
1349 } | 1481 } |
1350 | 1482 |
1351 XVisualInfo* RealXConnection::GetVisualInfo(long mask, | 1483 XVisualInfo* RealXConnection::GetVisualInfo(long mask, |
1352 XVisualInfo* visual_template, | 1484 XVisualInfo* visual_template, |
1353 int* item_count) { | 1485 int* item_count) { |
1354 return XGetVisualInfo(display_, mask, visual_template, item_count); | 1486 return XGetVisualInfo(display_, mask, visual_template, item_count); |
1355 } | 1487 } |
1356 | 1488 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 string message; | 1642 string message; |
1511 StringAppendV(&message, format, ap); | 1643 StringAppendV(&message, format, ap); |
1512 va_end(ap); | 1644 va_end(ap); |
1513 | 1645 |
1514 LOG(WARNING) << "Got XCB error while " << message << ": " | 1646 LOG(WARNING) << "Got XCB error while " << message << ": " |
1515 << GetErrorText(error->error_code); | 1647 << GetErrorText(error->error_code); |
1516 return false; | 1648 return false; |
1517 } | 1649 } |
1518 | 1650 |
1519 } // namespace window_manager | 1651 } // namespace window_manager |
OLD | NEW |