blob: 270f7873abaaf5b3f4ab8728aba3c11c9edde0bb [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 GrRenderTarget* rt = rtProxy->instantiate(provider);
44 REPORTER_ASSERT(reporter, rt);
45
46 REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
47 if (SkBackingFit::kExact == fit) {
48 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
49 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
50 } else {
51 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
52 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
53 }
54 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
55
56 REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled());
57 REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() ==
58 rtProxy->isStencilBufferMultisampled());
59 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
60 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
csmartdaltonf9635992016-08-10 11:09:07 -070061 REPORTER_ASSERT(reporter, rt->isMixedSampled() == rtProxy->isMixedSampled());
62 REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070063}
64
65static void check_texture(skiatest::Reporter* reporter,
66 GrTextureProvider* provider,
67 GrTextureProxy* texProxy,
68 SkBackingFit fit) {
robertphillips76948d42016-05-04 12:47:41 -070069 GrTexture* tex = texProxy->instantiate(provider);
70 REPORTER_ASSERT(reporter, tex);
71
72 REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
73 if (SkBackingFit::kExact == fit) {
74 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
75 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
76 } else {
77 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
78 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
79 }
80 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
81}
82
83
robertphillips8abb3702016-08-31 14:04:06 -070084DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070085 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
Robert Phillipsabacf092016-11-02 10:23:32 -040086 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -070087
88 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
89 for (auto widthHeight : { 100, 128 }) {
90 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
91 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
92 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
93 for (auto numSamples : { 0, 4}) {
bsalomon8b7451a2016-05-11 06:33:06 -070094 bool renderable = ctxInfo.grContext()->caps()->isConfigRenderable(
robertphillipsd0e36a92016-05-10 10:23:30 -070095 config, numSamples > 0) &&
bsalomon8b7451a2016-05-11 06:33:06 -070096 numSamples <= ctxInfo.grContext()->caps()->maxColorSampleCount();
robertphillips76948d42016-05-04 12:47:41 -070097
98 GrSurfaceDesc desc;
Robert Phillips84a81202016-11-04 11:59:10 -040099 desc.fFlags = kRenderTarget_GrSurfaceFlag;
robertphillips76948d42016-05-04 12:47:41 -0700100 desc.fOrigin = origin;
101 desc.fWidth = widthHeight;
102 desc.fHeight = widthHeight;
103 desc.fConfig = config;
104 desc.fSampleCnt = numSamples;
105
106 if (renderable) {
107 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(
Robert Phillipsabacf092016-11-02 10:23:32 -0400108 caps, desc,
109 fit, budgeted));
robertphillips76948d42016-05-04 12:47:41 -0700110 check_surface(reporter, rtProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400111 widthHeight, widthHeight, config,
112 SK_InvalidUniqueID, budgeted);
113 check_rendertarget(reporter, provider, rtProxy.get(),
114 numSamples, fit);
robertphillips76948d42016-05-04 12:47:41 -0700115 }
116
Robert Phillips84a81202016-11-04 11:59:10 -0400117 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700118 desc.fSampleCnt = 0;
119
Robert Phillips84a81202016-11-04 11:59:10 -0400120 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(caps, provider,
Robert Phillips8bc06d02016-11-01 17:28:40 -0400121 desc,
robertphillips76948d42016-05-04 12:47:41 -0700122 fit,
123 budgeted));
124 check_surface(reporter, texProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400125 widthHeight, widthHeight, config,
126 SK_InvalidUniqueID, budgeted);
robertphillips76948d42016-05-04 12:47:41 -0700127 check_texture(reporter, provider, texProxy.get(), fit);
128 }
129 }
130 }
131 }
132 }
133 }
134}
135
egdanielab527a52016-06-28 08:07:26 -0700136DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700137 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
csmartdaltonf9635992016-08-10 11:09:07 -0700138 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -0700139
140 static const int kWidthHeight = 100;
141
142 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
143 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
144 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
145 for (auto numSamples: { 0, 4}) {
csmartdaltonf9635992016-08-10 11:09:07 -0700146 bool renderable = caps.isConfigRenderable(config, numSamples > 0);
robertphillips76948d42016-05-04 12:47:41 -0700147
148 GrSurfaceDesc desc;
149 desc.fOrigin = origin;
150 desc.fWidth = kWidthHeight;
151 desc.fHeight = kWidthHeight;
152 desc.fConfig = config;
153 desc.fSampleCnt = numSamples;
154
csmartdaltonf9635992016-08-10 11:09:07 -0700155 // External on-screen render target.
156 if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
157 GrBackendRenderTargetDesc backendDesc;
158 backendDesc.fWidth = kWidthHeight;
159 backendDesc.fHeight = kWidthHeight;
160 backendDesc.fConfig = config;
161 backendDesc.fOrigin = origin;
162 backendDesc.fSampleCnt = numSamples;
163 backendDesc.fStencilBits = 8;
164 backendDesc.fRenderTargetHandle = 0;
165
csmartdaltonf9635992016-08-10 11:09:07 -0700166 sk_sp<GrRenderTarget> defaultFBO(
Robert Phillipsabacf092016-11-02 10:23:32 -0400167 provider->wrapBackendRenderTarget(backendDesc));
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700168 REPORTER_ASSERT(reporter,
169 !defaultFBO->renderTargetPriv().maxWindowRectangles());
csmartdaltonf9635992016-08-10 11:09:07 -0700170
Robert Phillipsabacf092016-11-02 10:23:32 -0400171 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(defaultFBO));
csmartdaltonf9635992016-08-10 11:09:07 -0700172 check_surface(reporter, rtProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400173 kWidthHeight, kWidthHeight, config,
174 defaultFBO->uniqueID(), SkBudgeted::kNo);
175 check_rendertarget(reporter, provider, rtProxy.get(),
176 numSamples, SkBackingFit::kExact);
csmartdaltonf9635992016-08-10 11:09:07 -0700177 }
178
robertphillips76948d42016-05-04 12:47:41 -0700179 sk_sp<GrTexture> tex;
180
csmartdaltonf9635992016-08-10 11:09:07 -0700181 // Internal offscreen render target.
robertphillips76948d42016-05-04 12:47:41 -0700182 if (renderable) {
183 desc.fFlags = kRenderTarget_GrSurfaceFlag;
184 tex.reset(provider->createTexture(desc, budgeted));
185 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700186 REPORTER_ASSERT(reporter,
187 caps.maxWindowRectangles() ==
188 rt->renderTargetPriv().maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700189
Robert Phillipsabacf092016-11-02 10:23:32 -0400190 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(rt));
robertphillips76948d42016-05-04 12:47:41 -0700191 check_surface(reporter, rtProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400192 kWidthHeight, kWidthHeight, config,
193 rt->uniqueID(), budgeted);
194 check_rendertarget(reporter, provider, rtProxy.get(),
195 numSamples, SkBackingFit::kExact);
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
204 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex));
205 check_surface(reporter, texProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400206 kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted);
robertphillips76948d42016-05-04 12:47:41 -0700207 check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact);
208 }
209 }
210 }
211 }
212}
213
214#endif