chromium/components/viz/service/display/readback_pixeltest.cc

// Copyright 2020 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 <memory>
#include <tuple>

#include "base/command_line.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ref.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/bind.h"
#include "base/test/test_switches.h"
#include "build/build_config.h"
#include "cc/test/pixel_test.h"
#include "cc/test/pixel_test_utils.h"
#include "cc/test/resource_provider_test_utils.h"
#include "components/viz/common/frame_sinks/blit_request.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/gpu/context_provider.h"
#include "components/viz/common/resources/shared_image_format.h"
#include "components/viz/service/display/viz_pixel_test.h"
#include "components/viz/service/display_embedder/in_process_gpu_memory_buffer_manager.h"
#include "components/viz/service/display_embedder/skia_output_surface_impl.h"
#include "components/viz/service/gl/gpu_service_impl.h"
#include "components/viz/test/buildflags.h"
#include "components/viz/test/gl_scaler_test_util.h"
#include "components/viz/test/paths.h"
#include "gpu/command_buffer/client/client_shared_image.h"
#include "gpu/command_buffer/client/raster_interface.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/service/shared_context_state.h"
#include "gpu/command_buffer/service/shared_image/shared_image_manager.h"
#include "gpu/command_buffer/service/shared_image/shared_image_representation.h"
#include "gpu/command_buffer/service/skia_utils.h"
#include "gpu/config/gpu_finch_features.h"
#include "media/base/media_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkYUVAPixmaps.h"
#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/color_transform.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

namespace viz {
namespace {

#if !BUILDFLAG(IS_ANDROID)
constexpr float kAvgAbsoluteErrorLimit =;
constexpr int kMaxAbsoluteErrorLimit =;

cc::FuzzyPixelComparator GetDefaultFuzzyPixelComparator() {}
#endif

base::FilePath GetTestFilePath(const base::FilePath::CharType* basename) {}

SharedQuadState* CreateSharedQuadState(AggregatedRenderPass* render_pass,
                                       const gfx::Rect& rect) {}

base::span<const uint8_t> MakePixelSpan(const SkBitmap& bitmap) {}

void DeleteSharedImage(
    scoped_refptr<RasterContextProvider> context_provider,
    scoped_refptr<gpu::ClientSharedImage> client_shared_image,
    const gpu::SyncToken& sync_token,
    bool is_lost) {}

#if !BUILDFLAG(IS_ANDROID)
struct ReadbackTextureInfo {};

size_t GetRowBytesForColorType(int width, SkColorType color_type) {}

void ReadbackTexturesOnGpuThread(
    gpu::SharedImageManager* shared_image_manager,
    gpu::SharedContextState* context_state,
    const gpu::Mailbox& mailbox,
    base::span<ReadbackTextureInfo> readback_texture_infos) {}

// Reads back NV12 planes from textures returned in the result.
// Will issue a task to the GPU thread and block on its completion.
// The |texture_size| needs to be passed in explicitly, because if the request
// was issued with an appended BlitRequest, the |result->size()| only describes
// the size of the region that was populated in the caller-provided textures,
// *not* the entire texture.
void ReadbackNV12Planes(TestGpuServiceHolder* gpu_service_holder,
                        CopyOutputResult& result,
                        const gfx::Size& texture_size,
                        SkBitmap& out_luma_plane,
                        SkBitmap& out_chroma_planes) {}

// Readback RGBA CopyOutputResult from texture into `out_plane`.
void ReadbackResultRGBA(TestGpuServiceHolder* gpu_service_holder,
                        bool is_software,
                        CopyOutputResult& result,
                        const gfx::Size& texture_size,
                        SkBitmap& out_plane) {}

// Generates a sequence of bytes of specified length, using the given pattern.
// The pattern will be repeated in the generated sequence, and does not have to
// fit in the |num_bytes| evenly. For example, for byte pattern A B C and length
// 7, the result will be: A B C A B C A.
std::vector<uint8_t> GeneratePixels(size_t num_bytes,
                                    base::span<const uint8_t> pattern) {}
#endif  // !BUILDFLAG(IS_ANDROID)

}  // namespace

// Superclass providing common functionality to ReadbackPixelTest variants.
class ReadbackPixelTest : public VizPixelTest {};

class ReadbackPixelTestRGBA
    : public ReadbackPixelTest,
      public testing::WithParamInterface<
          std::tuple<RendererType, bool, CopyOutputResult::Destination>> {};

// Test that RGBA readback works correctly.
TEST_P(ReadbackPixelTestRGBA, ExecutesCopyRequest) {}

INSTANTIATE_TEST_SUITE_P();
#endif

#if !BUILDFLAG(IS_ANDROID)
class ReadbackPixelTestRGBAWithBlit
    : public ReadbackPixelTest,
      public testing::WithParamInterface<
          std::tuple<RendererType, bool, LetterboxingBehavior, bool>> {};

// Test that RGBA readback works correctly using existing textures.
TEST_P(ReadbackPixelTestRGBAWithBlit, ExecutesCopyRequestWithBlit) {}

INSTANTIATE_TEST_SUITE_P();

// Tests of NV12.

// NOTE: These tests don't run on Android. Android doesn't use NV12 GMB and
// doesn't support the MultiPlane:: kNV12 format.
class ReadbackPixelTestNV12
    : public ReadbackPixelTest,
      public testing::WithParamInterface<
          std::tuple<RendererType, bool, CopyOutputResult::Destination>> {};

// Test that NV12 readback works correctly.
TEST_P(ReadbackPixelTestNV12, ExecutesCopyRequest) {}

INSTANTIATE_TEST_SUITE_P();

class ReadbackPixelTestNV12WithBlit
    : public ReadbackPixelTest,
      public testing::WithParamInterface<
          std::tuple<RendererType, bool, LetterboxingBehavior, bool>> {};

// Test that NV12 readback works correctly using existing textures.
TEST_P(ReadbackPixelTestNV12WithBlit, ExecutesCopyRequestWithBlit) {}

INSTANTIATE_TEST_SUITE_P();
#endif  // !BUILDFLAG(IS_ANDROID)

}  // namespace viz