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