Commit d4121888 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Reland "Onion soup canvas_capture_handler.cc/h"

This is a reland of 2f2d5d96

This revised CL fixes the missing include of
third_party/blink/renderer/platform/scheduler/public/thread.h ,
originally missing.

TBR=haraken@chromium.org

Original change's description:
> Onion soup canvas_capture_handler.cc/h
>
> This is a first step to OnionSoup content/renderer/media_capture_from_element/.
>
> It summary, this CL
>
> - Moves content/renderer/media_capture_from_element/canvas_capture_handler* to
>   third_party/blink/renderer/modules/mediacapturefromelement/.
> - Adapts the existing code for Blink restrictions, eg use WTF::Bind
>   instead of base::Bind.
> - Removes the code that used to plumb the creation of
>   content::CanvasCaptureHandler instances through blink::Platform, and make
>   blink::HTMLCanvasElementCapture to create it (see the second TODO
>   below).
>
> To be done (follow up CLs):
>
> - migrate some remaining base::Bind{Once,Repeating} uses to the
>   respective Blink/WTF alternatives. This is now blocked on having
>   a CrossThreadBindOnce implementation available (see
>   crrev.com/c/1597228).
> - eliminate blink::WebCanvasCaptureHandler
>   third_party/blink/public/platform/web_canvas_capture_handler.h.
>   Note that this is not done now because there is code in
>   third_party/blink/renderer/core/html/canvas/canvas_draw_listener.cc|h
>   that use blink::WebCanvasCaptureHandler, and can not use
>   blink::CanvasCaptureHandler directly, because core/ can not depend on
>   modules/.
>
> R=kentaro@chromium.org, guidou@chromium.org
>
> BUG=787261
>
> Change-Id: Id2dc1f6441e2568c8420f0849a2cb5f87f9a6d75
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1600898
> Reviewed-by: Kentaro Hara <haraken@chromium.org>
> Reviewed-by: Guido Urdaneta <guidou@chromium.org>
> Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
> Cr-Commit-Position: refs/heads/master@{#658376}

Bug: 787261
Change-Id: I9b5829d82c1b5420a5fc8c4cbb33505284471912
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1605560
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarAntonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#658521}
parent 253d362f
...@@ -357,8 +357,6 @@ target(link_target_type, "renderer") { ...@@ -357,8 +357,6 @@ target(link_target_type, "renderer") {
"media/webrtc_local_audio_source_provider.h", "media/webrtc_local_audio_source_provider.h",
"media/webrtc_logging.cc", "media/webrtc_logging.cc",
"media/webrtc_logging.h", "media/webrtc_logging.h",
"media_capture_from_element/canvas_capture_handler.cc",
"media_capture_from_element/canvas_capture_handler.h",
"media_capture_from_element/html_audio_element_capturer_source.cc", "media_capture_from_element/html_audio_element_capturer_source.cc",
"media_capture_from_element/html_audio_element_capturer_source.h", "media_capture_from_element/html_audio_element_capturer_source.h",
"media_capture_from_element/html_video_element_capturer_source.cc", "media_capture_from_element/html_video_element_capturer_source.cc",
......
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
#include "content/renderer/media/audio_decoder.h" #include "content/renderer/media/audio_decoder.h"
#include "content/renderer/media/renderer_webaudiodevice_impl.h" #include "content/renderer/media/renderer_webaudiodevice_impl.h"
#include "content/renderer/media/webrtc/transmission_encoding_info_handler.h" #include "content/renderer/media/webrtc/transmission_encoding_info_handler.h"
#include "content/renderer/media_capture_from_element/canvas_capture_handler.h"
#include "content/renderer/media_capture_from_element/html_audio_element_capturer_source.h" #include "content/renderer/media_capture_from_element/html_audio_element_capturer_source.h"
#include "content/renderer/media_capture_from_element/html_video_element_capturer_source.h" #include "content/renderer/media_capture_from_element/html_video_element_capturer_source.h"
#include "content/renderer/media_recorder/media_recorder_handler.h" #include "content/renderer/media_recorder/media_recorder_handler.h"
...@@ -129,7 +128,6 @@ using blink::Platform; ...@@ -129,7 +128,6 @@ using blink::Platform;
using blink::WebAudioDevice; using blink::WebAudioDevice;
using blink::WebAudioLatencyHint; using blink::WebAudioLatencyHint;
using blink::WebBlobRegistry; using blink::WebBlobRegistry;
using blink::WebCanvasCaptureHandler;
using blink::WebDatabaseObserver; using blink::WebDatabaseObserver;
using blink::WebMediaPlayer; using blink::WebMediaPlayer;
using blink::WebMediaRecorderHandler; using blink::WebMediaRecorderHandler;
...@@ -759,17 +757,6 @@ RendererBlinkPlatformImpl::CreateWebRtcAsyncResolverFactory() { ...@@ -759,17 +757,6 @@ RendererBlinkPlatformImpl::CreateWebRtcAsyncResolverFactory() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
std::unique_ptr<WebCanvasCaptureHandler>
RendererBlinkPlatformImpl::CreateCanvasCaptureHandler(
const WebSize& size,
double frame_rate,
WebMediaStreamTrack* track) {
return CanvasCaptureHandler::CreateCanvasCaptureHandler(
size, frame_rate, RenderThread::Get()->GetIOTaskRunner(), track);
}
//------------------------------------------------------------------------------
void RendererBlinkPlatformImpl::CreateHTMLVideoElementCapturer( void RendererBlinkPlatformImpl::CreateHTMLVideoElementCapturer(
WebMediaStream* web_media_stream, WebMediaStream* web_media_stream,
WebMediaPlayer* web_media_player, WebMediaPlayer* web_media_player,
......
...@@ -39,7 +39,6 @@ namespace blink { ...@@ -39,7 +39,6 @@ namespace blink {
namespace scheduler { namespace scheduler {
class WebThreadScheduler; class WebThreadScheduler;
} }
class WebCanvasCaptureHandler;
class WebGraphicsContext3DProvider; class WebGraphicsContext3DProvider;
class WebMediaPlayer; class WebMediaPlayer;
class WebMediaRecorderHandler; class WebMediaRecorderHandler;
...@@ -160,10 +159,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { ...@@ -160,10 +159,6 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
blink::WebLocalFrame* frame) override; blink::WebLocalFrame* frame) override;
std::unique_ptr<webrtc::AsyncResolverFactory> std::unique_ptr<webrtc::AsyncResolverFactory>
CreateWebRtcAsyncResolverFactory() override; CreateWebRtcAsyncResolverFactory() override;
std::unique_ptr<blink::WebCanvasCaptureHandler> CreateCanvasCaptureHandler(
const blink::WebSize& size,
double frame_rate,
blink::WebMediaStreamTrack* track) override;
void CreateHTMLVideoElementCapturer( void CreateHTMLVideoElementCapturer(
blink::WebMediaStream* web_media_stream, blink::WebMediaStream* web_media_stream,
blink::WebMediaPlayer* web_media_player, blink::WebMediaPlayer* web_media_player,
......
...@@ -1865,7 +1865,6 @@ test("content_unittests") { ...@@ -1865,7 +1865,6 @@ test("content_unittests") {
"../renderer/media/webrtc/webrtc_set_description_observer_unittest.cc", "../renderer/media/webrtc/webrtc_set_description_observer_unittest.cc",
"../renderer/media/webrtc/webrtc_video_track_source_unittest.cc", "../renderer/media/webrtc/webrtc_video_track_source_unittest.cc",
"../renderer/media/webrtc_local_audio_source_provider_unittest.cc", "../renderer/media/webrtc_local_audio_source_provider_unittest.cc",
"../renderer/media_capture_from_element/canvas_capture_handler_unittest.cc",
"../renderer/media_capture_from_element/html_audio_element_capturer_source_unittest.cc", "../renderer/media_capture_from_element/html_audio_element_capturer_source_unittest.cc",
"../renderer/media_capture_from_element/html_video_element_capturer_source_unittest.cc", "../renderer/media_capture_from_element/html_video_element_capturer_source_unittest.cc",
"../renderer/media_recorder/audio_track_recorder_unittest.cc", "../renderer/media_recorder/audio_track_recorder_unittest.cc",
......
...@@ -105,7 +105,6 @@ struct ThreadCreationParams; ...@@ -105,7 +105,6 @@ struct ThreadCreationParams;
class WebAudioBus; class WebAudioBus;
class WebAudioLatencyHint; class WebAudioLatencyHint;
class WebBlobRegistry; class WebBlobRegistry;
class WebCanvasCaptureHandler;
class WebCookieJar; class WebCookieJar;
class WebCrypto; class WebCrypto;
class WebDatabaseObserver; class WebDatabaseObserver;
...@@ -117,7 +116,6 @@ class WebMediaPlayer; ...@@ -117,7 +116,6 @@ class WebMediaPlayer;
class WebMediaRecorderHandler; class WebMediaRecorderHandler;
class WebMediaStream; class WebMediaStream;
class WebMediaStreamCenter; class WebMediaStreamCenter;
class WebMediaStreamTrack;
class WebPrescientNetworking; class WebPrescientNetworking;
class WebPublicSuffixList; class WebPublicSuffixList;
class WebPushProvider; class WebPushProvider;
...@@ -134,7 +132,6 @@ class WebTransmissionEncodingInfoHandler; ...@@ -134,7 +132,6 @@ class WebTransmissionEncodingInfoHandler;
class WebURLLoaderMockFactory; class WebURLLoaderMockFactory;
class WebURLResponse; class WebURLResponse;
class WebURLResponse; class WebURLResponse;
struct WebSize;
namespace scheduler { namespace scheduler {
class WebThreadScheduler; class WebThreadScheduler;
...@@ -640,10 +637,6 @@ class BLINK_PLATFORM_EXPORT Platform { ...@@ -640,10 +637,6 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual std::unique_ptr<webrtc::AsyncResolverFactory> virtual std::unique_ptr<webrtc::AsyncResolverFactory>
CreateWebRtcAsyncResolverFactory(); CreateWebRtcAsyncResolverFactory();
// Creates a WebCanvasCaptureHandler to capture Canvas output.
virtual std::unique_ptr<WebCanvasCaptureHandler>
CreateCanvasCaptureHandler(const WebSize&, double, WebMediaStreamTrack*);
// Fills in the WebMediaStream to capture from the WebMediaPlayer identified // Fills in the WebMediaStream to capture from the WebMediaPlayer identified
// by the second parameter. // by the second parameter.
virtual void CreateHTMLVideoElementCapturer( virtual void CreateHTMLVideoElementCapturer(
......
...@@ -323,6 +323,7 @@ jumbo_source_set("unit_tests") { ...@@ -323,6 +323,7 @@ jumbo_source_set("unit_tests") {
"media_controls/media_controls_impl_test.cc", "media_controls/media_controls_impl_test.cc",
"media_controls/media_controls_orientation_lock_delegate_test.cc", "media_controls/media_controls_orientation_lock_delegate_test.cc",
"media_controls/media_controls_rotate_to_fullscreen_delegate_test.cc", "media_controls/media_controls_rotate_to_fullscreen_delegate_test.cc",
"mediacapturefromelement/canvas_capture_handler_unittest.cc",
"mediastream/media_constraints_test.cc", "mediastream/media_constraints_test.cc",
"mediastream/media_devices_test.cc", "mediastream/media_devices_test.cc",
"mediastream/media_stream_video_capturer_source_test.cc", "mediastream/media_stream_video_capturer_source_test.cc",
......
...@@ -8,6 +8,8 @@ blink_modules_sources("mediacapturefromelement") { ...@@ -8,6 +8,8 @@ blink_modules_sources("mediacapturefromelement") {
sources = [ sources = [
"auto_canvas_draw_listener.cc", "auto_canvas_draw_listener.cc",
"auto_canvas_draw_listener.h", "auto_canvas_draw_listener.h",
"canvas_capture_handler.cc",
"canvas_capture_handler.h",
"canvas_capture_media_stream_track.cc", "canvas_capture_media_stream_track.cc",
"canvas_capture_media_stream_track.h", "canvas_capture_media_stream_track.h",
"html_canvas_element_capture.cc", "html_canvas_element_capture.cc",
...@@ -19,4 +21,11 @@ blink_modules_sources("mediacapturefromelement") { ...@@ -19,4 +21,11 @@ blink_modules_sources("mediacapturefromelement") {
"timed_canvas_draw_listener.cc", "timed_canvas_draw_listener.cc",
"timed_canvas_draw_listener.h", "timed_canvas_draw_listener.h",
] ]
deps = [
"//components/viz/common",
"//media",
"//skia",
"//third_party/libyuv",
]
} }
...@@ -3,4 +3,17 @@ include_rules = [ ...@@ -3,4 +3,17 @@ include_rules = [
"+third_party/blink/renderer/modules/encryptedmedia", "+third_party/blink/renderer/modules/encryptedmedia",
"+third_party/blink/renderer/modules/mediacapturefromelement", "+third_party/blink/renderer/modules/mediacapturefromelement",
"+third_party/blink/renderer/modules/mediastream", "+third_party/blink/renderer/modules/mediastream",
"+third_party/blink/renderer/modules/modules_export.h",
"+components/viz/common",
"+media/base",
"+media/capture",
"+third_party/libyuv",
"+ui/gfx/color_space.h",
] ]
specific_include_rules = {
"canvas_capture_handler_unittest\.cc" : [
"+base/run_loop.h",
],
}
...@@ -2,16 +2,14 @@ ...@@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/media_capture_from_element/canvas_capture_handler.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_handler.h"
#include <utility> #include <utility>
#include "base/base64.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/viz/common/gl_helper.h" #include "components/viz/common/gl_helper.h"
#include "media/base/limits.h" #include "media/base/limits.h"
#include "third_party/blink/public/platform/modules/mediastream/webrtc_uma_histograms.h" #include "third_party/blink/public/platform/modules/mediastream/webrtc_uma_histograms.h"
...@@ -22,6 +20,8 @@ ...@@ -22,6 +20,8 @@
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_capturer_source.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_track.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
#include "third_party/libyuv/include/libyuv.h" #include "third_party/libyuv/include/libyuv.h"
#include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrBackendSurface.h"
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
using media::VideoFrame; using media::VideoFrame;
namespace content { namespace blink {
namespace { namespace {
...@@ -64,9 +64,9 @@ class VideoCapturerSource : public media::VideoCapturerSource { ...@@ -64,9 +64,9 @@ class VideoCapturerSource : public media::VideoCapturerSource {
media::VideoCaptureFormats GetPreferredFormats() override { media::VideoCaptureFormats GetPreferredFormats() override {
DCHECK_CALLED_ON_VALID_THREAD(main_render_thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(main_render_thread_checker_);
media::VideoCaptureFormats formats; media::VideoCaptureFormats formats;
formats.push_back(media::VideoCaptureFormat(size_, frame_rate_, formats.push_back(media::VideoCaptureFormat(gfx::Size(size_), frame_rate_,
media::PIXEL_FORMAT_I420)); media::PIXEL_FORMAT_I420));
formats.push_back(media::VideoCaptureFormat(size_, frame_rate_, formats.push_back(media::VideoCaptureFormat(gfx::Size(size_), frame_rate_,
media::PIXEL_FORMAT_I420A)); media::PIXEL_FORMAT_I420A));
return formats; return formats;
} }
...@@ -185,7 +185,8 @@ void CanvasCaptureHandler::SendNewFrame( ...@@ -185,7 +185,8 @@ void CanvasCaptureHandler::SendNewFrame(
SendFrame(ConvertToYUVFrame(image->isOpaque(), false, SendFrame(ConvertToYUVFrame(image->isOpaque(), false,
static_cast<const uint8_t*>(pixmap.addr(0, 0)), static_cast<const uint8_t*>(pixmap.addr(0, 0)),
gfx::Size(pixmap.width(), pixmap.height()), gfx::Size(pixmap.width(), pixmap.height()),
pixmap.rowBytes(), pixmap.colorType()), static_cast<int>(pixmap.rowBytes()),
pixmap.colorType()),
timestamp, GetImageYUVColorSpace(image)); timestamp, GetImageYUVColorSpace(image));
return; return;
} }
...@@ -307,9 +308,9 @@ void CanvasCaptureHandler::ReadARGBPixelsAsync( ...@@ -307,9 +308,9 @@ void CanvasCaptureHandler::ReadARGBPixelsAsync(
context_provider->GetGLHelper()->ReadbackTextureAsync( context_provider->GetGLHelper()->ReadbackTextureAsync(
texture_info.fID, image_size, texture_info.fID, image_size,
temp_argb_frame->visible_data(VideoFrame::kARGBPlane), kN32_SkColorType, temp_argb_frame->visible_data(VideoFrame::kARGBPlane), kN32_SkColorType,
base::BindOnce(&CanvasCaptureHandler::OnARGBPixelsReadAsync, WTF::Bind(&CanvasCaptureHandler::OnARGBPixelsReadAsync,
weak_ptr_factory_.GetWeakPtr(), image, temp_argb_frame, weak_ptr_factory_.GetWeakPtr(), image, temp_argb_frame,
timestamp, surface_origin != kTopLeft_GrSurfaceOrigin)); timestamp, surface_origin != kTopLeft_GrSurfaceOrigin));
} }
void CanvasCaptureHandler::ReadYUVPixelsAsync( void CanvasCaptureHandler::ReadYUVPixelsAsync(
...@@ -346,9 +347,9 @@ void CanvasCaptureHandler::ReadYUVPixelsAsync( ...@@ -346,9 +347,9 @@ void CanvasCaptureHandler::ReadYUVPixelsAsync(
output_frame->visible_data(media::VideoFrame::kUPlane), output_frame->visible_data(media::VideoFrame::kUPlane),
output_frame->stride(media::VideoFrame::kVPlane), output_frame->stride(media::VideoFrame::kVPlane),
output_frame->visible_data(media::VideoFrame::kVPlane), gfx::Point(0, 0), output_frame->visible_data(media::VideoFrame::kVPlane), gfx::Point(0, 0),
base::BindOnce(&CanvasCaptureHandler::OnYUVPixelsReadAsync, WTF::Bind(&CanvasCaptureHandler::OnYUVPixelsReadAsync,
weak_ptr_factory_.GetWeakPtr(), image, output_frame, weak_ptr_factory_.GetWeakPtr(), image, output_frame,
timestamp)); timestamp));
} }
void CanvasCaptureHandler::OnARGBPixelsReadAsync( void CanvasCaptureHandler::OnARGBPixelsReadAsync(
...@@ -479,9 +480,10 @@ void CanvasCaptureHandler::SendFrame(scoped_refptr<VideoFrame> video_frame, ...@@ -479,9 +480,10 @@ void CanvasCaptureHandler::SendFrame(scoped_refptr<VideoFrame> video_frame,
void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack( void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack(
std::unique_ptr<media::VideoCapturerSource> source, std::unique_ptr<media::VideoCapturerSource> source,
blink::WebMediaStreamTrack* web_track) { blink::WebMediaStreamTrack* web_track) {
std::string str_track_id; Vector<char> base64_track_id;
base::Base64Encode(base::RandBytesAsString(64), &str_track_id); Base64Encode(base::RandBytesAsString(64).c_str(), base64_track_id);
const blink::WebString track_id = blink::WebString::FromASCII(str_track_id); const auto track_id =
WebString::FromUTF8(base64_track_id.data(), base64_track_id.size());
media::VideoCaptureFormats preferred_formats = source->GetPreferredFormats(); media::VideoCaptureFormats preferred_formats = source->GetPreferredFormats();
blink::MediaStreamVideoSource* media_stream_source = blink::MediaStreamVideoSource* media_stream_source =
new blink::MediaStreamVideoCapturerSource( new blink::MediaStreamVideoCapturerSource(
...@@ -502,4 +504,4 @@ void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack( ...@@ -502,4 +504,4 @@ void CanvasCaptureHandler::AddVideoCapturerSourceToVideoTrack(
true)); true));
} }
} // namespace content } // namespace blink
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_CAPTURE_FROM_ELEMENT_CANVAS_CAPTURE_HANDLER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIACAPTUREFROMELEMENT_CANVAS_CAPTURE_HANDLER_H_
#define CONTENT_RENDERER_MEDIA_CAPTURE_FROM_ELEMENT_CANVAS_CAPTURE_HANDLER_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIACAPTUREFROMELEMENT_CANVAS_CAPTURE_HANDLER_H_
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
...@@ -11,21 +11,21 @@ ...@@ -11,21 +11,21 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "media/base/video_frame_pool.h" #include "media/base/video_frame_pool.h"
#include "media/capture/video_capturer_source.h" #include "media/capture/video_capturer_source.h"
#include "third_party/blink/public/platform/web_canvas_capture_handler.h" #include "third_party/blink/public/platform/web_canvas_capture_handler.h"
#include "third_party/blink/public/platform/web_media_stream_track.h" #include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/public/platform/web_size.h" #include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkImageInfo.h"
class SkImage; class SkImage;
namespace content { namespace blink {
// CanvasCaptureHandler acts as the link between Blink side HTMLCanvasElement // CanvasCaptureHandler acts as the link between Blink side HTMLCanvasElement
// and Chrome side VideoCapturerSource. It is responsible for handling // and Chrome side VideoCapturerSource. It is responsible for handling
...@@ -36,7 +36,7 @@ namespace content { ...@@ -36,7 +36,7 @@ namespace content {
// All methods are called on the same thread as construction and destruction, // All methods are called on the same thread as construction and destruction,
// i.e. the Main Render thread. Note that a CanvasCaptureHandlerDelegate is // i.e. the Main Render thread. Note that a CanvasCaptureHandlerDelegate is
// used to send back frames to |io_task_runner_|, i.e. IO thread. // used to send back frames to |io_task_runner_|, i.e. IO thread.
class CONTENT_EXPORT CanvasCaptureHandler final class MODULES_EXPORT CanvasCaptureHandler final
: public blink::WebCanvasCaptureHandler { : public blink::WebCanvasCaptureHandler {
public: public:
~CanvasCaptureHandler() override; ~CanvasCaptureHandler() override;
...@@ -127,6 +127,6 @@ class CONTENT_EXPORT CanvasCaptureHandler final ...@@ -127,6 +127,6 @@ class CONTENT_EXPORT CanvasCaptureHandler final
DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandler); DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandler);
}; };
} // namespace content } // namespace blink
#endif // CONTENT_RENDERER_MEDIA_CAPTURE_FROM_ELEMENT_CANVAS_CAPTURE_HANDLER_H_ #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIACAPTUREFROMELEMENT_CANVAS_CAPTURE_HANDLER_H_
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/media_capture_from_element/canvas_capture_handler.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_handler.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_task_environment.h"
#include "content/child/child_process.h"
#include "media/base/limits.h" #include "media/base/limits.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -17,6 +15,7 @@ ...@@ -17,6 +15,7 @@
#include "third_party/blink/public/platform/web_size.h" #include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_capturer_source.h" #include "third_party/blink/public/web/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/public/web/web_heap.h" #include "third_party/blink/public/web/web_heap.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkRefCnt.h"
...@@ -27,7 +26,7 @@ using ::testing::SaveArg; ...@@ -27,7 +26,7 @@ using ::testing::SaveArg;
using ::testing::Test; using ::testing::Test;
using ::testing::TestWithParam; using ::testing::TestWithParam;
namespace content { namespace blink {
namespace { namespace {
...@@ -49,9 +48,7 @@ ACTION_P(RunClosure, closure) { ...@@ -49,9 +48,7 @@ ACTION_P(RunClosure, closure) {
class CanvasCaptureHandlerTest class CanvasCaptureHandlerTest
: public TestWithParam<testing::tuple<bool, int, int>> { : public TestWithParam<testing::tuple<bool, int, int>> {
public: public:
CanvasCaptureHandlerTest() CanvasCaptureHandlerTest() = default;
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
void SetUp() override { void SetUp() override {
canvas_capture_handler_ = CanvasCaptureHandler::CreateCanvasCaptureHandler( canvas_capture_handler_ = CanvasCaptureHandler::CreateCanvasCaptureHandler(
...@@ -131,11 +128,7 @@ class CanvasCaptureHandlerTest ...@@ -131,11 +128,7 @@ class CanvasCaptureHandlerTest
return ms_source->GetSourceForTesting(); return ms_source->GetSourceForTesting();
} }
// A ChildProcess is needed to fool the Tracks and Sources believing they are ScopedTestingPlatformSupport<IOTaskRunnerTestingPlatformSupport> platform_;
// on the right threads. A ScopedTaskEnvironment must be instantiated before
// ChildProcess to prevent it from leaking a ThreadPool.
base::test::ScopedTaskEnvironment scoped_task_environment_;
ChildProcess child_process_;
private: private:
DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandlerTest); DISALLOW_COPY_AND_ASSIGN(CanvasCaptureHandlerTest);
...@@ -190,7 +183,8 @@ TEST_P(CanvasCaptureHandlerTest, GetFormatsStartAndStop) { ...@@ -190,7 +183,8 @@ TEST_P(CanvasCaptureHandlerTest, GetFormatsStartAndStop) {
params, params,
base::BindRepeating(&CanvasCaptureHandlerTest::OnDeliverFrame, base::BindRepeating(&CanvasCaptureHandlerTest::OnDeliverFrame,
base::Unretained(this)), base::Unretained(this)),
base::Bind(&CanvasCaptureHandlerTest::OnRunning, base::Unretained(this))); base::BindRepeating(&CanvasCaptureHandlerTest::OnRunning,
base::Unretained(this)));
canvas_capture_handler_->SendNewFrame( canvas_capture_handler_->SendNewFrame(
GenerateTestImage(testing::get<0>(GetParam()), GenerateTestImage(testing::get<0>(GetParam()),
testing::get<1>(GetParam()), testing::get<1>(GetParam()),
...@@ -247,4 +241,4 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -247,4 +241,4 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(kTestCanvasCaptureFrameEvenSize, ::testing::Values(kTestCanvasCaptureFrameEvenSize,
kTestCanvasCaptureFrameOddSize))); kTestCanvasCaptureFrameOddSize)));
} // namespace content } // namespace blink
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include <memory> #include <memory>
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_canvas_capture_handler.h"
#include "third_party/blink/public/platform/web_media_stream.h" #include "third_party/blink/public/platform/web_media_stream.h"
#include "third_party/blink/public/platform/web_media_stream_track.h" #include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h" #include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_handler.h"
#include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_media_stream_track.h" #include "third_party/blink/renderer/modules/mediacapturefromelement/canvas_capture_media_stream_track.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream.h" #include "third_party/blink/renderer/modules/mediastream/media_stream.h"
...@@ -57,11 +57,12 @@ MediaStream* HTMLCanvasElementCapture::captureStream( ...@@ -57,11 +57,12 @@ MediaStream* HTMLCanvasElementCapture::captureStream(
const WebSize size(element.width(), element.height()); const WebSize size(element.width(), element.height());
std::unique_ptr<WebCanvasCaptureHandler> handler; std::unique_ptr<WebCanvasCaptureHandler> handler;
if (given_frame_rate) { if (given_frame_rate) {
handler = Platform::Current()->CreateCanvasCaptureHandler(size, frame_rate, handler = CanvasCaptureHandler::CreateCanvasCaptureHandler(
&track); size, frame_rate, Platform::Current()->GetIOTaskRunner(), &track);
} else { } else {
handler = Platform::Current()->CreateCanvasCaptureHandler( handler = CanvasCaptureHandler::CreateCanvasCaptureHandler(
size, kDefaultFrameRate, &track); size, kDefaultFrameRate, Platform::Current()->GetIOTaskRunner(),
&track);
} }
if (!handler) { if (!handler) {
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "third_party/blink/renderer/modules/mediastream/mock_mojo_media_stream_dispatcher_host.h" #include "third_party/blink/renderer/modules/mediastream/mock_mojo_media_stream_dispatcher_host.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h" #include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h" #include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h" #include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "third_party/blink/renderer/platform/wtf/functional.h" #include "third_party/blink/renderer/platform/wtf/functional.h"
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/platform/interface_provider.h" #include "third_party/blink/public/platform/interface_provider.h"
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h" #include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
#include "third_party/blink/public/platform/web_canvas_capture_handler.h"
#include "third_party/blink/public/platform/web_graphics_context_3d_provider.h" #include "third_party/blink/public/platform/web_graphics_context_3d_provider.h"
#include "third_party/blink/public/platform/web_media_recorder_handler.h" #include "third_party/blink/public/platform/web_media_recorder_handler.h"
#include "third_party/blink/public/platform/web_media_stream_center.h" #include "third_party/blink/public/platform/web_media_stream_center.h"
...@@ -334,13 +333,6 @@ std::unique_ptr<WebMediaStreamCenter> Platform::CreateMediaStreamCenter() { ...@@ -334,13 +333,6 @@ std::unique_ptr<WebMediaStreamCenter> Platform::CreateMediaStreamCenter() {
return nullptr; return nullptr;
} }
std::unique_ptr<WebCanvasCaptureHandler> Platform::CreateCanvasCaptureHandler(
const WebSize&,
double,
WebMediaStreamTrack*) {
return nullptr;
}
std::unique_ptr<webrtc::RtpCapabilities> Platform::GetRtpSenderCapabilities( std::unique_ptr<webrtc::RtpCapabilities> Platform::GetRtpSenderCapabilities(
const WebString& kind) { const WebString& kind) {
return nullptr; return nullptr;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h" #include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
namespace blink { namespace blink {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h" #include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
namespace base { namespace base {
class SingleThreadTaskRunner; class SingleThreadTaskRunner;
...@@ -15,8 +16,6 @@ class SingleThreadTaskRunner; ...@@ -15,8 +16,6 @@ class SingleThreadTaskRunner;
namespace blink { namespace blink {
class Thread;
class IOTaskRunnerTestingPlatformSupport : public TestingPlatformSupport { class IOTaskRunnerTestingPlatformSupport : public TestingPlatformSupport {
public: public:
IOTaskRunnerTestingPlatformSupport(); IOTaskRunnerTestingPlatformSupport();
......
...@@ -184,6 +184,7 @@ _CONFIG = [ ...@@ -184,6 +184,7 @@ _CONFIG = [
'base::RandGenerator', 'base::RandGenerator',
'base::RandDouble', 'base::RandDouble',
'base::RandBytes', 'base::RandBytes',
'base::RandBytesAsString',
# Feature list checking. # Feature list checking.
'base::Feature.*', 'base::Feature.*',
...@@ -548,6 +549,15 @@ _CONFIG = [ ...@@ -548,6 +549,15 @@ _CONFIG = [
'media::.+', 'media::.+',
] ]
}, },
{
'paths': [
'third_party/blink/renderer/modules/mediacapturefromelement/',
],
'allowed': [
'media::.+',
'libyuv::.+',
]
},
{ {
'paths': [ 'paths': [
'third_party/blink/renderer/modules/mediastream/', 'third_party/blink/renderer/modules/mediastream/',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment