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 | |
| 8 | #include "SkTypes.h" |
| 9 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 10 | #include "GrBackendSurface.h" |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 11 | #include "GrBackendTextureImageGenerator.h" |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 12 | #include "GrContext.h" |
| 13 | #include "GrContextPriv.h" |
| 14 | #include "GrGpu.h" |
| 15 | #include "GrRenderTargetContext.h" |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 16 | #include "GrSemaphore.h" |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 17 | #include "GrSurfaceProxyPriv.h" |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 18 | #include "GrTexturePriv.h" |
| 19 | #include "GrTextureProxy.h" |
| 20 | #include "SkCanvas.h" |
| 21 | #include "SkImage_Base.h" |
| 22 | #include "SkGpuDevice.h" |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 23 | #include "SkPoint.h" |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 24 | #include "SkSurface.h" |
| 25 | #include "SkSurface_Gpu.h" |
| 26 | #include "Test.h" |
| 27 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 28 | static constexpr int kSize = 8; |
| 29 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 30 | // Test that the correct mip map states are on the GrTextures when wrapping GrBackendTextures in |
| 31 | // SkImages and SkSurfaces |
| 32 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { |
| 33 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 34 | if (!context->priv().caps()->mipMapSupport()) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 35 | return; |
| 36 | } |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 37 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 38 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 39 | for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { |
| 40 | for (auto isRT : {false, true}) { |
| 41 | // CreateTestingOnlyBackendTexture currently doesn't support uploading data to mip maps |
| 42 | // so we don't send any. However, we pretend there is data for the checks below which is |
| 43 | // fine since we are never actually using these textures for any work on the gpu. |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 44 | GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 45 | nullptr, kSize, kSize, GrColorType::kRGBA_8888, isRT, mipMapped); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 46 | |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 47 | sk_sp<GrTextureProxy> proxy; |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 48 | sk_sp<SkImage> image; |
| 49 | if (isRT) { |
| 50 | sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture( |
| 51 | context, |
| 52 | backendTex, |
| 53 | kTopLeft_GrSurfaceOrigin, |
| 54 | 0, |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 55 | kRGBA_8888_SkColorType, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 56 | nullptr, |
| 57 | nullptr); |
| 58 | |
| 59 | SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 60 | proxy = device->accessRenderTargetContext()->asTextureProxyRef(); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 61 | } else { |
| 62 | image = SkImage::MakeFromTexture(context, backendTex, |
| 63 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 64 | kRGBA_8888_SkColorType, |
| 65 | kPremul_SkAlphaType, nullptr, |
| 66 | nullptr, nullptr); |
Robert Phillips | e0070c0 | 2017-11-13 12:47:24 -0500 | [diff] [blame] | 67 | proxy = as_IB(image)->asTextureProxyRef(); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 68 | } |
| 69 | REPORTER_ASSERT(reporter, proxy); |
| 70 | if (!proxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 71 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 72 | return; |
| 73 | } |
| 74 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 75 | REPORTER_ASSERT(reporter, proxy->isInstantiated()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 76 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 77 | GrTexture* texture = proxy->peekTexture(); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 78 | REPORTER_ASSERT(reporter, texture); |
| 79 | if (!texture) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 80 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
| 84 | if (GrMipMapped::kYes == mipMapped) { |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 85 | REPORTER_ASSERT(reporter, GrMipMapped::kYes == texture->texturePriv().mipMapped()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 86 | if (isRT) { |
| 87 | REPORTER_ASSERT(reporter, texture->texturePriv().mipMapsAreDirty()); |
| 88 | } else { |
| 89 | REPORTER_ASSERT(reporter, !texture->texturePriv().mipMapsAreDirty()); |
| 90 | } |
| 91 | } else { |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 92 | REPORTER_ASSERT(reporter, GrMipMapped::kNo == texture->texturePriv().mipMapped()); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 93 | } |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 94 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 99 | // Test that we correctly copy or don't copy GrBackendTextures in the GrBackendTextureImageGenerator |
| 100 | // based on if we will use mips in the draw and the mip status of the GrBackendTexture. |
| 101 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, ctxInfo) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 102 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 103 | if (!context->priv().caps()->mipMapSupport()) { |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 104 | return; |
| 105 | } |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 106 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 107 | |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 108 | for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { |
| 109 | for (auto willUseMips : {false, true}) { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 110 | GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 111 | nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, mipMapped); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 112 | |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 113 | sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backendTex, |
| 114 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 115 | kRGBA_8888_SkColorType, |
| 116 | kPremul_SkAlphaType, nullptr, |
| 117 | nullptr, nullptr); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 118 | |
| 119 | GrTextureProxy* proxy = as_IB(image)->peekProxy(); |
| 120 | REPORTER_ASSERT(reporter, proxy); |
| 121 | if (!proxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 122 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 123 | return; |
| 124 | } |
| 125 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 126 | REPORTER_ASSERT(reporter, proxy->isInstantiated()); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 127 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 128 | sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture()); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 129 | REPORTER_ASSERT(reporter, texture); |
| 130 | if (!texture) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 131 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 132 | return; |
| 133 | } |
| 134 | |
| 135 | std::unique_ptr<SkImageGenerator> imageGen = GrBackendTextureImageGenerator::Make( |
Brian Osman | 052ef69 | 2018-03-27 09:56:31 -0400 | [diff] [blame] | 136 | texture, kTopLeft_GrSurfaceOrigin, nullptr, kRGBA_8888_SkColorType, |
| 137 | kPremul_SkAlphaType, nullptr); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 138 | REPORTER_ASSERT(reporter, imageGen); |
| 139 | if (!imageGen) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 140 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | |
| 144 | SkIPoint origin = SkIPoint::Make(0,0); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 145 | SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, |
| 146 | kPremul_SkAlphaType); |
| 147 | sk_sp<GrTextureProxy> genProxy = imageGen->generateTexture(context, imageInfo, |
Brian Osman | c87cfb6 | 2018-07-11 09:08:46 -0400 | [diff] [blame] | 148 | origin, willUseMips); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 149 | |
| 150 | REPORTER_ASSERT(reporter, genProxy); |
| 151 | if (!genProxy) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 152 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 153 | return; |
| 154 | } |
| 155 | |
Greg Daniel | e728f67 | 2018-01-17 10:52:04 -0500 | [diff] [blame] | 156 | if (GrSurfaceProxy::LazyState::kNot != genProxy->lazyInstantiationState()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 157 | genProxy->priv().doLazyInstantiation(context->priv().resourceProvider()); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 158 | } else if (!genProxy->isInstantiated()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 159 | genProxy->instantiate(context->priv().resourceProvider()); |
Greg Daniel | e728f67 | 2018-01-17 10:52:04 -0500 | [diff] [blame] | 160 | } |
| 161 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 162 | REPORTER_ASSERT(reporter, genProxy->isInstantiated()); |
| 163 | if (!genProxy->isInstantiated()) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 164 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | bddcc95 | 2018-01-24 13:22:24 -0500 | [diff] [blame] | 165 | return; |
| 166 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 167 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 168 | GrTexture* genTexture = genProxy->peekTexture(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 169 | REPORTER_ASSERT(reporter, genTexture); |
| 170 | if (!genTexture) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 171 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 175 | GrBackendTexture genBackendTex = genTexture->getBackendTexture(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 176 | |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 177 | if (GrBackendApi::kOpenGL == genBackendTex.backend()) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 178 | GrGLTextureInfo genTexInfo; |
| 179 | GrGLTextureInfo origTexInfo; |
| 180 | if (genBackendTex.getGLTextureInfo(&genTexInfo) && |
| 181 | backendTex.getGLTextureInfo(&origTexInfo)) { |
| 182 | if (willUseMips && GrMipMapped::kNo == mipMapped) { |
| 183 | // We did a copy so the texture IDs should be different |
| 184 | REPORTER_ASSERT(reporter, origTexInfo.fID != genTexInfo.fID); |
| 185 | } else { |
| 186 | REPORTER_ASSERT(reporter, origTexInfo.fID == genTexInfo.fID); |
| 187 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 188 | } else { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 189 | ERRORF(reporter, "Failed to get GrGLTextureInfo"); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 190 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 191 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 192 | } else if (GrBackendApi::kVulkan == genBackendTex.backend()) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 193 | GrVkImageInfo genImageInfo; |
| 194 | GrVkImageInfo origImageInfo; |
| 195 | if (genBackendTex.getVkImageInfo(&genImageInfo) && |
| 196 | backendTex.getVkImageInfo(&origImageInfo)) { |
| 197 | if (willUseMips && GrMipMapped::kNo == mipMapped) { |
| 198 | // We did a copy so the texture IDs should be different |
| 199 | REPORTER_ASSERT(reporter, origImageInfo.fImage != genImageInfo.fImage); |
| 200 | } else { |
| 201 | REPORTER_ASSERT(reporter, origImageInfo.fImage == genImageInfo.fImage); |
| 202 | } |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 203 | } else { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 204 | ERRORF(reporter, "Failed to get GrVkImageInfo"); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 205 | } |
| 206 | #endif |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 207 | } else { |
| 208 | REPORTER_ASSERT(reporter, false); |
| 209 | } |
| 210 | |
| 211 | // 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] | 212 | // queued up copy) before we delete the backend texture. |
| 213 | context->flush(); |
| 214 | gpu->testingOnly_flushGpuAndSync(); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 215 | |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 216 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 261b8aa | 2017-10-23 09:37:36 -0400 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 221 | // Test that when we call makeImageSnapshot on an SkSurface we retains the same mip status as the |
| 222 | // resource we took the snapshot of. |
| 223 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxInfo) { |
| 224 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 225 | if (!context->priv().caps()->mipMapSupport()) { |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 226 | return; |
| 227 | } |
| 228 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 229 | auto resourceProvider = context->priv().resourceProvider(); |
| 230 | GrGpu* gpu = context->priv().getGpu(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 231 | |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 232 | for (auto willUseMips : {false, true}) { |
| 233 | for (auto isWrapped : {false, true}) { |
| 234 | GrMipMapped mipMapped = willUseMips ? GrMipMapped::kYes : GrMipMapped::kNo; |
| 235 | sk_sp<SkSurface> surface; |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 236 | GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 237 | nullptr, kSize, kSize, GrColorType::kRGBA_8888, true, mipMapped); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 238 | if (isWrapped) { |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 239 | surface = SkSurface::MakeFromBackendTexture(context, |
| 240 | backendTex, |
| 241 | kTopLeft_GrSurfaceOrigin, |
| 242 | 0, |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 243 | kRGBA_8888_SkColorType, |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 244 | nullptr, |
| 245 | nullptr); |
| 246 | } else { |
| 247 | SkImageInfo info = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, |
| 248 | kPremul_SkAlphaType); |
| 249 | surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0, |
| 250 | kTopLeft_GrSurfaceOrigin, nullptr, |
| 251 | willUseMips); |
| 252 | } |
| 253 | REPORTER_ASSERT(reporter, surface); |
| 254 | if (!surface) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 255 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 256 | } |
| 257 | SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); |
| 258 | GrTextureProxy* texProxy = device->accessRenderTargetContext()->asTextureProxy(); |
| 259 | REPORTER_ASSERT(reporter, mipMapped == texProxy->mipMapped()); |
| 260 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 261 | texProxy->instantiate(resourceProvider); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 262 | GrTexture* texture = texProxy->peekTexture(); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 263 | REPORTER_ASSERT(reporter, mipMapped == texture->texturePriv().mipMapped()); |
| 264 | |
| 265 | sk_sp<SkImage> image = surface->makeImageSnapshot(); |
| 266 | REPORTER_ASSERT(reporter, image); |
| 267 | if (!image) { |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 268 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 269 | } |
| 270 | texProxy = as_IB(image)->peekProxy(); |
| 271 | REPORTER_ASSERT(reporter, mipMapped == texProxy->mipMapped()); |
| 272 | |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 273 | texProxy->instantiate(resourceProvider); |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 274 | texture = texProxy->peekTexture(); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 275 | REPORTER_ASSERT(reporter, mipMapped == texture->texturePriv().mipMapped()); |
| 276 | |
| 277 | // Must flush the context to make sure all the cmds (copies, etc.) from above are sent |
| 278 | // to the gpu before we delete the backendHandle. |
| 279 | context->flush(); |
Greg Daniel | d2d367d | 2018-04-16 10:24:45 -0400 | [diff] [blame] | 280 | gpu->testingOnly_flushGpuAndSync(); |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 281 | gpu->deleteTestingOnlyBackendTexture(backendTex); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | } |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 285 | |
| 286 | // Test that we don't create a mip mapped texture if the size is 1x1 even if the filter mode is set |
| 287 | // to use mips. This test passes by not crashing or hitting asserts in code. |
| 288 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(Gr1x1TextureMipMappedTest, reporter, ctxInfo) { |
| 289 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 290 | if (!context->priv().caps()->mipMapSupport()) { |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | |
| 294 | // Make surface to draw into |
| 295 | SkImageInfo info = SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType); |
| 296 | sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); |
| 297 | |
| 298 | // Make 1x1 raster bitmap |
| 299 | SkBitmap bmp; |
| 300 | bmp.allocN32Pixels(1, 1); |
| 301 | SkPMColor* pixel = reinterpret_cast<SkPMColor*>(bmp.getPixels()); |
| 302 | *pixel = 0; |
| 303 | |
| 304 | sk_sp<SkImage> bmpImage = SkImage::MakeFromBitmap(bmp); |
| 305 | |
| 306 | // Make sure we scale so we don't optimize out the use of mips. |
| 307 | surface->getCanvas()->scale(0.5f, 0.5f); |
| 308 | |
| 309 | SkPaint paint; |
| 310 | // This should upload the image to a non mipped GrTextureProxy. |
| 311 | surface->getCanvas()->drawImage(bmpImage, 0, 0, &paint); |
| 312 | surface->flush(); |
| 313 | |
| 314 | // Now set the filter quality to high so we use mip maps. We should find the non mipped texture |
| 315 | // in the cache for the SkImage. Since the texture is 1x1 we should just use that texture |
| 316 | // instead of trying to do a copy to a mipped texture. |
| 317 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 318 | surface->getCanvas()->drawImage(bmpImage, 0, 0, &paint); |
| 319 | surface->flush(); |
| 320 | } |
| 321 | |