#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/renderers/video_resource_updater.h"
#include <stddef.h>
#include <stdint.h>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/test/task_environment.h"
#include "components/viz/client/client_resource_provider.h"
#include "components/viz/client/shared_bitmap_reporter.h"
#include "components/viz/common/quads/compositor_render_pass.h"
#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/common/resources/shared_image_format.h"
#include "components/viz/test/fake_output_surface.h"
#include "components/viz/test/test_gles2_interface.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/ipc/client/client_shared_image_interface.h"
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"
#include "skia/ext/skcolorspace_primaries.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace {
class FakeSharedBitmapReporter : public viz::SharedBitmapReporter { … };
class UploadCounterGLES2Interface : public viz::TestGLES2Interface { … };
class VideoResourceUpdaterTest : public testing::Test { … };
const gpu::SyncToken VideoResourceUpdaterTest::kMailboxSyncToken = …;
TEST_F(VideoResourceUpdaterTest, SoftwareFrame) { … }
TEST_F(VideoResourceUpdaterTest, SoftwareFrameNV12) { … }
TEST_F(VideoResourceUpdaterTest, SoftwareFrameRGB) { … }
TEST_F(VideoResourceUpdaterTest, SoftwareFrameRGBNonOrigin) { … }
TEST_F(VideoResourceUpdaterTest, SoftwareFrameY16NonOrigin) { … }
TEST_F(VideoResourceUpdaterTest, HighBitFrameNoF16) { … }
class VideoResourceUpdaterTestWithF16 : public VideoResourceUpdaterTest { … };
TEST_F(VideoResourceUpdaterTestWithF16, HighBitFrame) { … }
class VideoResourceUpdaterTestWithR16 : public VideoResourceUpdaterTest { … };
TEST_F(VideoResourceUpdaterTestWithR16, HighBitFrame) { … }
TEST_F(VideoResourceUpdaterTest, NV12FrameSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, P010FrameSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, HighBitFrameSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, WonkySoftwareFrame) { … }
TEST_F(VideoResourceUpdaterTest, WonkySoftwareFrameSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, ReuseResource) { … }
TEST_F(VideoResourceUpdaterTest, ReuseResourceNV12) { … }
TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDelete) { … }
TEST_F(VideoResourceUpdaterTest, SoftwareFrameSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, SoftwareFrameRGBSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, ReuseResourceSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDeleteSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, ChangeResourceSizeSoftwareCompositor) { … }
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SharedImageFormat) { … }
TEST_F(VideoResourceUpdaterTest,
CreateForHardwarePlanes_StreamTexture_CopyToNewTexture) { … }
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_TextureQuad) { … }
#if BUILDFLAG(IS_WIN)
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_DCompSurface) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
EXPECT_EQ(0u, GetSharedImageCount());
scoped_refptr<VideoFrame> video_frame = CreateTestDCompSurfaceVideoFrame();
VideoFrameExternalResources resources =
updater->CreateExternalResourcesFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::STREAM_TEXTURE, resources.type);
EXPECT_EQ(1u, resources.resources.size());
EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
resources.resources[0].texture_target());
EXPECT_EQ(1u, resources.release_callbacks.size());
EXPECT_EQ(0u, GetSharedImageCount());
updater->ObtainFrameResources(video_frame);
std::unique_ptr<viz::CompositorRenderPass> pass =
viz::CompositorRenderPass::Create();
pass->SetNew(viz::CompositorRenderPassId{1},
gfx::Rect(video_frame->coded_size()),
gfx::Rect(),
gfx::Transform());
updater->AppendQuads(
pass.get(), video_frame,
gfx::Transform(),
gfx::Rect(video_frame->coded_size()),
gfx::Rect(video_frame->coded_size()),
gfx::MaskFilterInfo(), std::nullopt,
true, 1.0,
0);
EXPECT_EQ(1u, pass->quad_list.size());
const viz::TextureDrawQuad* quad =
pass->quad_list.ElementAt(0)->DynamicCast<viz::TextureDrawQuad>();
EXPECT_NE(nullptr, quad);
EXPECT_EQ(true, quad->is_stream_video);
EXPECT_EQ(viz::OverlayPriority::kRequired, quad->overlay_priority_hint);
updater->ReleaseFrameResources();
}
#endif
TEST_F(VideoResourceUpdaterTest, PassReleaseSyncToken) { … }
TEST_F(VideoResourceUpdaterTest, GenerateReleaseSyncToken) { … }
TEST_F(VideoResourceUpdaterTest, PassMailboxSyncToken) { … }
TEST_F(VideoResourceUpdaterTest, GenerateSyncTokenOnTextureCopy) { … }
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleNV12) { … }
TEST_F(VideoResourceUpdaterTest,
CreateForHardwarePlanes_DualNV12_SharedImageFormat) { … }
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleP010HDR) { … }
}
}