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

Side by Side Diff: chrome/browser/media/window_icon_util_mac.mm

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 <ApplicationServices/ApplicationServices.h>
8 #include <Cocoa/Cocoa.h>
9 #include <CoreFoundation/CoreFoundation.h>
10
11 #include "third_party/libyuv/include/libyuv/convert_argb.h"
12
13 gfx::ImageSkia WindowIconUtil::GetWindowIcon(content::DesktopMediaID id) {
14 CGWindowID ids[1];
15 ids[0] = id.id;
16 CFArrayRef window_id_array =
17 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr);
18 CFArrayRef window_array =
19 CGWindowListCreateDescriptionFromArray(window_id_array);
20 if (!window_array || 0 == CFArrayGetCount(window_array)) {
21 return gfx::ImageSkia();
22 }
23
24 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>(
25 CFArrayGetValueAtIndex(window_array, 0));
26 CFNumberRef pid_ref = reinterpret_cast<CFNumberRef>(
27 CFDictionaryGetValue(window, kCGWindowOwnerPID));
28
29 int pid;
30 CFNumberGetValue(pid_ref, kCFNumberIntType, &pid);
31
32 NSImage* icon_image =
33 [[NSRunningApplication runningApplicationWithProcessIdentifier:pid] icon];
34
35 int width = [icon_image size].width;
36 int height = [icon_image size].height;
37
38 CGImageRef cg_icon_image =
39 [icon_image CGImageForProposedRect:nil context:nil hints:nil];
40
41 int bits_per_pixel = CGImageGetBitsPerPixel(cg_icon_image);
42 if (bits_per_pixel != 32) {
43 return gfx::ImageSkia();
44 }
45
46 CGDataProviderRef provider = CGImageGetDataProvider(cg_icon_image);
47 CFDataRef cf_data = CGDataProviderCopyData(provider);
48
49 int src_stride = CGImageGetBytesPerRow(cg_icon_image);
50 const uint8_t* src_data = CFDataGetBytePtr(cf_data);
51
52 SkBitmap result;
53 result.allocN32Pixels(width, height, false);
54 result.lockPixels();
55
56 uint8_t* pixels_data = reinterpret_cast<uint8_t*>(result.getPixels());
57
58 libyuv::ABGRToARGB(src_data, src_stride, pixels_data, result.rowBytes(),
59 width, height);
60
61 CFRelease(cf_data);
62
63 return gfx::ImageSkia::CreateFrom1xBitmap(result);
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698