blob: 618941e0be493a6167eb017177e89fe984c440de [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,
Robert Phillipsec2249f2016-11-09 08:54:35 -050037 const GrCaps& caps,
robertphillips76948d42016-05-04 12:47:41 -070038 GrTextureProvider* provider,
39 GrRenderTargetProxy* rtProxy,
Robert Phillipsabacf092016-11-02 10:23:32 -040040 int numSamples,
Robert Phillipsec2249f2016-11-09 08:54:35 -050041 SkBackingFit fit,
42 int expectedMaxWindowRects) {
43 REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
Robert Phillipsabacf092016-11-02 10:23:32 -040044 REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
45
robertphillips76948d42016-05-04 12:47:41 -070046 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) {
robertphillips76948d42016-05-04 12:47:41 -070072 GrTexture* tex = texProxy->instantiate(provider);
73 REPORTER_ASSERT(reporter, tex);
74
75 REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
76 if (SkBackingFit::kExact == fit) {
77 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
78 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
79 } else {
80 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
81 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
82 }
83 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
84}
85
86
robertphillips8abb3702016-08-31 14:04:06 -070087DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070088 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
Robert Phillipsabacf092016-11-02 10:23:32 -040089 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -070090
91 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
92 for (auto widthHeight : { 100, 128 }) {
93 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
94 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
95 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
96 for (auto numSamples : { 0, 4}) {
bsalomon8b7451a2016-05-11 06:33:06 -070097 bool renderable = ctxInfo.grContext()->caps()->isConfigRenderable(
robertphillipsd0e36a92016-05-10 10:23:30 -070098 config, numSamples > 0) &&
bsalomon8b7451a2016-05-11 06:33:06 -070099 numSamples <= ctxInfo.grContext()->caps()->maxColorSampleCount();
robertphillips76948d42016-05-04 12:47:41 -0700100
101 GrSurfaceDesc desc;
Robert Phillips84a81202016-11-04 11:59:10 -0400102 desc.fFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -0700103 desc.fOrigin = origin;
104 desc.fWidth = widthHeight;
105 desc.fHeight = widthHeight;
106 desc.fConfig = config;
107 desc.fSampleCnt = numSamples;
108
109 if (renderable) {
Robert Phillips37430132016-11-09 06:50:43 -0500110 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(
Robert Phillipsabacf092016-11-02 10:23:32 -0400111 caps, desc,
112 fit, budgeted));
Robert Phillips37430132016-11-09 06:50:43 -0500113 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400114 widthHeight, widthHeight, config,
115 SK_InvalidUniqueID, budgeted);
Robert Phillipsec2249f2016-11-09 08:54:35 -0500116 check_rendertarget(reporter, caps, provider,
Robert Phillips37430132016-11-09 06:50:43 -0500117 sProxy->asRenderTargetProxy(),
Robert Phillipsec2249f2016-11-09 08:54:35 -0500118 numSamples, fit, caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700119 }
120
Robert Phillips84a81202016-11-04 11:59:10 -0400121 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700122 desc.fSampleCnt = 0;
123
Robert Phillips37430132016-11-09 06:50:43 -0500124 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps,
125 desc,
126 fit,
127 budgeted));
128 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400129 widthHeight, widthHeight, config,
130 SK_InvalidUniqueID, budgeted);
Robert Phillips37430132016-11-09 06:50:43 -0500131 check_texture(reporter, provider, sProxy->asTextureProxy(), fit);
robertphillips76948d42016-05-04 12:47:41 -0700132 }
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));
csmartdaltonf9635992016-08-10 11:09:07 -0700172
Robert Phillips37430132016-11-09 06:50:43 -0500173 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO));
174 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400175 kWidthHeight, kWidthHeight, config,
176 defaultFBO->uniqueID(), SkBudgeted::kNo);
Robert Phillipsec2249f2016-11-09 08:54:35 -0500177 check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
178 numSamples, SkBackingFit::kExact, 0);
csmartdaltonf9635992016-08-10 11:09:07 -0700179 }
180
robertphillips76948d42016-05-04 12:47:41 -0700181 sk_sp<GrTexture> tex;
182
csmartdaltonf9635992016-08-10 11:09:07 -0700183 // Internal offscreen render target.
robertphillips76948d42016-05-04 12:47:41 -0700184 if (renderable) {
185 desc.fFlags = kRenderTarget_GrSurfaceFlag;
186 tex.reset(provider->createTexture(desc, budgeted));
187 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
188
Robert Phillips37430132016-11-09 06:50:43 -0500189 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(rt));
190 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400191 kWidthHeight, kWidthHeight, config,
192 rt->uniqueID(), budgeted);
Robert Phillipsec2249f2016-11-09 08:54:35 -0500193 check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
194 numSamples, SkBackingFit::kExact,
195 caps.maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700196 }
197
198 if (!tex) {
199 SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
200 desc.fSampleCnt = 0;
201 tex.reset(provider->createTexture(desc, budgeted));
202 }
203
Robert Phillips37430132016-11-09 06:50:43 -0500204 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(tex));
205 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400206 kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted);
Robert Phillips37430132016-11-09 06:50:43 -0500207 check_texture(reporter, provider, sProxy->asTextureProxy(),
208 SkBackingFit::kExact);
robertphillips76948d42016-05-04 12:47:41 -0700209 }
210 }
211 }
212 }
213}
214
215#endif