| 1 |
/* |
| 2 |
* Copyright 2024 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef MacWindowGLUtils_DEFINED |
| 9 |
#define MacWindowGLUtils_DEFINED |
| 10 |
|
| 11 |
#include "include/private/base/SkAssert.h" |
| 12 |
|
| 13 |
#include <Cocoa/Cocoa.h> |
| 14 |
|
| 15 |
// All of NSOpenGL is deprecated. |
| 16 |
#pragma clang diagnostic push |
| 17 |
#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 18 |
|
| 19 |
namespace skwindow { |
| 20 |
|
| 21 |
static inline NSOpenGLPixelFormat* GetGLPixelFormat(int sampleCount) { |
| 22 |
constexpr int kMaxAttributes = 19; |
| 23 |
NSOpenGLPixelFormatAttribute attributes[kMaxAttributes]; |
| 24 |
int numAttributes = 0; |
| 25 |
attributes[numAttributes++] = NSOpenGLPFAAccelerated; |
| 26 |
attributes[numAttributes++] = NSOpenGLPFAClosestPolicy; |
| 27 |
attributes[numAttributes++] = NSOpenGLPFADoubleBuffer; |
| 28 |
attributes[numAttributes++] = NSOpenGLPFAOpenGLProfile; |
| 29 |
attributes[numAttributes++] = NSOpenGLProfileVersion3_2Core; |
| 30 |
attributes[numAttributes++] = NSOpenGLPFAColorSize; |
| 31 |
attributes[numAttributes++] = 24; |
| 32 |
attributes[numAttributes++] = NSOpenGLPFAAlphaSize; |
| 33 |
attributes[numAttributes++] = 8; |
| 34 |
attributes[numAttributes++] = NSOpenGLPFADepthSize; |
| 35 |
attributes[numAttributes++] = 0; |
| 36 |
attributes[numAttributes++] = NSOpenGLPFAStencilSize; |
| 37 |
attributes[numAttributes++] = 8; |
| 38 |
if (sampleCount > 1) { |
| 39 |
attributes[numAttributes++] = NSOpenGLPFAMultisample; |
| 40 |
attributes[numAttributes++] = NSOpenGLPFASampleBuffers; |
| 41 |
attributes[numAttributes++] = 1; |
| 42 |
attributes[numAttributes++] = NSOpenGLPFASamples; |
| 43 |
attributes[numAttributes++] = sampleCount; |
| 44 |
} else { |
| 45 |
attributes[numAttributes++] = NSOpenGLPFASampleBuffers; |
| 46 |
attributes[numAttributes++] = 0; |
| 47 |
} |
| 48 |
attributes[numAttributes++] = 0; |
| 49 |
SkASSERT(numAttributes <= kMaxAttributes); |
| 50 |
return [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; |
| 51 |
} |
| 52 |
|
| 53 |
} // namespace skwindow |
| 54 |
|
| 55 |
#pragma clang diagnostic pop |
| 56 |
|
| 57 |
#endif |