blob: b73adc0b1ef96b664614ece74acf2dd2e6a87fcd [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
bsalomon@google.com686bcb82013-04-09 15:04:12 +00008#if SK_SUPPORT_GPU
9
bsalomon@google.com686bcb82013-04-09 15:04:12 +000010#include "GrContext.h"
11#include "GrContextFactory.h"
12#include "GrRenderTarget.h"
13#include "GrTexture.h"
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000014#include "SkTypes.h"
15#include "Test.h"
bsalomon@google.com686bcb82013-04-09 15:04:12 +000016
tfarina@chromium.org4ee16bf2014-01-10 22:08:27 +000017DEF_GPUTEST(GrSurfaceTest, reporter, factory) {
bsalomon@google.com686bcb82013-04-09 15:04:12 +000018 GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
19 if (NULL != context) {
20 GrTextureDesc desc;
21 desc.fConfig = kSkia8888_GrPixelConfig;
22 desc.fFlags = kRenderTarget_GrTextureFlagBit;
23 desc.fWidth = 256;
24 desc.fHeight = 256;
25 desc.fSampleCnt = 0;
26 GrSurface* texRT1 = context->createUncachedTexture(desc, NULL, 0);
27 GrSurface* texRT2 = context->createUncachedTexture(desc, NULL, 0);
28 desc.fFlags = kNone_GrTextureFlags;
29 GrSurface* tex1 = context->createUncachedTexture(desc, NULL, 0);
30
31 REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1));
32 REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1->asRenderTarget()));
33 REPORTER_ASSERT(reporter, texRT1->asRenderTarget()->isSameAs(texRT1));
34 REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1));
35 REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(texRT1));
36 REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1->asRenderTarget()));
37 REPORTER_ASSERT(reporter, !texRT2->isSameAs(tex1));
38 REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(tex1));
39
40 GrBackendTextureDesc backendDesc;
41 backendDesc.fConfig = kSkia8888_GrPixelConfig;
42 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
43 backendDesc.fWidth = 256;
44 backendDesc.fHeight = 256;
45 backendDesc.fSampleCnt = 0;
46 backendDesc.fTextureHandle = 5;
47 GrSurface* externalTexRT = context->wrapBackendTexture(backendDesc);
48 REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT));
49 REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT->asRenderTarget()));
50 REPORTER_ASSERT(reporter, externalTexRT->asRenderTarget()->isSameAs(externalTexRT));
51 REPORTER_ASSERT(reporter, !externalTexRT->isSameAs(texRT1));
52 REPORTER_ASSERT(reporter, !externalTexRT->asRenderTarget()->isSameAs(texRT1));
53
54 texRT1->unref();
55 texRT2->unref();
56 tex1->unref();
57 externalTexRT->unref();
58 }
59}
60
bsalomon@google.com686bcb82013-04-09 15:04:12 +000061#endif