176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips/*
276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips * Copyright 2016 Google Inc.
376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips *
476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips * Use of this source code is governed by a BSD-style license that can be
576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips * found in the LICENSE file.
676948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips */
776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips// This is a GPU-backend specific test.
976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
1076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips#include "Test.h"
1176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
1276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips#if SK_SUPPORT_GPU
13c7635fa374b87711e5ccd8222957a8fbdc772f7bRobert Phillips#include "GrRenderTargetPriv.h"
1476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips#include "GrRenderTargetProxy.h"
1532342f032e1dfd133040324f851f0365f9d4cb51Brian Osman#include "GrResourceProvider.h"
1632342f032e1dfd133040324f851f0365f9d4cb51Brian Osman#include "GrSurfaceProxy.h"
1732342f032e1dfd133040324f851f0365f9d4cb51Brian Osman#include "GrTextureProxy.h"
1876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
198abb370aca280516f4861c6c942ec453aad018farobertphillips// Check that the surface proxy's member vars are set as expected
2076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillipsstatic void check_surface(skiatest::Reporter* reporter,
2176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                          GrSurfaceProxy* proxy,
2276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                          GrSurfaceOrigin origin,
2376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                          int width, int height,
248abb370aca280516f4861c6c942ec453aad018farobertphillips                          GrPixelConfig config,
25294870ff119b89fc902773643b054f14e5d1f554Robert Phillips                          const GrGpuResource::UniqueID& uniqueID,
26abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                          SkBudgeted budgeted) {
2776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, proxy->origin() == origin);
2876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, proxy->width() == width);
2976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, proxy->height() == height);
3076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, proxy->config() == config);
31294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    if (!uniqueID.isInvalid()) {
32294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        REPORTER_ASSERT(reporter, proxy->uniqueID().asUInt() == uniqueID.asUInt());
33294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    } else {
34294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
358abb370aca280516f4861c6c942ec453aad018farobertphillips    }
36abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips    REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
3776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips}
3876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
3976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillipsstatic void check_rendertarget(skiatest::Reporter* reporter,
40ec2249fc73b36621af9efd4a9fc62e1be84b784dRobert Phillips                               const GrCaps& caps,
4132342f032e1dfd133040324f851f0365f9d4cb51Brian Osman                               GrResourceProvider* provider,
4276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                               GrRenderTargetProxy* rtProxy,
43abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                               int numSamples,
44ec2249fc73b36621af9efd4a9fc62e1be84b784dRobert Phillips                               SkBackingFit fit,
45294870ff119b89fc902773643b054f14e5d1f554Robert Phillips                               int expectedMaxWindowRects,
46294870ff119b89fc902773643b054f14e5d1f554Robert Phillips                               bool wasWrapped) {
47ec2249fc73b36621af9efd4a9fc62e1be84b784dRobert Phillips    REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
48abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips    REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
49abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips
50294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
5176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    GrRenderTarget* rt = rtProxy->instantiate(provider);
5276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, rt);
5376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
54294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
55294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    if (wasWrapped) {
56294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        // Wrapped resources share their uniqueID with the wrapping RenderTargetProxy
57294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
58294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    } else {
59294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        // Deferred resources should always have a different ID from their instantiated rendertarget
60294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
61294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    }
62294870ff119b89fc902773643b054f14e5d1f554Robert Phillips
6376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
6476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    if (SkBackingFit::kExact == fit) {
6576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
6676948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
6776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    } else {
6876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
69294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
7076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    }
7176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
7276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
7376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, rt->isUnifiedMultisampled() == rtProxy->isUnifiedMultisampled());
7476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, rt->isStencilBufferMultisampled() ==
7576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                              rtProxy->isStencilBufferMultisampled());
7676948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, rt->numColorSamples() == rtProxy->numColorSamples());
7776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, rt->numStencilSamples() == rtProxy->numStencilSamples());
78f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton    REPORTER_ASSERT(reporter, rt->isMixedSampled() == rtProxy->isMixedSampled());
79f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton    REPORTER_ASSERT(reporter, rt->renderTargetPriv().flags() == rtProxy->testingOnly_getFlags());
8076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips}
8176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
8276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillipsstatic void check_texture(skiatest::Reporter* reporter,
8332342f032e1dfd133040324f851f0365f9d4cb51Brian Osman                          GrResourceProvider* provider,
8476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                          GrTextureProxy* texProxy,
85294870ff119b89fc902773643b054f14e5d1f554Robert Phillips                          SkBackingFit fit,
86294870ff119b89fc902773643b054f14e5d1f554Robert Phillips                          bool wasWrapped) {
87294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
8876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    GrTexture* tex = texProxy->instantiate(provider);
8976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, tex);
9076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
91294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
92294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    if (wasWrapped) {
93294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        // Wrapped resources share their uniqueID with the wrapping TextureProxy
94294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
95294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    } else {
96294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        // Deferred resources should always have a different ID from their instantiated texture
97294870ff119b89fc902773643b054f14e5d1f554Robert Phillips        REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
98294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    }
99294870ff119b89fc902773643b054f14e5d1f554Robert Phillips
10076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
10176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    if (SkBackingFit::kExact == fit) {
10276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
10376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
10476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    } else {
10576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
10676948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
10776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    }
10876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
10976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips}
11076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
11176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
1128abb370aca280516f4861c6c942ec453aad018farobertphillipsDEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
11332342f032e1dfd133040324f851f0365f9d4cb51Brian Osman    GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider();
114abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips    const GrCaps& caps = *ctxInfo.grContext()->caps();
11576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
116294870ff119b89fc902773643b054f14e5d1f554Robert Phillips    const GrGpuResource::UniqueID kInvalidResourceID = GrGpuResource::UniqueID::InvalidID();
117294870ff119b89fc902773643b054f14e5d1f554Robert Phillips
1186520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips    int attempt = 0; // useful for debugging
1196520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips
12076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
12140d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips        for (auto widthHeight : { 100, 128, 1048576 }) {
1226520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips            for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig,
1236520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                 kETC1_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
12476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
12576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
1266520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                        for (auto numSamples : { 0, 4, 16, 128 }) {
12776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                            GrSurfaceDesc desc;
12884a812061f1d16aa6d349ca065bf67d06767bbc2Robert Phillips                            desc.fFlags = kRenderTarget_GrSurfaceFlag;
12976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                            desc.fOrigin = origin;
13076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                            desc.fWidth = widthHeight;
13176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                            desc.fHeight = widthHeight;
13276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                            desc.fConfig = config;
13376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                            desc.fSampleCnt = numSamples;
13476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
1356520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                            {
1366520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                sk_sp<GrTexture> tex;
1376520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                if (SkBackingFit::kApprox == fit) {
13832342f032e1dfd133040324f851f0365f9d4cb51Brian Osman                                    tex.reset(provider->createApproxTexture(desc, 0));
1396520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                } else {
1405c446570ed3cefd854607c77226a6faa17cf18d7Robert Phillips                                    tex.reset(provider->createTexture(desc, budgeted));
1416520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                }
1426520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips
1432f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(
14426c90e04797e15c37ec00e0f836292b8a207d294Robert Phillips                                                                                provider, desc,
145abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                                                                                fit, budgeted));
1462f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
1472f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                if (proxy) {
1482f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                    REPORTER_ASSERT(reporter, proxy->asRenderTargetProxy());
14940d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                    // This forces the proxy to compute and cache its
15040d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                    // pre-instantiation size guess. Later, when it is actually
15140d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                    // instantiated, it checks that the instantiated size is <= to
15240d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                    // the pre-computation. If the proxy never computed its
15340d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                    // pre-instantiation size then the check is skipped.
1542f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                    proxy->gpuMemorySize();
15540d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips
1562f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                    check_surface(reporter, proxy.get(), origin,
15740d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                                  widthHeight, widthHeight, config,
15840d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                                  kInvalidResourceID, budgeted);
15940d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                    check_rendertarget(reporter, caps, provider,
1602f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                                       proxy->asRenderTargetProxy(),
1616520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                                       SkTMin(numSamples, caps.maxSampleCount()),
16240d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                                       fit, caps.maxWindowRectangles(), false);
16340d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                                }
16476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                            }
16576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
16684a812061f1d16aa6d349ca065bf67d06767bbc2Robert Phillips                            desc.fFlags = kNone_GrSurfaceFlags;
1676520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips
1686520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                            {
1696520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                sk_sp<GrTexture> tex;
1706520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                if (SkBackingFit::kApprox == fit) {
17132342f032e1dfd133040324f851f0365f9d4cb51Brian Osman                                    tex.reset(provider->createApproxTexture(desc, 0));
1726520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                } else {
1735c446570ed3cefd854607c77226a6faa17cf18d7Robert Phillips                                    tex.reset(provider->createTexture(desc, budgeted));
1746520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                }
1756520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips
1762f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeDeferred(provider,
17726c90e04797e15c37ec00e0f836292b8a207d294Robert Phillips                                                                                         desc,
17826c90e04797e15c37ec00e0f836292b8a207d294Robert Phillips                                                                                         fit,
17926c90e04797e15c37ec00e0f836292b8a207d294Robert Phillips                                                                                         budgeted));
1802f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(proxy));
1812f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                if (proxy) {
1826520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                    // This forces the proxy to compute and cache its pre-instantiation
1836520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                    // size guess. Later, when it is actually instantiated, it checks
1846520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                    // that the instantiated size is <= to the pre-computation.
1856520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                    // If the proxy never computed its pre-instantiation size then the
1866520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                    // check is skipped.
1872f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                    proxy->gpuMemorySize();
1886520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips
1892f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                    check_surface(reporter, proxy.get(), origin,
1906520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                                  widthHeight, widthHeight, config,
1916520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                                  kInvalidResourceID, budgeted);
1922f49314227053dd5acc011e04681faee05c5e0ffRobert Phillips                                    check_texture(reporter, provider, proxy->asTextureProxy(),
1936520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                                  fit, false);
1946520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                                }
19540d9495a1f50707bf3696b9a573aa7bc29edf87aRobert Phillips                            }
1966520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips
1976520a69e6455afe371d647e033aa3ae5dabf6010Robert Phillips                            attempt++;
19876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                        }
19976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    }
20076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                }
20176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips            }
20276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        }
20376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    }
20476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips}
20576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
206ab527a5bbfb1eae4f99a1435d349a44d00477d82egdanielDEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
20732342f032e1dfd133040324f851f0365f9d4cb51Brian Osman    GrResourceProvider* provider = ctxInfo.grContext()->resourceProvider();
208f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton    const GrCaps& caps = *ctxInfo.grContext()->caps();
20976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
21076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    static const int kWidthHeight = 100;
21176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
21276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
21376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
21476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips            for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
21576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                for (auto numSamples: { 0, 4}) {
216f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                    bool renderable = caps.isConfigRenderable(config, numSamples > 0);
21776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
21876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    GrSurfaceDesc desc;
21976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    desc.fOrigin = origin;
22076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    desc.fWidth = kWidthHeight;
22176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    desc.fHeight = kWidthHeight;
22276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    desc.fConfig = config;
22376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    desc.fSampleCnt = numSamples;
22476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
225f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                    // External on-screen render target.
226f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                    if (renderable && kOpenGL_GrBackend == ctxInfo.backend()) {
227f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        GrBackendRenderTargetDesc backendDesc;
228f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        backendDesc.fWidth = kWidthHeight;
229f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        backendDesc.fHeight = kWidthHeight;
230f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        backendDesc.fConfig = config;
231f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        backendDesc.fOrigin = origin;
232f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        backendDesc.fSampleCnt = numSamples;
233f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        backendDesc.fStencilBits = 8;
234f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        backendDesc.fRenderTargetHandle = 0;
235f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton
236f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                        sk_sp<GrRenderTarget> defaultFBO(
237abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                            provider->wrapBackendRenderTarget(backendDesc));
238f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton
2393743013f755d23c215d852af7d829c3cd74f34a2Robert Phillips                        sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO));
2403743013f755d23c215d852af7d829c3cd74f34a2Robert Phillips                        check_surface(reporter, sProxy.get(), origin,
241abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                                      kWidthHeight, kWidthHeight, config,
242abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                                      defaultFBO->uniqueID(), SkBudgeted::kNo);
243ec2249fc73b36621af9efd4a9fc62e1be84b784dRobert Phillips                        check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
244294870ff119b89fc902773643b054f14e5d1f554Robert Phillips                                           numSamples, SkBackingFit::kExact, 0, true);
245f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                    }
246f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton
24776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    sk_sp<GrTexture> tex;
24876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
249f9635999a4aa8810d04e8ef04594a9fbcc061e3dcsmartdalton                    // Internal offscreen render target.
25076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    if (renderable) {
25176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                        desc.fFlags = kRenderTarget_GrSurfaceFlag;
25276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                        tex.reset(provider->createTexture(desc, budgeted));
25376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                        sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
25476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
2553743013f755d23c215d852af7d829c3cd74f34a2Robert Phillips                        sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(rt));
2563743013f755d23c215d852af7d829c3cd74f34a2Robert Phillips                        check_surface(reporter, sProxy.get(), origin,
257abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                                      kWidthHeight, kWidthHeight, config,
258abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                                      rt->uniqueID(), budgeted);
259ec2249fc73b36621af9efd4a9fc62e1be84b784dRobert Phillips                        check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
260ec2249fc73b36621af9efd4a9fc62e1be84b784dRobert Phillips                                           numSamples, SkBackingFit::kExact,
261294870ff119b89fc902773643b054f14e5d1f554Robert Phillips                                           caps.maxWindowRectangles(), true);
26276948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    }
26376948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
26476948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    if (!tex) {
26576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                        SkASSERT(kNone_GrSurfaceFlags == desc.fFlags );
26676948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                        desc.fSampleCnt = 0;
26776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                        tex.reset(provider->createTexture(desc, budgeted));
26876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                    }
26976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
2703743013f755d23c215d852af7d829c3cd74f34a2Robert Phillips                    sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(tex));
2713743013f755d23c215d852af7d829c3cd74f34a2Robert Phillips                    check_surface(reporter, sProxy.get(), origin,
272abacf0978fc06f88278d073655dff6ff8503a612Robert Phillips                                  kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted);
2733743013f755d23c215d852af7d829c3cd74f34a2Robert Phillips                    check_texture(reporter, provider, sProxy->asTextureProxy(),
274294870ff119b89fc902773643b054f14e5d1f554Robert Phillips                                  SkBackingFit::kExact, true);
27576948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips                }
27676948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips            }
27776948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips        }
27876948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips    }
27976948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips}
28076948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips
28176948d4faaca9fd7730576e2f79790ca8d93c10brobertphillips#endif
282