1 /*
2  * Copyright 2013 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 "include/core/SkAlphaType.h"
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkColorSpace.h"
12 #include "include/core/SkColorType.h"
13 #include "include/core/SkData.h"
14 #include "include/core/SkImage.h"
15 #include "include/core/SkImageInfo.h"
16 #include "include/core/SkPixmap.h"
17 #include "include/core/SkRect.h"
18 #include "include/core/SkRefCnt.h"
19 #include "include/core/SkSamplingOptions.h"
20 #include "include/core/SkSize.h"
21 #include "include/core/SkString.h"
22 #include "include/core/SkTypes.h"
23 #include "include/gpu/GpuTypes.h"
24 #include "include/gpu/GrBackendSurface.h"
25 #include "include/gpu/GrContextOptions.h"
26 #include "include/gpu/GrDirectContext.h"
27 #include "include/gpu/GrTypes.h"
28 #include "include/private/base/SkTo.h"
29 #include "include/private/gpu/ganesh/GrTypesPriv.h"
30 #include "src/core/SkAutoPixmapStorage.h"
31 #include "src/core/SkCompressedDataUtils.h"
32 #include "src/gpu/SkBackingFit.h"
33 #include "src/gpu/Swizzle.h"
34 #include "src/gpu/ganesh/GrBackendUtils.h"
35 #include "src/gpu/ganesh/GrCaps.h"
36 #include "src/gpu/ganesh/GrColorInfo.h"
37 #include "src/gpu/ganesh/GrDataUtils.h"
38 #include "src/gpu/ganesh/GrDirectContextPriv.h"
39 #include "src/gpu/ganesh/GrGpu.h"
40 #include "src/gpu/ganesh/GrImageInfo.h"
41 #include "src/gpu/ganesh/GrProxyProvider.h"
42 #include "src/gpu/ganesh/GrRenderTarget.h"
43 #include "src/gpu/ganesh/GrResourceCache.h"
44 #include "src/gpu/ganesh/GrResourceProvider.h"
45 #include "src/gpu/ganesh/GrSamplerState.h"
46 #include "src/gpu/ganesh/GrSurface.h"
47 #include "src/gpu/ganesh/GrSurfaceProxy.h"
48 #include "src/gpu/ganesh/GrSurfaceProxyView.h"
49 #include "src/gpu/ganesh/GrTexture.h"
50 #include "src/gpu/ganesh/GrTextureProxy.h"
51 #include "src/gpu/ganesh/SkGr.h"
52 #include "src/gpu/ganesh/SurfaceContext.h"
53 #include "src/gpu/ganesh/TestFormatColorTypeCombination.h"
54 #include "tests/CtsEnforcement.h"
55 #include "tests/Test.h"
56 #include "tools/gpu/ManagedBackendTexture.h"
57 
58 #include <cstdint>
59 #include <functional>
60 #include <initializer_list>
61 #include <memory>
62 #include <tuple>
63 #include <utility>
64 #include <vector>
65 
66 // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
67 // and render targets to GrSurface all work as expected.
DEF_GANESH_TEST_FOR_MOCK_CONTEXT(GrSurface,reporter,ctxInfo)68 DEF_GANESH_TEST_FOR_MOCK_CONTEXT(GrSurface, reporter, ctxInfo) {
69     auto context = ctxInfo.directContext();
70     auto resourceProvider = context->priv().resourceProvider();
71 
72     static constexpr SkISize kDesc = {256, 256};
73     auto format = context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
74                                                                   GrRenderable::kYes);
75     sk_sp<GrSurface> texRT1 = resourceProvider->createTexture(kDesc,
76                                                               format,
77                                                               GrTextureType::k2D,
78                                                               GrRenderable::kYes,
79                                                               1,
80                                                               GrMipmapped::kNo,
81                                                               skgpu::Budgeted::kNo,
82                                                               GrProtected::kNo,
83                                                               /*label=*/{});
84 
85     REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget());
86     REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture());
87     REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
88                     texRT1->asTexture());
89     REPORTER_ASSERT(reporter, texRT1->asRenderTarget() ==
90                     static_cast<GrSurface*>(texRT1->asTexture()));
91     REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
92                     static_cast<GrSurface*>(texRT1->asTexture()));
93 
94     sk_sp<GrTexture> tex1 = resourceProvider->createTexture(kDesc,
95                                                             format,
96                                                             GrTextureType::k2D,
97                                                             GrRenderable::kNo,
98                                                             1,
99                                                             GrMipmapped::kNo,
100                                                             skgpu::Budgeted::kNo,
101                                                             GrProtected::kNo,
102                                                             /*label=*/{});
103     REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
104     REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture());
105     REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
106 
107     GrBackendTexture backendTex = context->createBackendTexture(256,
108                                                                 256,
109                                                                 kRGBA_8888_SkColorType,
110                                                                 SkColors::kTransparent,
111                                                                 GrMipmapped::kNo,
112                                                                 GrRenderable::kNo,
113                                                                 GrProtected::kNo);
114 
115     sk_sp<GrSurface> texRT2 = resourceProvider->wrapRenderableBackendTexture(
116             backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
117 
118     REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
119     REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
120     REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
121                     texRT2->asTexture());
122     REPORTER_ASSERT(reporter, texRT2->asRenderTarget() ==
123                     static_cast<GrSurface*>(texRT2->asTexture()));
124     REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
125                     static_cast<GrSurface*>(texRT2->asTexture()));
126 
127     context->deleteBackendTexture(backendTex);
128 }
129 
130 // This test checks that the isFormatTexturable and isFormatRenderable are
131 // consistent with createTexture's result.
DEF_GANESH_TEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability,reporter,ctxInfo,CtsEnforcement::kApiLevel_T)132 DEF_GANESH_TEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability,
133                                  reporter,
134                                  ctxInfo,
135                                  CtsEnforcement::kApiLevel_T) {
136     auto context = ctxInfo.directContext();
137     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
138     GrResourceProvider* resourceProvider = context->priv().resourceProvider();
139     const GrCaps* caps = context->priv().caps();
140 
141     // TODO: Should only need format here but need to determine compression type from format
142     // without config.
143     auto createTexture = [](SkISize dimensions, GrColorType colorType,
144                             const GrBackendFormat& format, GrRenderable renderable,
145                             GrResourceProvider* rp) -> sk_sp<GrTexture> {
146         SkImage::CompressionType compression = GrBackendFormatToCompressionType(format);
147         if (compression != SkImage::CompressionType::kNone) {
148             if (renderable == GrRenderable::kYes) {
149                 return nullptr;
150             }
151             auto size = SkCompressedDataSize(compression, dimensions, nullptr, false);
152             auto data = SkData::MakeUninitialized(size);
153             SkColor4f color = {0, 0, 0, 0};
154             GrFillInCompressedData(compression, dimensions, GrMipmapped::kNo,
155                                    (char*)data->writable_data(), color);
156             return rp->createCompressedTexture(dimensions,
157                                                format,
158                                                skgpu::Budgeted::kNo,
159                                                GrMipmapped::kNo,
160                                                GrProtected::kNo,
161                                                data.get(),
162                                                /*label=*/{});
163         } else {
164             return rp->createTexture(dimensions,
165                                      format,
166                                      GrTextureType::k2D,
167                                      renderable,
168                                      1,
169                                      GrMipmapped::kNo,
170                                      skgpu::Budgeted::kNo,
171                                      GrProtected::kNo,
172                                      /*label=*/{});
173         }
174     };
175 
176     static constexpr SkISize kDims = {64, 64};
177 
178     const std::vector<GrTest::TestFormatColorTypeCombination>& combos =
179             caps->getTestingCombinations();
180 
181     for (const GrTest::TestFormatColorTypeCombination& combo : combos) {
182 
183         SkASSERT(combo.fColorType != GrColorType::kUnknown);
184         SkASSERT(combo.fFormat.isValid());
185 
186         // Right now Vulkan has two backend formats that support ABGR_4444 (R4G4B4A4 and B4G4R4A4).
187         // Until we can create textures directly from the backend format this yields some
188         // ambiguity in what is actually supported and which textures can be created.
189         if (ctxInfo.backend() == kVulkan_GrBackend && combo.fColorType == GrColorType::kABGR_4444) {
190             continue;
191         }
192 
193         // Check if 'isFormatTexturable' agrees with 'createTexture' and that the mipmap
194         // support check is working
195         {
196             bool isCompressed = caps->isFormatCompressed(combo.fFormat);
197             bool isTexturable = caps->isFormatTexturable(combo.fFormat, GrTextureType::k2D);
198 
199             sk_sp<GrSurface> tex = createTexture(kDims, combo.fColorType, combo.fFormat,
200                                                  GrRenderable::kNo, resourceProvider);
201             REPORTER_ASSERT(reporter, SkToBool(tex) == isTexturable,
202                             "ct:%s format:%s, tex:%d, isTexturable:%d",
203                             GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
204                             SkToBool(tex), isTexturable);
205 
206             // Check that the lack of mipmap support blocks the creation of mipmapped
207             // proxies
208             bool expectedMipMapability = isTexturable && caps->mipmapSupport() && !isCompressed;
209 
210             sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(combo.fFormat,
211                                                                      kDims,
212                                                                      GrRenderable::kNo,
213                                                                      1,
214                                                                      GrMipmapped::kYes,
215                                                                      SkBackingFit::kExact,
216                                                                      skgpu::Budgeted::kNo,
217                                                                      GrProtected::kNo,
218                                                                      /*label=*/{});
219             REPORTER_ASSERT(reporter, SkToBool(proxy.get()) == expectedMipMapability,
220                             "ct:%s format:%s, tex:%d, expectedMipMapability:%d",
221                             GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
222                             SkToBool(proxy.get()), expectedMipMapability);
223         }
224 
225         // Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' (w/o MSAA)
226         {
227             bool isRenderable = caps->isFormatRenderable(combo.fFormat, 1);
228 
229             sk_sp<GrSurface> tex = resourceProvider->createTexture(kDims,
230                                                                    combo.fFormat,
231                                                                    GrTextureType::k2D,
232                                                                    GrRenderable::kYes,
233                                                                    1,
234                                                                    GrMipmapped::kNo,
235                                                                    skgpu::Budgeted::kNo,
236                                                                    GrProtected::kNo,
237                                                                    /*label=*/{});
238             REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable,
239                             "ct:%s format:%s, tex:%d, isRenderable:%d",
240                             GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
241                             SkToBool(tex), isRenderable);
242         }
243 
244         // Check if 'isFormatAsColorTypeRenderable' agrees with 'createTexture' w/ MSAA
245         {
246             bool isRenderable = caps->isFormatRenderable(combo.fFormat, 2);
247 
248             sk_sp<GrSurface> tex = resourceProvider->createTexture(kDims,
249                                                                    combo.fFormat,
250                                                                    GrTextureType::k2D,
251                                                                    GrRenderable::kYes,
252                                                                    2,
253                                                                    GrMipmapped::kNo,
254                                                                    skgpu::Budgeted::kNo,
255                                                                    GrProtected::kNo,
256                                                                    /*label=*/{});
257             REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable,
258                             "ct:%s format:%s, tex:%d, isRenderable:%d",
259                             GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
260                             SkToBool(tex), isRenderable);
261         }
262     }
263 }
264 
265 // For each context, set it to always clear the textures and then run through all the
266 // supported formats checking that the textures are actually cleared
DEF_GANESH_TEST(InitialTextureClear,reporter,baseOptions,CtsEnforcement::kApiLevel_T)267 DEF_GANESH_TEST(InitialTextureClear, reporter, baseOptions, CtsEnforcement::kApiLevel_T) {
268     GrContextOptions options = baseOptions;
269     options.fClearAllTextures = true;
270 
271     static constexpr int kSize = 100;
272     static constexpr SkColor kClearColor = 0xABABABAB;
273 
274     const SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
275                                                     kPremul_SkAlphaType);
276 
277     SkAutoPixmapStorage readback;
278     readback.alloc(imageInfo);
279 
280     SkISize desc;
281     desc.fWidth = desc.fHeight = kSize;
282 
283     for (int ct = 0; ct < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++ct) {
284         sk_gpu_test::GrContextFactory factory(options);
285         auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(ct);
286         if (!sk_gpu_test::GrContextFactory::IsRenderingContext(contextType)) {
287             continue;
288         }
289         auto dContext = factory.get(contextType);
290         if (!dContext) {
291             continue;
292         }
293 
294         GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
295         const GrCaps* caps = dContext->priv().caps();
296 
297         const std::vector<GrTest::TestFormatColorTypeCombination>& combos =
298                 caps->getTestingCombinations();
299 
300         for (const GrTest::TestFormatColorTypeCombination& combo : combos) {
301 
302             SkASSERT(combo.fColorType != GrColorType::kUnknown);
303             SkASSERT(combo.fFormat.isValid());
304 
305             if (!caps->isFormatTexturable(combo.fFormat, GrTextureType::k2D)) {
306                 continue;
307             }
308 
309             auto checkColor = [reporter](const GrTest::TestFormatColorTypeCombination& combo,
310                                          uint32_t readColor) {
311                 // We expect that if there is no alpha in the src color type and we read it to a
312                 // color type with alpha that we will get one for alpha rather than zero. We used to
313                 // require this but the Intel Iris 6100 on Win 10 test bot doesn't put one in the
314                 // alpha channel when reading back from GL_RG16 or GL_RG16F. So now we allow either.
315                 uint32_t channels = GrColorTypeChannelFlags(combo.fColorType);
316                 bool allowAlphaOne = !(channels & kAlpha_SkColorChannelFlag);
317                 if (allowAlphaOne) {
318                     if (readColor != 0x00000000 && readColor != 0xFF000000) {
319                         ERRORF(reporter,
320                                "Failed on ct %s format %s 0x%08x is not 0x00000000 or 0xFF000000",
321                                GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
322                                readColor);
323                         return false;
324                     }
325                 } else {
326                     if (readColor) {
327                         ERRORF(reporter, "Failed on ct %s format %s 0x%08x != 0x00000000",
328                                GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(),
329                                readColor);
330                         return false;
331                     }
332                 }
333                 return true;
334             };
335 
336             for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
337                 if (renderable == GrRenderable::kYes &&
338                     !caps->isFormatAsColorTypeRenderable(combo.fColorType, combo.fFormat)) {
339                     continue;
340                 }
341 
342                 for (auto fit : {SkBackingFit::kApprox, SkBackingFit::kExact}) {
343 
344                     // Does directly allocating a texture clear it?
345                     {
346                         auto proxy = proxyProvider->testingOnly_createInstantiatedProxy(
347                                 {kSize, kSize},
348                                 combo.fFormat,
349                                 renderable,
350                                 1,
351                                 fit,
352                                 skgpu::Budgeted::kYes,
353                                 GrProtected::kNo);
354                         if (proxy) {
355                             skgpu::Swizzle swizzle = caps->getReadSwizzle(combo.fFormat,
356                                                                           combo.fColorType);
357                             GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin,
358                                                     swizzle);
359                             GrColorInfo info(combo.fColorType, kPremul_SkAlphaType, nullptr);
360                             auto texCtx = dContext->priv().makeSC(std::move(view), info);
361 
362                             readback.erase(kClearColor);
363                             if (texCtx->readPixels(dContext, readback, {0, 0})) {
364                                 for (int i = 0; i < kSize * kSize; ++i) {
365                                     if (!checkColor(combo, readback.addr32()[i])) {
366                                         break;
367                                     }
368                                 }
369                             }
370                         }
371 
372                         dContext->priv().getResourceCache()->purgeUnlockedResources();
373                     }
374 
375                     // Try creating the texture as a deferred proxy.
376                     {
377                         GrImageInfo info(combo.fColorType,
378                                          GrColorTypeHasAlpha(combo.fColorType)
379                                                                             ? kPremul_SkAlphaType
380                                                                             : kOpaque_SkAlphaType,
381                                          nullptr,
382                                          {desc.fHeight, desc.fHeight});
383 
384                         auto sc = dContext->priv().makeSC(info,
385                                                           combo.fFormat,
386                                                           /*label=*/{},
387                                                           fit,
388                                                           kTopLeft_GrSurfaceOrigin,
389                                                           renderable);
390                         if (!sc) {
391                             continue;
392                         }
393 
394                         readback.erase(kClearColor);
395                         if (sc->readPixels(dContext, readback, {0, 0})) {
396                             for (int i = 0; i < kSize * kSize; ++i) {
397                                 if (!checkColor(combo, readback.addr32()[i])) {
398                                     break;
399                                 }
400                             }
401                         }
402                         dContext->priv().getResourceCache()->purgeUnlockedResources();
403                     }
404                 }
405             }
406         }
407     }
408 }
409 
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture,reporter,context_info,CtsEnforcement::kApiLevel_T)410 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture,
411                                        reporter,
412                                        context_info,
413                                        CtsEnforcement::kApiLevel_T) {
414     auto fillPixels = [](SkPixmap* p, const std::function<uint32_t(int x, int y)>& f) {
415         for (int y = 0; y < p->height(); ++y) {
416             for (int x = 0; x < p->width(); ++x) {
417                 *p->writable_addr32(x, y) = f(x, y);
418             }
419         }
420     };
421 
422     auto comparePixels = [](const SkPixmap& p1, const SkPixmap& p2, skiatest::Reporter* reporter) {
423         SkASSERT(p1.info() == p2.info());
424         for (int y = 0; y < p1.height(); ++y) {
425             for (int x = 0; x < p1.width(); ++x) {
426                 REPORTER_ASSERT(reporter, p1.getColor(x, y) == p2.getColor(x, y));
427                 if (p1.getColor(x, y) != p2.getColor(x, y)) {
428                     return;
429                 }
430             }
431         }
432     };
433 
434     static constexpr int kSize = 100;
435     SkImageInfo ii = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
436     SkAutoPixmapStorage srcPixmap;
437     srcPixmap.alloc(ii);
438     fillPixels(&srcPixmap,
439                [](int x, int y) {
440                     return (0xFFU << 24) | (x << 16) | (y << 8) | uint8_t((x * y) & 0xFF);
441                });
442 
443     auto dContext = context_info.directContext();
444     GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
445 
446     // We test both kRW in addition to kRead mostly to ensure that the calls are structured such
447     // that they'd succeed if the texture wasn't kRead. We want to be sure we're failing with
448     // kRead for the right reason.
449     for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) {
450         auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData(dContext,
451                                                                      srcPixmap,
452                                                                      kTopLeft_GrSurfaceOrigin,
453                                                                      GrRenderable::kNo,
454                                                                      GrProtected::kNo);
455         if (!mbet) {
456             ERRORF(reporter, "Could not make texture.");
457             return;
458         }
459         auto proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership,
460                                                        GrWrapCacheable::kNo, ioType,
461                                                        mbet->refCountedCallback());
462         skgpu::Swizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
463                                                                          GrColorType::kRGBA_8888);
464         GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
465         auto surfContext = dContext->priv().makeSC(std::move(view), ii.colorInfo());
466         // Read pixels should work with a read-only texture.
467         {
468             SkAutoPixmapStorage read;
469             read.alloc(srcPixmap.info());
470             auto readResult = surfContext->readPixels(dContext, read, {0, 0});
471             REPORTER_ASSERT(reporter, readResult);
472             if (readResult) {
473                 comparePixels(srcPixmap, read, reporter);
474             }
475         }
476 
477         // Write pixels should not work with a read-only texture.
478         SkAutoPixmapStorage write;
479         write.alloc(srcPixmap.info());
480         fillPixels(&write, [&srcPixmap](int x, int y) { return ~*srcPixmap.addr32(); });
481         auto writeResult = surfContext->writePixels(dContext, write, {0, 0});
482         REPORTER_ASSERT(reporter, writeResult == (ioType == kRW_GrIOType));
483         // Try the low level write.
484         dContext->flushAndSubmit();
485         auto gpuWriteResult = dContext->priv().getGpu()->writePixels(
486                 proxy->peekTexture(),
487                 SkIRect::MakeWH(kSize, kSize),
488                 GrColorType::kRGBA_8888,
489                 GrColorType::kRGBA_8888,
490                 write.addr32(),
491                 kSize*GrColorTypeBytesPerPixel(GrColorType::kRGBA_8888));
492         REPORTER_ASSERT(reporter, gpuWriteResult == (ioType == kRW_GrIOType));
493 
494         SkBitmap copySrcBitmap;
495         copySrcBitmap.installPixels(write);
496         copySrcBitmap.setImmutable();
497 
498         auto copySrc = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, copySrcBitmap));
499 
500         REPORTER_ASSERT(reporter, copySrc);
501         auto copyResult = surfContext->testCopy(copySrc.refProxy());
502         REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType));
503         // Try the low level copy.
504         dContext->flushAndSubmit();
505         auto gpuCopyResult = dContext->priv().getGpu()->copySurface(
506                 proxy->peekSurface(),
507                 SkIRect::MakeWH(kSize, kSize),
508                 copySrc.proxy()->peekSurface(),
509                 SkIRect::MakeWH(kSize, kSize),
510                 GrSamplerState::Filter::kNearest);
511         REPORTER_ASSERT(reporter, gpuCopyResult == (ioType == kRW_GrIOType));
512 
513         // Mip regen should not work with a read only texture.
514         if (dContext->priv().caps()->mipmapSupport()) {
515             mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext,
516                                                                        kSize,
517                                                                        kSize,
518                                                                        kRGBA_8888_SkColorType,
519                                                                        GrMipmapped::kYes,
520                                                                        GrRenderable::kNo,
521                                                                        GrProtected::kNo);
522             proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership,
523                                                       GrWrapCacheable::kNo, ioType,
524                                                       mbet->refCountedCallback());
525             dContext->flushAndSubmit();
526             proxy->peekTexture()->markMipmapsDirty();  // avoids assert in GrGpu.
527             auto regenResult =
528                     dContext->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture());
529             REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType));
530         }
531     }
532 }
533