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" |
| 9 | #include "tests/Test.h" |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 10 | |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 11 | class GrSurfaceContext; |
| 12 | class GrSurfaceProxy; |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 13 | typedef uint32_t GrColor; |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 14 | |
| 15 | // Ensure that reading back from 'srcContext' as RGBA 8888 matches 'expectedPixelValues |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 16 | void test_read_pixels(skiatest::Reporter*, |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 17 | GrSurfaceContext* srcContext, uint32_t expectedPixelValues[], |
| 18 | const char* testName); |
| 19 | |
| 20 | // See if trying to write RGBA 8888 pixels to 'dstContext' matches matches the |
| 21 | // expectation ('expectedToWork') |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 22 | void test_write_pixels(skiatest::Reporter*, |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 23 | GrSurfaceContext* srcContext, bool expectedToWork, const char* testName); |
| 24 | |
| 25 | // Ensure that the pixels can be copied from 'proxy' to an RGBA 8888 destination (both |
| 26 | // texture-backed and rendertarget-backed). |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 27 | void test_copy_from_surface(skiatest::Reporter*, GrContext*, |
Robert Phillips | 3500b77 | 2017-01-27 10:11:42 -0500 | [diff] [blame] | 28 | GrSurfaceProxy* proxy, 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, |
| 36 | const SkImageInfo& ii, GrMipMapped mipMapped, SkColor color, |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 37 | 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 |
| 42 | bool does_full_buffer_contain_correct_color(GrColor* srcBuffer, GrColor* dstBuffer, int width, |
| 43 | 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); |