OLD | NEW |
(Empty) | |
| 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_STAGING_H_ |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_STAGING_H_ |
| 13 |
| 14 #include <wrl/client.h> |
| 15 #include <D3D11.h> |
| 16 #include <DXGI1_2.h> |
| 17 |
| 18 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 19 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 20 #include "webrtc/modules/desktop_capture/win/d3d_device.h" |
| 21 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" |
| 22 |
| 23 namespace webrtc { |
| 24 |
| 25 // A pair of an ID3D11Texture2D and an IDXGISurface. We need an ID3D11Texture2D |
| 26 // instance to copy GPU texture to RAM, but an IDXGISurface instance to map the |
| 27 // texture into a bitmap buffer. These two instances are pointing to a same |
| 28 // object. |
| 29 // |
| 30 // An ID3D11Texture2D is created by an ID3D11Device, so a DxgiTexture cannot be |
| 31 // shared between two DxgiAdapterDuplicators. |
| 32 class DxgiTextureStaging : public DxgiTexture { |
| 33 public: |
| 34 // Creates a DxgiTextureStaging instance. Caller must maintain the lifetime |
| 35 // of input device to make sure it outlives this instance. |
| 36 DxgiTextureStaging(const DesktopRect& desktop_rect, const D3dDevice& device); |
| 37 |
| 38 ~DxgiTextureStaging() override; |
| 39 |
| 40 // Copies selected regions of a frame represented by frame_info and resource. |
| 41 // Returns false if anything wrong. |
| 42 bool CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| 43 IDXGIResource* resource, |
| 44 const DesktopRegion& region) override; |
| 45 |
| 46 bool DoRelease() override; |
| 47 |
| 48 private: |
| 49 // Initializes stage_ from a CPU inaccessible IDXGIResource. Returns false if |
| 50 // it failed to execute Windows APIs, or the size of the texture is not |
| 51 // consistent with desktop_rect. |
| 52 bool InitializeStage(ID3D11Texture2D* texture); |
| 53 |
| 54 // Makes sure stage_ and surface_ are always pointing to a same object. |
| 55 // We need an ID3D11Texture2D instance for |
| 56 // ID3D11DeviceContext::CopySubresourceRegion, but an IDXGISurface for |
| 57 // IDXGISurface::Map. |
| 58 void AssertStageAndSurfaceAreSameObject(); |
| 59 |
| 60 const DesktopRect desktop_rect_; |
| 61 const D3dDevice& device_; |
| 62 Microsoft::WRL::ComPtr<ID3D11Texture2D> stage_; |
| 63 Microsoft::WRL::ComPtr<IDXGISurface> surface_; |
| 64 }; |
| 65 |
| 66 } // namespace webrtc |
| 67 |
| 68 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_STAGING_H_ |
OLD | NEW |