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 | 009e9af | 2017-06-15 14:01:04 -0400 | [diff] [blame] | 14 | #include "GrRenderTarget.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 15 | #include "GrRenderTargetProxy.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 16 | #include "GrResourceProvider.h" |
| 17 | #include "GrSurfaceProxy.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 18 | #include "GrTexture.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 19 | #include "GrTextureProxy.h" |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 20 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 21 | static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrResourceProvider* provider, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 22 | skiatest::Reporter* reporter, |
| 23 | const GrSurfaceDesc& desc) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 24 | GrGLFramebufferInfo fboInfo; |
| 25 | fboInfo.fFBOID = 0; |
| 26 | GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8, |
| 27 | desc.fConfig, fboInfo); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 28 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 29 | sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT, desc.fOrigin)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 30 | SkASSERT(!defaultFBO->asTexture()); |
| 31 | |
Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 32 | return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO), desc.fOrigin); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 33 | } |
| 34 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 35 | static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrResourceProvider* provider, |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 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 | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 43 | return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 44 | } |
| 45 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 46 | static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrResourceProvider* 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 | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 51 | return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin); |
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) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 57 | GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider(); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 58 | |
| 59 | GrSurfaceDesc desc; |
| 60 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 61 | desc.fWidth = 64; |
| 62 | desc.fHeight = 64; |
| 63 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 64 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 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 |