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