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 "include/private/GrSurfaceProxy.h" |
| 13 | #include "src/gpu/GrContextPriv.h" |
| 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 | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 32 | kTopLeft_GrSurfaceOrigin, srcBuffer, 0); |
Brian Salomon | 7128fdd | 2017-05-22 14:00:07 -0400 | [diff] [blame] | 33 | REPORTER_ASSERT(reporter, proxy); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 34 | if (proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 35 | sk_sp<GrSurfaceContext> sContext = context->priv().makeWrappedSurfaceContext(proxy); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 36 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 37 | SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 38 | |
| 39 | bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0); |
| 40 | REPORTER_ASSERT(reporter, result); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, |
| 42 | dstBuffer, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 43 | kWidth, |
| 44 | kHeight)); |
| 45 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 46 | dstInfo = SkImageInfo::Make(10, 2, ct, kPremul_SkAlphaType); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 47 | result = sContext->writePixels(dstInfo, srcBuffer, 0, 2, 10); |
| 48 | REPORTER_ASSERT(reporter, result); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 49 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 50 | memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor)); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 51 | |
| 52 | result = sContext->readPixels(dstInfo, dstBuffer, 0, 2, 10); |
| 53 | REPORTER_ASSERT(reporter, result); |
| 54 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 55 | REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, |
| 56 | dstBuffer, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 57 | 10, |
| 58 | 2)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 61 | proxy = sk_gpu_test::MakeTextureProxyFromData(context, renderable, kWidth, kHeight, ct, |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 62 | kBottomLeft_GrSurfaceOrigin, srcBuffer, 0); |
Brian Salomon | 7128fdd | 2017-05-22 14:00:07 -0400 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, proxy); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 64 | if (proxy) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 65 | sk_sp<GrSurfaceContext> sContext = context->priv().makeWrappedSurfaceContext(proxy); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 66 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 67 | SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 68 | |
| 69 | bool result = sContext->readPixels(dstInfo, dstBuffer, 0, 0, 0); |
| 70 | REPORTER_ASSERT(reporter, result); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, |
| 72 | dstBuffer, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 73 | kWidth, |
| 74 | kHeight)); |
| 75 | |
Brian Salomon | 5fba7ad | 2018-03-22 10:01:16 -0400 | [diff] [blame] | 76 | dstInfo = SkImageInfo::Make(4, 5, ct, kPremul_SkAlphaType); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 77 | result = sContext->writePixels(dstInfo, srcBuffer, 0, 5, 4); |
| 78 | REPORTER_ASSERT(reporter, result); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 79 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 80 | memset(dstBuffer, 0, kWidth*kHeight*sizeof(GrColor)); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 81 | |
| 82 | result = sContext->readPixels(dstInfo, dstBuffer, 0, 5, 4); |
| 83 | REPORTER_ASSERT(reporter, result); |
| 84 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 85 | REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(srcBuffer, |
| 86 | dstBuffer, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 87 | 4, |
| 88 | 5)); |
| 89 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
Timothy Liang | a8046af | 2018-07-19 09:58:00 -0400 | [diff] [blame] | 93 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrUploadPixelsTests, reporter, ctxInfo) { |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 94 | // RGBA |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 95 | basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, GrRenderable::kNo); |
| 96 | basic_texture_test(reporter, ctxInfo.grContext(), kRGBA_8888_SkColorType, GrRenderable::kYes); |
Robert Phillips | bab2dbb | 2017-04-17 07:43:27 -0400 | [diff] [blame] | 97 | |
| 98 | // BGRA |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 99 | basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, GrRenderable::kNo); |
| 100 | basic_texture_test(reporter, ctxInfo.grContext(), kBGRA_8888_SkColorType, GrRenderable::kYes); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 101 | } |