blob: 9a7697c8ae15e8605dc9efd34c5e481a4447f2e3 [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"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040016#include "GrRenderTargetPriv.h"
robertphillips76948d42016-05-04 12:47:41 -070017#include "GrRenderTargetProxy.h"
18
robertphillips8abb3702016-08-31 14:04:06 -070019// Check that the surface proxy's member vars are set as expected
robertphillips76948d42016-05-04 12:47:41 -070020static void check_surface(skiatest::Reporter* reporter,
21 GrSurfaceProxy* proxy,
22 GrSurfaceOrigin origin,
23 int width, int height,
robertphillips8abb3702016-08-31 14:04:06 -070024 GrPixelConfig config,
25 uint32_t uniqueID) {
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 }
robertphillips76948d42016-05-04 12:47:41 -070033}
34
35static void check_rendertarget(skiatest::Reporter* reporter,
36 GrTextureProvider* provider,
37 GrRenderTargetProxy* rtProxy,
38 SkBackingFit fit) {
39 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == nullptr); // for now
40 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
41
42 GrRenderTarget* rt = rtProxy->instantiate(provider);
43 REPORTER_ASSERT(reporter, rt);
44
45 REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
46 if (SkBackingFit::kExact == fit) {
47 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
48 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
49 } else {
50 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
51 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
52 }
53 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
54
55 REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled());
56 REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() ==
57 rtProxy->isStencilBufferMultisampled());
58 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
59 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
csmartdaltonf9635992016-08-10 11:09:07 -070060 REPORTER_ASSERT(reporter, rt->isMixedSampled() == rtProxy->isMixedSampled());
61 REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070062}
63
64static void check_texture(skiatest::Reporter* reporter,
65 GrTextureProvider* provider,
66 GrTextureProxy* texProxy,
67 SkBackingFit fit) {
68 REPORTER_ASSERT(reporter, texProxy->asTextureProxy() == texProxy);
69 REPORTER_ASSERT(reporter, texProxy->asRenderTargetProxy() == nullptr); // for now
70
71 GrTexture* tex = texProxy->instantiate(provider);
72 REPORTER_ASSERT(reporter, tex);
73
74 REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
75 if (SkBackingFit::kExact == fit) {
76 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
77 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
78 } else {
79 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
80 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
81 }
82 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
83}
84
85
robertphillips8abb3702016-08-31 14:04:06 -070086DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070087 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
robertphillips76948d42016-05-04 12:47:41 -070088
89 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
90 for (auto widthHeight : { 100, 128 }) {
91 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
92 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
93 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
94 for (auto numSamples : { 0, 4}) {
bsalomon8b7451a2016-05-11 06:33:06 -070095 bool renderable = ctxInfo.grContext()->caps()->isConfigRenderable(
robertphillipsd0e36a92016-05-10 10:23:30 -070096 config, numSamples > 0) &&
bsalomon8b7451a2016-05-11 06:33:06 -070097 numSamples <= ctxInfo.grContext()->caps()->maxColorSampleCount();
robertphillips76948d42016-05-04 12:47:41 -070098
99 GrSurfaceDesc desc;
100 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(
bsalomon8b7451a2016-05-11 06:33:06 -0700108 *ctxInfo.grContext()->caps(),
robertphillips76948d42016-05-04 12:47:41 -0700109 desc,
110 fit,
111 budgeted));
112 check_surface(reporter, rtProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700113 widthHeight, widthHeight, config, SK_InvalidUniqueID);
robertphillips76948d42016-05-04 12:47:41 -0700114 check_rendertarget(reporter, provider, rtProxy.get(), fit);
115 }
116
117 desc.fSampleCnt = 0;
118
119 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(desc,
120 fit,
121 budgeted));
122 check_surface(reporter, texProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700123 widthHeight, widthHeight, config, SK_InvalidUniqueID);
robertphillips76948d42016-05-04 12:47:41 -0700124 check_texture(reporter, provider, texProxy.get(), fit);
125 }
126 }
127 }
128 }
129 }
130 }
131}
132
egdanielab527a52016-06-28 08:07:26 -0700133DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700134 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
csmartdaltonf9635992016-08-10 11:09:07 -0700135 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -0700136
137 static const int kWidthHeight = 100;
138
139 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
140 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
141 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
142 for (auto numSamples: { 0, 4}) {
csmartdaltonf9635992016-08-10 11:09:07 -0700143 bool renderable = caps.isConfigRenderable(config, numSamples > 0);
robertphillips76948d42016-05-04 12:47:41 -0700144
145 GrSurfaceDesc desc;
146 desc.fOrigin = origin;
147 desc.fWidth = kWidthHeight;
148 desc.fHeight = kWidthHeight;
149 desc.fConfig = config;
150 desc.fSampleCnt = numSamples;
151
csmartdaltonf9635992016-08-10 11:09:07 -0700152 // External on-screen render target.
153 if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
154 GrBackendRenderTargetDesc backendDesc;
155 backendDesc.fWidth = kWidthHeight;
156 backendDesc.fHeight = kWidthHeight;
157 backendDesc.fConfig = config;
158 backendDesc.fOrigin = origin;
159 backendDesc.fSampleCnt = numSamples;
160 backendDesc.fStencilBits = 8;
161 backendDesc.fRenderTargetHandle = 0;
162
163 GrGpu* gpu = ctxInfo.grContext()->getGpu();
164 sk_sp<GrRenderTarget> defaultFBO(
165 gpu->wrapBackendRenderTarget(backendDesc, kBorrow_GrWrapOwnership));
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700166 REPORTER_ASSERT(reporter,
167 !defaultFBO->renderTargetPriv().maxWindowRectangles());
csmartdaltonf9635992016-08-10 11:09:07 -0700168
169 sk_sp<GrRenderTargetProxy> rtProxy(
170 GrRenderTargetProxy::Make(caps, defaultFBO));
171 check_surface(reporter, rtProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700172 kWidthHeight, kWidthHeight, config, defaultFBO->uniqueID());
csmartdaltonf9635992016-08-10 11:09:07 -0700173 check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
174 }
175
robertphillips76948d42016-05-04 12:47:41 -0700176 sk_sp<GrTexture> tex;
177
csmartdaltonf9635992016-08-10 11:09:07 -0700178 // Internal offscreen render target.
robertphillips76948d42016-05-04 12:47:41 -0700179 if (renderable) {
180 desc.fFlags = kRenderTarget_GrSurfaceFlag;
181 tex.reset(provider->createTexture(desc, budgeted));
182 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700183 REPORTER_ASSERT(reporter,
184 caps.maxWindowRectangles() ==
185 rt->renderTargetPriv().maxWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700186
csmartdaltonf9635992016-08-10 11:09:07 -0700187 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(caps, rt));
robertphillips76948d42016-05-04 12:47:41 -0700188 check_surface(reporter, rtProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700189 kWidthHeight, kWidthHeight, config, rt->uniqueID());
robertphillips76948d42016-05-04 12:47:41 -0700190 check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
191 }
192
193 if (!tex) {
194 SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
195 desc.fSampleCnt = 0;
196 tex.reset(provider->createTexture(desc, budgeted));
197 }
198
199 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex));
200 check_surface(reporter, texProxy.get(), origin,
robertphillips8abb3702016-08-31 14:04:06 -0700201 kWidthHeight, kWidthHeight, config, tex->uniqueID());
robertphillips76948d42016-05-04 12:47:41 -0700202 check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact);
203 }
204 }
205 }
206 }
207}
208
209#endif