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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/window_icon_util_x11.cc
diff --git a/chrome/browser/media/window_icon_util_x11.cc b/chrome/browser/media/window_icon_util_x11.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8920fd253fdb51849499f78b37d03dc583d0986b
--- /dev/null
+++ b/chrome/browser/media/window_icon_util_x11.cc
@@ -0,0 +1,74 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/window_icon_util.h"
+
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#include "third_party/webrtc/modules/desktop_capture/x11/shared_x_display.h"
+
+class WindowIconUtilLinux : public WindowIconUtil {
+ public:
+ explicit WindowIconUtilLinux(const webrtc::DesktopCaptureOptions& options);
+ gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) override;
+
+ private:
+ webrtc::SharedXDisplay* x_display_;
+};
+
+WindowIconUtilLinux::WindowIconUtilLinux(
+ const webrtc::DesktopCaptureOptions& options) {
+ x_display_ = options.x_display();
+}
+
+gfx::ImageSkia WindowIconUtilLinux::GetWindowIcon(content::DesktopMediaID id) {
+ Atom property = XInternAtom(x_display_->display(), "_NET_WM_ICON", True);
+ Atom actual_type;
+ int actual_format;
+ unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty
+ unsigned long size;
+ long* data;
+
+ int status = XGetWindowProperty(x_display_->display(), id.id, property, 0L,
+ ~0L, False, AnyPropertyType, &actual_type,
+ &actual_format, &size, &bytes_after,
+ reinterpret_cast<unsigned char**>(&data));
+ if (status != Success) {
+ return gfx::ImageSkia();
+ }
+
+ 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.
+ int start = 0;
+ 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
+ while (i < size) {
+ if (i == 0 || data[i] * data[i + 1] > width * height) {
+ width = data[i];
+ height = data[i + 1];
+ start = i + 2;
+ }
+ 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
+ }
+
+ SkBitmap result;
+ result.allocN32Pixels(width, height, false);
+ result.lockPixels();
+
+ uint32_t* pixels_data = reinterpret_cast<uint32_t*>(result.getPixels());
+
+ for (long y = 0; y < height; ++y) {
+ for (long x = 0; x < width; ++x) {
+ pixels_data[result.rowBytesAsPixels() * y + x] = SkPreMultiplyColor(
+ static_cast<uint32_t>(data[start + width * y + x]));
+ }
+ }
+
+ XFree(data);
+ return gfx::ImageSkia::CreateFrom1xBitmap(result);
+}
+
+std::unique_ptr<WindowIconUtil> WindowIconUtil::Create(
+ const webrtc::DesktopCaptureOptions& options) {
+ return std::unique_ptr<WindowIconUtil>(new WindowIconUtilLinux(options));
+}

Powered by Google App Engine
This is Rietveld 408576698