Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [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/SkTypes.h" |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkPoint.h" |
| 12 | #include "include/core/SkSurface.h" |
| 13 | #include "include/gpu/GrBackendSurface.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 14 | #include "include/gpu/GrDirectContext.h" |
Jim Van Verth | 1c318eb | 2021-05-07 16:25:49 -0400 | [diff] [blame] | 15 | #ifdef SK_DIRECT3D |
| 16 | #include "include/gpu/d3d/GrD3DTypes.h" |
| 17 | #endif |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 18 | #include "src/gpu/BaseDevice.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrBackendTextureImageGenerator.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrDirectContextPriv.h" |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 21 | #include "src/gpu/GrDrawingManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "src/gpu/GrGpu.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 23 | #include "src/gpu/GrProxyProvider.h" |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrRecordingContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrSemaphore.h" |
| 26 | #include "src/gpu/GrSurfaceProxyPriv.h" |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 27 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 28 | #include "src/gpu/GrTextureProxy.h" |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 29 | #include "src/gpu/v1/SurfaceDrawContext_v1.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "src/image/SkImage_Base.h" |
| 31 | #include "src/image/SkSurface_Gpu.h" |
| 32 | #include "tests/Test.h" |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 33 | #include "tests/TestUtils.h" |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 34 | #include "tools/gpu/BackendSurfaceFactory.h" |
| 35 | #include "tools/gpu/BackendTextureImageFactory.h" |
| 36 | #include "tools/gpu/ManagedBackendTexture.h" |
Brian Salomon | e666254 | 2021-02-23 10:45:39 -0500 | [diff] [blame] | 37 | #include "tools/gpu/ProxyUtils.h" |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 38 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 39 | static constexpr int kSize = 8; |
| 40 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 41 | // Test that the correct mip map states are on the GrTextures when wrapping GrBackendTextures in |
| 42 | // SkImages and SkSurfaces |
| 43 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 44 | auto dContext = ctxInfo.directContext(); |
| 45 | if (!dContext->priv().caps()->mipmapSupport()) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 46 | return; |
| 47 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 48 | |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 49 | for (auto mipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 50 | for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) { |
Robert Phillips | 9b16f81 | 2019-05-17 10:01:21 -0400 | [diff] [blame] | 51 | // createBackendTexture currently doesn't support uploading data to mip maps |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 52 | // so we don't send any. However, we pretend there is data for the checks below which is |
| 53 | // fine since we are never actually using these textures for any work on the gpu. |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 54 | auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData(dContext, |
| 55 | kSize, |
| 56 | kSize, |
| 57 | kRGBA_8888_SkColorType, |
| 58 | SkColors::kTransparent, |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 59 | mipmapped, |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 60 | renderable, |
| 61 | GrProtected::kNo); |
Brian Salomon | 88d7e62 | 2020-11-05 11:11:20 -0500 | [diff] [blame] | 62 | if (!mbet) { |
| 63 | ERRORF(reporter, "Could not make texture."); |
| 64 | return; |
| 65 | } |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 66 | |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 67 | sk_sp<GrTextureProxy> proxy; |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 68 | sk_sp<SkImage> image; |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 69 | if (renderable == GrRenderable::kYes) { |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 70 | sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture( |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 71 | dContext, |
| 72 | mbet->texture(), |
| 73 | kTopLeft_GrSurfaceOrigin, |
| 74 | 0, |
| 75 | kRGBA_8888_SkColorType, |
| 76 | /*color space*/ nullptr, |
| 77 | /*surface props*/ nullptr, |
| 78 | sk_gpu_test::ManagedBackendTexture::ReleaseProc, |
| 79 | mbet->releaseContext()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 80 | |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 81 | auto device = ((SkSurface_Gpu*)surface.get())->getDevice(); |
Robert Phillips | 5ccb4c1 | 2021-05-24 15:35:08 -0400 | [diff] [blame] | 82 | proxy = device->readSurfaceView().asTextureProxyRef(); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 83 | } else { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 84 | image = SkImage::MakeFromTexture(dContext, |
| 85 | mbet->texture(), |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 86 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 87 | kRGBA_8888_SkColorType, |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 88 | kPremul_SkAlphaType, |
| 89 | /* color space */ nullptr, |
| 90 | sk_gpu_test::ManagedBackendTexture::ReleaseProc, |
| 91 | mbet->releaseContext()); |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 92 | REPORTER_ASSERT(reporter, (mipmapped == GrMipmapped::kYes) == image->hasMipmaps()); |
Brian Salomon | e666254 | 2021-02-23 10:45:39 -0500 | [diff] [blame] | 93 | proxy = sk_ref_sp(sk_gpu_test::GetTextureImageProxy(image.get(), dContext)); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 94 | } |
| 95 | REPORTER_ASSERT(reporter, proxy); |
| 96 | if (!proxy) { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 97 | continue; |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 100 | REPORTER_ASSERT(reporter, proxy->isInstantiated()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 101 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 102 | GrTexture* texture = proxy->peekTexture(); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 103 | REPORTER_ASSERT(reporter, texture); |
| 104 | if (!texture) { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 105 | continue; |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 108 | if (mipmapped == GrMipmapped::kYes) { |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 109 | REPORTER_ASSERT(reporter, GrMipmapped::kYes == texture->mipmapped()); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 110 | if (GrRenderable::kYes == renderable) { |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 111 | REPORTER_ASSERT(reporter, texture->mipmapsAreDirty()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 112 | } else { |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 113 | REPORTER_ASSERT(reporter, !texture->mipmapsAreDirty()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 114 | } |
| 115 | } else { |
Brian Salomon | 4cfae3b | 2020-07-23 10:33:24 -0400 | [diff] [blame] | 116 | REPORTER_ASSERT(reporter, GrMipmapped::kNo == texture->mipmapped()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 117 | } |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 122 | // Test that we correctly copy or don't copy GrBackendTextures in the GrBackendTextureImageGenerator |
| 123 | // based on if we will use mips in the draw and the mip status of the GrBackendTexture. |
| 124 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, ctxInfo) { |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 125 | auto dContext = ctxInfo.directContext(); |
| 126 | if (!dContext->priv().caps()->mipmapSupport()) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 127 | return; |
| 128 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 129 | |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 130 | for (auto betMipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) { |
| 131 | for (auto requestMipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 132 | auto ii = |
| 133 | SkImageInfo::Make({kSize, kSize}, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 134 | sk_sp<SkImage> image = sk_gpu_test::MakeBackendTextureImage( |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 135 | dContext, ii, SkColors::kTransparent, betMipmapped); |
| 136 | REPORTER_ASSERT(reporter, (betMipmapped == GrMipmapped::kYes) == image->hasMipmaps()); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 137 | |
Brian Salomon | e666254 | 2021-02-23 10:45:39 -0500 | [diff] [blame] | 138 | GrTextureProxy* proxy = sk_gpu_test::GetTextureImageProxy(image.get(), dContext); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 139 | REPORTER_ASSERT(reporter, proxy); |
| 140 | if (!proxy) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, proxy->isInstantiated()); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 145 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 146 | sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture()); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 147 | REPORTER_ASSERT(reporter, texture); |
| 148 | if (!texture) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 149 | return; |
| 150 | } |
| 151 | |
| 152 | std::unique_ptr<SkImageGenerator> imageGen = GrBackendTextureImageGenerator::Make( |
Brian Osman | 052ef69 | 2018-03-27 09:56:31 -0400 | [diff] [blame] | 153 | texture, kTopLeft_GrSurfaceOrigin, nullptr, kRGBA_8888_SkColorType, |
| 154 | kPremul_SkAlphaType, nullptr); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, imageGen); |
| 156 | if (!imageGen) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
| 160 | SkIPoint origin = SkIPoint::Make(0,0); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 161 | SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, |
| 162 | kPremul_SkAlphaType); |
Brian Salomon | bc074a6 | 2020-03-18 10:06:13 -0400 | [diff] [blame] | 163 | GrSurfaceProxyView genView = imageGen->generateTexture( |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 164 | dContext, imageInfo, origin, requestMipmapped, GrImageTexGenPolicy::kDraw); |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 165 | GrSurfaceProxy* genProxy = genView.proxy(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 166 | |
| 167 | REPORTER_ASSERT(reporter, genProxy); |
| 168 | if (!genProxy) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 169 | return; |
| 170 | } |
| 171 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 172 | if (genProxy->isLazy()) { |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 173 | genProxy->priv().doLazyInstantiation(dContext->priv().resourceProvider()); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 174 | } else if (!genProxy->isInstantiated()) { |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 175 | genProxy->instantiate(dContext->priv().resourceProvider()); |
Greg Daniel | e728f67 | 2018-01-17 10:52:04 -0500 | [diff] [blame] | 176 | } |
| 177 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 178 | REPORTER_ASSERT(reporter, genProxy->isInstantiated()); |
| 179 | if (!genProxy->isInstantiated()) { |
Greg Daniel | bddcc95 | 2018-01-24 13:22:24 -0500 | [diff] [blame] | 180 | return; |
| 181 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 182 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 183 | GrTexture* genTexture = genProxy->peekTexture(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 184 | REPORTER_ASSERT(reporter, genTexture); |
| 185 | if (!genTexture) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 186 | return; |
| 187 | } |
| 188 | |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 189 | GrBackendTexture backendTex = texture->getBackendTexture(); |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 190 | GrBackendTexture genBackendTex = genTexture->getBackendTexture(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 191 | |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 192 | if (GrBackendApi::kOpenGL == genBackendTex.backend()) { |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 193 | #ifdef SK_GL |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 194 | GrGLTextureInfo genTexInfo; |
| 195 | GrGLTextureInfo origTexInfo; |
| 196 | if (genBackendTex.getGLTextureInfo(&genTexInfo) && |
| 197 | backendTex.getGLTextureInfo(&origTexInfo)) { |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 198 | if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 199 | // We did a copy so the texture IDs should be different |
| 200 | REPORTER_ASSERT(reporter, origTexInfo.fID != genTexInfo.fID); |
| 201 | } else { |
| 202 | REPORTER_ASSERT(reporter, origTexInfo.fID == genTexInfo.fID); |
| 203 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 204 | } else { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 205 | ERRORF(reporter, "Failed to get GrGLTextureInfo"); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 206 | } |
Greg Daniel | 8426165 | 2021-09-19 17:53:40 -0400 | [diff] [blame^] | 207 | #endif |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 208 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 209 | } else if (GrBackendApi::kVulkan == genBackendTex.backend()) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 210 | GrVkImageInfo genImageInfo; |
| 211 | GrVkImageInfo origImageInfo; |
| 212 | if (genBackendTex.getVkImageInfo(&genImageInfo) && |
| 213 | backendTex.getVkImageInfo(&origImageInfo)) { |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 214 | if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 215 | // We did a copy so the texture IDs should be different |
| 216 | REPORTER_ASSERT(reporter, origImageInfo.fImage != genImageInfo.fImage); |
| 217 | } else { |
| 218 | REPORTER_ASSERT(reporter, origImageInfo.fImage == genImageInfo.fImage); |
| 219 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 220 | } else { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 221 | ERRORF(reporter, "Failed to get GrVkImageInfo"); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 222 | } |
| 223 | #endif |
Jim Van Verth | 9896a0d | 2019-04-10 15:11:12 -0400 | [diff] [blame] | 224 | #ifdef SK_METAL |
| 225 | } else if (GrBackendApi::kMetal == genBackendTex.backend()) { |
| 226 | GrMtlTextureInfo genImageInfo; |
| 227 | GrMtlTextureInfo origImageInfo; |
| 228 | if (genBackendTex.getMtlTextureInfo(&genImageInfo) && |
| 229 | backendTex.getMtlTextureInfo(&origImageInfo)) { |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 230 | if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) { |
Jim Van Verth | 9896a0d | 2019-04-10 15:11:12 -0400 | [diff] [blame] | 231 | // We did a copy so the texture IDs should be different |
| 232 | REPORTER_ASSERT(reporter, origImageInfo.fTexture != genImageInfo.fTexture); |
| 233 | } else { |
| 234 | REPORTER_ASSERT(reporter, origImageInfo.fTexture == genImageInfo.fTexture); |
| 235 | } |
| 236 | } else { |
| 237 | ERRORF(reporter, "Failed to get GrMtlTextureInfo"); |
| 238 | } |
| 239 | #endif |
Jim Van Verth | 1c318eb | 2021-05-07 16:25:49 -0400 | [diff] [blame] | 240 | #ifdef SK_DIRECT3D |
| 241 | } else if (GrBackendApi::kDirect3D == genBackendTex.backend()) { |
| 242 | GrD3DTextureResourceInfo genImageInfo; |
| 243 | GrD3DTextureResourceInfo origImageInfo; |
| 244 | if (genBackendTex.getD3DTextureResourceInfo(&genImageInfo) && |
| 245 | backendTex.getD3DTextureResourceInfo(&origImageInfo)) { |
| 246 | if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) { |
| 247 | // We did a copy so the texture resources should be different |
| 248 | REPORTER_ASSERT(reporter, |
| 249 | origImageInfo.fResource != genImageInfo.fResource); |
| 250 | } else { |
| 251 | REPORTER_ASSERT(reporter, |
| 252 | origImageInfo.fResource == genImageInfo.fResource); |
| 253 | } |
| 254 | } else { |
| 255 | ERRORF(reporter, "Failed to get GrMtlTextureInfo"); |
| 256 | } |
| 257 | #endif |
Stephen White | e895cdc | 2020-10-08 13:43:40 -0400 | [diff] [blame] | 258 | #ifdef SK_DAWN |
| 259 | } else if (GrBackendApi::kDawn == genBackendTex.backend()) { |
| 260 | GrDawnTextureInfo genImageInfo; |
| 261 | GrDawnTextureInfo origImageInfo; |
| 262 | if (genBackendTex.getDawnTextureInfo(&genImageInfo) && |
| 263 | backendTex.getDawnTextureInfo(&origImageInfo)) { |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 264 | if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) { |
Stephen White | e895cdc | 2020-10-08 13:43:40 -0400 | [diff] [blame] | 265 | // We did a copy so the texture IDs should be different |
| 266 | REPORTER_ASSERT(reporter, |
| 267 | origImageInfo.fTexture.Get() != genImageInfo.fTexture.Get()); |
| 268 | } else { |
| 269 | REPORTER_ASSERT(reporter, |
| 270 | origImageInfo.fTexture.Get() == genImageInfo.fTexture.Get()); |
| 271 | } |
| 272 | } else { |
| 273 | ERRORF(reporter, "Failed to get GrDawnTextureInfo"); |
| 274 | } |
| 275 | #endif |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 276 | } else { |
| 277 | REPORTER_ASSERT(reporter, false); |
| 278 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 283 | // Test that when we call makeImageSnapshot on an SkSurface we retains the same mip status as the |
| 284 | // resource we took the snapshot of. |
| 285 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxInfo) { |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 286 | auto dContext = ctxInfo.directContext(); |
| 287 | if (!dContext->priv().caps()->mipmapSupport()) { |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 288 | return; |
| 289 | } |
| 290 | |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 291 | auto resourceProvider = dContext->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 292 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 293 | for (auto willUseMips : {false, true}) { |
| 294 | for (auto isWrapped : {false, true}) { |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 295 | GrMipmapped mipmapped = willUseMips ? GrMipmapped::kYes : GrMipmapped::kNo; |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 296 | sk_sp<SkSurface> surface; |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 297 | SkImageInfo info = |
| 298 | SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 299 | if (isWrapped) { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 300 | surface = sk_gpu_test::MakeBackendTextureSurface(dContext, |
| 301 | info, |
| 302 | kTopLeft_GrSurfaceOrigin, |
| 303 | /* sample count */ 1, |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 304 | mipmapped); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 305 | } else { |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 306 | surface = SkSurface::MakeRenderTarget(dContext, |
| 307 | SkBudgeted::kYes, |
| 308 | info, |
| 309 | /* sample count */ 1, |
| 310 | kTopLeft_GrSurfaceOrigin, |
| 311 | nullptr, |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 312 | willUseMips); |
| 313 | } |
| 314 | REPORTER_ASSERT(reporter, surface); |
Robert Phillips | cc44feb | 2021-07-06 12:21:37 -0400 | [diff] [blame] | 315 | auto device = ((SkSurface_Gpu*)surface.get())->getDevice(); |
Robert Phillips | 5ccb4c1 | 2021-05-24 15:35:08 -0400 | [diff] [blame] | 316 | GrTextureProxy* texProxy = device->readSurfaceView().asTextureProxy(); |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 317 | REPORTER_ASSERT(reporter, mipmapped == texProxy->mipmapped()); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 318 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 319 | texProxy->instantiate(resourceProvider); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 320 | GrTexture* texture = texProxy->peekTexture(); |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 321 | REPORTER_ASSERT(reporter, mipmapped == texture->mipmapped()); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 322 | |
| 323 | sk_sp<SkImage> image = surface->makeImageSnapshot(); |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 324 | REPORTER_ASSERT(reporter, willUseMips == image->hasMipmaps()); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 325 | REPORTER_ASSERT(reporter, image); |
Brian Salomon | e666254 | 2021-02-23 10:45:39 -0500 | [diff] [blame] | 326 | texProxy = sk_gpu_test::GetTextureImageProxy(image.get(), dContext); |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 327 | REPORTER_ASSERT(reporter, mipmapped == texProxy->mipmapped()); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 328 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 329 | texProxy->instantiate(resourceProvider); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 330 | texture = texProxy->peekTexture(); |
Brian Salomon | 7d2757f | 2021-01-26 17:46:50 -0500 | [diff] [blame] | 331 | REPORTER_ASSERT(reporter, mipmapped == texture->mipmapped()); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | } |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 335 | |
| 336 | // Test that we don't create a mip mapped texture if the size is 1x1 even if the filter mode is set |
| 337 | // to use mips. This test passes by not crashing or hitting asserts in code. |
| 338 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(Gr1x1TextureMipMappedTest, reporter, ctxInfo) { |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 339 | auto dContext = ctxInfo.directContext(); |
| 340 | if (!dContext->priv().caps()->mipmapSupport()) { |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 341 | return; |
| 342 | } |
| 343 | |
| 344 | // Make surface to draw into |
| 345 | SkImageInfo info = SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType); |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 346 | sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info); |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 347 | |
| 348 | // Make 1x1 raster bitmap |
| 349 | SkBitmap bmp; |
| 350 | bmp.allocN32Pixels(1, 1); |
| 351 | SkPMColor* pixel = reinterpret_cast<SkPMColor*>(bmp.getPixels()); |
| 352 | *pixel = 0; |
| 353 | |
Mike Reed | dc607e3 | 2020-12-23 11:50:36 -0500 | [diff] [blame] | 354 | sk_sp<SkImage> bmpImage = bmp.asImage(); |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 355 | |
| 356 | // Make sure we scale so we don't optimize out the use of mips. |
| 357 | surface->getCanvas()->scale(0.5f, 0.5f); |
| 358 | |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 359 | // This should upload the image to a non mipped GrTextureProxy. |
Mike Reed | 039f136 | 2021-01-27 21:21:08 -0500 | [diff] [blame] | 360 | surface->getCanvas()->drawImage(bmpImage, 0, 0); |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 361 | surface->flushAndSubmit(); |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 362 | |
| 363 | // Now set the filter quality to high so we use mip maps. We should find the non mipped texture |
| 364 | // in the cache for the SkImage. Since the texture is 1x1 we should just use that texture |
| 365 | // instead of trying to do a copy to a mipped texture. |
Mike Reed | 039f136 | 2021-01-27 21:21:08 -0500 | [diff] [blame] | 366 | surface->getCanvas()->drawImage(bmpImage, 0, 0, SkSamplingOptions({1.0f/3, 1.0f/3})); |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 367 | surface->flushAndSubmit(); |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 368 | } |
| 369 | |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 370 | // Create a new render target and draw 'mipmapView' into it using the provided 'filter'. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 371 | static std::unique_ptr<skgpu::v1::SurfaceDrawContext> draw_mipmap_into_new_render_target( |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 372 | GrRecordingContext* rContext, |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 373 | GrColorType colorType, |
| 374 | SkAlphaType alphaType, |
| 375 | GrSurfaceProxyView mipmapView, |
| 376 | GrSamplerState::MipmapMode mm) { |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 377 | auto proxyProvider = rContext->priv().proxyProvider(); |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 378 | sk_sp<GrSurfaceProxy> renderTarget = |
| 379 | proxyProvider->createProxy(mipmapView.proxy()->backendFormat(), |
| 380 | {1, 1}, |
| 381 | GrRenderable::kYes, |
| 382 | 1, |
| 383 | GrMipmapped::kNo, |
| 384 | SkBackingFit::kApprox, |
| 385 | SkBudgeted::kYes, |
| 386 | GrProtected::kNo); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 387 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 388 | auto sdc = skgpu::v1::SurfaceDrawContext::Make(rContext, |
| 389 | colorType, |
| 390 | std::move(renderTarget), |
| 391 | nullptr, |
| 392 | kTopLeft_GrSurfaceOrigin, |
| 393 | SkSurfaceProps(), |
| 394 | false); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 395 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 396 | sdc->drawTexture(nullptr, |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 397 | std::move(mipmapView), |
| 398 | alphaType, |
| 399 | GrSamplerState::Filter::kLinear, |
| 400 | mm, |
| 401 | SkBlendMode::kSrcOver, |
| 402 | {1, 1, 1, 1}, |
| 403 | SkRect::MakeWH(4, 4), |
| 404 | SkRect::MakeWH(1, 1), |
| 405 | GrAA::kYes, |
| 406 | GrQuadAAFlags::kAll, |
| 407 | SkCanvas::kFast_SrcRectConstraint, |
| 408 | SkMatrix::I(), |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 409 | nullptr); |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 410 | return sdc; |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 411 | } |
| 412 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 413 | // Test that two opsTasks using the same mipmaps both depend on the same GrTextureResolveRenderTask. |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 414 | DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) { |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 415 | using Enable = GrContextOptions::Enable; |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame] | 416 | using MipmapMode = GrSamplerState::MipmapMode; |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 417 | |
| 418 | for (auto enableSortingAndReduction : {Enable::kYes, Enable::kNo}) { |
| 419 | GrMockOptions mockOptions; |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 420 | mockOptions.fMipmapSupport = true; |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 421 | GrContextOptions ctxOptions; |
Greg Daniel | 9313874 | 2019-08-22 17:15:39 -0400 | [diff] [blame] | 422 | ctxOptions.fReduceOpsTaskSplitting = enableSortingAndReduction; |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 423 | sk_sp<GrDirectContext> dContext = GrDirectContext::MakeMock(&mockOptions, ctxOptions); |
| 424 | GrDrawingManager* drawingManager = dContext->priv().drawingManager(); |
| 425 | if (!dContext) { |
| 426 | ERRORF(reporter, "could not create mock dContext with fReduceOpsTaskSplitting %s.", |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 427 | (Enable::kYes == enableSortingAndReduction) ? "enabled" : "disabled"); |
| 428 | continue; |
| 429 | } |
| 430 | |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 431 | SkASSERT(dContext->priv().caps()->mipmapSupport()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 432 | |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 433 | GrBackendFormat format = dContext->defaultBackendFormat( |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 434 | kRGBA_8888_SkColorType, GrRenderable::kYes); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 435 | GrColorType colorType = GrColorType::kRGBA_8888; |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 436 | SkAlphaType alphaType = kPremul_SkAlphaType; |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 437 | |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 438 | GrProxyProvider* proxyProvider = dContext->priv().proxyProvider(); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 439 | |
| 440 | // Create a mipmapped render target. |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 441 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 442 | sk_sp<GrTextureProxy> mipmapProxy = proxyProvider->createProxy( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 443 | format, {4, 4}, GrRenderable::kYes, 1, GrMipmapped::kYes, SkBackingFit::kExact, |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 444 | SkBudgeted::kYes, GrProtected::kNo); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 445 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 446 | // Mark the mipmaps clean to ensure things still work properly when they won't be marked |
| 447 | // dirty again until GrRenderTask::makeClosed(). |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 448 | mipmapProxy->markMipmapsClean(); |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 449 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 450 | auto mipmapSDC = skgpu::v1::SurfaceDrawContext::Make( |
Robert Phillips | 779125d | 2021-05-24 13:14:39 -0400 | [diff] [blame] | 451 | dContext.get(), colorType, mipmapProxy, nullptr, kTopLeft_GrSurfaceOrigin, |
Chris Dalton | f5b87f9 | 2021-04-19 17:27:09 -0600 | [diff] [blame] | 452 | SkSurfaceProps(), false); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 453 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 454 | mipmapSDC->clear(SkPMColor4f{.1f, .2f, .3f, .4f}); |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 455 | REPORTER_ASSERT(reporter, drawingManager->getLastRenderTask(mipmapProxy.get())); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 456 | // mipmapProxy's last render task should now just be the opsTask containing the clear. |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 457 | REPORTER_ASSERT(reporter, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 458 | mipmapSDC->testingOnly_PeekLastOpsTask() == |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 459 | drawingManager->getLastRenderTask(mipmapProxy.get())); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 460 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 461 | // Mipmaps don't get marked dirty until makeClosed(). |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 462 | REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty()); |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 463 | |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 464 | GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(format, colorType); |
Greg Daniel | 40903af | 2020-01-30 14:55:05 -0500 | [diff] [blame] | 465 | GrSurfaceProxyView mipmapView(mipmapProxy, kTopLeft_GrSurfaceOrigin, swizzle); |
| 466 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 467 | // Draw the dirty mipmap texture into a render target. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 468 | auto sdc1 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType, |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 469 | mipmapView, MipmapMode::kLinear); |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 470 | auto sdc1Task = sk_ref_sp(sdc1->testingOnly_PeekLastOpsTask()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 471 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 472 | // Mipmaps should have gotten marked dirty during makeClosed, then marked clean again as |
| 473 | // soon as a GrTextureResolveRenderTask was inserted. The way we know they were resolved is |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 474 | // if mipmapProxy->getLastRenderTask() has switched from the opsTask that drew to it, to the |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 475 | // task that resolved its mips. |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 476 | GrRenderTask* initialMipmapRegenTask = drawingManager->getLastRenderTask(mipmapProxy.get()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 477 | REPORTER_ASSERT(reporter, initialMipmapRegenTask); |
| 478 | REPORTER_ASSERT(reporter, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 479 | initialMipmapRegenTask != mipmapSDC->testingOnly_PeekLastOpsTask()); |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 480 | REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 481 | |
| 482 | // Draw the now-clean mipmap texture into a second target. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 483 | auto sdc2 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType, |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 484 | mipmapView, MipmapMode::kLinear); |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 485 | auto sdc2Task = sk_ref_sp(sdc2->testingOnly_PeekLastOpsTask()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 486 | |
| 487 | // Make sure the mipmap texture still has the same regen task. |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 488 | REPORTER_ASSERT(reporter, |
| 489 | drawingManager->getLastRenderTask(mipmapProxy.get()) == initialMipmapRegenTask); |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 490 | SkASSERT(!mipmapProxy->mipmapsAreDirty()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 491 | |
| 492 | // Reset everything so we can go again, this time with the first draw not mipmapped. |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 493 | dContext->flushAndSubmit(); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 494 | |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 495 | // Mip regen tasks don't get added as dependencies until makeClosed(). |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 496 | REPORTER_ASSERT(reporter, sdc1Task->dependsOn(initialMipmapRegenTask)); |
| 497 | REPORTER_ASSERT(reporter, sdc2Task->dependsOn(initialMipmapRegenTask)); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 498 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 499 | // Render something to dirty the mips. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 500 | mipmapSDC->clear(SkPMColor4f{.1f, .2f, .3f, .4f}); |
| 501 | auto mipmapRTCTask = sk_ref_sp(mipmapSDC->testingOnly_PeekLastOpsTask()); |
Brian Salomon | 3b8486a | 2020-04-21 12:43:26 -0400 | [diff] [blame] | 502 | REPORTER_ASSERT(reporter, mipmapRTCTask); |
| 503 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 504 | // mipmapProxy's last render task should now just be the opsTask containing the clear. |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 505 | REPORTER_ASSERT(reporter, |
| 506 | mipmapRTCTask.get() == drawingManager->getLastRenderTask(mipmapProxy.get())); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 507 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 508 | // Mipmaps don't get marked dirty until makeClosed(). |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 509 | REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty()); |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 510 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 511 | // Draw the dirty mipmap texture into a render target, but don't do mipmap filtering. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 512 | sdc1 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType, |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 513 | mipmapView, MipmapMode::kNone); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 514 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 515 | // Mipmaps should have gotten marked dirty during makeClosed() when adding the dependency. |
| 516 | // Since the last draw did not use mips, they will not have been regenerated and should |
| 517 | // therefore still be dirty. |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 518 | REPORTER_ASSERT(reporter, mipmapProxy->mipmapsAreDirty()); |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 519 | |
| 520 | // Since mips weren't regenerated, the last render task shouldn't have changed. |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 521 | REPORTER_ASSERT(reporter, |
| 522 | mipmapRTCTask.get() == drawingManager->getLastRenderTask(mipmapProxy.get())); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 523 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 524 | // Draw the stil-dirty mipmap texture into a second target with mipmap filtering. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 525 | sdc2 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType, |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 526 | std::move(mipmapView), MipmapMode::kLinear); |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 527 | sdc2Task = sk_ref_sp(sdc2->testingOnly_PeekLastOpsTask()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 528 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 529 | // Make sure the mipmap texture now has a new last render task that regenerates the mips, |
| 530 | // and that the mipmaps are now clean. |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 531 | auto mipRegenTask2 = drawingManager->getLastRenderTask(mipmapProxy.get()); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 532 | REPORTER_ASSERT(reporter, mipRegenTask2); |
Brian Salomon | 3b8486a | 2020-04-21 12:43:26 -0400 | [diff] [blame] | 533 | REPORTER_ASSERT(reporter, mipmapRTCTask.get() != mipRegenTask2); |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 534 | SkASSERT(!mipmapProxy->mipmapsAreDirty()); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 535 | |
| 536 | // Mip regen tasks don't get added as dependencies until makeClosed(). |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 537 | dContext->flushAndSubmit(); |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 538 | REPORTER_ASSERT(reporter, sdc2Task->dependsOn(mipRegenTask2)); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 539 | } |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 540 | } |