blob: 17a3dad3b843ba04daada7e84bac6951f141a8a8 [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) {
Robert Phillips37430132016-11-09 06:50:43 -0500107 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(
Robert Phillipsabacf092016-11-02 10:23:32 -0400108 caps, desc,
109 fit, budgeted));
Robert Phillips37430132016-11-09 06:50:43 -0500110 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400111 widthHeight, widthHeight, config,
112 SK_InvalidUniqueID, budgeted);
Robert Phillips37430132016-11-09 06:50:43 -0500113 check_rendertarget(reporter, provider,
114 sProxy->asRenderTargetProxy(),
Robert Phillipsabacf092016-11-02 10:23:32 -0400115 numSamples, fit);
robertphillips76948d42016-05-04 12:47:41 -0700116 }
117
Robert Phillips84a81202016-11-04 11:59:10 -0400118 desc.fFlags = kNone_GrSurfaceFlags;
robertphillips76948d42016-05-04 12:47:41 -0700119 desc.fSampleCnt = 0;
120
Robert Phillips37430132016-11-09 06:50:43 -0500121 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps,
122 desc,
123 fit,
124 budgeted));
125 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400126 widthHeight, widthHeight, config,
127 SK_InvalidUniqueID, budgeted);
Robert Phillips37430132016-11-09 06:50:43 -0500128 check_texture(reporter, provider, sProxy->asTextureProxy(), fit);
robertphillips76948d42016-05-04 12:47:41 -0700129 }
130 }
131 }
132 }
133 }
134 }
135}
136
egdanielab527a52016-06-28 08:07:26 -0700137DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700138 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
csmartdaltonf9635992016-08-10 11:09:07 -0700139 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -0700140
141 static const int kWidthHeight = 100;
142
143 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
144 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
145 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
146 for (auto numSamples: { 0, 4}) {
csmartdaltonf9635992016-08-10 11:09:07 -0700147 bool renderable = caps.isConfigRenderable(config, numSamples > 0);
robertphillips76948d42016-05-04 12:47:41 -0700148
149 GrSurfaceDesc desc;
150 desc.fOrigin = origin;
151 desc.fWidth = kWidthHeight;
152 desc.fHeight = kWidthHeight;
153 desc.fConfig = config;
154 desc.fSampleCnt = numSamples;
155
csmartdaltonf9635992016-08-10 11:09:07 -0700156 // External on-screen render target.
157 if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
158 GrBackendRenderTargetDesc backendDesc;
159 backendDesc.fWidth = kWidthHeight;
160 backendDesc.fHeight = kWidthHeight;
161 backendDesc.fConfig = config;
162 backendDesc.fOrigin = origin;
163 backendDesc.fSampleCnt = numSamples;
164 backendDesc.fStencilBits = 8;
165 backendDesc.fRenderTargetHandle = 0;
166
csmartdaltonf9635992016-08-10 11:09:07 -0700167 sk_sp<GrRenderTarget> defaultFBO(
Robert Phillipsabacf092016-11-02 10:23:32 -0400168 provider->wrapBackendRenderTarget(backendDesc));
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700169 REPORTER_ASSERT(reporter,
170 !defaultFBO->renderTargetPriv().maxWindowRectangles());
csmartdaltonf9635992016-08-10 11:09:07 -0700171
Robert Phillips37430132016-11-09 06:50:43 -0500172 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO));
173 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400174 kWidthHeight, kWidthHeight, config,
175 defaultFBO->uniqueID(), SkBudgeted::kNo);
Robert Phillips37430132016-11-09 06:50:43 -0500176 check_rendertarget(reporter, provider, sProxy->asRenderTargetProxy(),
Robert Phillipsabacf092016-11-02 10:23:32 -0400177 numSamples, SkBackingFit::kExact);
csmartdaltonf9635992016-08-10 11:09:07 -0700178 }
179
robertphillips76948d42016-05-04 12:47:41 -0700180 sk_sp<GrTexture> tex;
181
csmartdaltonf9635992016-08-10 11:09:07 -0700182 // Internal offscreen render target.
robertphillips76948d42016-05-04 12:47:41 -0700183 if (renderable) {
184 desc.fFlags = kRenderTarget_GrSurfaceFlag;
185 tex.reset(provider->createTexture(desc, budgeted));
186 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700187 REPORTER_ASSERT(reporter,
188 caps.maxWindowRectangles() ==
189 rt->renderTargetPriv().maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700190
Robert Phillips37430132016-11-09 06:50:43 -0500191 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(rt));
192 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400193 kWidthHeight, kWidthHeight, config,
194 rt->uniqueID(), budgeted);
Robert Phillips37430132016-11-09 06:50:43 -0500195 check_rendertarget(reporter, provider, sProxy->asRenderTargetProxy(),
Robert Phillipsabacf092016-11-02 10:23:32 -0400196 numSamples, SkBackingFit::kExact);
robertphillips76948d42016-05-04 12:47:41 -0700197 }
198
199 if (!tex) {
200 SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
201 desc.fSampleCnt = 0;
202 tex.reset(provider->createTexture(desc, budgeted));
203 }
204
Robert Phillips37430132016-11-09 06:50:43 -0500205 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(tex));
206 check_surface(reporter, sProxy.get(), origin,
Robert Phillipsabacf092016-11-02 10:23:32 -0400207 kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted);
Robert Phillips37430132016-11-09 06:50:43 -0500208 check_texture(reporter, provider, sProxy->asTextureProxy(),
209 SkBackingFit::kExact);
robertphillips76948d42016-05-04 12:47:41 -0700210 }
211 }
212 }
213 }
214}
215
216#endif