blob: 6b7ab25a3f0fb2b49dae79f45ef0326564566ad5 [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040015#include "GrRenderTargetPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070016#include "GrRenderTargetProxy.h"
17
robertphillips8abb3702016-08-31 14:04:06 -070018// Check that the surface proxy's member vars are set as expected
robertphillips76948d42016-05-04 12:47:41 -070019static void check_surface(skiatest::Reporter* reporter,
20 GrSurfaceProxy* proxy,
21 GrSurfaceOrigin origin,
22 int width, int height,
robertphillips8abb3702016-08-31 14:04:06 -070023 GrPixelConfig config,
Robert Phillipsabacf092016-11-02 10:23:32 -040024 uint32_t uniqueID,
25 SkBudgeted budgeted) {
robertphillips76948d42016-05-04 12:47:41 -070026 REPORTER_ASSERT(reporter, proxy->origin() == origin);
27 REPORTER_ASSERT(reporter, proxy->width() == width);
28 REPORTER_ASSERT(reporter, proxy->height() == height);
29 REPORTER_ASSERT(reporter, proxy->config() == config);
robertphillips8abb3702016-08-31 14:04:06 -070030 if (SK_InvalidUniqueID != uniqueID) {
31 REPORTER_ASSERT(reporter, proxy->uniqueID() == uniqueID);
32 }
Robert Phillipsabacf092016-11-02 10:23:32 -040033 REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
robertphillips76948d42016-05-04 12:47:41 -070034}
35
36static void check_rendertarget(skiatest::Reporter* reporter,
37 GrTextureProvider* provider,
38 GrRenderTargetProxy* rtProxy,
Robert Phillipsabacf092016-11-02 10:23:32 -040039 int numSamples,
robertphillips76948d42016-05-04 12:47:41 -070040 SkBackingFit fit) {
Robert Phillipsabacf092016-11-02 10:23:32 -040041 REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
42
robertphillips76948d42016-05-04 12:47:41 -070043 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == nullptr); // for now
44 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
45
46 GrRenderTarget* rt = rtProxy->instantiate(provider);
47 REPORTER_ASSERT(reporter, rt);
48
49 REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
50 if (SkBackingFit::kExact == fit) {
51 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
52 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
53 } else {
54 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
55 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
56 }
57 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
58
59 REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled());
60 REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() ==
61 rtProxy->isStencilBufferMultisampled());
62 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
63 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
csmartdaltonf9635992016-08-10 11:09:07 -070064 REPORTER_ASSERT(reporter, rt->isMixedSampled() == rtProxy->isMixedSampled());
65 REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070066}
67
68static void check_texture(skiatest::Reporter* reporter,
69 GrTextureProvider* provider,
70 GrTextureProxy* texProxy,
71 SkBackingFit fit) {
72 REPORTER_ASSERT(reporter, texProxy->asTextureProxy() == texProxy);
73 REPORTER_ASSERT(reporter, texProxy->asRenderTargetProxy() == nullptr); // for now
74
75 GrTexture* tex = texProxy->instantiate(provider);
76 REPORTER_ASSERT(reporter, tex);
77
78 REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
79 if (SkBackingFit::kExact == fit) {
80 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
81 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
82 } else {
83 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
84 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
85 }
86 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
87}
88
89
robertphillips8abb3702016-08-31 14:04:06 -070090DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070091 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
Robert Phillipsabacf092016-11-02 10:23:32 -040092 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -070093
94 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
95 for (auto widthHeight : { 100, 128 }) {
96 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
97 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
98 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
99 for (auto numSamples : { 0, 4}) {
bsalomon8b7451a2016-05-11 06:33:06 -0700100 bool renderable = ctxInfo.grContext()->caps()->isConfigRenderable(
robertphillipsd0e36a92016-05-10 10:23:30 -0700101 config, numSamples > 0) &&
bsalomon8b7451a2016-05-11 06:33:06 -0700102 numSamples <= ctxInfo.grContext()->caps()->maxColorSampleCount();
robertphillips76948d42016-05-04 12:47:41 -0700103
104 GrSurfaceDesc desc;
105 desc.fOrigin = origin;
106 desc.fWidth = widthHeight;
107 desc.fHeight = widthHeight;
108 desc.fConfig = config;
109 desc.fSampleCnt = numSamples;
110
111 if (renderable) {
112 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(
Robert Phillipsabacf092016-11-02 10:23:32 -0400113 caps, desc,
114 fit, budgeted));
robertphillips76948d42016-05-04 12:47:41 -0700115 check_surface(reporter, rtProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400116 widthHeight, widthHeight, config,
117 SK_InvalidUniqueID, budgeted);
118 check_rendertarget(reporter, provider, rtProxy.get(),
119 numSamples, fit);
robertphillips76948d42016-05-04 12:47:41 -0700120 }
121
122 desc.fSampleCnt = 0;
123
Robert Phillips8bc06d02016-11-01 17:28:40 -0400124 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(provider,
125 desc,
robertphillips76948d42016-05-04 12:47:41 -0700126 fit,
127 budgeted));
128 check_surface(reporter, texProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400129 widthHeight, widthHeight, config,
130 SK_InvalidUniqueID, budgeted);
robertphillips76948d42016-05-04 12:47:41 -0700131 check_texture(reporter, provider, texProxy.get(), fit);
132 }
133 }
134 }
135 }
136 }
137 }
138}
139
egdanielab527a52016-06-28 08:07:26 -0700140DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700141 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
csmartdaltonf9635992016-08-10 11:09:07 -0700142 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -0700143
144 static const int kWidthHeight = 100;
145
146 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
147 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
148 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
149 for (auto numSamples: { 0, 4}) {
csmartdaltonf9635992016-08-10 11:09:07 -0700150 bool renderable = caps.isConfigRenderable(config, numSamples > 0);
robertphillips76948d42016-05-04 12:47:41 -0700151
152 GrSurfaceDesc desc;
153 desc.fOrigin = origin;
154 desc.fWidth = kWidthHeight;
155 desc.fHeight = kWidthHeight;
156 desc.fConfig = config;
157 desc.fSampleCnt = numSamples;
158
csmartdaltonf9635992016-08-10 11:09:07 -0700159 // External on-screen render target.
160 if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
161 GrBackendRenderTargetDesc backendDesc;
162 backendDesc.fWidth = kWidthHeight;
163 backendDesc.fHeight = kWidthHeight;
164 backendDesc.fConfig = config;
165 backendDesc.fOrigin = origin;
166 backendDesc.fSampleCnt = numSamples;
167 backendDesc.fStencilBits = 8;
168 backendDesc.fRenderTargetHandle = 0;
169
csmartdaltonf9635992016-08-10 11:09:07 -0700170 sk_sp<GrRenderTarget> defaultFBO(
Robert Phillipsabacf092016-11-02 10:23:32 -0400171 provider->wrapBackendRenderTarget(backendDesc));
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700172 REPORTER_ASSERT(reporter,
173 !defaultFBO->renderTargetPriv().maxWindowRectangles());
csmartdaltonf9635992016-08-10 11:09:07 -0700174
Robert Phillipsabacf092016-11-02 10:23:32 -0400175 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(defaultFBO));
csmartdaltonf9635992016-08-10 11:09:07 -0700176 check_surface(reporter, rtProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400177 kWidthHeight, kWidthHeight, config,
178 defaultFBO->uniqueID(), SkBudgeted::kNo);
179 check_rendertarget(reporter, provider, rtProxy.get(),
180 numSamples, SkBackingFit::kExact);
csmartdaltonf9635992016-08-10 11:09:07 -0700181 }
182
robertphillips76948d42016-05-04 12:47:41 -0700183 sk_sp<GrTexture> tex;
184
csmartdaltonf9635992016-08-10 11:09:07 -0700185 // Internal offscreen render target.
robertphillips76948d42016-05-04 12:47:41 -0700186 if (renderable) {
187 desc.fFlags = kRenderTarget_GrSurfaceFlag;
188 tex.reset(provider->createTexture(desc, budgeted));
189 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700190 REPORTER_ASSERT(reporter,
191 caps.maxWindowRectangles() ==
192 rt->renderTargetPriv().maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700193
Robert Phillipsabacf092016-11-02 10:23:32 -0400194 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(rt));
robertphillips76948d42016-05-04 12:47:41 -0700195 check_surface(reporter, rtProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400196 kWidthHeight, kWidthHeight, config,
197 rt->uniqueID(), budgeted);
198 check_rendertarget(reporter, provider, rtProxy.get(),
199 numSamples, SkBackingFit::kExact);
robertphillips76948d42016-05-04 12:47:41 -0700200 }
201
202 if (!tex) {
203 SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
204 desc.fSampleCnt = 0;
205 tex.reset(provider->createTexture(desc, budgeted));
206 }
207
208 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex));
209 check_surface(reporter, texProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400210 kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted);
robertphillips76948d42016-05-04 12:47:41 -0700211 check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact);
212 }
213 }
214 }
215 }
216}
217
218#endif