blob: 70ee62bcc80b0778cb871ea30263b74cbfeaeaad [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.
13sk_sp<GrContext> create_grcontext() {
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
20 auto osmesa_get = [](void* ctx, const char name[]) {
21 SkASSERT(nullptr == ctx);
22 SkASSERT(OSMesaGetCurrentContext());
23 return OSMesaGetProcAddress(name);
24 };
25 sk_sp<const GrGLInterface> mesa(GrGLAssembleInterface(nullptr, osmesa_get));
26 if (!mesa) {
27 return nullptr;
28 }
29 return sk_sp<GrContext>(GrContext::Create(
30 kOpenGL_GrBackend,
31 reinterpret_cast<intptr_t>(mesa.get())));
32}