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

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: Static Function 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 "ui/gfx/x/x11_types.h"
11
12 gfx::ImageSkia WindowIconUtil::GetWindowIcon(content::DesktopMediaID id) {
13 Display* display = gfx::GetXDisplay();
14 Atom property = XInternAtom(display, "_NET_WM_ICON", True);
15 Atom actual_type;
16 int actual_format;
17 unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty
18 unsigned long size;
19 long* data;
20
21 int status = XGetWindowProperty(display, id.id, property, 0L,
22 ~0L, False, AnyPropertyType, &actual_type,
23 &actual_format, &size, &bytes_after,
24 reinterpret_cast<unsigned char**>(&data));
25 if (status != Success) {
26 return gfx::ImageSkia();
27 }
28
29 int width = 0;
30 int height = 0;
31 int start = 0;
32 int i = 0;
33 while (i < static_cast<int>(size)) {
Sergey Ulanov 2016/08/18 05:38:19 Please add a comment above to explain what happens
qiangchen 2016/08/18 20:07:46 Done.
34 if (i == 0 || static_cast<int>(data[i] * data[i + 1]) > width * height) {
Sergey Ulanov 2016/08/18 05:38:18 data[i+1] may be outside of the buffer size. Need
qiangchen 2016/08/18 20:07:46 Done.
35 width = static_cast<int>(data[i]);
36 height = static_cast<int>(data[i + 1]);
37 start = i + 2;
Sergey Ulanov 2016/08/18 05:38:19 verify here that start + 2 + width*height < size
qiangchen 2016/08/18 20:07:46 Done.
38 }
39 i = i + 2 + static_cast<int>(data[i] * data[i + 1]);
40 }
41
42 SkBitmap result;
43 result.allocN32Pixels(width, height, false);
44 result.lockPixels();
45
46 uint32_t* pixels_data = reinterpret_cast<uint32_t*>(result.getPixels());
47
48 for (long y = 0; y < height; ++y) {
49 for (long x = 0; x < width; ++x) {
50 pixels_data[result.rowBytesAsPixels() * y + x] = SkPreMultiplyColor(
Sergey Ulanov 2016/08/18 05:38:19 nit: you can allocate SkBitmap of type kUnpremul_S
qiangchen 2016/08/18 20:07:46 Create SkBitmap with Unpremul_SkAlphaType. But me
51 static_cast<uint32_t>(data[start + width * y + x]));
52 }
53 }
54
55 XFree(data);
56 return gfx::ImageSkia::CreateFrom1xBitmap(result);
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698