Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TestUtils.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef TestUtils_DEFINED
9#define TestUtils_DEFINED
10
15#include "include/gpu/GrTypes.h"
19
20#include <cstdint>
21#include <functional>
22#include <memory>
23
24class GrDirectContext;
26class GrSurfaceProxy;
27class SkPixmap;
28enum class GrColorType;
29namespace skiatest { class Reporter; }
30namespace skgpu::ganesh {
31class SurfaceContext;
32}
33typedef uint32_t GrColor;
34
35// Ensure that reading back from 'srcContext' as RGBA 8888 matches 'expectedPixelValues
39 uint32_t expectedPixelValues[],
40 const char* testName);
41
42// See if trying to write RGBA 8888 pixels to 'dstContext' matches the
43// expectation ('expectedToWork')
47 bool expectedToWork,
48 const char* testName);
49
50// Ensure that the pixels can be copied from 'proxy' viewed as colorType, to an RGBA 8888
51// destination (both texture-backed and rendertarget-backed).
55 GrSurfaceOrigin origin,
57 uint32_t expectedPixelValues[],
58 const char* testName);
59
60/** Used by compare_pixels. */
61using ComparePixmapsErrorReporter = void(int x, int y, const float diffs[4]);
62
63/**
64 * Compares pixels pointed to by 'a' to pixels pointed to by 'b'.
65 *
66 * If the pixmaps have different dimensions error is called with negative coordinate values and
67 * zero diffs and no comparisons are made.
68 *
69 * Before comparison pixels are converted to a common color type, alpha type, and color space.
70 * The color type is always 32 bit float. The alpha type is premul if one of the pixmaps is
71 * premul and the other is unpremul. The color space is linear sRGB if the pixmaps have
72 * different colorspaces, otherwise their common color space is used.
73 *
74 * 'tolRGBA' expresses the allowed difference between pixels in the comparison space per channel. If
75 * pixel components differ more than by 'tolRGBA' in absolute value in any channel then 'error' is
76 * called with the coordinate and difference in the comparison space (B - A).
77 *
78 * The function quits after a single error is reported and returns false if 'error' was called and
79 * true otherwise.
80 */
81bool ComparePixels(const GrCPixmap& a,
82 const GrCPixmap& b,
83 const float tolRGBA[4],
84 std::function<ComparePixmapsErrorReporter>& error);
85
86/**
87 * Convenience version that checks that 'pixmap' is a solid field of 'col'
88 */
89bool CheckSolidPixels(const SkColor4f& col,
90 const SkPixmap& pixmap,
91 const float tolRGBA[4],
92 std::function<ComparePixmapsErrorReporter>& error);
93
94/**
95 * Checks the ref cnt on a proxy and its backing store. This is only valid if the proxy and the
96 * resource are both used on a single thread.
97 */
99 GrSurfaceProxy* proxy,
100 int32_t expectedProxyRefs,
101 int32_t expectedBackingRefs);
102
103// Makes either a SurfaceContext, SurfaceFillContext, or a SurfaceDrawContext, depending on
104// GrRenderable and the GrImageInfo.
105// The texture format is the default for the provided color type.
106std::unique_ptr<skgpu::ganesh::SurfaceContext> CreateSurfaceContext(
108 const GrImageInfo&,
111 GrRenderable = GrRenderable::kNo,
112 int sampleCount = 1,
113 skgpu::Mipmapped = skgpu::Mipmapped::kNo,
114 GrProtected = GrProtected::kNo,
116
117#endif
reporter
GrColorType
GrSurfaceOrigin
Definition GrTypes.h:147
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
SkBackingFit
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
void TestReadPixels(skiatest::Reporter *, GrDirectContext *, skgpu::ganesh::SurfaceContext *, uint32_t expectedPixelValues[], const char *testName)
Definition TestUtils.cpp:39
void(int x, int y, const float diffs[4]) ComparePixmapsErrorReporter
Definition TestUtils.h:61
std::unique_ptr< skgpu::ganesh::SurfaceContext > CreateSurfaceContext(GrRecordingContext *, const GrImageInfo &, SkBackingFit=SkBackingFit::kExact, GrSurfaceOrigin=kTopLeft_GrSurfaceOrigin, GrRenderable=GrRenderable::kNo, int sampleCount=1, skgpu::Mipmapped=skgpu::Mipmapped::kNo, GrProtected=GrProtected::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
void CheckSingleThreadedProxyRefs(skiatest::Reporter *reporter, GrSurfaceProxy *proxy, int32_t expectedProxyRefs, int32_t expectedBackingRefs)
uint32_t GrColor
Definition TestUtils.h:33
void TestWritePixels(skiatest::Reporter *, GrDirectContext *, skgpu::ganesh::SurfaceContext *, bool expectedToWork, const char *testName)
Definition TestUtils.cpp:66
void TestCopyFromSurface(skiatest::Reporter *, GrDirectContext *, sk_sp< GrSurfaceProxy > proxy, GrSurfaceOrigin origin, GrColorType colorType, uint32_t expectedPixelValues[], const char *testName)
Definition TestUtils.cpp:98
bool ComparePixels(const GrCPixmap &a, const GrCPixmap &b, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
bool CheckSolidPixels(const SkColor4f &col, const SkPixmap &pixmap, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
static bool b
struct MyStruct a[10]
const uint8_t uint32_t uint32_t GError ** error
double y
double x
Budgeted
Definition GpuTypes.h:35
Renderable
Definition GpuTypes.h:69
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61