Chromium Code Reviews| 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) { | |
|
Daniel Erat
2011/04/04 21:16:35
nit: make this be a reference instead of a pointer
marcheu
2011/04/05 00:23:40
Done.
| |
| 1367 Size size = container->GetSize(); | |
| 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, XPicture src, XPicture mask, | |
| 1416 XPicture dst, Point srcpos, Point maskpos, | |
|
Daniel Erat
2011/04/04 21:16:35
use const references for non-POD types, and use se
marcheu
2011/04/05 00:23:40
Done.
| |
| 1417 Matrix4 transform, Size size) { | |
| 1418 Point dstpos(transform[3][0], transform[3][1]); | |
| 1419 | |
| 1420 // Don't use transform/filtering all the time, | |
| 1421 // there are performance implications in doing so. | |
| 1422 if ((size.width != transform[0][0]) || (size.height != transform[1][1])) { | |
|
Daniel Erat
2011/04/04 21:16:35
might be simpler as this (may require static_casts
marcheu
2011/04/05 00:23:40
Done.
| |
| 1423 XTransform xform = {{{XDoubleToFixed(size.width/float(transform[0][0])), | |
| 1424 XDoubleToFixed(transform[1][0]), | |
| 1425 XDoubleToFixed(transform[2][0])}, | |
| 1426 {XDoubleToFixed(transform[0][1]), | |
| 1427 XDoubleToFixed(size.height/float(transform[1][1])), | |
| 1428 XDoubleToFixed(transform[2][1])}, | |
| 1429 {XDoubleToFixed(0.0), | |
| 1430 XDoubleToFixed(0.0), | |
| 1431 XDoubleToFixed(1.0)}}}; | |
| 1432 XRenderSetPictureTransform(display_, src, &xform); | |
| 1433 XRenderSetPictureFilter(display_, src, FilterBilinear, 0, 0); | |
| 1434 } | |
| 1435 | |
| 1436 int op = blend ? PictOpOver : PictOpSrc; | |
| 1437 XRenderComposite(display_, | |
| 1438 op, | |
| 1439 src, | |
| 1440 mask, | |
| 1441 dst, | |
| 1442 int(srcpos.x), (int)(srcpos.y), | |
|
Daniel Erat
2011/04/04 21:16:35
nit: use static_cast (also, you're mixing int() an
marcheu
2011/04/05 00:23:40
Done.
| |
| 1443 int(maskpos.x), int(maskpos.y), | |
| 1444 int(dstpos.x), (int)(dstpos.y), | |
| 1445 int(transform[0][0]), int(transform[1][1])); | |
| 1446 } | |
| 1447 | |
| 1448 void RealXConnection::RenderFreePicture(XPicture pict) { | |
| 1449 XRenderFreePicture(display_, pict); | |
| 1450 } | |
| 1451 | |
| 1452 void RealXConnection::RenderFillRectangle(XPicture dst, | |
| 1453 float red, | |
| 1454 float green, | |
| 1455 float blue, | |
| 1456 Point pos, | |
|
Daniel Erat
2011/04/04 21:16:35
const Point&, const Size&
marcheu
2011/04/05 00:23:40
Done.
| |
| 1457 Size size) { | |
| 1458 XRenderColor c; | |
| 1459 | |
| 1460 c.red = red * 0xffff; | |
| 1461 c.green = green * 0xffff; | |
| 1462 c.blue = blue * 0xffff; | |
| 1463 c.alpha = 0xffff; | |
| 1464 XRenderFillRectangle(display_, | |
| 1465 PictOpSrc, | |
| 1466 dst, | |
| 1467 &c, | |
| 1468 pos.x, pos.y, | |
| 1469 size.width, size.height); | |
| 1470 } | |
| 1471 | |
| 1347 void RealXConnection::Free(void* item) { | 1472 void RealXConnection::Free(void* item) { |
| 1348 XFree(item); | 1473 XFree(item); |
| 1349 } | 1474 } |
| 1350 | 1475 |
| 1351 XVisualInfo* RealXConnection::GetVisualInfo(long mask, | 1476 XVisualInfo* RealXConnection::GetVisualInfo(long mask, |
| 1352 XVisualInfo* visual_template, | 1477 XVisualInfo* visual_template, |
| 1353 int* item_count) { | 1478 int* item_count) { |
| 1354 return XGetVisualInfo(display_, mask, visual_template, item_count); | 1479 return XGetVisualInfo(display_, mask, visual_template, item_count); |
| 1355 } | 1480 } |
| 1356 | 1481 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1510 string message; | 1635 string message; |
| 1511 StringAppendV(&message, format, ap); | 1636 StringAppendV(&message, format, ap); |
| 1512 va_end(ap); | 1637 va_end(ap); |
| 1513 | 1638 |
| 1514 LOG(WARNING) << "Got XCB error while " << message << ": " | 1639 LOG(WARNING) << "Got XCB error while " << message << ": " |
| 1515 << GetErrorText(error->error_code); | 1640 << GetErrorText(error->error_code); |
| 1516 return false; | 1641 return false; |
| 1517 } | 1642 } |
| 1518 | 1643 |
| 1519 } // namespace window_manager | 1644 } // namespace window_manager |
| OLD | NEW |