Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkBitmap.h" |
Brian Salomon | 85aeccf | 2019-07-15 12:30:44 -0400 | [diff] [blame] | 9 | #include "src/gpu/GrDataUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 11 | |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 12 | class GrSurfaceContext; |
| 13 | class GrSurfaceProxy; |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 14 | typedef uint32_t GrColor; |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 15 | |
| 16 | // Ensure that reading back from 'srcContext' as RGBA 8888 matches 'expectedPixelValues |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 17 | void test_read_pixels(skiatest::Reporter*, GrSurfaceContext* srcContext, |
| 18 | uint32_t expectedPixelValues[], const char* testName); |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 19 | |
| 20 | // See if trying to write RGBA 8888 pixels to 'dstContext' matches matches the |
| 21 | // expectation ('expectedToWork') |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 22 | void test_write_pixels(skiatest::Reporter*, GrSurfaceContext* srcContext, bool expectedToWork, |
| 23 | const char* testName); |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 24 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 25 | // Ensure that the pixels can be copied from 'proxy' viewed as colorType, to an RGBA 8888 |
| 26 | // destination (both texture-backed and rendertarget-backed). |
| 27 | void test_copy_from_surface(skiatest::Reporter*, GrContext*, GrSurfaceProxy* proxy, |
| 28 | GrColorType colorType, uint32_t expectedPixelValues[], |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 29 | const char* testName); |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 30 | |
| 31 | // Fills data with a red-green gradient |
| 32 | void fill_pixel_data(int width, int height, GrColor* data); |
| 33 | |
Robert Phillips | ee5fd13 | 2019-05-07 13:29:22 -0400 | [diff] [blame] | 34 | // Create a solid colored backend texture |
| 35 | bool create_backend_texture(GrContext*, GrBackendTexture* backendTex, |
Robert Phillips | 4d87b2b | 2019-07-23 13:44:16 -0400 | [diff] [blame] | 36 | const SkImageInfo& ii, const SkColor4f& color, |
| 37 | GrMipMapped, GrRenderable); |
Robert Phillips | ee5fd13 | 2019-05-07 13:29:22 -0400 | [diff] [blame] | 38 | |
| 39 | void delete_backend_texture(GrContext*, const GrBackendTexture& backendTex); |
| 40 | |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 41 | // Checks srcBuffer and dstBuffer contain the same colors |
Robert Phillips | cb1adb4 | 2019-06-10 15:09:34 -0400 | [diff] [blame] | 42 | bool does_full_buffer_contain_correct_color(const GrColor* srcBuffer, const GrColor* dstBuffer, |
| 43 | int width, int height); |
Michael Ludwig | e8e1075 | 2018-10-01 12:42:53 -0400 | [diff] [blame] | 44 | |
| 45 | // Encodes the bitmap into a data:/image/png;base64,... url suitable to view in a browser after |
| 46 | // printing to a log. If false is returned, dst holds an error message instead of a URI. |
| 47 | bool bitmap_to_base64_data_uri(const SkBitmap& bitmap, SkString* dst); |
Brian Salomon | 85aeccf | 2019-07-15 12:30:44 -0400 | [diff] [blame] | 48 | |
| 49 | /** Used by compare_pixels. */ |
| 50 | using ComparePixmapsErrorReporter = void(int x, int y, const float diffs[4]); |
| 51 | |
| 52 | /** |
| 53 | * Compares pixels pointed to by 'a' with 'infoA' and rowBytesA to pixels pointed to by 'b' with |
| 54 | * 'infoB' and 'rowBytesB'. |
| 55 | * |
| 56 | * If the infos have different dimensions error is called with negative coordinate values and |
| 57 | * zero diffs and no comparisons are made. |
| 58 | * |
| 59 | * Before comparison pixels are converted to a common color type, alpha type, and color space. |
| 60 | * The color type is always 32 bit float. The alpha type is premul if one of 'infoA' and 'infoB' is |
| 61 | * premul and the other is unpremul. The color space is linear sRGB if 'infoA' and 'infoB' have |
| 62 | * different colorspaces, otherwise their common color space is used. |
| 63 | * |
| 64 | * 'tolRGBA' expresses the allowed difference between pixels in the comparison space per channel. If |
| 65 | * pixel components differ more than by 'tolRGBA' in absolute value in any channel then 'error' is |
| 66 | * called with the coordinate and difference in the comparison space (B - A). |
| 67 | * |
| 68 | * The function quits after a single error is reported and returns false if 'error' was called and |
| 69 | * true otherwise. |
| 70 | */ |
| 71 | bool compare_pixels(const GrPixelInfo& infoA, const char* a, size_t rowBytesA, |
| 72 | const GrPixelInfo& infoB, const char* b, size_t rowBytesB, |
| 73 | const float tolRGBA[4], std::function<ComparePixmapsErrorReporter>& error); |
| 74 | |
| 75 | /** Convenience version of above that takes SkPixmap inputs. */ |
| 76 | bool compare_pixels(const SkPixmap& a, const SkPixmap& b, const float tolRGBA[4], |
| 77 | std::function<ComparePixmapsErrorReporter>& error); |
Robert Phillips | e3b6fe4 | 2019-09-11 11:26:46 -0400 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Convenience version that checks that 'pixmap' is a solid field of 'col' |
| 81 | */ |
| 82 | bool check_solid_pixels(const SkColor4f& col, const SkPixmap& pixmap, |
| 83 | const float tolRGBA[4], std::function<ComparePixmapsErrorReporter>& error); |