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

Unified Diff: tools/gpu/gl/mesa/GLContext_mesa.cpp

Issue 1815823002: Move SkGLContext and some GrGLInterface implementations to skgputest module (Closed) Base URL: https://chromium.googlesource.com/skia.git@debugobject
Patch Set: fix windows and android? Created 4 years, 9 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
« no previous file with comments | « tools/gpu/gl/mesa/GLContext_mesa.h ('k') | tools/gpu/gl/mesa/osmesa_wrapper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gpu/gl/mesa/GLContext_mesa.cpp
diff --git a/src/gpu/gl/mesa/SkMesaGLContext.cpp b/tools/gpu/gl/mesa/GLContext_mesa.cpp
similarity index 52%
rename from src/gpu/gl/mesa/SkMesaGLContext.cpp
rename to tools/gpu/gl/mesa/GLContext_mesa.cpp
index eeccbd64ae6964a84ca15bbf0269b6259acd92e6..e6cc7c7f4b7dfc2b295483b5bfd8614c796a9a61 100644
--- a/src/gpu/gl/mesa/SkMesaGLContext.cpp
+++ b/tools/gpu/gl/mesa/GLContext_mesa.cpp
@@ -1,3 +1,4 @@
+
/*
* Copyright 2011 Google Inc.
*
@@ -7,14 +8,52 @@
#include <GL/osmesa.h>
-#include "gl/mesa/SkMesaGLContext.h"
+#include "gl/mesa/GLContext_mesa.h"
#include "gl/GrGLDefines.h"
+#include "gl/GrGLAssembleInterface.h"
+#include "gl/GrGLUtil.h"
+#include "osmesa_wrapper.h"
+
+namespace {
+
+static GrGLFuncPtr osmesa_get(void* ctx, const char name[]) {
+ SkASSERT(nullptr == ctx);
+ SkASSERT(OSMesaGetCurrentContext());
+ return OSMesaGetProcAddress(name);
+}
+
+static const GrGLInterface* create_mesa_interface() {
+ if (nullptr == OSMesaGetCurrentContext()) {
+ return nullptr;
+ }
+ return GrGLAssembleInterface(nullptr, osmesa_get);
+}
+
static const GrGLint gBOGUS_SIZE = 16;
-SkMesaGLContext::SkMesaGLContext()
- : fContext(static_cast<Context>(0))
- , fImage(nullptr) {
+class MesaGLContext : public sk_gpu_test::GLContext {
+private:
+ typedef intptr_t Context;
+
+public:
+ MesaGLContext();
+ ~MesaGLContext() override;
+
+private:
+ void destroyGLContext();
+
+ void onPlatformMakeCurrent() const override;
+
+ void onPlatformSwapBuffers() const override;
+
+ GrGLFuncPtr onPlatformGetProcAddress(const char *) const override;
+
+ Context fContext;
+ GrGLubyte *fImage;
+};
+
+MesaGLContext::MesaGLContext() : fContext(static_cast<Context>(0)), fImage(nullptr) {
GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));
/* Create an RGBA-mode context */
@@ -22,7 +61,7 @@ SkMesaGLContext::SkMesaGLContext()
/* specify Z, stencil, accum sizes */
fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr);
#else
- fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, nullptr);
+ fContext = (Context) OSMesaCreateContext(OSMESA_BGRA, nullptr);
#endif
if (!fContext) {
SkDebugf("OSMesaCreateContext failed!\n");
@@ -39,7 +78,7 @@ SkMesaGLContext::SkMesaGLContext()
}
// Bind the buffer to the context and make it current
- if (!OSMesaMakeCurrent((OSMesaContext)fContext,
+ if (!OSMesaMakeCurrent((OSMesaContext) fContext,
fImage,
GR_GL_UNSIGNED_BYTE,
gBOGUS_SIZE,
@@ -49,7 +88,7 @@ SkMesaGLContext::SkMesaGLContext()
return;
}
- SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface());
+ SkAutoTUnref<const GrGLInterface> gl(create_mesa_interface());
if (nullptr == gl.get()) {
SkDebugf("Could not create GL interface!\n");
this->destroyGLContext();
@@ -65,36 +104,48 @@ SkMesaGLContext::SkMesaGLContext()
this->init(gl.release());
}
-SkMesaGLContext::~SkMesaGLContext() {
+MesaGLContext::~MesaGLContext() {
this->teardown();
this->destroyGLContext();
}
-void SkMesaGLContext::destroyGLContext() {
+void MesaGLContext::destroyGLContext() {
if (fImage) {
sk_free(fImage);
fImage = nullptr;
}
if (fContext) {
- OSMesaDestroyContext((OSMesaContext)fContext);
+ OSMesaDestroyContext((OSMesaContext) fContext);
fContext = static_cast<Context>(0);
}
}
-
-void SkMesaGLContext::onPlatformMakeCurrent() const {
+void MesaGLContext::onPlatformMakeCurrent() const {
if (fContext) {
- if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage,
+ if (!OSMesaMakeCurrent((OSMesaContext) fContext, fImage,
GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
SkDebugf("Could not make MESA context current.");
}
}
}
-void SkMesaGLContext::onPlatformSwapBuffers() const { }
+void MesaGLContext::onPlatformSwapBuffers() const { }
-GrGLFuncPtr SkMesaGLContext::onPlatformGetProcAddress(const char* procName) const {
+GrGLFuncPtr MesaGLContext::onPlatformGetProcAddress(const char *procName) const {
return OSMesaGetProcAddress(procName);
}
+} // anonymous namespace
+
+
+namespace sk_gpu_test {
+GLContext *CreateMesaGLContext() {
+ MesaGLContext *ctx = new MesaGLContext;
+ if (!ctx->isValid()) {
+ delete ctx;
+ return nullptr;
+ }
+ return ctx;
+}
+} // sk_gpu_test
« no previous file with comments | « tools/gpu/gl/mesa/GLContext_mesa.h ('k') | tools/gpu/gl/mesa/osmesa_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698