summaryrefslogtreecommitdiffstats
path: root/ppapi/lib/gl/egl/egldriver.c
blob: 90f573e0cf344b539cc069f2095499262238081e (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/mesa/MesaLib/src/egl/main/egldriver.h"

#include "third_party/mesa/MesaLib/src/egl/main/eglconfig.h"
#include "third_party/mesa/MesaLib/src/egl/main/eglcontext.h"
#include "third_party/mesa/MesaLib/src/egl/main/egldisplay.h"
#include "third_party/mesa/MesaLib/src/egl/main/eglmisc.h"
#include "third_party/mesa/MesaLib/src/egl/main/eglsurface.h"

/**
 * Functions for choosing and opening/loading device drivers.
 */

static _EGLDriver *_eglDriver;

static EGLBoolean _eglLoadDriver() {
  assert(!_eglDriver);

  _eglDriver = _eglMain(NULL);
  return _eglDriver ? EGL_TRUE : EGL_FALSE;
}

/**
 * Match a display to a driver.  The display is initialized unless use_probe is
 * true.
 */

_EGLDriver * _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe) {
  _EGLDriver * drv = NULL;
  EGLint major = 0, minor = 0;

  if (!_eglDriver && !_eglLoadDriver())
    return NULL;

  if (use_probe) {
    if (_eglDriver->Probe)
      _eglDriver->Probe(_eglDriver, dpy);
    drv = _eglDriver;
  } else {
    if (_eglDriver->API.Initialize(_eglDriver, dpy, &major, &minor)) {
      drv = _eglDriver;
      dpy->Driver = drv;
      dpy->Initialized = EGL_TRUE;
      dpy->APImajor = major;
      dpy->APIminor = minor;
    }
  }

  return drv;
}

__eglMustCastToProperFunctionPointerType _eglGetDriverProc(
    const char *procname) {
  _EGLProc proc = NULL;

  return proc;
}

/**
 * Unload all drivers.
 */
void _eglUnloadDrivers(void) {
  if (_eglDriver && _eglDriver->Unload)
    _eglDriver->Unload(_eglDriver);

  _eglDriver = NULL;
}

/**
 * Plug all the available fallback routines into the given driver's
 * dispatch table.
 */
void _eglInitDriverFallbacks(_EGLDriver *drv) {
  /* If a pointer is set to NULL, then the device driver _really_ has
   * to implement it.
   */
  drv->API.Initialize = NULL;
  drv->API.Terminate = NULL;

  drv->API.GetConfigs = _eglGetConfigs;
  drv->API.ChooseConfig = _eglChooseConfig;
  drv->API.GetConfigAttrib = _eglGetConfigAttrib;

  drv->API.CreateContext = _eglCreateContext;
  drv->API.DestroyContext = _eglDestroyContext;
  drv->API.MakeCurrent = _eglMakeCurrent;
  drv->API.QueryContext = _eglQueryContext;

  drv->API.CreateWindowSurface = _eglCreateWindowSurface;
  drv->API.CreatePixmapSurface = _eglCreatePixmapSurface;
  drv->API.CreatePbufferSurface = _eglCreatePbufferSurface;
  drv->API.DestroySurface = _eglDestroySurface;
  drv->API.QuerySurface = _eglQuerySurface;
  drv->API.SurfaceAttrib = _eglSurfaceAttrib;
  drv->API.BindTexImage = _eglBindTexImage;
  drv->API.ReleaseTexImage = _eglReleaseTexImage;
  drv->API.SwapInterval = _eglSwapInterval;
  drv->API.SwapBuffers = _eglSwapBuffers;
  drv->API.CopyBuffers = _eglCopyBuffers;

  drv->API.QueryString = _eglQueryString;
  drv->API.WaitClient = _eglWaitClient;
  drv->API.WaitNative = _eglWaitNative;
}