diff options
author | bsalomon <bsalomon@google.com> | 2016-05-11 10:09:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-11 10:09:18 -0700 |
commit | 18a2f9dff839a3f60850c25e1a701b682a497afb (patch) | |
tree | 0113e4f746b09221f6ccce88beadb60432347682 /tools/gpu/gl | |
parent | 393c2ff0d2db9c5d84e6ed660ea9f546f438cb47 (diff) |
Add base class for GLTestContext and add new subclass VkTestContext.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1964243003
Review-Url: https://codereview.chromium.org/1964243003
Diffstat (limited to 'tools/gpu/gl')
-rw-r--r-- | tools/gpu/gl/GLTestContext.cpp | 58 | ||||
-rw-r--r-- | tools/gpu/gl/GLTestContext.h | 93 |
2 files changed, 26 insertions, 125 deletions
diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp index 1069929bf2..3bd814762e 100644 --- a/tools/gpu/gl/GLTestContext.cpp +++ b/tools/gpu/gl/GLTestContext.cpp @@ -1,13 +1,12 @@ - /* * Copyright 2013 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + #include "GLTestContext.h" #include "gl/GrGLUtil.h" -#include "SkGpuFenceSync.h" namespace sk_gpu_test { class GLTestContext::GLFenceSync : public SkGpuFenceSync { @@ -38,75 +37,28 @@ private: typedef SkGpuFenceSync INHERITED; }; -GLTestContext::GLTestContext() - : fCurrentFenceIdx(0) { - memset(fFrameFences, 0, sizeof(fFrameFences)); -} +GLTestContext::GLTestContext() : TestContext() {} GLTestContext::~GLTestContext() { - // Subclass should call teardown. -#ifdef SK_DEBUG - for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) { - SkASSERT(0 == fFrameFences[i]); - } -#endif SkASSERT(nullptr == fGL.get()); - SkASSERT(nullptr == fFenceSync.get()); } void GLTestContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { SkASSERT(!fGL.get()); fGL.reset(gl); - fFenceSync.reset(fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this)); + fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this); } void GLTestContext::teardown() { - if (fFenceSync) { - for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) { - if (fFrameFences[i]) { - fFenceSync->deleteFence(fFrameFences[i]); - fFrameFences[i] = 0; - } - } - fFenceSync.reset(nullptr); - } - fGL.reset(nullptr); -} - -void GLTestContext::makeCurrent() const { - this->onPlatformMakeCurrent(); -} - -void GLTestContext::swapBuffers() { - this->onPlatformSwapBuffers(); -} - -void GLTestContext::waitOnSyncOrSwap() { - if (!fFenceSync) { - // Fallback on the platform SwapBuffers method for synchronization. This may have no effect. - this->swapBuffers(); - return; - } - - if (fFrameFences[fCurrentFenceIdx]) { - if (!fFenceSync->waitFence(fFrameFences[fCurrentFenceIdx], true)) { - SkDebugf("WARNING: Wait failed for fence sync. Timings might not be accurate.\n"); - } - fFenceSync->deleteFence(fFrameFences[fCurrentFenceIdx]); - } - - fFrameFences[fCurrentFenceIdx] = fFenceSync->insertFence(); - fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences); + INHERITED::teardown(); } void GLTestContext::testAbandon() { + INHERITED::testAbandon(); if (fGL) { fGL->abandon(); } - if (fFenceSync) { - memset(fFrameFences, 0, sizeof(fFrameFences)); - } } GLTestContext::GLFenceSync* GLTestContext::GLFenceSync::CreateIfSupported(const GLTestContext* ctx) { diff --git a/tools/gpu/gl/GLTestContext.h b/tools/gpu/gl/GLTestContext.h index d6054a8ba6..a940f8dce7 100644 --- a/tools/gpu/gl/GLTestContext.h +++ b/tools/gpu/gl/GLTestContext.h @@ -8,34 +8,26 @@ #ifndef GLTestContext_DEFINED #define GLTestContext_DEFINED +#include "TestContext.h" #include "gl/GrGLInterface.h" -#include "../private/SkGpuFenceSync.h" - namespace sk_gpu_test { /** - * Create an offscreen Oppengl context. Provides a GrGLInterface struct of function pointers for - * the context. This class is intended for Skia's internal testing needs and not for general use. + * An offscreen OpenGL context. Provides a GrGLInterface struct of function pointers for the context + * This class is intended for Skia's internal testing needs and not for general use. */ -class GLTestContext : public SkNoncopyable { +class GLTestContext : public TestContext { public: virtual ~GLTestContext(); - bool isValid() const { return NULL != gl(); } - - const GrGLInterface *gl() const { return fGL.get(); } - - bool fenceSyncSupport() const { return fFenceSync != nullptr; } - - bool getMaxGpuFrameLag(int *maxFrameLag) const { - if (!fFenceSync) { - return false; - } - *maxFrameLag = kMaxFrameLag; - return true; + virtual GrBackend backend() override { return kOpenGL_GrBackend; } + virtual GrBackendContext backendContext() override { + return reinterpret_cast<GrBackendContext>(fGL.get()); } - void makeCurrent() const; + bool isValid() const override { return SkToBool(this->gl()); } + + const GrGLInterface *gl() const { return fGL.get(); } /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */ virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return 0; } @@ -53,30 +45,7 @@ public: */ virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; } - void swapBuffers(); - - /** - * The only purpose of this function it to provide a means of scheduling - * work on the GPU (since all of the subclasses create primary buffers for - * testing that are small and not meant to be rendered to the screen). - * - * If the platform supports fence sync (OpenGL 3.2+ or EGL_KHR_fence_sync), - * this will not swap any buffers, but rather emulate triple buffer - * synchronization using fences. - * - * Otherwise it will call the platform SwapBuffers method. This may or may - * not perform some sort of synchronization, depending on whether the - * drawing surface provided by the platform is double buffered. - */ - void waitOnSyncOrSwap(); - - /** - * This notifies the context that we are deliberately testing abandoning - * the context. It is useful for debugging contexts that would otherwise - * test that GPU resources are properly deleted. It also allows a debugging - * context to test that further GL calls are not made by Skia GPU code. - */ - void testAbandon(); + void testAbandon() override; /** * Creates a new GL context of the same type and makes the returned context current @@ -84,13 +53,6 @@ public: */ virtual GLTestContext *createNew() const { return nullptr; } - class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL functionality. - - /* - * returns the fencesync object owned by this GLTestContext - */ - SkGpuFenceSync *fenceSync() { return fFenceSync.get(); } - protected: GLTestContext(); @@ -99,43 +61,30 @@ protected: */ void init(const GrGLInterface *, SkGpuFenceSync * = NULL); - void teardown(); - - /* - * Operations that have a platform-dependent implementation. - */ - virtual void onPlatformMakeCurrent() const = 0; - - virtual void onPlatformSwapBuffers() const = 0; + void teardown() override; virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0; private: - enum { - kMaxFrameLag = 3 - }; - - SkAutoTDelete <SkGpuFenceSync> fFenceSync; - SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1]; - int fCurrentFenceIdx; + class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL functionality. /** Subclass provides the gl interface object if construction was * successful. */ SkAutoTUnref<const GrGLInterface> fGL; friend class GLFenceSync; // For onPlatformGetProcAddress. -}; + typedef TestContext INHERITED; +}; -/** Creates platform-dependent GL context object. The shareContext parameter is in an optional +/** + * Creates platform-dependent GL context object. The shareContext parameter is in an optional * context with which to share display lists. This should be a pointer to an GLTestContext created - * with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to take place. Returns a valid - * gl context object or NULL if such can not be created. - * Note: If Skia embedder needs a custom GL context that sets up the GL interface, this function - * should be implemented by the embedder. Otherwise, the default implementation for the platform - * should be compiled in the library. + * with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to take place. Returns a + * valid gl context object or NULL if such can not be created. */ -GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, GLTestContext *shareContext = nullptr); +GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, + GLTestContext *shareContext = nullptr); } // namespace sk_gpu_test #endif |