summaryrefslogtreecommitdiffstats
path: root/gfx/gl/WGLLibrary.h
blob: 82c764b3dba884656de7431fa9728561704666f1 (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
109
110
111
112
113
114
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "GLContextTypes.h"
#include "GLLibraryLoader.h"
#include "mozilla/UniquePtr.h"
#include <windows.h>

struct PRLibrary;

namespace mozilla {
namespace gl {
/*
struct ScopedDC
{
    const HDC mDC;

    ScopedDC() = delete;
    virtual ~ScopedDC() = 0;
};

struct WindowDC final : public ScopedDC
{
    const HWND mWindow;

    WindowDC() = delete;
    ~WindowDC();
};

struct PBufferDC final : public ScopedDC
{
    const HWND mWindow;

    PBufferDC() = delete;
    ~PBufferDC();
};
*/
class WGLLibrary {
 public:
  ~WGLLibrary() { Reset(); }

 private:
  void Reset();

 public:
  struct {
    HGLRC(GLAPIENTRY* fCreateContext)(HDC);
    BOOL(GLAPIENTRY* fDeleteContext)(HGLRC);
    BOOL(GLAPIENTRY* fMakeCurrent)(HDC, HGLRC);
    PROC(GLAPIENTRY* fGetProcAddress)(LPCSTR);
    HGLRC(GLAPIENTRY* fGetCurrentContext)(void);
    HDC(GLAPIENTRY* fGetCurrentDC)(void);
    // BOOL   (GLAPIENTRY * fShareLists) (HGLRC oldContext, HGLRC newContext);
    HANDLE(GLAPIENTRY* fCreatePbuffer)
    (HDC hDC, int iPixelFormat, int iWidth, int iHeight,
     const int* piAttribList);
    BOOL(GLAPIENTRY* fDestroyPbuffer)(HANDLE hPbuffer);
    HDC(GLAPIENTRY* fGetPbufferDC)(HANDLE hPbuffer);
    int(GLAPIENTRY* fReleasePbufferDC)(HANDLE hPbuffer, HDC dc);
    // BOOL (GLAPIENTRY * fBindTexImage) (HANDLE hPbuffer, int iBuffer);
    // BOOL (GLAPIENTRY * fReleaseTexImage) (HANDLE hPbuffer, int iBuffer);
    BOOL(GLAPIENTRY* fChoosePixelFormat)
    (HDC hdc, const int* piAttribIList, const FLOAT* pfAttribFList,
     UINT nMaxFormats, int* piFormats, UINT* nNumFormats);
    // BOOL (GLAPIENTRY * fGetPixelFormatAttribiv) (HDC hdc,
    //                                             int iPixelFormat,
    //                                             int iLayerPlane,
    //                                             UINT nAttributes,
    //                                             int* piAttributes,
    //                                             int* piValues);
    const char*(GLAPIENTRY* fGetExtensionsStringARB)(HDC hdc);
    HGLRC(GLAPIENTRY* fCreateContextAttribsARB)
    (HDC hdc, HGLRC hShareContext, const int* attribList);
    // WGL_NV_DX_interop:
    BOOL(GLAPIENTRY* fDXSetResourceShareHandleNV)
    (void* dxObject, HANDLE shareHandle);
    HANDLE(GLAPIENTRY* fDXOpenDeviceNV)(void* dxDevice);
    BOOL(GLAPIENTRY* fDXCloseDeviceNV)(HANDLE hDevice);
    HANDLE(GLAPIENTRY* fDXRegisterObjectNV)
    (HANDLE hDevice, void* dxObject, GLuint name, GLenum type, GLenum access);
    BOOL(GLAPIENTRY* fDXUnregisterObjectNV)(HANDLE hDevice, HANDLE hObject);
    BOOL(GLAPIENTRY* fDXObjectAccessNV)(HANDLE hObject, GLenum access);
    BOOL(GLAPIENTRY* fDXLockObjectsNV)
    (HANDLE hDevice, GLint count, HANDLE* hObjects);
    BOOL(GLAPIENTRY* fDXUnlockObjectsNV)
    (HANDLE hDevice, GLint count, HANDLE* hObjects);
  } mSymbols = {};

  bool EnsureInitialized();
  // UniquePtr<WindowDC> CreateDummyWindow();
  HGLRC CreateContextWithFallback(HDC dc, bool tryRobustBuffers) const;

  bool HasDXInterop2() const { return bool(mSymbols.fDXOpenDeviceNV); }
  bool IsInitialized() const { return mInitialized; }
  auto GetOGLLibrary() const { return mOGLLibrary; }
  auto RootDc() const { return mRootDc; }
  SymbolLoader GetSymbolLoader() const;

 private:
  bool mInitialized = false;
  PRLibrary* mOGLLibrary;
  bool mHasRobustness;
  HWND mDummyWindow;
  HDC mRootDc;
  HGLRC mDummyGlrc;
};

// a global WGLLibrary instance
extern WGLLibrary sWGLLib;

} /* namespace gl */
} /* namespace mozilla */