author Mozilla Releng Treescript <>
Tue, 16 Aug 2022 19:03:11 +0000
changeset 627318 a51ffdf576ee6dde088f4a39c8e0d7d37844a830
parent 460654 cf7f4cea93be4a11ecb91c916a0514e403edd042
permissions -rw-r--r--
no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD cy -> fe475b7bab2af983d4cee8e65e4972bfbcf66cec en-CA -> a3ef65c7edaf9177bc6d86a575da123b8724a329 en-GB -> a5a0d021121c2b7a8df335e57bfb0b432f7c7ca4 fr -> 4970122e206d2d09f9c62e143b6c762f0cbe1a9a fy-NL -> 291db3aaa83f252be9f5da671b265bb6fb45a28c gn -> 788acda2302098b31a0812bac3041737be91f8e3 it -> 12c20d432cac1df7c787e5c3d3aa112079c2378d nn-NO -> 2b14fbbce8aab53ad5eebbe7c2f13022a0fddd0f si -> 579629b003e5dd54eefdef80b4fd0c41bc167ee7 tr -> 1ace5ae3f35fafb4c08e4f2c6b43f87716f2bd7e

/* -*- 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 */

#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;

struct PBufferDC final : public ScopedDC
    const HWND mWindow;

    PBufferDC() = delete;
class WGLLibrary {
  ~WGLLibrary() { Reset(); }

  void Reset();

  struct {
    HGLRC(GLAPIENTRY* fCreateContext)(HDC);
    BOOL(GLAPIENTRY* fDeleteContext)(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 hDevice, void* dxObject, GLuint name, GLenum type, GLenum access);
    BOOL(GLAPIENTRY* fDXUnregisterObjectNV)(HANDLE hDevice, HANDLE hObject);
    BOOL(GLAPIENTRY* fDXObjectAccessNV)(HANDLE hObject, GLenum access);
    (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;

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

// a global WGLLibrary instance
extern WGLLibrary sWGLLib;

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