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" |
| 14 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrBackendTextureImageGenerator.h" |
| 16 | #include "src/gpu/GrContextPriv.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" |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrRecordingContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTargetContext.h" |
| 21 | #include "src/gpu/GrSemaphore.h" |
| 22 | #include "src/gpu/GrSurfaceProxyPriv.h" |
| 23 | #include "src/gpu/GrTexturePriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 24 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/SkGpuDevice.h" |
| 26 | #include "src/image/SkImage_Base.h" |
| 27 | #include "src/image/SkSurface_Gpu.h" |
| 28 | #include "tests/Test.h" |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 29 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 30 | static constexpr int kSize = 8; |
| 31 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 32 | // Test that the correct mip map states are on the GrTextures when wrapping GrBackendTextures in |
| 33 | // SkImages and SkSurfaces |
| 34 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { |
| 35 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 36 | if (!context->priv().caps()->mipMapSupport()) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 37 | return; |
| 38 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 39 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 40 | for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 41 | for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) { |
Robert Phillips | 9b16f81 | 2019-05-17 10:01:21 -0400 | [diff] [blame] | 42 | // createBackendTexture currently doesn't support uploading data to mip maps |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 43 | // so we don't send any. However, we pretend there is data for the checks below which is |
| 44 | // fine since we are never actually using these textures for any work on the gpu. |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 45 | GrBackendTexture backendTex = context->createBackendTexture( |
Robert Phillips | 8062679 | 2019-06-04 07:16:10 -0400 | [diff] [blame] | 46 | kSize, kSize, kRGBA_8888_SkColorType, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 47 | SkColors::kTransparent, mipMapped, renderable, GrProtected::kNo); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 48 | |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 49 | sk_sp<GrTextureProxy> proxy; |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 50 | sk_sp<SkImage> image; |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 51 | if (GrRenderable::kYes == renderable) { |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 52 | sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture( |
| 53 | context, |
| 54 | backendTex, |
| 55 | kTopLeft_GrSurfaceOrigin, |
| 56 | 0, |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 57 | kRGBA_8888_SkColorType, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 58 | nullptr, |
| 59 | nullptr); |
| 60 | |
| 61 | SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 62 | proxy = device->accessRenderTargetContext()->asTextureProxyRef(); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 63 | } else { |
| 64 | image = SkImage::MakeFromTexture(context, backendTex, |
| 65 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 66 | kRGBA_8888_SkColorType, |
| 67 | kPremul_SkAlphaType, nullptr, |
| 68 | nullptr, nullptr); |
Robert Phillips | 6603a17 | 2019-03-05 12:35:44 -0500 | [diff] [blame] | 69 | proxy = as_IB(image)->asTextureProxyRef(context); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 70 | } |
| 71 | REPORTER_ASSERT(reporter, proxy); |
| 72 | if (!proxy) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 73 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 74 | return; |
| 75 | } |
| 76 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 77 | REPORTER_ASSERT(reporter, proxy->isInstantiated()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 78 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 79 | GrTexture* texture = proxy->peekTexture(); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 80 | REPORTER_ASSERT(reporter, texture); |
| 81 | if (!texture) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 82 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
| 86 | if (GrMipMapped::kYes == mipMapped) { |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 87 | REPORTER_ASSERT(reporter, GrMipMapped::kYes == texture->texturePriv().mipMapped()); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 88 | if (GrRenderable::kYes == renderable) { |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 89 | REPORTER_ASSERT(reporter, texture->texturePriv().mipMapsAreDirty()); |
| 90 | } else { |
| 91 | REPORTER_ASSERT(reporter, !texture->texturePriv().mipMapsAreDirty()); |
| 92 | } |
| 93 | } else { |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 94 | REPORTER_ASSERT(reporter, GrMipMapped::kNo == texture->texturePriv().mipMapped()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 95 | } |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 96 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 101 | // Test that we correctly copy or don't copy GrBackendTextures in the GrBackendTextureImageGenerator |
| 102 | // based on if we will use mips in the draw and the mip status of the GrBackendTexture. |
| 103 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, ctxInfo) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 104 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 105 | if (!context->priv().caps()->mipMapSupport()) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 106 | return; |
| 107 | } |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 108 | |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 109 | for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { |
| 110 | for (auto willUseMips : {false, true}) { |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 111 | GrBackendTexture backendTex = context->createBackendTexture( |
Robert Phillips | 8062679 | 2019-06-04 07:16:10 -0400 | [diff] [blame] | 112 | kSize, kSize, kRGBA_8888_SkColorType, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 113 | SkColors::kTransparent, mipMapped, GrRenderable::kNo, GrProtected::kNo); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 114 | |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 115 | sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backendTex, |
| 116 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 117 | kRGBA_8888_SkColorType, |
| 118 | kPremul_SkAlphaType, nullptr, |
| 119 | nullptr, nullptr); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 120 | |
| 121 | GrTextureProxy* proxy = as_IB(image)->peekProxy(); |
| 122 | REPORTER_ASSERT(reporter, proxy); |
| 123 | if (!proxy) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 124 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 125 | return; |
| 126 | } |
| 127 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 128 | REPORTER_ASSERT(reporter, proxy->isInstantiated()); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 129 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 130 | sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture()); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 131 | REPORTER_ASSERT(reporter, texture); |
| 132 | if (!texture) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 133 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 134 | return; |
| 135 | } |
| 136 | |
| 137 | std::unique_ptr<SkImageGenerator> imageGen = GrBackendTextureImageGenerator::Make( |
Brian Osman | 052ef69 | 2018-03-27 09:56:31 -0400 | [diff] [blame] | 138 | texture, kTopLeft_GrSurfaceOrigin, nullptr, kRGBA_8888_SkColorType, |
| 139 | kPremul_SkAlphaType, nullptr); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 140 | REPORTER_ASSERT(reporter, imageGen); |
| 141 | if (!imageGen) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 142 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | |
| 146 | SkIPoint origin = SkIPoint::Make(0,0); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 147 | SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, |
| 148 | kPremul_SkAlphaType); |
| 149 | sk_sp<GrTextureProxy> genProxy = imageGen->generateTexture(context, imageInfo, |
Brian Osman | c87cfb6 | 2018-07-11 09:08:46 -0400 | [diff] [blame] | 150 | origin, willUseMips); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 151 | |
| 152 | REPORTER_ASSERT(reporter, genProxy); |
| 153 | if (!genProxy) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 154 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 155 | return; |
| 156 | } |
| 157 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 158 | if (genProxy->isLazy()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 159 | genProxy->priv().doLazyInstantiation(context->priv().resourceProvider()); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 160 | } else if (!genProxy->isInstantiated()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 161 | genProxy->instantiate(context->priv().resourceProvider()); |
Greg Daniel | e728f67 | 2018-01-17 10:52:04 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 164 | REPORTER_ASSERT(reporter, genProxy->isInstantiated()); |
| 165 | if (!genProxy->isInstantiated()) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 166 | context->deleteBackendTexture(backendTex); |
Greg Daniel | bddcc95 | 2018-01-24 13:22:24 -0500 | [diff] [blame] | 167 | return; |
| 168 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 169 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 170 | GrTexture* genTexture = genProxy->peekTexture(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 171 | REPORTER_ASSERT(reporter, genTexture); |
| 172 | if (!genTexture) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 173 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 174 | return; |
| 175 | } |
| 176 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 177 | GrBackendTexture genBackendTex = genTexture->getBackendTexture(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 178 | |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 179 | if (GrBackendApi::kOpenGL == genBackendTex.backend()) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 180 | GrGLTextureInfo genTexInfo; |
| 181 | GrGLTextureInfo origTexInfo; |
| 182 | if (genBackendTex.getGLTextureInfo(&genTexInfo) && |
| 183 | backendTex.getGLTextureInfo(&origTexInfo)) { |
| 184 | if (willUseMips && GrMipMapped::kNo == mipMapped) { |
| 185 | // We did a copy so the texture IDs should be different |
| 186 | REPORTER_ASSERT(reporter, origTexInfo.fID != genTexInfo.fID); |
| 187 | } else { |
| 188 | REPORTER_ASSERT(reporter, origTexInfo.fID == genTexInfo.fID); |
| 189 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 190 | } else { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 191 | ERRORF(reporter, "Failed to get GrGLTextureInfo"); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 192 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 193 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 194 | } else if (GrBackendApi::kVulkan == genBackendTex.backend()) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 195 | GrVkImageInfo genImageInfo; |
| 196 | GrVkImageInfo origImageInfo; |
| 197 | if (genBackendTex.getVkImageInfo(&genImageInfo) && |
| 198 | backendTex.getVkImageInfo(&origImageInfo)) { |
| 199 | if (willUseMips && GrMipMapped::kNo == mipMapped) { |
| 200 | // We did a copy so the texture IDs should be different |
| 201 | REPORTER_ASSERT(reporter, origImageInfo.fImage != genImageInfo.fImage); |
| 202 | } else { |
| 203 | REPORTER_ASSERT(reporter, origImageInfo.fImage == genImageInfo.fImage); |
| 204 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 205 | } else { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 206 | ERRORF(reporter, "Failed to get GrVkImageInfo"); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 207 | } |
| 208 | #endif |
Jim Van Verth | 9896a0d | 2019-04-10 15:11:12 -0400 | [diff] [blame] | 209 | #ifdef SK_METAL |
| 210 | } else if (GrBackendApi::kMetal == genBackendTex.backend()) { |
| 211 | GrMtlTextureInfo genImageInfo; |
| 212 | GrMtlTextureInfo origImageInfo; |
| 213 | if (genBackendTex.getMtlTextureInfo(&genImageInfo) && |
| 214 | backendTex.getMtlTextureInfo(&origImageInfo)) { |
| 215 | if (willUseMips && GrMipMapped::kNo == mipMapped) { |
| 216 | // We did a copy so the texture IDs should be different |
| 217 | REPORTER_ASSERT(reporter, origImageInfo.fTexture != genImageInfo.fTexture); |
| 218 | } else { |
| 219 | REPORTER_ASSERT(reporter, origImageInfo.fTexture == genImageInfo.fTexture); |
| 220 | } |
| 221 | } else { |
| 222 | ERRORF(reporter, "Failed to get GrMtlTextureInfo"); |
| 223 | } |
| 224 | #endif |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 225 | } else { |
| 226 | REPORTER_ASSERT(reporter, false); |
| 227 | } |
| 228 | |
| 229 | // Must make sure the uses of the backend texture have finished (we possibly have a |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 230 | // queued up copy) before we delete the backend texture. |
| 231 | context->flush(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 232 | |
Robert Phillips | 9b16f81 | 2019-05-17 10:01:21 -0400 | [diff] [blame] | 233 | context->priv().getGpu()->testingOnly_flushGpuAndSync(); |
| 234 | |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 235 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 240 | // Test that when we call makeImageSnapshot on an SkSurface we retains the same mip status as the |
| 241 | // resource we took the snapshot of. |
| 242 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxInfo) { |
| 243 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 244 | if (!context->priv().caps()->mipMapSupport()) { |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 245 | return; |
| 246 | } |
| 247 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 248 | auto resourceProvider = context->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 249 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 250 | for (auto willUseMips : {false, true}) { |
| 251 | for (auto isWrapped : {false, true}) { |
| 252 | GrMipMapped mipMapped = willUseMips ? GrMipMapped::kYes : GrMipMapped::kNo; |
| 253 | sk_sp<SkSurface> surface; |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 254 | GrBackendTexture backendTex = context->createBackendTexture( |
Robert Phillips | 8062679 | 2019-06-04 07:16:10 -0400 | [diff] [blame] | 255 | kSize, kSize, kRGBA_8888_SkColorType, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 256 | SkColors::kTransparent, mipMapped, GrRenderable::kYes, GrProtected::kNo); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 257 | if (isWrapped) { |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 258 | surface = SkSurface::MakeFromBackendTexture(context, |
| 259 | backendTex, |
| 260 | kTopLeft_GrSurfaceOrigin, |
| 261 | 0, |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 262 | kRGBA_8888_SkColorType, |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 263 | nullptr, |
| 264 | nullptr); |
| 265 | } else { |
| 266 | SkImageInfo info = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, |
| 267 | kPremul_SkAlphaType); |
| 268 | surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0, |
| 269 | kTopLeft_GrSurfaceOrigin, nullptr, |
| 270 | willUseMips); |
| 271 | } |
| 272 | REPORTER_ASSERT(reporter, surface); |
| 273 | if (!surface) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 274 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 275 | } |
| 276 | SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); |
| 277 | GrTextureProxy* texProxy = device->accessRenderTargetContext()->asTextureProxy(); |
| 278 | REPORTER_ASSERT(reporter, mipMapped == texProxy->mipMapped()); |
| 279 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 280 | texProxy->instantiate(resourceProvider); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 281 | GrTexture* texture = texProxy->peekTexture(); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 282 | REPORTER_ASSERT(reporter, mipMapped == texture->texturePriv().mipMapped()); |
| 283 | |
| 284 | sk_sp<SkImage> image = surface->makeImageSnapshot(); |
| 285 | REPORTER_ASSERT(reporter, image); |
| 286 | if (!image) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 287 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 288 | } |
| 289 | texProxy = as_IB(image)->peekProxy(); |
| 290 | REPORTER_ASSERT(reporter, mipMapped == texProxy->mipMapped()); |
| 291 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 292 | texProxy->instantiate(resourceProvider); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 293 | texture = texProxy->peekTexture(); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 294 | REPORTER_ASSERT(reporter, mipMapped == texture->texturePriv().mipMapped()); |
| 295 | |
| 296 | // Must flush the context to make sure all the cmds (copies, etc.) from above are sent |
| 297 | // to the gpu before we delete the backendHandle. |
| 298 | context->flush(); |
Robert Phillips | 9b16f81 | 2019-05-17 10:01:21 -0400 | [diff] [blame] | 299 | context->priv().getGpu()->testingOnly_flushGpuAndSync(); |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 300 | context->deleteBackendTexture(backendTex); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 304 | |
| 305 | // Test that we don't create a mip mapped texture if the size is 1x1 even if the filter mode is set |
| 306 | // to use mips. This test passes by not crashing or hitting asserts in code. |
| 307 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(Gr1x1TextureMipMappedTest, reporter, ctxInfo) { |
| 308 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 309 | if (!context->priv().caps()->mipMapSupport()) { |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | |
| 313 | // Make surface to draw into |
| 314 | SkImageInfo info = SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType); |
| 315 | sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); |
| 316 | |
| 317 | // Make 1x1 raster bitmap |
| 318 | SkBitmap bmp; |
| 319 | bmp.allocN32Pixels(1, 1); |
| 320 | SkPMColor* pixel = reinterpret_cast<SkPMColor*>(bmp.getPixels()); |
| 321 | *pixel = 0; |
| 322 | |
| 323 | sk_sp<SkImage> bmpImage = SkImage::MakeFromBitmap(bmp); |
| 324 | |
| 325 | // Make sure we scale so we don't optimize out the use of mips. |
| 326 | surface->getCanvas()->scale(0.5f, 0.5f); |
| 327 | |
| 328 | SkPaint paint; |
| 329 | // This should upload the image to a non mipped GrTextureProxy. |
| 330 | surface->getCanvas()->drawImage(bmpImage, 0, 0, &paint); |
| 331 | surface->flush(); |
| 332 | |
| 333 | // Now set the filter quality to high so we use mip maps. We should find the non mipped texture |
| 334 | // in the cache for the SkImage. Since the texture is 1x1 we should just use that texture |
| 335 | // instead of trying to do a copy to a mipped texture. |
| 336 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 337 | surface->getCanvas()->drawImage(bmpImage, 0, 0, &paint); |
| 338 | surface->flush(); |
| 339 | } |
| 340 | |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 341 | // Create a new render target and draw 'mipmapProxy' into it using the provided 'filter'. |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 342 | static std::unique_ptr<GrRenderTargetContext> draw_mipmap_into_new_render_target( |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 343 | GrRecordingContext* context, GrProxyProvider* proxyProvider, GrColorType colorType, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 344 | SkAlphaType alphaType, sk_sp<GrTextureProxy> mipmapProxy, GrSamplerState::Filter filter) { |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 345 | GrSurfaceDesc desc; |
| 346 | desc.fWidth = 1; |
| 347 | desc.fHeight = 1; |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 348 | GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(mipmapProxy->backendFormat(), |
| 349 | colorType); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 350 | sk_sp<GrSurfaceProxy> renderTarget = proxyProvider->createProxy( |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 351 | mipmapProxy->backendFormat(), desc, swizzle, GrRenderable::kYes, 1, |
| 352 | kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes, |
| 353 | GrProtected::kNo); |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 354 | |
| 355 | auto rtc = GrRenderTargetContext::Make( |
| 356 | context, colorType, nullptr, std::move(renderTarget), kTopLeft_GrSurfaceOrigin, |
| 357 | nullptr); |
| 358 | |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 359 | rtc->drawTexture(GrNoClip(), mipmapProxy, colorType, alphaType, filter, SkBlendMode::kSrcOver, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 360 | {1,1,1,1}, SkRect::MakeWH(4, 4), SkRect::MakeWH(1,1), GrAA::kYes, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 361 | GrQuadAAFlags::kAll, SkCanvas::kFast_SrcRectConstraint, SkMatrix::I(), |
| 362 | nullptr); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 363 | return rtc; |
| 364 | } |
| 365 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 366 | // 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] | 367 | DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) { |
| 368 | using CanClearFullscreen = GrRenderTargetContext::CanClearFullscreen; |
| 369 | using Enable = GrContextOptions::Enable; |
| 370 | using Filter = GrSamplerState::Filter; |
| 371 | |
| 372 | for (auto enableSortingAndReduction : {Enable::kYes, Enable::kNo}) { |
| 373 | GrMockOptions mockOptions; |
| 374 | mockOptions.fMipMapSupport = true; |
| 375 | GrContextOptions ctxOptions; |
Greg Daniel | 9313874 | 2019-08-22 17:15:39 -0400 | [diff] [blame] | 376 | ctxOptions.fReduceOpsTaskSplitting = enableSortingAndReduction; |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 377 | sk_sp<GrContext> context = GrContext::MakeMock(&mockOptions, ctxOptions); |
| 378 | if (!context) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 379 | ERRORF(reporter, "could not create mock context with fReduceOpsTaskSplitting %s.", |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 380 | (Enable::kYes == enableSortingAndReduction) ? "enabled" : "disabled"); |
| 381 | continue; |
| 382 | } |
| 383 | |
| 384 | SkASSERT(context->priv().caps()->mipMapSupport()); |
| 385 | |
| 386 | GrBackendFormat format = context->defaultBackendFormat( |
| 387 | kRGBA_8888_SkColorType, GrRenderable::kYes); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 388 | GrColorType colorType = GrColorType::kRGBA_8888; |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 389 | SkAlphaType alphaType = kPremul_SkAlphaType; |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 390 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 391 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
| 392 | |
| 393 | // Create a mipmapped render target. |
| 394 | GrSurfaceDesc desc; |
| 395 | desc.fWidth = 4; |
| 396 | desc.fHeight = 4; |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 397 | |
| 398 | GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, colorType); |
| 399 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 400 | sk_sp<GrTextureProxy> mipmapProxy = proxyProvider->createProxy( |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 401 | format, desc, swizzle, GrRenderable::kYes, 1, kTopLeft_GrSurfaceOrigin, |
| 402 | GrMipMapped::kYes, SkBackingFit::kExact, SkBudgeted::kYes, GrProtected::kNo); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 403 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 404 | // Mark the mipmaps clean to ensure things still work properly when they won't be marked |
| 405 | // dirty again until GrRenderTask::makeClosed(). |
| 406 | mipmapProxy->markMipMapsClean(); |
| 407 | |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 408 | auto mipmapRTC = GrRenderTargetContext::Make( |
| 409 | context.get(), colorType, nullptr, mipmapProxy, kTopLeft_GrSurfaceOrigin, nullptr); |
| 410 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 411 | mipmapRTC->clear(nullptr, {.1f,.2f,.3f,.4f}, CanClearFullscreen::kYes); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 412 | REPORTER_ASSERT(reporter, mipmapProxy->getLastRenderTask()); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 413 | // 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] | 414 | REPORTER_ASSERT(reporter, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 415 | mipmapRTC->testingOnly_PeekLastOpsTask() == mipmapProxy->getLastRenderTask()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 416 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 417 | // Mipmaps don't get marked dirty until makeClosed(). |
| 418 | REPORTER_ASSERT(reporter, !mipmapProxy->mipMapsAreDirty()); |
| 419 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 420 | // Draw the dirty mipmap texture into a render target. |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 421 | auto rtc1 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 422 | alphaType, mipmapProxy, Filter::kMipMap); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 423 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 424 | // Mipmaps should have gotten marked dirty during makeClosed, then marked clean again as |
| 425 | // 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] | 426 | // 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] | 427 | // task that resolved its mips. |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 428 | GrRenderTask* initialMipmapRegenTask = mipmapProxy->getLastRenderTask(); |
| 429 | REPORTER_ASSERT(reporter, initialMipmapRegenTask); |
| 430 | REPORTER_ASSERT(reporter, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 431 | initialMipmapRegenTask != mipmapRTC->testingOnly_PeekLastOpsTask()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 432 | REPORTER_ASSERT(reporter, !mipmapProxy->mipMapsAreDirty()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 433 | |
| 434 | // Draw the now-clean mipmap texture into a second target. |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 435 | auto rtc2 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 436 | alphaType, mipmapProxy, Filter::kMipMap); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 437 | |
| 438 | // Make sure the mipmap texture still has the same regen task. |
| 439 | REPORTER_ASSERT(reporter, mipmapProxy->getLastRenderTask() == initialMipmapRegenTask); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 440 | SkASSERT(!mipmapProxy->mipMapsAreDirty()); |
| 441 | |
| 442 | // Reset everything so we can go again, this time with the first draw not mipmapped. |
| 443 | context->flush(); |
| 444 | |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 445 | // Mip regen tasks don't get added as dependencies until makeClosed(). |
| 446 | REPORTER_ASSERT(reporter, |
| 447 | rtc1->testingOnly_PeekLastOpsTask()->dependsOn(initialMipmapRegenTask)); |
| 448 | REPORTER_ASSERT(reporter, |
| 449 | rtc2->testingOnly_PeekLastOpsTask()->dependsOn(initialMipmapRegenTask)); |
| 450 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 451 | // Render something to dirty the mips. |
| 452 | mipmapRTC->clear(nullptr, {.1f,.2f,.3f,.4f}, CanClearFullscreen::kYes); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 453 | REPORTER_ASSERT(reporter, mipmapProxy->getLastRenderTask()); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 454 | // 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] | 455 | REPORTER_ASSERT(reporter, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 456 | mipmapRTC->testingOnly_PeekLastOpsTask() == mipmapProxy->getLastRenderTask()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 457 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 458 | // Mipmaps don't get marked dirty until makeClosed(). |
| 459 | REPORTER_ASSERT(reporter, !mipmapProxy->mipMapsAreDirty()); |
| 460 | |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 461 | // Draw the dirty mipmap texture into a render target, but don't do mipmap filtering. |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 462 | rtc1 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 463 | alphaType, mipmapProxy, Filter::kBilerp); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 464 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 465 | // Mipmaps should have gotten marked dirty during makeClosed() when adding the dependency. |
| 466 | // Since the last draw did not use mips, they will not have been regenerated and should |
| 467 | // therefore still be dirty. |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 468 | REPORTER_ASSERT(reporter, mipmapProxy->mipMapsAreDirty()); |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 469 | |
| 470 | // Since mips weren't regenerated, the last render task shouldn't have changed. |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 471 | REPORTER_ASSERT(reporter, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 472 | mipmapRTC->testingOnly_PeekLastOpsTask() == mipmapProxy->getLastRenderTask()); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 473 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 474 | // Draw the stil-dirty mipmap texture into a second target with mipmap filtering. |
Greg Daniel | ba0ff78 | 2020-01-07 15:42:57 -0500 | [diff] [blame] | 475 | rtc2 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 476 | alphaType, mipmapProxy, Filter::kMipMap); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 477 | |
Chris Dalton | aa3cbb8 | 2019-08-21 00:01:21 -0600 | [diff] [blame] | 478 | // Make sure the mipmap texture now has a new last render task that regenerates the mips, |
| 479 | // and that the mipmaps are now clean. |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 480 | auto mipRegenTask2 = mipmapProxy->getLastRenderTask(); |
| 481 | REPORTER_ASSERT(reporter, mipRegenTask2); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 482 | REPORTER_ASSERT(reporter, |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 483 | mipmapRTC->testingOnly_PeekLastOpsTask() != mipRegenTask2); |
Chris Dalton | 30eea6c | 2019-08-21 10:22:50 -0600 | [diff] [blame] | 484 | SkASSERT(!mipmapProxy->mipMapsAreDirty()); |
Chris Dalton | e2a903e | 2019-09-18 13:41:50 -0600 | [diff] [blame] | 485 | |
| 486 | // Mip regen tasks don't get added as dependencies until makeClosed(). |
| 487 | context->flush(); |
| 488 | REPORTER_ASSERT(reporter, rtc2->testingOnly_PeekLastOpsTask()->dependsOn(mipRegenTask2)); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 489 | } |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 490 | } |