aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-09 15:04:12 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-09 15:04:12 +0000
commit686bcb871b8425603b9accbf72e27a9309f786d8 (patch)
tree0b1181c0a00e28d30a0f1f54754e1c0c7119c79c /tests
parent59dd7162a3d563bf6cf7fab32b0adf166f95d6fd (diff)
Reland of 8525 with fix for case when GrRT outlives GrTexture.
Review URL: https://codereview.chromium.org/13814015 git-svn-id: http://skia.googlecode.com/svn/trunk@8573 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/GrSurfaceTest.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
new file mode 100644
index 0000000000..3fe071ca0f
--- /dev/null
+++ b/tests/GrSurfaceTest.cpp
@@ -0,0 +1,68 @@
+
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// This is a GPU-backend specific test.
+
+#include "SkTypes.h"
+
+#if SK_SUPPORT_GPU
+
+#include "Test.h"
+#include "GrContext.h"
+#include "GrContextFactory.h"
+#include "GrRenderTarget.h"
+#include "GrTexture.h"
+
+static void GrSurfaceIsSameTest(skiatest::Reporter* reporter, GrContextFactory* factory) {
+ GrContext* context = factory->get(GrContextFactory::kNull_GLContextType);
+ if (NULL != context) {
+ GrTextureDesc desc;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fFlags = kRenderTarget_GrTextureFlagBit;
+ desc.fWidth = 256;
+ desc.fHeight = 256;
+ desc.fSampleCnt = 0;
+ GrSurface* texRT1 = context->createUncachedTexture(desc, NULL, 0);
+ GrSurface* texRT2 = context->createUncachedTexture(desc, NULL, 0);
+ desc.fFlags = kNone_GrTextureFlags;
+ GrSurface* tex1 = context->createUncachedTexture(desc, NULL, 0);
+
+ REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1));
+ REPORTER_ASSERT(reporter, texRT1->isSameAs(texRT1->asRenderTarget()));
+ REPORTER_ASSERT(reporter, texRT1->asRenderTarget()->isSameAs(texRT1));
+ REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1));
+ REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(texRT1));
+ REPORTER_ASSERT(reporter, !texRT2->isSameAs(texRT1->asRenderTarget()));
+ REPORTER_ASSERT(reporter, !texRT2->isSameAs(tex1));
+ REPORTER_ASSERT(reporter, !texRT2->asRenderTarget()->isSameAs(tex1));
+
+ GrBackendTextureDesc backendDesc;
+ backendDesc.fConfig = kSkia8888_GrPixelConfig;
+ backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
+ backendDesc.fWidth = 256;
+ backendDesc.fHeight = 256;
+ backendDesc.fSampleCnt = 0;
+ backendDesc.fTextureHandle = 5;
+ GrSurface* externalTexRT = context->wrapBackendTexture(backendDesc);
+ REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT));
+ REPORTER_ASSERT(reporter, externalTexRT->isSameAs(externalTexRT->asRenderTarget()));
+ REPORTER_ASSERT(reporter, externalTexRT->asRenderTarget()->isSameAs(externalTexRT));
+ REPORTER_ASSERT(reporter, !externalTexRT->isSameAs(texRT1));
+ REPORTER_ASSERT(reporter, !externalTexRT->asRenderTarget()->isSameAs(texRT1));
+
+ texRT1->unref();
+ texRT2->unref();
+ tex1->unref();
+ externalTexRT->unref();
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_GPUTESTCLASS("GrSurfaceIsSame", GrSurfaceIsSameTestClass, GrSurfaceIsSameTest)
+
+#endif