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