bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 8 | #include "SkTypes.h" |
| 9 | |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 10 | #if SK_SUPPORT_GPU |
| 11 | |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 13 | #include "GrContextPriv.h" |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 14 | #include "GrGpu.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 15 | #include "GrRenderTarget.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 16 | #include "GrResourceProvider.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 17 | #include "GrTest.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 18 | #include "GrTexture.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 19 | #include "GrSurfacePriv.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 20 | #include "Test.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 21 | |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 22 | // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture |
| 23 | // and render targets to GrSurface all work as expected. |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 24 | DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 25 | GrContext* context = ctxInfo.grContext(); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 26 | GrSurfaceDesc desc; |
Brian Osman | 777b563 | 2016-10-14 09:16:21 -0400 | [diff] [blame] | 27 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 28 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 29 | desc.fWidth = 256; |
| 30 | desc.fHeight = 256; |
| 31 | desc.fSampleCnt = 0; |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 32 | sk_sp<GrSurface> texRT1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 33 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 34 | REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget()); |
| 35 | REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 37 | texRT1->asTexture()); |
| 38 | REPORTER_ASSERT(reporter, texRT1->asRenderTarget() == |
| 39 | static_cast<GrSurface*>(texRT1->asTexture())); |
| 40 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 41 | static_cast<GrSurface*>(texRT1->asTexture())); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 42 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 43 | desc.fFlags = kNone_GrSurfaceFlags; |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 44 | sk_sp<GrTexture> tex1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 45 | REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget()); |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture()); |
| 47 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture()); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 48 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 49 | GrBackendObject backendTexHandle = context->getGpu()->createTestingOnlyBackendTexture( |
Brian Osman | 777b563 | 2016-10-14 09:16:21 -0400 | [diff] [blame] | 50 | nullptr, 256, 256, kRGBA_8888_GrPixelConfig); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 51 | GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), |
| 52 | 256, |
| 53 | 256, |
| 54 | kRGBA_8888_GrPixelConfig, |
| 55 | backendTexHandle); |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 56 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 57 | sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapBackendTexture( |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 58 | backendTex, kTopLeft_GrSurfaceOrigin, kRenderTarget_GrBackendTextureFlag, 0, |
| 59 | kBorrow_GrWrapOwnership); |
| 60 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget()); |
| 62 | REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 64 | texRT2->asTexture()); |
| 65 | REPORTER_ASSERT(reporter, texRT2->asRenderTarget() == |
| 66 | static_cast<GrSurface*>(texRT2->asTexture())); |
| 67 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 68 | static_cast<GrSurface*>(texRT2->asTexture())); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 69 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 70 | context->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame^] | 73 | #if 0 |
| 74 | // This test checks that the isConfigTexturable and isConfigRenderable are |
| 75 | // consistent with createTexture's result. |
| 76 | DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { |
| 77 | GrContext* context = ctxInfo.grContext(); |
| 78 | const GrCaps* caps = context->caps(); |
| 79 | |
| 80 | GrPixelConfig configs[] = { |
| 81 | kUnknown_GrPixelConfig, |
| 82 | kAlpha_8_GrPixelConfig, |
| 83 | kGray_8_GrPixelConfig, |
| 84 | kRGB_565_GrPixelConfig, |
| 85 | kRGBA_4444_GrPixelConfig, |
| 86 | kRGBA_8888_GrPixelConfig, |
| 87 | kBGRA_8888_GrPixelConfig, |
| 88 | kSRGBA_8888_GrPixelConfig, |
| 89 | kSBGRA_8888_GrPixelConfig, |
| 90 | kRGBA_8888_sint_GrPixelConfig, |
| 91 | kETC1_GrPixelConfig, |
| 92 | kRGBA_float_GrPixelConfig, |
| 93 | kRG_float_GrPixelConfig, |
| 94 | kAlpha_half_GrPixelConfig, |
| 95 | kRGBA_half_GrPixelConfig, |
| 96 | }; |
| 97 | SkASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs)); |
| 98 | |
| 99 | GrSurfaceDesc desc; |
| 100 | desc.fWidth = 64; |
| 101 | desc.fHeight = 64; |
| 102 | |
| 103 | for (GrPixelConfig config : configs) { |
| 104 | for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) { |
| 105 | desc.fFlags = kNone_GrSurfaceFlags; |
| 106 | desc.fOrigin = origin; |
| 107 | desc.fSampleCnt = 0; |
| 108 | desc.fConfig = config; |
| 109 | |
| 110 | sk_sp<GrSurface> tex = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo); |
| 111 | REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigTexturable(desc.fConfig, |
| 112 | desc.fOrigin)); |
| 113 | |
| 114 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 115 | tex = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo); |
| 116 | REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigRenderable(config, false)); |
| 117 | |
| 118 | desc.fSampleCnt = 4; |
| 119 | tex = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo); |
| 120 | REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigRenderable(config, true)); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | #endif |
| 125 | |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 126 | #endif |