aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar kkinnunen <kkinnunen@nvidia.com>2014-10-15 23:03:54 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-15 23:03:54 -0700
commit30bc88ccd524c0372fd2f8f79190ea4b81685beb (patch)
treebc506a76edaa98c6285f6e2496c83585d1ada1cc /include
parentde258cd6b402c4da78b66e88191ad02162d87916 (diff)
Refactor SkGLContext to be actually extendable
Refactor SkGLContext to be actually extendable. Before, non-trivial subclass would need to destroy the GL connection upon running the destructor. However, the base class would run GL commands in its own destructor (with destroyed GL connection) Refactor so that SkGLContext subclass object creation is completely done by the factory function. If the factory function returns a non-NULL ptr, it means the context is usable. The destruction is done with the destructor instead of virtual function called upon destruction. Make the destructors not to call virtual functions, for clarity. Remove custom 1x1 FBO setup code from the base class. It appears not to be used anymore. BUG=skia:2992 Review URL: https://codereview.chromium.org/640283004
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrContextFactory.h20
-rw-r--r--include/gpu/gl/SkANGLEGLContext.h23
-rw-r--r--include/gpu/gl/SkDebugGLContext.h16
-rw-r--r--include/gpu/gl/SkGLContext.h41
-rw-r--r--include/gpu/gl/SkMesaGLContext.h22
-rw-r--r--include/gpu/gl/SkNullGLContext.h23
6 files changed, 72 insertions, 73 deletions
diff --git a/include/gpu/GrContextFactory.h b/include/gpu/GrContextFactory.h
index eff1f5834c..143ca31aad 100644
--- a/include/gpu/GrContextFactory.h
+++ b/include/gpu/GrContextFactory.h
@@ -135,35 +135,33 @@ public:
switch (type) {
case kNVPR_GLContextType: // fallthru
case kNative_GLContextType:
- glCtx.reset(SkCreatePlatformGLContext());
+ glCtx.reset(SkCreatePlatformGLContext(forcedGpuAPI));
break;
#ifdef SK_ANGLE
case kANGLE_GLContextType:
- glCtx.reset(SkNEW(SkANGLEGLContext));
+ glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI));
break;
#endif
#ifdef SK_MESA
case kMESA_GLContextType:
- glCtx.reset(SkNEW(SkMesaGLContext));
+ glCtx.reset(SkMesaGLContext::Create(forcedGpuAPI));
break;
#endif
case kNull_GLContextType:
- glCtx.reset(SkNEW(SkNullGLContext));
+ glCtx.reset(SkNullGLContext::Create(forcedGpuAPI));
break;
case kDebug_GLContextType:
- glCtx.reset(SkNEW(SkDebugGLContext));
+ glCtx.reset(SkDebugGLContext::Create(forcedGpuAPI));
break;
}
- static const int kBogusSize = 1;
- if (!glCtx.get()) {
- return NULL;
- }
- if (!glCtx.get()->init(forcedGpuAPI, kBogusSize, kBogusSize)) {
+ if (NULL == glCtx.get()) {
return NULL;
}
+ SkASSERT(glCtx->isValid());
+
// Ensure NVPR is available for the NVPR type and block it from other types.
- SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx.get()->gl()));
+ SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl()));
if (kNVPR_GLContextType == type) {
if (!glInterface->hasExtension("GL_NV_path_rendering")) {
return NULL;
diff --git a/include/gpu/gl/SkANGLEGLContext.h b/include/gpu/gl/SkANGLEGLContext.h
index 18cdbdb213..797e997972 100644
--- a/include/gpu/gl/SkANGLEGLContext.h
+++ b/include/gpu/gl/SkANGLEGLContext.h
@@ -17,19 +17,26 @@
class SkANGLEGLContext : public SkGLContext {
public:
- SkANGLEGLContext();
-
- virtual ~SkANGLEGLContext();
-
+ virtual ~SkANGLEGLContext() SK_OVERRIDE;
virtual void makeCurrent() const SK_OVERRIDE;
virtual void swapBuffers() const SK_OVERRIDE;
-protected:
- virtual const GrGLInterface* createGLContext(
- GrGLStandard forcedGpuAPI) SK_OVERRIDE;
- virtual void destroyGLContext() SK_OVERRIDE;
+ static SkANGLEGLContext* Create(GrGLStandard forcedGpuAPI) {
+ if (kGL_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+ SkANGLEGLContext* ctx = SkNEW(SkANGLEGLContext);
+ if (!ctx->isValid()) {
+ SkDELETE(ctx);
+ return NULL;
+ }
+ return ctx;
+ }
private:
+ SkANGLEGLContext();
+ void destroyGLContext();
+
EGLContext fContext;
EGLDisplay fDisplay;
EGLSurface fSurface;
diff --git a/include/gpu/gl/SkDebugGLContext.h b/include/gpu/gl/SkDebugGLContext.h
index 792666332e..ad157fa653 100644
--- a/include/gpu/gl/SkDebugGLContext.h
+++ b/include/gpu/gl/SkDebugGLContext.h
@@ -11,17 +11,19 @@
#include "SkGLContext.h"
class SkDebugGLContext : public SkGLContext {
-
public:
- SkDebugGLContext() {}
-
+ virtual ~SkDebugGLContext() SK_OVERRIDE;
virtual void makeCurrent() const SK_OVERRIDE {}
virtual void swapBuffers() const SK_OVERRIDE {}
-protected:
- virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_OVERRIDE;
-
- virtual void destroyGLContext() SK_OVERRIDE {};
+ static SkDebugGLContext* Create(GrGLStandard forcedGpuAPI) {
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+ return SkNEW(SkDebugGLContext);
+ }
+private:
+ SkDebugGLContext();
};
#endif
diff --git a/include/gpu/gl/SkGLContext.h b/include/gpu/gl/SkGLContext.h
index 83c9146c9b..ceaced539b 100644
--- a/include/gpu/gl/SkGLContext.h
+++ b/include/gpu/gl/SkGLContext.h
@@ -19,17 +19,11 @@ 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);
+ virtual ~SkGLContext() SK_OVERRIDE;
- int getFBOID() const { return fFBO; }
+ bool isValid() const { return NULL != gl(); }
- const GrGLInterface* gl() const { return fGL; }
+ const GrGLInterface* gl() const { return fGL.get(); }
virtual void makeCurrent() const = 0;
@@ -45,11 +39,6 @@ public:
*/
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
@@ -59,35 +48,23 @@ public:
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;
+ SkGLContext();
-private:
- GrGLuint fFBO;
- GrGLuint fColorBufferID;
- GrGLuint fDepthStencilBufferID;
- const GrGLInterface* fGL;
+ /** Subclass provides the gl interface object if construction was
+ * successful. */
+ SkAutoTUnref<const GrGLInterface> fGL;
typedef SkRefCnt INHERITED;
};
/** Creates platform-dependent GL context object
+ * 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.
*/
-SK_API SkGLContext* SkCreatePlatformGLContext();
+SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI);
/**
* Helper macros for using the GL context through the GrGLInterface. Example:
diff --git a/include/gpu/gl/SkMesaGLContext.h b/include/gpu/gl/SkMesaGLContext.h
index ef0017180c..70a391df10 100644
--- a/include/gpu/gl/SkMesaGLContext.h
+++ b/include/gpu/gl/SkMesaGLContext.h
@@ -17,18 +17,26 @@ private:
typedef intptr_t Context;
public:
- SkMesaGLContext();
-
- virtual ~SkMesaGLContext();
-
+ virtual ~SkMesaGLContext() SK_OVERRIDE;
virtual void makeCurrent() const SK_OVERRIDE;
virtual void swapBuffers() const SK_OVERRIDE;
-protected:
- virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_OVERRIDE;
- virtual void destroyGLContext() SK_OVERRIDE;
+ static SkMesaGLContext* Create(GrGLStandard forcedGpuAPI) {
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+ SkMesaGLContext* ctx = SkNEW(SkMesaGLContext);
+ if (!ctx->isValid()) {
+ SkDELETE(ctx);
+ return NULL;
+ }
+ return ctx;
+ }
private:
+ SkMesaGLContext();
+ void destroyGLContext();
+
Context fContext;
GrGLubyte *fImage;
};
diff --git a/include/gpu/gl/SkNullGLContext.h b/include/gpu/gl/SkNullGLContext.h
index 16621fc696..35e94d2ab9 100644
--- a/include/gpu/gl/SkNullGLContext.h
+++ b/include/gpu/gl/SkNullGLContext.h
@@ -11,18 +11,25 @@
#include "SkGLContext.h"
class SK_API SkNullGLContext : public SkGLContext {
-
public:
- SkNullGLContext() {};
-
+ virtual ~SkNullGLContext() SK_OVERRIDE;
virtual void makeCurrent() const SK_OVERRIDE {};
-
virtual void swapBuffers() const SK_OVERRIDE {};
-protected:
- virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_OVERRIDE;
-
- virtual void destroyGLContext() SK_OVERRIDE {};
+ static SkNullGLContext* Create(GrGLStandard forcedGpuAPI) {
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+ SkNullGLContext* ctx = SkNEW(SkNullGLContext);
+ if (!ctx->isValid()) {
+ SkDELETE(ctx);
+ return NULL;
+ }
+ return ctx;
+ }
+
+private:
+ SkNullGLContext();
};
#endif