xref: /aosp_15_r20/frameworks/native/libs/renderengine/skia/SkiaGLRenderEngine.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 //#define LOG_NDEBUG 0
18 #undef LOG_TAG
19 #define LOG_TAG "RenderEngine"
20 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
21 
22 #include "SkiaGLRenderEngine.h"
23 
24 #include <EGL/egl.h>
25 #include <EGL/eglext.h>
26 #include <android-base/stringprintf.h>
27 #include <common/trace.h>
28 #include <include/gpu/ganesh/GrContextOptions.h>
29 #include <include/gpu/ganesh/GrTypes.h>
30 #include <include/gpu/ganesh/gl/GrGLDirectContext.h>
31 #include <include/gpu/ganesh/gl/GrGLInterface.h>
32 #include <log/log_main.h>
33 #include <sync/sync.h>
34 #include <ui/DebugUtils.h>
35 
36 #include <cmath>
37 #include <cstdint>
38 #include <memory>
39 #include <numeric>
40 
41 #include "GLExtensions.h"
42 #include "compat/SkiaGpuContext.h"
43 
44 namespace android {
45 namespace renderengine {
46 namespace skia {
47 
48 using base::StringAppendF;
49 
checkGlError(const char * op,int lineNumber)50 static bool checkGlError(const char* op, int lineNumber) {
51     bool errorFound = false;
52     GLint error = glGetError();
53     while (error != GL_NO_ERROR) {
54         errorFound = true;
55         error = glGetError();
56         ALOGV("after %s() (line # %d) glError (0x%x)\n", op, lineNumber, error);
57     }
58     return errorFound;
59 }
60 
selectConfigForAttribute(EGLDisplay dpy,EGLint const * attrs,EGLint attribute,EGLint wanted,EGLConfig * outConfig)61 static status_t selectConfigForAttribute(EGLDisplay dpy, EGLint const* attrs, EGLint attribute,
62                                          EGLint wanted, EGLConfig* outConfig) {
63     EGLint numConfigs = -1, n = 0;
64     eglGetConfigs(dpy, nullptr, 0, &numConfigs);
65     std::vector<EGLConfig> configs(numConfigs, EGL_NO_CONFIG_KHR);
66     eglChooseConfig(dpy, attrs, configs.data(), configs.size(), &n);
67     configs.resize(n);
68 
69     if (!configs.empty()) {
70         if (attribute != EGL_NONE) {
71             for (EGLConfig config : configs) {
72                 EGLint value = 0;
73                 eglGetConfigAttrib(dpy, config, attribute, &value);
74                 if (wanted == value) {
75                     *outConfig = config;
76                     return NO_ERROR;
77                 }
78             }
79         } else {
80             // just pick the first one
81             *outConfig = configs[0];
82             return NO_ERROR;
83         }
84     }
85 
86     return NAME_NOT_FOUND;
87 }
88 
selectEGLConfig(EGLDisplay display,EGLint format,EGLint renderableType,EGLConfig * config)89 static status_t selectEGLConfig(EGLDisplay display, EGLint format, EGLint renderableType,
90                                 EGLConfig* config) {
91     // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
92     // it is to be used with WIFI displays
93     status_t err;
94     EGLint wantedAttribute;
95     EGLint wantedAttributeValue;
96 
97     std::vector<EGLint> attribs;
98     if (renderableType) {
99         const ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(format);
100         const bool is1010102 = pixelFormat == ui::PixelFormat::RGBA_1010102;
101 
102         // Default to 8 bits per channel.
103         const EGLint tmpAttribs[] = {
104                 EGL_RENDERABLE_TYPE,
105                 renderableType,
106                 EGL_RECORDABLE_ANDROID,
107                 EGL_TRUE,
108                 EGL_SURFACE_TYPE,
109                 EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
110                 EGL_FRAMEBUFFER_TARGET_ANDROID,
111                 EGL_TRUE,
112                 EGL_RED_SIZE,
113                 is1010102 ? 10 : 8,
114                 EGL_GREEN_SIZE,
115                 is1010102 ? 10 : 8,
116                 EGL_BLUE_SIZE,
117                 is1010102 ? 10 : 8,
118                 EGL_ALPHA_SIZE,
119                 is1010102 ? 2 : 8,
120                 EGL_NONE,
121         };
122         std::copy(tmpAttribs, tmpAttribs + (sizeof(tmpAttribs) / sizeof(EGLint)),
123                   std::back_inserter(attribs));
124         wantedAttribute = EGL_NONE;
125         wantedAttributeValue = EGL_NONE;
126     } else {
127         // if no renderable type specified, fallback to a simplified query
128         wantedAttribute = EGL_NATIVE_VISUAL_ID;
129         wantedAttributeValue = format;
130     }
131 
132     err = selectConfigForAttribute(display, attribs.data(), wantedAttribute, wantedAttributeValue,
133                                    config);
134     if (err == NO_ERROR) {
135         EGLint caveat;
136         if (eglGetConfigAttrib(display, *config, EGL_CONFIG_CAVEAT, &caveat))
137             ALOGW_IF(caveat == EGL_SLOW_CONFIG, "EGL_SLOW_CONFIG selected!");
138     }
139 
140     return err;
141 }
142 
create(const RenderEngineCreationArgs & args)143 std::unique_ptr<SkiaGLRenderEngine> SkiaGLRenderEngine::create(
144         const RenderEngineCreationArgs& args) {
145     // initialize EGL for the default display
146     EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
147     if (!eglInitialize(display, nullptr, nullptr)) {
148         LOG_ALWAYS_FATAL("failed to initialize EGL");
149     }
150 
151     const auto eglVersion = eglQueryString(display, EGL_VERSION);
152     if (!eglVersion) {
153         checkGlError(__FUNCTION__, __LINE__);
154         LOG_ALWAYS_FATAL("eglQueryString(EGL_VERSION) failed");
155     }
156 
157     const auto eglExtensions = eglQueryString(display, EGL_EXTENSIONS);
158     if (!eglExtensions) {
159         checkGlError(__FUNCTION__, __LINE__);
160         LOG_ALWAYS_FATAL("eglQueryString(EGL_EXTENSIONS) failed");
161     }
162 
163     auto& extensions = GLExtensions::getInstance();
164     extensions.initWithEGLStrings(eglVersion, eglExtensions);
165 
166     // The code assumes that ES2 or later is available if this extension is
167     // supported.
168     EGLConfig config = EGL_NO_CONFIG_KHR;
169     if (!extensions.hasNoConfigContext()) {
170         config = chooseEglConfig(display, args.pixelFormat, /*logConfig*/ true);
171     }
172 
173     EGLContext protectedContext = EGL_NO_CONTEXT;
174     const std::optional<RenderEngine::ContextPriority> priority = createContextPriority(args);
175     if (args.enableProtectedContext && extensions.hasProtectedContent()) {
176         protectedContext =
177                 createEglContext(display, config, nullptr, priority, Protection::PROTECTED);
178         ALOGE_IF(protectedContext == EGL_NO_CONTEXT, "Can't create protected context");
179     }
180 
181     EGLContext ctxt =
182             createEglContext(display, config, protectedContext, priority, Protection::UNPROTECTED);
183 
184     // if can't create a GL context, we can only abort.
185     LOG_ALWAYS_FATAL_IF(ctxt == EGL_NO_CONTEXT, "EGLContext creation failed");
186 
187     EGLSurface placeholder = EGL_NO_SURFACE;
188     if (!extensions.hasSurfacelessContext()) {
189         placeholder = createPlaceholderEglPbufferSurface(display, config, args.pixelFormat,
190                                                          Protection::UNPROTECTED);
191         LOG_ALWAYS_FATAL_IF(placeholder == EGL_NO_SURFACE, "can't create placeholder pbuffer");
192     }
193     EGLBoolean success = eglMakeCurrent(display, placeholder, placeholder, ctxt);
194     LOG_ALWAYS_FATAL_IF(!success, "can't make placeholder pbuffer current");
195     extensions.initWithGLStrings(glGetString(GL_VENDOR), glGetString(GL_RENDERER),
196                                  glGetString(GL_VERSION), glGetString(GL_EXTENSIONS));
197 
198     EGLSurface protectedPlaceholder = EGL_NO_SURFACE;
199     if (protectedContext != EGL_NO_CONTEXT && !extensions.hasSurfacelessContext()) {
200         protectedPlaceholder = createPlaceholderEglPbufferSurface(display, config, args.pixelFormat,
201                                                                   Protection::PROTECTED);
202         ALOGE_IF(protectedPlaceholder == EGL_NO_SURFACE,
203                  "can't create protected placeholder pbuffer");
204     }
205 
206     // initialize the renderer while GL is current
207     std::unique_ptr<SkiaGLRenderEngine> engine(new SkiaGLRenderEngine(args, display, ctxt,
208                                                                       placeholder, protectedContext,
209                                                                       protectedPlaceholder));
210     engine->ensureContextsCreated();
211 
212     ALOGI("OpenGL ES informations:");
213     ALOGI("vendor    : %s", extensions.getVendor());
214     ALOGI("renderer  : %s", extensions.getRenderer());
215     ALOGI("version   : %s", extensions.getVersion());
216     ALOGI("extensions: %s", extensions.getExtensions());
217     ALOGI("GL_MAX_TEXTURE_SIZE = %zu", engine->getMaxTextureSize());
218     ALOGI("GL_MAX_VIEWPORT_DIMS = %zu", engine->getMaxViewportDims());
219 
220     return engine;
221 }
222 
chooseEglConfig(EGLDisplay display,int format,bool logConfig)223 EGLConfig SkiaGLRenderEngine::chooseEglConfig(EGLDisplay display, int format, bool logConfig) {
224     status_t err;
225     EGLConfig config;
226 
227     // First try to get an ES3 config
228     err = selectEGLConfig(display, format, EGL_OPENGL_ES3_BIT, &config);
229     if (err != NO_ERROR) {
230         // If ES3 fails, try to get an ES2 config
231         err = selectEGLConfig(display, format, EGL_OPENGL_ES2_BIT, &config);
232         if (err != NO_ERROR) {
233             // If ES2 still doesn't work, probably because we're on the emulator.
234             // try a simplified query
235             ALOGW("no suitable EGLConfig found, trying a simpler query");
236             err = selectEGLConfig(display, format, 0, &config);
237             if (err != NO_ERROR) {
238                 // this EGL is too lame for android
239                 LOG_ALWAYS_FATAL("no suitable EGLConfig found, giving up"
240                                  " (format: %d, vendor: %s, version: %s, extensions: %s, Client"
241                                  " API: %s)",
242                                  format, eglQueryString(display, EGL_VENDOR),
243                                  eglQueryString(display, EGL_VERSION),
244                                  eglQueryString(display, EGL_EXTENSIONS),
245                                  eglQueryString(display, EGL_CLIENT_APIS) ?: "Not Supported");
246             }
247         }
248     }
249 
250     if (logConfig) {
251         // print some debugging info
252         EGLint r, g, b, a;
253         eglGetConfigAttrib(display, config, EGL_RED_SIZE, &r);
254         eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g);
255         eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &b);
256         eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a);
257         ALOGI("EGL information:");
258         ALOGI("vendor    : %s", eglQueryString(display, EGL_VENDOR));
259         ALOGI("version   : %s", eglQueryString(display, EGL_VERSION));
260         ALOGI("extensions: %s", eglQueryString(display, EGL_EXTENSIONS));
261         ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS) ?: "Not Supported");
262         ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config);
263     }
264 
265     return config;
266 }
267 
SkiaGLRenderEngine(const RenderEngineCreationArgs & args,EGLDisplay display,EGLContext ctxt,EGLSurface placeholder,EGLContext protectedContext,EGLSurface protectedPlaceholder)268 SkiaGLRenderEngine::SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display,
269                                        EGLContext ctxt, EGLSurface placeholder,
270                                        EGLContext protectedContext, EGLSurface protectedPlaceholder)
271       : SkiaRenderEngine(args.threaded, static_cast<PixelFormat>(args.pixelFormat),
272                          args.blurAlgorithm),
273         mEGLDisplay(display),
274         mEGLContext(ctxt),
275         mPlaceholderSurface(placeholder),
276         mProtectedEGLContext(protectedContext),
277         mProtectedPlaceholderSurface(protectedPlaceholder) {}
278 
~SkiaGLRenderEngine()279 SkiaGLRenderEngine::~SkiaGLRenderEngine() {
280     finishRenderingAndAbandonContexts();
281     if (mPlaceholderSurface != EGL_NO_SURFACE) {
282         eglDestroySurface(mEGLDisplay, mPlaceholderSurface);
283     }
284     if (mProtectedPlaceholderSurface != EGL_NO_SURFACE) {
285         eglDestroySurface(mEGLDisplay, mProtectedPlaceholderSurface);
286     }
287     if (mEGLContext != EGL_NO_CONTEXT) {
288         eglDestroyContext(mEGLDisplay, mEGLContext);
289     }
290     if (mProtectedEGLContext != EGL_NO_CONTEXT) {
291         eglDestroyContext(mEGLDisplay, mProtectedEGLContext);
292     }
293     eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
294     eglTerminate(mEGLDisplay);
295     eglReleaseThread();
296 }
297 
createContexts()298 SkiaRenderEngine::Contexts SkiaGLRenderEngine::createContexts() {
299     LOG_ALWAYS_FATAL_IF(isProtected(),
300                         "Cannot setup contexts while already in protected mode");
301 
302     sk_sp<const GrGLInterface> glInterface = GrGLMakeNativeInterface();
303 
304     LOG_ALWAYS_FATAL_IF(!glInterface.get(), "GrGLMakeNativeInterface() failed");
305 
306     SkiaRenderEngine::Contexts contexts;
307     contexts.first = SkiaGpuContext::MakeGL_Ganesh(glInterface, mSkSLCacheMonitor);
308     if (supportsProtectedContentImpl()) {
309         useProtectedContextImpl(GrProtected::kYes);
310         contexts.second = SkiaGpuContext::MakeGL_Ganesh(glInterface, mSkSLCacheMonitor);
311         useProtectedContextImpl(GrProtected::kNo);
312     }
313 
314     return contexts;
315 }
316 
supportsProtectedContentImpl() const317 bool SkiaGLRenderEngine::supportsProtectedContentImpl() const {
318     return mProtectedEGLContext != EGL_NO_CONTEXT;
319 }
320 
useProtectedContextImpl(GrProtected isProtected)321 bool SkiaGLRenderEngine::useProtectedContextImpl(GrProtected isProtected) {
322     const EGLSurface surface =
323         (isProtected == GrProtected::kYes) ?
324         mProtectedPlaceholderSurface : mPlaceholderSurface;
325     const EGLContext context = (isProtected == GrProtected::kYes) ?
326         mProtectedEGLContext : mEGLContext;
327 
328     return eglMakeCurrent(mEGLDisplay, surface, surface, context) == EGL_TRUE;
329 }
330 
waitFence(SkiaGpuContext *,base::borrowed_fd fenceFd)331 void SkiaGLRenderEngine::waitFence(SkiaGpuContext*, base::borrowed_fd fenceFd) {
332     if (fenceFd.get() >= 0 && !waitGpuFence(fenceFd)) {
333         SFTRACE_NAME("SkiaGLRenderEngine::waitFence");
334         sync_wait(fenceFd.get(), -1);
335     }
336 }
337 
flushAndSubmit(SkiaGpuContext * context,sk_sp<SkSurface> dstSurface)338 base::unique_fd SkiaGLRenderEngine::flushAndSubmit(SkiaGpuContext* context,
339                                                    sk_sp<SkSurface> dstSurface) {
340     sk_sp<GrDirectContext> grContext = context->grDirectContext();
341     {
342         SFTRACE_NAME("flush surface");
343         grContext->flush(dstSurface.get());
344     }
345     base::unique_fd drawFence = flushGL();
346 
347     bool requireSync = drawFence.get() < 0;
348     if (requireSync) {
349         SFTRACE_BEGIN("Submit(sync=true)");
350     } else {
351         SFTRACE_BEGIN("Submit(sync=false)");
352     }
353     bool success = grContext->submit(requireSync ? GrSyncCpu::kYes : GrSyncCpu::kNo);
354     SFTRACE_END();
355     if (!success) {
356         ALOGE("Failed to flush RenderEngine commands");
357         // Chances are, something illegal happened (Skia's internal GPU object
358         // doesn't exist, or the context was abandoned).
359         return drawFence;
360     }
361 
362     return drawFence;
363 }
364 
waitGpuFence(base::borrowed_fd fenceFd)365 bool SkiaGLRenderEngine::waitGpuFence(base::borrowed_fd fenceFd) {
366     if (!GLExtensions::getInstance().hasNativeFenceSync() ||
367         !GLExtensions::getInstance().hasWaitSync()) {
368         return false;
369     }
370 
371     // Duplicate the fence for passing to eglCreateSyncKHR.
372     base::unique_fd fenceDup(dup(fenceFd.get()));
373     if (fenceDup.get() < 0) {
374         ALOGE("failed to create duplicate fence fd: %d", fenceDup.get());
375         return false;
376     }
377 
378     // release the fd and transfer the ownership to EGLSync
379     EGLint attribs[] = {EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceDup.release(), EGL_NONE};
380     EGLSyncKHR sync = eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
381     if (sync == EGL_NO_SYNC_KHR) {
382         ALOGE("failed to create EGL native fence sync: %#x", eglGetError());
383         return false;
384     }
385 
386     // XXX: The spec draft is inconsistent as to whether this should return an
387     // EGLint or void.  Ignore the return value for now, as it's not strictly
388     // needed.
389     eglWaitSyncKHR(mEGLDisplay, sync, 0);
390     EGLint error = eglGetError();
391     eglDestroySyncKHR(mEGLDisplay, sync);
392     if (error != EGL_SUCCESS) {
393         ALOGE("failed to wait for EGL native fence sync: %#x", error);
394         return false;
395     }
396 
397     return true;
398 }
399 
flushGL()400 base::unique_fd SkiaGLRenderEngine::flushGL() {
401     SFTRACE_CALL();
402     if (!GLExtensions::getInstance().hasNativeFenceSync()) {
403         return base::unique_fd();
404     }
405 
406     EGLSyncKHR sync = eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, nullptr);
407     if (sync == EGL_NO_SYNC_KHR) {
408         ALOGW("failed to create EGL native fence sync: %#x", eglGetError());
409         return base::unique_fd();
410     }
411 
412     // native fence fd will not be populated until flush() is done.
413     glFlush();
414 
415     // get the fence fd
416     base::unique_fd fenceFd(eglDupNativeFenceFDANDROID(mEGLDisplay, sync));
417     eglDestroySyncKHR(mEGLDisplay, sync);
418     if (fenceFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
419         ALOGW("failed to dup EGL native fence sync: %#x", eglGetError());
420     }
421 
422     return fenceFd;
423 }
424 
createEglContext(EGLDisplay display,EGLConfig config,EGLContext shareContext,std::optional<ContextPriority> contextPriority,Protection protection)425 EGLContext SkiaGLRenderEngine::createEglContext(EGLDisplay display, EGLConfig config,
426                                                 EGLContext shareContext,
427                                                 std::optional<ContextPriority> contextPriority,
428                                                 Protection protection) {
429     EGLint renderableType = 0;
430     if (config == EGL_NO_CONFIG_KHR) {
431         renderableType = EGL_OPENGL_ES3_BIT;
432     } else if (!eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType)) {
433         LOG_ALWAYS_FATAL("can't query EGLConfig RENDERABLE_TYPE");
434     }
435     EGLint contextClientVersion = 0;
436     if (renderableType & EGL_OPENGL_ES3_BIT) {
437         contextClientVersion = 3;
438     } else if (renderableType & EGL_OPENGL_ES2_BIT) {
439         contextClientVersion = 2;
440     } else if (renderableType & EGL_OPENGL_ES_BIT) {
441         contextClientVersion = 1;
442     } else {
443         LOG_ALWAYS_FATAL("no supported EGL_RENDERABLE_TYPEs");
444     }
445 
446     std::vector<EGLint> contextAttributes;
447     contextAttributes.reserve(7);
448     contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
449     contextAttributes.push_back(contextClientVersion);
450     if (contextPriority) {
451         contextAttributes.push_back(EGL_CONTEXT_PRIORITY_LEVEL_IMG);
452         switch (*contextPriority) {
453             case ContextPriority::REALTIME:
454                 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_REALTIME_NV);
455                 break;
456             case ContextPriority::MEDIUM:
457                 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_MEDIUM_IMG);
458                 break;
459             case ContextPriority::LOW:
460                 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_LOW_IMG);
461                 break;
462             case ContextPriority::HIGH:
463             default:
464                 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_HIGH_IMG);
465                 break;
466         }
467     }
468     if (protection == Protection::PROTECTED) {
469         contextAttributes.push_back(EGL_PROTECTED_CONTENT_EXT);
470         contextAttributes.push_back(EGL_TRUE);
471     }
472     contextAttributes.push_back(EGL_NONE);
473 
474     EGLContext context = eglCreateContext(display, config, shareContext, contextAttributes.data());
475 
476     if (contextClientVersion == 3 && context == EGL_NO_CONTEXT) {
477         // eglGetConfigAttrib indicated we can create GLES 3 context, but we failed, thus
478         // EGL_NO_CONTEXT so that we can abort.
479         if (config != EGL_NO_CONFIG_KHR) {
480             return context;
481         }
482         // If |config| is EGL_NO_CONFIG_KHR, we speculatively try to create GLES 3 context, so we
483         // should try to fall back to GLES 2.
484         contextAttributes[1] = 2;
485         context = eglCreateContext(display, config, shareContext, contextAttributes.data());
486     }
487 
488     return context;
489 }
490 
createContextPriority(const RenderEngineCreationArgs & args)491 std::optional<RenderEngine::ContextPriority> SkiaGLRenderEngine::createContextPriority(
492         const RenderEngineCreationArgs& args) {
493     if (!GLExtensions::getInstance().hasContextPriority()) {
494         return std::nullopt;
495     }
496 
497     switch (args.contextPriority) {
498         case RenderEngine::ContextPriority::REALTIME:
499             if (GLExtensions::getInstance().hasRealtimePriority()) {
500                 return RenderEngine::ContextPriority::REALTIME;
501             } else {
502                 ALOGI("Realtime priority unsupported, degrading gracefully to high priority");
503                 return RenderEngine::ContextPriority::HIGH;
504             }
505         case RenderEngine::ContextPriority::HIGH:
506         case RenderEngine::ContextPriority::MEDIUM:
507         case RenderEngine::ContextPriority::LOW:
508             return args.contextPriority;
509         default:
510             return std::nullopt;
511     }
512 }
513 
createPlaceholderEglPbufferSurface(EGLDisplay display,EGLConfig config,int hwcFormat,Protection protection)514 EGLSurface SkiaGLRenderEngine::createPlaceholderEglPbufferSurface(EGLDisplay display,
515                                                                   EGLConfig config, int hwcFormat,
516                                                                   Protection protection) {
517     EGLConfig placeholderConfig = config;
518     if (placeholderConfig == EGL_NO_CONFIG_KHR) {
519         placeholderConfig = chooseEglConfig(display, hwcFormat, /*logConfig*/ true);
520     }
521     std::vector<EGLint> attributes;
522     attributes.reserve(7);
523     attributes.push_back(EGL_WIDTH);
524     attributes.push_back(1);
525     attributes.push_back(EGL_HEIGHT);
526     attributes.push_back(1);
527     if (protection == Protection::PROTECTED) {
528         attributes.push_back(EGL_PROTECTED_CONTENT_EXT);
529         attributes.push_back(EGL_TRUE);
530     }
531     attributes.push_back(EGL_NONE);
532 
533     return eglCreatePbufferSurface(display, placeholderConfig, attributes.data());
534 }
535 
getContextPriority()536 int SkiaGLRenderEngine::getContextPriority() {
537     int value;
538     eglQueryContext(mEGLDisplay, mEGLContext, EGL_CONTEXT_PRIORITY_LEVEL_IMG, &value);
539     return value;
540 }
541 
appendBackendSpecificInfoToDump(std::string & result)542 void SkiaGLRenderEngine::appendBackendSpecificInfoToDump(std::string& result) {
543     const GLExtensions& extensions = GLExtensions::getInstance();
544     StringAppendF(&result, "\n ------------RE GLES (Ganesh)------------\n");
545     StringAppendF(&result, "EGL implementation : %s\n", extensions.getEGLVersion());
546     StringAppendF(&result, "%s\n", extensions.getEGLExtensions());
547     StringAppendF(&result, "GLES: %s, %s, %s\n", extensions.getVendor(), extensions.getRenderer(),
548                   extensions.getVersion());
549     StringAppendF(&result, "%s\n", extensions.getExtensions());
550 }
551 
552 } // namespace skia
553 } // namespace renderengine
554 } // namespace android
555