14#define EGL_PROTECTED_CONTENT_EXT 0x32C0
22 ~GLWindowContext_android()
override;
31 EGLContext fEGLContext;
32 EGLSurface fSurfaceAndroid;
43 , fDisplay(EGL_NO_DISPLAY)
44 , fEGLContext(EGL_NO_CONTEXT)
45 , fSurfaceAndroid(EGL_NO_SURFACE)
50 this->initializeContext();
53GLWindowContext_android::~GLWindowContext_android() {
54 this->destroyContext();
58 fWidth = ANativeWindow_getWidth(fNativeWindow);
59 fHeight = ANativeWindow_getHeight(fNativeWindow);
61 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
65 eglInitialize(fDisplay, &majorVersion, &minorVersion);
67 const char*
extensions = eglQueryString(fDisplay, EGL_EXTENSIONS);
69 if (fDisplayParams.fCreateProtectedNativeBackend &&
70 !strstr(
extensions,
"EGL_EXT_protected_content")) {
71 SkDebugf(
"Protected Context requested but no protected support\n");
72 fDisplayParams.fCreateProtectedNativeBackend =
false;
77 EGLint numConfigs = 0;
78 EGLint eglSampleCnt = fDisplayParams.fMSAASampleCount > 1 ? fDisplayParams.fMSAASampleCount > 1
80 const EGLint configAttribs[] = {
81 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
82 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
88 EGL_SAMPLE_BUFFERS, eglSampleCnt ? 1 : 0,
89 EGL_SAMPLES, eglSampleCnt,
93 EGLConfig surfaceConfig;
94 SkAssertResult(eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs));
97 std::vector<EGLint> kEGLContextAttribsForOpenGLES = {
98 EGL_CONTEXT_CLIENT_VERSION, 2,
101 if (fDisplayParams.fCreateProtectedNativeBackend) {
103 kEGLContextAttribsForOpenGLES.push_back(EGL_TRUE);
106 kEGLContextAttribsForOpenGLES.push_back(EGL_NONE);
108 fEGLContext = eglCreateContext(
109 fDisplay, surfaceConfig,
nullptr, kEGLContextAttribsForOpenGLES.data());
110 SkASSERT(EGL_NO_CONTEXT != fEGLContext);
116 const EGLint surfaceAttribs[] = {
118 fDisplayParams.fCreateProtectedNativeBackend ? EGL_TRUE : EGL_NONE,
122 fSurfaceAndroid = eglCreateWindowSurface(fDisplay, surfaceConfig, fNativeWindow,
124 SkASSERT(EGL_NO_SURFACE != fSurfaceAndroid);
126 SkAssertResult(eglMakeCurrent(fDisplay, fSurfaceAndroid, fSurfaceAndroid, fEGLContext));
131 glClearColor(0, 0, 0, 0);
132 glStencilMask(0xffffffff);
133 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
135 eglGetConfigAttrib(fDisplay, surfaceConfig, EGL_STENCIL_SIZE, &fStencilBits);
136 eglGetConfigAttrib(fDisplay, surfaceConfig, EGL_SAMPLES, &fSampleCount);
137 fSampleCount =
std::max(fSampleCount, 1);
139 eglSwapInterval(fDisplay, fDisplayParams.fDisableVsync ? 0 : 1);
144void GLWindowContext_android::onDestroyContext() {
145 if (!fDisplay || !fEGLContext || !fSurfaceAndroid) {
148 eglMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
151 fEGLContext = EGL_NO_CONTEXT;
152 fSurfaceAndroid = EGL_NO_SURFACE;
155void GLWindowContext_android::onSwapBuffers() {
156 if (fDisplay && fEGLContext && fSurfaceAndroid) {
157 eglSwapBuffers(fDisplay, fSurfaceAndroid);
167 std::unique_ptr<WindowContext> ctx(
new GLWindowContext_android(
window,
params));
168 if (!ctx->isValid()) {
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define EGL_PROTECTED_CONTENT_EXT
SK_API sk_sp< const GrGLInterface > GrGLMakeNativeInterface()
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define INHERITED(method,...)
virtual void onSwapBuffers()=0
virtual sk_sp< const GrGLInterface > onInitializeContext()=0
GLWindowContext(const DisplayParams &)
virtual void onDestroyContext()=0
const EmbeddedViewParams * params
static float max(float r, float g, float b)
std::unique_ptr< WindowContext > MakeGLForAndroid(ANativeWindow *window, const DisplayParams ¶ms)
struct ANativeWindow ANativeWindow