aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
authorGravatar kkinnunen <kkinnunen@nvidia.com>2014-10-09 05:24:15 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-09 05:24:15 -0700
commit9e61bb7815b133bc40ea7b00fccc853f4b728e3c (patch)
treefb63fc7dbc1ede28f821af30fc0c6634e6e1168d /src/gpu/gl
parent78c71272fb26852bf3d2ca31785e61d4a598af82 (diff)
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 Review URL: https://codereview.chromium.org/630843002
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/SkGLContext.cpp (renamed from src/gpu/gl/SkGLContextHelper.cpp)10
-rw-r--r--src/gpu/gl/angle/SkANGLEGLContext.cpp15
-rw-r--r--src/gpu/gl/debug/GrGLCreateDebugInterface.cpp2
-rw-r--r--src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp (renamed from src/gpu/gl/egl/SkNativeGLContext_egl.cpp)51
-rw-r--r--src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp (renamed from src/gpu/gl/glx/SkNativeGLContext_glx.cpp)78
-rw-r--r--src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm (renamed from src/gpu/gl/iOS/SkNativeGLContext_iOS.mm)50
-rw-r--r--src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp (renamed from src/gpu/gl/mac/SkNativeGLContext_mac.cpp)43
-rw-r--r--src/gpu/gl/mesa/SkMesaGLContext.cpp18
-rw-r--r--src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp60
-rw-r--r--src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp37
-rw-r--r--src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp (renamed from src/gpu/gl/win/SkNativeGLContext_win.cpp)54
11 files changed, 254 insertions, 164 deletions
diff --git a/src/gpu/gl/SkGLContextHelper.cpp b/src/gpu/gl/SkGLContext.cpp
index 03b70c38f7..92f65cd924 100644
--- a/src/gpu/gl/SkGLContextHelper.cpp
+++ b/src/gpu/gl/SkGLContext.cpp
@@ -5,17 +5,17 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include "gl/SkGLContextHelper.h"
+#include "gl/SkGLContext.h"
#include "GrGLUtil.h"
-SkGLContextHelper::SkGLContextHelper()
+SkGLContext::SkGLContext()
: fFBO(0)
, fColorBufferID(0)
, fDepthStencilBufferID(0)
, fGL(NULL) {
}
-SkGLContextHelper::~SkGLContextHelper() {
+SkGLContext::~SkGLContext() {
if (fGL) {
// TODO: determine why DeleteFramebuffers is generating a GL error in tests
@@ -27,7 +27,7 @@ SkGLContextHelper::~SkGLContextHelper() {
SkSafeUnref(fGL);
}
-bool SkGLContextHelper::init(GrGLStandard forcedGpuAPI, int width,
+bool SkGLContext::init(GrGLStandard forcedGpuAPI, int width,
int height) {
if (fGL) {
fGL->unref();
@@ -135,7 +135,7 @@ bool SkGLContextHelper::init(GrGLStandard forcedGpuAPI, int width,
return false;
}
-void SkGLContextHelper::testAbandon() {
+void SkGLContext::testAbandon() {
if (fGL) {
fGL->abandon();
}
diff --git a/src/gpu/gl/angle/SkANGLEGLContext.cpp b/src/gpu/gl/angle/SkANGLEGLContext.cpp
index 81fccebba0..4914ba5533 100644
--- a/src/gpu/gl/angle/SkANGLEGLContext.cpp
+++ b/src/gpu/gl/angle/SkANGLEGLContext.cpp
@@ -8,21 +8,6 @@
#include "gl/SkANGLEGLContext.h"
-SkANGLEGLContext::AutoContextRestore::AutoContextRestore() {
- fOldEGLContext = eglGetCurrentContext();
- fOldDisplay = eglGetCurrentDisplay();
- fOldSurface = eglGetCurrentSurface(EGL_DRAW);
-
-}
-
-SkANGLEGLContext::AutoContextRestore::~AutoContextRestore() {
- if (fOldDisplay) {
- eglMakeCurrent(fOldDisplay, fOldSurface, fOldSurface, fOldEGLContext);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
SkANGLEGLContext::SkANGLEGLContext()
: fContext(EGL_NO_CONTEXT)
, fDisplay(EGL_NO_DISPLAY)
diff --git a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
index 4bd8f99e22..287a43fad0 100644
--- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
+++ b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
@@ -819,7 +819,7 @@ public:
// The solution to this is probably to alter SkDebugGlContext's
// "makeCurrent" method to make a call like "makeCurrent(this)" to
// the debug GL interface (assuming that the application will create
- // multiple SkGLContextHelper's) to let it switch between the active
+ // multiple SkGLContext's) to let it switch between the active
// context. Everything in the GrDebugGL object would then need to be
// moved to a GrContextObj and the GrDebugGL object would just switch
// between them. Note that this approach would also require that
diff --git a/src/gpu/gl/egl/SkNativeGLContext_egl.cpp b/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp
index d4d7219b5b..f33e84abc4 100644
--- a/src/gpu/gl/egl/SkNativeGLContext_egl.cpp
+++ b/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp
@@ -5,34 +5,42 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include "gl/SkNativeGLContext.h"
+#include "gl/SkGLContext.h"
-SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
- fOldEGLContext = eglGetCurrentContext();
- fOldDisplay = eglGetCurrentDisplay();
- fOldSurface = eglGetCurrentSurface(EGL_DRAW);
+#include <GLES2/gl2.h>
+#include <EGL/egl.h>
-}
+namespace {
-SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
- if (fOldDisplay) {
- eglMakeCurrent(fOldDisplay, fOldSurface, fOldSurface, fOldEGLContext);
- }
-}
+class EGLGLContext : public SkGLContext {
+public:
+ EGLGLContext();
+
+ virtual ~EGLGLContext();
+
+ 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;
-///////////////////////////////////////////////////////////////////////////////
+private:
+ EGLContext fContext;
+ EGLDisplay fDisplay;
+ EGLSurface fSurface;
+};
-SkNativeGLContext::SkNativeGLContext()
+EGLGLContext::EGLGLContext()
: fContext(EGL_NO_CONTEXT)
, fDisplay(EGL_NO_DISPLAY)
, fSurface(EGL_NO_SURFACE) {
}
-SkNativeGLContext::~SkNativeGLContext() {
+EGLGLContext::~EGLGLContext() {
this->destroyGLContext();
}
-void SkNativeGLContext::destroyGLContext() {
+void EGLGLContext::destroyGLContext() {
if (fDisplay) {
eglMakeCurrent(fDisplay, 0, 0, 0);
@@ -51,7 +59,7 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+const GrGLInterface* EGLGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
static const EGLint kEGLContextAttribsForOpenGL[] = {
EGL_NONE
};
@@ -169,14 +177,21 @@ const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
return interface;
}
-void SkNativeGLContext::makeCurrent() const {
+void EGLGLContext::makeCurrent() const {
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
SkDebugf("Could not set the context.\n");
}
}
-void SkNativeGLContext::swapBuffers() const {
+void EGLGLContext::swapBuffers() const {
if (!eglSwapBuffers(fDisplay, fSurface)) {
SkDebugf("Could not complete eglSwapBuffers.\n");
}
}
+
+} // anonymous namespace
+
+SkGLContext* SkCreatePlatformGLContext() {
+ return SkNEW(EGLGLContext);
+}
+
diff --git a/src/gpu/gl/glx/SkNativeGLContext_glx.cpp b/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp
index bd130b545c..794cdb6f03 100644
--- a/src/gpu/gl/glx/SkNativeGLContext_glx.cpp
+++ b/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp
@@ -5,25 +5,38 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include "gl/SkNativeGLContext.h"
+#include "gl/SkGLContext.h"
+#include <X11/Xlib.h>
+#include <GL/glx.h>
#include <GL/glu.h>
-/* Note: Skia requires glx 1.3 or newer */
-
-SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
- fOldGLXContext = glXGetCurrentContext();
- fOldDisplay = glXGetCurrentDisplay();
- fOldDrawable = glXGetCurrentDrawable();
-}
+namespace {
-SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
- if (fOldDisplay) {
- glXMakeCurrent(fOldDisplay, fOldDrawable, fOldGLXContext);
- }
-}
+/* Note: Skia requires glx 1.3 or newer */
-///////////////////////////////////////////////////////////////////////////////
+/* 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)
static bool ctxErrorOccurred = false;
static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
@@ -31,18 +44,37 @@ static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
return 0;
}
-SkNativeGLContext::SkNativeGLContext()
+class GLXGLContext : public SkGLContext {
+public:
+ GLXGLContext();
+
+ virtual ~GLXGLContext();
+
+ 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;
+
+private:
+ GLXContext fContext;
+ Display* fDisplay;
+ Pixmap fPixmap;
+ GLXPixmap fGlxPixmap;
+};
+
+GLXGLContext::GLXGLContext()
: fContext(NULL)
, fDisplay(NULL)
, fPixmap(0)
, fGlxPixmap(0) {
}
-SkNativeGLContext::~SkNativeGLContext() {
+GLXGLContext::~GLXGLContext() {
this->destroyGLContext();
}
-void SkNativeGLContext::destroyGLContext() {
+void GLXGLContext::destroyGLContext() {
if (fDisplay) {
glXMakeCurrent(fDisplay, 0, 0);
@@ -66,7 +98,7 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+const GrGLInterface* GLXGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
fDisplay = XOpenDisplay(0);
if (!fDisplay) {
@@ -277,12 +309,18 @@ const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
return interface;
}
-void SkNativeGLContext::makeCurrent() const {
+void GLXGLContext::makeCurrent() const {
if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) {
SkDebugf("Could not set the context.\n");
}
}
-void SkNativeGLContext::swapBuffers() const {
+void GLXGLContext::swapBuffers() const {
glXSwapBuffers(fDisplay, fGlxPixmap);
}
+
+} // anonymous namespace
+
+SkGLContext* SkCreatePlatformGLContext() {
+ return SkNEW(GLXGLContext);
+}
diff --git a/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm b/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm
index 1bdaf70f1c..9989957ac9 100644
--- a/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm
+++ b/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm
@@ -6,36 +6,38 @@
* found in the LICENSE file.
*/
-#include "gl/SkNativeGLContext.h"
+#include "gl/SkGLContext.h"
#import <OpenGLES/EAGL.h>
#define EAGLCTX ((EAGLContext*)(fEAGLContext))
-SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
- fEAGLContext = [EAGLContext currentContext];
- if (EAGLCTX) {
- [EAGLCTX retain];
- }
-}
+namespace {
-SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
- if (EAGLCTX) {
- [EAGLContext setCurrentContext:EAGLCTX];
- [EAGLCTX release];
- }
-}
+class IOSGLContext : public SkGLContext {
+public:
+ IOSGLContext();
+
+ virtual ~IOSGLContext();
-///////////////////////////////////////////////////////////////////////////////
+ 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;
-SkNativeGLContext::SkNativeGLContext()
+private:
+ void* fEAGLContext;
+};
+
+IOSGLContext::IOSGLContext()
: fEAGLContext(NULL) {
}
-SkNativeGLContext::~SkNativeGLContext() {
+IOSGLContext::~IOSGLContext() {
this->destroyGLContext();
}
-void SkNativeGLContext::destroyGLContext() {
+void IOSGLContext::destroyGLContext() {
if (fEAGLContext) {
if ([EAGLContext currentContext] == EAGLCTX) {
[EAGLContext setCurrentContext:nil];
@@ -45,7 +47,7 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+const GrGLInterface* IOSGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
if (kGL_GrGLStandard == forcedGpuAPI) {
return NULL;
}
@@ -62,10 +64,18 @@ const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
return interface;
}
-void SkNativeGLContext::makeCurrent() const {
+void IOSGLContext::makeCurrent() const {
if (![EAGLContext setCurrentContext:EAGLCTX]) {
SkDebugf("Could not set the context.\n");
}
}
-void SkNativeGLContext::swapBuffers() const { }
+void IOSGLContext::swapBuffers() const { }
+
+} // anonymous namespace
+
+
+SkGLContext* SkCreatePlatformGLContext() {
+ return SkNEW(IOSGLContext);
+}
+
diff --git a/src/gpu/gl/mac/SkNativeGLContext_mac.cpp b/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp
index f63471c16a..35ec276296 100644
--- a/src/gpu/gl/mac/SkNativeGLContext_mac.cpp
+++ b/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp
@@ -5,34 +5,43 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include "gl/SkNativeGLContext.h"
+#include "gl/SkGLContext.h"
#include "AvailabilityMacros.h"
-SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
- fOldCGLContext = CGLGetCurrentContext();
-}
+#include <OpenGL/OpenGL.h>
-SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
- CGLSetCurrentContext(fOldCGLContext);
-}
+namespace {
+class MacGLContext : public SkGLContext {
+public:
+ MacGLContext();
+
+ virtual ~MacGLContext();
+
+ 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;
-///////////////////////////////////////////////////////////////////////////////
+private:
+ CGLContextObj fContext;
+};
-SkNativeGLContext::SkNativeGLContext()
+MacGLContext::MacGLContext()
: fContext(NULL) {
}
-SkNativeGLContext::~SkNativeGLContext() {
+MacGLContext::~MacGLContext() {
this->destroyGLContext();
}
-void SkNativeGLContext::destroyGLContext() {
+void MacGLContext::destroyGLContext() {
if (fContext) {
CGLReleaseContext(fContext);
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+const GrGLInterface* MacGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
SkASSERT(NULL == fContext);
if (kGLES_GrGLStandard == forcedGpuAPI) {
return NULL;
@@ -75,10 +84,16 @@ const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
return interface;
}
-void SkNativeGLContext::makeCurrent() const {
+void MacGLContext::makeCurrent() const {
CGLSetCurrentContext(fContext);
}
-void SkNativeGLContext::swapBuffers() const {
+void MacGLContext::swapBuffers() const {
CGLFlushDrawable(fContext);
}
+
+} // anonymous namespace
+
+SkGLContext* SkCreatePlatformGLContext() {
+ return SkNEW(MacGLContext);
+}
diff --git a/src/gpu/gl/mesa/SkMesaGLContext.cpp b/src/gpu/gl/mesa/SkMesaGLContext.cpp
index 31402c5a3c..8c339c7fac 100644
--- a/src/gpu/gl/mesa/SkMesaGLContext.cpp
+++ b/src/gpu/gl/mesa/SkMesaGLContext.cpp
@@ -11,24 +11,6 @@
#include "gl/SkMesaGLContext.h"
#include "gl/GrGLDefines.h"
-SkMesaGLContext::AutoContextRestore::AutoContextRestore() {
- fOldContext = (Context)OSMesaGetCurrentContext();
- if (fOldContext) {
- OSMesaGetColorBuffer((OSMesaContext)fOldContext,
- &fOldWidth, &fOldHeight,
- &fOldFormat, &fOldImage);
- }
-}
-
-SkMesaGLContext::AutoContextRestore::~AutoContextRestore() {
- if (fOldContext) {
- OSMesaMakeCurrent((OSMesaContext)fOldContext, fOldImage,
- fOldFormat, fOldWidth, fOldHeight);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
SkMesaGLContext::SkMesaGLContext()
: fContext(static_cast<Context>(NULL))
, fImage(NULL) {
diff --git a/src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp b/src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp
new file mode 100644
index 0000000000..5e4b2e4917
--- /dev/null
+++ b/src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp
@@ -0,0 +1,60 @@
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "gl/SkGLContext.h"
+
+#include <GLES2/gl2.h>
+#include <EGL/egl.h>
+
+namespace {
+class NACLGLContext : public SkGLContext {
+public:
+ SkGLContextEGL();
+
+ virtual ~NACLGLContext();
+
+ 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;
+
+private:
+ EGLContext fContext;
+ EGLDisplay fDisplay;
+ EGLSurface fSurface;
+};
+
+NACLGLContext::NACLGLContext()
+ : fContext(NULL)
+ , fDisplay(NULL)
+{
+}
+
+NACLGLContext::~NACLGLContext() {
+ this->destroyGLContext();
+}
+
+void NACLGLContext::destroyGLContext() {
+}
+
+const GrGLInterface* NACLGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+ return NULL;
+}
+
+void NACLGLContext::makeCurrent() const {
+}
+
+void NACLGLContext::swapBuffers() const {
+}
+
+} // anonymous namespace
+
+NACLGLContext* SkCreatePlatformGLContext() {
+ return SkNEW(NACLGLContext);
+}
+
diff --git a/src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp b/src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp
deleted file mode 100644
index 334be1d954..0000000000
--- a/src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "gl/SkNativeGLContext.h"
-
-SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
-}
-
-SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
-}
-
-SkNativeGLContext::SkNativeGLContext()
- : fContext(NULL)
- , fDisplay(NULL)
-{
-}
-
-SkNativeGLContext::~SkNativeGLContext() {
- this->destroyGLContext();
-}
-
-void SkNativeGLContext::destroyGLContext() {
-}
-
-const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
- return NULL;
-}
-
-void SkNativeGLContext::makeCurrent() const {
-}
-
-void SkNativeGLContext::swapBuffers() const {
-}
diff --git a/src/gpu/gl/win/SkNativeGLContext_win.cpp b/src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp
index ab66ba4d55..d362556a4e 100644
--- a/src/gpu/gl/win/SkNativeGLContext_win.cpp
+++ b/src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp
@@ -6,36 +6,51 @@
* found in the LICENSE file.
*/
-#include "gl/SkNativeGLContext.h"
+#include "gl/SkGLContext.h"
+
+#include <windows.h>
+#include <GL/GL.h>
+#include "SkWGL.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
- fOldHGLRC = wglGetCurrentContext();
- fOldHDC = wglGetCurrentDC();
-}
+namespace {
-SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
- wglMakeCurrent(fOldHDC, fOldHGLRC);
-}
+class WinGLContext : public SkGLContext {
+public:
+ WinGLContext();
+
+ virtual ~WinGLContext();
-///////////////////////////////////////////////////////////////////////////////
+ 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;
-ATOM SkNativeGLContext::gWC = 0;
+private:
+ HWND fWindow;
+ HDC fDeviceContext;
+ HGLRC fGlRenderContext;
+ static ATOM gWC;
+ SkWGLPbufferContext* fPbufferContext;
+};
-SkNativeGLContext::SkNativeGLContext()
+ATOM WinGLContext::gWC = 0;
+
+WinGLContext::WinGLContext()
: fWindow(NULL)
, fDeviceContext(NULL)
, fGlRenderContext(0)
, fPbufferContext(NULL) {
}
-SkNativeGLContext::~SkNativeGLContext() {
+WinGLContext::~WinGLContext() {
this->destroyGLContext();
}
-void SkNativeGLContext::destroyGLContext() {
+void WinGLContext::destroyGLContext() {
SkSafeSetNull(fPbufferContext);
if (fGlRenderContext) {
wglDeleteContext(fGlRenderContext);
@@ -51,7 +66,7 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+const GrGLInterface* WinGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
if (!gWC) {
@@ -134,7 +149,7 @@ const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP
return interface;
}
-void SkNativeGLContext::makeCurrent() const {
+void WinGLContext::makeCurrent() const {
HDC dc;
HGLRC glrc;
@@ -151,7 +166,7 @@ void SkNativeGLContext::makeCurrent() const {
}
}
-void SkNativeGLContext::swapBuffers() const {
+void WinGLContext::swapBuffers() const {
HDC dc;
if (NULL == fPbufferContext) {
@@ -163,3 +178,10 @@ void SkNativeGLContext::swapBuffers() const {
SkDebugf("Could not complete SwapBuffers.\n");
}
}
+
+} // anonymous namespace
+
+SkGLContext* SkCreatePlatformGLContext() {
+ return SkNEW(WinGLContext);
+}
+