1686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com/*
2686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com * Copyright 2013 Google Inc.
3686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com *
4686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com * Use of this source code is governed by a BSD-style license that can be
5686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com * found in the LICENSE file.
6686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com */
7686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com
8686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com#if SK_SUPPORT_GPU
9686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com
10686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com#include "GrContext.h"
11686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com#include "GrContextFactory.h"
12686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com#include "GrRenderTarget.h"
13686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com#include "GrTexture.h"
144ee16bfaedb14aff8cf102f1f0722ff2529a9699tfarina@chromium.org#include "SkTypes.h"
154ee16bfaedb14aff8cf102f1f0722ff2529a9699tfarina@chromium.org#include "Test.h"
16686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com
174ee16bfaedb14aff8cf102f1f0722ff2529a9699tfarina@chromium.orgDEF_GPUTEST(GrSurfaceTest, reporter, factory) {
18686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com    GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
19686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com    if (NULL != context) {
20686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        GrTextureDesc desc;
21686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        desc.fConfig = kSkia8888_GrPixelConfig;
22686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        desc.fFlags = kRenderTarget_GrTextureFlagBit;
23686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        desc.fWidth = 256;
24686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        desc.fHeight = 256;
25686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        desc.fSampleCnt = 0;
26686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        GrSurface* texRT1 = context->createUncachedTexture(desc, NULL, 0);
27686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        GrSurface* texRT2 = context->createUncachedTexture(desc, NULL, 0);
28686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        desc.fFlags = kNone_GrTextureFlags;
29686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        GrSurface* tex1 = context->createUncachedTexture(desc, NULL, 0);
30686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com
31686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1));
32686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1->asRenderTarget()));
33686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, texRT1->asRenderTarget()->isSameAs(texRT1));
34686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1));
35686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(texRT1));
36686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1->asRenderTarget()));
37686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, !texRT2->isSameAs(tex1));
38686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(tex1));
39686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com
40686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        GrBackendTextureDesc backendDesc;
41686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        backendDesc.fConfig = kSkia8888_GrPixelConfig;
42686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
43686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        backendDesc.fWidth = 256;
44686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        backendDesc.fHeight = 256;
45686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        backendDesc.fSampleCnt = 0;
46686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        backendDesc.fTextureHandle = 5;
47686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        GrSurface* externalTexRT = context->wrapBackendTexture(backendDesc);
48686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT));
49686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT->asRenderTarget()));
50686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, externalTexRT->asRenderTarget()->isSameAs(externalTexRT));
51686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, !externalTexRT->isSameAs(texRT1));
52686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        REPORTER_ASSERT(reporter, !externalTexRT->asRenderTarget()->isSameAs(texRT1));
53686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com
54686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        texRT1->unref();
55686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        texRT2->unref();
56686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        tex1->unref();
57686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com        externalTexRT->unref();
58686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com    }
59686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com}
60686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com
61686bcb871b8425603b9accbf72e27a9309f786d8bsalomon@google.com#endif
62