OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "base/threading/thread.h" | 35 #include "base/threading/thread.h" |
36 #include "skia/ext/image_operations.h" | 36 #include "skia/ext/image_operations.h" |
37 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
38 #include "third_party/skia/include/core/SkPostConfig.h" | 38 #include "third_party/skia/include/core/SkPostConfig.h" |
39 #include "ui/base/x/x11_menu_list.h" | 39 #include "ui/base/x/x11_menu_list.h" |
40 #include "ui/base/x/x11_util_internal.h" | 40 #include "ui/base/x/x11_util_internal.h" |
41 #include "ui/events/event_utils.h" | 41 #include "ui/events/event_utils.h" |
42 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 42 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
43 #include "ui/events/x/device_data_manager_x11.h" | 43 #include "ui/events/x/device_data_manager_x11.h" |
44 #include "ui/events/x/touch_factory_x11.h" | 44 #include "ui/events/x/touch_factory_x11.h" |
45 #include "ui/gfx/canvas.h" | |
46 #include "ui/gfx/geometry/insets.h" | 45 #include "ui/gfx/geometry/insets.h" |
47 #include "ui/gfx/geometry/point.h" | 46 #include "ui/gfx/geometry/point.h" |
48 #include "ui/gfx/geometry/point_conversions.h" | 47 #include "ui/gfx/geometry/point_conversions.h" |
49 #include "ui/gfx/geometry/rect.h" | 48 #include "ui/gfx/geometry/rect.h" |
50 #include "ui/gfx/geometry/size.h" | 49 #include "ui/gfx/geometry/size.h" |
51 #include "ui/gfx/image/image_skia.h" | |
52 #include "ui/gfx/image/image_skia_rep.h" | |
53 #include "ui/gfx/skia_util.h" | 50 #include "ui/gfx/skia_util.h" |
54 #include "ui/gfx/x/x11_error_tracker.h" | 51 #include "ui/gfx/x/x11_error_tracker.h" |
55 | 52 |
56 #if defined(OS_FREEBSD) | 53 #if defined(OS_FREEBSD) |
57 #include <sys/sysctl.h> | 54 #include <sys/sysctl.h> |
58 #include <sys/types.h> | 55 #include <sys/types.h> |
59 #endif | 56 #endif |
60 | 57 |
61 namespace ui { | 58 namespace ui { |
62 | 59 |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 for (long i = static_cast<long>(count) - 1; i >= 0; i--) | 1183 for (long i = static_cast<long>(count) - 1; i >= 0; i--) |
1187 windows->push_back(stack[i]); | 1184 windows->push_back(stack[i]); |
1188 } | 1185 } |
1189 | 1186 |
1190 if (data) | 1187 if (data) |
1191 XFree(data); | 1188 XFree(data); |
1192 | 1189 |
1193 return result; | 1190 return result; |
1194 } | 1191 } |
1195 | 1192 |
1196 bool CopyAreaToCanvas(XID drawable, | |
1197 gfx::Rect source_bounds, | |
1198 gfx::Point dest_offset, | |
1199 gfx::Canvas* canvas) { | |
1200 ui::XScopedImage scoped_image( | |
1201 XGetImage(gfx::GetXDisplay(), drawable, | |
1202 source_bounds.x(), source_bounds.y(), | |
1203 source_bounds.width(), source_bounds.height(), | |
1204 AllPlanes, ZPixmap)); | |
1205 XImage* image = scoped_image.get(); | |
1206 if (!image) { | |
1207 LOG(ERROR) << "XGetImage failed"; | |
1208 return false; | |
1209 } | |
1210 | |
1211 if (image->bits_per_pixel == 32) { | |
1212 if ((0xff << SK_R32_SHIFT) != image->red_mask || | |
1213 (0xff << SK_G32_SHIFT) != image->green_mask || | |
1214 (0xff << SK_B32_SHIFT) != image->blue_mask) { | |
1215 LOG(WARNING) << "XImage and Skia byte orders differ"; | |
1216 return false; | |
1217 } | |
1218 | |
1219 // Set the alpha channel before copying to the canvas. Otherwise, areas of | |
1220 // the framebuffer that were cleared by ply-image rather than being obscured | |
1221 // by an image during boot may end up transparent. | |
1222 // TODO(derat|marcheu): Remove this if/when ply-image has been updated to | |
1223 // set the framebuffer's alpha channel regardless of whether the device | |
1224 // claims to support alpha or not. | |
1225 for (int i = 0; i < image->width * image->height * 4; i += 4) | |
1226 image->data[i + 3] = 0xff; | |
1227 | |
1228 SkBitmap bitmap; | |
1229 bitmap.installPixels(SkImageInfo::MakeN32Premul(image->width, | |
1230 image->height), | |
1231 image->data, image->bytes_per_line); | |
1232 gfx::ImageSkia image_skia; | |
1233 gfx::ImageSkiaRep image_rep(bitmap, canvas->image_scale()); | |
1234 image_skia.AddRepresentation(image_rep); | |
1235 canvas->DrawImageInt(image_skia, dest_offset.x(), dest_offset.y()); | |
1236 } else { | |
1237 NOTIMPLEMENTED() << "Unsupported bits-per-pixel " << image->bits_per_pixel; | |
1238 return false; | |
1239 } | |
1240 | |
1241 return true; | |
1242 } | |
1243 | |
1244 WindowManagerName GuessWindowManager() { | 1193 WindowManagerName GuessWindowManager() { |
1245 std::string name; | 1194 std::string name; |
1246 if (GetWindowManagerName(&name)) { | 1195 if (GetWindowManagerName(&name)) { |
1247 // These names are taken from the WMs' source code. | 1196 // These names are taken from the WMs' source code. |
1248 if (name == "awesome") | 1197 if (name == "awesome") |
1249 return WM_AWESOME; | 1198 return WM_AWESOME; |
1250 if (name == "Blackbox") | 1199 if (name == "Blackbox") |
1251 return WM_BLACKBOX; | 1200 return WM_BLACKBOX; |
1252 if (name == "Compiz" || name == "compiz") | 1201 if (name == "Compiz" || name == "compiz") |
1253 return WM_COMPIZ; | 1202 return WM_COMPIZ; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1442 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1494 << "minor_code " << static_cast<int>(error_event.minor_code) | 1443 << "minor_code " << static_cast<int>(error_event.minor_code) |
1495 << " (" << request_str << ")"; | 1444 << " (" << request_str << ")"; |
1496 } | 1445 } |
1497 | 1446 |
1498 // ---------------------------------------------------------------------------- | 1447 // ---------------------------------------------------------------------------- |
1499 // End of x11_util_internal.h | 1448 // End of x11_util_internal.h |
1500 | 1449 |
1501 | 1450 |
1502 } // namespace ui | 1451 } // namespace ui |
OLD | NEW |