blob: 5a69e53474a75e2efdde18016bc6b5e7443f879a [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"
15#include "GrTexture.h"
bsalomonafbf2d62014-09-30 12:18:44 -070016#include "GrSurfacePriv.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000017#include "Test.h"
bsalomon@google.com686bcb82013-04-09 15:04:12 +000018
bsalomona2c23232014-11-25 07:41:12 -080019// Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture
20// and render targets to GrSurface all work as expected.
bsalomon758586c2016-04-06 14:02:39 -070021DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -070022 GrContext* context = ctxInfo.grContext();
kkinnunen15302832015-12-01 04:35:26 -080023 GrSurfaceDesc desc;
Brian Osman777b5632016-10-14 09:16:21 -040024 desc.fConfig = kRGBA_8888_GrPixelConfig;
kkinnunen15302832015-12-01 04:35:26 -080025 desc.fFlags = kRenderTarget_GrSurfaceFlag;
26 desc.fWidth = 256;
27 desc.fHeight = 256;
28 desc.fSampleCnt = 0;
bsalomon5ec26ae2016-02-25 08:33:02 -080029 GrSurface* texRT1 = context->textureProvider()->createTexture(
30 desc, SkBudgeted::kNo, nullptr, 0);
bsalomona2c23232014-11-25 07:41:12 -080031
kkinnunen15302832015-12-01 04:35:26 -080032 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()));
bsalomona2c23232014-11-25 07:41:12 -080040
kkinnunen15302832015-12-01 04:35:26 -080041 desc.fFlags = kNone_GrSurfaceFlags;
bsalomon5ec26ae2016-02-25 08:33:02 -080042 GrSurface* tex1 = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0);
kkinnunen15302832015-12-01 04:35:26 -080043 REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
44 REPORTER_ASSERT(reporter, tex1 == tex1->asTexture());
45 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture());
bsalomon@google.com686bcb82013-04-09 15:04:12 +000046
kkinnunen15302832015-12-01 04:35:26 -080047 GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture(
Brian Osman777b5632016-10-14 09:16:21 -040048 nullptr, 256, 256, kRGBA_8888_GrPixelConfig);
bsalomon091f60c2015-11-10 11:54:56 -080049
kkinnunen15302832015-12-01 04:35:26 -080050 GrBackendTextureDesc backendDesc;
Brian Osman777b5632016-10-14 09:16:21 -040051 backendDesc.fConfig = kRGBA_8888_GrPixelConfig;
kkinnunen15302832015-12-01 04:35:26 -080052 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
53 backendDesc.fWidth = 256;
54 backendDesc.fHeight = 256;
55 backendDesc.fSampleCnt = 0;
56 backendDesc.fTextureHandle = backendTex;
bungeman6bd52842016-10-27 09:30:08 -070057 sk_sp<GrSurface> texRT2 = context->textureProvider()->wrapBackendTexture(
kkinnunen15302832015-12-01 04:35:26 -080058 backendDesc, kBorrow_GrWrapOwnership);
bungeman6bd52842016-10-27 09:30:08 -070059 REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget());
60 REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture());
kkinnunen15302832015-12-01 04:35:26 -080061 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
62 texRT2->asTexture());
63 REPORTER_ASSERT(reporter, texRT2->asRenderTarget() ==
64 static_cast<GrSurface*>(texRT2->asTexture()));
65 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
66 static_cast<GrSurface*>(texRT2->asTexture()));
bsalomon@google.com686bcb82013-04-09 15:04:12 +000067
kkinnunen15302832015-12-01 04:35:26 -080068 texRT1->unref();
kkinnunen15302832015-12-01 04:35:26 -080069 tex1->unref();
70 context->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
bsalomon@google.com686bcb82013-04-09 15:04:12 +000071}
72
bsalomon@google.com686bcb82013-04-09 15:04:12 +000073#endif