#ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_H_
#define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_H_
#include <stdint.h>
#include <memory>
#include "base/memory/ref_counted.h"
#include "base/task/single_thread_task_runner.h"
#include "base/unguessable_token.h"
#include "cc/layers/video_frame_provider.h"
#include "content/common/content_export.h"
#include "content/renderer/stream_texture_host_android.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/ipc/common/gpu_channel.mojom.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
namespace gpu {
class ClientSharedImageInterface;
class GpuChannelHost;
class SharedImageInterface;
struct VulkanYCbCrInfo;
}
namespace content {
class StreamTextureFactory;
class CONTENT_EXPORT StreamTextureProxy : public StreamTextureHost::Listener {
public:
using CreateVideoFrameCB = base::RepeatingCallback<void(
const gpu::Mailbox& mailbox,
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const absl::optional<gpu::VulkanYCbCrInfo>&)>;
StreamTextureProxy() = delete;
StreamTextureProxy(const StreamTextureProxy&) = delete;
StreamTextureProxy& operator=(const StreamTextureProxy&) = delete;
~StreamTextureProxy() override;
void BindToTaskRunner(
const base::RepeatingClosure& received_frame_cb,
const CreateVideoFrameCB& create_video_frame_cb,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
void OnFrameAvailable() override;
void OnFrameWithInfoAvailable(
const gpu::Mailbox& mailbox,
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const absl::optional<gpu::VulkanYCbCrInfo>& ycbcr_info) override;
void ForwardStreamTextureForSurfaceRequest(
const base::UnguessableToken& request_token);
void UpdateRotatedVisibleSize(const gfx::Size& size);
void ClearReceivedFrameCB();
void ClearCreateVideoFrameCB();
struct Deleter {
inline void operator()(StreamTextureProxy* ptr) const { ptr->Release(); }
};
private:
friend class StreamTextureFactory;
friend class StreamTextureProxyTest;
explicit StreamTextureProxy(std::unique_ptr<StreamTextureHost> host);
void BindOnThread();
void Release();
const std::unique_ptr<StreamTextureHost> host_;
base::Lock lock_;
base::RepeatingClosure received_frame_cb_;
CreateVideoFrameCB create_video_frame_cb_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
};
typedef std::unique_ptr<StreamTextureProxy, StreamTextureProxy::Deleter>
ScopedStreamTextureProxy;
class CONTENT_EXPORT StreamTextureFactory
: public base::RefCountedThreadSafe<StreamTextureFactory> {
public:
static scoped_refptr<StreamTextureFactory> Create(
scoped_refptr<gpu::GpuChannelHost> channel);
StreamTextureFactory() = delete;
StreamTextureFactory(const StreamTextureFactory&) = delete;
StreamTextureFactory& operator=(const StreamTextureFactory&) = delete;
ScopedStreamTextureProxy CreateProxy();
bool IsLost() const;
gpu::SharedImageInterface* SharedImageInterface();
private:
friend class base::RefCountedThreadSafe<StreamTextureFactory>;
StreamTextureFactory(scoped_refptr<gpu::GpuChannelHost> channel);
~StreamTextureFactory();
scoped_refptr<gpu::GpuChannelHost> channel_;
std::unique_ptr<gpu::ClientSharedImageInterface> shared_image_interface_;
};
}
#endif