Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [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 | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetProxy.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 14 | #include "GrResourceProvider.h" |
| 15 | #include "GrSurfaceProxy.h" |
| 16 | #include "GrTextureProxy.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 17 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 18 | static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 19 | skiatest::Reporter* reporter, |
| 20 | const GrSurfaceDesc& desc) { |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 21 | GrBackendRenderTargetDesc backendDesc; |
| 22 | backendDesc.fWidth = desc.fWidth; |
| 23 | backendDesc.fHeight = desc.fHeight; |
| 24 | backendDesc.fConfig = desc.fConfig; |
| 25 | backendDesc.fOrigin = desc.fOrigin; |
| 26 | backendDesc.fSampleCnt = desc.fSampleCnt; |
| 27 | backendDesc.fStencilBits = 8; |
| 28 | backendDesc.fRenderTargetHandle = 0; |
| 29 | |
| 30 | sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendDesc)); |
| 31 | SkASSERT(!defaultFBO->asTexture()); |
| 32 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 33 | return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 34 | } |
| 35 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 36 | static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrResourceProvider* provider, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 37 | skiatest::Reporter* reporter, |
| 38 | const GrSurfaceDesc& desc, |
| 39 | SkBudgeted budgeted) { |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 40 | SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags); |
| 41 | |
| 42 | sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 43 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 44 | return GrSurfaceProxy::MakeWrapped(std::move(tex)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 47 | static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrResourceProvider* provider, |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 48 | const GrSurfaceDesc& desc, |
| 49 | SkBudgeted budgeted) { |
| 50 | sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted)); |
| 51 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 52 | return GrSurfaceProxy::MakeWrapped(std::move(tex)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // Test converting between RenderTargetProxies and TextureProxies for wrapped |
| 56 | // Proxies |
| 57 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 58 | GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider(); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 59 | |
| 60 | GrSurfaceDesc desc; |
| 61 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 62 | desc.fWidth = 64; |
| 63 | desc.fHeight = 64; |
| 64 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 65 | |
| 66 | if (kOpenGL_GrBackend == ctxInfo.backend()) { |
| 67 | // External on-screen render target. |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 68 | sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(provider, reporter, desc)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 69 | |
| 70 | // RenderTarget-only |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 71 | GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy(); |
| 72 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 73 | REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy()); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 74 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | { |
| 78 | // Internal offscreen render target. |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 79 | sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(provider, |
| 80 | reporter, desc, |
| 81 | SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 82 | |
| 83 | // Both RenderTarget and Texture |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 84 | GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy(); |
| 85 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 86 | GrTextureProxy* tProxy = rtProxy->asTextureProxy(); |
| 87 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 88 | REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy); |
| 89 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | { |
| 93 | // Internal offscreen render target - but through GrTextureProxy |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 94 | sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 95 | |
| 96 | // Both RenderTarget and Texture |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 97 | GrTextureProxy* tProxy = sProxy->asTextureProxy(); |
| 98 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 99 | GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy(); |
| 100 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 101 | REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy); |
| 102 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | { |
| 106 | desc.fFlags = kNone_GrSurfaceFlags; // force no-RT |
| 107 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 108 | sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 109 | |
| 110 | // Texture-only |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 111 | GrTextureProxy* tProxy = sProxy->asTextureProxy(); |
| 112 | REPORTER_ASSERT(reporter, tProxy); |
| 113 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 114 | REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy()); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // Test converting between RenderTargetProxies and TextureProxies for deferred |
| 119 | // Proxies |
| 120 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 121 | GrResourceProvider* resourceProvider = ctxInfo.grContext()->resourceProvider(); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 122 | |
| 123 | GrSurfaceDesc desc; |
| 124 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 125 | desc.fWidth = 64; |
| 126 | desc.fHeight = 64; |
| 127 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 128 | |
| 129 | { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 130 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 131 | SkBackingFit::kApprox, |
| 132 | SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 133 | |
| 134 | // Both RenderTarget and Texture |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 135 | GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 136 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 137 | GrTextureProxy* tProxy = rtProxy->asTextureProxy(); |
| 138 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 139 | REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy); |
| 140 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 141 | } |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 142 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 143 | { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 144 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 145 | SkBackingFit::kApprox, |
| 146 | SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 147 | |
| 148 | // Both RenderTarget and Texture - but via GrTextureProxy |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 149 | GrTextureProxy* tProxy = proxy->asTextureProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 150 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 151 | GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy(); |
| 152 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 153 | REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy); |
| 154 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | { |
| 158 | desc.fFlags = kNone_GrSurfaceFlags; // force no-RT |
| 159 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 160 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 161 | SkBackingFit::kApprox, |
| 162 | SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 163 | |
| 164 | // Texture-only |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 165 | GrTextureProxy* tProxy = proxy->asTextureProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 166 | REPORTER_ASSERT(reporter, tProxy); |
| 167 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy()); |
| 169 | } |
| 170 | } |
| 171 | #endif |