17#import <GLKit/GLKit.h>
18#import <UIKit/UIKit.h>
19#import <OpenGLES/ES3/gl.h>
21#include <CoreFoundation/CoreFoundation.h>
24 [view setDrawableColorFormat:GLKViewDrawableColorFormatRGBA8888];
25 [view setDrawableDepthFormat:GLKViewDrawableDepthFormat24];
26 [view setDrawableStencilFormat:GLKViewDrawableStencilFormat8];
30 static constexpr int kStencilBits = 8;
37 glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fboid);
56 - (void)drawRect:(CGRect)
rect;
60 withEAGLContext:(EAGLContext*)eaglContext
69 withEAGLContext:(EAGLContext*)eaglContext
71 self = [
super initWithFrame:frame context:eaglContext];
77- (void)drawRect:(CGRect)
rect {
79 static constexpr double kFrameRate = 1.0 / 30.0;
82 [
super drawRect:rect];
85 height = (
int)[
self drawableHeight];
87 NSLog(
@"Error: GrDirectContext missing.\n");
91 [viewController
draw:rect
93 atSize:CGSize{(CGFloat)width, (CGFloat)height}];
97 [NSTimer scheduledTimerWithTimeInterval:std::max(0.0, next - SkTime::GetNSecs() * 1e-9)
99 selector:@selector(setNeedsDisplay)
107 @property (strong) EAGLContext* eaglContext;
108 - (instancetype)
init;
116- (instancetype)
init {
118 [
self setEaglContext:[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]];
119 if (![
self eaglContext]) {
120 NSLog(
@"Falling back to GLES2.\n");
121 [
self setEaglContext:[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]];
123 if (![
self eaglContext]) {
124 NSLog(
@"[[EAGLContext alloc] initWithAPI:...] failed");
127 EAGLContext* oldContext = [EAGLContext currentContext];
128 [EAGLContext setCurrentContext:[
self eaglContext]];
130 [EAGLContext setCurrentContext:oldContext];
132 NSLog(
@"GrDirectContexts::MakeGL failed");
141 withDirectContext:fDContext.get()];
142 [skiaView setController:vc];
static constexpr int kSampleCount
@ kBottomLeft_GrSurfaceOrigin
static float next(float f)
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
static void configure_glkview_for_skia(GLKView *view)
static sk_sp< SkSurface > make_gl_surface(GrDirectContext *dContext, int width, int height)
SkiaContext * MakeSkiaGLContext()
GrDirectContext * fDContext
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
EAGLContext * eaglContext
SkiaViewController * controller
void draw:toCanvas:atSize:(CGRect rect,[toCanvas] SkCanvas *canvas,[atSize] CGSize size)
FlutterViewController * viewController
instancetype initWithFrame
SK_API GrBackendRenderTarget MakeGL(int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo &glInfo)
SK_API sk_sp< GrDirectContext > MakeGL(sk_sp< const GrGLInterface >, const GrContextOptions &)
sk_sp< SkBlender > blender SkRect rect
SK_API sk_sp< SkSurface > WrapBackendRenderTarget(GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)