#ifdef UNSAFE_BUFFERS_BUILD
#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) { … }
void ReadbackNV12Planes(TestGpuServiceHolder* gpu_service_holder,
CopyOutputResult& result,
const gfx::Size& texture_size,
SkBitmap& out_luma_plane,
SkBitmap& out_chroma_planes) { … }
void ReadbackResultRGBA(TestGpuServiceHolder* gpu_service_holder,
bool is_software,
CopyOutputResult& result,
const gfx::Size& texture_size,
SkBitmap& out_plane) { … }
std::vector<uint8_t> GeneratePixels(size_t num_bytes,
base::span<const uint8_t> pattern) { … }
#endif
}
class ReadbackPixelTest : public VizPixelTest { … };
class ReadbackPixelTestRGBA
: public ReadbackPixelTest,
public testing::WithParamInterface<
std::tuple<RendererType, bool, CopyOutputResult::Destination>> { … };
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_P(ReadbackPixelTestRGBAWithBlit, ExecutesCopyRequestWithBlit) { … }
INSTANTIATE_TEST_SUITE_P(…);
class ReadbackPixelTestNV12
: public ReadbackPixelTest,
public testing::WithParamInterface<
std::tuple<RendererType, bool, CopyOutputResult::Destination>> { … };
TEST_P(ReadbackPixelTestNV12, ExecutesCopyRequest) { … }
INSTANTIATE_TEST_SUITE_P(…);
class ReadbackPixelTestNV12WithBlit
: public ReadbackPixelTest,
public testing::WithParamInterface<
std::tuple<RendererType, bool, LetterboxingBehavior, bool>> { … };
TEST_P(ReadbackPixelTestNV12WithBlit, ExecutesCopyRequestWithBlit) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
}