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" |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 13 | #include "GrGpu.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 14 | #include "GrRenderTarget.h" |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 15 | #include "GrResourceProvider.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 16 | #include "GrTexture.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 17 | #include "GrSurfacePriv.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 18 | #include "Test.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 19 | |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 20 | // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture |
| 21 | // and render targets to GrSurface all work as expected. |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 22 | DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 23 | GrContext* context = ctxInfo.grContext(); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 24 | GrSurfaceDesc desc; |
Brian Osman | 777b563 | 2016-10-14 09:16:21 -0400 | [diff] [blame] | 25 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 26 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 27 | desc.fWidth = 256; |
| 28 | desc.fHeight = 256; |
| 29 | desc.fSampleCnt = 0; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 30 | GrSurface* texRT1 = context->resourceProvider()->createTexture( |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 31 | desc, SkBudgeted::kNo, nullptr, 0); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 32 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 33 | REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget()); |
| 34 | REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture()); |
| 35 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 36 | texRT1->asTexture()); |
| 37 | REPORTER_ASSERT(reporter, texRT1->asRenderTarget() == |
| 38 | static_cast<GrSurface*>(texRT1->asTexture())); |
| 39 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 40 | static_cast<GrSurface*>(texRT1->asTexture())); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 41 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 42 | desc.fFlags = kNone_GrSurfaceFlags; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 43 | GrSurface* tex1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget()); |
| 45 | REPORTER_ASSERT(reporter, tex1 == tex1->asTexture()); |
| 46 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture()); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 47 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 48 | GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture( |
Brian Osman | 777b563 | 2016-10-14 09:16:21 -0400 | [diff] [blame] | 49 | nullptr, 256, 256, kRGBA_8888_GrPixelConfig); |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 50 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 51 | GrBackendTextureDesc backendDesc; |
Brian Osman | 777b563 | 2016-10-14 09:16:21 -0400 | [diff] [blame] | 52 | backendDesc.fConfig = kRGBA_8888_GrPixelConfig; |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 53 | backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 54 | backendDesc.fWidth = 256; |
| 55 | backendDesc.fHeight = 256; |
| 56 | backendDesc.fSampleCnt = 0; |
| 57 | backendDesc.fTextureHandle = backendTex; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 58 | sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapBackendTexture( |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 59 | backendDesc, kBorrow_GrWrapOwnership); |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 60 | REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget()); |
| 61 | REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture()); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 62 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 63 | texRT2->asTexture()); |
| 64 | REPORTER_ASSERT(reporter, texRT2->asRenderTarget() == |
| 65 | static_cast<GrSurface*>(texRT2->asTexture())); |
| 66 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 67 | static_cast<GrSurface*>(texRT2->asTexture())); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 68 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 69 | texRT1->unref(); |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 70 | tex1->unref(); |
| 71 | context->getGpu()->deleteTestingOnlyBackendTexture(backendTex); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 72 | } |
| 73 | |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 74 | #endif |