Revert "Revert "Make mock GrContext unit testable.""
This reverts commit c867a89b012c07e7e5cb719a31ed90e61f4a4901.
Reason for revert: test
Original change's description:
> Revert "Make mock GrContext unit testable."
>
> This reverts commit 993e7e25217df05d63c3354c817e8bd18ea3738b.
>
> Reason for revert: Seeing if this fixes the NexusPlayer bots
>
> Original change's description:
> > Make mock GrContext unit testable.
> >
> > Bug: skia:
> > Change-Id: I959122f1f2c390832ab1033bcdbdd2ca6cfc0419
> > Reviewed-on: https://skia-review.googlesource.com/20699
> > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > Commit-Queue: Brian Salomon <bsalomon@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com
>
> Change-Id: I25ed9329962d930fe38108f779ff7083e0e4847e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/21731
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>
TBR=egdaniel@google.com,bsalomon@google.com
Change-Id: I62c579e087db1ff9891cf6c41b3eb40f47561887
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/21733
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index 23ffad1..d614b06 100644
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -22,6 +22,7 @@
#endif
#include "gl/null/NullGLTestContext.h"
#include "gl/GrGLGpu.h"
+#include "mock/MockTestContext.h"
#include "GrCaps.h"
#if defined(SK_BUILD_FOR_WIN32) && defined(SK_ENABLE_DISCRETE_GPU)
@@ -220,6 +221,19 @@
break;
}
#endif
+ case kMock_GrBackend: {
+ TestContext* sharedContext = masterContext ? masterContext->fTestContext : nullptr;
+ SkASSERT(kMock_ContextType == type);
+ if (ContextOverrides::kRequireNVPRSupport & overrides) {
+ return ContextInfo();
+ }
+ testCtx.reset(CreateMockTestContext(sharedContext));
+ if (!testCtx) {
+ return ContextInfo();
+ }
+ backendContext = testCtx->backendContext();
+ break;
+ }
default:
return ContextInfo();
}
diff --git a/tools/gpu/GrContextFactory.h b/tools/gpu/GrContextFactory.h
index 508249b..215b922 100644
--- a/tools/gpu/GrContextFactory.h
+++ b/tools/gpu/GrContextFactory.h
@@ -44,7 +44,8 @@
kNullGL_ContextType, //! Non-rendering OpenGL mock context.
kDebugGL_ContextType, //! Non-rendering, state verifying OpenGL context.
kVulkan_ContextType, //! Vulkan
- kLastContextType = kVulkan_ContextType
+ kMock_ContextType, //! Mock context that does not draw.
+ kLastContextType = kMock_ContextType
};
static const int kContextTypeCnt = kLastContextType + 1;
@@ -68,6 +69,7 @@
switch (type) {
case kNullGL_ContextType:
case kDebugGL_ContextType:
+ case kMock_ContextType:
return false;
default:
return true;
@@ -78,6 +80,8 @@
switch (type) {
case kVulkan_ContextType:
return kVulkan_GrBackend;
+ case kMock_ContextType:
+ return kMock_GrBackend;
default:
return kOpenGL_GrBackend;
}
@@ -109,8 +113,10 @@
return "Debug GL";
case kVulkan_ContextType:
return "Vulkan";
+ case kMock_ContextType:
+ return "Mock";
}
- SkDEBUGFAIL("Unreachable");
+ SkFAIL("Unreachable");
return "Unknown";
}
diff --git a/tools/gpu/mock/MockTestContext.cpp b/tools/gpu/mock/MockTestContext.cpp
new file mode 100644
index 0000000..c47fff5
--- /dev/null
+++ b/tools/gpu/mock/MockTestContext.cpp
@@ -0,0 +1,45 @@
+
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef GLTestContext_DEFINED
+#define GLTestContext_DEFINED
+
+#include "MockTestContext.h"
+
+namespace {
+
+class MockTestContext : public sk_gpu_test::TestContext {
+public:
+ MockTestContext() {}
+ ~MockTestContext() override {}
+
+ virtual GrBackend backend() override { return kMock_GrBackend; }
+ virtual GrBackendContext backendContext() override {
+ return reinterpret_cast<GrBackendContext>(nullptr);
+ }
+ bool isValid() const override { return true; }
+ void testAbandon() override {}
+ void submit() override {}
+ void finish() override {}
+
+protected:
+ void teardown() override {}
+ void onPlatformMakeCurrent() const override {}
+ void onPlatformSwapBuffers() const override {}
+
+private:
+ typedef sk_gpu_test::TestContext INHERITED;
+};
+
+} // anonymous namespace
+
+namespace sk_gpu_test {
+
+TestContext* CreateMockTestContext(TestContext*) { return new MockTestContext(); }
+
+} // namespace sk_gpu_test
+#endif
diff --git a/tools/gpu/mock/MockTestContext.h b/tools/gpu/mock/MockTestContext.h
new file mode 100644
index 0000000..4aac248
--- /dev/null
+++ b/tools/gpu/mock/MockTestContext.h
@@ -0,0 +1,22 @@
+
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef MockTestContext_DEFINED
+#define MockTestContext_DEFINED
+
+#include "TestContext.h"
+
+namespace sk_gpu_test {
+
+/**
+ * Creates mock context object for use with GrContexts created with kMock_GrBackend. It will
+ * trivially succeed at everything.
+ */
+TestContext* CreateMockTestContext(TestContext* shareContext = nullptr);
+
+} // namespace sk_gpu_test
+#endif