scoped_window_capture_request.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_AURA_SCOPED_WINDOW_CAPTURE_REQUEST_H_
  5. #define UI_AURA_SCOPED_WINDOW_CAPTURE_REQUEST_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "components/viz/common/surfaces/subtree_capture_id.h"
  8. #include "ui/aura/aura_export.h"
  9. #include "ui/aura/window_observer.h"
  10. namespace aura {
  11. class Window;
  12. // A scoped move-only object which is associated with a request to make a
  13. // non-root window individually capturable by a FrameSinkVideoCapturer. This
  14. // request is tracked as long as this object lives. Once all requests are
  15. // destroyed, the window will no longer be uniquely identifiable by a
  16. // viz::SubtreeCaptureId, and can no longer be individually capturable by the
  17. // FrameSinkVideoCapturer.
  18. // Note that making a window capturable forces the layer tree root at its layer
  19. // to be promoted to a render surface that draw into a render pass.
  20. // See https://crbug.com/1143930 for more details.
  21. class AURA_EXPORT ScopedWindowCaptureRequest : public WindowObserver {
  22. public:
  23. // Creates an empty request that doesn't affect any window.
  24. ScopedWindowCaptureRequest() = default;
  25. ScopedWindowCaptureRequest(ScopedWindowCaptureRequest&& other);
  26. ScopedWindowCaptureRequest& operator=(ScopedWindowCaptureRequest&& rhs);
  27. ~ScopedWindowCaptureRequest() override;
  28. Window* window() const { return window_; }
  29. viz::SubtreeCaptureId GetCaptureId() const;
  30. // WindowObserver:
  31. void OnWindowDestroying(Window* window) override;
  32. private:
  33. friend class Window;
  34. // Private so it can only be called through Window::MakeWindowCapturable().
  35. explicit ScopedWindowCaptureRequest(Window* window);
  36. // Attaches to the current |window_| by observing it. If |increment_requests|
  37. // is true (meaning this is a new request, rather than an existing one being
  38. // moved into |this|), OnScopedWindowCaptureRequestAdded() will be called on
  39. // |window_|. |window_| must be valid.
  40. void AttachToCurrentWindow(bool increment_requests);
  41. // Detaches from the current |window_| (if any) by ending observing it. If
  42. // |decrement_requests| is true (meaning this request is actually ending
  43. // rather than being moved from |this|), OnScopedWindowCaptureRequestRemoved()
  44. // will be called on |window_|.
  45. // |window_| will be reset to |nullptr|, and its old value will be returned.
  46. Window* DetachFromCurrentWindow(bool decrement_requests);
  47. // The window on which this request has been made. Can be |nullptr| if this is
  48. // an empty request (created by the default ctor), or if this object was
  49. // std::move()'d from.
  50. raw_ptr<Window> window_ = nullptr;
  51. };
  52. } // namespace aura
  53. #endif // UI_AURA_SCOPED_WINDOW_CAPTURE_REQUEST_H_