aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/fiddle/mesa_context.cpp
blob: 70ee62bcc80b0778cb871ea30263b74cbfeaeaad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "fiddle_main.h"

#include <GL/osmesa.h>

// create_grcontext implementation for Mesa.
sk_sp<GrContext> create_grcontext() {
    // We just leak the OSMesaContext... the process will die soon anyway.
    if (OSMesaContext osMesaContext = OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr)) {
        static uint32_t buffer[16 * 16];
        OSMesaMakeCurrent(osMesaContext, &buffer, GL_UNSIGNED_BYTE, 16, 16);
    }

    auto osmesa_get = [](void* ctx, const char name[]) {
        SkASSERT(nullptr == ctx);
        SkASSERT(OSMesaGetCurrentContext());
        return OSMesaGetProcAddress(name);
    };
    sk_sp<const GrGLInterface> mesa(GrGLAssembleInterface(nullptr, osmesa_get));
    if (!mesa) {
        return nullptr;
    }
    return sk_sp<GrContext>(GrContext::Create(
                kOpenGL_GrBackend,
                reinterpret_cast<intptr_t>(mesa.get())));
}