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 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 29 | sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendRT)); |
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; |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 125 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 126 | desc.fWidth = 64; |
| 127 | desc.fHeight = 64; |
| 128 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 129 | |
| 130 | { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 131 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 132 | SkBackingFit::kApprox, |
| 133 | SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 134 | |
| 135 | // Both RenderTarget and Texture |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 136 | GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 137 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 138 | GrTextureProxy* tProxy = rtProxy->asTextureProxy(); |
| 139 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 140 | REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy); |
| 141 | REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 142 | } |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 143 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 144 | { |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 145 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 146 | SkBackingFit::kApprox, |
| 147 | SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 148 | |
| 149 | // Both RenderTarget and Texture - but via GrTextureProxy |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 150 | GrTextureProxy* tProxy = proxy->asTextureProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 151 | REPORTER_ASSERT(reporter, tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 152 | GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy(); |
| 153 | REPORTER_ASSERT(reporter, rtProxy); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 154 | REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy); |
| 155 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | { |
| 159 | desc.fFlags = kNone_GrSurfaceFlags; // force no-RT |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 160 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 161 | |
Robert Phillips | 26c90e0 | 2017-03-14 14:39:29 -0400 | [diff] [blame] | 162 | sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(resourceProvider, desc, |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 163 | SkBackingFit::kApprox, |
| 164 | SkBudgeted::kYes)); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 165 | |
| 166 | // Texture-only |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 167 | GrTextureProxy* tProxy = proxy->asTextureProxy(); |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, tProxy); |
| 169 | REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy); |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 170 | REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy()); |
| 171 | } |
| 172 | } |
| 173 | #endif |