blob: 016ce5e763a82d85bcfc684e702c01a31cf70b74 [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
csmartdaltonf9635992016-08-10 11:09:07 -070013#include "GrGpu.h"
robertphillips76948d42016-05-04 12:47:41 -070014#include "GrSurfaceProxy.h"
15#include "GrTextureProxy.h"
16#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,
24 uint32_t uniqueID) {
robertphillips76948d42016-05-04 12:47:41 -070025 REPORTER_ASSERT(reporter, proxy->origin() == origin);
26 REPORTER_ASSERT(reporter, proxy->width() == width);
27 REPORTER_ASSERT(reporter, proxy->height() == height);
28 REPORTER_ASSERT(reporter, proxy->config() == config);
robertphillips8abb3702016-08-31 14:04:06 -070029 if (SK_InvalidUniqueID != uniqueID) {
30 REPORTER_ASSERT(reporter, proxy->uniqueID() == uniqueID);
31 }
robertphillips76948d42016-05-04 12:47:41 -070032}
33
34static void check_rendertarget(skiatest::Reporter* reporter,
35 GrTextureProvider* provider,
36 GrRenderTargetProxy* rtProxy,
37 SkBackingFit fit) {
38 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == nullptr); // for now
39 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
40
41 GrRenderTarget* rt = rtProxy->instantiate(provider);
42 REPORTER_ASSERT(reporter, rt);
43
44 REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
45 if (SkBackingFit::kExact == fit) {
46 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
47 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
48 } else {
49 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
50 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
51 }
52 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
53
54 REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled());
55 REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() ==
56 rtProxy->isStencilBufferMultisampled());
57 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
58 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
csmartdaltonf9635992016-08-10 11:09:07 -070059 REPORTER_ASSERT(reporter, rt->isMixedSampled() == rtProxy->isMixedSampled());
60 REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070061}
62
63static void check_texture(skiatest::Reporter* reporter,
64 GrTextureProvider* provider,
65 GrTextureProxy* texProxy,
66 SkBackingFit fit) {
67 REPORTER_ASSERT(reporter, texProxy->asTextureProxy() == texProxy);
68 REPORTER_ASSERT(reporter, texProxy->asRenderTargetProxy() == nullptr); // for now
69
70 GrTexture* tex = texProxy->instantiate(provider);
71 REPORTER_ASSERT(reporter, tex);
72
73 REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
74 if (SkBackingFit::kExact == fit) {
75 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
76 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
77 } else {
78 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
79 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
80 }
81 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
82}
83
84
robertphillips8abb3702016-08-31 14:04:06 -070085DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070086 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
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;
99 desc.fOrigin = origin;
100 desc.fWidth = widthHeight;
101 desc.fHeight = widthHeight;
102 desc.fConfig = config;
103 desc.fSampleCnt = numSamples;
104
105 if (renderable) {
106 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(
bsalomon8b7451a2016-05-11 06:33:06 -0700107 *ctxInfo.grContext()->caps(),
robertphillips76948d42016-05-04 12:47:41 -0700108 desc,
109 fit,
110 budgeted));
111 check_surface(reporter, rtProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700112 widthHeight, widthHeight, config, SK_InvalidUniqueID);
robertphillips76948d42016-05-04 12:47:41 -0700113 check_rendertarget(reporter, provider, rtProxy.get(), fit);
114 }
115
116 desc.fSampleCnt = 0;
117
118 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(desc,
119 fit,
120 budgeted));
121 check_surface(reporter, texProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700122 widthHeight, widthHeight, config, SK_InvalidUniqueID);
robertphillips76948d42016-05-04 12:47:41 -0700123 check_texture(reporter, provider, texProxy.get(), fit);
124 }
125 }
126 }
127 }
128 }
129 }
130}
131
egdanielab527a52016-06-28 08:07:26 -0700132DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700133 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
csmartdaltonf9635992016-08-10 11:09:07 -0700134 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -0700135
136 static const int kWidthHeight = 100;
137
138 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
139 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
140 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
141 for (auto numSamples: { 0, 4}) {
csmartdaltonf9635992016-08-10 11:09:07 -0700142 bool renderable = caps.isConfigRenderable(config, numSamples > 0);
robertphillips76948d42016-05-04 12:47:41 -0700143
144 GrSurfaceDesc desc;
145 desc.fOrigin = origin;
146 desc.fWidth = kWidthHeight;
147 desc.fHeight = kWidthHeight;
148 desc.fConfig = config;
149 desc.fSampleCnt = numSamples;
150
csmartdaltonf9635992016-08-10 11:09:07 -0700151 // External on-screen render target.
152 if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
153 GrBackendRenderTargetDesc backendDesc;
154 backendDesc.fWidth = kWidthHeight;
155 backendDesc.fHeight = kWidthHeight;
156 backendDesc.fConfig = config;
157 backendDesc.fOrigin = origin;
158 backendDesc.fSampleCnt = numSamples;
159 backendDesc.fStencilBits = 8;
160 backendDesc.fRenderTargetHandle = 0;
161
162 GrGpu* gpu = ctxInfo.grContext()->getGpu();
163 sk_sp<GrRenderTarget> defaultFBO(
164 gpu->wrapBackendRenderTarget(backendDesc, kBorrow_GrWrapOwnership));
165 SkASSERT(!defaultFBO->renderTargetPriv().supportsWindowRectangles());
166
167 sk_sp<GrRenderTargetProxy> rtProxy(
168 GrRenderTargetProxy::Make(caps, defaultFBO));
169 check_surface(reporter, rtProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700170 kWidthHeight, kWidthHeight, config, defaultFBO->uniqueID());
csmartdaltonf9635992016-08-10 11:09:07 -0700171 check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
172 }
173
robertphillips76948d42016-05-04 12:47:41 -0700174 sk_sp<GrTexture> tex;
175
csmartdaltonf9635992016-08-10 11:09:07 -0700176 // Internal offscreen render target.
robertphillips76948d42016-05-04 12:47:41 -0700177 if (renderable) {
178 desc.fFlags = kRenderTarget_GrSurfaceFlag;
179 tex.reset(provider->createTexture(desc, budgeted));
180 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
csmartdaltonf9635992016-08-10 11:09:07 -0700181 SkASSERT(caps.maxWindowRectangles() <= 0 ||
182 rt->renderTargetPriv().supportsWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700183
csmartdaltonf9635992016-08-10 11:09:07 -0700184 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(caps, rt));
robertphillips76948d42016-05-04 12:47:41 -0700185 check_surface(reporter, rtProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700186 kWidthHeight, kWidthHeight, config, rt->uniqueID());
robertphillips76948d42016-05-04 12:47:41 -0700187 check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
188 }
189
190 if (!tex) {
191 SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
192 desc.fSampleCnt = 0;
193 tex.reset(provider->createTexture(desc, budgeted));
194 }
195
196 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex));
197 check_surface(reporter, texProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700198 kWidthHeight, kWidthHeight, config, tex->uniqueID());
robertphillips76948d42016-05-04 12:47:41 -0700199 check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact);
200 }
201 }
202 }
203 }
204}
205
206#endif