| Index: webrtc/modules/desktop_capture/window_capturer_win.cc
|
| diff --git a/webrtc/modules/desktop_capture/window_capturer_win.cc b/webrtc/modules/desktop_capture/window_capturer_win.cc
|
| index c7c312a17e957b3d132ed00ec7ab6c2f4a1e3cf0..26529aa53ccda037159fca908105a04be9a0f9ea 100644
|
| --- a/webrtc/modules/desktop_capture/window_capturer_win.cc
|
| +++ b/webrtc/modules/desktop_capture/window_capturer_win.cc
|
| @@ -25,6 +25,80 @@ namespace webrtc {
|
|
|
| namespace {
|
|
|
| +void InitializeBitmapHeader(BITMAPV5HEADER* header, int width, int height) {
|
| + memset(header, 0, sizeof(BITMAPV5HEADER));
|
| + header->bV5Size = sizeof(BITMAPV5HEADER);
|
| +
|
| + // Note that icons are created using top-down DIBs so we must negate the
|
| + // value used for the icon's height.
|
| + header->bV5Width = width;
|
| + header->bV5Height = -height;
|
| + header->bV5Planes = 1;
|
| + header->bV5Compression = BI_RGB;
|
| +
|
| + // Initializing the bitmap format to 32 bit ARGB.
|
| + header->bV5BitCount = 32;
|
| + header->bV5RedMask = 0x00FF0000;
|
| + header->bV5GreenMask = 0x0000FF00;
|
| + header->bV5BlueMask = 0x000000FF;
|
| + header->bV5AlphaMask = 0xFF000000;
|
| +
|
| + // Use the system color space. The default value is LCS_CALIBRATED_RGB, which
|
| + // causes us to crash if we don't specify the approprite gammas, etc. See
|
| + // <http://msdn.microsoft.com/en-us/library/ms536531(VS.85).aspx> and
|
| + // <http://b/1283121>.
|
| + header->bV5CSType = LCS_WINDOWS_COLOR_SPACE;
|
| +
|
| + // Use a valid value for bV5Intent as 0 is not a valid one.
|
| + // <http://msdn.microsoft.com/en-us/library/dd183381(VS.85).aspx>
|
| + header->bV5Intent = LCS_GM_IMAGES;
|
| +}
|
| +
|
| +std::unique_ptr<DesktopFrame> GetWindowIcon(HWND hwnd) {
|
| + HICON icon_handle =
|
| + reinterpret_cast<HICON>(SendMessage(hwnd, WM_GETICON, ICON_BIG, 0));
|
| + if (icon_handle == NULL)
|
| + icon_handle = (HICON)GetClassLongPtr(hwnd, GCLP_HICON);
|
| + if (icon_handle == NULL)
|
| + icon_handle =
|
| + reinterpret_cast<HICON>(SendMessage(hwnd, WM_GETICON, ICON_SMALL, 0));
|
| + if (icon_handle == NULL)
|
| + icon_handle =
|
| + reinterpret_cast<HICON>(SendMessage(hwnd, WM_GETICON, ICON_SMALL2, 0));
|
| + if (icon_handle == NULL)
|
| + icon_handle = (HICON)GetClassLongPtr(hwnd, GCLP_HICONSM);
|
| +
|
| + if (icon_handle == NULL)
|
| + return nullptr;
|
| +
|
| + ICONINFO icon_info;
|
| + ::GetIconInfo(icon_handle, &icon_info);
|
| +
|
| + BITMAP bitmap_info = {0};
|
| + ::GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info);
|
| +
|
| + std::unique_ptr<DesktopFrame> frame(new BasicDesktopFrame(
|
| + DesktopSize(bitmap_info.bmWidth, bitmap_info.bmHeight)));
|
| +
|
| + BITMAPV5HEADER h;
|
| + InitializeBitmapHeader(&h, bitmap_info.bmWidth, bitmap_info.bmHeight);
|
| + HDC hdc = ::GetDC(NULL);
|
| + uint8_t* bits;
|
| + HBITMAP dib =
|
| + ::CreateDIBSection(hdc, reinterpret_cast<BITMAPINFO*>(&h), DIB_RGB_COLORS,
|
| + reinterpret_cast<void**>(&bits), NULL, 0);
|
| + HDC dib_dc = CreateCompatibleDC(hdc);
|
| + ::SelectObject(dib_dc, dib);
|
| + ::DrawIconEx(dib_dc, 0, 0, icon_handle, bitmap_info.bmWidth,
|
| + bitmap_info.bmHeight, 0, NULL, DI_NORMAL);
|
| + for (int y = 0; y < bitmap_info.bmHeight; ++y) {
|
| + memcpy(frame->data() + frame->stride() * y,
|
| + bits + bitmap_info.bmWidth * DesktopFrame::kBytesPerPixel * y,
|
| + DesktopFrame::kBytesPerPixel * bitmap_info.bmWidth);
|
| + }
|
| + return frame;
|
| +}
|
| +
|
| BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
|
| WindowCapturer::WindowList* list =
|
| reinterpret_cast<WindowCapturer::WindowList*>(param);
|
| @@ -70,12 +144,13 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
|
| // Truncate the title if it's longer than kTitleLength.
|
| GetWindowText(hwnd, window_title, kTitleLength);
|
| window.title = rtc::ToUtf8(window_title);
|
| + window.icon = GetWindowIcon(hwnd);
|
|
|
| // Skip windows when we failed to convert the title or it is empty.
|
| if (window.title.empty())
|
| return TRUE;
|
|
|
| - list->push_back(window);
|
| + list->push_back(std::move(window));
|
|
|
| return TRUE;
|
| }
|
| @@ -116,11 +191,10 @@ WindowCapturerWin::WindowCapturerWin() {}
|
| WindowCapturerWin::~WindowCapturerWin() {}
|
|
|
| bool WindowCapturerWin::GetWindowList(WindowList* windows) {
|
| - WindowList result;
|
| - LPARAM param = reinterpret_cast<LPARAM>(&result);
|
| + windows->clear();
|
| + LPARAM param = reinterpret_cast<LPARAM>(windows);
|
| if (!EnumWindows(&WindowsEnumerationHandler, param))
|
| return false;
|
| - windows->swap(result);
|
|
|
| std::map<HWND, DesktopSize> new_map;
|
| for (const auto& item : *windows) {
|
|
|