1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2016 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci// This is a GPU-backend specific test.
9cb93a386Sopenharmony_ci
10cb93a386Sopenharmony_ci#include "include/gpu/GrBackendSurface.h"
11cb93a386Sopenharmony_ci#include "include/gpu/GrDirectContext.h"
12cb93a386Sopenharmony_ci#include "src/gpu/GrDirectContextPriv.h"
13cb93a386Sopenharmony_ci#include "src/gpu/GrGpu.h"
14cb93a386Sopenharmony_ci#include "src/gpu/GrProxyProvider.h"
15cb93a386Sopenharmony_ci#include "src/gpu/GrRenderTarget.h"
16cb93a386Sopenharmony_ci#include "src/gpu/GrRenderTargetProxy.h"
17cb93a386Sopenharmony_ci#include "src/gpu/GrResourceProvider.h"
18cb93a386Sopenharmony_ci#include "src/gpu/GrSurface.h"
19cb93a386Sopenharmony_ci#include "src/gpu/GrSurfaceProxyPriv.h"
20cb93a386Sopenharmony_ci#include "src/gpu/GrTexture.h"
21cb93a386Sopenharmony_ci#include "src/gpu/GrTextureProxy.h"
22cb93a386Sopenharmony_ci#include "src/gpu/SkGr.h"
23cb93a386Sopenharmony_ci#include "tests/Test.h"
24cb93a386Sopenharmony_ci#include "tools/gpu/ManagedBackendTexture.h"
25cb93a386Sopenharmony_ci#ifdef SK_GL
26cb93a386Sopenharmony_ci#include "src/gpu/gl/GrGLDefines.h"
27cb93a386Sopenharmony_ci#include "src/gpu/gl/GrGLUtil.h"
28cb93a386Sopenharmony_ci#endif
29cb93a386Sopenharmony_ci
30cb93a386Sopenharmony_ci#include "tests/TestUtils.h"
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_ci// Check that the surface proxy's member vars are set as expected
33cb93a386Sopenharmony_cistatic void check_surface(skiatest::Reporter* reporter,
34cb93a386Sopenharmony_ci                          GrSurfaceProxy* proxy,
35cb93a386Sopenharmony_ci                          int width, int height,
36cb93a386Sopenharmony_ci                          SkBudgeted budgeted) {
37cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, proxy->width() == width);
38cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, proxy->height() == height);
39cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
40cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
41cb93a386Sopenharmony_ci}
42cb93a386Sopenharmony_ci
43cb93a386Sopenharmony_cistatic void check_rendertarget(skiatest::Reporter* reporter,
44cb93a386Sopenharmony_ci                               const GrCaps& caps,
45cb93a386Sopenharmony_ci                               GrResourceProvider* provider,
46cb93a386Sopenharmony_ci                               GrRenderTargetProxy* rtProxy,
47cb93a386Sopenharmony_ci                               int numSamples,
48cb93a386Sopenharmony_ci                               SkBackingFit fit,
49cb93a386Sopenharmony_ci                               int expectedMaxWindowRects) {
50cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
51cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, rtProxy->numSamples() == numSamples);
52cb93a386Sopenharmony_ci
53cb93a386Sopenharmony_ci    GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
54cb93a386Sopenharmony_ci    bool preinstantiated = rtProxy->isInstantiated();
55cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, rtProxy->instantiate(provider));
56cb93a386Sopenharmony_ci    GrRenderTarget* rt = rtProxy->peekRenderTarget();
57cb93a386Sopenharmony_ci
58cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
59cb93a386Sopenharmony_ci    // Deferred resources should always have a different ID from their instantiated rendertarget
60cb93a386Sopenharmony_ci    if (preinstantiated) {
61cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
62cb93a386Sopenharmony_ci    } else {
63cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
64cb93a386Sopenharmony_ci    }
65cb93a386Sopenharmony_ci
66cb93a386Sopenharmony_ci    if (SkBackingFit::kExact == fit) {
67cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rt->dimensions() == rtProxy->dimensions());
68cb93a386Sopenharmony_ci    } else {
69cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
70cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
71cb93a386Sopenharmony_ci    }
72cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, rt->backendFormat() == rtProxy->backendFormat());
73cb93a386Sopenharmony_ci
74cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, rt->numSamples() == rtProxy->numSamples());
75cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, rt->flags() == rtProxy->testingOnly_getFlags());
76cb93a386Sopenharmony_ci}
77cb93a386Sopenharmony_ci
78cb93a386Sopenharmony_cistatic void check_texture(skiatest::Reporter* reporter,
79cb93a386Sopenharmony_ci                          GrResourceProvider* provider,
80cb93a386Sopenharmony_ci                          GrTextureProxy* texProxy,
81cb93a386Sopenharmony_ci                          SkBackingFit fit) {
82cb93a386Sopenharmony_ci    GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
83cb93a386Sopenharmony_ci
84cb93a386Sopenharmony_ci    bool preinstantiated = texProxy->isInstantiated();
85cb93a386Sopenharmony_ci    // The instantiated texture should have these dimensions. If the fit is kExact, then
86cb93a386Sopenharmony_ci    // 'backingStoreDimensions' reports the original WxH. If it is kApprox, make sure that
87cb93a386Sopenharmony_ci    // the texture is that size and didn't reuse one of the kExact surfaces in the provider.
88cb93a386Sopenharmony_ci    // This is important because upstream usage (e.g. SkImage) reports size based on the
89cb93a386Sopenharmony_ci    // backingStoreDimensions and client code may rely on that if they are creating backend
90cb93a386Sopenharmony_ci    // resources.
91cb93a386Sopenharmony_ci    // NOTE: we store these before instantiating, since after instantiation backingStoreDimensions
92cb93a386Sopenharmony_ci    // just returns the target's dimensions. In this instance, we want to ensure the target's
93cb93a386Sopenharmony_ci    // dimensions are no different from the original approximate (or exact) dimensions.
94cb93a386Sopenharmony_ci    SkISize expectedSize = texProxy->backingStoreDimensions();
95cb93a386Sopenharmony_ci
96cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
97cb93a386Sopenharmony_ci    GrTexture* tex = texProxy->peekTexture();
98cb93a386Sopenharmony_ci
99cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
100cb93a386Sopenharmony_ci    // Deferred resources should always have a different ID from their instantiated texture
101cb93a386Sopenharmony_ci    if (preinstantiated) {
102cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
103cb93a386Sopenharmony_ci    } else {
104cb93a386Sopenharmony_ci        REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
105cb93a386Sopenharmony_ci    }
106cb93a386Sopenharmony_ci
107cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, tex->dimensions() == expectedSize);
108cb93a386Sopenharmony_ci
109cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, tex->backendFormat() == texProxy->backendFormat());
110cb93a386Sopenharmony_ci}
111cb93a386Sopenharmony_ci
112cb93a386Sopenharmony_ci
113cb93a386Sopenharmony_ciDEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
114cb93a386Sopenharmony_ci    auto direct = ctxInfo.directContext();
115cb93a386Sopenharmony_ci    GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
116cb93a386Sopenharmony_ci    GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
117cb93a386Sopenharmony_ci    const GrCaps& caps = *direct->priv().caps();
118cb93a386Sopenharmony_ci
119cb93a386Sopenharmony_ci    int attempt = 0; // useful for debugging
120cb93a386Sopenharmony_ci
121cb93a386Sopenharmony_ci    for (auto widthHeight : {100, 128, 1048576}) {
122cb93a386Sopenharmony_ci        for (auto ct : {GrColorType::kAlpha_8, GrColorType::kBGR_565, GrColorType::kRGBA_8888,
123cb93a386Sopenharmony_ci                        GrColorType::kRGBA_1010102}) {
124cb93a386Sopenharmony_ci            for (auto fit : {SkBackingFit::kExact, SkBackingFit::kApprox}) {
125cb93a386Sopenharmony_ci                for (auto budgeted : {SkBudgeted::kYes, SkBudgeted::kNo}) {
126cb93a386Sopenharmony_ci                    for (auto numSamples : {1, 4, 16, 128}) {
127cb93a386Sopenharmony_ci                        SkISize dims = {widthHeight, widthHeight};
128cb93a386Sopenharmony_ci
129cb93a386Sopenharmony_ci                        auto format = caps.getDefaultBackendFormat(ct, GrRenderable::kYes);
130cb93a386Sopenharmony_ci                        if (!format.isValid()) {
131cb93a386Sopenharmony_ci                            continue;
132cb93a386Sopenharmony_ci                        }
133cb93a386Sopenharmony_ci
134cb93a386Sopenharmony_ci                        // Renderable
135cb93a386Sopenharmony_ci                        {
136cb93a386Sopenharmony_ci                            sk_sp<GrTexture> tex;
137cb93a386Sopenharmony_ci                            if (SkBackingFit::kApprox == fit) {
138cb93a386Sopenharmony_ci                                tex = resourceProvider->createApproxTexture(
139cb93a386Sopenharmony_ci                                        dims, format, GrTextureType::k2D, GrRenderable::kYes,
140cb93a386Sopenharmony_ci                                        numSamples, GrProtected::kNo);
141cb93a386Sopenharmony_ci                            } else {
142cb93a386Sopenharmony_ci                                tex = resourceProvider->createTexture(
143cb93a386Sopenharmony_ci                                        dims, format, GrTextureType::k2D, GrRenderable::kYes,
144cb93a386Sopenharmony_ci                                        numSamples, GrMipmapped::kNo, budgeted, GrProtected::kNo);
145cb93a386Sopenharmony_ci                            }
146cb93a386Sopenharmony_ci
147cb93a386Sopenharmony_ci                            sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
148cb93a386Sopenharmony_ci                                    format, dims, GrRenderable::kYes, numSamples, GrMipmapped::kNo,
149cb93a386Sopenharmony_ci                                    fit, budgeted, GrProtected::kNo);
150cb93a386Sopenharmony_ci                            REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
151cb93a386Sopenharmony_ci                            if (proxy) {
152cb93a386Sopenharmony_ci                                REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
153cb93a386Sopenharmony_ci                                // This forces the proxy to compute and cache its
154cb93a386Sopenharmony_ci                                // pre-instantiation size guess. Later, when it is actually
155cb93a386Sopenharmony_ci                                // instantiated, it checks that the instantiated size is <= to
156cb93a386Sopenharmony_ci                                // the pre-computation. If the proxy never computed its
157cb93a386Sopenharmony_ci                                // pre-instantiation size then the check is skipped.
158cb93a386Sopenharmony_ci                                proxy->gpuMemorySize();
159cb93a386Sopenharmony_ci
160cb93a386Sopenharmony_ci                                check_surface(reporter, proxy.get(), widthHeight, widthHeight,
161cb93a386Sopenharmony_ci                                              budgeted);
162cb93a386Sopenharmony_ci                                int supportedSamples =
163cb93a386Sopenharmony_ci                                        caps.getRenderTargetSampleCount(numSamples, format);
164cb93a386Sopenharmony_ci                                check_rendertarget(reporter, caps, resourceProvider,
165cb93a386Sopenharmony_ci                                                   proxy->asRenderTargetProxy(), supportedSamples,
166cb93a386Sopenharmony_ci                                                   fit, caps.maxWindowRectangles());
167cb93a386Sopenharmony_ci                            }
168cb93a386Sopenharmony_ci                        }
169cb93a386Sopenharmony_ci
170cb93a386Sopenharmony_ci                        // Not renderable
171cb93a386Sopenharmony_ci                        {
172cb93a386Sopenharmony_ci                            sk_sp<GrTexture> tex;
173cb93a386Sopenharmony_ci                            if (SkBackingFit::kApprox == fit) {
174cb93a386Sopenharmony_ci                                tex = resourceProvider->createApproxTexture(
175cb93a386Sopenharmony_ci                                        dims, format, GrTextureType::k2D, GrRenderable::kNo,
176cb93a386Sopenharmony_ci                                        numSamples, GrProtected::kNo);
177cb93a386Sopenharmony_ci                            } else {
178cb93a386Sopenharmony_ci                                tex = resourceProvider->createTexture(
179cb93a386Sopenharmony_ci                                        dims, format, GrTextureType::k2D, GrRenderable::kNo,
180cb93a386Sopenharmony_ci                                        numSamples, GrMipmapped::kNo, budgeted, GrProtected::kNo);
181cb93a386Sopenharmony_ci                            }
182cb93a386Sopenharmony_ci
183cb93a386Sopenharmony_ci                            sk_sp<GrTextureProxy> proxy(proxyProvider->createProxy(
184cb93a386Sopenharmony_ci                                    format, dims, GrRenderable::kNo, numSamples, GrMipmapped::kNo,
185cb93a386Sopenharmony_ci                                    fit, budgeted, GrProtected::kNo));
186cb93a386Sopenharmony_ci                            REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
187cb93a386Sopenharmony_ci                            if (proxy) {
188cb93a386Sopenharmony_ci                                // This forces the proxy to compute and cache its
189cb93a386Sopenharmony_ci                                // pre-instantiation size guess. Later, when it is actually
190cb93a386Sopenharmony_ci                                // instantiated, it checks that the instantiated size is <= to
191cb93a386Sopenharmony_ci                                // the pre-computation. If the proxy never computed its
192cb93a386Sopenharmony_ci                                // pre-instantiation size then the check is skipped.
193cb93a386Sopenharmony_ci                                proxy->gpuMemorySize();
194cb93a386Sopenharmony_ci
195cb93a386Sopenharmony_ci                                check_surface(reporter, proxy.get(), widthHeight, widthHeight,
196cb93a386Sopenharmony_ci                                              budgeted);
197cb93a386Sopenharmony_ci                                check_texture(reporter, resourceProvider, proxy->asTextureProxy(),
198cb93a386Sopenharmony_ci                                              fit);
199cb93a386Sopenharmony_ci                            }
200cb93a386Sopenharmony_ci                        }
201cb93a386Sopenharmony_ci
202cb93a386Sopenharmony_ci                        attempt++;
203cb93a386Sopenharmony_ci                    }
204cb93a386Sopenharmony_ci                }
205cb93a386Sopenharmony_ci            }
206cb93a386Sopenharmony_ci        }
207cb93a386Sopenharmony_ci    }
208cb93a386Sopenharmony_ci}
209cb93a386Sopenharmony_ci
210cb93a386Sopenharmony_ciDEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
211cb93a386Sopenharmony_ci    auto direct = ctxInfo.directContext();
212cb93a386Sopenharmony_ci    GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
213cb93a386Sopenharmony_ci    GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
214cb93a386Sopenharmony_ci    GrGpu* gpu = direct->priv().getGpu();
215cb93a386Sopenharmony_ci    const GrCaps& caps = *direct->priv().caps();
216cb93a386Sopenharmony_ci
217cb93a386Sopenharmony_ci    static const int kWidthHeight = 100;
218cb93a386Sopenharmony_ci
219cb93a386Sopenharmony_ci    for (auto colorType :
220cb93a386Sopenharmony_ci         {kAlpha_8_SkColorType, kRGBA_8888_SkColorType, kRGBA_1010102_SkColorType}) {
221cb93a386Sopenharmony_ci        GrColorType grColorType = SkColorTypeToGrColorType(colorType);
222cb93a386Sopenharmony_ci
223cb93a386Sopenharmony_ci        // External on-screen render target.
224cb93a386Sopenharmony_ci        // Tests wrapBackendRenderTarget with a GrBackendRenderTarget
225cb93a386Sopenharmony_ci        // Our test-only function that creates a backend render target doesn't currently support
226cb93a386Sopenharmony_ci        // sample counts :(.
227cb93a386Sopenharmony_ci        if (direct->colorTypeSupportedAsSurface(colorType)) {
228cb93a386Sopenharmony_ci            GrBackendRenderTarget backendRT = gpu->createTestingOnlyBackendRenderTarget(
229cb93a386Sopenharmony_ci                    {kWidthHeight, kWidthHeight}, grColorType);
230cb93a386Sopenharmony_ci            sk_sp<GrSurfaceProxy> sProxy(
231cb93a386Sopenharmony_ci                    proxyProvider->wrapBackendRenderTarget(backendRT, nullptr));
232cb93a386Sopenharmony_ci            check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo);
233cb93a386Sopenharmony_ci            static constexpr int kExpectedNumSamples = 1;
234cb93a386Sopenharmony_ci            check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
235cb93a386Sopenharmony_ci                               kExpectedNumSamples, SkBackingFit::kExact,
236cb93a386Sopenharmony_ci                               caps.maxWindowRectangles());
237cb93a386Sopenharmony_ci            gpu->deleteTestingOnlyBackendRenderTarget(backendRT);
238cb93a386Sopenharmony_ci        }
239cb93a386Sopenharmony_ci
240cb93a386Sopenharmony_ci        for (auto numSamples : {1, 4}) {
241cb93a386Sopenharmony_ci            auto beFormat = caps.getDefaultBackendFormat(grColorType, GrRenderable::kYes);
242cb93a386Sopenharmony_ci            int supportedNumSamples = caps.getRenderTargetSampleCount(numSamples, beFormat);
243cb93a386Sopenharmony_ci            if (!supportedNumSamples) {
244cb93a386Sopenharmony_ci                continue;
245cb93a386Sopenharmony_ci            }
246cb93a386Sopenharmony_ci
247cb93a386Sopenharmony_ci#ifdef SK_GL
248cb93a386Sopenharmony_ci            // Test wrapping FBO 0 (with made up properties). This tests sample count and the
249cb93a386Sopenharmony_ci            // special case where FBO 0 doesn't support window rectangles.
250cb93a386Sopenharmony_ci            if (GrBackendApi::kOpenGL == ctxInfo.backend()) {
251cb93a386Sopenharmony_ci                GrGLFramebufferInfo fboInfo;
252cb93a386Sopenharmony_ci                fboInfo.fFBOID = 0;
253cb93a386Sopenharmony_ci                fboInfo.fFormat = GrGLFormatToEnum(beFormat.asGLFormat());
254cb93a386Sopenharmony_ci                SkASSERT(fboInfo.fFormat);
255cb93a386Sopenharmony_ci                static constexpr int kStencilBits = 8;
256cb93a386Sopenharmony_ci                GrBackendRenderTarget backendRT(kWidthHeight, kWidthHeight, numSamples,
257cb93a386Sopenharmony_ci                                                kStencilBits, fboInfo);
258cb93a386Sopenharmony_ci                sk_sp<GrSurfaceProxy> sProxy(
259cb93a386Sopenharmony_ci                        proxyProvider->wrapBackendRenderTarget(backendRT, nullptr));
260cb93a386Sopenharmony_ci                check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo);
261cb93a386Sopenharmony_ci                check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
262cb93a386Sopenharmony_ci                                   supportedNumSamples, SkBackingFit::kExact, 0);
263cb93a386Sopenharmony_ci            }
264cb93a386Sopenharmony_ci#endif
265cb93a386Sopenharmony_ci
266cb93a386Sopenharmony_ci            // Tests wrapBackendTexture that is only renderable
267cb93a386Sopenharmony_ci            {
268cb93a386Sopenharmony_ci                auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(direct,
269cb93a386Sopenharmony_ci                                                                                kWidthHeight,
270cb93a386Sopenharmony_ci                                                                                kWidthHeight,
271cb93a386Sopenharmony_ci                                                                                colorType,
272cb93a386Sopenharmony_ci                                                                                GrMipmapped::kNo,
273cb93a386Sopenharmony_ci                                                                                GrRenderable::kYes);
274cb93a386Sopenharmony_ci                if (!mbet) {
275cb93a386Sopenharmony_ci                    ERRORF(reporter,
276cb93a386Sopenharmony_ci                           "Could not create renderable backend texture of color type %d",
277cb93a386Sopenharmony_ci                           colorType);
278cb93a386Sopenharmony_ci                    continue;
279cb93a386Sopenharmony_ci                }
280cb93a386Sopenharmony_ci                sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapRenderableBackendTexture(
281cb93a386Sopenharmony_ci                        mbet->texture(), supportedNumSamples, kBorrow_GrWrapOwnership,
282cb93a386Sopenharmony_ci                        GrWrapCacheable::kNo, nullptr);
283cb93a386Sopenharmony_ci                if (!sProxy) {
284cb93a386Sopenharmony_ci                    ERRORF(reporter, "wrapRenderableBackendTexture failed");
285cb93a386Sopenharmony_ci                    continue;
286cb93a386Sopenharmony_ci                }
287cb93a386Sopenharmony_ci
288cb93a386Sopenharmony_ci                check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo);
289cb93a386Sopenharmony_ci                check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(),
290cb93a386Sopenharmony_ci                                   supportedNumSamples, SkBackingFit::kExact,
291cb93a386Sopenharmony_ci                                   caps.maxWindowRectangles());
292cb93a386Sopenharmony_ci            }
293cb93a386Sopenharmony_ci
294cb93a386Sopenharmony_ci            {
295cb93a386Sopenharmony_ci                // Tests wrapBackendTexture that is only textureable
296cb93a386Sopenharmony_ci                auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(direct,
297cb93a386Sopenharmony_ci                                                                                kWidthHeight,
298cb93a386Sopenharmony_ci                                                                                kWidthHeight,
299cb93a386Sopenharmony_ci                                                                                colorType,
300cb93a386Sopenharmony_ci                                                                                GrMipmapped::kNo,
301cb93a386Sopenharmony_ci                                                                                GrRenderable::kNo);
302cb93a386Sopenharmony_ci                if (!mbet) {
303cb93a386Sopenharmony_ci                    ERRORF(reporter,
304cb93a386Sopenharmony_ci                           "Could not create non-renderable backend texture of color type %d",
305cb93a386Sopenharmony_ci                           colorType);
306cb93a386Sopenharmony_ci                    continue;
307cb93a386Sopenharmony_ci                }
308cb93a386Sopenharmony_ci                sk_sp<GrSurfaceProxy> sProxy = proxyProvider->wrapBackendTexture(
309cb93a386Sopenharmony_ci                        mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
310cb93a386Sopenharmony_ci                        kRead_GrIOType, mbet->refCountedCallback());
311cb93a386Sopenharmony_ci                if (!sProxy) {
312cb93a386Sopenharmony_ci                    ERRORF(reporter, "wrapBackendTexture failed");
313cb93a386Sopenharmony_ci                    continue;
314cb93a386Sopenharmony_ci                }
315cb93a386Sopenharmony_ci
316cb93a386Sopenharmony_ci                check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo);
317cb93a386Sopenharmony_ci                check_texture(reporter, resourceProvider, sProxy->asTextureProxy(),
318cb93a386Sopenharmony_ci                              SkBackingFit::kExact);
319cb93a386Sopenharmony_ci            }
320cb93a386Sopenharmony_ci        }
321cb93a386Sopenharmony_ci    }
322cb93a386Sopenharmony_ci}
323cb93a386Sopenharmony_ci
324cb93a386Sopenharmony_ciDEF_GPUTEST_FOR_RENDERING_CONTEXTS(ZeroSizedProxyTest, reporter, ctxInfo) {
325cb93a386Sopenharmony_ci    auto direct = ctxInfo.directContext();
326cb93a386Sopenharmony_ci    GrProxyProvider* provider = direct->priv().proxyProvider();
327cb93a386Sopenharmony_ci
328cb93a386Sopenharmony_ci    for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
329cb93a386Sopenharmony_ci        for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
330cb93a386Sopenharmony_ci            for (int width : { 0, 100 }) {
331cb93a386Sopenharmony_ci                for (int height : { 0, 100}) {
332cb93a386Sopenharmony_ci                    if (width && height) {
333cb93a386Sopenharmony_ci                        continue; // not zero-sized
334cb93a386Sopenharmony_ci                    }
335cb93a386Sopenharmony_ci
336cb93a386Sopenharmony_ci                    const GrBackendFormat format =
337cb93a386Sopenharmony_ci                            direct->priv().caps()->getDefaultBackendFormat(
338cb93a386Sopenharmony_ci                                GrColorType::kRGBA_8888,
339cb93a386Sopenharmony_ci                                renderable);
340cb93a386Sopenharmony_ci
341cb93a386Sopenharmony_ci                    sk_sp<GrTextureProxy> proxy = provider->createProxy(
342cb93a386Sopenharmony_ci                            format, {width, height}, renderable, 1, GrMipmapped::kNo, fit,
343cb93a386Sopenharmony_ci                            SkBudgeted::kNo, GrProtected::kNo);
344cb93a386Sopenharmony_ci                    REPORTER_ASSERT(reporter, !proxy);
345cb93a386Sopenharmony_ci                }
346cb93a386Sopenharmony_ci            }
347cb93a386Sopenharmony_ci        }
348cb93a386Sopenharmony_ci    }
349cb93a386Sopenharmony_ci}
350