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_
|
|
|
|
|
|
|
|
#include "base/callback.h"
|
2016-02-16 02:44:10 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2016-02-18 00:15:00 +00:00
|
|
|
#include "content/public/browser/render_widget_host_view.h"
|
2018-04-18 00:45:15 +00:00
|
|
|
#include "mojo/public/cpp/bindings/binding.h"
|
|
|
|
#include "services/viz/privileged/interfaces/compositing/frame_sink_video_capture.mojom.h"
|
2016-02-18 00:15:00 +00:00
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
2015-09-18 07:57:43 +00:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2018-04-18 00:45:15 +00:00
|
|
|
class FrameSubscriber : public viz::mojom::FrameSinkVideoConsumer {
|
2015-09-18 07:57:43 +00:00
|
|
|
public:
|
2016-06-21 00:15:39 +00:00
|
|
|
using FrameCaptureCallback =
|
2016-06-26 02:46:40 +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,
|
2016-02-18 00:15:00 +00:00
|
|
|
content::RenderWidgetHostView* view,
|
2018-04-18 00:45:15 +00:00
|
|
|
const FrameCaptureCallback& callback);
|
2018-04-17 23:37:22 +00:00
|
|
|
~FrameSubscriber() override;
|
2015-09-18 07:57:43 +00:00
|
|
|
|
|
|
|
private:
|
2018-04-18 00:45:15 +00:00
|
|
|
void OnFrameCaptured(
|
|
|
|
mojo::ScopedSharedBufferHandle buffer,
|
|
|
|
uint32_t buffer_size,
|
|
|
|
::media::mojom::VideoFrameInfoPtr info,
|
|
|
|
const gfx::Rect& update_rect,
|
|
|
|
const gfx::Rect& content_rect,
|
|
|
|
viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr callbacks) override;
|
|
|
|
void OnTargetLost(const viz::FrameSinkId& frame_sink_id) override;
|
|
|
|
void OnStopped() override;
|
|
|
|
viz::mojom::FrameSinkVideoCapturerPtr CreateVideoCapturer();
|
2015-09-18 07:57:43 +00:00
|
|
|
|
|
|
|
v8::Isolate* isolate_;
|
2016-02-18 00:15:00 +00:00
|
|
|
content::RenderWidgetHostView* view_;
|
2015-09-18 07:57:43 +00:00
|
|
|
FrameCaptureCallback callback_;
|
2016-02-16 02:44:10 +00:00
|
|
|
|
2018-04-18 00:45:15 +00:00
|
|
|
SkBitmap frame_;
|
|
|
|
|
|
|
|
// This object keeps the shared memory that backs |frame_| mapped.
|
|
|
|
mojo::ScopedSharedBufferMapping shared_memory_mapping_;
|
|
|
|
|
|
|
|
// This object prevents FrameSinkVideoCapturer from recycling the shared
|
|
|
|
// memory that backs |frame_|.
|
|
|
|
viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr shared_memory_releaser_;
|
|
|
|
|
|
|
|
viz::mojom::FrameSinkVideoCapturerPtr video_capturer_;
|
|
|
|
mojo::Binding<viz::mojom::FrameSinkVideoConsumer> video_consumer_binding_;
|
2017-04-13 10:21:30 +00:00
|
|
|
|
2016-02-16 02:44:10 +00:00
|
|
|
base::WeakPtrFactory<FrameSubscriber> weak_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_
|