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

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

Issue 2246923002: Icon Capture Utility For Linux, Windows and Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/window_icon_util.h"
6
7 #include <X11/Xatom.h>
8 #include <X11/Xutil.h>
9
10 #include "third_party/webrtc/modules/desktop_capture/x11/shared_x_display.h"
11
12 class WindowIconUtilLinux : public WindowIconUtil {
13 public:
14 explicit WindowIconUtilLinux(const webrtc::DesktopCaptureOptions& options);
15 gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) override;
16
17 private:
18 webrtc::SharedXDisplay* x_display_;
19 };
20
21 WindowIconUtilLinux::WindowIconUtilLinux(
22 const webrtc::DesktopCaptureOptions& options) {
23 x_display_ = options.x_display();
24 }
25
26 gfx::ImageSkia WindowIconUtilLinux::GetWindowIcon(content::DesktopMediaID id) {
27 Atom property = XInternAtom(x_display_->display(), "_NET_WM_ICON", True);
28 Atom actual_type;
29 int actual_format;
30 unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty
31 unsigned long size;
32 long* data;
33
34 int status = XGetWindowProperty(x_display_->display(), id.id, property, 0L,
35 ~0L, False, AnyPropertyType, &actual_type,
36 &actual_format, &size, &bytes_after,
37 reinterpret_cast<unsigned char**>(&data));
38 if (status != Success) {
39 return gfx::ImageSkia();
40 }
41
42 long width, height;
Sergey Ulanov 2016/08/15 22:28:39 These are not set before being used below
qiangchen 2016/08/16 22:29:53 Done.
43 int start = 0;
44 unsigned long i = 0;
Sergey Ulanov 2016/08/15 22:28:39 Please don't use types like "unsigned long" and "l
qiangchen 2016/08/16 22:29:53 It is due to weird setting of linux for XGetProper
45 while (i < size) {
46 if (i == 0 || data[i] * data[i + 1] > width * height) {
47 width = data[i];
48 height = data[i + 1];
49 start = i + 2;
50 }
51 i = i + 2 + data[i] * data[i + 1];
Sergey Ulanov 2016/08/15 22:28:39 It's very confusing what happens here. Is it that
qiangchen 2016/08/16 22:29:52 The |size| is not how many icons are there, but ju
52 }
53
54 SkBitmap result;
55 result.allocN32Pixels(width, height, false);
56 result.lockPixels();
57
58 uint32_t* pixels_data = reinterpret_cast<uint32_t*>(result.getPixels());
59
60 for (long y = 0; y < height; ++y) {
61 for (long x = 0; x < width; ++x) {
62 pixels_data[result.rowBytesAsPixels() * y + x] = SkPreMultiplyColor(
63 static_cast<uint32_t>(data[start + width * y + x]));
64 }
65 }
66
67 XFree(data);
68 return gfx::ImageSkia::CreateFrom1xBitmap(result);
69 }
70
71 std::unique_ptr<WindowIconUtil> WindowIconUtil::Create(
72 const webrtc::DesktopCaptureOptions& options) {
73 return std::unique_ptr<WindowIconUtil>(new WindowIconUtilLinux(options));
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698