blob: 2ed4591a723c83eb562f3d0f7d63fd6e71821c29 [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"
15#include "GrRenderTargetProxy.h"
16
17static void check_surface(skiatest::Reporter* reporter,
18 GrSurfaceProxy* proxy,
19 GrSurfaceOrigin origin,
20 int width, int height,
21 GrPixelConfig config) {
22 REPORTER_ASSERT(reporter, proxy->origin() == origin);
23 REPORTER_ASSERT(reporter, proxy->width() == width);
24 REPORTER_ASSERT(reporter, proxy->height() == height);
25 REPORTER_ASSERT(reporter, proxy->config() == config);
26}
27
28static void check_rendertarget(skiatest::Reporter* reporter,
29 GrTextureProvider* provider,
30 GrRenderTargetProxy* rtProxy,
31 SkBackingFit fit) {
32 REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == nullptr); // for now
33 REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
34
35 GrRenderTarget* rt = rtProxy->instantiate(provider);
36 REPORTER_ASSERT(reporter, rt);
37
38 REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
39 if (SkBackingFit::kExact == fit) {
40 REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
41 REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
42 } else {
43 REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
44 REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
45 }
46 REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
47
48 REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled());
49 REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() ==
50 rtProxy->isStencilBufferMultisampled());
51 REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
52 REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
53 REPORTER_ASSERT(reporter, rt->hasMixedSamples() == rtProxy->hasMixedSamples());
54}
55
56static void check_texture(skiatest::Reporter* reporter,
57 GrTextureProvider* provider,
58 GrTextureProxy* texProxy,
59 SkBackingFit fit) {
60 REPORTER_ASSERT(reporter, texProxy->asTextureProxy() == texProxy);
61 REPORTER_ASSERT(reporter, texProxy->asRenderTargetProxy() == nullptr); // for now
62
63 GrTexture* tex = texProxy->instantiate(provider);
64 REPORTER_ASSERT(reporter, tex);
65
66 REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
67 if (SkBackingFit::kExact == fit) {
68 REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
69 REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
70 } else {
71 REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
72 REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
73 }
74 REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
75}
76
77
egdanielab527a52016-06-28 08:07:26 -070078DEF_GPUTEST_FOR_RENDERING_CONTEXTS(AllocedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070079 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
robertphillips76948d42016-05-04 12:47:41 -070080
81 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
82 for (auto widthHeight : { 100, 128 }) {
83 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
84 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
85 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
86 for (auto numSamples : { 0, 4}) {
bsalomon8b7451a2016-05-11 06:33:06 -070087 bool renderable = ctxInfo.grContext()->caps()->isConfigRenderable(
robertphillipsd0e36a92016-05-10 10:23:30 -070088 config, numSamples > 0) &&
bsalomon8b7451a2016-05-11 06:33:06 -070089 numSamples <= ctxInfo.grContext()->caps()->maxColorSampleCount();
robertphillips76948d42016-05-04 12:47:41 -070090
91 GrSurfaceDesc desc;
92 desc.fOrigin = origin;
93 desc.fWidth = widthHeight;
94 desc.fHeight = widthHeight;
95 desc.fConfig = config;
96 desc.fSampleCnt = numSamples;
97
98 if (renderable) {
99 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(
bsalomon8b7451a2016-05-11 06:33:06 -0700100 *ctxInfo.grContext()->caps(),
robertphillips76948d42016-05-04 12:47:41 -0700101 desc,
102 fit,
103 budgeted));
104 check_surface(reporter, rtProxy.get(), origin,
105 widthHeight, widthHeight, config);
106 check_rendertarget(reporter, provider, rtProxy.get(), fit);
107 }
108
109 desc.fSampleCnt = 0;
110
111 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(desc,
112 fit,
113 budgeted));
114 check_surface(reporter, texProxy.get(), origin,
115 widthHeight, widthHeight, config);
116 check_texture(reporter, provider, texProxy.get(), fit);
117 }
118 }
119 }
120 }
121 }
122 }
123}
124
egdanielab527a52016-06-28 08:07:26 -0700125DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700126 GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
robertphillips76948d42016-05-04 12:47:41 -0700127
128 static const int kWidthHeight = 100;
129
130 for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
131 for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
132 for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
133 for (auto numSamples: { 0, 4}) {
bsalomon8b7451a2016-05-11 06:33:06 -0700134 bool renderable = ctxInfo.grContext()->caps()->isConfigRenderable(
robertphillips76948d42016-05-04 12:47:41 -0700135 config, numSamples > 0);
136
137 GrSurfaceDesc desc;
138 desc.fOrigin = origin;
139 desc.fWidth = kWidthHeight;
140 desc.fHeight = kWidthHeight;
141 desc.fConfig = config;
142 desc.fSampleCnt = numSamples;
143
144 sk_sp<GrTexture> tex;
145
146 if (renderable) {
147 desc.fFlags = kRenderTarget_GrSurfaceFlag;
148 tex.reset(provider->createTexture(desc, budgeted));
149 sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
150
151 sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(rt));
152 check_surface(reporter, rtProxy.get(), origin,
153 kWidthHeight, kWidthHeight, config);
154 check_rendertarget(reporter, provider, rtProxy.get(), SkBackingFit::kExact);
155 }
156
157 if (!tex) {
158 SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
159 desc.fSampleCnt = 0;
160 tex.reset(provider->createTexture(desc, budgeted));
161 }
162
163 sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex));
164 check_surface(reporter, texProxy.get(), origin,
165 kWidthHeight, kWidthHeight, config);
166 check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact);
167 }
168 }
169 }
170 }
171}
172
173#endif