blob: 45d3945c7ff6995a08f3a401656c00298501c3d6 [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
18static void check_surface(skiatest::Reporter* reporter,
19 GrSurfaceProxy* proxy,
20 GrSurfaceOrigin origin,
21 int width, int height,
22 GrPixelConfig config) {
23 REPORTER_ASSERT(reporter, proxy->origin() == origin);
24 REPORTER_ASSERT(reporter, proxy->width() == width);
25 REPORTER_ASSERT(reporter, proxy->height() == height);
26 REPORTER_ASSERT(reporter, proxy->config() == config);
27}
28
29static void check_rendertarget(skiatest::Reporter* reporter,
30 GrTextureProvider* provider,
31 GrRenderTargetProxy* rtProxy,
32 SkBackingFit fit) {
33 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == nullptr); // for now
34 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
35
36 GrRenderTarget* rt = rtProxy->instantiate(provider);
37 REPORTER_ASSERT(reporter, rt);
38
39 REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
40 if (SkBackingFit::kExact == fit) {
41 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
42 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
43 } else {
44 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
45 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
46 }
47 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
48
49 REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled());
50 REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() ==
51 rtProxy->isStencilBufferMultisampled());
52 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
53 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
csmartdaltonf9635992016-08-10 11:09:07 -070054 REPORTER_ASSERT(reporter, rt->isMixedSampled() == rtProxy->isMixedSampled());
55 REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags());
robertphillips76948d42016-05-04 12:47:41 -070056}
57
58static void check_texture(skiatest::Reporter* reporter,
59 GrTextureProvider* provider,
60 GrTextureProxy* texProxy,
61 SkBackingFit fit) {
62 REPORTER_ASSERT(reporter, texProxy->asTextureProxy() == texProxy);
63 REPORTER_ASSERT(reporter, texProxy->asRenderTargetProxy() == nullptr); // for now
64
65 GrTexture* tex = texProxy->instantiate(provider);
66 REPORTER_ASSERT(reporter, tex);
67
68 REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
69 if (SkBackingFit::kExact == fit) {
70 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
71 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
72 } else {
73 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
74 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
75 }
76 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
77}
78
79
egdanielab527a52016-06-28 08:07:26 -070080DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AllocedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070081 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
robertphillips76948d42016-05-04 12:47:41 -070082
83 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
84 for (auto widthHeight : { 100, 128 }) {
85 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
86 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
87 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
88 for (auto numSamples : { 0, 4}) {
bsalomon8b7451a2016-05-11 06:33:06 -070089 bool renderable = ctxInfo.grContext()->caps()->isConfigRenderable(
robertphillipsd0e36a92016-05-10 10:23:30 -070090 config, numSamples > 0) &&
bsalomon8b7451a2016-05-11 06:33:06 -070091 numSamples <= ctxInfo.grContext()->caps()->maxColorSampleCount();
robertphillips76948d42016-05-04 12:47:41 -070092
93 GrSurfaceDesc desc;
94 desc.fOrigin = origin;
95 desc.fWidth = widthHeight;
96 desc.fHeight = widthHeight;
97 desc.fConfig = config;
98 desc.fSampleCnt = numSamples;
99
100 if (renderable) {
101 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(
bsalomon8b7451a2016-05-11 06:33:06 -0700102 *ctxInfo.grContext()->caps(),
robertphillips76948d42016-05-04 12:47:41 -0700103 desc,
104 fit,
105 budgeted));
106 check_surface(reporter, rtProxy.get(), origin,
107 widthHeight, widthHeight, config);
108 check_rendertarget(reporter, provider, rtProxy.get(), fit);
109 }
110
111 desc.fSampleCnt = 0;
112
113 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(desc,
114 fit,
115 budgeted));
116 check_surface(reporter, texProxy.get(), origin,
117 widthHeight, widthHeight, config);
118 check_texture(reporter, provider, texProxy.get(), fit);
119 }
120 }
121 }
122 }
123 }
124 }
125}
126
egdanielab527a52016-06-28 08:07:26 -0700127DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700128 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
csmartdaltonf9635992016-08-10 11:09:07 -0700129 const GrCaps& caps = *ctxInfo.grContext()->caps();
robertphillips76948d42016-05-04 12:47:41 -0700130
131 static const int kWidthHeight = 100;
132
133 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
134 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
135 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
136 for (auto numSamples: { 0, 4}) {
csmartdaltonf9635992016-08-10 11:09:07 -0700137 bool renderable = caps.isConfigRenderable(config, numSamples > 0);
robertphillips76948d42016-05-04 12:47:41 -0700138
139 GrSurfaceDesc desc;
140 desc.fOrigin = origin;
141 desc.fWidth = kWidthHeight;
142 desc.fHeight = kWidthHeight;
143 desc.fConfig = config;
144 desc.fSampleCnt = numSamples;
145
csmartdaltonf9635992016-08-10 11:09:07 -0700146 // External on-screen render target.
147 if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
148 GrBackendRenderTargetDesc backendDesc;
149 backendDesc.fWidth = kWidthHeight;
150 backendDesc.fHeight = kWidthHeight;
151 backendDesc.fConfig = config;
152 backendDesc.fOrigin = origin;
153 backendDesc.fSampleCnt = numSamples;
154 backendDesc.fStencilBits = 8;
155 backendDesc.fRenderTargetHandle = 0;
156
157 GrGpu* gpu = ctxInfo.grContext()->getGpu();
158 sk_sp<GrRenderTarget> defaultFBO(
159 gpu->wrapBackendRenderTarget(backendDesc, kBorrow_GrWrapOwnership));
160 SkASSERT(!defaultFBO->renderTargetPriv().supportsWindowRectangles());
161
162 sk_sp<GrRenderTargetProxy> rtProxy(
163 GrRenderTargetProxy::Make(caps, defaultFBO));
164 check_surface(reporter, rtProxy.get(), origin,
165 kWidthHeight, kWidthHeight, config);
166 check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
167 }
168
robertphillips76948d42016-05-04 12:47:41 -0700169 sk_sp<GrTexture> tex;
170
csmartdaltonf9635992016-08-10 11:09:07 -0700171 // Internal offscreen render target.
robertphillips76948d42016-05-04 12:47:41 -0700172 if (renderable) {
173 desc.fFlags = kRenderTarget_GrSurfaceFlag;
174 tex.reset(provider->createTexture(desc, budgeted));
175 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
csmartdaltonf9635992016-08-10 11:09:07 -0700176 SkASSERT(caps.maxWindowRectangles() <= 0 ||
177 rt->renderTargetPriv().supportsWindowRectangles());
robertphillips76948d42016-05-04 12:47:41 -0700178
csmartdaltonf9635992016-08-10 11:09:07 -0700179 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(caps, rt));
robertphillips76948d42016-05-04 12:47:41 -0700180 check_surface(reporter, rtProxy.get(), origin,
181 kWidthHeight, kWidthHeight, config);
182 check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
183 }
184
185 if (!tex) {
186 SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
187 desc.fSampleCnt = 0;
188 tex.reset(provider->createTexture(desc, budgeted));
189 }
190
191 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex));
192 check_surface(reporter, texProxy.get(), origin,
193 kWidthHeight, kWidthHeight, config);
194 check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact);
195 }
196 }
197 }
198 }
199}
200
201#endif