1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // wgl_utils.cpp: Utility routines specific to the WGL->EGL implementation.
8 
9 #include "libANGLE/renderer/gl/wgl/wgl_utils.h"
10 
11 #include "libANGLE/renderer/gl/wgl/FunctionsWGL.h"
12 
13 namespace rx
14 {
15 
16 namespace wgl
17 {
18 
GetDefaultPixelFormatDescriptor()19 PIXELFORMATDESCRIPTOR GetDefaultPixelFormatDescriptor()
20 {
21     PIXELFORMATDESCRIPTOR pixelFormatDescriptor = {};
22     pixelFormatDescriptor.nSize                 = sizeof(pixelFormatDescriptor);
23     pixelFormatDescriptor.nVersion              = 1;
24     pixelFormatDescriptor.dwFlags =
25         PFD_DRAW_TO_WINDOW | PFD_GENERIC_ACCELERATED | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
26     pixelFormatDescriptor.iPixelType   = PFD_TYPE_RGBA;
27     pixelFormatDescriptor.cColorBits   = 24;
28     pixelFormatDescriptor.cAlphaBits   = 8;
29     pixelFormatDescriptor.cDepthBits   = 24;
30     pixelFormatDescriptor.cStencilBits = 8;
31     pixelFormatDescriptor.iLayerType   = PFD_MAIN_PLANE;
32 
33     return pixelFormatDescriptor;
34 }
35 
GetDefaultPixelFormatAttributes(bool preservedSwap)36 std::vector<int> GetDefaultPixelFormatAttributes(bool preservedSwap)
37 {
38     std::vector<int> attribs;
39     attribs.push_back(WGL_DRAW_TO_WINDOW_ARB);
40     attribs.push_back(TRUE);
41 
42     attribs.push_back(WGL_ACCELERATION_ARB);
43     attribs.push_back(WGL_FULL_ACCELERATION_ARB);
44 
45     attribs.push_back(WGL_SUPPORT_OPENGL_ARB);
46     attribs.push_back(TRUE);
47 
48     attribs.push_back(WGL_DOUBLE_BUFFER_ARB);
49     attribs.push_back(TRUE);
50 
51     attribs.push_back(WGL_PIXEL_TYPE_ARB);
52     attribs.push_back(WGL_TYPE_RGBA_ARB);
53 
54     attribs.push_back(WGL_COLOR_BITS_ARB);
55     attribs.push_back(24);
56 
57     attribs.push_back(WGL_ALPHA_BITS_ARB);
58     attribs.push_back(8);
59 
60     attribs.push_back(WGL_DEPTH_BITS_ARB);
61     attribs.push_back(24);
62 
63     attribs.push_back(WGL_STENCIL_BITS_ARB);
64     attribs.push_back(8);
65 
66     attribs.push_back(WGL_SWAP_METHOD_ARB);
67     attribs.push_back(preservedSwap ? WGL_SWAP_COPY_ARB : WGL_SWAP_UNDEFINED_ARB);
68 
69     attribs.push_back(0);
70 
71     return attribs;
72 }
73 
QueryWGLFormatAttrib(HDC dc,int format,int attribName,const FunctionsWGL * functions)74 int QueryWGLFormatAttrib(HDC dc, int format, int attribName, const FunctionsWGL *functions)
75 {
76     int result = 0;
77     if (functions->getPixelFormatAttribivARB == nullptr ||
78         !functions->getPixelFormatAttribivARB(dc, format, 0, 1, &attribName, &result))
79     {
80         return 0;
81     }
82     return result;
83 }
84 }  // namespace wgl
85 
86 }  // namespace rx
87