42 uint32_t expectedPixelValues[],
43 const char* testName) {
44 int pixelCnt = srcContext->
width() * srcContext->
height();
57 for (
int i = 0; i < pixelCnt; ++i) {
58 if (pm.
addr32()[i] != expectedPixelValues[i]) {
59 ERRORF(
reporter,
"%s: Error, pixel value %d should be 0x%08x, got 0x%08x.",
60 testName, i, expectedPixelValues[i], pm.
addr32()[i]);
70 const char* testName) {
76 for (
int y = 0;
y < dstContext->
height(); ++
y) {
77 for (
int x = 0;
x < dstContext->
width(); ++
x) {
90 if (
write && !expectedToWork) {
91 ERRORF(
reporter,
"%s: writePixels succeeded when it wasn't supposed to.", testName);
103 uint32_t expectedPixelValues[],
104 const char* testName) {
108 skgpu::Mipmapped::kNo,
111 "CopyFromSurface_Test");
115 auto dstContext = dContext->
priv().
makeSC(std::move(view),
125 const float tolRGBA[4],
126 std::function<ComparePixmapsErrorReporter>&
error) {
129 for (
int i = 0; i < 4; ++i) {
130 diffs[i] = rgbaB[i] - rgbaA[i];
131 if (std::abs(diffs[i]) > std::abs(tolRGBA[i])) {
144 const float tolRGBA[4],
145 std::function<ComparePixmapsErrorReporter>&
error) {
146 if (
a.dimensions() !=
b.dimensions()) {
147 static constexpr float kEmptyDiffs[4] = {};
148 error(-1, -1, kEmptyDiffs);
160 floatCS =
a.refColorSpace();
175 auto at = [rb = floatA.
rowBytes()](
const void*
base,
int x,
int y) {
176 return SkTAddOffset<const float>(
base,
y*rb +
x*
sizeof(
float)*4);
179 for (
int y = 0;
y < floatA.
height(); ++
y) {
180 for (
int x = 0;
x < floatA.
width(); ++
x) {
181 const float* rgbaA = at(floatA.
addr(),
x,
y);
182 const float* rgbaB = at(floatB.
addr(),
x,
y);
193 const float tolRGBA[4],
194 std::function<ComparePixmapsErrorReporter>&
error) {
205 GrCPixmap srcPixmap(srcInfo, col.vec(), floatBpp);
212 size_t floatRowBytes = floatBpp * pixmap.
width();
213 std::unique_ptr<char[]> floatB(
new char[floatRowBytes * pixmap.
height()]);
218 for (
int y = 0;
y < f32Pixmap.
height(); ++
y) {
219 for (
int x = 0;
x < f32Pixmap.
width(); ++
x) {
220 auto rgbaA = SkTAddOffset<const float>(f32Pixmap.
addr(),
222 auto rgbaB =
static_cast<const float*
>(colorPixmap.
addr());
233 int32_t expectedProxyRefs,
234 int32_t expectedBackingRefs) {
235 int32_t actualBackingRefs = proxy->testingOnly_getBackingRefCnt();
274 UnicharGen(
int step) : fU(0), fStep(
step) {}
288 for (
int i = 0; i < 500; ++i) {
292 int index = cache.findGlyphIndex(c);
294 index = cache.findGlyphIndex(c);
297 cache.insertCharAndGlyph(~index, c, glyph);
299 UnicharGen gen2(
step);
300 for (
int j = 0; j <= i; ++j) {
303 index = cache.findGlyphIndex(c);
304 if ((
unsigned)index != glyph) {
305 index = cache.findGlyphIndex(c);
static int step(int x, SkScalar min, SkScalar max)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
bool GrConvertPixels(const GrPixmap &dst, const GrCPixmap &src, bool flipY)
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
static float next(float f)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
#define SkAssertResult(cond)
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
constexpr SkColor SK_ColorTRANSPARENT
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
static bool read(SkStream *stream, void *buffer, size_t amount)
static GrColor SkColorToPremulGrColor(SkColor c)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
constexpr uint16_t SkToU16(S x)
std::unique_ptr< skgpu::ganesh::SurfaceContext > CreateSurfaceContext(GrRecordingContext *rContext, const GrImageInfo &info, SkBackingFit fit, GrSurfaceOrigin origin, GrRenderable renderable, int sampleCount, skgpu::Mipmapped mipmapped, GrProtected isProtected, skgpu::Budgeted budgeted)
static bool compare_colors(int x, int y, const float rgbaA[], const float rgbaB[], const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
void CheckSingleThreadedProxyRefs(skiatest::Reporter *reporter, GrSurfaceProxy *proxy, int32_t expectedProxyRefs, int32_t expectedBackingRefs)
void TestReadPixels(skiatest::Reporter *reporter, GrDirectContext *dContext, skgpu::ganesh::SurfaceContext *srcContext, uint32_t expectedPixelValues[], const char *testName)
static SkGlyphID hash_to_glyph(uint32_t value)
void TestWritePixels(skiatest::Reporter *reporter, GrDirectContext *dContext, skgpu::ganesh::SurfaceContext *dstContext, bool expectedToWork, const char *testName)
void TestCopyFromSurface(skiatest::Reporter *reporter, GrDirectContext *dContext, sk_sp< GrSurfaceProxy > proxy, GrSurfaceOrigin origin, GrColorType colorType, uint32_t expectedPixelValues[], const char *testName)
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)
#define DEF_TEST(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
const GrCaps * caps() const
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
GrDirectContextPriv priv()
GrImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
GrImageInfo makeAlphaType(SkAlphaType at) const
static GrPixmap Allocate(const GrImageInfo &info)
std::unique_ptr< skgpu::ganesh::SurfaceContext > makeSC(GrSurfaceProxyView readView, const GrColorInfo &)
GrRecordingContextPriv priv()
static sk_sp< GrSurfaceProxy > Copy(GrRecordingContext *, sk_sp< GrSurfaceProxy > src, GrSurfaceOrigin, skgpu::Mipmapped, SkIRect srcRect, SkBackingFit, skgpu::Budgeted, std::string_view label, RectsMustMatch=RectsMustMatch::kNo, sk_sp< GrRenderTask > *outTask=nullptr)
void alloc(const SkImageInfo &)
static bool Equals(const SkColorSpace *, const SkColorSpace *)
static sk_sp< SkColorSpace > MakeSRGBLinear()
bool refCntGreaterThan(int32_t threadIsolatedTestCnt) const
const uint32_t * addr32() const
bool erase(SkColor color, const SkIRect &subset) const
const SkImageInfo & info() const
uint32_t * writable_addr32(int x, int y) const
sk_sp< SkColorSpace > refColorSpace() const
SkAlphaType alphaType() const
bool readPixels(GrDirectContext *dContext, GrPixmap dst, SkIPoint srcPt)
SkISize dimensions() const
bool writePixels(GrDirectContext *dContext, GrCPixmap src, SkIPoint dstPt)
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
void write(SkWStream *wStream, const T &text)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkImageInfo makeColorType(SkColorType newColorType) const