2017-01-27 15:11:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-10-06 14:07:38 +00:00
|
|
|
#ifndef TestUtils_DEFINED
|
|
|
|
#define TestUtils_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-07-15 16:30:44 +00:00
|
|
|
#include "src/gpu/GrDataUtils.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2017-01-27 15:11:42 +00:00
|
|
|
|
|
|
|
class GrSurfaceContext;
|
|
|
|
class GrSurfaceProxy;
|
2018-07-17 17:28:20 +00:00
|
|
|
typedef uint32_t GrColor;
|
2017-01-27 15:11:42 +00:00
|
|
|
|
|
|
|
// Ensure that reading back from 'srcContext' as RGBA 8888 matches 'expectedPixelValues
|
2020-08-11 16:02:22 +00:00
|
|
|
void TestReadPixels(skiatest::Reporter*, GrDirectContext*, GrSurfaceContext* srcContext,
|
2019-10-25 00:07:39 +00:00
|
|
|
uint32_t expectedPixelValues[], const char* testName);
|
2017-01-27 15:11:42 +00:00
|
|
|
|
|
|
|
// See if trying to write RGBA 8888 pixels to 'dstContext' matches matches the
|
|
|
|
// expectation ('expectedToWork')
|
2020-08-11 16:02:22 +00:00
|
|
|
void TestWritePixels(skiatest::Reporter*, GrDirectContext*, GrSurfaceContext* srcContext,
|
|
|
|
bool expectedToWork, const char* testName);
|
2017-01-27 15:11:42 +00:00
|
|
|
|
2019-06-24 19:50:07 +00:00
|
|
|
// Ensure that the pixels can be copied from 'proxy' viewed as colorType, to an RGBA 8888
|
|
|
|
// destination (both texture-backed and rendertarget-backed).
|
2021-01-21 15:43:35 +00:00
|
|
|
void TestCopyFromSurface(skiatest::Reporter*,
|
|
|
|
GrDirectContext*,
|
|
|
|
sk_sp<GrSurfaceProxy> proxy,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
GrColorType colorType,
|
|
|
|
uint32_t expectedPixelValues[],
|
|
|
|
const char* testName);
|
2018-07-17 17:28:20 +00:00
|
|
|
|
2018-10-01 16:42:53 +00:00
|
|
|
// Encodes the bitmap into a data:/image/png;base64,... url suitable to view in a browser after
|
|
|
|
// printing to a log. If false is returned, dst holds an error message instead of a URI.
|
2019-10-25 00:07:39 +00:00
|
|
|
bool BipmapToBase64DataURI(const SkBitmap& bitmap, SkString* dst);
|
2019-07-15 16:30:44 +00:00
|
|
|
|
|
|
|
/** Used by compare_pixels. */
|
|
|
|
using ComparePixmapsErrorReporter = void(int x, int y, const float diffs[4]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares pixels pointed to by 'a' with 'infoA' and rowBytesA to pixels pointed to by 'b' with
|
|
|
|
* 'infoB' and 'rowBytesB'.
|
|
|
|
*
|
2021-03-31 18:19:31 +00:00
|
|
|
* If the pixmaps have different dimensions error is called with negative coordinate values and
|
2019-07-15 16:30:44 +00:00
|
|
|
* zero diffs and no comparisons are made.
|
|
|
|
*
|
|
|
|
* Before comparison pixels are converted to a common color type, alpha type, and color space.
|
2021-03-31 18:19:31 +00:00
|
|
|
* The color type is always 32 bit float. The alpha type is premul if one of the pixmaps is
|
|
|
|
* premul and the other is unpremul. The color space is linear sRGB if the pixmaps have
|
2019-07-15 16:30:44 +00:00
|
|
|
* different colorspaces, otherwise their common color space is used.
|
|
|
|
*
|
|
|
|
* 'tolRGBA' expresses the allowed difference between pixels in the comparison space per channel. If
|
|
|
|
* pixel components differ more than by 'tolRGBA' in absolute value in any channel then 'error' is
|
|
|
|
* called with the coordinate and difference in the comparison space (B - A).
|
|
|
|
*
|
|
|
|
* The function quits after a single error is reported and returns false if 'error' was called and
|
|
|
|
* true otherwise.
|
|
|
|
*/
|
2021-03-31 18:19:31 +00:00
|
|
|
bool ComparePixels(const GrCPixmap& a,
|
|
|
|
const GrCPixmap& b,
|
|
|
|
const float tolRGBA[4],
|
2019-10-25 00:07:39 +00:00
|
|
|
std::function<ComparePixmapsErrorReporter>& error);
|
2019-09-11 15:26:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience version that checks that 'pixmap' is a solid field of 'col'
|
|
|
|
*/
|
2019-10-25 00:07:39 +00:00
|
|
|
bool CheckSolidPixels(const SkColor4f& col,
|
|
|
|
const SkPixmap& pixmap,
|
|
|
|
const float tolRGBA[4],
|
|
|
|
std::function<ComparePixmapsErrorReporter>& error);
|
2019-10-24 14:37:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the ref cnt on a proxy and its backing store. This is only valid if the proxy and the
|
|
|
|
* resource are both used on a single thread.
|
|
|
|
*/
|
2019-10-25 00:07:39 +00:00
|
|
|
void CheckSingleThreadedProxyRefs(skiatest::Reporter* reporter,
|
2020-02-10 21:36:07 +00:00
|
|
|
GrSurfaceProxy* proxy,
|
2019-10-25 00:07:39 +00:00
|
|
|
int32_t expectedProxyRefs,
|
|
|
|
int32_t expectedBackingRefs);
|
2020-10-06 14:07:38 +00:00
|
|
|
|
|
|
|
#endif
|