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

Side by Side Diff: chrome/browser/media/window_icon_util_x11.cc

Issue 2270543003: Display Window Icon In Picker UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add file Created 4 years, 4 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
OLDNEW
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_types.h" 10 #include "ui/gfx/x/x11_types.h"
11 11
12 int ErrorHandler(Display* display, XErrorEvent* event) {
msw 2016/08/24 17:01:28 Why is this needed? Can you add an explanatory com
qiangchen 2016/08/24 18:03:30 Done.
13 return 0;
14 }
15
12 gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) { 16 gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) {
13 DCHECK(id.type == content::DesktopMediaID::TYPE_WINDOW); 17 DCHECK(id.type == content::DesktopMediaID::TYPE_WINDOW);
14 18
15 Display* display = gfx::GetXDisplay(); 19 Display* display = gfx::GetXDisplay();
16 Atom property = XInternAtom(display, "_NET_WM_ICON", True); 20 Atom property = XInternAtom(display, "_NET_WM_ICON", True);
17 Atom actual_type; 21 Atom actual_type;
18 int actual_format; 22 int actual_format;
19 unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty 23 unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty
20 unsigned long size; 24 unsigned long size;
21 long* data; 25 long* data;
22 26
27 XSetErrorHandler(&ErrorHandler);
23 int status = XGetWindowProperty(display, id.id, property, 0L, ~0L, False, 28 int status = XGetWindowProperty(display, id.id, property, 0L, ~0L, False,
24 AnyPropertyType, &actual_type, &actual_format, 29 AnyPropertyType, &actual_type, &actual_format,
25 &size, &bytes_after, 30 &size, &bytes_after,
26 reinterpret_cast<unsigned char**>(&data)); 31 reinterpret_cast<unsigned char**>(&data));
27 if (status != Success) { 32 if (status != Success) {
28 return gfx::ImageSkia(); 33 return gfx::ImageSkia();
29 } 34 }
35 XSetErrorHandler(nullptr);
msw 2016/08/24 17:01:28 Cache the old handler and restore it afterwards, l
qiangchen 2016/08/24 18:03:30 Is this quite useful here? The error handler is ju
msw 2016/08/24 18:13:56 My thought is that there may be some pre-existing
qiangchen 2016/08/24 18:59:13 Done.
30 36
31 // The format of |data| is concatenation of sections like 37 // The format of |data| is concatenation of sections like
32 // [width, height, pixel data of size width * height], and the total bytes 38 // [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. 39 // number of |data| is |size|. And here we are picking the largest icon.
34 int width = 0; 40 int width = 0;
35 int height = 0; 41 int height = 0;
36 int start = 0; 42 int start = 0;
37 int i = 0; 43 int i = 0;
38 while (i + 1 < static_cast<int>(size)) { 44 while (i + 1 < static_cast<int>(size)) {
39 if ((i == 0 || static_cast<int>(data[i] * data[i + 1]) > width * height) && 45 if ((i == 0 || static_cast<int>(data[i] * data[i + 1]) > width * height) &&
(...skipping 15 matching lines...) Expand all
55 for (long y = 0; y < height; ++y) { 61 for (long y = 0; y < height; ++y) {
56 for (long x = 0; x < width; ++x) { 62 for (long x = 0; x < width; ++x) {
57 pixels_data[result.rowBytesAsPixels() * y + x] = 63 pixels_data[result.rowBytesAsPixels() * y + x] =
58 static_cast<uint32_t>(data[start + width * y + x]); 64 static_cast<uint32_t>(data[start + width * y + x]);
59 } 65 }
60 } 66 }
61 67
62 XFree(data); 68 XFree(data);
63 return gfx::ImageSkia::CreateFrom1xBitmap(result); 69 return gfx::ImageSkia::CreateFrom1xBitmap(result);
64 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698