Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/desktop_capture/mac/window_list_utils.h" | 11 #include "webrtc/modules/desktop_capture/mac/window_list_utils.h" |
| 12 | 12 |
| 13 #include <ApplicationServices/ApplicationServices.h> | 13 #include <ApplicationServices/ApplicationServices.h> |
| 14 #include <Cocoa/Cocoa.h> | |
| 14 | 15 |
| 15 #include "webrtc/base/macutils.h" | 16 #include "webrtc/base/macutils.h" |
| 17 #include "webrtc/system_wrappers/include/logging.h" | |
| 16 | 18 |
| 17 namespace webrtc { | 19 namespace webrtc { |
| 18 | 20 |
| 21 std::unique_ptr<DesktopFrame> GetWindowIcon(WindowId id) { | |
| 22 CGWindowID ids[1]; | |
| 23 ids[0] = id; | |
| 24 CFArrayRef window_id_array = | |
| 25 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr); | |
| 26 CFArrayRef window_array = | |
| 27 CGWindowListCreateDescriptionFromArray(window_id_array); | |
| 28 if (!window_array || 0 == CFArrayGetCount(window_array)) { | |
| 29 return nullptr; | |
| 30 } | |
| 31 | |
| 32 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( | |
| 33 CFArrayGetValueAtIndex(window_array, 0)); | |
| 34 CFNumberRef pid_ref = reinterpret_cast<CFNumberRef>( | |
| 35 CFDictionaryGetValue(window, kCGWindowOwnerPID)); | |
| 36 | |
| 37 int pid; | |
| 38 CFNumberGetValue(pid_ref, kCFNumberIntType, &pid); | |
| 39 | |
| 40 NSImage* icon_image = | |
| 41 [[NSRunningApplication runningApplicationWithProcessIdentifier:pid] icon]; | |
| 42 | |
| 43 int width = [icon_image size].width; | |
| 44 int height = [icon_image size].height; | |
| 45 | |
| 46 CGImageRef cg_icon_image = | |
| 47 [icon_image CGImageForProposedRect:nil context:nil hints:nil]; | |
| 48 | |
| 49 int bits_per_pixel = CGImageGetBitsPerPixel(cg_icon_image); | |
| 50 if (bits_per_pixel != 32) { | |
| 51 LOG(LS_ERROR) << "Unsupported icon image depth: " << bits_per_pixel; | |
| 52 return nullptr; | |
| 53 } | |
| 54 | |
| 55 CGDataProviderRef provider = CGImageGetDataProvider(cg_icon_image); | |
| 56 CFDataRef cf_data = CGDataProviderCopyData(provider); | |
| 57 std::unique_ptr<DesktopFrame> frame( | |
| 58 new BasicDesktopFrame(DesktopSize(width, height))); | |
| 59 | |
| 60 int src_stride = CGImageGetBytesPerRow(cg_icon_image); | |
| 61 const uint32_t* src_data = (const uint32_t*)CFDataGetBytePtr(cf_data); | |
| 62 uint32_t* des_data = (uint32_t*)frame->data(); | |
| 63 | |
| 64 for (int y = 0; y < height; ++y) { | |
|
Sergey Ulanov
2016/08/12 06:00:29
Use ABGRToARGB() from libyuv to convert ABGR to AR
| |
| 65 for (int x = 0; x < width; ++x) { | |
| 66 uint32_t color = src_data[src_stride / 4 * y + x]; | |
| 67 uint32_t alpha = color & 0xFF000000; | |
| 68 uint32_t blue = color & 0x00FF0000; | |
| 69 uint32_t green = color & 0x0000FF00; | |
| 70 uint32_t red = color & 0x000000FF; | |
| 71 uint32_t colorD = alpha | (blue >> 16) | green | (red << 16); | |
| 72 des_data[frame->stride() / 4 * y + x] = colorD; | |
| 73 } | |
| 74 } | |
| 75 CFRelease(cf_data); | |
| 76 | |
| 77 return frame; | |
| 78 } | |
| 79 | |
| 19 bool GetWindowList(WindowCapturer::WindowList* windows) { | 80 bool GetWindowList(WindowCapturer::WindowList* windows) { |
| 20 // Only get on screen, non-desktop windows. | 81 // Only get on screen, non-desktop windows. |
| 21 CFArrayRef window_array = CGWindowListCopyWindowInfo( | 82 CFArrayRef window_array = CGWindowListCopyWindowInfo( |
| 22 kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, | 83 kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, |
| 23 kCGNullWindowID); | 84 kCGNullWindowID); |
| 24 if (!window_array) | 85 if (!window_array) |
| 25 return false; | 86 return false; |
| 26 | 87 |
| 27 // Check windows to make sure they have an id, title, and use window layer | 88 // Check windows to make sure they have an id, title, and use window layer |
| 28 // other than 0. | 89 // other than 0. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 40 // Skip windows with layer=0 (menu, dock). | 101 // Skip windows with layer=0 (menu, dock). |
| 41 int layer; | 102 int layer; |
| 42 CFNumberGetValue(window_layer, kCFNumberIntType, &layer); | 103 CFNumberGetValue(window_layer, kCFNumberIntType, &layer); |
| 43 if (layer != 0) | 104 if (layer != 0) |
| 44 continue; | 105 continue; |
| 45 | 106 |
| 46 int id; | 107 int id; |
| 47 CFNumberGetValue(window_id, kCFNumberIntType, &id); | 108 CFNumberGetValue(window_id, kCFNumberIntType, &id); |
| 48 WindowCapturer::Window window; | 109 WindowCapturer::Window window; |
| 49 window.id = id; | 110 window.id = id; |
| 50 if (!rtc::ToUtf8(window_title, &(window.title)) || | 111 if (!rtc::ToUtf8(window_title, &(window.title)) || window.title.empty()) { |
| 51 window.title.empty()) { | |
| 52 continue; | 112 continue; |
| 53 } | 113 } |
| 54 windows->push_back(window); | 114 window.icon = GetWindowIcon(id); |
| 115 windows->push_back(std::move(window)); | |
| 55 } | 116 } |
| 56 } | 117 } |
| 57 | 118 |
| 58 CFRelease(window_array); | 119 CFRelease(window_array); |
| 59 return true; | 120 return true; |
| 60 } | 121 } |
| 61 | 122 |
| 62 // Returns true if the window is occupying a full screen. | 123 // Returns true if the window is occupying a full screen. |
| 63 bool IsWindowFullScreen( | 124 bool IsWindowFullScreen(const MacDesktopConfiguration& desktop_config, |
| 64 const MacDesktopConfiguration& desktop_config, | 125 CFDictionaryRef window) { |
| 65 CFDictionaryRef window) { | |
| 66 bool fullscreen = false; | 126 bool fullscreen = false; |
| 67 CFDictionaryRef bounds_ref = reinterpret_cast<CFDictionaryRef>( | 127 CFDictionaryRef bounds_ref = reinterpret_cast<CFDictionaryRef>( |
| 68 CFDictionaryGetValue(window, kCGWindowBounds)); | 128 CFDictionaryGetValue(window, kCGWindowBounds)); |
| 69 | 129 |
| 70 CGRect bounds; | 130 CGRect bounds; |
| 71 if (bounds_ref && | 131 if (bounds_ref && |
| 72 CGRectMakeWithDictionaryRepresentation(bounds_ref, &bounds)) { | 132 CGRectMakeWithDictionaryRepresentation(bounds_ref, &bounds)) { |
| 73 for (MacDisplayConfigurations::const_iterator it = | 133 for (MacDisplayConfigurations::const_iterator it = |
| 74 desktop_config.displays.begin(); | 134 desktop_config.displays.begin(); |
| 75 it != desktop_config.displays.end(); ++it) { | 135 it != desktop_config.displays.end(); ++it) { |
| 76 if (it->bounds.equals(DesktopRect::MakeXYWH(bounds.origin.x, | 136 if (it->bounds.equals( |
| 77 bounds.origin.y, | 137 DesktopRect::MakeXYWH(bounds.origin.x, bounds.origin.y, |
| 78 bounds.size.width, | 138 bounds.size.width, bounds.size.height))) { |
| 79 bounds.size.height))) { | |
| 80 fullscreen = true; | 139 fullscreen = true; |
| 81 break; | 140 break; |
| 82 } | 141 } |
| 83 } | 142 } |
| 84 } | 143 } |
| 85 | 144 |
| 86 return fullscreen; | 145 return fullscreen; |
| 87 } | 146 } |
| 88 | 147 |
| 89 // Returns true if the window is minimized. | 148 // Returns true if the window is minimized. |
| 90 bool IsWindowMinimized(CGWindowID id) { | 149 bool IsWindowMinimized(CGWindowID id) { |
| 91 CFArrayRef window_id_array = | 150 CFArrayRef window_id_array = |
| 92 CFArrayCreate(NULL, reinterpret_cast<const void **>(&id), 1, NULL); | 151 CFArrayCreate(NULL, reinterpret_cast<const void**>(&id), 1, NULL); |
| 93 CFArrayRef window_array = | 152 CFArrayRef window_array = |
| 94 CGWindowListCreateDescriptionFromArray(window_id_array); | 153 CGWindowListCreateDescriptionFromArray(window_id_array); |
| 95 bool minimized = false; | 154 bool minimized = false; |
| 96 | 155 |
| 97 if (window_array && CFArrayGetCount(window_array)) { | 156 if (window_array && CFArrayGetCount(window_array)) { |
| 98 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( | 157 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( |
| 99 CFArrayGetValueAtIndex(window_array, 0)); | 158 CFArrayGetValueAtIndex(window_array, 0)); |
| 100 CFBooleanRef on_screen = reinterpret_cast<CFBooleanRef>( | 159 CFBooleanRef on_screen = reinterpret_cast<CFBooleanRef>( |
| 101 CFDictionaryGetValue(window, kCGWindowIsOnscreen)); | 160 CFDictionaryGetValue(window, kCGWindowIsOnscreen)); |
| 102 | 161 |
| 103 minimized = !on_screen; | 162 minimized = !on_screen; |
| 104 } | 163 } |
| 105 | 164 |
| 106 CFRelease(window_id_array); | 165 CFRelease(window_id_array); |
| 107 CFRelease(window_array); | 166 CFRelease(window_array); |
| 108 | 167 |
| 109 return minimized; | 168 return minimized; |
| 110 } | 169 } |
| 111 | 170 |
| 112 | |
| 113 | |
| 114 } // namespace webrtc | 171 } // namespace webrtc |
| OLD | NEW |