blob: 91e740a76f2801ed4681b198e8786d24520aa5c1 [file] [log] [blame]
Robert Phillips3500b772017-01-27 10:11:42 -05001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkBitmap.h"
Brian Salomon85aeccf2019-07-15 12:30:44 -04009#include "src/gpu/GrDataUtils.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "tests/Test.h"
Robert Phillips3500b772017-01-27 10:11:42 -050011
Robert Phillips3500b772017-01-27 10:11:42 -050012class GrSurfaceContext;
13class GrSurfaceProxy;
Timothy Liang760dbc42018-07-17 13:28:20 -040014typedef uint32_t GrColor;
Robert Phillips3500b772017-01-27 10:11:42 -050015
16// Ensure that reading back from 'srcContext' as RGBA 8888 matches 'expectedPixelValues
Brian Salomon28a8f282019-10-24 20:07:39 -040017void TestReadPixels(skiatest::Reporter*, GrSurfaceContext* srcContext,
18 uint32_t expectedPixelValues[], const char* testName);
Robert Phillips3500b772017-01-27 10:11:42 -050019
20// See if trying to write RGBA 8888 pixels to 'dstContext' matches matches the
21// expectation ('expectedToWork')
Brian Salomon28a8f282019-10-24 20:07:39 -040022void TestWritePixels(skiatest::Reporter*, GrSurfaceContext* srcContext, bool expectedToWork,
23 const char* testName);
Robert Phillips3500b772017-01-27 10:11:42 -050024
Brian Salomond6287472019-06-24 15:50:07 -040025// Ensure that the pixels can be copied from 'proxy' viewed as colorType, to an RGBA 8888
26// destination (both texture-backed and rendertarget-backed).
Robert Phillipseffd13f2020-07-20 15:00:36 -040027void TestCopyFromSurface(skiatest::Reporter*, GrRecordingContext*, GrSurfaceProxy* proxy,
Greg Daniel40903af2020-01-30 14:55:05 -050028 GrSurfaceOrigin origin, GrColorType colorType,
29 uint32_t expectedPixelValues[], const char* testName);
Timothy Liang760dbc42018-07-17 13:28:20 -040030
31// Fills data with a red-green gradient
Brian Salomon28a8f282019-10-24 20:07:39 -040032void FillPixelData(int width, int height, GrColor* data);
Timothy Liang760dbc42018-07-17 13:28:20 -040033
Greg Danielc1ad77c2020-05-06 11:40:03 -040034// Create a solid colored backend texture and syncs the CPU to wait for upload to finish
Robert Phillipseffd13f2020-07-20 15:00:36 -040035bool CreateBackendTexture(GrDirectContext*,
Greg Danielc1ad77c2020-05-06 11:40:03 -040036 GrBackendTexture* backendTex,
37 int width, int height,
38 SkColorType colorType,
39 const SkColor4f& color,
Robert Phillipseffd13f2020-07-20 15:00:36 -040040 GrMipMapped,
41 GrRenderable,
Greg Danielc1ad77c2020-05-06 11:40:03 -040042 GrProtected = GrProtected::kNo);
43
Robert Phillipseffd13f2020-07-20 15:00:36 -040044bool CreateBackendTexture(GrDirectContext*,
Brian Salomon28a8f282019-10-24 20:07:39 -040045 GrBackendTexture* backendTex,
46 const SkImageInfo& ii,
47 const SkColor4f& color,
48 GrMipMapped,
Greg Danielc1ad77c2020-05-06 11:40:03 -040049 GrRenderable,
50 GrProtected = GrProtected::kNo);
Robert Phillipsee5fd132019-05-07 13:29:22 -040051
Robert Phillipseffd13f2020-07-20 15:00:36 -040052void DeleteBackendTexture(GrDirectContext*, const GrBackendTexture& backendTex);
Robert Phillipsee5fd132019-05-07 13:29:22 -040053
Timothy Liang760dbc42018-07-17 13:28:20 -040054// Checks srcBuffer and dstBuffer contain the same colors
Brian Salomon28a8f282019-10-24 20:07:39 -040055bool DoesFullBufferContainCorrectColor(const GrColor* srcBuffer,
56 const GrColor* dstBuffer,
57 int width, int height);
Michael Ludwige8e10752018-10-01 12:42:53 -040058
59// Encodes the bitmap into a data:/image/png;base64,... url suitable to view in a browser after
60// printing to a log. If false is returned, dst holds an error message instead of a URI.
Brian Salomon28a8f282019-10-24 20:07:39 -040061bool BipmapToBase64DataURI(const SkBitmap& bitmap, SkString* dst);
Brian Salomon85aeccf2019-07-15 12:30:44 -040062
63/** Used by compare_pixels. */
64using ComparePixmapsErrorReporter = void(int x, int y, const float diffs[4]);
65
66/**
67 * Compares pixels pointed to by 'a' with 'infoA' and rowBytesA to pixels pointed to by 'b' with
68 * 'infoB' and 'rowBytesB'.
69 *
70 * If the infos have different dimensions error is called with negative coordinate values and
71 * zero diffs and no comparisons are made.
72 *
73 * Before comparison pixels are converted to a common color type, alpha type, and color space.
74 * The color type is always 32 bit float. The alpha type is premul if one of 'infoA' and 'infoB' is
75 * premul and the other is unpremul. The color space is linear sRGB if 'infoA' and 'infoB' have
76 * different colorspaces, otherwise their common color space is used.
77 *
78 * 'tolRGBA' expresses the allowed difference between pixels in the comparison space per channel. If
79 * pixel components differ more than by 'tolRGBA' in absolute value in any channel then 'error' is
80 * called with the coordinate and difference in the comparison space (B - A).
81 *
82 * The function quits after a single error is reported and returns false if 'error' was called and
83 * true otherwise.
84 */
Brian Salomon28a8f282019-10-24 20:07:39 -040085bool ComparePixels(const GrImageInfo& infoA, const char* a, size_t rowBytesA,
86 const GrImageInfo& infoB, const char* b, size_t rowBytesB,
87 const float tolRGBA[4], std::function<ComparePixmapsErrorReporter>& error);
Brian Salomon85aeccf2019-07-15 12:30:44 -040088
89/** Convenience version of above that takes SkPixmap inputs. */
Brian Salomon28a8f282019-10-24 20:07:39 -040090bool ComparePixels(const SkPixmap& a, const SkPixmap& b, const float tolRGBA[4],
91 std::function<ComparePixmapsErrorReporter>& error);
Robert Phillipse3b6fe42019-09-11 11:26:46 -040092
93/**
94 * Convenience version that checks that 'pixmap' is a solid field of 'col'
95 */
Brian Salomon28a8f282019-10-24 20:07:39 -040096bool CheckSolidPixels(const SkColor4f& col,
97 const SkPixmap& pixmap,
98 const float tolRGBA[4],
99 std::function<ComparePixmapsErrorReporter>& error);
Brian Salomon557e8122019-10-24 10:37:08 -0400100
101/**
102 * Checks the ref cnt on a proxy and its backing store. This is only valid if the proxy and the
103 * resource are both used on a single thread.
104 */
Brian Salomon28a8f282019-10-24 20:07:39 -0400105void CheckSingleThreadedProxyRefs(skiatest::Reporter* reporter,
Greg Danield11ae2e2020-02-10 16:36:07 -0500106 GrSurfaceProxy* proxy,
Brian Salomon28a8f282019-10-24 20:07:39 -0400107 int32_t expectedProxyRefs,
108 int32_t expectedBackingRefs);