2015-09-18 01:57:43 -06:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_FRAME_SUBSCRIBER_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_FRAME_SUBSCRIBER_H_
|
2015-09-18 01:57:43 -06:00
|
|
|
|
2018-11-08 09:58:54 -07:00
|
|
|
#include <memory>
|
2020-04-13 17:39:26 -06:00
|
|
|
#include <string>
|
2018-05-14 09:55:39 -06:00
|
|
|
|
2023-02-03 04:43:42 -07:00
|
|
|
#include "base/functional/callback.h"
|
2023-05-11 14:07:39 -06:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2018-07-13 03:54:49 -06:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2018-11-08 09:58:54 -07:00
|
|
|
#include "components/viz/host/client_frame_sink_video_capturer.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
2018-05-14 09:55:39 -06:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2022-01-10 15:31:39 -07:00
|
|
|
#include "media/capture/mojom/video_capture_buffer.mojom-forward.h"
|
2019-10-28 16:12:35 -06:00
|
|
|
#include "mojo/public/cpp/bindings/pending_remote.h"
|
2015-09-18 01:57:43 -06:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
2019-04-04 12:36:12 -06:00
|
|
|
namespace gfx {
|
|
|
|
class Image;
|
2021-07-01 18:51:37 -06:00
|
|
|
class Rect;
|
|
|
|
} // namespace gfx
|
2019-04-04 12:36:12 -06:00
|
|
|
|
2022-06-29 13:55:47 -06:00
|
|
|
namespace electron::api {
|
2015-09-18 01:57:43 -06:00
|
|
|
|
2018-05-14 09:55:39 -06:00
|
|
|
class WebContents;
|
|
|
|
|
2024-05-21 13:21:31 -06:00
|
|
|
class FrameSubscriber : private content::WebContentsObserver,
|
|
|
|
private viz::mojom::FrameSinkVideoConsumer {
|
2015-09-18 01:57:43 -06:00
|
|
|
public:
|
2016-06-20 18:15:39 -06:00
|
|
|
using FrameCaptureCallback =
|
2019-05-29 14:02:15 -06:00
|
|
|
base::RepeatingCallback<void(const gfx::Image&, const gfx::Rect&)>;
|
2015-09-18 01:57:43 -06:00
|
|
|
|
2019-04-04 12:36:12 -06:00
|
|
|
FrameSubscriber(content::WebContents* web_contents,
|
2018-05-14 11:09:05 -06:00
|
|
|
const FrameCaptureCallback& callback,
|
|
|
|
bool only_dirty);
|
2018-06-20 13:51:36 -06:00
|
|
|
~FrameSubscriber() override;
|
2015-09-18 01:57:43 -06:00
|
|
|
|
2021-11-03 05:41:45 -06:00
|
|
|
// disable copy
|
|
|
|
FrameSubscriber(const FrameSubscriber&) = delete;
|
|
|
|
FrameSubscriber& operator=(const FrameSubscriber&) = delete;
|
|
|
|
|
2015-09-18 01:57:43 -06:00
|
|
|
private:
|
2018-11-08 09:58:54 -07:00
|
|
|
void AttachToHost(content::RenderWidgetHost* host);
|
|
|
|
void DetachFromHost();
|
|
|
|
|
2024-06-20 02:49:07 -06:00
|
|
|
// content::WebContentsObserver
|
2021-03-04 10:27:05 -07:00
|
|
|
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
|
2023-02-03 04:43:42 -07:00
|
|
|
void PrimaryPageChanged(content::Page& page) override;
|
2018-11-08 09:58:54 -07:00
|
|
|
void RenderViewDeleted(content::RenderViewHost* host) override;
|
|
|
|
|
2024-06-20 02:49:07 -06:00
|
|
|
// viz::mojom::FrameSinkVideoConsumer
|
2018-11-08 09:58:54 -07:00
|
|
|
void OnFrameCaptured(
|
2022-01-10 15:31:39 -07:00
|
|
|
::media::mojom::VideoBufferHandlePtr data,
|
2018-11-08 09:58:54 -07:00
|
|
|
::media::mojom::VideoFrameInfoPtr info,
|
|
|
|
const gfx::Rect& content_rect,
|
2019-10-28 16:12:35 -06:00
|
|
|
mojo::PendingRemote<viz::mojom::FrameSinkVideoConsumerFrameCallbacks>
|
|
|
|
callbacks) override;
|
2023-11-01 08:02:12 -06:00
|
|
|
void OnNewSubCaptureTargetVersion(uint32_t crop_version) override;
|
2022-02-25 11:17:35 -07:00
|
|
|
void OnFrameWithEmptyRegionCapture() override;
|
2018-11-08 09:58:54 -07:00
|
|
|
void OnStopped() override;
|
2020-04-13 17:39:26 -06:00
|
|
|
void OnLog(const std::string& message) override;
|
2018-11-08 09:58:54 -07:00
|
|
|
|
2018-05-14 09:55:39 -06:00
|
|
|
void Done(const gfx::Rect& damage, const SkBitmap& frame);
|
2015-09-18 01:57:43 -06:00
|
|
|
|
2019-04-07 20:35:33 -06:00
|
|
|
// Get the pixel size of render view.
|
|
|
|
gfx::Size GetRenderViewSize() const;
|
|
|
|
|
2015-09-18 01:57:43 -06:00
|
|
|
FrameCaptureCallback callback_;
|
2018-05-14 11:09:05 -06:00
|
|
|
bool only_dirty_;
|
2016-02-15 19:44:10 -07:00
|
|
|
|
2023-05-11 14:07:39 -06:00
|
|
|
raw_ptr<content::RenderWidgetHost> host_;
|
2018-11-08 09:58:54 -07:00
|
|
|
std::unique_ptr<viz::ClientFrameSinkVideoCapturer> video_capturer_;
|
|
|
|
|
2021-01-26 11:16:21 -07:00
|
|
|
base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_{this};
|
2015-09-18 01:57:43 -06:00
|
|
|
};
|
|
|
|
|
2022-06-29 13:55:47 -06:00
|
|
|
} // namespace electron::api
|
2015-09-18 01:57:43 -06:00
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_FRAME_SUBSCRIBER_H_
|