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