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 if (!XRenderQueryExtension (display_, &render_event, &render_error)) | |
|
Daniel Erat
2011/04/02 14:54:36
why not do "return XRenderQueryExtension(...)"?
marcheu
2011/04/04 19:55:58
Done.
| |
| 1351 return false; | |
| 1352 return true; | |
| 1353 } | |
| 1354 | |
| 1355 XPicture RealXConnection::RenderCreatePicture(XDrawable drawable, int depth) { | |
| 1356 XRenderPictFormat *format; | |
| 1357 XRenderPictureAttributes pa; | |
| 1358 | |
| 1359 format = XRenderFindStandardFormat(display_, | |
|
Daniel Erat
2011/04/02 14:54:36
nit: move 'display_' to the beginning of the next
marcheu
2011/04/04 19:55:58
Done.
| |
| 1360 depth == 24 ? PictStandardRGB24 : PictStandardARGB32); | |
| 1361 pa.repeat = True; | |
| 1362 XPicture r = XRenderCreatePicture(display_, drawable, format, CPRepeat, &pa); | |
| 1363 return r; | |
| 1364 } | |
| 1365 | |
| 1366 XPixmap RealXConnection::CreatePixmapFromData(char* data, const Size& size) { | |
|
Daniel Erat
2011/04/02 14:54:36
see other comment about using ImageContainer inste
marcheu
2011/04/04 19:55:58
Done.
| |
| 1367 int data_size = size.width * size.height * 4; | |
| 1368 char* pixmap_data = (char*)malloc(data_size); | |
|
Daniel Erat
2011/04/02 14:54:36
use static_cast
marcheu
2011/04/02 23:31:38
Note to self: add a comment that XDestroyImage wil
marcheu
2011/04/04 19:55:58
Done.
| |
| 1369 | |
| 1370 /* premultiply the RGB channels */ | |
| 1371 memcpy(pixmap_data, data, data_size); | |
| 1372 for(int i = 0; i<size.width * size.height; i++) { | |
|
Daniel Erat
2011/04/02 14:54:36
add space between for and ( and around <
marcheu
2011/04/04 19:55:58
Done.
| |
| 1373 pixmap_data[i*4+0] = pixmap_data[i*4+0] * pixmap_data[i*4+3] / 255; | |
| 1374 pixmap_data[i*4+1] = pixmap_data[i*4+1] * pixmap_data[i*4+3] / 255; | |
| 1375 pixmap_data[i*4+2] = pixmap_data[i*4+2] * pixmap_data[i*4+3] / 255; | |
| 1376 } | |
| 1377 | |
| 1378 XPixmap pixmap = XCreatePixmap(display_, root_, size.width, size.height, 32); | |
| 1379 | |
| 1380 XImage* image = XCreateImage (display_, | |
| 1381 DefaultVisual(display_, DefaultScreen(display_)), | |
|
Daniel Erat
2011/04/02 14:54:36
fix indenting
marcheu
2011/04/04 19:55:58
Done.
| |
| 1382 32, | |
|
Daniel Erat
2011/04/02 14:54:36
nit: mind labeling the ambiguous arguments with tr
marcheu
2011/04/04 19:55:58
Done.
| |
| 1383 ZPixmap, | |
| 1384 0, | |
| 1385 pixmap_data, | |
| 1386 size.width, size.height, | |
| 1387 32, 0); | |
| 1388 | |
| 1389 GC gc = XCreateGC (display_, pixmap, 0, NULL); | |
|
Daniel Erat
2011/04/02 14:54:36
remove space
marcheu
2011/04/04 19:55:58
Done.
| |
| 1390 if (!gc) { | |
| 1391 XDestroyImage (image); | |
|
Daniel Erat
2011/04/02 14:54:36
remove space
marcheu
2011/04/04 19:55:58
Done.
| |
| 1392 XFreePixmap (display_, pixmap); | |
|
Daniel Erat
2011/04/02 14:54:36
remove space
marcheu
2011/04/04 19:55:58
Done.
| |
| 1393 return None; | |
| 1394 } | |
| 1395 | |
| 1396 XPutImage (display_, pixmap, gc, image, 0, 0, 0, 0, size.width, size.height); | |
|
Daniel Erat
2011/04/02 14:54:36
ditto
marcheu
2011/04/04 19:55:58
Done.
| |
| 1397 XDestroyImage(image); | |
| 1398 | |
| 1399 XFreeGC (display_, gc); | |
| 1400 | |
| 1401 return pixmap; | |
| 1402 } | |
| 1403 | |
| 1404 void RealXConnection::RenderComposite(bool blend, XPicture src, XPicture mask, | |
| 1405 XPicture dst, Point srcpos, Point maskpos, Matrix4 transform, Size size) | |
|
Daniel Erat
2011/04/02 14:54:36
fix indenting
marcheu
2011/04/04 19:55:58
Done.
| |
| 1406 { | |
|
Daniel Erat
2011/04/02 14:54:36
move to end of previous line
marcheu
2011/04/04 19:55:58
Done.
| |
| 1407 XTransform xform = {{ | |
| 1408 { XDoubleToFixed( size.width/(float)transform[0][0] ), | |
|
Daniel Erat
2011/04/02 14:54:36
fix indenting/spacing/casts
marcheu
2011/04/04 19:55:58
Tried to do something about it, not sure exactly h
| |
| 1409 XDoubleToFixed( transform[1][0] ), | |
| 1410 XDoubleToFixed( transform[2][0] ) }, | |
| 1411 { XDoubleToFixed( transform[0][1] ), | |
| 1412 XDoubleToFixed( size.height/(float)transform[1][1] ), | |
| 1413 XDoubleToFixed( transform[2][1] ) }, | |
| 1414 { XDoubleToFixed( 0.0 ), | |
| 1415 XDoubleToFixed( 0.0 ), | |
| 1416 XDoubleToFixed( 1.0 ) } | |
| 1417 }}; | |
| 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/02 14:54:36
remove extra spaces here and below
marcheu
2011/04/04 19:55:58
Done.
| |
| 1423 XRenderSetPictureTransform( display_, src, &xform ); | |
| 1424 XRenderSetPictureFilter( display_, src, FilterBilinear, 0, 0 ); | |
| 1425 } | |
| 1426 | |
| 1427 int op = blend ? PictOpOver : PictOpSrc; | |
| 1428 XRenderComposite(display_, op, src, mask, dst, | |
| 1429 (int)srcpos.x, (int)srcpos.y, (int)maskpos.x, (int)maskpos.y, | |
|
Daniel Erat
2011/04/02 14:54:36
c++ casts, and group related params together on li
marcheu
2011/04/04 19:55:58
Done.
| |
| 1430 (int)dstpos.x, (int)dstpos.y, | |
| 1431 (int)transform[0][0], (int)transform[1][1]); | |
| 1432 } | |
| 1433 | |
| 1434 void RealXConnection::RenderFreePicture(XPicture pict) | |
| 1435 { | |
|
Daniel Erat
2011/04/02 14:54:36
...
marcheu
2011/04/04 19:55:58
Done.
| |
| 1436 XRenderFreePicture(display_, pict); | |
| 1437 } | |
| 1438 | |
| 1439 void RealXConnection::RenderFillRectangle(XPicture dst, | |
| 1440 float red, | |
| 1441 float green, | |
| 1442 float blue, | |
| 1443 Point pos, | |
| 1444 Size size) | |
| 1445 { | |
|
Daniel Erat
2011/04/02 14:54:36
...
marcheu
2011/04/04 19:55:58
Done.
| |
| 1446 XRenderColor c; | |
| 1447 | |
| 1448 c.red = red * 0xffff; | |
| 1449 c.green = green * 0xffff; | |
| 1450 c.blue = blue * 0xffff; | |
| 1451 c.alpha = 0xffff; | |
| 1452 XRenderFillRectangle(display_, PictOpSrc, dst, &c, | |
| 1453 pos.x, pos.y, size.width, size.height); | |
| 1454 } | |
| 1455 | |
| 1347 void RealXConnection::Free(void* item) { | 1456 void RealXConnection::Free(void* item) { |
| 1348 XFree(item); | 1457 XFree(item); |
| 1349 } | 1458 } |
| 1350 | 1459 |
| 1351 XVisualInfo* RealXConnection::GetVisualInfo(long mask, | 1460 XVisualInfo* RealXConnection::GetVisualInfo(long mask, |
| 1352 XVisualInfo* visual_template, | 1461 XVisualInfo* visual_template, |
| 1353 int* item_count) { | 1462 int* item_count) { |
| 1354 return XGetVisualInfo(display_, mask, visual_template, item_count); | 1463 return XGetVisualInfo(display_, mask, visual_template, item_count); |
| 1355 } | 1464 } |
| 1356 | 1465 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1510 string message; | 1619 string message; |
| 1511 StringAppendV(&message, format, ap); | 1620 StringAppendV(&message, format, ap); |
| 1512 va_end(ap); | 1621 va_end(ap); |
| 1513 | 1622 |
| 1514 LOG(WARNING) << "Got XCB error while " << message << ": " | 1623 LOG(WARNING) << "Got XCB error while " << message << ": " |
| 1515 << GetErrorText(error->error_code); | 1624 << GetErrorText(error->error_code); |
| 1516 return false; | 1625 return false; |
| 1517 } | 1626 } |
| 1518 | 1627 |
| 1519 } // namespace window_manager | 1628 } // namespace window_manager |
| OLD | NEW |