Joe Gregorio | a8fabd3 | 2017-05-31 09:45:19 -0400 | [diff] [blame] | 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. |
Joe Gregorio | 97b10ac | 2017-06-01 13:24:11 -0400 | [diff] [blame] | 13 | sk_sp<GrContext> create_grcontext(std::ostringstream &driverinfo) { |
Joe Gregorio | a8fabd3 | 2017-05-31 09:45:19 -0400 | [diff] [blame] | 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 | } |
Joe Gregorio | 97b10ac | 2017-06-01 13:24:11 -0400 | [diff] [blame] | 19 | driverinfo << "Mesa"; |
Joe Gregorio | a8fabd3 | 2017-05-31 09:45:19 -0400 | [diff] [blame] | 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 | } |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 30 | return GrContext::MakeGL(mesa.get()); |
Joe Gregorio | a8fabd3 | 2017-05-31 09:45:19 -0400 | [diff] [blame] | 31 | } |