Home | History | Annotate | Download | only in fiddle
      1 /*
      2  * Copyright 2017 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "fiddle_main.h"
      9 
     10 #include <GL/osmesa.h>
     11 
     12 // create_grcontext implementation for Mesa.
     13 sk_sp<GrContext> create_grcontext(std::ostringstream &driverinfo) {
     14     // We just leak the OSMesaContext... the process will die soon anyway.
     15     if (OSMesaContext osMesaContext = OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr)) {
     16         static uint32_t buffer[16 * 16];
     17         OSMesaMakeCurrent(osMesaContext, &buffer, GL_UNSIGNED_BYTE, 16, 16);
     18     }
     19     driverinfo << "Mesa";
     20 
     21     auto osmesa_get = [](void* ctx, const char name[]) {
     22         SkASSERT(nullptr == ctx);
     23         SkASSERT(OSMesaGetCurrentContext());
     24         return OSMesaGetProcAddress(name);
     25     };
     26     sk_sp<const GrGLInterface> mesa(GrGLAssembleInterface(nullptr, osmesa_get));
     27     if (!mesa) {
     28         return nullptr;
     29     }
     30     return sk_sp<GrContext>(GrContext::Create(
     31                 kOpenGL_GrBackend,
     32                 reinterpret_cast<intptr_t>(mesa.get())));
     33 }
     34