Commit 298ef248 authored by CJ DiMeglio's avatar CJ DiMeglio Committed by Commit Bot

Allows cc::Surfaces for video to work with software compositing.

This CL makes software compositing for the cc::Surface for video case
by making VideoFrameSubmitter a SharedBitmapReporter. Before we would
see blue boxes instead of the video frames. Now we see video frames as
they should be.

Bug: 807840
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I486456f4d4e96b05317089557084242eeda04455
Reviewed-on: https://chromium-review.googlesource.com/1057962Reviewed-by: default avatarJustin Novosad <junov@chromium.org>
Reviewed-by: default avatarFrank Liberato <liberato@chromium.org>
Commit-Queue: CJ DiMeglio <lethalantidote@chromium.org>
Cr-Commit-Position: refs/heads/master@{#559267}
parent 6ec60707
......@@ -276,8 +276,7 @@ blink::WebMediaPlayer* MediaFactory::CreateMediaPlayer(
video_frame_compositor_task_runner;
std::unique_ptr<blink::WebVideoFrameSubmitter> submitter;
bool use_surface_layer_for_video =
base::FeatureList::IsEnabled(media::kUseSurfaceLayerForVideo) &&
!RenderThreadImpl::current()->IsGpuCompositingDisabled();
base::FeatureList::IsEnabled(media::kUseSurfaceLayerForVideo);
if (use_surface_layer_for_video) {
// TODO(lethalantidote): Use a separate task_runner. https://crbug/753605.
video_frame_compositor_task_runner =
......
......@@ -28,15 +28,13 @@ VideoFrameResourceProvider::~VideoFrameResourceProvider() {
}
void VideoFrameResourceProvider::Initialize(
viz::ContextProvider* media_context_provider) {
viz::ContextProvider* media_context_provider,
viz::SharedBitmapReporter* shared_bitmap_reporter) {
resource_provider_ = std::make_unique<cc::LayerTreeResourceProvider>(
media_context_provider, true, settings_.resource_settings);
// TODO(kylechar): VideoResourceUpdater needs something it can notify about
// SharedBitmaps that isn't a LayerTreeFrameSink. https://crbug.com/730660#c88
resource_updater_ = std::make_unique<cc::VideoResourceUpdater>(
media_context_provider, nullptr, resource_provider_.get(),
media_context_provider, shared_bitmap_reporter, resource_provider_.get(),
settings_.use_stream_video_draw_quad,
settings_.resource_settings.use_gpu_memory_buffer_resources,
settings_.resource_settings.use_r16_texture);
......
......@@ -9,6 +9,7 @@
#include "cc/resources/layer_tree_resource_provider.h"
#include "cc/resources/video_resource_updater.h"
#include "cc/trees/layer_tree_settings.h"
#include "components/viz/common/resources/shared_bitmap_reporter.h"
#include "media/base/video_frame.h"
#include "third_party/blink/public/platform/web_video_frame_submitter.h"
#include "third_party/blink/renderer/platform/platform_export.h"
......@@ -30,7 +31,7 @@ class PLATFORM_EXPORT VideoFrameResourceProvider {
virtual ~VideoFrameResourceProvider();
virtual void Initialize(viz::ContextProvider*);
virtual void Initialize(viz::ContextProvider*, viz::SharedBitmapReporter*);
virtual void AppendQuads(viz::RenderPass*,
scoped_refptr<media::VideoFrame>,
media::VideoRotation);
......
......@@ -21,8 +21,21 @@
namespace blink {
namespace {
// TODO(danakj): One day the gpu::mojom::Mailbox type should be shared with
// blink directly and we won't need to use gpu::mojom::blink::Mailbox, nor the
// conversion through WTF::Vector.
gpu::mojom::blink::MailboxPtr SharedBitmapIdToGpuMailboxPtr(
const viz::SharedBitmapId& id) {
WTF::Vector<int8_t> name(GL_MAILBOX_SIZE_CHROMIUM);
for (int i = 0; i < GL_MAILBOX_SIZE_CHROMIUM; ++i)
name[i] = id.name[i];
return {base::in_place, name};
}
// Delay to retry getting the context_provider.
constexpr int kGetContextProviderRetryMS = 150;
} // namespace
VideoFrameSubmitter::VideoFrameSubmitter(
......@@ -132,10 +145,12 @@ void VideoFrameSubmitter::OnReceivedContextProvider(
}
context_provider_ = context_provider;
resource_provider_->Initialize(context_provider);
if (context_provider_)
if (use_gpu_compositing) {
context_provider_->AddObserver(this);
resource_provider_->Initialize(context_provider, nullptr);
} else {
resource_provider_->Initialize(nullptr, this);
}
if (frame_sink_id_.is_valid())
StartSubmitting();
......@@ -275,4 +290,19 @@ void VideoFrameSubmitter::DidPresentCompositorFrame(
void VideoFrameSubmitter::DidDiscardCompositorFrame(
uint32_t presentation_token) {}
void VideoFrameSubmitter::DidAllocateSharedBitmap(
mojo::ScopedSharedBufferHandle buffer,
const viz::SharedBitmapId& id) {
DCHECK(compositor_frame_sink_);
compositor_frame_sink_->DidAllocateSharedBitmap(
std::move(buffer), SharedBitmapIdToGpuMailboxPtr(id));
}
void VideoFrameSubmitter::DidDeleteSharedBitmap(const viz::SharedBitmapId& id) {
DCHECK(compositor_frame_sink_);
compositor_frame_sink_->DidDeleteSharedBitmap(
SharedBitmapIdToGpuMailboxPtr(id));
}
} // namespace blink
......@@ -8,8 +8,11 @@
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/quads/shared_bitmap.h"
#include "components/viz/common/resources/shared_bitmap_reporter.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/system/buffer.h"
#include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom-blink.h"
#include "third_party/blink/public/platform/web_video_frame_submitter.h"
#include "third_party/blink/renderer/platform/graphics/video_frame_resource_provider.h"
......@@ -26,6 +29,7 @@ namespace blink {
class PLATFORM_EXPORT VideoFrameSubmitter
: public WebVideoFrameSubmitter,
public viz::ContextLostObserver,
public viz::SharedBitmapReporter,
public viz::mojom::blink::CompositorFrameSinkClient {
public:
explicit VideoFrameSubmitter(WebContextProviderCallback,
......@@ -72,6 +76,11 @@ class PLATFORM_EXPORT VideoFrameSubmitter
void ReclaimResources(
const WTF::Vector<viz::ReturnedResource>& resources) override;
// viz::SharedBitmapReporter implementation.
void DidAllocateSharedBitmap(mojo::ScopedSharedBufferHandle,
const viz::SharedBitmapId&) override;
void DidDeleteSharedBitmap(const viz::SharedBitmapId&) override;
private:
void StartSubmitting();
void SubmitFrame(viz::BeginFrameAck, scoped_refptr<media::VideoFrame>);
......
......@@ -91,13 +91,17 @@ class MockCompositorFrameSink : public viz::mojom::blink::CompositorFrameSink {
class MockVideoFrameResourceProvider
: public blink::VideoFrameResourceProvider {
public:
MockVideoFrameResourceProvider(viz::ContextProvider* context_provider)
MockVideoFrameResourceProvider(
viz::ContextProvider* context_provider,
viz::SharedBitmapReporter* shared_bitmap_reporter)
: blink::VideoFrameResourceProvider(cc::LayerTreeSettings()) {
blink::VideoFrameResourceProvider::Initialize(context_provider);
blink::VideoFrameResourceProvider::Initialize(context_provider,
shared_bitmap_reporter);
}
~MockVideoFrameResourceProvider() override = default;
MOCK_METHOD1(Initialize, void(viz::ContextProvider*));
MOCK_METHOD2(Initialize,
void(viz::ContextProvider*, viz::SharedBitmapReporter*));
MOCK_METHOD3(AppendQuads,
void(viz::RenderPass*,
scoped_refptr<media::VideoFrame>,
......@@ -132,8 +136,8 @@ class VideoFrameSubmitterTest : public testing::Test {
}
void MakeSubmitter() {
resource_provider_ =
new StrictMock<MockVideoFrameResourceProvider>(context_provider_.get());
resource_provider_ = new StrictMock<MockVideoFrameResourceProvider>(
context_provider_.get(), nullptr);
submitter_ = std::make_unique<VideoFrameSubmitter>(
base::BindRepeating(
[](base::OnceCallback<void(bool, viz::ContextProvider*)>) {}),
......
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