Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Unified Diff: webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h

Issue 2099123002: [Chromoting] Improve DirectX capturer to support multiple outputs (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix several lint errors Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h
diff --git a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h
new file mode 100644
index 0000000000000000000000000000000000000000..31fb32ab9e53fb22bc9f674c5f86c645bd2cf609
--- /dev/null
+++ b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
+#define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
+
+#include <comdef.h>
+#include <wrl/client.h>
+#include <DXGI.h>
+#include <DXGI1_2.h>
+
+#include <memory>
+#include <vector>
+
+#include "webrtc/base/criticalsection.h"
+#include "webrtc/base/thread_annotations.h"
+#include "webrtc/modules/desktop_capture/desktop_frame.h"
+#include "webrtc/modules/desktop_capture/desktop_geometry.h"
+#include "webrtc/modules/desktop_capture/desktop_region.h"
+#include "webrtc/modules/desktop_capture/win/d3d_device.h"
+#include "webrtc/modules/desktop_capture/win/dxgi_texture.h"
+
+namespace webrtc {
+
+// Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one
+// video card. None of functions in this class is thread-safe.
+// TODO(zijiehe): Understand the meaning of rotation.
+class DxgiOutputDuplicator {
+ public:
+ struct Context {
+ // The updated region DxgiOutputDuplicator::DetectUpdatedRegion() output
+ // during last Duplicate() function call. It's a DesktopRegion translated by
+ // offset of each DxgiOutputDuplicator instance.
+ DesktopRegion updated_region;
+ };
+
+ // Creates an instance of DxgiOutputDuplicator from a D3dDevice and one of its
+ // IDXGIOutput1. Caller must maintain the lifetime of device, to make sure it
+ // outlives this instance. Only DxgiAdapterDuplicator can create an instance.
+ DxgiOutputDuplicator(const D3dDevice& device,
+ const Microsoft::WRL::ComPtr<IDXGIOutput1>& output,
+ const DXGI_OUTPUT_DESC& desc);
+
+ // To allow this class to work with vector.
+ DxgiOutputDuplicator(DxgiOutputDuplicator&& other);
+
+ // Destructs this instance. We need to make sure texture_ has been released
+ // before duplication_.
+ ~DxgiOutputDuplicator();
+
+ // Initializes duplication_ object.
+ bool Initialize();
+
+ // Copies the content of current IDXGIOutput to the |target|. To improve the
+ // performance, this function copies only regions merged from
+ // |last_frame|.updated_region and DetectUpdatedRegion(). The |offset| decides
+ // the
+ // offset in the |target| where the content should be copied to. i.e. this
+ // function copies the content to the rectangle of (offset.x(), offset.y()) to
+ // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()).
+ // The |last_frame| is always expected to be translated by the same offset.
+ // Returns false in case of a failure.
+ bool Duplicate(Context* context,
+ const DesktopFrame* last_frame,
+ const DesktopVector offset,
+ DesktopFrame* target);
+
+ // Returns the desktop rect covered by this DxgiOutputDuplicator.
+ DesktopRect desktop_rect() const { return desktop_rect_; }
+
+ private:
+ friend class DxgiAdapterDuplicator;
+
+ // Detects updated region translated by offset from IDXGIOutput1. This
+ // function will set the |updated_region| as entire DesktopRect starts from
+ // offset if it failed to execute Windows APIs.
+ void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
+ const DesktopVector offset,
+ DesktopRegion* updated_region);
+
+ // Returns untranslated updated region, which are directly returned by Windows
+ // APIs. Returns false in case of a failure.
+ bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
+ DesktopRegion* updated_region);
+
+ bool ReleaseFrame();
+
+ // Initializes duplication_ instance. Expects duplication_ is in empty status.
+ // Returns false if system does not support IDXGIOutputDuplication.
+ bool DuplicateOutput();
+
+ // Returns a DesktopRect with the same size of desktop_size_, but translated
+ // by offset.
+ DesktopRect TranslatedDesktopRect(const DesktopVector offset);
+
+ void Setup(Context* context);
+
+ void Unregister(const Context* const context);
+
+ // Spreads changes from |context| to other registered Context(s) in
+ // contexts_.
+ void SpreadContextChange(const Context* const context);
+
+ const D3dDevice& device_;
+ const Microsoft::WRL::ComPtr<IDXGIOutput1> output_;
+ const DesktopRect desktop_rect_;
+ Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_;
+ DXGI_OUTDUPL_DESC desc_;
+ std::vector<uint8_t> metadata;
+ std::unique_ptr<DxgiTexture> texture_;
+
+ // After each AcquireNextFrame() function call, updated_region_(s) of all
+ // active Context(s) need to be updated. Since they have missed the
+ // change this time. And during next Duplicate() function call, their
+ // updated_region_ will be merged and copied.
+ std::vector<Context*> contexts_;
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_

Powered by Google App Engine
This is Rietveld 408576698