zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_H_ |
| 12 | #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_H_ |
| 13 | |
zijiehe | 5fea5fb | 2017-02-16 12:07:44 -0800 | [diff] [blame] | 14 | #include <D3D11.h> |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 15 | #include <DXGI1_2.h> |
| 16 | |
| 17 | #include <memory> |
| 18 | |
| 19 | #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 20 | #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | class DesktopRegion; |
| 25 | |
| 26 | // A texture copied or mapped from a DXGI_OUTDUPL_FRAME_INFO and IDXGIResource. |
| 27 | class DxgiTexture { |
| 28 | public: |
zijiehe | e61fbff | 2016-11-29 16:09:51 -0800 | [diff] [blame] | 29 | // Creates a DxgiTexture instance, which represents the |desktop_size| area of |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 30 | // entire screen -- usually a monitor on the system. |
zijiehe | 5fea5fb | 2017-02-16 12:07:44 -0800 | [diff] [blame] | 31 | DxgiTexture(); |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 32 | |
sergeyu | e183121 | 2016-10-26 13:15:42 -0700 | [diff] [blame] | 33 | virtual ~DxgiTexture(); |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 34 | |
| 35 | // Copies selected regions of a frame represented by frame_info and resource. |
| 36 | // Returns false if anything wrong. |
zijiehe | 5fea5fb | 2017-02-16 12:07:44 -0800 | [diff] [blame] | 37 | bool CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| 38 | IDXGIResource* resource); |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 39 | |
zijiehe | e61fbff | 2016-11-29 16:09:51 -0800 | [diff] [blame] | 40 | const DesktopSize& desktop_size() const { return desktop_size_; } |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 41 | |
| 42 | uint8_t* bits() const { return static_cast<uint8_t*>(rect_.pBits); } |
| 43 | |
| 44 | int pitch() const { return static_cast<int>(rect_.Pitch); } |
| 45 | |
| 46 | // Releases the resource currently holds by this instance. Returns false if |
| 47 | // anything wrong, and this instance should be deprecated in this state. bits, |
| 48 | // pitch and AsDesktopFrame are only valid after a success CopyFrom() call, |
| 49 | // but before Release() call. |
| 50 | bool Release(); |
| 51 | |
| 52 | // Returns a DesktopFrame snapshot of a DxgiTexture instance. This |
| 53 | // DesktopFrame is used to copy a DxgiTexture content to another DesktopFrame |
| 54 | // only. And it should not outlive its DxgiTexture instance. |
| 55 | const DesktopFrame& AsDesktopFrame(); |
| 56 | |
| 57 | protected: |
zijiehe | 5fea5fb | 2017-02-16 12:07:44 -0800 | [diff] [blame] | 58 | DXGI_MAPPED_RECT* rect(); |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 59 | |
zijiehe | 5fea5fb | 2017-02-16 12:07:44 -0800 | [diff] [blame] | 60 | virtual bool CopyFromTexture(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| 61 | ID3D11Texture2D* texture) = 0; |
| 62 | |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 63 | virtual bool DoRelease() = 0; |
| 64 | |
zijiehe | 5fea5fb | 2017-02-16 12:07:44 -0800 | [diff] [blame] | 65 | private: |
| 66 | DXGI_MAPPED_RECT rect_ = {0}; |
| 67 | DesktopSize desktop_size_; |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 68 | std::unique_ptr<DesktopFrame> frame_; |
zijiehe | 2d618de | 2016-08-08 17:50:21 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace webrtc |
| 72 | |
| 73 | #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_H_ |