blob: d98d0d042847e89a0870b25d3cce8899fa6865c0 [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"
bsalomon091f60c2015-11-10 11:54:56 -080013#include "GrGpu.h"
bsalomon@google.com686bcb82013-04-09 15:04:12 +000014#include "GrRenderTarget.h"
Brian Osman32342f02017-03-04 08:12:46 -050015#include "GrResourceProvider.h"
bsalomon@google.com686bcb82013-04-09 15:04:12 +000016#include "GrTexture.h"
bsalomonafbf2d62014-09-30 12:18:44 -070017#include "GrSurfacePriv.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000018#include "Test.h"
bsalomon@google.com686bcb82013-04-09 15:04:12 +000019
bsalomona2c23232014-11-25 07:41:12 -080020// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
21// and render targets to GrSurface all work as expected.
bsalomon758586c2016-04-06 14:02:39 -070022DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070023 GrContext* context = ctxInfo.grContext();
kkinnunen15302832015-12-01 04:35:26 -080024 GrSurfaceDesc desc;
Brian Osman777b5632016-10-14 09:16:21 -040025 desc.fConfig = kRGBA_8888_GrPixelConfig;
kkinnunen15302832015-12-01 04:35:26 -080026 desc.fFlags = kRenderTarget_GrSurfaceFlag;
27 desc.fWidth = 256;
28 desc.fHeight = 256;
29 desc.fSampleCnt = 0;
Brian Osman32342f02017-03-04 08:12:46 -050030 GrSurface* texRT1 = context->resourceProvider()->createTexture(
bsalomon5ec26ae2016-02-25 08:33:02 -080031 desc, SkBudgeted::kNo, nullptr, 0);
bsalomona2c23232014-11-25 07:41:12 -080032
kkinnunen15302832015-12-01 04:35:26 -080033 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()));
bsalomona2c23232014-11-25 07:41:12 -080041
kkinnunen15302832015-12-01 04:35:26 -080042 desc.fFlags = kNone_GrSurfaceFlags;
Brian Osman32342f02017-03-04 08:12:46 -050043 GrSurface* tex1 = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0);
kkinnunen15302832015-12-01 04:35:26 -080044 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.com686bcb82013-04-09 15:04:12 +000047
kkinnunen15302832015-12-01 04:35:26 -080048 GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture(
Brian Osman777b5632016-10-14 09:16:21 -040049 nullptr, 256, 256, kRGBA_8888_GrPixelConfig);
bsalomon091f60c2015-11-10 11:54:56 -080050
kkinnunen15302832015-12-01 04:35:26 -080051 GrBackendTextureDesc backendDesc;
Brian Osman777b5632016-10-14 09:16:21 -040052 backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
kkinnunen15302832015-12-01 04:35:26 -080053 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
54 backendDesc.fWidth = 256;
55 backendDesc.fHeight = 256;
56 backendDesc.fSampleCnt = 0;
57 backendDesc.fTextureHandle = backendTex;
Brian Osman32342f02017-03-04 08:12:46 -050058 sk_sp<GrSurface> texRT2 = context->resourceProvider()->wrapBackendTexture(
kkinnunen15302832015-12-01 04:35:26 -080059 backendDesc, kBorrow_GrWrapOwnership);
bungeman6bd52842016-10-27 09:30:08 -070060 REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
61 REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
kkinnunen15302832015-12-01 04:35:26 -080062 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.com686bcb82013-04-09 15:04:12 +000068
kkinnunen15302832015-12-01 04:35:26 -080069 texRT1->unref();
kkinnunen15302832015-12-01 04:35:26 -080070 tex1->unref();
71 context->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
bsalomon@google.com686bcb82013-04-09 15:04:12 +000072}
73
bsalomon@google.com686bcb82013-04-09 15:04:12 +000074#endif