Commit 8ac910dc authored by liberato@chromium.org's avatar liberato@chromium.org Committed by Commit Bot

Revert "Switch VideoFrameFactoryImpl to use a SharedImageVideoProvider"

This reverts commit 579b12b9.

Reason for revert: crbug.com/968470 (want to revert before branch cut)

Original change's description:
> Switch VideoFrameFactoryImpl to use a SharedImageVideoProvider
> 
> This CL creates DirectSharedImageVideoProvider, which does a hop to
> the gpu main thread for every SharedImageVideo request.  This is
> almost identical to what was happening before, just refactored.
> 
> GpuVideoFrameFactory is now an implementation detail of the provider
> rather than VideoFrameFactoryImpl.
> 
> A follow-up CL will provide an implementation of
> SharedImageVideoProvider that maintains a pool of SharedImageVideo
> objects to provide without hopping to the gpu main thread on the
> critical path.  It will still post a "MaybeRenderEarly" to the main
> thread, but that doesn't need to hold up delivery of the VideoFrame
> to the renderer.
> 
> Change-Id: Ia318862daf610327e716515f020b3eeb934dd012
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1628154
> Commit-Queue: Frank Liberato <liberato@chromium.org>
> Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#663361}

TBR=dalecurtis@chromium.org,liberato@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I2c7878a5f6a31c2b4518a9756f144891a6341863
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636561Reviewed-by: default avatarFrank Liberato <liberato@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Frank Liberato <liberato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664900}
parent aa6941be
...@@ -127,8 +127,6 @@ component("gpu") { ...@@ -127,8 +127,6 @@ component("gpu") {
"android/promotion_hint_aggregator_impl.h", "android/promotion_hint_aggregator_impl.h",
"android/shared_image_video.cc", "android/shared_image_video.cc",
"android/shared_image_video.h", "android/shared_image_video.h",
"android/shared_image_video_provider.cc",
"android/shared_image_video_provider.h",
"android/surface_chooser_helper.cc", "android/surface_chooser_helper.cc",
"android/surface_chooser_helper.h", "android/surface_chooser_helper.h",
"android/surface_texture_gl_owner.cc", "android/surface_texture_gl_owner.cc",
......
...@@ -41,24 +41,20 @@ std::unique_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded( ...@@ -41,24 +41,20 @@ std::unique_ptr<ui::ScopedMakeCurrent> MakeCurrentIfNeeded(
} // namespace } // namespace
CodecImage::CodecImage() = default; CodecImage::CodecImage(
std::unique_ptr<CodecOutputBuffer> output_buffer,
scoped_refptr<TextureOwner> texture_owner,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb)
: phase_(Phase::kInCodec),
output_buffer_(std::move(output_buffer)),
texture_owner_(std::move(texture_owner)),
promotion_hint_cb_(std::move(promotion_hint_cb)) {}
CodecImage::~CodecImage() { CodecImage::~CodecImage() {
if (destruction_cb_) if (destruction_cb_)
std::move(destruction_cb_).Run(this); std::move(destruction_cb_).Run(this);
} }
void CodecImage::Initialize(
std::unique_ptr<CodecOutputBuffer> output_buffer,
scoped_refptr<TextureOwner> texture_owner,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb) {
DCHECK(output_buffer);
phase_ = Phase::kInCodec;
output_buffer_ = std::move(output_buffer);
texture_owner_ = std::move(texture_owner);
promotion_hint_cb_ = std::move(promotion_hint_cb);
}
void CodecImage::SetDestructionCb(DestructionCb destruction_cb) { void CodecImage::SetDestructionCb(DestructionCb destruction_cb) {
destruction_cb_ = std::move(destruction_cb); destruction_cb_ = std::move(destruction_cb);
} }
......
...@@ -33,16 +33,9 @@ class MEDIA_GPU_EXPORT CodecImage : public gpu::gles2::GLStreamTextureImage { ...@@ -33,16 +33,9 @@ class MEDIA_GPU_EXPORT CodecImage : public gpu::gles2::GLStreamTextureImage {
// since CodecImageGroup calls the same cb for multiple images. // since CodecImageGroup calls the same cb for multiple images.
using DestructionCb = base::RepeatingCallback<void(CodecImage*)>; using DestructionCb = base::RepeatingCallback<void(CodecImage*)>;
CodecImage(); CodecImage(std::unique_ptr<CodecOutputBuffer> output_buffer,
scoped_refptr<TextureOwner> texture_owner,
// (Re-)Initialize this CodecImage to use |output_buffer| et. al. PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb);
//
// May be called on a random thread, but only if the CodecImage is otherwise
// not in use.
void Initialize(
std::unique_ptr<CodecOutputBuffer> output_buffer,
scoped_refptr<TextureOwner> texture_owner,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb);
void SetDestructionCb(DestructionCb destruction_cb); void SetDestructionCb(DestructionCb destruction_cb);
...@@ -139,7 +132,7 @@ class MEDIA_GPU_EXPORT CodecImage : public gpu::gles2::GLStreamTextureImage { ...@@ -139,7 +132,7 @@ class MEDIA_GPU_EXPORT CodecImage : public gpu::gles2::GLStreamTextureImage {
bool RenderToOverlay(); bool RenderToOverlay();
// The phase of the image buffer's lifecycle. // The phase of the image buffer's lifecycle.
Phase phase_ = Phase::kInvalidated; Phase phase_;
// The buffer backing this image. // The buffer backing this image.
std::unique_ptr<CodecOutputBuffer> output_buffer_; std::unique_ptr<CodecOutputBuffer> output_buffer_;
......
...@@ -43,7 +43,10 @@ class CodecImageGroupWithDestructionHook : public CodecImageGroup { ...@@ -43,7 +43,10 @@ class CodecImageGroupWithDestructionHook : public CodecImageGroup {
// CodecImage with a mocked ReleaseCodecBuffer. // CodecImage with a mocked ReleaseCodecBuffer.
class MockCodecImage : public CodecImage { class MockCodecImage : public CodecImage {
public: public:
MockCodecImage() = default; MockCodecImage()
: CodecImage(nullptr,
nullptr,
PromotionHintAggregator::NotifyPromotionHintCB()) {}
MOCK_METHOD0(ReleaseCodecBuffer, void()); MOCK_METHOD0(ReleaseCodecBuffer, void());
......
...@@ -81,8 +81,7 @@ class CodecImageTest : public testing::Test { ...@@ -81,8 +81,7 @@ class CodecImageTest : public testing::Test {
CodecImage::DestructionCb destruction_cb = base::DoNothing()) { CodecImage::DestructionCb destruction_cb = base::DoNothing()) {
std::unique_ptr<CodecOutputBuffer> buffer; std::unique_ptr<CodecOutputBuffer> buffer;
wrapper_->DequeueOutputBuffer(nullptr, nullptr, &buffer); wrapper_->DequeueOutputBuffer(nullptr, nullptr, &buffer);
scoped_refptr<CodecImage> image = new CodecImage(); scoped_refptr<CodecImage> image = new CodecImage(
image->Initialize(
std::move(buffer), kind == kTextureOwner ? texture_owner_ : nullptr, std::move(buffer), kind == kTextureOwner ? texture_owner_ : nullptr,
base::BindRepeating(&PromotionHintReceiver::OnPromotionHint, base::BindRepeating(&PromotionHintReceiver::OnPromotionHint,
base::Unretained(&promotion_hint_receiver_))); base::Unretained(&promotion_hint_receiver_)));
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/gpu/android/shared_image_video_provider.h"
namespace media {
SharedImageVideoProvider::ImageSpec::ImageSpec(
gfx::Size our_size,
scoped_refptr<CodecImageGroup> group)
: size(our_size), image_group(std::move(group)) {}
SharedImageVideoProvider::ImageSpec::ImageSpec(const ImageSpec&) = default;
SharedImageVideoProvider::ImageSpec::~ImageSpec() = default;
SharedImageVideoProvider::ImageRecord::ImageRecord() = default;
SharedImageVideoProvider::ImageRecord::ImageRecord(ImageRecord&&) = default;
SharedImageVideoProvider::ImageRecord::~ImageRecord() = default;
} // namespace media
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_GPU_ANDROID_SHARED_IMAGE_VIDEO_PROVIDER_H_
#define MEDIA_GPU_ANDROID_SHARED_IMAGE_VIDEO_PROVIDER_H_
#include "base/callback.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/ipc/common/vulkan_ycbcr_info.h"
#include "media/gpu/android/codec_image_group.h"
#include "media/gpu/android/promotion_hint_aggregator.h"
#include "media/gpu/media_gpu_export.h"
#include "ui/gfx/geometry/size.h"
namespace gpu {
struct SyncToken;
} // namespace gpu
namespace media {
// Provider class for shared images.
class MEDIA_GPU_EXPORT SharedImageVideoProvider {
public:
// Description of the underlying properties of the shared image.
struct ImageSpec {
ImageSpec(gfx::Size size, scoped_refptr<CodecImageGroup> group);
ImageSpec(const ImageSpec&);
~ImageSpec();
// Size of the underlying texture.
gfx::Size size;
// Image group to which the CodecImage should belong. In other words, this
// indicates that the image will share the same underlying TextureOwner.
scoped_refptr<CodecImageGroup> image_group;
// TODO: Include other properties, if they matter, like texture format.
bool operator==(const ImageSpec&);
};
using ReleaseCB = base::OnceCallback<void(const gpu::SyncToken&)>;
// Description of the image that's being provided to the client.
struct ImageRecord {
ImageRecord();
ImageRecord(ImageRecord&&);
~ImageRecord();
// Mailbox to which this shared image is bound.
gpu::Mailbox mailbox;
// Sampler conversion information which is used in vulkan context.
base::Optional<gpu::VulkanYCbCrInfo> ycbcr_info;
// Release callback. When this is called (or dropped), the image will be
// considered unused.
ReleaseCB release_cb;
private:
DISALLOW_COPY_AND_ASSIGN(ImageRecord);
};
SharedImageVideoProvider() = default;
virtual ~SharedImageVideoProvider() = default;
using ImageReadyCB = base::OnceCallback<void(ImageRecord)>;
// Call |cb| when we have a shared image that matches |spec|. We may call
// |cb| back before returning, or we might post it for later.
// |output_buffer|, |texture_owner|, and |promotion_hint_cb| probably should
// not be provided to the provider, but need to be refactored a bit first.
// They will be used to configure the SharedImageVideo to display the buffer
// on the given texture, and return promotion hints.
virtual void RequestImage(
ImageReadyCB cb,
const ImageSpec& spec,
std::unique_ptr<CodecOutputBuffer> output_buffer,
scoped_refptr<TextureOwner> texture_owner,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(SharedImageVideoProvider);
};
} // namespace media
#endif // MEDIA_GPU_ANDROID_SHARED_IMAGE_VIDEO_PROVIDER_H_
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "media/gpu/android/codec_image.h" #include "media/gpu/android/codec_image.h"
#include "media/gpu/android/codec_wrapper.h" #include "media/gpu/android/codec_wrapper.h"
#include "media/gpu/android/shared_image_video_provider.h"
#include "media/gpu/android/surface_texture_gl_owner.h" #include "media/gpu/android/surface_texture_gl_owner.h"
#include "media/gpu/android/video_frame_factory.h" #include "media/gpu/android/video_frame_factory.h"
#include "media/gpu/gles2_decoder_helper.h" #include "media/gpu/gles2_decoder_helper.h"
...@@ -27,6 +26,7 @@ ...@@ -27,6 +26,7 @@
namespace media { namespace media {
class CodecImageGroup; class CodecImageGroup;
class GpuVideoFrameFactory;
// VideoFrameFactoryImpl creates CodecOutputBuffer backed VideoFrames and tries // VideoFrameFactoryImpl creates CodecOutputBuffer backed VideoFrames and tries
// to eagerly render them to their surface to release the buffers back to the // to eagerly render them to their surface to release the buffers back to the
...@@ -40,7 +40,8 @@ class MEDIA_GPU_EXPORT VideoFrameFactoryImpl : public VideoFrameFactory { ...@@ -40,7 +40,8 @@ class MEDIA_GPU_EXPORT VideoFrameFactoryImpl : public VideoFrameFactory {
// cleaned up properly. The release callback may be called from any thread. // cleaned up properly. The release callback may be called from any thread.
using ImageReadyCB = using ImageReadyCB =
base::OnceCallback<void(gpu::Mailbox mailbox, base::OnceCallback<void(gpu::Mailbox mailbox,
VideoFrame::ReleaseMailboxCB release_cb)>; VideoFrame::ReleaseMailboxCB release_cb,
base::Optional<gpu::VulkanYCbCrInfo> ycbcr_info)>;
// |get_stub_cb| will be run on |gpu_task_runner|. // |get_stub_cb| will be run on |gpu_task_runner|.
VideoFrameFactoryImpl( VideoFrameFactoryImpl(
...@@ -80,9 +81,12 @@ class MEDIA_GPU_EXPORT VideoFrameFactoryImpl : public VideoFrameFactory { ...@@ -80,9 +81,12 @@ class MEDIA_GPU_EXPORT VideoFrameFactoryImpl : public VideoFrameFactory {
VideoPixelFormat pixel_format, VideoPixelFormat pixel_format,
OverlayMode overlay_mode, OverlayMode overlay_mode,
bool enable_threaded_texture_mailboxes, bool enable_threaded_texture_mailboxes,
SharedImageVideoProvider::ImageRecord record); gpu::Mailbox mailbox,
VideoFrame::ReleaseMailboxCB release_cb,
base::Optional<gpu::VulkanYCbCrInfo> ycbcr_info);
std::unique_ptr<SharedImageVideoProvider> image_provider_; // The gpu thread side of the implementation.
std::unique_ptr<GpuVideoFrameFactory> gpu_video_frame_factory_;
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
GetStubCb get_stub_cb_; GetStubCb get_stub_cb_;
...@@ -94,65 +98,47 @@ class MEDIA_GPU_EXPORT VideoFrameFactoryImpl : public VideoFrameFactory { ...@@ -94,65 +98,47 @@ class MEDIA_GPU_EXPORT VideoFrameFactoryImpl : public VideoFrameFactory {
// Is the sync mailbox manager enabled? // Is the sync mailbox manager enabled?
bool enable_threaded_texture_mailboxes_ = false; bool enable_threaded_texture_mailboxes_ = false;
// Current group that new CodecImages should belong to. Do not use this on
// our thread; everything must be posted to the gpu main thread, including
// destruction of it.
scoped_refptr<CodecImageGroup> image_group_;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(VideoFrameFactoryImpl); DISALLOW_COPY_AND_ASSIGN(VideoFrameFactoryImpl);
}; };
// GpuSharedImageVideoFactory creates SharedImageVideo objects. It must be run // GpuVideoFrameFactory is an implementation detail of VideoFrameFactoryImpl. It
// on the gpu main thread. // may be created on any thread but only accessed on the gpu thread thereafter.
// class GpuVideoFrameFactory
// GpuSharedImageVideoFactory is an implementation detail of
// DirectSharedImageVideoProvider. It really should be split out into its own
// file from here, but in the interest of making CL diffs more readable, that
// is left for later.
class GpuSharedImageVideoFactory
: public gpu::CommandBufferStub::DestructionObserver { : public gpu::CommandBufferStub::DestructionObserver {
public: public:
GpuSharedImageVideoFactory(); GpuVideoFrameFactory();
~GpuSharedImageVideoFactory() override; ~GpuVideoFrameFactory() override;
// TODO(liberato): Now that this is used as part of an image provider, it scoped_refptr<TextureOwner> Initialize(
// doesn't really make sense for it to call back with a TextureOwner. That VideoFrameFactory::OverlayMode overlay_mode,
// should be handled by VideoFrameFactoryImpl if it wants. VideoFrameFactory::GetStubCb get_stub_cb);
void Initialize(VideoFrameFactory::OverlayMode overlay_mode,
VideoFrameFactory::GetStubCb get_stub_cb, // Creates a SharedImage for |output_buffer|, and returns it via the callback.
VideoFrameFactory::InitCb init_cb); void CreateImage(
std::unique_ptr<CodecOutputBuffer> output_buffer,
// Similar to SharedImageVideoProvider::ImageReadyCB, but provides additional scoped_refptr<TextureOwner> texture_owner,
// details for the provider that's using us. PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb,
using FactoryImageReadyCB = VideoFrameFactoryImpl::ImageReadyCB image_ready_cb,
base::OnceCallback<void(SharedImageVideoProvider::ImageRecord record, scoped_refptr<base::SingleThreadTaskRunner> task_runner);
scoped_refptr<CodecImage> codec_image)>;
// Set our image group. Must be called before the first call to
// Creates a SharedImage for |spec|, and returns it via the callback. // CreateVideoFrame occurs.
// TODO(liberato): |texture_owner| is only needed to get the service id, to void SetImageGroup(scoped_refptr<CodecImageGroup> image_group);
// create the per-frame texture. All of that is only needed for legacy
// mailbox support, where we have to have one texture per CodecImage.
void CreateImage(FactoryImageReadyCB cb,
const SharedImageVideoProvider::ImageSpec& spec,
scoped_refptr<TextureOwner> texture_owner);
private: private:
// Creates a SharedImage for |mailbox|, and returns success or failure. // Creates a SharedImage for |mailbox|, and returns success or failure.
bool CreateImageInternal(const SharedImageVideoProvider::ImageSpec& spec, bool CreateImageInternal(
scoped_refptr<TextureOwner> texture_owner, std::unique_ptr<CodecOutputBuffer> output_buffer,
gpu::Mailbox mailbox, scoped_refptr<TextureOwner> texture_owner,
scoped_refptr<CodecImage> image); gpu::Mailbox mailbox,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb);
void OnWillDestroyStub(bool have_context) override; void OnWillDestroyStub(bool have_context) override;
// Removes |image| from |images_|. // Removes |image| from |images_|.
void OnImageDestructed(CodecImage* image); void OnImageDestructed(CodecImage* image);
// Set our image group. Must be called before the first call to
// CreateVideoFrame occurs.
void SetImageGroup(scoped_refptr<CodecImageGroup> image_group);
// Outstanding images that should be considered for early rendering. // Outstanding images that should be considered for early rendering.
std::vector<CodecImage*> images_; std::vector<CodecImage*> images_;
...@@ -170,8 +156,8 @@ class GpuSharedImageVideoFactory ...@@ -170,8 +156,8 @@ class GpuSharedImageVideoFactory
base::Optional<gpu::VulkanYCbCrInfo> ycbcr_info_; base::Optional<gpu::VulkanYCbCrInfo> ycbcr_info_;
THREAD_CHECKER(thread_checker_); THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<GpuSharedImageVideoFactory> weak_factory_; base::WeakPtrFactory<GpuVideoFrameFactory> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GpuSharedImageVideoFactory); DISALLOW_COPY_AND_ASSIGN(GpuVideoFrameFactory);
}; };
namespace internal { namespace internal {
......
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