#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/webcodecs/background_readback.h"
#include "base/feature_list.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/bind_post_task.h"
#include "base/task/task_traits.h"
#include "base/threading/thread_checker.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/gpu/raster_context_provider.h"
#include "gpu/command_buffer/client/raster_interface.h"
#include "media/base/video_frame_pool.h"
#include "media/base/video_util.h"
#include "media/base/wait_and_replace_sync_token_client.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_data_init.h"
#include "third_party/blink/renderer/modules/webaudio/audio_buffer.h"
#include "third_party/blink/renderer/modules/webcodecs/video_frame_rect_util.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h"
#include "third_party/blink/renderer/platform/graphics/web_graphics_context_3d_provider_util.h"
#include "third_party/blink/renderer/platform/heap/cross_thread_handle.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_gfx.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
namespace {
bool CanUseRgbReadback(media::VideoFrame& frame) { … }
SkImageInfo GetImageInfoForFrame(const media::VideoFrame& frame,
const gfx::Size& size) { … }
gpu::raster::RasterInterface* GetSharedGpuRasterInterface() { … }
}
namespace WTF {
template <>
struct CrossThreadCopier<blink::VideoFrameLayout>
: public CrossThreadCopierPassThrough<blink::VideoFrameLayout> { … };
template <>
struct CrossThreadCopier<base::span<uint8_t>>
: public CrossThreadCopierPassThrough<base::span<uint8_t>> { … };
}
namespace blink {
class SyncReadbackThread
: public WTF::ThreadSafeRefCounted<SyncReadbackThread> { … };
BackgroundReadback::BackgroundReadback(base::PassKey<BackgroundReadback> key,
ExecutionContext& context)
: … { … }
BackgroundReadback::~BackgroundReadback() { … }
const char BackgroundReadback::kSupplementName[] = …;
BackgroundReadback* BackgroundReadback::From(ExecutionContext& context) { … }
void BackgroundReadback::ReadbackTextureBackedFrameToMemoryFrame(
scoped_refptr<media::VideoFrame> txt_frame,
ReadbackToFrameDoneCallback result_cb) { … }
void BackgroundReadback::ReadbackTextureBackedFrameToBuffer(
scoped_refptr<media::VideoFrame> txt_frame,
const gfx::Rect& src_rect,
const VideoFrameLayout& dest_layout,
base::span<uint8_t> dest_buffer,
ReadbackDoneCallback done_cb) { … }
void BackgroundReadback::ReadbackOnThread(
scoped_refptr<media::VideoFrame> txt_frame,
ReadbackToFrameDoneCallback result_cb) { … }
void BackgroundReadback::ReadbackOnThread(
scoped_refptr<media::VideoFrame> txt_frame,
const gfx::Rect& src_rect,
const VideoFrameLayout& dest_layout,
base::span<uint8_t> dest_buffer,
ReadbackDoneCallback done_cb) { … }
void BackgroundReadback::ReadbackRGBTextureBackedFrameToMemory(
scoped_refptr<media::VideoFrame> txt_frame,
ReadbackToFrameDoneCallback result_cb) { … }
void BackgroundReadback::OnARGBPixelsFrameReadCompleted(
ReadbackToFrameDoneCallback result_cb,
scoped_refptr<media::VideoFrame> txt_frame,
scoped_refptr<media::VideoFrame> result_frame,
bool success) { … }
void BackgroundReadback::ReadbackRGBTextureBackedFrameToBuffer(
scoped_refptr<media::VideoFrame> txt_frame,
const gfx::Rect& src_rect,
const VideoFrameLayout& dest_layout,
base::span<uint8_t> dest_buffer,
ReadbackDoneCallback done_cb) { … }
void BackgroundReadback::OnARGBPixelsBufferReadCompleted(
scoped_refptr<media::VideoFrame> txt_frame,
const gfx::Rect& src_rect,
const VideoFrameLayout& dest_layout,
base::span<uint8_t> dest_buffer,
ReadbackDoneCallback done_cb,
bool success) { … }
SyncReadbackThread::SyncReadbackThread() { … }
bool SyncReadbackThread::LazyInitialize() { … }
scoped_refptr<media::VideoFrame> SyncReadbackThread::ReadbackToFrame(
scoped_refptr<media::VideoFrame> frame) { … }
bool SyncReadbackThread::ReadbackToBuffer(
scoped_refptr<media::VideoFrame> frame,
const gfx::Rect src_rect,
const VideoFrameLayout dest_layout,
base::span<uint8_t> dest_buffer) { … }
}