1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTypes.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrGpu.h"
#include "GrProxyProvider.h"
#include "GrRenderTarget.h"
#include "GrResourceProvider.h"
#include "GrTest.h"
#include "GrTexture.h"
#include "SkMipMap.h"
#include "Test.h"
// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
// and render targets to GrSurface all work as expected.
DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
auto resourceProvider = context->contextPriv().resourceProvider();
GrGpu* gpu = context->contextPriv().getGpu();
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fWidth = 256;
desc.fHeight = 256;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fSampleCnt = 1;
sk_sp<GrSurface> texRT1 = resourceProvider->createTexture(desc, SkBudgeted::kNo);
REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget());
REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
texRT1->asTexture());
REPORTER_ASSERT(reporter, texRT1->asRenderTarget() ==
static_cast<GrSurface*>(texRT1->asTexture()));
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
static_cast<GrSurface*>(texRT1->asTexture()));
desc.fFlags = kNone_GrSurfaceFlags;
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
sk_sp<GrTexture> tex1 = resourceProvider->createTexture(desc, SkBudgeted::kNo);
REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
nullptr, 256, 256, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo);
sk_sp<GrSurface> texRT2 =
resourceProvider->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
texRT2->asTexture());
REPORTER_ASSERT(reporter, texRT2->asRenderTarget() ==
static_cast<GrSurface*>(texRT2->asTexture()));
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
static_cast<GrSurface*>(texRT2->asTexture()));
gpu->deleteTestingOnlyBackendTexture(&backendTex);
}
// This test checks that the isConfigTexturable and isConfigRenderable are
// consistent with createTexture's result.
DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider();
const GrCaps* caps = context->caps();
GrPixelConfig configs[] = {
kUnknown_GrPixelConfig,
kAlpha_8_GrPixelConfig,
kAlpha_8_as_Alpha_GrPixelConfig,
kAlpha_8_as_Red_GrPixelConfig,
kGray_8_GrPixelConfig,
kGray_8_as_Lum_GrPixelConfig,
kGray_8_as_Red_GrPixelConfig,
kRGB_565_GrPixelConfig,
kRGBA_4444_GrPixelConfig,
kRGBA_8888_GrPixelConfig,
kBGRA_8888_GrPixelConfig,
kSRGBA_8888_GrPixelConfig,
kSBGRA_8888_GrPixelConfig,
kRGBA_8888_sint_GrPixelConfig,
kRGBA_float_GrPixelConfig,
kRG_float_GrPixelConfig,
kAlpha_half_GrPixelConfig,
kAlpha_half_as_Red_GrPixelConfig,
kRGBA_half_GrPixelConfig,
};
SkASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs));
GrSurfaceDesc desc;
desc.fWidth = 64;
desc.fHeight = 64;
// Enough space for the first mip of our largest pixel config
const size_t pixelBufferSize = desc.fWidth * desc.fHeight *
GrBytesPerPixel(kRGBA_float_GrPixelConfig);
std::unique_ptr<char[]> pixelData(new char[pixelBufferSize]);
memset(pixelData.get(), 0, pixelBufferSize);
// We re-use the same mip level objects (with updated pointers and rowBytes) for each config
const int levelCount = SkMipMap::ComputeLevelCount(desc.fWidth, desc.fHeight) + 1;
std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[levelCount]);
for (GrPixelConfig config : configs) {
for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) {
desc.fFlags = kNone_GrSurfaceFlags;
desc.fOrigin = origin;
desc.fConfig = config;
desc.fSampleCnt = 1;
sk_sp<GrSurface> tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
bool ict = caps->isConfigTexturable(desc.fConfig);
REPORTER_ASSERT(reporter, SkToBool(tex) == ict,
"config:%d, tex:%d, isConfigTexturable:%d", config, SkToBool(tex), ict);
size_t rowBytes = desc.fWidth * GrBytesPerPixel(desc.fConfig);
for (int i = 0; i < levelCount; ++i) {
texels[i].fPixels = pixelData.get();
texels[i].fRowBytes = rowBytes >> i;
}
sk_sp<GrTextureProxy> proxy = proxyProvider->createMipMapProxy(
desc, SkBudgeted::kNo,
texels.get(), levelCount);
REPORTER_ASSERT(reporter, SkToBool(proxy.get()) ==
(caps->isConfigTexturable(desc.fConfig) &&
caps->mipMapSupport() &&
!GrPixelConfigIsSint(desc.fConfig)));
desc.fFlags = kRenderTarget_GrSurfaceFlag;
tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
bool isRenderable = caps->isConfigRenderable(config);
REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable,
"config:%d, tex:%d, isRenderable:%d", config, SkToBool(tex),
isRenderable);
desc.fSampleCnt = 2;
tex = resourceProvider->createTexture(desc, SkBudgeted::kNo);
isRenderable = SkToBool(caps->getRenderTargetSampleCount(2, config));
REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable,
"config:%d, tex:%d, isRenderable:%d", config, SkToBool(tex),
isRenderable);
}
}
}
#include "GrDrawingManager.h"
#include "GrSurfaceProxy.h"
#include "GrTextureContext.h"
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(InitialTextureClear, reporter, context_info) {
static constexpr int kSize = 100;
GrSurfaceDesc desc;
desc.fWidth = desc.fHeight = kSize;
std::unique_ptr<uint32_t[]> data(new uint32_t[kSize * kSize]);
GrContext* context = context_info.grContext();
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
for (int c = 0; c <= kLast_GrPixelConfig; ++c) {
desc.fConfig = static_cast<GrPixelConfig>(c);
if (!context_info.grContext()->caps()->isConfigTexturable(desc.fConfig)) {
continue;
}
desc.fFlags = kPerformInitialClear_GrSurfaceFlag;
for (bool rt : {false, true}) {
if (rt && !context->caps()->isConfigRenderable(desc.fConfig)) {
continue;
}
desc.fFlags |= rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
for (GrSurfaceOrigin origin :
{kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
desc.fOrigin = origin;
for (auto fit : { SkBackingFit::kApprox, SkBackingFit::kExact }) {
// Try directly creating the texture.
// Do this twice in an attempt to hit the cache on the second time through.
for (int i = 0; i < 2; ++i) {
sk_sp<GrTextureProxy> proxy = proxyProvider->createInstantiatedProxy(
desc, fit, SkBudgeted::kYes);
if (!proxy) {
continue;
}
auto texCtx = context->contextPriv().makeWrappedSurfaceContext(
std::move(proxy));
SkImageInfo info = SkImageInfo::Make(
kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t));
if (texCtx->readPixels(info, data.get(), 0, 0, 0)) {
uint32_t cmp = GrPixelConfigIsOpaque(desc.fConfig) ? 0xFF000000 : 0;
for (int i = 0; i < kSize * kSize; ++i) {
if (cmp != data.get()[i]) {
ERRORF(reporter, "Failed on config %d", desc.fConfig);
break;
}
}
}
memset(data.get(), 0xBC, kSize * kSize * sizeof(uint32_t));
// Here we overwrite the texture so that the second time through we
// test against recycling without reclearing.
if (0 == i) {
texCtx->writePixels(info, data.get(), 0, 0, 0);
}
}
context->purgeAllUnlockedResources();
// Try creating the texture as a deferred proxy.
for (int i = 0; i < 2; ++i) {
auto surfCtx = context->contextPriv().makeDeferredSurfaceContext(
desc, GrMipMapped::kNo, fit, SkBudgeted::kYes);
if (!surfCtx) {
continue;
}
SkImageInfo info = SkImageInfo::Make(
kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
memset(data.get(), 0xAB, kSize * kSize * sizeof(uint32_t));
if (surfCtx->readPixels(info, data.get(), 0, 0, 0)) {
uint32_t cmp = GrPixelConfigIsOpaque(desc.fConfig) ? 0xFF000000 : 0;
for (int i = 0; i < kSize * kSize; ++i) {
if (cmp != data.get()[i]) {
ERRORF(reporter, "Failed on config %d", desc.fConfig);
break;
}
}
}
// Here we overwrite the texture so that the second time through we
// test against recycling without reclearing.
if (0 == i) {
surfCtx->writePixels(info, data.get(), 0, 0, 0);
}
}
context->purgeAllUnlockedResources();
}
}
}
}
}
#endif
|