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