robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | // This is a GPU-backend specific test. |
| 9 | |
| 10 | #include "Test.h" |
| 11 | |
| 12 | #if SK_SUPPORT_GPU |
Robert Phillips | 8bf1f9f | 2017-05-31 15:01:20 -0400 | [diff] [blame] | 13 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 14 | #include "GrBackendSurface.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetPriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 16 | #include "GrRenderTargetProxy.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 17 | #include "GrResourceProvider.h" |
Robert Phillips | f95b175 | 2017-08-31 08:56:07 -0400 | [diff] [blame] | 18 | #include "GrSurfaceProxyPriv.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 19 | #include "GrTexture.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 20 | #include "GrTextureProxy.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 21 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 22 | // Check that the surface proxy's member vars are set as expected |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 23 | static void check_surface(skiatest::Reporter* reporter, |
| 24 | GrSurfaceProxy* proxy, |
| 25 | GrSurfaceOrigin origin, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 26 | int width, int height, |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 27 | GrPixelConfig config, |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 28 | const GrGpuResource::UniqueID& uniqueID, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 29 | SkBudgeted budgeted) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 30 | REPORTER_ASSERT(reporter, proxy->origin() == origin); |
| 31 | REPORTER_ASSERT(reporter, proxy->width() == width); |
| 32 | REPORTER_ASSERT(reporter, proxy->height() == height); |
| 33 | REPORTER_ASSERT(reporter, proxy->config() == config); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 34 | if (!uniqueID.isInvalid()) { |
| 35 | REPORTER_ASSERT(reporter, proxy->uniqueID().asUInt() == uniqueID.asUInt()); |
| 36 | } else { |
| 37 | REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid()); |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 38 | } |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 39 | REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void check_rendertarget(skiatest::Reporter* reporter, |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 43 | const GrCaps& caps, |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 44 | GrResourceProvider* provider, |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 45 | GrRenderTargetProxy* rtProxy, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 46 | int numSamples, |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 47 | SkBackingFit fit, |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 48 | int expectedMaxWindowRects, |
| 49 | bool wasWrapped) { |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples); |
| 52 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 53 | GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 54 | REPORTER_ASSERT(reporter, rtProxy->instantiate(provider)); |
| 55 | GrRenderTarget* rt = rtProxy->priv().peekRenderTarget(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 56 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 57 | REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore); |
| 58 | if (wasWrapped) { |
| 59 | // Wrapped resources share their uniqueID with the wrapping RenderTargetProxy |
| 60 | REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt()); |
| 61 | } else { |
| 62 | // Deferred resources should always have a different ID from their instantiated rendertarget |
| 63 | REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt()); |
| 64 | } |
| 65 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 66 | if (SkBackingFit::kExact == fit) { |
| 67 | REPORTER_ASSERT(reporter, rt->width() == rtProxy->width()); |
| 68 | REPORTER_ASSERT(reporter, rt->height() == rtProxy->height()); |
| 69 | } else { |
| 70 | REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width()); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 72 | } |
| 73 | REPORTER_ASSERT(reporter, rt->config() == rtProxy->config()); |
| 74 | |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 75 | REPORTER_ASSERT(reporter, rt->fsaaType() == rtProxy->fsaaType()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples()); |
| 77 | REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples()); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 78 | REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static void check_texture(skiatest::Reporter* reporter, |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 82 | GrResourceProvider* provider, |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 83 | GrTextureProxy* texProxy, |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 84 | SkBackingFit fit, |
| 85 | bool wasWrapped) { |
| 86 | GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID(); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 87 | |
| 88 | REPORTER_ASSERT(reporter, texProxy->instantiate(provider)); |
| 89 | GrTexture* tex = texProxy->priv().peekTexture(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 90 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 91 | REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore); |
| 92 | if (wasWrapped) { |
| 93 | // Wrapped resources share their uniqueID with the wrapping TextureProxy |
| 94 | REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt()); |
| 95 | } else { |
| 96 | // Deferred resources should always have a different ID from their instantiated texture |
| 97 | REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt()); |
| 98 | } |
| 99 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 100 | if (SkBackingFit::kExact == fit) { |
| 101 | REPORTER_ASSERT(reporter, tex->width() == texProxy->width()); |
| 102 | REPORTER_ASSERT(reporter, tex->height() == texProxy->height()); |
| 103 | } else { |
| 104 | REPORTER_ASSERT(reporter, tex->width() >= texProxy->width()); |
| 105 | REPORTER_ASSERT(reporter, tex->height() >= texProxy->height()); |
| 106 | } |
| 107 | REPORTER_ASSERT(reporter, tex->config() == texProxy->config()); |
| 108 | } |
| 109 | |
| 110 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 111 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 112 | GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider(); |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 113 | const GrCaps& caps = *ctxInfo.grContext()->caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 114 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 115 | const GrGpuResource::UniqueID kInvalidResourceID = GrGpuResource::UniqueID::InvalidID(); |
| 116 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 117 | int attempt = 0; // useful for debugging |
| 118 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 119 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 120 | for (auto widthHeight : { 100, 128, 1048576 }) { |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 121 | for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig, |
Robert Phillips | 92de631 | 2017-05-23 07:43:48 -0400 | [diff] [blame] | 122 | kRGBA_8888_GrPixelConfig }) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 123 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 124 | for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 125 | for (auto numSamples : { 0, 4, 16, 128 }) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 126 | GrSurfaceDesc desc; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 127 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 128 | desc.fOrigin = origin; |
| 129 | desc.fWidth = widthHeight; |
| 130 | desc.fHeight = widthHeight; |
| 131 | desc.fConfig = config; |
| 132 | desc.fSampleCnt = numSamples; |
| 133 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 134 | { |
| 135 | sk_sp<GrTexture> tex; |
| 136 | if (SkBackingFit::kApprox == fit) { |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 137 | tex = provider->createApproxTexture(desc, 0); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 138 | } else { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 139 | tex = provider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 142 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred( |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 143 | provider, desc, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 144 | fit, budgeted)); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 145 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 146 | if (proxy) { |
| 147 | REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy()); |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 148 | // This forces the proxy to compute and cache its |
| 149 | // pre-instantiation size guess. Later, when it is actually |
| 150 | // instantiated, it checks that the instantiated size is <= to |
| 151 | // the pre-computation. If the proxy never computed its |
| 152 | // pre-instantiation size then the check is skipped. |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 153 | proxy->gpuMemorySize(); |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 154 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 155 | check_surface(reporter, proxy.get(), origin, |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 156 | widthHeight, widthHeight, config, |
| 157 | kInvalidResourceID, budgeted); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 158 | int supportedSamples = caps.getSampleCount(numSamples, config); |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 159 | check_rendertarget(reporter, caps, provider, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 160 | proxy->asRenderTargetProxy(), |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 161 | supportedSamples, |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 162 | fit, caps.maxWindowRectangles(), false); |
| 163 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 166 | desc.fFlags = kNone_GrSurfaceFlags; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 167 | |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 168 | { |
| 169 | sk_sp<GrTexture> tex; |
| 170 | if (SkBackingFit::kApprox == fit) { |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 171 | tex = provider->createApproxTexture(desc, 0); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 172 | } else { |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 173 | tex = provider->createTexture(desc, budgeted); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 174 | } |
Robert Phillips | b446088 | 2016-11-17 14:43:51 -0500 | [diff] [blame] | 175 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 176 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(provider, |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 177 | desc, |
| 178 | fit, |
| 179 | budgeted)); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 180 | REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy)); |
| 181 | if (proxy) { |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 182 | // This forces the proxy to compute and cache its pre-instantiation |
| 183 | // size guess. Later, when it is actually instantiated, it checks |
| 184 | // that the instantiated size is <= to the pre-computation. |
| 185 | // If the proxy never computed its pre-instantiation size then the |
| 186 | // check is skipped. |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 187 | proxy->gpuMemorySize(); |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 188 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 189 | check_surface(reporter, proxy.get(), origin, |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 190 | widthHeight, widthHeight, config, |
| 191 | kInvalidResourceID, budgeted); |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 192 | check_texture(reporter, provider, proxy->asTextureProxy(), |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 193 | fit, false); |
| 194 | } |
Robert Phillips | 40d9495 | 2017-01-30 14:15:59 -0500 | [diff] [blame] | 195 | } |
Robert Phillips | 6520a69 | 2017-02-01 09:20:00 -0500 | [diff] [blame] | 196 | |
| 197 | attempt++; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 206 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 207 | GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider(); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 208 | const GrCaps& caps = *ctxInfo.grContext()->caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 209 | |
| 210 | static const int kWidthHeight = 100; |
| 211 | |
| 212 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
| 213 | for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) { |
| 214 | for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { |
| 215 | for (auto numSamples: { 0, 4}) { |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 216 | int supportedNumSamples = caps.getSampleCount(numSamples, config); |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 217 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 218 | bool renderable = caps.isConfigRenderable(config, numSamples > 0); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 219 | |
| 220 | GrSurfaceDesc desc; |
| 221 | desc.fOrigin = origin; |
| 222 | desc.fWidth = kWidthHeight; |
| 223 | desc.fHeight = kWidthHeight; |
| 224 | desc.fConfig = config; |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 225 | desc.fSampleCnt = supportedNumSamples; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 226 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 227 | // External on-screen render target. |
| 228 | if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 229 | GrGLFramebufferInfo fboInfo; |
| 230 | fboInfo.fFBOID = 0; |
| 231 | GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples, 8, |
| 232 | config, fboInfo); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 233 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 234 | sk_sp<GrRenderTarget> defaultFBO( |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 235 | provider->wrapBackendRenderTarget(backendRT)); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 236 | |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 237 | sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO, |
| 238 | origin)); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 239 | check_surface(reporter, sProxy.get(), origin, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 240 | kWidthHeight, kWidthHeight, config, |
| 241 | defaultFBO->uniqueID(), SkBudgeted::kNo); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 242 | check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(), |
Greg Daniel | d62f554 | 2017-07-20 09:11:41 -0400 | [diff] [blame] | 243 | supportedNumSamples, SkBackingFit::kExact, 0, true); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 244 | } |
| 245 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 246 | sk_sp<GrTexture> tex; |
| 247 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 248 | // Internal offscreen render target. |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 249 | if (renderable) { |
| 250 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 251 | tex = provider->createTexture(desc, budgeted); |
Robert Phillips | d9971c0 | 2017-08-02 11:51:43 -0400 | [diff] [blame] | 252 | if (!tex) { |
| 253 | continue; // This can fail on Mesa |
| 254 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 255 | sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget())); |
| 256 | |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 257 | sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(rt, origin)); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 258 | check_surface(reporter, sProxy.get(), origin, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 259 | kWidthHeight, kWidthHeight, config, |
| 260 | rt->uniqueID(), budgeted); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 261 | check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(), |
Greg Daniel | d62f554 | 2017-07-20 09:11:41 -0400 | [diff] [blame] | 262 | supportedNumSamples, SkBackingFit::kExact, |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 263 | caps.maxWindowRectangles(), true); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | if (!tex) { |
| 267 | SkASSERT(kNone_GrSurfaceFlags == desc.fFlags ); |
| 268 | desc.fSampleCnt = 0; |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 269 | tex = provider->createTexture(desc, budgeted); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 272 | sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(tex, origin)); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 273 | check_surface(reporter, sProxy.get(), origin, |
Robert Phillips | abacf09 | 2016-11-02 10:23:32 -0400 | [diff] [blame] | 274 | kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 275 | check_texture(reporter, provider, sProxy->asTextureProxy(), |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 276 | SkBackingFit::kExact, true); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
Robert Phillips | 78de212 | 2017-04-26 07:44:26 -0400 | [diff] [blame] | 283 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) { |
| 284 | GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider(); |
| 285 | |
| 286 | for (auto flags : { kRenderTarget_GrSurfaceFlag, kNone_GrSurfaceFlags }) { |
| 287 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 288 | for (int width : { 0, 100 }) { |
| 289 | for (int height : { 0, 100}) { |
| 290 | if (width && height) { |
| 291 | continue; // not zero-sized |
| 292 | } |
| 293 | |
| 294 | GrSurfaceDesc desc; |
| 295 | desc.fFlags = flags; |
| 296 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 297 | desc.fWidth = width; |
| 298 | desc.fHeight = height; |
| 299 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 300 | desc.fSampleCnt = 0; |
| 301 | |
| 302 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(provider, |
| 303 | desc, |
| 304 | fit, |
| 305 | SkBudgeted::kNo)); |
| 306 | REPORTER_ASSERT(reporter, !proxy); |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 313 | #endif |