bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 8 | #include <set> |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/core/SkSurface.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 10 | #include "include/gpu/GrDirectContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/core/SkAutoPixmapStorage.h" |
Brian Salomon | 8f7d953 | 2020-12-23 09:16:59 -0500 | [diff] [blame] | 12 | #include "src/core/SkCanvasPriv.h" |
Robert Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 13 | #include "src/core/SkCompressedDataUtils.h" |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrBackendUtils.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrGpu.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrProxyProvider.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrResourceProvider.h" |
Robert Phillips | 1a2e7de | 2021-07-29 11:23:48 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrSurfaceContext.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 22 | #include "src/gpu/GrTexture.h" |
Brian Salomon | 27c4202 | 2021-04-28 12:39:21 -0400 | [diff] [blame] | 23 | #include "src/gpu/SkGr.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "tests/Test.h" |
Robert Phillips | ee5fd13 | 2019-05-07 13:29:22 -0400 | [diff] [blame] | 25 | #include "tests/TestUtils.h" |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 26 | #include "tools/gpu/BackendTextureImageFactory.h" |
| 27 | #include "tools/gpu/ManagedBackendTexture.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 28 | |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 29 | // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture |
| 30 | // and render targets to GrSurface all work as expected. |
Brian Osman | fbe2406 | 2019-04-03 16:04:45 +0000 | [diff] [blame] | 31 | DEF_GPUTEST_FOR_MOCK_CONTEXT(GrSurface, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 32 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 33 | auto resourceProvider = context->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 34 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 35 | static constexpr SkISize kDesc = {256, 256}; |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 36 | auto format = context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 37 | GrRenderable::kYes); |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 38 | sk_sp<GrSurface> texRT1 = |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 39 | resourceProvider->createTexture(kDesc, format, GrRenderable::kYes, 1, GrMipmapped::kNo, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 40 | SkBudgeted::kNo, GrProtected::kNo); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 41 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget()); |
| 43 | REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 45 | texRT1->asTexture()); |
| 46 | REPORTER_ASSERT(reporter, texRT1->asRenderTarget() == |
| 47 | static_cast<GrSurface*>(texRT1->asTexture())); |
| 48 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 49 | static_cast<GrSurface*>(texRT1->asTexture())); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 50 | |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 51 | sk_sp<GrTexture> tex1 = |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 52 | resourceProvider->createTexture(kDesc, format, GrRenderable::kNo, 1, GrMipmapped::kNo, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 53 | SkBudgeted::kNo, GrProtected::kNo); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 54 | REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget()); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 55 | REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture()); |
| 56 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture()); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 57 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 58 | GrBackendTexture backendTex = context->createBackendTexture( |
Robert Phillips | 8062679 | 2019-06-04 07:16:10 -0400 | [diff] [blame] | 59 | 256, 256, kRGBA_8888_SkColorType, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 60 | SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo); |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 61 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 62 | sk_sp<GrSurface> texRT2 = resourceProvider->wrapRenderableBackendTexture( |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 63 | backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 64 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 65 | REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget()); |
| 66 | REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 68 | texRT2->asTexture()); |
| 69 | REPORTER_ASSERT(reporter, texRT2->asRenderTarget() == |
| 70 | static_cast<GrSurface*>(texRT2->asTexture())); |
| 71 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 72 | static_cast<GrSurface*>(texRT2->asTexture())); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 73 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 74 | context->deleteBackendTexture(backendTex); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 77 | // This test checks that the isFormatTexturable and isFormatRenderable are |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 78 | // consistent with createTexture's result. |
| 79 | DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 80 | auto context = ctxInfo.directContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 81 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 82 | GrResourceProvider* resourceProvider = context->priv().resourceProvider(); |
| 83 | const GrCaps* caps = context->priv().caps(); |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 84 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 85 | // TODO: Should only need format here but need to determine compression type from format |
| 86 | // without config. |
Robert Phillips | 48257d7 | 2019-12-16 14:20:53 -0500 | [diff] [blame] | 87 | auto createTexture = [](SkISize dimensions, GrColorType colorType, |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 88 | const GrBackendFormat& format, GrRenderable renderable, |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 89 | GrResourceProvider* rp) -> sk_sp<GrTexture> { |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 90 | SkImage::CompressionType compression = GrBackendFormatToCompressionType(format); |
Robert Phillips | d6df7b5 | 2019-12-13 11:17:46 -0500 | [diff] [blame] | 91 | if (compression != SkImage::CompressionType::kNone) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 92 | if (renderable == GrRenderable::kYes) { |
| 93 | return nullptr; |
| 94 | } |
Robert Phillips | 99dead9 | 2020-01-27 16:11:57 -0500 | [diff] [blame] | 95 | auto size = SkCompressedDataSize(compression, dimensions, nullptr, false); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 96 | auto data = SkData::MakeUninitialized(size); |
| 97 | SkColor4f color = {0, 0, 0, 0}; |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 98 | GrFillInCompressedData(compression, dimensions, GrMipmapped::kNo, |
Robert Phillips | 48257d7 | 2019-12-16 14:20:53 -0500 | [diff] [blame] | 99 | (char*)data->writable_data(), color); |
Robert Phillips | e4720c6 | 2020-01-14 14:33:24 -0500 | [diff] [blame] | 100 | return rp->createCompressedTexture(dimensions, format, SkBudgeted::kNo, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 101 | GrMipmapped::kNo, GrProtected::kNo, data.get()); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 102 | } else { |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 103 | return rp->createTexture(dimensions, format, renderable, 1, GrMipmapped::kNo, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 104 | SkBudgeted::kNo, GrProtected::kNo); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 105 | } |
| 106 | }; |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 107 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 108 | static constexpr SkISize kDims = {64, 64}; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 109 | |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 110 | const std::vector<GrCaps::TestFormatColorTypeCombination>& combos = |
John Stiles | bd3ffa4 | 2020-07-30 20:24:57 -0400 | [diff] [blame] | 111 | caps->getTestingCombinations(); |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 112 | |
John Stiles | bd3ffa4 | 2020-07-30 20:24:57 -0400 | [diff] [blame] | 113 | for (const GrCaps::TestFormatColorTypeCombination& combo : combos) { |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 114 | |
| 115 | SkASSERT(combo.fColorType != GrColorType::kUnknown); |
| 116 | SkASSERT(combo.fFormat.isValid()); |
| 117 | |
| 118 | // Right now Vulkan has two backend formats that support ABGR_4444 (R4G4B4A4 and B4G4R4A4). |
| 119 | // Until we can create textures directly from the backend format this yields some |
| 120 | // ambiguity in what is actually supported and which textures can be created. |
| 121 | if (ctxInfo.backend() == kVulkan_GrBackend && combo.fColorType == GrColorType::kABGR_4444) { |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 122 | continue; |
| 123 | } |
| 124 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 125 | // Check if 'isFormatTexturable' agrees with 'createTexture' and that the mipmap |
| 126 | // support check is working |
| 127 | { |
| 128 | bool isCompressed = caps->isFormatCompressed(combo.fFormat); |
Brian Salomon | 469046c | 2020-03-30 14:21:04 -0400 | [diff] [blame] | 129 | bool isTexturable = caps->isFormatTexturable(combo.fFormat); |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 130 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 131 | sk_sp<GrSurface> tex = createTexture(kDims, combo.fColorType, combo.fFormat, |
| 132 | GrRenderable::kNo, resourceProvider); |
| 133 | REPORTER_ASSERT(reporter, SkToBool(tex) == isTexturable, |
| 134 | "ct:%s format:%s, tex:%d, isTexturable:%d", |
| 135 | GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(), |
| 136 | SkToBool(tex), isTexturable); |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 137 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 138 | // Check that the lack of mipmap support blocks the creation of mipmapped |
| 139 | // proxies |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 140 | bool expectedMipMapability = isTexturable && caps->mipmapSupport() && !isCompressed; |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 141 | |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 142 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 143 | combo.fFormat, kDims, GrRenderable::kNo, 1, GrMipmapped::kYes, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 144 | SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo); |
| 145 | REPORTER_ASSERT(reporter, SkToBool(proxy.get()) == expectedMipMapability, |
| 146 | "ct:%s format:%s, tex:%d, expectedMipMapability:%d", |
| 147 | GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(), |
| 148 | SkToBool(proxy.get()), expectedMipMapability); |
| 149 | } |
| 150 | |
| 151 | // Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' (w/o MSAA) |
| 152 | { |
| 153 | bool isRenderable = caps->isFormatRenderable(combo.fFormat, 1); |
| 154 | |
| 155 | sk_sp<GrSurface> tex = resourceProvider->createTexture( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 156 | kDims, combo.fFormat, GrRenderable::kYes, 1, GrMipmapped::kNo, SkBudgeted::kNo, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 157 | GrProtected::kNo); |
| 158 | REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable, |
| 159 | "ct:%s format:%s, tex:%d, isRenderable:%d", |
| 160 | GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(), |
| 161 | SkToBool(tex), isRenderable); |
| 162 | } |
| 163 | |
| 164 | // Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' w/ MSAA |
| 165 | { |
| 166 | bool isRenderable = caps->isFormatRenderable(combo.fFormat, 2); |
| 167 | |
| 168 | sk_sp<GrSurface> tex = resourceProvider->createTexture( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 169 | kDims, combo.fFormat, GrRenderable::kYes, 2, GrMipmapped::kNo, SkBudgeted::kNo, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 170 | GrProtected::kNo); |
| 171 | REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable, |
| 172 | "ct:%s format:%s, tex:%d, isRenderable:%d", |
| 173 | GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(), |
| 174 | SkToBool(tex), isRenderable); |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | } |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 178 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 179 | #include "src/gpu/GrDrawingManager.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 180 | #include "src/gpu/GrSurfaceProxy.h" |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 181 | |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 182 | // For each context, set it to always clear the textures and then run through all the |
| 183 | // supported formats checking that the textures are actually cleared |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 184 | DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) { |
| 185 | GrContextOptions options = baseOptions; |
| 186 | options.fClearAllTextures = true; |
Robert Phillips | d344284 | 2019-08-02 12:26:22 -0400 | [diff] [blame] | 187 | |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 188 | static constexpr int kSize = 100; |
Robert Phillips | d344284 | 2019-08-02 12:26:22 -0400 | [diff] [blame] | 189 | static constexpr SkColor kClearColor = 0xABABABAB; |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 190 | |
| 191 | const SkImageInfo info = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, |
| 192 | kPremul_SkAlphaType); |
| 193 | |
Robert Phillips | d344284 | 2019-08-02 12:26:22 -0400 | [diff] [blame] | 194 | SkAutoPixmapStorage readback; |
| 195 | readback.alloc(info); |
| 196 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 197 | SkISize desc; |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 198 | desc.fWidth = desc.fHeight = kSize; |
| 199 | |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 200 | for (int ct = 0; ct < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++ct) { |
| 201 | sk_gpu_test::GrContextFactory factory(options); |
| 202 | auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(ct); |
| 203 | if (!sk_gpu_test::GrContextFactory::IsRenderingContext(contextType)) { |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 204 | continue; |
| 205 | } |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 206 | auto dContext = factory.get(contextType); |
| 207 | if (!dContext) { |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 208 | continue; |
| 209 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 210 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 211 | GrProxyProvider* proxyProvider = dContext->priv().proxyProvider(); |
| 212 | const GrCaps* caps = dContext->priv().caps(); |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 213 | |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 214 | const std::vector<GrCaps::TestFormatColorTypeCombination>& combos = |
John Stiles | bd3ffa4 | 2020-07-30 20:24:57 -0400 | [diff] [blame] | 215 | caps->getTestingCombinations(); |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 216 | |
John Stiles | bd3ffa4 | 2020-07-30 20:24:57 -0400 | [diff] [blame] | 217 | for (const GrCaps::TestFormatColorTypeCombination& combo : combos) { |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 218 | |
| 219 | SkASSERT(combo.fColorType != GrColorType::kUnknown); |
| 220 | SkASSERT(combo.fFormat.isValid()); |
| 221 | |
Brian Salomon | 469046c | 2020-03-30 14:21:04 -0400 | [diff] [blame] | 222 | if (!caps->isFormatTexturable(combo.fFormat)) { |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 223 | continue; |
| 224 | } |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 225 | |
Brian Salomon | 614cdab | 2019-09-26 11:04:28 -0400 | [diff] [blame] | 226 | auto checkColor = [reporter](const GrCaps::TestFormatColorTypeCombination& combo, |
| 227 | uint32_t readColor) { |
| 228 | // We expect that if there is no alpha in the src color type and we read it to a |
| 229 | // color type with alpha that we will get one for alpha rather than zero. We used to |
| 230 | // require this but the Intel Iris 6100 on Win 10 test bot doesn't put one in the |
| 231 | // alpha channel when reading back from GL_RG16 or GL_RG16F. So now we allow either. |
Brian Salomon | 2f23ae6 | 2020-03-26 16:17:56 -0400 | [diff] [blame] | 232 | uint32_t channels = GrColorTypeChannelFlags(combo.fColorType); |
| 233 | bool allowAlphaOne = !(channels & kAlpha_SkColorChannelFlag); |
Brian Salomon | 614cdab | 2019-09-26 11:04:28 -0400 | [diff] [blame] | 234 | if (allowAlphaOne) { |
| 235 | if (readColor != 0x00000000 && readColor != 0xFF000000) { |
| 236 | ERRORF(reporter, |
| 237 | "Failed on ct %s format %s 0x%08x is not 0x00000000 or 0xFF000000", |
| 238 | GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(), |
| 239 | readColor); |
| 240 | return false; |
| 241 | } |
| 242 | } else { |
| 243 | if (readColor) { |
| 244 | ERRORF(reporter, "Failed on ct %s format %s 0x%08x != 0x00000000", |
| 245 | GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(), |
| 246 | readColor); |
| 247 | return false; |
| 248 | } |
| 249 | } |
| 250 | return true; |
| 251 | }; |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 252 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 253 | for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) { |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 254 | if (renderable == GrRenderable::kYes && |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 255 | !caps->isFormatAsColorTypeRenderable(combo.fColorType, combo.fFormat)) { |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 256 | continue; |
| 257 | } |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 258 | |
| 259 | for (auto fit : {SkBackingFit::kApprox, SkBackingFit::kExact}) { |
| 260 | |
| 261 | // Does directly allocating a texture clear it? |
| 262 | { |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 263 | auto proxy = proxyProvider->testingOnly_createInstantiatedProxy( |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 264 | {kSize, kSize}, combo.fFormat, renderable, 1, fit, SkBudgeted::kYes, |
| 265 | GrProtected::kNo); |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 266 | if (proxy) { |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 267 | GrSwizzle swizzle = caps->getReadSwizzle(combo.fFormat, |
| 268 | combo.fColorType); |
| 269 | GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin, |
| 270 | swizzle); |
Brian Salomon | 14f99fc | 2020-12-07 12:19:47 -0500 | [diff] [blame] | 271 | GrColorInfo info(combo.fColorType, kPremul_SkAlphaType, nullptr); |
Robert Phillips | 33bf2b5 | 2021-08-02 11:14:38 -0400 | [diff] [blame] | 272 | auto texCtx = dContext->priv().makeSC(std::move(view), info); |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 273 | |
Robert Phillips | d344284 | 2019-08-02 12:26:22 -0400 | [diff] [blame] | 274 | readback.erase(kClearColor); |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 275 | if (texCtx->readPixels(dContext, readback, {0, 0})) { |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 276 | for (int i = 0; i < kSize * kSize; ++i) { |
Brian Salomon | 614cdab | 2019-09-26 11:04:28 -0400 | [diff] [blame] | 277 | if (!checkColor(combo, readback.addr32()[i])) { |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 278 | break; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 284 | dContext->priv().getResourceCache()->purgeUnlockedResources(); |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | // Try creating the texture as a deferred proxy. |
| 288 | { |
Robert Phillips | 1a2e7de | 2021-07-29 11:23:48 -0400 | [diff] [blame] | 289 | GrImageInfo info(combo.fColorType, |
| 290 | GrColorTypeHasAlpha(combo.fColorType) |
| 291 | ? kPremul_SkAlphaType |
| 292 | : kOpaque_SkAlphaType, |
| 293 | nullptr, |
| 294 | {desc.fHeight, desc.fHeight}); |
| 295 | |
| 296 | auto sc = GrSurfaceContext::Make(dContext, |
| 297 | info, |
| 298 | combo.fFormat, |
| 299 | fit, |
| 300 | kTopLeft_GrSurfaceOrigin, |
| 301 | renderable); |
| 302 | if (!sc) { |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 303 | continue; |
| 304 | } |
Robert Phillips | ffe2729 | 2019-08-01 10:08:07 -0400 | [diff] [blame] | 305 | |
Robert Phillips | d344284 | 2019-08-02 12:26:22 -0400 | [diff] [blame] | 306 | readback.erase(kClearColor); |
Robert Phillips | 1a2e7de | 2021-07-29 11:23:48 -0400 | [diff] [blame] | 307 | if (sc->readPixels(dContext, readback, {0, 0})) { |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 308 | for (int i = 0; i < kSize * kSize; ++i) { |
Brian Salomon | 614cdab | 2019-09-26 11:04:28 -0400 | [diff] [blame] | 309 | if (!checkColor(combo, readback.addr32()[i])) { |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 310 | break; |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 311 | } |
| 312 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 313 | } |
Michael Ludwig | 9d1cc05 | 2021-06-09 20:49:48 -0400 | [diff] [blame] | 314 | dContext->priv().getResourceCache()->purgeUnlockedResources(); |
Greg Daniel | 90f28ec | 2017-09-25 12:26:58 -0400 | [diff] [blame] | 315 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | } |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 321 | |
| 322 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) { |
Robert Phillips | cb1adb4 | 2019-06-10 15:09:34 -0400 | [diff] [blame] | 323 | auto fillPixels = [](SkPixmap* p, const std::function<uint32_t(int x, int y)>& f) { |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 324 | for (int y = 0; y < p->height(); ++y) { |
| 325 | for (int x = 0; x < p->width(); ++x) { |
| 326 | *p->writable_addr32(x, y) = f(x, y); |
| 327 | } |
| 328 | } |
| 329 | }; |
| 330 | |
| 331 | auto comparePixels = [](const SkPixmap& p1, const SkPixmap& p2, skiatest::Reporter* reporter) { |
| 332 | SkASSERT(p1.info() == p2.info()); |
| 333 | for (int y = 0; y < p1.height(); ++y) { |
| 334 | for (int x = 0; x < p1.width(); ++x) { |
| 335 | REPORTER_ASSERT(reporter, p1.getColor(x, y) == p2.getColor(x, y)); |
| 336 | if (p1.getColor(x, y) != p2.getColor(x, y)) { |
| 337 | return; |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | }; |
| 342 | |
| 343 | static constexpr int kSize = 100; |
Robert Phillips | 4d87b2b | 2019-07-23 13:44:16 -0400 | [diff] [blame] | 344 | SkImageInfo ii = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 345 | SkAutoPixmapStorage srcPixmap; |
| 346 | srcPixmap.alloc(ii); |
| 347 | fillPixels(&srcPixmap, |
Robert Phillips | cb1adb4 | 2019-06-10 15:09:34 -0400 | [diff] [blame] | 348 | [](int x, int y) { |
| 349 | return (0xFFU << 24) | (x << 16) | (y << 8) | uint8_t((x * y) & 0xFF); |
| 350 | }); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 351 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 352 | auto dContext = context_info.directContext(); |
| 353 | GrProxyProvider* proxyProvider = dContext->priv().proxyProvider(); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 354 | |
| 355 | // We test both kRW in addition to kRead mostly to ensure that the calls are structured such |
| 356 | // that they'd succeed if the texture wasn't kRead. We want to be sure we're failing with |
| 357 | // kRead for the right reason. |
| 358 | for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 359 | auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData( |
Brian Salomon | b5f880a | 2020-12-07 11:30:16 -0500 | [diff] [blame] | 360 | dContext, srcPixmap, kTopLeft_GrSurfaceOrigin, GrRenderable::kNo, GrProtected::kNo); |
Brian Salomon | 88d7e62 | 2020-11-05 11:11:20 -0500 | [diff] [blame] | 361 | if (!mbet) { |
| 362 | ERRORF(reporter, "Could not make texture."); |
| 363 | return; |
| 364 | } |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 365 | auto proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership, |
| 366 | GrWrapCacheable::kNo, ioType, |
| 367 | mbet->refCountedCallback()); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 368 | GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), |
| 369 | GrColorType::kRGBA_8888); |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 370 | GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle); |
Robert Phillips | 33bf2b5 | 2021-08-02 11:14:38 -0400 | [diff] [blame] | 371 | auto surfContext = dContext->priv().makeSC(std::move(view), ii.colorInfo()); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 372 | // Read pixels should work with a read-only texture. |
Robert Phillips | 4d87b2b | 2019-07-23 13:44:16 -0400 | [diff] [blame] | 373 | { |
| 374 | SkAutoPixmapStorage read; |
| 375 | read.alloc(srcPixmap.info()); |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 376 | auto readResult = surfContext->readPixels(dContext, read, {0, 0}); |
Robert Phillips | 4d87b2b | 2019-07-23 13:44:16 -0400 | [diff] [blame] | 377 | REPORTER_ASSERT(reporter, readResult); |
| 378 | if (readResult) { |
| 379 | comparePixels(srcPixmap, read, reporter); |
| 380 | } |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | // Write pixels should not work with a read-only texture. |
| 384 | SkAutoPixmapStorage write; |
Robert Phillips | 4d87b2b | 2019-07-23 13:44:16 -0400 | [diff] [blame] | 385 | write.alloc(srcPixmap.info()); |
| 386 | fillPixels(&write, [&srcPixmap](int x, int y) { return ~*srcPixmap.addr32(); }); |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 387 | auto writeResult = surfContext->writePixels(dContext, write, {0, 0}); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 388 | REPORTER_ASSERT(reporter, writeResult == (ioType == kRW_GrIOType)); |
| 389 | // Try the low level write. |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 390 | dContext->flushAndSubmit(); |
| 391 | auto gpuWriteResult = dContext->priv().getGpu()->writePixels( |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 392 | proxy->peekTexture(), |
| 393 | SkIRect::MakeWH(kSize, kSize), |
| 394 | GrColorType::kRGBA_8888, |
| 395 | GrColorType::kRGBA_8888, |
| 396 | write.addr32(), |
| 397 | kSize*GrColorTypeBytesPerPixel(GrColorType::kRGBA_8888)); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 398 | REPORTER_ASSERT(reporter, gpuWriteResult == (ioType == kRW_GrIOType)); |
| 399 | |
Greg Daniel | 6f5441a | 2020-01-28 17:02:49 -0500 | [diff] [blame] | 400 | SkBitmap copySrcBitmap; |
| 401 | copySrcBitmap.installPixels(write); |
| 402 | copySrcBitmap.setImmutable(); |
| 403 | |
Brian Salomon | 27c4202 | 2021-04-28 12:39:21 -0400 | [diff] [blame] | 404 | auto copySrc = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, copySrcBitmap)); |
Greg Daniel | 6f5441a | 2020-01-28 17:02:49 -0500 | [diff] [blame] | 405 | |
Brian Salomon | 27c4202 | 2021-04-28 12:39:21 -0400 | [diff] [blame] | 406 | REPORTER_ASSERT(reporter, copySrc); |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 407 | auto copyResult = surfContext->testCopy(copySrc.refProxy()); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 408 | REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType)); |
| 409 | // Try the low level copy. |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 410 | dContext->flushAndSubmit(); |
| 411 | auto gpuCopyResult = dContext->priv().getGpu()->copySurface( |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 412 | proxy->peekSurface(), copySrc.proxy()->peekSurface(), SkIRect::MakeWH(kSize, kSize), |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 413 | {0, 0}); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 414 | REPORTER_ASSERT(reporter, gpuCopyResult == (ioType == kRW_GrIOType)); |
| 415 | |
| 416 | // Mip regen should not work with a read only texture. |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 417 | if (dContext->priv().caps()->mipmapSupport()) { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 418 | mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext, |
| 419 | kSize, |
| 420 | kSize, |
| 421 | kRGBA_8888_SkColorType, |
| 422 | GrMipmapped::kYes, |
| 423 | GrRenderable::kNo, |
| 424 | GrProtected::kNo); |
| 425 | proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership, |
| 426 | GrWrapCacheable::kNo, ioType, |
| 427 | mbet->refCountedCallback()); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 428 | dContext->flushAndSubmit(); |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 429 | proxy->peekTexture()->markMipmapsDirty(); // avoids assert in GrGpu. |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 430 | auto regenResult = |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 431 | dContext->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture()); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 432 | REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType)); |
| 433 | } |
| 434 | } |
| 435 | } |