OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/browser/media/window_icon_util.h" | 5 #include "chrome/browser/media/window_icon_util.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/Xutil.h> | 8 #include <X11/Xutil.h> |
9 | 9 |
10 #include "ui/gfx/x/x11_error_tracker.h" | |
10 #include "ui/gfx/x/x11_types.h" | 11 #include "ui/gfx/x/x11_types.h" |
11 | 12 |
12 gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) { | 13 gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) { |
13 DCHECK(id.type == content::DesktopMediaID::TYPE_WINDOW); | 14 DCHECK(id.type == content::DesktopMediaID::TYPE_WINDOW); |
14 | 15 |
15 Display* display = gfx::GetXDisplay(); | 16 Display* display = gfx::GetXDisplay(); |
16 Atom property = XInternAtom(display, "_NET_WM_ICON", True); | 17 Atom property = XInternAtom(display, "_NET_WM_ICON", True); |
17 Atom actual_type; | 18 Atom actual_type; |
18 int actual_format; | 19 int actual_format; |
19 unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty | 20 unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty |
20 unsigned long size; | 21 unsigned long size; |
21 long* data; | 22 long* data; |
22 | 23 |
24 gfx::X11ErrorTracker error_tracker; | |
Daniel Erat
2016/08/26 01:50:39
this should probably be in an std::unique_ptr so y
qiangchen
2016/08/26 15:53:46
Done.
| |
23 int status = XGetWindowProperty(display, id.id, property, 0L, ~0L, False, | 25 int status = XGetWindowProperty(display, id.id, property, 0L, ~0L, False, |
24 AnyPropertyType, &actual_type, &actual_format, | 26 AnyPropertyType, &actual_type, &actual_format, |
25 &size, &bytes_after, | 27 &size, &bytes_after, |
26 reinterpret_cast<unsigned char**>(&data)); | 28 reinterpret_cast<unsigned char**>(&data)); |
29 | |
27 if (status != Success) { | 30 if (status != Success) { |
28 return gfx::ImageSkia(); | 31 return gfx::ImageSkia(); |
29 } | 32 } |
30 | 33 |
31 // The format of |data| is concatenation of sections like | 34 // The format of |data| is concatenation of sections like |
32 // [width, height, pixel data of size width * height], and the total bytes | 35 // [width, height, pixel data of size width * height], and the total bytes |
33 // number of |data| is |size|. And here we are picking the largest icon. | 36 // number of |data| is |size|. And here we are picking the largest icon. |
34 int width = 0; | 37 int width = 0; |
35 int height = 0; | 38 int height = 0; |
36 int start = 0; | 39 int start = 0; |
(...skipping 18 matching lines...) Expand all Loading... | |
55 for (long y = 0; y < height; ++y) { | 58 for (long y = 0; y < height; ++y) { |
56 for (long x = 0; x < width; ++x) { | 59 for (long x = 0; x < width; ++x) { |
57 pixels_data[result.rowBytesAsPixels() * y + x] = | 60 pixels_data[result.rowBytesAsPixels() * y + x] = |
58 static_cast<uint32_t>(data[start + width * y + x]); | 61 static_cast<uint32_t>(data[start + width * y + x]); |
59 } | 62 } |
60 } | 63 } |
61 | 64 |
62 XFree(data); | 65 XFree(data); |
63 return gfx::ImageSkia::CreateFrom1xBitmap(result); | 66 return gfx::ImageSkia::CreateFrom1xBitmap(result); |
64 } | 67 } |
OLD | NEW |