blob: 685bf4187461f352c6bdca227f0e78326393ff6e [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"
13#include "GrContextFactory.h"
14#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.
tfarina9ea53f92014-06-24 06:50:39 -070021DEF_GPUTEST(GrSurface, reporter, factory) {
bsalomon@google.com686bcb82013-04-09 15:04:12 +000022 GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
bsalomon49f085d2014-09-05 13:34:00 -070023 if (context) {
bsalomonf2703d82014-10-28 14:33:06 -070024 GrSurfaceDesc desc;
bsalomon@google.com686bcb82013-04-09 15:04:12 +000025 desc.fConfig = kSkia8888_GrPixelConfig;
bsalomonf2703d82014-10-28 14:33:06 -070026 desc.fFlags = kRenderTarget_GrSurfaceFlag;
bsalomon@google.com686bcb82013-04-09 15:04:12 +000027 desc.fWidth = 256;
28 desc.fHeight = 256;
29 desc.fSampleCnt = 0;
bsalomond309e7a2015-04-30 14:18:54 -070030 GrSurface* texRT1 = context->textureProvider()->createTexture(desc, false, NULL, 0);
bsalomona2c23232014-11-25 07:41:12 -080031
32 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()));
40
bsalomonf2703d82014-10-28 14:33:06 -070041 desc.fFlags = kNone_GrSurfaceFlags;
bsalomond309e7a2015-04-30 14:18:54 -070042 GrSurface* tex1 = context->textureProvider()->createTexture(desc, false, NULL, 0);
bsalomona2c23232014-11-25 07:41:12 -080043 REPORTER_ASSERT(reporter, NULL == 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
47 GrBackendTextureDesc backendDesc;
48 backendDesc.fConfig = kSkia8888_GrPixelConfig;
49 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
50 backendDesc.fWidth = 256;
51 backendDesc.fHeight = 256;
52 backendDesc.fSampleCnt = 0;
53 backendDesc.fTextureHandle = 5;
bsalomond309e7a2015-04-30 14:18:54 -070054 GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture(backendDesc);
bsalomona2c23232014-11-25 07:41:12 -080055 REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget());
56 REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture());
57 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
58 texRT2->asTexture());
59 REPORTER_ASSERT(reporter, texRT2->asRenderTarget() ==
60 static_cast<GrSurface*>(texRT2->asTexture()));
61 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
62 static_cast<GrSurface*>(texRT2->asTexture()));
bsalomon@google.com686bcb82013-04-09 15:04:12 +000063
64 texRT1->unref();
65 texRT2->unref();
66 tex1->unref();
bsalomon@google.com686bcb82013-04-09 15:04:12 +000067 }
68}
69
bsalomon@google.com686bcb82013-04-09 15:04:12 +000070#endif