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 SkBackingFit 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 (SkBackingFit::kExact == 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 SkBackingFit 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 (SkBackingFit::kExact == 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 : { SkBackingFit::kExact, SkBackingFit::kApprox })
{ | |
85 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo })
{ | |
86 for (auto numSamples : { 0, 4}) { | |
87 GrSurfaceDesc desc; | |
88 desc.fOrigin = origin; | |
89 desc.fWidth = widthHeight; | |
90 desc.fHeight = widthHeight; | |
91 desc.fConfig = config; | |
92 desc.fSampleCnt = numSamples; | |
93 | |
94 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetPro
xy::Make( | |
95 *ctxInfo.fGr
Context->caps(), | |
96 desc, | |
97 fit, | |
98 budgeted)); | |
99 check_surface(reporter, rtProxy.get(), origin, | |
100 widthHeight, widthHeight, config); | |
101 check_rendertarget(reporter, provider, rtProxy.get()
, fit); | |
102 | |
103 desc.fSampleCnt = 0; | |
104 | |
105 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(
desc, | |
106
fit, | |
107
budgeted)); | |
108 check_surface(reporter, texProxy.get(), origin, | |
109 widthHeight, widthHeight, config); | |
110 check_texture(reporter, provider, texProxy.get(), fi
t); | |
111 } | |
112 } | |
113 } | |
114 } | |
115 } | |
116 } | |
117 } | |
118 | |
119 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { | |
120 GrTextureProvider* provider = ctxInfo.fGrContext->textureProvider(); | |
121 | |
122 static const int kWidthHeight = 100; | |
123 | |
124 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }
) { | |
125 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig })
{ | |
126 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) { | |
127 for (auto numSamples: { 0, 4}) { | |
128 GrSurfaceDesc desc; | |
129 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
130 desc.fOrigin = origin; | |
131 desc.fWidth = kWidthHeight; | |
132 desc.fHeight = kWidthHeight; | |
133 desc.fConfig = config; | |
134 desc.fSampleCnt = numSamples; | |
135 | |
136 sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted)
); | |
137 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget())); | |
138 | |
139 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make
(rt)); | |
140 check_surface(reporter, rtProxy.get(), origin, | |
141 kWidthHeight, kWidthHeight, config); | |
142 check_rendertarget(reporter, provider, rtProxy.get(), SkBack
ingFit::kExact); | |
143 | |
144 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex)); | |
145 check_surface(reporter, texProxy.get(), origin, | |
146 kWidthHeight, kWidthHeight, config); | |
147 check_texture(reporter, provider, texProxy.get(), SkBackingF
it::kExact); | |
148 } | |
149 } | |
150 } | |
151 } | |
152 } | |
153 | |
154 #endif | |
OLD | NEW |