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