blob: 99c0becbefc37046391b44ac3f254328298343fb [file] [log] [blame]
bsalomon@google.com686bcb82013-04-09 15:04:12 +00001/*
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
bsalomona2c23232014-11-25 07:41:12 -08008#include "SkTypes.h"
9
bsalomon@google.com686bcb82013-04-09 15:04:12 +000010#if SK_SUPPORT_GPU
11
bsalomon@google.com686bcb82013-04-09 15:04:12 +000012#include "GrContext.h"
Greg Daniel7ef28f32017-04-20 16:41:55 +000013#include "GrContextPriv.h"
bsalomon091f60c2015-11-10 11:54:56 -080014#include "GrGpu.h"
bsalomon@google.com686bcb82013-04-09 15:04:12 +000015#include "GrRenderTarget.h"
Brian Osman32342f02017-03-04 08:12:46 -050016#include "GrResourceProvider.h"
Greg Daniel7ef28f32017-04-20 16:41:55 +000017#include "GrTest.h"
bsalomon@google.com686bcb82013-04-09 15:04:12 +000018#include "GrTexture.h"
bsalomonafbf2d62014-09-30 12:18:44 -070019#include "GrSurfacePriv.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000020#include "Test.h"
bsalomon@google.com686bcb82013-04-09 15:04:12 +000021
bsalomona2c23232014-11-25 07:41:12 -080022// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
23// and render targets to GrSurface all work as expected.
bsalomon758586c2016-04-06 14:02:39 -070024DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070025 GrContext* context = ctxInfo.grContext();
kkinnunen15302832015-12-01 04:35:26 -080026 GrSurfaceDesc desc;
Brian Osman777b5632016-10-14 09:16:21 -040027 desc.fConfig = kRGBA_8888_GrPixelConfig;
kkinnunen15302832015-12-01 04:35:26 -080028 desc.fFlags = kRenderTarget_GrSurfaceFlag;
29 desc.fWidth = 256;
30 desc.fHeight = 256;
31 desc.fSampleCnt = 0;
Robert Phillipse78b7252017-04-06 07:59:41 -040032 sk_sp<GrSurface> texRT1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo);
bsalomona2c23232014-11-25 07:41:12 -080033
Robert Phillipse78b7252017-04-06 07:59:41 -040034 REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget());
35 REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture());
kkinnunen15302832015-12-01 04:35:26 -080036 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()));
bsalomona2c23232014-11-25 07:41:12 -080042
kkinnunen15302832015-12-01 04:35:26 -080043 desc.fFlags = kNone_GrSurfaceFlags;
Robert Phillipse78b7252017-04-06 07:59:41 -040044 sk_sp<GrTexture> tex1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo);
kkinnunen15302832015-12-01 04:35:26 -080045 REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
Robert Phillipse78b7252017-04-06 07:59:41 -040046 REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture());
47 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1.get()) == tex1->asTexture());
bsalomon@google.com686bcb82013-04-09 15:04:12 +000048
Greg Daniel7ef28f32017-04-20 16:41:55 +000049 GrBackendObject backendTexHandle = context->getGpu()->createTestingOnlyBackendTexture(
Brian Osman777b5632016-10-14 09:16:21 -040050 nullptr, 256, 256, kRGBA_8888_GrPixelConfig);
Greg Daniel7ef28f32017-04-20 16:41:55 +000051 GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
52 256,
53 256,
54 kRGBA_8888_GrPixelConfig,
55 backendTexHandle);
bsalomon091f60c2015-11-10 11:54:56 -080056
Brian Osman32342f02017-03-04 08:12:46 -050057 sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapBackendTexture(
Greg Daniel7ef28f32017-04-20 16:41:55 +000058 backendTex, kTopLeft_GrSurfaceOrigin, kRenderTarget_GrBackendTextureFlag, 0,
59 kBorrow_GrWrapOwnership);
60
bungeman6bd52842016-10-27 09:30:08 -070061 REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
62 REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
kkinnunen15302832015-12-01 04:35:26 -080063 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.com686bcb82013-04-09 15:04:12 +000069
Greg Daniel7ef28f32017-04-20 16:41:55 +000070 context->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle);
bsalomon@google.com686bcb82013-04-09 15:04:12 +000071}
72
bsalomon@google.com686bcb82013-04-09 15:04:12 +000073#endif