Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: x11/real_x_connection.cc

Issue 6902072: wm: Update a lot of code to use structs from geometry.h. (Closed) Base URL: ssh://gitrw.chromium.org:9222/window_manager.git@master
Patch Set: move override-redirect stacking and visibility into Window Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« window.cc ('K') | « x11/mock_x_connection.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 int count = 0, ordering = 0; 698 int count = 0, ordering = 0;
699 XRectangle* rects = 699 XRectangle* rects =
700 XShapeGetRectangles(display_, xid, ShapeBounding, &count, &ordering); 700 XShapeGetRectangles(display_, xid, ShapeBounding, &count, &ordering);
701 if (int error = UntrapErrors()) { 701 if (int error = UntrapErrors()) {
702 LOG(WARNING) << "Got X error while getting bounding rectangles for " 702 LOG(WARNING) << "Got X error while getting bounding rectangles for "
703 << XidStr(xid) << ": " << GetErrorText(error); 703 << XidStr(xid) << ": " << GetErrorText(error);
704 return false; 704 return false;
705 } 705 }
706 bytemap->Clear(0x0); 706 bytemap->Clear(0x0);
707 for (int i = 0; i < count; ++i) { 707 for (int i = 0; i < count; ++i) {
708 const XRectangle& rect = rects[i]; 708 const XRectangle& xrect = rects[i];
709 bytemap->SetRectangle(rect.x, rect.y, rect.width, rect.height, 0xff); 709 const Rect rect(xrect.x, xrect.y, xrect.width, xrect.height);
710 bytemap->SetRectangle(rect, 0xff);
710 } 711 }
711 XFree(rects); 712 XFree(rects);
712 713
713 // Note that xcb_shape_get_rectangles() appears to be broken up to and 714 // Note that xcb_shape_get_rectangles() appears to be broken up to and
714 // including libxcb 1.4, the version in Ubuntu 9.10 (the rectangles that 715 // including libxcb 1.4, the version in Ubuntu 9.10 (the rectangles that
715 // it returns are full of garbage values), but works correctly in 1.5. 716 // it returns are full of garbage values), but works correctly in 1.5.
716 // TODO: Switch to the XCB version of this code if/when we go to 1.5. 717 // TODO: Switch to the XCB version of this code if/when we go to 1.5.
717 #if 0 718 #if 0
718 xcb_shape_get_rectangles_cookie_t cookie = 719 xcb_shape_get_rectangles_cookie_t cookie =
719 xcb_shape_get_rectangles(xcb_conn_, xid, XCB_SHAPE_SK_BOUNDING); 720 xcb_shape_get_rectangles(xcb_conn_, xid, XCB_SHAPE_SK_BOUNDING);
720 xcb_generic_error_t* error = NULL; 721 xcb_generic_error_t* error = NULL;
721 scoped_ptr_malloc<xcb_shape_get_rectangles_reply_t> reply( 722 scoped_ptr_malloc<xcb_shape_get_rectangles_reply_t> reply(
722 xcb_shape_get_rectangles_reply(xcb_conn_, cookie, &error)); 723 xcb_shape_get_rectangles_reply(xcb_conn_, cookie, &error));
723 scoped_ptr_malloc<xcb_generic_error_t> scoped_error(error); 724 scoped_ptr_malloc<xcb_generic_error_t> scoped_error(error);
724 if (error || !reply.get()) { 725 if (error || !reply.get()) {
725 LOG(WARNING) << "Got X error while getting bounding region for " 726 LOG(WARNING) << "Got X error while getting bounding region for "
726 << XidStr(xid); 727 << XidStr(xid);
727 return false; 728 return false;
728 } 729 }
729 730
730 bytemap->Clear(0x0); 731 bytemap->Clear(0x0);
731 xcb_rectangle_t* rectangles = 732 xcb_rectangle_t* rectangles =
732 xcb_shape_get_rectangles_rectangles(reply.get()); 733 xcb_shape_get_rectangles_rectangles(reply.get());
733 int num_rectangles = xcb_shape_get_rectangles_rectangles_length(reply.get()); 734 int num_rectangles = xcb_shape_get_rectangles_rectangles_length(reply.get());
734 for (int i = 0; i < num_rectangles; ++i) { 735 for (int i = 0; i < num_rectangles; ++i) {
735 const xcb_rectangle_t& rect = rectangles[i]; 736 const xcb_rectangle_t& xrect = rectangles[i];
736 bytemap->SetRectangle(rect.x, rect.y, rect.width, rect.height, 0xff); 737 const Rect rect(xrect.x, xrect.y, xrect.width, xrect.height);
738 bytemap->SetRectangle(rect, 0xff);
737 } 739 }
738 #endif 740 #endif
739 741
740 return true; 742 return true;
741 } 743 }
742 744
743 bool RealXConnection::SetWindowBoundingRegionToRect(XWindow xid, 745 bool RealXConnection::SetWindowBoundingRegionToRect(XWindow xid,
744 const Rect& region) { 746 const Rect& region) {
745 xcb_rectangle_t rect; 747 xcb_rectangle_t rect;
746 rect.x = region.x; 748 rect.x = region.x;
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 << " drawable=" << XidStr(drawable) 1077 << " drawable=" << XidStr(drawable)
1076 << " drawable_depth=" << drawable_depth 1078 << " drawable_depth=" << drawable_depth
1077 << " image_depth=" << image->bits_per_pixel 1079 << " image_depth=" << image->bits_per_pixel
1078 << " lsb_first=" << (image->byte_order == LSBFirst); 1080 << " lsb_first=" << (image->byte_order == LSBFirst);
1079 XDestroyImage(image); 1081 XDestroyImage(image);
1080 return false; 1082 return false;
1081 } 1083 }
1082 1084
1083 const size_t data_size = image->bytes_per_line * image->height; 1085 const size_t data_size = image->bytes_per_line * image->height;
1084 const int format_bpp = GetBitsPerPixelInImageFormat(*format_out); 1086 const int format_bpp = GetBitsPerPixelInImageFormat(*format_out);
1085 const size_t expected_size = bounds.width * bounds.height * format_bpp / 8; 1087 const size_t expected_size = bounds.size().area() * format_bpp / 8;
1086 if (data_size != expected_size) { 1088 if (data_size != expected_size) {
1087 DLOG(WARNING) << "Expected " << expected_size << " bytes in image from " 1089 DLOG(WARNING) << "Expected " << expected_size << " bytes in image from "
1088 << XidStr(drawable) << " (" << bounds.size() << " at " 1090 << XidStr(drawable) << " (" << bounds.size() << " at "
1089 << format_bpp << " bpp) " << " but got " << data_size; 1091 << format_bpp << " bpp) " << " but got " << data_size;
1090 XDestroyImage(image); 1092 XDestroyImage(image);
1091 return false; 1093 return false;
1092 } 1094 }
1093 1095
1094 data_out->reset(reinterpret_cast<uint8_t*>(image->data)); 1096 data_out->reset(reinterpret_cast<uint8_t*>(image->data));
1095 image->data = NULL; // Take ownership so Xlib doesn't free it. 1097 image->data = NULL; // Take ownership so Xlib doesn't free it.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 display_, 1362 display_,
1361 depth == 24 ? PictStandardRGB24 : PictStandardARGB32); 1363 depth == 24 ? PictStandardRGB24 : PictStandardARGB32);
1362 pa.repeat = True; 1364 pa.repeat = True;
1363 XPicture r = XRenderCreatePicture(display_, drawable, format, CPRepeat, &pa); 1365 XPicture r = XRenderCreatePicture(display_, drawable, format, CPRepeat, &pa);
1364 return r; 1366 return r;
1365 } 1367 }
1366 1368
1367 XPixmap RealXConnection::CreatePixmapFromContainer( 1369 XPixmap RealXConnection::CreatePixmapFromContainer(
1368 const ImageContainer& container) { 1370 const ImageContainer& container) {
1369 Size size = container.size(); 1371 Size size = container.size();
1370 int data_size = size.width * size.height * 4; 1372 int data_size = size.area() * 4;
1371 1373
1372 // XDestroyImage will free() this. 1374 // XDestroyImage will free() this.
1373 char* pixmap_data = static_cast<char*>(malloc(data_size)); 1375 char* pixmap_data = static_cast<char*>(malloc(data_size));
1374 1376
1375 // Premultiply the RGB channels. 1377 // Premultiply the RGB channels.
1376 memcpy(pixmap_data, container.data(), data_size); 1378 memcpy(pixmap_data, container.data(), data_size);
1377 for (int i = 0; i < size.width * size.height; i++) { 1379 for (int i = 0; i < size.area(); i++) {
1378 pixmap_data[i*4+0] = pixmap_data[i*4+0] * pixmap_data[i*4+3] / 255; 1380 pixmap_data[i*4+0] = pixmap_data[i*4+0] * pixmap_data[i*4+3] / 255;
1379 pixmap_data[i*4+1] = pixmap_data[i*4+1] * pixmap_data[i*4+3] / 255; 1381 pixmap_data[i*4+1] = pixmap_data[i*4+1] * pixmap_data[i*4+3] / 255;
1380 pixmap_data[i*4+2] = pixmap_data[i*4+2] * pixmap_data[i*4+3] / 255; 1382 pixmap_data[i*4+2] = pixmap_data[i*4+2] * pixmap_data[i*4+3] / 255;
1381 } 1383 }
1382 1384
1383 XPixmap pixmap = XCreatePixmap(display_, root_, size.width, size.height, 32); 1385 XPixmap pixmap = XCreatePixmap(display_, root_, size.width, size.height, 32);
1384 1386
1385 XImage* image = XCreateImage( 1387 XImage* image = XCreateImage(
1386 display_, 1388 display_,
1387 DefaultVisual(display_, DefaultScreen(display_)), 1389 DefaultVisual(display_, DefaultScreen(display_)),
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 string message; 1646 string message;
1645 StringAppendV(&message, format, ap); 1647 StringAppendV(&message, format, ap);
1646 va_end(ap); 1648 va_end(ap);
1647 1649
1648 LOG(WARNING) << "Got XCB error while " << message << ": " 1650 LOG(WARNING) << "Got XCB error while " << message << ": "
1649 << GetErrorText(error->error_code); 1651 << GetErrorText(error->error_code);
1650 return false; 1652 return false;
1651 } 1653 }
1652 1654
1653 } // namespace window_manager 1655 } // namespace window_manager
OLDNEW
« window.cc ('K') | « x11/mock_x_connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698