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" |
| 13 | #include "GrContextFactory.h" |
| 14 | #include "GrRenderTarget.h" |
| 15 | #include "GrTexture.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 16 | #include "GrSurfacePriv.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 17 | #include "Test.h" |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 18 | |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 19 | // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture |
| 20 | // and render targets to GrSurface all work as expected. |
tfarina | 9ea53f9 | 2014-06-24 06:50:39 -0700 | [diff] [blame] | 21 | DEF_GPUTEST(GrSurface, reporter, factory) { |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 22 | GrContext* context = factory->get(GrContextFactory::kNull_GLContextType); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 23 | if (context) { |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 24 | GrSurfaceDesc desc; |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 25 | desc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 26 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 27 | desc.fWidth = 256; |
| 28 | desc.fHeight = 256; |
| 29 | desc.fSampleCnt = 0; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 30 | GrSurface* texRT1 = context->textureProvider()->createTexture(desc, false, NULL, 0); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 31 | |
| 32 | REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget()); |
| 33 | REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture()); |
| 34 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 35 | texRT1->asTexture()); |
| 36 | REPORTER_ASSERT(reporter, texRT1->asRenderTarget() == |
| 37 | static_cast<GrSurface*>(texRT1->asTexture())); |
| 38 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) == |
| 39 | static_cast<GrSurface*>(texRT1->asTexture())); |
| 40 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 41 | desc.fFlags = kNone_GrSurfaceFlags; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 42 | GrSurface* tex1 = context->textureProvider()->createTexture(desc, false, NULL, 0); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 43 | REPORTER_ASSERT(reporter, NULL == tex1->asRenderTarget()); |
| 44 | REPORTER_ASSERT(reporter, tex1 == tex1->asTexture()); |
| 45 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture()); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 46 | |
| 47 | GrBackendTextureDesc backendDesc; |
| 48 | backendDesc.fConfig = kSkia8888_GrPixelConfig; |
| 49 | backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 50 | backendDesc.fWidth = 256; |
| 51 | backendDesc.fHeight = 256; |
| 52 | backendDesc.fSampleCnt = 0; |
| 53 | backendDesc.fTextureHandle = 5; |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 54 | GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture( |
| 55 | backendDesc, kBorrow_GrWrapOwnership); |
bsalomon | a2c2323 | 2014-11-25 07:41:12 -0800 | [diff] [blame] | 56 | REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget()); |
| 57 | REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture()); |
| 58 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 59 | texRT2->asTexture()); |
| 60 | REPORTER_ASSERT(reporter, texRT2->asRenderTarget() == |
| 61 | static_cast<GrSurface*>(texRT2->asTexture())); |
| 62 | REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == |
| 63 | static_cast<GrSurface*>(texRT2->asTexture())); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 64 | |
| 65 | texRT1->unref(); |
| 66 | texRT2->unref(); |
| 67 | tex1->unref(); |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
bsalomon@google.com | 686bcb8 | 2013-04-09 15:04:12 +0000 | [diff] [blame] | 71 | #endif |