blob: 4b7dbd30de31642c520a7d27928ffd5723a144c0 [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.
kkinnunen15302832015-12-01 04:35:26 -080021DEF_GPUTEST_FOR_NULL_CONTEXT(GrSurface, reporter, context) {
22 GrSurfaceDesc desc;
23 desc.fConfig = kSkia8888_GrPixelConfig;
24 desc.fFlags = kRenderTarget_GrSurfaceFlag;
25 desc.fWidth = 256;
26 desc.fHeight = 256;
27 desc.fSampleCnt = 0;
28 GrSurface* texRT1 = context->textureProvider()->createTexture(desc, false, nullptr, 0);
bsalomona2c23232014-11-25 07:41:12 -080029
kkinnunen15302832015-12-01 04:35:26 -080030 REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget());
31 REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture());
32 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
33 texRT1->asTexture());
34 REPORTER_ASSERT(reporter, texRT1->asRenderTarget() ==
35 static_cast<GrSurface*>(texRT1->asTexture()));
36 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT1->asRenderTarget()) ==
37 static_cast<GrSurface*>(texRT1->asTexture()));
bsalomona2c23232014-11-25 07:41:12 -080038
kkinnunen15302832015-12-01 04:35:26 -080039 desc.fFlags = kNone_GrSurfaceFlags;
40 GrSurface* tex1 = context->textureProvider()->createTexture(desc, false, nullptr, 0);
41 REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
42 REPORTER_ASSERT(reporter, tex1 == tex1->asTexture());
43 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture());
bsalomon@google.com686bcb82013-04-09 15:04:12 +000044
kkinnunen15302832015-12-01 04:35:26 -080045 GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture(
46 nullptr, 256, 256, kSkia8888_GrPixelConfig);
bsalomon091f60c2015-11-10 11:54:56 -080047
kkinnunen15302832015-12-01 04:35:26 -080048 GrBackendTextureDesc backendDesc;
49 backendDesc.fConfig = kSkia8888_GrPixelConfig;
50 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
51 backendDesc.fWidth = 256;
52 backendDesc.fHeight = 256;
53 backendDesc.fSampleCnt = 0;
54 backendDesc.fTextureHandle = backendTex;
55 GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture(
56 backendDesc, kBorrow_GrWrapOwnership);
57 REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget());
58 REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture());
59 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
60 texRT2->asTexture());
61 REPORTER_ASSERT(reporter, texRT2->asRenderTarget() ==
62 static_cast<GrSurface*>(texRT2->asTexture()));
63 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
64 static_cast<GrSurface*>(texRT2->asTexture()));
bsalomon@google.com686bcb82013-04-09 15:04:12 +000065
kkinnunen15302832015-12-01 04:35:26 -080066 texRT1->unref();
67 texRT2->unref();
68 tex1->unref();
69 context->getGpu()->deleteTestingOnlyBackendTexture(backendTex);
bsalomon@google.com686bcb82013-04-09 15:04:12 +000070}
71
bsalomon@google.com686bcb82013-04-09 15:04:12 +000072#endif