blob: fb120921da73123cbeec3ba1ed6bfa4f4d8b0d0e [file] [log] [blame]
zijiehe2d618de2016-08-08 17:50:21 -07001/*
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
zijiehe5fea5fb2017-02-16 12:07:44 -080014#include <D3D11.h>
zijiehe2d618de2016-08-08 17:50:21 -070015#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
22namespace webrtc {
23
24class DesktopRegion;
25
26// A texture copied or mapped from a DXGI_OUTDUPL_FRAME_INFO and IDXGIResource.
27class DxgiTexture {
28 public:
zijiehee61fbff2016-11-29 16:09:51 -080029 // Creates a DxgiTexture instance, which represents the |desktop_size| area of
zijiehe2d618de2016-08-08 17:50:21 -070030 // entire screen -- usually a monitor on the system.
zijiehe5fea5fb2017-02-16 12:07:44 -080031 DxgiTexture();
zijiehe2d618de2016-08-08 17:50:21 -070032
sergeyue1831212016-10-26 13:15:42 -070033 virtual ~DxgiTexture();
zijiehe2d618de2016-08-08 17:50:21 -070034
35 // Copies selected regions of a frame represented by frame_info and resource.
36 // Returns false if anything wrong.
zijiehe5fea5fb2017-02-16 12:07:44 -080037 bool CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
38 IDXGIResource* resource);
zijiehe2d618de2016-08-08 17:50:21 -070039
zijiehee61fbff2016-11-29 16:09:51 -080040 const DesktopSize& desktop_size() const { return desktop_size_; }
zijiehe2d618de2016-08-08 17:50:21 -070041
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:
zijiehe5fea5fb2017-02-16 12:07:44 -080058 DXGI_MAPPED_RECT* rect();
zijiehe2d618de2016-08-08 17:50:21 -070059
zijiehe5fea5fb2017-02-16 12:07:44 -080060 virtual bool CopyFromTexture(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
61 ID3D11Texture2D* texture) = 0;
62
zijiehe2d618de2016-08-08 17:50:21 -070063 virtual bool DoRelease() = 0;
64
zijiehe5fea5fb2017-02-16 12:07:44 -080065 private:
66 DXGI_MAPPED_RECT rect_ = {0};
67 DesktopSize desktop_size_;
zijiehe2d618de2016-08-08 17:50:21 -070068 std::unique_ptr<DesktopFrame> frame_;
zijiehe2d618de2016-08-08 17:50:21 -070069};
70
71} // namespace webrtc
72
73#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_TEXTURE_H_