blob: b9bb3192109714cbc9ee29bcaf9789a8916badb7 [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;
bsalomon6dc6f5f2015-06-18 09:12:16 -070054 GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture(
55 backendDesc, kBorrow_GrWrapOwnership);
bsalomona2c23232014-11-25 07:41:12 -080056 REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget());
57 REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture());
58 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
59 texRT2->asTexture());
60 REPORTER_ASSERT(reporter, texRT2->asRenderTarget() ==
61 static_cast<GrSurface*>(texRT2->asTexture()));
62 REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==
63 static_cast<GrSurface*>(texRT2->asTexture()));
bsalomon@google.com686bcb82013-04-09 15:04:12 +000064
65 texRT1->unref();
66 texRT2->unref();
67 tex1->unref();
bsalomon@google.com686bcb82013-04-09 15:04:12 +000068 }
69}
70
bsalomon@google.com686bcb82013-04-09 15:04:12 +000071#endif