dxgi_texture.h (2424B)
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 MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_H_ 12 #define MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_H_ 13 14 #include <d3d11.h> 15 #include <dxgi.h> 16 #include <dxgi1_2.h> 17 18 #include <cstdint> 19 #include <memory> 20 21 #include "modules/desktop_capture/desktop_frame.h" 22 #include "modules/desktop_capture/desktop_geometry.h" 23 24 namespace webrtc { 25 26 class DesktopRegion; 27 28 // A texture copied or mapped from a DXGI_OUTDUPL_FRAME_INFO and IDXGIResource. 29 class DxgiTexture { 30 public: 31 // Creates a DxgiTexture instance, which represents the `desktop_size` area of 32 // entire screen -- usually a monitor on the system. 33 DxgiTexture(); 34 35 virtual ~DxgiTexture(); 36 37 // Copies selected regions of a frame represented by frame_info and resource. 38 // Returns false if anything wrong. 39 bool CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info, 40 IDXGIResource* resource); 41 42 const DesktopSize& desktop_size() const { return desktop_size_; } 43 44 uint8_t* bits() const { return static_cast<uint8_t*>(rect_.pBits); } 45 46 int pitch() const { return static_cast<int>(rect_.Pitch); } 47 48 // Releases the resource currently holds by this instance. Returns false if 49 // anything wrong, and this instance should be deprecated in this state. bits, 50 // pitch and AsDesktopFrame are only valid after a success CopyFrom() call, 51 // but before Release() call. 52 bool Release(); 53 54 // Returns a DesktopFrame snapshot of a DxgiTexture instance. This 55 // DesktopFrame is used to copy a DxgiTexture content to another DesktopFrame 56 // only. And it should not outlive its DxgiTexture instance. 57 const DesktopFrame& AsDesktopFrame(); 58 59 protected: 60 DXGI_MAPPED_RECT* rect(); 61 62 virtual bool CopyFromTexture(const DXGI_OUTDUPL_FRAME_INFO& frame_info, 63 ID3D11Texture2D* texture) = 0; 64 65 virtual bool DoRelease() = 0; 66 67 private: 68 DXGI_MAPPED_RECT rect_ = {0}; 69 DesktopSize desktop_size_; 70 std::unique_ptr<DesktopFrame> frame_; 71 }; 72 73 } // namespace webrtc 74 75 #endif // MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_H_