blob: e61b934a71fc8d790ca9cfd34232bcf7ba249e88 [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;
24 desc.fConfig = kSkia8888_GrPixelConfig;
25 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(
48 nullptr, 256, 256, kSkia8888_GrPixelConfig);
bsalomon091f60c2015-11-10 11:54:56 -080049
kkinnunen15302832015-12-01 04:35:26 -080050 GrBackendTextureDesc backendDesc;
51 backendDesc.fConfig = kSkia8888_GrPixelConfig;
52 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
53 backendDesc.fWidth = 256;
54 backendDesc.fHeight = 256;
55 backendDesc.fSampleCnt = 0;
56 backendDesc.fTextureHandle = backendTex;
57 GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture(
58 backendDesc, kBorrow_GrWrapOwnership);
59 REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget());
60 REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture());
61 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();
69 texRT2->unref();
70 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