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.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
|
|
|
|
#define ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
|
|
|
|
|
2018-11-08 16:58:54 +00:00
|
|
|
#include <memory>
|
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"
|
2015-09-18 07:57:43 +00:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
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 =
|
2018-06-19 17:49:44 +00:00
|
|
|
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
|
2015-09-18 07:57:43 +00:00
|
|
|
|
|
|
|
FrameSubscriber(v8::Isolate* isolate,
|
2018-05-14 15:55:39 +00:00
|
|
|
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
|
|
|
|
|
|
|
private:
|
2018-11-08 16:58:54 +00:00
|
|
|
void AttachToHost(content::RenderWidgetHost* host);
|
|
|
|
void DetachFromHost();
|
|
|
|
|
|
|
|
void RenderViewCreated(content::RenderViewHost* host) override;
|
|
|
|
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,
|
|
|
|
viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr callbacks) override;
|
|
|
|
void OnStopped() override;
|
|
|
|
|
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
|
|
|
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
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_;
|
|
|
|
|
2018-07-13 09:54:49 +00:00
|
|
|
base::WeakPtrFactory<FrameSubscriber> weak_ptr_factory_;
|
|
|
|
|
2015-09-18 07:57:43 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(FrameSubscriber);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_API_FRAME_SUBSCRIBER_H_
|