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