From 10805961ce424868e8315e00f6dbeeaa62d466ac Mon Sep 17 00:00:00 2001 From: bsalomon Date: Wed, 8 Oct 2014 04:45:09 -0700 Subject: Revert of Make the Sk GL context class an abstract base class (patchset #4 id:60001 of https://codereview.chromium.org/630843002/) Reason for revert: nanobech failing on Android Original issue's description: > Make the Sk GL context class an abstract base class > > Make the Sk GL context class, SkGLNativeContext, an abstract base class. Before, > it depended on ifdefs to implement the platform dependent polymorphism. Move > the logic to subclasses of the various platform implementations. > > This a step to enable Skia embedders to compile dm and bench_pictures. The > concrete goal is to support running these test apps with Chromium command buffer. > > With this change, Chromium can implement its own version of SkGLNativeContext > that uses command buffer, and host the implementation in its own repository. > > Implements the above by renaming the SkGLContextHelper to SkGLContext and > removing the unneeded SkGLNativeContext. Also removes > SkGLNativeContext::AutoRestoreContext functionality, it appeared to be unused: > no use in Skia code, and no tests. > > BUG=skia:2992 > > Committed: https://skia.googlesource.com/skia/+/a90ed4e83897b45d6331ee4c54e1edd4054de9a8 TBR=kkinnunen@nvidia.com NOTREECHECKS=true NOTRY=true BUG=skia:2992 Review URL: https://codereview.chromium.org/639793002 --- include/gpu/GrContextFactory.h | 10 ++-- include/gpu/gl/SkANGLEGLContext.h | 15 ++++- include/gpu/gl/SkDebugGLContext.h | 4 +- include/gpu/gl/SkGLContext.h | 103 ---------------------------------- include/gpu/gl/SkGLContextHelper.h | 95 +++++++++++++++++++++++++++++++ include/gpu/gl/SkMesaGLContext.h | 17 +++++- include/gpu/gl/SkNativeGLContext.h | 111 +++++++++++++++++++++++++++++++++++++ include/gpu/gl/SkNullGLContext.h | 4 +- 8 files changed, 243 insertions(+), 116 deletions(-) delete mode 100644 include/gpu/gl/SkGLContext.h create mode 100644 include/gpu/gl/SkGLContextHelper.h create mode 100644 include/gpu/gl/SkNativeGLContext.h (limited to 'include') diff --git a/include/gpu/GrContextFactory.h b/include/gpu/GrContextFactory.h index eff1f5834c..d78120ccb0 100644 --- a/include/gpu/GrContextFactory.h +++ b/include/gpu/GrContextFactory.h @@ -15,7 +15,7 @@ #if SK_MESA #include "gl/SkMesaGLContext.h" #endif -#include "gl/SkGLContext.h" +#include "gl/SkNativeGLContext.h" #include "gl/SkNullGLContext.h" #include "GrContext.h" @@ -130,12 +130,12 @@ public: return fContexts[i].fGrContext; } } - SkAutoTUnref glCtx; + SkAutoTUnref glCtx; SkAutoTUnref grCtx; switch (type) { case kNVPR_GLContextType: // fallthru case kNative_GLContextType: - glCtx.reset(SkCreatePlatformGLContext()); + glCtx.reset(SkNEW(SkNativeGLContext)); break; #ifdef SK_ANGLE case kANGLE_GLContextType: @@ -192,7 +192,7 @@ public: // Returns the GLContext of the given type. If it has not been created yet, // NULL is returned instead. - SkGLContext* getGLContext(GLContextType type) { + SkGLContextHelper* getGLContext(GLContextType type) { for (int i = 0; i < fContexts.count(); ++i) { if (fContexts[i].fType == type) { return fContexts[i].fGLContext; @@ -207,7 +207,7 @@ public: private: struct GPUContext { GLContextType fType; - SkGLContext* fGLContext; + SkGLContextHelper* fGLContext; GrContext* fGrContext; }; SkTArray fContexts; diff --git a/include/gpu/gl/SkANGLEGLContext.h b/include/gpu/gl/SkANGLEGLContext.h index 18cdbdb213..c5f62ff3ce 100644 --- a/include/gpu/gl/SkANGLEGLContext.h +++ b/include/gpu/gl/SkANGLEGLContext.h @@ -10,12 +10,12 @@ #if SK_ANGLE -#include "SkGLContext.h" +#include "SkGLContextHelper.h" #include #include -class SkANGLEGLContext : public SkGLContext { +class SkANGLEGLContext : public SkGLContextHelper { public: SkANGLEGLContext(); @@ -24,6 +24,17 @@ public: virtual void makeCurrent() const SK_OVERRIDE; virtual void swapBuffers() const SK_OVERRIDE; + class AutoContextRestore { + public: + AutoContextRestore(); + ~AutoContextRestore(); + + private: + EGLContext fOldEGLContext; + EGLDisplay fOldDisplay; + EGLSurface fOldSurface; + }; + protected: virtual const GrGLInterface* createGLContext( GrGLStandard forcedGpuAPI) SK_OVERRIDE; diff --git a/include/gpu/gl/SkDebugGLContext.h b/include/gpu/gl/SkDebugGLContext.h index 792666332e..7db9579617 100644 --- a/include/gpu/gl/SkDebugGLContext.h +++ b/include/gpu/gl/SkDebugGLContext.h @@ -8,9 +8,9 @@ #ifndef SkDebugGLContext_DEFINED #define SkDebugGLContext_DEFINED -#include "SkGLContext.h" +#include "SkGLContextHelper.h" -class SkDebugGLContext : public SkGLContext { +class SkDebugGLContext : public SkGLContextHelper { public: SkDebugGLContext() {} diff --git a/include/gpu/gl/SkGLContext.h b/include/gpu/gl/SkGLContext.h deleted file mode 100644 index 83c9146c9b..0000000000 --- a/include/gpu/gl/SkGLContext.h +++ /dev/null @@ -1,103 +0,0 @@ - -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#ifndef SkGLContext_DEFINED -#define SkGLContext_DEFINED - -#include "GrGLInterface.h" - -/** - * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. - * Provides a GrGLInterface struct of function pointers for the context. - */ - -class SK_API SkGLContext : public SkRefCnt { -public: - SK_DECLARE_INST_COUNT(SkGLContext) - - SkGLContext(); - virtual ~SkGLContext(); - - /** - * Initializes the context and makes it current. - */ - bool init(GrGLStandard forcedGpuAPI, const int width, const int height); - - int getFBOID() const { return fFBO; } - - const GrGLInterface* gl() const { return fGL; } - - virtual void makeCurrent() const = 0; - - /** - * The primary 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 drawing surface provided by the platform is double buffered this - * call will cause the platform to swap which buffer is currently being - * targeted. If the current surface does not include a back buffer, this - * call has no effect. - */ - virtual void swapBuffers() const = 0; - - bool hasExtension(const char* extensionName) const { - SkASSERT(fGL); - return fGL->hasExtension(extensionName); - } - - /** - * 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(); - -protected: - /** - * Subclass implements this to make a GL context. The returned GrGLInterface - * should be populated with functions compatible with the context. The - * format and size of backbuffers does not matter since an FBO will be - * created. - */ - virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) = 0; - - /** - * Subclass should destroy the underlying GL context. - */ - virtual void destroyGLContext() = 0; - -private: - GrGLuint fFBO; - GrGLuint fColorBufferID; - GrGLuint fDepthStencilBufferID; - const GrGLInterface* fGL; - - typedef SkRefCnt INHERITED; -}; - -/** Creates platform-dependent GL context object - * 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. - */ -SK_API SkGLContext* SkCreatePlatformGLContext(); - -/** - * Helper macros for using the GL context through the GrGLInterface. Example: - * SK_GL(glCtx, GenTextures(1, &texID)); - */ -#define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ - SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) -#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ - SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) -#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X -#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X - -#endif diff --git a/include/gpu/gl/SkGLContextHelper.h b/include/gpu/gl/SkGLContextHelper.h new file mode 100644 index 0000000000..c4d9bdf997 --- /dev/null +++ b/include/gpu/gl/SkGLContextHelper.h @@ -0,0 +1,95 @@ + +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkGLContextHelper_DEFINED +#define SkGLContextHelper_DEFINED + +#include "GrGLInterface.h" + +/** + * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. + * Provides a GrGLInterface struct of function pointers for the context. + */ + +class SK_API SkGLContextHelper : public SkRefCnt { +public: + SK_DECLARE_INST_COUNT(SkGLContextHelper) + + SkGLContextHelper(); + virtual ~SkGLContextHelper(); + + /** + * Initializes the context and makes it current. + */ + bool init(GrGLStandard forcedGpuAPI, const int width, const int height); + + int getFBOID() const { return fFBO; } + + const GrGLInterface* gl() const { return fGL; } + + virtual void makeCurrent() const = 0; + + /** + * The primary 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 drawing surface provided by the platform is double buffered this + * call will cause the platform to swap which buffer is currently being + * targeted. If the current surface does not include a back buffer, this + * call has no effect. + */ + virtual void swapBuffers() const = 0; + + bool hasExtension(const char* extensionName) const { + SkASSERT(fGL); + return fGL->hasExtension(extensionName); + } + + /** + * 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(); + +protected: + /** + * Subclass implements this to make a GL context. The returned GrGLInterface + * should be populated with functions compatible with the context. The + * format and size of backbuffers does not matter since an FBO will be + * created. + */ + virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) = 0; + + /** + * Subclass should destroy the underlying GL context. + */ + virtual void destroyGLContext() = 0; + +private: + GrGLuint fFBO; + GrGLuint fColorBufferID; + GrGLuint fDepthStencilBufferID; + const GrGLInterface* fGL; + + typedef SkRefCnt INHERITED; +}; + +/** + * Helper macros for using the GL context through the GrGLInterface. Example: + * SK_GL(glCtx, GenTextures(1, &texID)); + */ +#define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ + SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) +#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ + SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) +#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X +#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X + +#endif diff --git a/include/gpu/gl/SkMesaGLContext.h b/include/gpu/gl/SkMesaGLContext.h index ef0017180c..28349ddd88 100644 --- a/include/gpu/gl/SkMesaGLContext.h +++ b/include/gpu/gl/SkMesaGLContext.h @@ -8,11 +8,11 @@ #ifndef SkMesaGLContext_DEFINED #define SkMesaGLContext_DEFINED -#include "SkGLContext.h" +#include "SkGLContextHelper.h" #if SK_MESA -class SkMesaGLContext : public SkGLContext { +class SkMesaGLContext : public SkGLContextHelper { private: typedef intptr_t Context; @@ -24,6 +24,19 @@ public: virtual void makeCurrent() const SK_OVERRIDE; virtual void swapBuffers() const SK_OVERRIDE; + class AutoContextRestore { + public: + AutoContextRestore(); + ~AutoContextRestore(); + + private: + Context fOldContext; + GrGLint fOldWidth; + GrGLint fOldHeight; + GrGLint fOldFormat; + void* fOldImage; + }; + protected: virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_OVERRIDE; virtual void destroyGLContext() SK_OVERRIDE; diff --git a/include/gpu/gl/SkNativeGLContext.h b/include/gpu/gl/SkNativeGLContext.h new file mode 100644 index 0000000000..93b5b4183a --- /dev/null +++ b/include/gpu/gl/SkNativeGLContext.h @@ -0,0 +1,111 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkNativeGLContext_DEFINED +#define SkNativeGLContext_DEFINED + +#include "SkGLContextHelper.h" + +/* This struct is taken from a mesa demo. Please update as required */ +static const struct { int major, minor; } gl_versions[] = { + {1, 0}, + {1, 1}, + {1, 2}, + {1, 3}, + {1, 4}, + {1, 5}, + {2, 0}, + {2, 1}, + {3, 0}, + {3, 1}, + {3, 2}, + {3, 3}, + {4, 0}, + {4, 1}, + {4, 2}, + {4, 3}, + {4, 4}, + {0, 0} /* end of list */ +}; +#define NUM_GL_VERSIONS SK_ARRAY_COUNT(gl_versions) + +#if defined(SK_BUILD_FOR_MAC) + #include +#elif SK_EGL + #include + #include +#elif defined(SK_BUILD_FOR_UNIX) + #include + #include +#elif defined(SK_BUILD_FOR_WIN32) + #include + #include + #include "SkWGL.h" +#endif + +class SkNativeGLContext : public SkGLContextHelper { +public: + SkNativeGLContext(); + + virtual ~SkNativeGLContext(); + + virtual void makeCurrent() const SK_OVERRIDE; + virtual void swapBuffers() const SK_OVERRIDE; + + class AutoContextRestore { + public: + AutoContextRestore(); + ~AutoContextRestore(); + + private: + #if defined(SK_BUILD_FOR_MAC) + CGLContextObj fOldCGLContext; + #elif SK_EGL + EGLContext fOldEGLContext; + EGLDisplay fOldDisplay; + EGLSurface fOldSurface; + #elif defined(SK_BUILD_FOR_UNIX) + GLXContext fOldGLXContext; + Display* fOldDisplay; + GLXDrawable fOldDrawable; + #elif defined(SK_BUILD_FOR_WIN32) + HDC fOldHDC; + HGLRC fOldHGLRC; + + #elif defined(SK_BUILD_FOR_IOS) + void* fEAGLContext; + #endif + }; + +protected: + virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_OVERRIDE; + virtual void destroyGLContext() SK_OVERRIDE; + +private: +#if defined(SK_BUILD_FOR_MAC) + CGLContextObj fContext; +#elif SK_EGL + EGLContext fContext; + EGLDisplay fDisplay; + EGLSurface fSurface; +#elif defined(SK_BUILD_FOR_UNIX) + GLXContext fContext; + Display* fDisplay; + Pixmap fPixmap; + GLXPixmap fGlxPixmap; +#elif defined(SK_BUILD_FOR_WIN32) + HWND fWindow; + HDC fDeviceContext; + HGLRC fGlRenderContext; + static ATOM gWC; + SkWGLPbufferContext* fPbufferContext; +#elif defined(SK_BUILD_FOR_IOS) + void* fEAGLContext; +#endif +}; + +#endif diff --git a/include/gpu/gl/SkNullGLContext.h b/include/gpu/gl/SkNullGLContext.h index 16621fc696..6c2a1d7e59 100644 --- a/include/gpu/gl/SkNullGLContext.h +++ b/include/gpu/gl/SkNullGLContext.h @@ -8,9 +8,9 @@ #ifndef SkNullGLContext_DEFINED #define SkNullGLContext_DEFINED -#include "SkGLContext.h" +#include "SkGLContextHelper.h" -class SK_API SkNullGLContext : public SkGLContext { +class SK_API SkNullGLContext : public SkGLContextHelper { public: SkNullGLContext() {}; -- cgit v1.2.3