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

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: 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 class WindowIconUtilMac : public WindowIconUtil {
14 public:
15 WindowIconUtilMac() {}
16 gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) override;
17 };
18
19 gfx::ImageSkia WindowIconUtilMac::GetWindowIcon(content::DesktopMediaID id) {
20 CGWindowID ids[1];
21 ids[0] = id.id;
22 CFArrayRef window_id_array =
23 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr);
24 CFArrayRef window_array =
25 CGWindowListCreateDescriptionFromArray(window_id_array);
26 if (!window_array || 0 == CFArrayGetCount(window_array)) {
27 return gfx::ImageSkia();
28 }
29
30 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>(
31 CFArrayGetValueAtIndex(window_array, 0));
32 CFNumberRef pid_ref = reinterpret_cast<CFNumberRef>(
33 CFDictionaryGetValue(window, kCGWindowOwnerPID));
34
35 int pid;
36 CFNumberGetValue(pid_ref, kCFNumberIntType, &pid);
37
38 NSImage* icon_image =
39 [[NSRunningApplication runningApplicationWithProcessIdentifier:pid] icon];
40
41 int width = [icon_image size].width;
42 int height = [icon_image size].height;
43
44 CGImageRef cg_icon_image =
45 [icon_image CGImageForProposedRect:nil context:nil hints:nil];
46
47 int bits_per_pixel = CGImageGetBitsPerPixel(cg_icon_image);
48 if (bits_per_pixel != 32) {
49 return gfx::ImageSkia();
50 }
51
52 CGDataProviderRef provider = CGImageGetDataProvider(cg_icon_image);
53 CFDataRef cf_data = CGDataProviderCopyData(provider);
54
55 int src_stride = CGImageGetBytesPerRow(cg_icon_image);
56 const uint8_t* src_data = CFDataGetBytePtr(cf_data);
57
58 SkBitmap result;
59 result.allocN32Pixels(width, height, false);
60 result.lockPixels();
61
62 uint8_t* pixels_data = reinterpret_cast<uint8_t*>(result.getPixels());
63
64 libyuv::ABGRToARGB(src_data, src_stride, pixels_data, result.rowBytes(),
65 width, height);
66
67 CFRelease(cf_data);
68
69 return gfx::ImageSkia::CreateFrom1xBitmap(result);
70 }
71
72 std::unique_ptr<WindowIconUtil> WindowIconUtil::Create(
73 const webrtc::DesktopCaptureOptions& options) {
74 return std::unique_ptr<WindowIconUtil>(new WindowIconUtilMac());
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698