OLD | NEW |
(Empty) | |
| 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 |
| 17 static void check_surface(skiatest::Reporter* reporter, |
| 18 GrSurfaceProxy* proxy, |
| 19 GrSurfaceOrigin origin, |
| 20 int width, int height, |
| 21 GrPixelConfig config) { |
| 22 REPORTER_ASSERT(reporter, proxy->origin() == origin); |
| 23 REPORTER_ASSERT(reporter, proxy->width() == width); |
| 24 REPORTER_ASSERT(reporter, proxy->height() == height); |
| 25 REPORTER_ASSERT(reporter, proxy->config() == config); |
| 26 } |
| 27 |
| 28 static void check_rendertarget(skiatest::Reporter* reporter, |
| 29 GrTextureProvider* provider, |
| 30 GrRenderTargetProxy* rtProxy, |
| 31 GrSurfaceProxy::BackingFit fit) { |
| 32 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == nullptr); // for now |
| 33 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy); |
| 34 |
| 35 GrRenderTarget* rt = rtProxy->instantiate(provider); |
| 36 REPORTER_ASSERT(reporter, rt); |
| 37 |
| 38 REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin()); |
| 39 if (GrSurfaceProxy::kExact_BackingFit == fit) { |
| 40 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width()); |
| 41 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height()); |
| 42 } else { |
| 43 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width()); |
| 44 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height()); |
| 45 } |
| 46 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config()); |
| 47 |
| 48 REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedM
ultisampled()); |
| 49 REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() == |
| 50 rtProxy->isStencilBufferMultisampled()); |
| 51 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples(
)); |
| 52 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamp
les()); |
| 53 REPORTER_ASSERT(reporter, rt->hasMixedSamples() == rtProxy->hasMixedSamples(
)); |
| 54 } |
| 55 |
| 56 static void check_texture(skiatest::Reporter* reporter, |
| 57 GrTextureProvider* provider, |
| 58 GrTextureProxy* texProxy, |
| 59 GrSurfaceProxy::BackingFit fit) { |
| 60 REPORTER_ASSERT(reporter, texProxy->asTextureProxy() == texProxy); |
| 61 REPORTER_ASSERT(reporter, texProxy->asRenderTargetProxy() == nullptr); // fo
r now |
| 62 |
| 63 GrTexture* tex = texProxy->instantiate(provider); |
| 64 REPORTER_ASSERT(reporter, tex); |
| 65 |
| 66 REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin()); |
| 67 if (GrSurfaceProxy::kExact_BackingFit == fit) { |
| 68 REPORTER_ASSERT(reporter, tex->width() == texProxy->width()); |
| 69 REPORTER_ASSERT(reporter, tex->height() == texProxy->height()); |
| 70 } else { |
| 71 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width()); |
| 72 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height()); |
| 73 } |
| 74 REPORTER_ASSERT(reporter, tex->config() == texProxy->config()); |
| 75 } |
| 76 |
| 77 |
| 78 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(AllocedProxyTest, reporter, ctxInfo) { |
| 79 GrTextureProvider* provider = ctxInfo.fGrContext->textureProvider(); |
| 80 |
| 81 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }
) { |
| 82 for (auto widthHeight : { 100, 128 }) { |
| 83 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfi
g }) { |
| 84 for (auto fit : { GrSurfaceProxy::kExact_BackingFit, |
| 85 GrSurfaceProxy::kApprox_BackingFit }) { |
| 86 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo })
{ |
| 87 for (auto numSamples : { 0, 4}) { |
| 88 GrSurfaceDesc desc; |
| 89 desc.fOrigin = origin; |
| 90 desc.fWidth = widthHeight; |
| 91 desc.fHeight = widthHeight; |
| 92 desc.fConfig = config; |
| 93 desc.fSampleCnt = numSamples; |
| 94 |
| 95 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetPro
xy::Make( |
| 96 *ctxInfo.fGr
Context->caps(), |
| 97 desc, |
| 98 fit, |
| 99 budgeted)); |
| 100 check_surface(reporter, rtProxy.get(), origin, |
| 101 widthHeight, widthHeight, config); |
| 102 check_rendertarget(reporter, provider, rtProxy.get()
, fit); |
| 103 |
| 104 desc.fSampleCnt = 0; |
| 105 |
| 106 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(
desc, |
| 107
fit, |
| 108
budgeted)); |
| 109 check_surface(reporter, texProxy.get(), origin, |
| 110 widthHeight, widthHeight, config); |
| 111 check_texture(reporter, provider, texProxy.get(), fi
t); |
| 112 } |
| 113 } |
| 114 } |
| 115 } |
| 116 } |
| 117 } |
| 118 } |
| 119 |
| 120 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { |
| 121 GrTextureProvider* provider = ctxInfo.fGrContext->textureProvider(); |
| 122 |
| 123 static const int kWidthHeight = 100; |
| 124 |
| 125 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }
) { |
| 126 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig })
{ |
| 127 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { |
| 128 for (auto numSamples: { 0, 4}) { |
| 129 GrSurfaceDesc desc; |
| 130 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 131 desc.fOrigin = origin; |
| 132 desc.fWidth = kWidthHeight; |
| 133 desc.fHeight = kWidthHeight; |
| 134 desc.fConfig = config; |
| 135 desc.fSampleCnt = numSamples; |
| 136 |
| 137 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted)
); |
| 138 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget())); |
| 139 |
| 140 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make
(rt)); |
| 141 check_surface(reporter, rtProxy.get(), origin, |
| 142 kWidthHeight, kWidthHeight, config); |
| 143 check_rendertarget(reporter, provider, rtProxy.get(), |
| 144 GrSurfaceProxy::kExact_BackingFit); |
| 145 |
| 146 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex)); |
| 147 check_surface(reporter, texProxy.get(), origin, |
| 148 kWidthHeight, kWidthHeight, config); |
| 149 check_texture(reporter, provider, texProxy.get(), |
| 150 GrSurfaceProxy::kExact_BackingFit); |
| 151 } |
| 152 } |
| 153 } |
| 154 } |
| 155 } |
| 156 |
| 157 #endif |
OLD | NEW |