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

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

Issue 2307083002: Cleanup: move WebRTC related files from chrome/browser/media to chrome/browser/media/webrtc/ (Closed)
Patch Set: Removed file wrongly resuscitated during rebase Created 4 years, 3 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 GetWindowIcon(content::DesktopMediaID id) {
14 DCHECK(id.type == content::DesktopMediaID::TYPE_WINDOW);
15
16 CGWindowID ids[1];
17 ids[0] = id.id;
18 CFArrayRef window_id_array =
19 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr);
20 CFArrayRef window_array =
21 CGWindowListCreateDescriptionFromArray(window_id_array);
22 if (!window_array || 0 == CFArrayGetCount(window_array)) {
23 return gfx::ImageSkia();
24 }
25
26 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>(
27 CFArrayGetValueAtIndex(window_array, 0));
28 CFNumberRef pid_ref = reinterpret_cast<CFNumberRef>(
29 CFDictionaryGetValue(window, kCGWindowOwnerPID));
30
31 int pid;
32 CFNumberGetValue(pid_ref, kCFNumberIntType, &pid);
33
34 NSImage* icon_image =
35 [[NSRunningApplication runningApplicationWithProcessIdentifier:pid] icon];
36
37 int width = [icon_image size].width;
38 int height = [icon_image size].height;
39
40 CGImageRef cg_icon_image =
41 [icon_image CGImageForProposedRect:nil context:nil hints:nil];
42
43 int bits_per_pixel = CGImageGetBitsPerPixel(cg_icon_image);
44 if (bits_per_pixel != 32) {
45 return gfx::ImageSkia();
46 }
47
48 CGDataProviderRef provider = CGImageGetDataProvider(cg_icon_image);
49 CFDataRef cf_data = CGDataProviderCopyData(provider);
50
51 int src_stride = CGImageGetBytesPerRow(cg_icon_image);
52 const uint8_t* src_data = CFDataGetBytePtr(cf_data);
53
54 SkBitmap result;
55 result.allocN32Pixels(width, height, false);
56 result.lockPixels();
57
58 uint8_t* pixels_data = reinterpret_cast<uint8_t*>(result.getPixels());
59
60 libyuv::ABGRToARGB(src_data, src_stride, pixels_data, result.rowBytes(),
61 width, height);
62
63 CFRelease(cf_data);
64
65 return gfx::ImageSkia::CreateFrom1xBitmap(result);
66 }
OLDNEW
« no previous file with comments | « chrome/browser/media/window_icon_util_chromeos.cc ('k') | chrome/browser/media/window_icon_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698