Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(975)

Unified Diff: src/gpu/gl/egl/SkNativeGLContext_egl.cpp

Issue 630843002: Make the Sk GL context class an abstract base class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/gl/egl/SkNativeGLContext_egl.cpp
diff --git a/src/gpu/gl/egl/SkNativeGLContext_egl.cpp b/src/gpu/gl/egl/SkNativeGLContext_egl.cpp
index d4d7219b5bbbf7a3799e367d7102288cfa382abc..6b488535a50ce9ddebba9fda7281317e0c08ee72 100644
--- a/src/gpu/gl/egl/SkNativeGLContext_egl.cpp
+++ b/src/gpu/gl/egl/SkNativeGLContext_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 SkGLContextEGL : public SkGLContext {
+public:
+ SkGLContextEGL();
+
+ virtual ~SkGLContextEGL();
+
+ 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()
+SkGLContextEGL::SkGLContextEGL()
: fContext(EGL_NO_CONTEXT)
, fDisplay(EGL_NO_DISPLAY)
, fSurface(EGL_NO_SURFACE) {
}
-SkNativeGLContext::~SkNativeGLContext() {
+SkGLContextEGL::~SkGLContextEGL() {
this->destroyGLContext();
}
-void SkNativeGLContext::destroyGLContext() {
+void SkGLContextEGL::destroyGLContext() {
if (fDisplay) {
eglMakeCurrent(fDisplay, 0, 0, 0);
@@ -51,7 +59,7 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+const GrGLInterface* SkGLContextEGL::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 SkGLContextEGL::makeCurrent() const {
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
SkDebugf("Could not set the context.\n");
}
}
-void SkNativeGLContext::swapBuffers() const {
+void SkGLContextEGL::swapBuffers() const {
if (!eglSwapBuffers(fDisplay, fSurface)) {
SkDebugf("Could not complete eglSwapBuffers.\n");
}
}
+
+} // anonymous namespace
+
+SkGLContext* CreateNativeGLContext() {
+ return SkNEW(SkGLContextEGL);
+}
+

Powered by Google App Engine
This is Rietveld 408576698