20#include <Cocoa/Cocoa.h>
35 ~RasterWindowContext_mac()
override;
48 NSOpenGLContext* fGLContext;
49 NSOpenGLPixelFormat* fPixelFormat;
56 , fMainView(
info.fMainView)
61 this->initializeContext();
64RasterWindowContext_mac::~RasterWindowContext_mac() {
65 [NSOpenGLContext clearCurrentContext];
66 [fPixelFormat release];
77 constexpr int kMaxAttributes = 18;
78 NSOpenGLPixelFormatAttribute attributes[kMaxAttributes];
79 int numAttributes = 0;
80 attributes[numAttributes++] = NSOpenGLPFAAccelerated;
81 attributes[numAttributes++] = NSOpenGLPFAClosestPolicy;
82 attributes[numAttributes++] = NSOpenGLPFADoubleBuffer;
83 attributes[numAttributes++] = NSOpenGLPFAOpenGLProfile;
84 attributes[numAttributes++] = NSOpenGLProfileVersion3_2Core;
85 attributes[numAttributes++] = NSOpenGLPFAColorSize;
86 attributes[numAttributes++] = 24;
87 attributes[numAttributes++] = NSOpenGLPFAAlphaSize;
88 attributes[numAttributes++] = 8;
89 attributes[numAttributes++] = NSOpenGLPFADepthSize;
90 attributes[numAttributes++] = 0;
91 attributes[numAttributes++] = NSOpenGLPFAStencilSize;
92 attributes[numAttributes++] = 8;
93 if (fDisplayParams.fMSAASampleCount > 1) {
94 attributes[numAttributes++] = NSOpenGLPFASampleBuffers;
95 attributes[numAttributes++] = 1;
96 attributes[numAttributes++] = NSOpenGLPFASamples;
97 attributes[numAttributes++] = fDisplayParams.fMSAASampleCount;
99 attributes[numAttributes++] = NSOpenGLPFASampleBuffers;
100 attributes[numAttributes++] = 0;
102 attributes[numAttributes++] = 0;
103 SkASSERT(numAttributes <= kMaxAttributes);
105 fPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
106 if (nil == fPixelFormat) {
111 fGLContext = [[NSOpenGLContext alloc] initWithFormat:fPixelFormat shareContext:nil];
112 if (nil == fGLContext) {
113 [fPixelFormat release];
118 [fMainView setWantsBestResolutionOpenGLSurface:YES];
119 [fGLContext setView:fMainView];
121 GLint swapInterval = fDisplayParams.fDisableVsync ? 0 : 1;
122 [fGLContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
126 [fGLContext makeCurrentContext];
129 glClearColor(0, 0, 0, 255);
130 glStencilMask(0xffffffff);
131 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
134 [fPixelFormat getValues:&stencilBits forAttribute:NSOpenGLPFAStencilSize forVirtualScreen:0];
135 fStencilBits = stencilBits;
137 [fPixelFormat getValues:&sampleCount forAttribute:NSOpenGLPFASamples forVirtualScreen:0];
138 fSampleCount = sampleCount;
139 fSampleCount =
std::max(fSampleCount, 1);
142 fWidth = fMainView.bounds.size.width * backingScaleFactor;
143 fHeight = fMainView.bounds.size.height * backingScaleFactor;
144 glViewport(0, 0, fWidth, fHeight);
153sk_sp<SkSurface> RasterWindowContext_mac::getBackbufferSurface() {
return fBackbufferSurface; }
155void RasterWindowContext_mac::onSwapBuffers() {
156 if (fBackbufferSurface) {
158 sk_sp<SkImage> snapshot = fBackbufferSurface->makeImageSnapshot();
165 [fGLContext flushBuffer];
169void RasterWindowContext_mac::resize(
int w,
int h) {
173 GLWindowContext::resize(0, 0);
182 std::unique_ptr<WindowContext> ctx(
new RasterWindowContext_mac(
info,
params));
183 if (!ctx->isValid()) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
virtual void onSwapBuffers()=0
void resize(int w, int h) override
virtual sk_sp< const GrGLInterface > onInitializeContext()=0
sk_sp< SkSurface > getBackbufferSurface() override
virtual void onDestroyContext()=0
const EmbeddedViewParams * params
static float max(float r, float g, float b)
SK_API sk_sp< const GrGLInterface > MakeMac()
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API GrSemaphoresSubmitted Flush(sk_sp< SkSurface >)
std::unique_ptr< WindowContext > MakeRasterForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
static CGFloat GetBackingScaleFactor(NSView *view)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)