blob: 89902ec711ed505c3da77851d344b31a7e42f9bf [file] [log] [blame]
Joe Gregorioa8fabd32017-05-31 09:45:19 -04001/*
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.
Joe Gregorio97b10ac2017-06-01 13:24:11 -040013sk_sp<GrContext> create_grcontext(std::ostringstream &driverinfo) {
Joe Gregorioa8fabd32017-05-31 09:45:19 -040014 // 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 }
Joe Gregorio97b10ac2017-06-01 13:24:11 -040019 driverinfo << "Mesa";
Joe Gregorioa8fabd32017-05-31 09:45:19 -040020
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 }
Greg Daniel02611d92017-07-25 10:05:01 -040030 return GrContext::MakeGL(mesa.get());
Joe Gregorioa8fabd32017-05-31 09:45:19 -040031}