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 |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 13 | #include "GrGpu.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 14 | #include "GrSurfaceProxy.h" |
| 15 | #include "GrTextureProxy.h" |
| 16 | #include "GrRenderTargetProxy.h" |
| 17 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 18 | // Check that the surface proxy's member vars are set as expected |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 19 | static void check_surface(skiatest::Reporter* reporter, |
| 20 | GrSurfaceProxy* proxy, |
| 21 | GrSurfaceOrigin origin, |
| 22 | int width, int height, |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 23 | GrPixelConfig config, |
| 24 | uint32_t uniqueID) { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 25 | REPORTER_ASSERT(reporter, proxy->origin() == origin); |
| 26 | REPORTER_ASSERT(reporter, proxy->width() == width); |
| 27 | REPORTER_ASSERT(reporter, proxy->height() == height); |
| 28 | REPORTER_ASSERT(reporter, proxy->config() == config); |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 29 | if (SK_InvalidUniqueID != uniqueID) { |
| 30 | REPORTER_ASSERT(reporter, proxy->uniqueID() == uniqueID); |
| 31 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void check_rendertarget(skiatest::Reporter* reporter, |
| 35 | GrTextureProvider* provider, |
| 36 | GrRenderTargetProxy* rtProxy, |
| 37 | SkBackingFit fit) { |
| 38 | REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == nullptr); // for now |
| 39 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
| 40 | |
| 41 | GrRenderTarget* rt = rtProxy->instantiate(provider); |
| 42 | REPORTER_ASSERT(reporter, rt); |
| 43 | |
| 44 | REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin()); |
| 45 | if (SkBackingFit::kExact == fit) { |
| 46 | REPORTER_ASSERT(reporter, rt->width() == rtProxy->width()); |
| 47 | REPORTER_ASSERT(reporter, rt->height() == rtProxy->height()); |
| 48 | } else { |
| 49 | REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width()); |
| 50 | REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height()); |
| 51 | } |
| 52 | REPORTER_ASSERT(reporter, rt->config() == rtProxy->config()); |
| 53 | |
| 54 | REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled()); |
| 55 | REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() == |
| 56 | rtProxy->isStencilBufferMultisampled()); |
| 57 | REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples()); |
| 58 | REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples()); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 59 | REPORTER_ASSERT(reporter, rt->isMixedSampled() == rtProxy->isMixedSampled()); |
| 60 | REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static void check_texture(skiatest::Reporter* reporter, |
| 64 | GrTextureProvider* provider, |
| 65 | GrTextureProxy* texProxy, |
| 66 | SkBackingFit fit) { |
| 67 | REPORTER_ASSERT(reporter, texProxy->asTextureProxy() == texProxy); |
| 68 | REPORTER_ASSERT(reporter, texProxy->asRenderTargetProxy() == nullptr); // for now |
| 69 | |
| 70 | GrTexture* tex = texProxy->instantiate(provider); |
| 71 | REPORTER_ASSERT(reporter, tex); |
| 72 | |
| 73 | REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin()); |
| 74 | if (SkBackingFit::kExact == fit) { |
| 75 | REPORTER_ASSERT(reporter, tex->width() == texProxy->width()); |
| 76 | REPORTER_ASSERT(reporter, tex->height() == texProxy->height()); |
| 77 | } else { |
| 78 | REPORTER_ASSERT(reporter, tex->width() >= texProxy->width()); |
| 79 | REPORTER_ASSERT(reporter, tex->height() >= texProxy->height()); |
| 80 | } |
| 81 | REPORTER_ASSERT(reporter, tex->config() == texProxy->config()); |
| 82 | } |
| 83 | |
| 84 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 85 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 86 | GrTextureProvider* provider = ctxInfo.grContext()->textureProvider(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 87 | |
| 88 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
| 89 | for (auto widthHeight : { 100, 128 }) { |
| 90 | for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) { |
| 91 | for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) { |
| 92 | for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { |
| 93 | for (auto numSamples : { 0, 4}) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 94 | bool renderable = ctxInfo.grContext()->caps()->isConfigRenderable( |
robertphillips | d0e36a9 | 2016-05-10 10:23:30 -0700 | [diff] [blame] | 95 | config, numSamples > 0) && |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 96 | numSamples <= ctxInfo.grContext()->caps()->maxColorSampleCount(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 97 | |
| 98 | GrSurfaceDesc desc; |
| 99 | desc.fOrigin = origin; |
| 100 | desc.fWidth = widthHeight; |
| 101 | desc.fHeight = widthHeight; |
| 102 | desc.fConfig = config; |
| 103 | desc.fSampleCnt = numSamples; |
| 104 | |
| 105 | if (renderable) { |
| 106 | sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make( |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 107 | *ctxInfo.grContext()->caps(), |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 108 | desc, |
| 109 | fit, |
| 110 | budgeted)); |
| 111 | check_surface(reporter, rtProxy.get(), origin, |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 112 | widthHeight, widthHeight, config, SK_InvalidUniqueID); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 113 | check_rendertarget(reporter, provider, rtProxy.get(), fit); |
| 114 | } |
| 115 | |
| 116 | desc.fSampleCnt = 0; |
| 117 | |
| 118 | sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(desc, |
| 119 | fit, |
| 120 | budgeted)); |
| 121 | check_surface(reporter, texProxy.get(), origin, |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 122 | widthHeight, widthHeight, config, SK_InvalidUniqueID); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 123 | check_texture(reporter, provider, texProxy.get(), fit); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 132 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 133 | GrTextureProvider* provider = ctxInfo.grContext()->textureProvider(); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 134 | const GrCaps& caps = *ctxInfo.grContext()->caps(); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 135 | |
| 136 | static const int kWidthHeight = 100; |
| 137 | |
| 138 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { |
| 139 | for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) { |
| 140 | for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { |
| 141 | for (auto numSamples: { 0, 4}) { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 142 | bool renderable = caps.isConfigRenderable(config, numSamples > 0); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 143 | |
| 144 | GrSurfaceDesc desc; |
| 145 | desc.fOrigin = origin; |
| 146 | desc.fWidth = kWidthHeight; |
| 147 | desc.fHeight = kWidthHeight; |
| 148 | desc.fConfig = config; |
| 149 | desc.fSampleCnt = numSamples; |
| 150 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 151 | // External on-screen render target. |
| 152 | if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) { |
| 153 | GrBackendRenderTargetDesc backendDesc; |
| 154 | backendDesc.fWidth = kWidthHeight; |
| 155 | backendDesc.fHeight = kWidthHeight; |
| 156 | backendDesc.fConfig = config; |
| 157 | backendDesc.fOrigin = origin; |
| 158 | backendDesc.fSampleCnt = numSamples; |
| 159 | backendDesc.fStencilBits = 8; |
| 160 | backendDesc.fRenderTargetHandle = 0; |
| 161 | |
| 162 | GrGpu* gpu = ctxInfo.grContext()->getGpu(); |
| 163 | sk_sp<GrRenderTarget> defaultFBO( |
| 164 | gpu->wrapBackendRenderTarget(backendDesc, kBorrow_GrWrapOwnership)); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 165 | REPORTER_ASSERT(reporter, |
| 166 | !defaultFBO->renderTargetPriv().maxWindowRectangles()); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 167 | |
| 168 | sk_sp<GrRenderTargetProxy> rtProxy( |
| 169 | GrRenderTargetProxy::Make(caps, defaultFBO)); |
| 170 | check_surface(reporter, rtProxy.get(), origin, |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 171 | kWidthHeight, kWidthHeight, config, defaultFBO->uniqueID()); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 172 | check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact); |
| 173 | } |
| 174 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 175 | sk_sp<GrTexture> tex; |
| 176 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 177 | // Internal offscreen render target. |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 178 | if (renderable) { |
| 179 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 180 | tex.reset(provider->createTexture(desc, budgeted)); |
| 181 | sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget())); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 182 | REPORTER_ASSERT(reporter, |
| 183 | caps.maxWindowRectangles() == |
| 184 | rt->renderTargetPriv().maxWindowRectangles()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 185 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 186 | sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(caps, rt)); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 187 | check_surface(reporter, rtProxy.get(), origin, |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 188 | kWidthHeight, kWidthHeight, config, rt->uniqueID()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 189 | check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact); |
| 190 | } |
| 191 | |
| 192 | if (!tex) { |
| 193 | SkASSERT(kNone_GrSurfaceFlags == desc.fFlags ); |
| 194 | desc.fSampleCnt = 0; |
| 195 | tex.reset(provider->createTexture(desc, budgeted)); |
| 196 | } |
| 197 | |
| 198 | sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex)); |
| 199 | check_surface(reporter, texProxy.get(), origin, |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 200 | kWidthHeight, kWidthHeight, config, tex->uniqueID()); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 201 | check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | #endif |