chromium/media/renderers/paint_canvas_video_renderer_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <GLES3/gl3.h>
#include <stdint.h>

#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/aligned_memory.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/byte_conversions.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/skia_paint_canvas.h"
#include "components/viz/common/gpu/context_provider.h"
#include "components/viz/test/test_context_provider.h"
#include "components/viz/test/test_gpu_service_holder.h"
#include "components/viz/test/test_in_process_context_provider.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/gles2_interface_stub.h"
#include "gpu/command_buffer/common/capabilities.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/config/gpu_feature_info.h"
#include "media/base/timestamp_constants.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
#include "media/renderers/paint_canvas_video_renderer.h"
#include "media/renderers/shared_image_video_frame_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libyuv/include/libyuv/convert.h"
#include "third_party/libyuv/include/libyuv/scale.h"
#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/test/gl_surface_test_support.h"

VideoFrame;

namespace media {

static const int kWidth =;
static const int kHeight =;
static const gfx::RectF kNaturalRect(kWidth, kHeight);

// Generate frame pixels to provided |external_memory| and wrap it as frame.
scoped_refptr<VideoFrame> CreateTestY16Frame(const gfx::Size& coded_size,
                                             const gfx::Rect& visible_rect,
                                             void* external_memory,
                                             base::TimeDelta timestamp) {}

// Readback the contents of a RGBA texture into an array of RGBA values.
static std::unique_ptr<uint8_t[]> ReadbackTexture(
    gpu::gles2::GLES2Interface* gl,
    GLuint texture,
    const gfx::Size& size) {}

// Returns a functor that retrieves a SkColor for a given pixel, from raw RGBA
// data.
static auto ColorGetter(uint8_t* pixels, const gfx::Size& size) {}

class PaintCanvasVideoRendererTest : public testing::Test {};

static SkBitmap AllocBitmap(int width, int height) {}

static scoped_refptr<VideoFrame> CreateCroppedFrame() {}

PaintCanvasVideoRendererTest::PaintCanvasVideoRendererTest()
    :{}

PaintCanvasVideoRendererTest::~PaintCanvasVideoRendererTest() = default;

void PaintCanvasVideoRendererTest::PaintWithoutFrame(cc::PaintCanvas* canvas) {}

void PaintCanvasVideoRendererTest::Paint(scoped_refptr<VideoFrame> video_frame,
                                         cc::PaintCanvas* canvas,
                                         Color color) {}

void PaintCanvasVideoRendererTest::PaintRotated(
    scoped_refptr<VideoFrame> video_frame,
    cc::PaintCanvas* canvas,
    const gfx::RectF& dest_rect,
    Color color,
    SkBlendMode mode,
    VideoTransformation video_transformation) {}

void PaintCanvasVideoRendererTest::Copy(scoped_refptr<VideoFrame> video_frame,
                                        cc::PaintCanvas* canvas) {}

TEST_F(PaintCanvasVideoRendererTest, NoFrame) {}

TEST_F(PaintCanvasVideoRendererTest, TransparentFrame) {}

TEST_F(PaintCanvasVideoRendererTest, TransparentFrameSrcMode) {}

TEST_F(PaintCanvasVideoRendererTest, TransparentFrameSrcMode1x1) {}

TEST_F(PaintCanvasVideoRendererTest, CopyTransparentFrame) {}

TEST_F(PaintCanvasVideoRendererTest, Natural) {}

TEST_F(PaintCanvasVideoRendererTest, Larger) {}

TEST_F(PaintCanvasVideoRendererTest, Smaller) {}

TEST_F(PaintCanvasVideoRendererTest, NoTimestamp) {}

TEST_F(PaintCanvasVideoRendererTest, CroppedFrame) {}

uint32_t MaybeConvertABGRToARGB(uint32_t abgr) {}

TEST_F(PaintCanvasVideoRendererTest, CroppedFrameToRGBParallel) {}

TEST_F(PaintCanvasVideoRendererTest, CroppedFrame_NoScaling) {}

TEST_F(PaintCanvasVideoRendererTest, Video_Rotation_90) {}

TEST_F(PaintCanvasVideoRendererTest, Video_Rotation_180) {}

TEST_F(PaintCanvasVideoRendererTest, Video_Rotation_270) {}

TEST_F(PaintCanvasVideoRendererTest, Video_Translate) {}

TEST_F(PaintCanvasVideoRendererTest, Video_Translate_Rotation_90) {}

TEST_F(PaintCanvasVideoRendererTest, Video_Translate_Rotation_180) {}

TEST_F(PaintCanvasVideoRendererTest, Video_Translate_Rotation_270) {}

TEST_F(PaintCanvasVideoRendererTest, HighBitDepth) {}

TEST_F(PaintCanvasVideoRendererTest, Y16) {}

// A reproducer test case for crbug.com/1230409 if run with ASAN enabled.
TEST_F(PaintCanvasVideoRendererTest, Yuv420P12OddWidth) {}

TEST_F(PaintCanvasVideoRendererTest, I420WithFilters) {}

namespace {
class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {};

#if !BUILDFLAG(IS_ANDROID)
void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {}
#endif
}  // namespace

// NOTE: The below test tests behavior when PaintCanvasVideoRenderer is used
// without GPU raster. It is not relevant on Android, where GPU raster is
// always used.
#if !BUILDFLAG(IS_ANDROID)
// Test that PaintCanvasVideoRenderer::Paint doesn't crash when GrContext is
// unable to wrap a video frame texture (eg due to being abandoned).
TEST_F(PaintCanvasVideoRendererTest, ContextLost) {}
#endif

void EmptyCallback(const gpu::SyncToken& sync_token) {}

TEST_F(PaintCanvasVideoRendererTest, CorrectFrameSizeToVisibleRect) {}

TEST_F(PaintCanvasVideoRendererTest, TexImage2D_Y16_RGBA32F) {}

TEST_F(PaintCanvasVideoRendererTest, TexSubImage2D_Y16_R32F) {}

// Fixture for tests that require a GL context as destination.
class PaintCanvasVideoRendererWithGLTest : public testing::Test {};

TEST_F(PaintCanvasVideoRendererWithGLTest, CopyVideoFrameYUVDataToGLTexture) {}

TEST_F(PaintCanvasVideoRendererWithGLTest,
       CopyVideoFrameYUVDataToGLTexture_FlipY) {}

// Checks that we correctly copy a RGBA shared image VideoFrame when using
// CopyVideoFrameYUVDataToGLTexture, including correct cropping.
TEST_F(PaintCanvasVideoRendererWithGLTest,
       CopyVideoFrameTexturesToGLTextureRGBA) {}

// Checks that we correctly copy a RGBA shared image VideoFrame that needs read
// lock fences, when using CopyVideoFrameYUVDataToGLTexture, including correct
// cropping.
TEST_F(PaintCanvasVideoRendererWithGLTest,
       CopyVideoFrameTexturesToGLTextureRGBA_ReadLockFence) {}

// Checks that we correctly paint a RGBA shared image VideoFrame, including
// correct cropping.
TEST_F(PaintCanvasVideoRendererWithGLTest, PaintRGBA) {}

// Checks that we correctly copy an I420 shared image VideoFrame when using
// CopyVideoFrameYUVDataToGLTexture, including correct cropping.
TEST_F(PaintCanvasVideoRendererWithGLTest,
       CopyVideoFrameTexturesToGLTextureI420) {}

// Checks that we correctly paint a I420 shared image VideoFrame, including
// correct cropping.
TEST_F(PaintCanvasVideoRendererWithGLTest, PaintI420) {}

// Checks that we correctly paint a I420 shared image VideoFrame, including
// correct cropping.
TEST_F(PaintCanvasVideoRendererWithGLTest, PaintI420NotSubset) {}

// Checks that we correctly copy a NV12 shared image VideoFrame when using
// CopyVideoFrameYUVDataToGLTexture, including correct cropping.
TEST_F(PaintCanvasVideoRendererWithGLTest,
       CopyVideoFrameTexturesToGLTextureNV12) {}

// Checks that we correctly paint a NV12 shared image VideoFrame, including
// correct cropping.
TEST_F(PaintCanvasVideoRendererWithGLTest, PaintNV12) {}

}  // namespace media