#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/viz/service/frame_sinks/video_capture/frame_sink_video_capturer_impl.h"
#include <map>
#include <optional>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/shared_memory_mapping.h"
#include "base/notimplemented.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/time/time.h"
#include "base/token.h"
#include "cc/base/math_util.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "components/viz/common/frame_sinks/copy_output_util.h"
#include "components/viz/common/resources/shared_image_format_utils.h"
#include "components/viz/common/surfaces/subtree_capture_id.h"
#include "components/viz/common/surfaces/video_capture_target.h"
#include "components/viz/service/frame_sinks/gmb_video_frame_pool_context_provider.h"
#include "components/viz/service/frame_sinks/video_capture/frame_sink_video_capturer_manager.h"
#include "components/viz/test/test_context_provider.h"
#include "gpu/command_buffer/client/client_shared_image.h"
#include "media/base/format_utils.h"
#include "media/base/limits.h"
#include "media/base/test_helpers.h"
#include "media/base/video_util.h"
#include "media/capture/mojom/video_capture_buffer.mojom.h"
#include "media/capture/mojom/video_capture_types.mojom.h"
#include "media/video/fake_gpu_memory_buffer.h"
#include "media/video/renderable_gpu_memory_buffer_video_frame_pool.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/viz/privileged/mojom/compositing/frame_sink_video_capture.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
VideoCaptureOracle;
VideoFrame;
VideoFrameMetadata;
_;
InvokeWithoutArgs;
NiceMock;
Return;
namespace viz {
namespace {
bool AlignsWithI420SubsamplingBoundaries(const gfx::Rect& update_rect) { … }
bool CompareVarsInCompositorFrameMetadata(
const VideoFrame& frame,
float device_scale_factor,
float page_scale_factor,
const gfx::PointF& root_scroll_offset) { … }
media::VideoPixelFormat CopyOutputRequestFormatToVideoPixelFormat(
CopyOutputRequest::ResultFormat format) { … }
gfx::ColorSpace GetColorSpaceForPixelFormat(media::VideoPixelFormat format) { … }
gfx::Size GetBufferSizeInPixelsForVideoPixelFormat(
media::VideoPixelFormat format,
const gfx::Size& coded_size) { … }
const VideoCaptureTarget kVideoCaptureTarget(FrameSinkId(1, 1));
constexpr auto kVsyncInterval = …;
const struct SizeSet { … } kSizeSets[5] = …;
constexpr float kDefaultDeviceScaleFactor = …;
constexpr float kDefaultPageScaleFactor = …;
constexpr gfx::PointF kDefaultRootScrollOffset = …;
struct YUVColor { … };
YUVColor RGBToYUV(uint32_t argb) { … }
void PropagateMojoTasks(
scoped_refptr<base::TestMockTimeTaskRunner> runner = nullptr) { … }
class MockFrameSinkManager : public FrameSinkVideoCapturerManager { … };
class MockConsumer : public mojom::FrameSinkVideoConsumer { … };
class FakeGpuCopyResult : public CopyOutputResult { … };
class SolidColorRGBAResult : public CopyOutputResult { … };
class SolidColorI420Result : public CopyOutputResult { … };
class FakeCapturableFrameSink : public CapturableFrameSink { … };
class InstrumentedVideoCaptureOracle : public media::VideoCaptureOracle { … };
namespace {
bool IsLetterboxedI420Plane(int plane,
uint8_t component,
gfx::Rect content_rect,
const VideoFrame& frame,
testing::MatchResultListener* result_listener) { … }
bool IsLetterboxedRGBA(SkColor color,
gfx::Rect content_rect,
const VideoFrame& frame,
testing::MatchResultListener* result_listener) { … }
}
MATCHER_P3(IsLetterboxedFrame, color, content_rect, pixel_format, "") { … }
class TestVideoCaptureOverlay : public VideoCaptureOverlay { … };
class TestGmbVideoFramePoolContext
: public media::RenderableGpuMemoryBufferVideoFramePool::Context { … };
class TestGmbVideoFramePoolContextProvider
: public GmbVideoFramePoolContextProvider { … };
}
class FrameSinkVideoCapturerTest
: public testing::Test,
public testing::WithParamInterface<
std::tuple<mojom::BufferFormatPreference, media::VideoPixelFormat>> { … };
TEST_P(FrameSinkVideoCapturerTest, ResolvesTargetImmediately) { … }
TEST_P(FrameSinkVideoCapturerTest, ResolvesTargetLater) { … }
TEST_P(FrameSinkVideoCapturerTest, PostponesCaptureWithoutATarget) { … }
TEST_P(FrameSinkVideoCapturerTest, CapturesCompositedFrames) { … }
TEST_P(FrameSinkVideoCapturerTest, HaltsWhenPoolIsFull) { … }
TEST_P(FrameSinkVideoCapturerTest, DeliversFramesInOrder) { … }
TEST_P(FrameSinkVideoCapturerTest, CancelsInFlightCapturesOnStop) { … }
TEST_P(FrameSinkVideoCapturerTest, EventuallySendsARefreshFrame) { … }
TEST_P(FrameSinkVideoCapturerTest, RefreshDemandsAreProperlyHandled) { … }
TEST_P(FrameSinkVideoCapturerTest, HonorsRequestRefreshFrame) { … }
TEST_P(FrameSinkVideoCapturerTest,
ResurrectsFramesForChangingCaptureResolution) { … }
TEST_P(FrameSinkVideoCapturerTest, CompositorFrameMetadataReachesConsumer) { … }
TEST_P(FrameSinkVideoCapturerTest, DeliversUpdateRectAndCaptureCounter) { … }
TEST_P(FrameSinkVideoCapturerTest, CaptureCounterSkipsWhenFramesAreDropped) { … }
TEST_P(FrameSinkVideoCapturerTest, ClientCaptureStartsAndStops) { … }
TEST_P(FrameSinkVideoCapturerTest, RegionCaptureCropId) { … }
TEST_P(FrameSinkVideoCapturerTest,
RegionCaptureTargetIsSetLaterWhenNotInitiallyAvailable) { … }
TEST_P(FrameSinkVideoCapturerTest, HandlesFrameWithEmptyRegion) { … }
TEST_P(FrameSinkVideoCapturerTest, HandlesFrameWithRegionCroppedToZero) { … }
TEST_P(FrameSinkVideoCapturerTest, ProperlyHandlesCaptureSizeForOverlay) { … }
TEST_P(FrameSinkVideoCapturerTest, HandlesSubtreeCaptureId) { … }
TEST_P(FrameSinkVideoCapturerTest, ProperlyHandlesSubtreeSizeForOverlay) { … }
TEST_P(FrameSinkVideoCapturerTest, HandlesNullSubTargetPtrCorrectly) { … }
INSTANTIATE_TEST_SUITE_P(…);
}