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
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// This is a GPU-backend specific test.
#include "Test.h"
#if SK_SUPPORT_GPU
#include "GrBackendSurface.h"
#include "GrContextPriv.h"
#include "GrProxyProvider.h"
#include "GrRenderTarget.h"
#include "GrRenderTargetProxy.h"
#include "GrSurfaceProxy.h"
#include "GrTexture.h"
#include "GrTextureProxy.h"
static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrProxyProvider* provider,
skiatest::Reporter* reporter,
const GrSurfaceDesc& desc) {
GrGLFramebufferInfo fboInfo;
fboInfo.fFBOID = 0;
GrBackendRenderTarget backendRT(desc.fWidth, desc.fHeight, desc.fSampleCnt, 8,
desc.fConfig, fboInfo);
return provider->createWrappedRenderTargetProxy(backendRT, desc.fOrigin);
}
static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrProxyProvider* provider,
const GrSurfaceDesc& desc) {
SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
return provider->createInstantiatedProxy(desc, SkBackingFit::kExact, SkBudgeted::kYes);
}
static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrProxyProvider* provider,
const GrSurfaceDesc& desc) {
return provider->createInstantiatedProxy(desc, SkBackingFit::kExact, SkBudgeted::kYes);
}
// Test converting between RenderTargetProxies and TextureProxies for wrapped
// Proxies
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = 64;
desc.fHeight = 64;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
if (kOpenGL_GrBackend == ctxInfo.backend()) {
// External on-screen render target.
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(proxyProvider, reporter, desc));
if (sProxy) {
// RenderTarget-only
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
REPORTER_ASSERT(reporter, rtProxy);
REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
}
}
{
// Internal offscreen render target.
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(proxyProvider, desc));
if (sProxy) {
// Both RenderTarget and Texture
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
REPORTER_ASSERT(reporter, rtProxy);
GrTextureProxy* tProxy = rtProxy->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
}
}
{
// Internal offscreen render target - but through GrTextureProxy
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(proxyProvider, desc));
if (sProxy) {
// Both RenderTarget and Texture
GrTextureProxy* tProxy = sProxy->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
REPORTER_ASSERT(reporter, rtProxy);
REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
}
}
{
desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(proxyProvider, desc));
if (sProxy) {
// Texture-only
GrTextureProxy* tProxy = sProxy->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
}
}
}
// Test converting between RenderTargetProxies and TextureProxies for deferred
// Proxies
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
GrProxyProvider* proxyProvider = ctxInfo.grContext()->contextPriv().proxyProvider();
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fWidth = 64;
desc.fHeight = 64;
desc.fConfig = kRGBA_8888_GrPixelConfig;
{
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, SkBackingFit::kApprox,
SkBudgeted::kYes);
// Both RenderTarget and Texture
GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
REPORTER_ASSERT(reporter, rtProxy);
GrTextureProxy* tProxy = rtProxy->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
}
{
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, SkBackingFit::kApprox,
SkBudgeted::kYes);
// Both RenderTarget and Texture - but via GrTextureProxy
GrTextureProxy* tProxy = proxy->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
REPORTER_ASSERT(reporter, rtProxy);
REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
}
{
desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, SkBackingFit::kApprox,
SkBudgeted::kYes);
// Texture-only
GrTextureProxy* tProxy = proxy->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
}
}
#endif
|