Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 8 | // This is a GPU-backend specific test. It relies on static intializers to work |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkTypes.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrImageInfo.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrSurfaceProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/SkGr.h" |
| 16 | #include "tests/Test.h" |
| 17 | #include "tests/TestUtils.h" |
| 18 | #include "tools/gpu/GrContextFactory.h" |
| 19 | #include "tools/gpu/ProxyUtils.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 20 | |
kkinnunen | 2ae4b2e | 2016-03-31 08:08:20 -0700 | [diff] [blame] | 21 | using sk_gpu_test::GrContextFactory; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 22 | |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 23 | void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct, |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 24 | GrRenderable renderable) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 25 | const int kWidth = 16; |
| 26 | const int kHeight = 16; |
| 27 | SkAutoTMalloc<GrColor> srcBuffer(kWidth*kHeight); |
| 28 | SkAutoTMalloc<GrColor> dstBuffer(kWidth*kHeight); |
| 29 | |
| 30 | fill_pixel_data(kWidth, kHeight, srcBuffer.get()); |
| 31 | |
Brian Salomon | 4eda710 | 2019-10-21 15:04:52 -0400 | [diff] [blame] | 32 | auto grCT = SkColorTypeToGrColorType(ct); |
| 33 | auto proxy = sk_gpu_test::MakeTextureProxyFromData( |
| 34 | context, renderable, kTopLeft_GrSurfaceOrigin, |
| 35 | {grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0); |
Brian Salomon | 7128fdd | 2017-05-22 14:00:07 -0400 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, proxy); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 37 | if (proxy) { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 38 | auto sContext = context->priv().makeWrappedSurfaceContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 39 | proxy, SkColorTypeToGrColorType(ct), kPremul_SkAlphaType); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 40 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 41 | SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 42 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 43 | bool result = sContext->readPixels(dstInfo, dstBuffer, 0, {0, 0}); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, result); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 45 | REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, |
| 46 | dstBuffer, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 47 | kWidth, |
| 48 | kHeight)); |
| 49 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 50 | dstInfo = SkImageInfo::Make(10, 2, ct, kPremul_SkAlphaType); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 51 | result = sContext->writePixels(dstInfo, srcBuffer, 0, {2, 10}); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 52 | REPORTER_ASSERT(reporter, result); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 53 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 54 | memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor)); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 55 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 56 | result = sContext->readPixels(dstInfo, dstBuffer, 0, {2, 10}); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 57 | REPORTER_ASSERT(reporter, result); |
| 58 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 59 | REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, |
| 60 | dstBuffer, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 61 | 10, |
| 62 | 2)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 63 | } |
| 64 | |
Brian Salomon | 4eda710 | 2019-10-21 15:04:52 -0400 | [diff] [blame] | 65 | proxy = sk_gpu_test::MakeTextureProxyFromData( |
| 66 | context, renderable, kBottomLeft_GrSurfaceOrigin, |
| 67 | {grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0); |
Brian Salomon | 7128fdd | 2017-05-22 14:00:07 -0400 | [diff] [blame] | 68 | REPORTER_ASSERT(reporter, proxy); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 69 | if (proxy) { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 70 | auto sContext = context->priv().makeWrappedSurfaceContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 71 | proxy, SkColorTypeToGrColorType(ct), kPremul_SkAlphaType); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 72 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 73 | SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 74 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 75 | bool result = sContext->readPixels(dstInfo, dstBuffer, 0, {0, 0}); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, result); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 77 | REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, |
| 78 | dstBuffer, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 79 | kWidth, |
| 80 | kHeight)); |
| 81 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 82 | dstInfo = SkImageInfo::Make(4, 5, ct, kPremul_SkAlphaType); |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 83 | result = sContext->writePixels(dstInfo, srcBuffer, 0, {5, 4}); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 84 | REPORTER_ASSERT(reporter, result); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 85 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 86 | memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor)); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 87 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 88 | result = sContext->readPixels(dstInfo, dstBuffer, 0, {5, 4}); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 89 | REPORTER_ASSERT(reporter, result); |
| 90 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 91 | REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, |
| 92 | dstBuffer, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 93 | 4, |
| 94 | 5)); |
| 95 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Timothy Liang | a8046af | 2018-07-19 09:58:00 -0400 | [diff] [blame] | 99 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrUploadPixelsTests, reporter, ctxInfo) { |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 100 | // RGBA |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 101 | basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, GrRenderable::kNo); |
| 102 | basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, GrRenderable::kYes); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 103 | |
| 104 | // BGRA |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 105 | basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, GrRenderable::kNo); |
| 106 | basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, GrRenderable::kYes); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 107 | } |