1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef GLES_WGL_STATE_H 17 #define GLES_WGL_STATE_H 18 19 #if _WIN32 20 21 #include <base/containers/string.h> 22 #include <base/containers/string_view.h> 23 #include <base/containers/vector.h> 24 #include <render/gles/intf_device_gles.h> 25 #include <render/namespace.h> 26 27 RENDER_BEGIN_NAMESPACE() 28 class SwapchainGLES; 29 struct DeviceCreateInfo; 30 struct DevicePlatformData; 31 32 namespace GlesImplementation { 33 struct SurfaceInfo; 34 } // namespace GlesImplementation 35 36 namespace WGLHelpers { 37 class WGLState final { 38 public: 39 WGLState() = default; 40 ~WGLState() = default; 41 void CreateContext(DeviceCreateInfo const& createInfo); 42 bool IsValid(); 43 void GlInitialize(); 44 void DestroyContext(); 45 void SetSwapInterval(uint32_t interval); 46 const DevicePlatformData& GetPlatformData() const; 47 48 void SaveContext(); 49 void SetContext(SwapchainGLES* swapChain); 50 void RestoreContext(); 51 void* ErrorFilter() const; 52 53 bool HasExtension(BASE_NS::string_view) const; 54 55 bool GetSurfaceInformation(HDC surface, GlesImplementation::SurfaceInfo& res) const; 56 57 protected: 58 DevicePlatformDataGL plat_; 59 struct ContextState { 60 HGLRC context { nullptr }; 61 HDC display { nullptr }; 62 }; 63 ContextState oldContext_; 64 ContextState dummyContext_; 65 bool vSync_ = false; 66 bool oldIsSet_ = false; 67 HMODULE glModule_ = NULL; 68 BASE_NS::string extensions_; 69 BASE_NS::vector<BASE_NS::string_view> extensionList_; 70 bool GetInformation(HDC surface, int32_t configId, GlesImplementation::SurfaceInfo& res) const; 71 int ChoosePixelFormat(HDC dc, const BASE_NS::vector<int>& inattributes); 72 bool hasSRGBFB_, hasColorSpace_; 73 }; 74 } // namespace WGLHelpers 75 RENDER_END_NAMESPACE() 76 77 #endif 78 #endif // GLES_WGL_STATE_H