Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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/desktop_frame_win.h" | 11 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
| 12 | 12 |
| 13 #include <assert.h> | |
| 13 #include <utility> | 14 #include <utility> |
| 14 | 15 |
| 15 #include "webrtc/system_wrappers/include/logging.h" | 16 #include "webrtc/system_wrappers/include/logging.h" |
| 16 | 17 |
| 17 namespace webrtc { | 18 namespace webrtc { |
| 18 | 19 |
| 19 DesktopFrameWin::DesktopFrameWin(DesktopSize size, | 20 DesktopFrameWin::DesktopFrameWin(DesktopSize size, |
| 20 int stride, | 21 int stride, |
| 21 uint8_t* data, | 22 uint8_t* data, |
| 22 std::unique_ptr<SharedMemory> shared_memory, | 23 std::unique_ptr<SharedMemory> shared_memory, |
| 23 HBITMAP bitmap) | 24 HBITMAP bitmap) |
| 24 : DesktopFrame(size, stride, data, shared_memory.get()), | 25 : DesktopFrame(size, stride, data, shared_memory.get()), |
| 25 bitmap_(bitmap), | 26 bitmap_(bitmap), |
| 26 owned_shared_memory_(std::move(shared_memory)) {} | 27 owned_shared_memory_(std::move(shared_memory)) {} |
| 27 | 28 |
| 28 DesktopFrameWin::~DesktopFrameWin() { | 29 DesktopFrameWin::~DesktopFrameWin() { |
| 29 DeleteObject(bitmap_); | 30 DeleteObject(bitmap_); |
| 30 } | 31 } |
| 31 | 32 |
| 32 // static | 33 // static |
| 33 DesktopFrameWin* DesktopFrameWin::Create( | 34 DesktopFrameWin* DesktopFrameWin::Create( |
| 34 DesktopSize size, | 35 DesktopSize size, |
| 35 SharedMemoryFactory* shared_memory_factory, | 36 SharedMemoryFactory* shared_memory_factory, |
| 36 HDC hdc) { | 37 HDC hdc) { |
| 37 int bytes_per_row = size.width() * kBytesPerPixel; | 38 int bytes_per_row = size.width() * DesktopFrame::kBytesPerPixel; |
|
Sergey Ulanov
2016/04/14 23:10:42
This class inherits from DesktopFrame, so we don't
Hzj_jie
2016/04/15 19:42:17
Sorry, changes to this file and its header file sh
| |
| 38 int buffer_size = bytes_per_row * size.height(); | 39 int buffer_size = bytes_per_row * size.height(); |
| 39 | 40 |
| 40 // Describe a device independent bitmap (DIB) that is the size of the desktop. | 41 // Describe a device independent bitmap (DIB) that is the size of the desktop. |
| 41 BITMAPINFO bmi = {}; | 42 BITMAPINFO bmi = {}; |
| 42 bmi.bmiHeader.biHeight = -size.height(); | 43 bmi.bmiHeader.biHeight = -size.height(); |
| 43 bmi.bmiHeader.biWidth = size.width(); | 44 bmi.bmiHeader.biWidth = size.width(); |
| 44 bmi.bmiHeader.biPlanes = 1; | 45 bmi.bmiHeader.biPlanes = 1; |
| 45 bmi.bmiHeader.biBitCount = DesktopFrameWin::kBytesPerPixel * 8; | 46 bmi.bmiHeader.biBitCount = DesktopFrame::kBytesPerPixel * 8; |
| 46 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); | 47 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); |
| 47 bmi.bmiHeader.biSizeImage = bytes_per_row * size.height(); | 48 bmi.bmiHeader.biSizeImage = buffer_size; |
| 48 | 49 |
| 49 std::unique_ptr<SharedMemory> shared_memory; | 50 std::unique_ptr<SharedMemory> shared_memory; |
| 50 HANDLE section_handle = nullptr; | 51 HANDLE section_handle = nullptr; |
| 51 if (shared_memory_factory) { | 52 if (shared_memory_factory) { |
| 52 shared_memory = rtc::ScopedToUnique( | 53 shared_memory = rtc::ScopedToUnique( |
| 53 shared_memory_factory->CreateSharedMemory(buffer_size)); | 54 shared_memory_factory->CreateSharedMemory(buffer_size)); |
| 54 if (shared_memory) | 55 if (shared_memory) |
| 55 section_handle = shared_memory->handle(); | 56 section_handle = shared_memory->handle(); |
| 56 } | 57 } |
| 57 void* data = nullptr; | 58 void* data = nullptr; |
| 58 HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data, | 59 HBITMAP bitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &data, |
| 59 section_handle, 0); | 60 section_handle, 0); |
| 60 if (!bitmap) { | 61 if (!bitmap) { |
| 61 LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError(); | 62 LOG(LS_WARNING) << "Failed to allocate new window frame " << GetLastError(); |
| 62 return nullptr; | 63 return nullptr; |
| 63 } | 64 } |
| 64 | 65 |
| 65 return new DesktopFrameWin(size, bytes_per_row, | 66 return new DesktopFrameWin(size, bytes_per_row, |
| 66 reinterpret_cast<uint8_t*>(data), | 67 reinterpret_cast<uint8_t*>(data), |
| 67 std::move(shared_memory), bitmap); | 68 std::move(shared_memory), bitmap); |
| 68 } | 69 } |
| 69 | 70 |
| 70 } // namespace webrtc | 71 } // namespace webrtc |
| OLD | NEW |