| 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 8b3666c497dc6a5acc8f6cdf974af323c93d66a2..e6cc7c7f4b7dfc2b295483b5bfd8614c796a9a61 100644
|
| --- a/src/gpu/gl/mesa/SkMesaGLContext.cpp
|
| +++ b/tools/gpu/gl/mesa/GLContext_mesa.cpp
|
| @@ -8,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 */
|
| @@ -23,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");
|
| @@ -40,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,
|
| @@ -50,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();
|
| @@ -66,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
|
|
|