blob: 3fe071ca0f63c82b408ece4c3a23f9e55f934174 [file] [log] [blame]
bsalomon@google.com686bcb82013-04-09 15:04:12 +00001
2/*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9// This is a GPU-backend specific test.
10
11#include "SkTypes.h"
12
13#if SK_SUPPORT_GPU
14
15#include "Test.h"
16#include "GrContext.h"
17#include "GrContextFactory.h"
18#include "GrRenderTarget.h"
19#include "GrTexture.h"
20
21static void GrSurfaceIsSameTest(skiatest::Reporter* reporter, GrContextFactory* factory) {
22 GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
23 if (NULL != context) {
24 GrTextureDesc desc;
25 desc.fConfig = kSkia8888_GrPixelConfig;
26 desc.fFlags = kRenderTarget_GrTextureFlagBit;
27 desc.fWidth = 256;
28 desc.fHeight = 256;
29 desc.fSampleCnt = 0;
30 GrSurface* texRT1 = context->createUncachedTexture(desc, NULL, 0);
31 GrSurface* texRT2 = context->createUncachedTexture(desc, NULL, 0);
32 desc.fFlags = kNone_GrTextureFlags;
33 GrSurface* tex1 = context->createUncachedTexture(desc, NULL, 0);
34
35 REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1));
36 REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1->asRenderTarget()));
37 REPORTER_ASSERT(reporter, texRT1->asRenderTarget()->isSameAs(texRT1));
38 REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1));
39 REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(texRT1));
40 REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1->asRenderTarget()));
41 REPORTER_ASSERT(reporter, !texRT2->isSameAs(tex1));
42 REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(tex1));
43
44 GrBackendTextureDesc backendDesc;
45 backendDesc.fConfig = kSkia8888_GrPixelConfig;
46 backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
47 backendDesc.fWidth = 256;
48 backendDesc.fHeight = 256;
49 backendDesc.fSampleCnt = 0;
50 backendDesc.fTextureHandle = 5;
51 GrSurface* externalTexRT = context->wrapBackendTexture(backendDesc);
52 REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT));
53 REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT->asRenderTarget()));
54 REPORTER_ASSERT(reporter, externalTexRT->asRenderTarget()->isSameAs(externalTexRT));
55 REPORTER_ASSERT(reporter, !externalTexRT->isSameAs(texRT1));
56 REPORTER_ASSERT(reporter, !externalTexRT->asRenderTarget()->isSameAs(texRT1));
57
58 texRT1->unref();
59 texRT2->unref();
60 tex1->unref();
61 externalTexRT->unref();
62 }
63}
64
65#include "TestClassDef.h"
66DEFINE_GPUTESTCLASS("GrSurfaceIsSame", GrSurfaceIsSameTestClass, GrSurfaceIsSameTest)
67
68#endif