2015-09-18 07:57:43 +00: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 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_FRAME_SUBSCRIBER_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_FRAME_SUBSCRIBER_H_
|
2015-09-18 07:57:43 +00:00
|
|
|
|
2018-11-08 16:58:54 +00:00
|
|
|
#include <memory>
|
2020-04-13 23:39:26 +00:00
|
|
|
#include <string>
|
2018-05-14 15:55:39 +00:00
|
|
|
|
2015-09-18 07:57:43 +00:00
|
|
|
#include "base/callback.h"
|
2018-07-13 09:54:49 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2018-11-08 16:58:54 +00:00
|
|
|
#include "components/viz/host/client_frame_sink_video_capturer.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
2018-05-14 15:55:39 +00:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
#include "mojo/public/cpp/bindings/pending_remote.h"
|
2015-09-18 07:57:43 +00:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
2019-04-04 18:36:12 +00:00
|
|
|
namespace gfx {
|
|
|
|
class Image;
|
2021-07-02 00:51:37 +00:00
|
|
|
class Rect;
|
|
|
|
} // namespace gfx
|
2019-04-04 18:36:12 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-09-18 07:57:43 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2018-05-14 15:55:39 +00:00
|
|
|
class WebContents;
|
|
|
|
|
2018-11-08 16:58:54 +00:00
|
|
|
class FrameSubscriber : public content::WebContentsObserver,
|
|
|
|
public viz::mojom::FrameSinkVideoConsumer {
|
2015-09-18 07:57:43 +00:00
|
|
|
public:
|
2016-06-21 00:15:39 +00:00
|
|
|
using FrameCaptureCallback =
|
2019-05-29 20:02:15 +00:00
|
|
|
base::RepeatingCallback<void(const gfx::Image&, const gfx::Rect&)>;
|
2015-09-18 07:57:43 +00:00
|
|
|
|
2019-04-04 18:36:12 +00:00
|
|
|
FrameSubscriber(content::WebContents* web_contents,
|
2018-05-14 17:09:05 +00:00
|
|
|
const FrameCaptureCallback& callback,
|
|
|
|
bool only_dirty);
|
2018-06-20 19:51:36 +00:00
|
|
|
~FrameSubscriber() override;
|
2015-09-18 07:57:43 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
FrameSubscriber(const FrameSubscriber&) = delete;
|
|
|
|
FrameSubscriber& operator=(const FrameSubscriber&) = delete;
|
|
|
|
|
2015-09-18 07:57:43 +00:00
|
|
|
private:
|
2018-11-08 16:58:54 +00:00
|
|
|
void AttachToHost(content::RenderWidgetHost* host);
|
|
|
|
void DetachFromHost();
|
|
|
|
|
2021-03-04 17:27:05 +00:00
|
|
|
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
|
2018-11-08 16:58:54 +00:00
|
|
|
void RenderViewDeleted(content::RenderViewHost* host) override;
|
|
|
|
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
|
|
|
content::RenderViewHost* new_host) override;
|
|
|
|
|
|
|
|
// viz::mojom::FrameSinkVideoConsumer implementation.
|
|
|
|
void OnFrameCaptured(
|
|
|
|
base::ReadOnlySharedMemoryRegion data,
|
|
|
|
::media::mojom::VideoFrameInfoPtr info,
|
|
|
|
const gfx::Rect& content_rect,
|
2019-10-28 22:12:35 +00:00
|
|
|
mojo::PendingRemote<viz::mojom::FrameSinkVideoConsumerFrameCallbacks>
|
|
|
|
callbacks) override;
|
2018-11-08 16:58:54 +00:00
|
|
|
void OnStopped() override;
|
2020-04-13 23:39:26 +00:00
|
|
|
void OnLog(const std::string& message) override;
|
2018-11-08 16:58:54 +00:00
|
|
|
|
2018-05-14 15:55:39 +00:00
|
|
|
void Done(const gfx::Rect& damage, const SkBitmap& frame);
|
2015-09-18 07:57:43 +00:00
|
|
|
|
2019-04-08 02:35:33 +00:00
|
|
|
// Get the pixel size of render view.
|
|
|
|
gfx::Size GetRenderViewSize() const;
|
|
|
|
|
2015-09-18 07:57:43 +00:00
|
|
|
FrameCaptureCallback callback_;
|
2018-05-14 17:09:05 +00:00
|
|
|
bool only_dirty_;
|
2016-02-16 02:44:10 +00:00
|
|
|
|
2018-11-08 16:58:54 +00:00
|
|
|
content::RenderWidgetHost* host_;
|
|
|
|
std::unique_ptr<viz::ClientFrameSinkVideoCapturer> video_capturer_;
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_{this};
|
2015-09-18 07:57:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2015-09-18 07:57:43 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_FRAME_SUBSCRIBER_H_
|