dxgi_texture.h 2.3 KB

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