| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/video/capture/screen/screen_capturer.h" | 5 #include "media/video/capture/screen/screen_capturer.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 ScreenCapturer::Delegate* delegate_; | 68 ScreenCapturer::Delegate* delegate_; |
| 69 | 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameWin); | 70 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameWin); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // ScreenCapturerWin captures 32bit RGB using GDI. | 73 // ScreenCapturerWin captures 32bit RGB using GDI. |
| 74 // | 74 // |
| 75 // ScreenCapturerWin is double-buffered as required by ScreenCapturer. | 75 // ScreenCapturerWin is double-buffered as required by ScreenCapturer. |
| 76 class ScreenCapturerWin : public ScreenCapturer { | 76 class ScreenCapturerWin : public ScreenCapturer { |
| 77 public: | 77 public: |
| 78 ScreenCapturerWin(); | 78 ScreenCapturerWin(bool disable_aero); |
| 79 virtual ~ScreenCapturerWin(); | 79 virtual ~ScreenCapturerWin(); |
| 80 | 80 |
| 81 // Overridden from ScreenCapturer: | 81 // Overridden from ScreenCapturer: |
| 82 virtual void Start(Delegate* delegate) OVERRIDE; | 82 virtual void Start(Delegate* delegate) OVERRIDE; |
| 83 virtual void Stop() OVERRIDE; | 83 virtual void Stop() OVERRIDE; |
| 84 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | 84 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; |
| 85 virtual void CaptureFrame() OVERRIDE; | 85 virtual void CaptureFrame() OVERRIDE; |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 // Make sure that the device contexts match the screen configuration. | 88 // Make sure that the device contexts match the screen configuration. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 CHECK(bitmap_ != NULL); | 196 CHECK(bitmap_ != NULL); |
| 197 CHECK(data != NULL); | 197 CHECK(data != NULL); |
| 198 | 198 |
| 199 set_pixels(reinterpret_cast<uint8*>(data)); | 199 set_pixels(reinterpret_cast<uint8*>(data)); |
| 200 set_dimensions(SkISize::Make(bmi.bmiHeader.biWidth, | 200 set_dimensions(SkISize::Make(bmi.bmiHeader.biWidth, |
| 201 std::abs(bmi.bmiHeader.biHeight))); | 201 std::abs(bmi.bmiHeader.biHeight))); |
| 202 set_bytes_per_row( | 202 set_bytes_per_row( |
| 203 bmi.bmiHeader.biSizeImage / std::abs(bmi.bmiHeader.biHeight)); | 203 bmi.bmiHeader.biSizeImage / std::abs(bmi.bmiHeader.biHeight)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 ScreenCapturerWin::ScreenCapturerWin() | 206 ScreenCapturerWin::ScreenCapturerWin(bool disable_aero) |
| 207 : delegate_(NULL), | 207 : delegate_(NULL), |
| 208 desktop_dc_rect_(SkIRect::MakeEmpty()), | 208 desktop_dc_rect_(SkIRect::MakeEmpty()), |
| 209 composition_func_(NULL), | 209 composition_func_(NULL), |
| 210 set_thread_execution_state_failed_(false) { | 210 set_thread_execution_state_failed_(false) { |
| 211 if (disable_aero) { |
| 212 // Load dwmapi.dll dynamically since it is not available on XP. |
| 213 if (!dwmapi_library_.is_valid()) { |
| 214 base::FilePath path(base::GetNativeLibraryName( |
| 215 UTF8ToUTF16(kDwmapiLibraryName))); |
| 216 dwmapi_library_.Reset(base::LoadNativeLibrary(path, NULL)); |
| 217 } |
| 218 |
| 219 if (dwmapi_library_.is_valid() && composition_func_ == NULL) { |
| 220 composition_func_ = static_cast<DwmEnableCompositionFunc>( |
| 221 dwmapi_library_.GetFunctionPointer("DwmEnableComposition")); |
| 222 } |
| 223 } |
| 211 } | 224 } |
| 212 | 225 |
| 213 ScreenCapturerWin::~ScreenCapturerWin() { | 226 ScreenCapturerWin::~ScreenCapturerWin() { |
| 214 } | 227 } |
| 215 | 228 |
| 216 void ScreenCapturerWin::InvalidateRegion(const SkRegion& invalid_region) { | 229 void ScreenCapturerWin::InvalidateRegion(const SkRegion& invalid_region) { |
| 217 helper_.InvalidateRegion(invalid_region); | 230 helper_.InvalidateRegion(invalid_region); |
| 218 } | 231 } |
| 219 | 232 |
| 220 void ScreenCapturerWin::CaptureFrame() { | 233 void ScreenCapturerWin::CaptureFrame() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 281 |
| 269 // Check for cursor shape update. | 282 // Check for cursor shape update. |
| 270 CaptureCursor(); | 283 CaptureCursor(); |
| 271 } | 284 } |
| 272 | 285 |
| 273 void ScreenCapturerWin::Start(Delegate* delegate) { | 286 void ScreenCapturerWin::Start(Delegate* delegate) { |
| 274 DCHECK(delegate_ == NULL); | 287 DCHECK(delegate_ == NULL); |
| 275 | 288 |
| 276 delegate_ = delegate; | 289 delegate_ = delegate; |
| 277 | 290 |
| 278 // Load dwmapi.dll dynamically since it is not available on XP. | |
| 279 if (!dwmapi_library_.is_valid()) { | |
| 280 base::FilePath path(base::GetNativeLibraryName( | |
| 281 UTF8ToUTF16(kDwmapiLibraryName))); | |
| 282 dwmapi_library_.Reset(base::LoadNativeLibrary(path, NULL)); | |
| 283 } | |
| 284 | |
| 285 if (dwmapi_library_.is_valid() && composition_func_ == NULL) { | |
| 286 composition_func_ = static_cast<DwmEnableCompositionFunc>( | |
| 287 dwmapi_library_.GetFunctionPointer("DwmEnableComposition")); | |
| 288 } | |
| 289 | |
| 290 // Vote to disable Aero composited desktop effects while capturing. Windows | 291 // Vote to disable Aero composited desktop effects while capturing. Windows |
| 291 // will restore Aero automatically if the process exits. This has no effect | 292 // will restore Aero automatically if the process exits. This has no effect |
| 292 // under Windows 8 or higher. See crbug.com/124018. | 293 // under Windows 8 or higher. See crbug.com/124018. |
| 293 if (composition_func_ != NULL) { | 294 if (composition_func_ != NULL) { |
| 294 (*composition_func_)(DWM_EC_DISABLECOMPOSITION); | 295 (*composition_func_)(DWM_EC_DISABLECOMPOSITION); |
| 295 } | 296 } |
| 296 } | 297 } |
| 297 | 298 |
| 298 void ScreenCapturerWin::Stop() { | 299 void ScreenCapturerWin::Stop() { |
| 299 // Restore Aero. | 300 // Restore Aero. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 uint32 size) { | 596 uint32 size) { |
| 596 return scoped_refptr<SharedBuffer>(); | 597 return scoped_refptr<SharedBuffer>(); |
| 597 } | 598 } |
| 598 | 599 |
| 599 void ScreenCapturer::Delegate::ReleaseSharedBuffer( | 600 void ScreenCapturer::Delegate::ReleaseSharedBuffer( |
| 600 scoped_refptr<SharedBuffer> buffer) { | 601 scoped_refptr<SharedBuffer> buffer) { |
| 601 } | 602 } |
| 602 | 603 |
| 603 // static | 604 // static |
| 604 scoped_ptr<ScreenCapturer> ScreenCapturer::Create() { | 605 scoped_ptr<ScreenCapturer> ScreenCapturer::Create() { |
| 605 return scoped_ptr<ScreenCapturer>(new ScreenCapturerWin()); | 606 return CreateWithDisableAero(true); |
| 607 } |
| 608 |
| 609 // static |
| 610 scoped_ptr<ScreenCapturer> ScreenCapturer::CreateWithDisableAero( |
| 611 bool disable_aero) { |
| 612 return scoped_ptr<ScreenCapturer>(new ScreenCapturerWin(disable_aero)); |
| 606 } | 613 } |
| 607 | 614 |
| 608 } // namespace media | 615 } // namespace media |
| OLD | NEW |