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