19#import <OpenGLES/ES3/gl.h>
20#import <UIKit/UIKit.h>
31 return [CAEAGLLayer class];
44 ~RasterWindowContext_ios()
override;
49 void onDestroyContext()
override;
51 void resize(
int w,
int h)
override;
54 void onSwapBuffers()
override;
57 UIViewController* fViewController;
59 EAGLContext* fGLContext;
68 , fWindow(
info.fWindow)
69 , fViewController(
info.fViewController)
74 this->initializeContext();
77RasterWindowContext_ios::~RasterWindowContext_ios() {
78 this->destroyContext();
79 [fRasterView removeFromSuperview];
80 [fRasterView release];
87 CGRect frameRect = [fViewController.view frame];
88 fRasterView = [[[
RasterView alloc] initWithFrame:frameRect] initWithWindow:fWindow];
89 [fViewController.view addSubview:fRasterView];
91 fGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
95 SkDebugf(
"Could Not Create OpenGL ES Context\n");
99 if (![EAGLContext setCurrentContext:fGLContext]) {
100 SkDebugf(
"Could Not Set OpenGL ES Context As Current\n");
101 this->onDestroyContext();
106 CAEAGLLayer* eaglLayer = (CAEAGLLayer*)fRasterView.layer;
107 eaglLayer.drawableProperties = @{kEAGLDrawablePropertyRetainedBacking : @NO,
108 kEAGLDrawablePropertyColorFormat : kEAGLColorFormatRGBA8 };
109 eaglLayer.opaque = YES;
110 eaglLayer.frame = frameRect;
111 eaglLayer.contentsGravity = kCAGravityTopLeft;
114 glGenFramebuffers(1, &fFramebuffer);
115 glBindFramebuffer(GL_FRAMEBUFFER, fFramebuffer);
117 glGenRenderbuffers(1, &fRenderbuffer);
118 glBindRenderbuffer(GL_RENDERBUFFER, fRenderbuffer);
119 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fRenderbuffer);
121 [fGLContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer];
123 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
124 if (status != GL_FRAMEBUFFER_COMPLETE) {
126 this->onDestroyContext();
131 glClearColor(0, 0, 0, 255);
132 glStencilMask(0xffffffff);
133 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
138 fWidth = fViewController.view.frame.size.width;
139 fHeight = fViewController.view.frame.size.height;
141 glViewport(0, 0, fWidth, fHeight);
150void RasterWindowContext_ios::onDestroyContext() {
151 glDeleteFramebuffers(1, &fFramebuffer);
152 glDeleteRenderbuffers(1, &fRenderbuffer);
153 [EAGLContext setCurrentContext:nil];
154 [fGLContext release];
159 return fBackbufferSurface;
162void RasterWindowContext_ios::onSwapBuffers() {
163 if (fBackbufferSurface) {
165 sk_sp<SkImage> snapshot = fBackbufferSurface->makeImageSnapshot();
171 dContext->flushAndSubmit();
173 glBindRenderbuffer(GL_RENDERBUFFER, fRenderbuffer);
174 [fGLContext presentRenderbuffer:GL_RENDERBUFFER];
178void RasterWindowContext_ios::resize(
int w,
int h) {
181 GLWindowContext::resize(
w,
h);
190 std::unique_ptr<WindowContext> ctx(
new RasterWindowContext_ios(
info,
params));
191 if (!ctx->isValid()) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
virtual GrRecordingContext * recordingContext() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
const EmbeddedViewParams * params
SK_API sk_sp< const GrGLInterface > MakeIOS()
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
std::unique_ptr< WindowContext > MakeRasterForIOS(const IOSWindowInfo &info, const DisplayParams ¶ms)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)