blob: e6fb94d1c1df8fa096418901d5657a7c74a65942 [file] [log] [blame]
John Reck67b1e2b2020-08-26 13:17:24 -07001/*
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
Ana Krulec70d15b1b2020-12-01 10:05:15 -080018#undef LOG_TAG
19#define LOG_TAG "RenderEngine"
20#define ATRACE_TAG ATRACE_TAG_GRAPHICS
21
Alec Mouri4ce5ec02021-01-07 17:33:21 -080022#include "SkiaGLRenderEngine.h"
John Reck67b1e2b2020-08-26 13:17:24 -070023
John Reck67b1e2b2020-08-26 13:17:24 -070024#include <EGL/egl.h>
25#include <EGL/eglext.h>
John Reck67b1e2b2020-08-26 13:17:24 -070026#include <GrContextOptions.h>
John Reck67b1e2b2020-08-26 13:17:24 -070027#include <SkCanvas.h>
Alec Mourib34f0b72020-10-02 13:18:34 -070028#include <SkColorFilter.h>
29#include <SkColorMatrix.h>
Alec Mourib5777452020-09-28 11:32:42 -070030#include <SkColorSpace.h>
Derek Sollenberger0e6d3562021-04-07 19:34:39 -040031#include <SkGraphics.h>
John Reck67b1e2b2020-08-26 13:17:24 -070032#include <SkImage.h>
Lucas Dupinf4cb4a02020-09-22 14:19:26 -070033#include <SkImageFilters.h>
Alec Mouric0aae732021-01-12 13:32:18 -080034#include <SkRegion.h>
Lucas Dupin3f11e922020-09-22 17:31:04 -070035#include <SkShadowUtils.h>
John Reck67b1e2b2020-08-26 13:17:24 -070036#include <SkSurface.h>
Ana Krulec1d12b3b2021-01-27 16:49:51 -080037#include <android-base/stringprintf.h>
Alec Mourib5777452020-09-28 11:32:42 -070038#include <gl/GrGLInterface.h>
Alec Mouricbd30932021-06-09 15:52:25 -070039#include <gui/TraceUtils.h>
Alec Mouri4ce5ec02021-01-07 17:33:21 -080040#include <sync/sync.h>
41#include <ui/BlurRegion.h>
Ana Krulec1d12b3b2021-01-27 16:49:51 -080042#include <ui/DebugUtils.h>
Alec Mouri4ce5ec02021-01-07 17:33:21 -080043#include <ui/GraphicBuffer.h>
44#include <utils/Trace.h>
Alec Mourib5777452020-09-28 11:32:42 -070045
46#include <cmath>
Alec Mouri4ce5ec02021-01-07 17:33:21 -080047#include <cstdint>
48#include <memory>
49
50#include "../gl/GLExtensions.h"
Derek Sollenberger0e6d3562021-04-07 19:34:39 -040051#include "Cache.h"
Alec Mouric0aae732021-01-12 13:32:18 -080052#include "ColorSpaces.h"
Alec Mouri4ce5ec02021-01-07 17:33:21 -080053#include "SkBlendMode.h"
54#include "SkImageInfo.h"
55#include "filters/BlurFilter.h"
Robin Lee026680a2021-07-26 12:49:53 +020056#include "filters/KawaseBlurFilter.h"
Alec Mouri4ce5ec02021-01-07 17:33:21 -080057#include "filters/LinearEffect.h"
58#include "log/log_main.h"
59#include "skia/debug/SkiaCapture.h"
Derek Sollenberger0e6d3562021-04-07 19:34:39 -040060#include "skia/debug/SkiaMemoryReporter.h"
Nader Jawad2dfc98b2021-04-08 20:35:39 -070061#include "skia/filters/StretchShaderFactory.h"
Alec Mouri4ce5ec02021-01-07 17:33:21 -080062#include "system/graphics-base-v1.0.h"
Alec Mourib5777452020-09-28 11:32:42 -070063
Nathaniel Nifongb9f27ef2021-04-01 16:44:12 -040064namespace {
65// Debugging settings
66static const bool kPrintLayerSettings = false;
67static const bool kFlushAfterEveryLayer = false;
68} // namespace
69
John Reck67b1e2b2020-08-26 13:17:24 -070070bool checkGlError(const char* op, int lineNumber);
71
72namespace android {
73namespace renderengine {
74namespace skia {
75
Ana Krulec1d12b3b2021-01-27 16:49:51 -080076using base::StringAppendF;
77
John Reck67b1e2b2020-08-26 13:17:24 -070078static status_t selectConfigForAttribute(EGLDisplay dpy, EGLint const* attrs, EGLint attribute,
79 EGLint wanted, EGLConfig* outConfig) {
80 EGLint numConfigs = -1, n = 0;
81 eglGetConfigs(dpy, nullptr, 0, &numConfigs);
82 std::vector<EGLConfig> configs(numConfigs, EGL_NO_CONFIG_KHR);
83 eglChooseConfig(dpy, attrs, configs.data(), configs.size(), &n);
84 configs.resize(n);
85
86 if (!configs.empty()) {
87 if (attribute != EGL_NONE) {
88 for (EGLConfig config : configs) {
89 EGLint value = 0;
90 eglGetConfigAttrib(dpy, config, attribute, &value);
91 if (wanted == value) {
92 *outConfig = config;
93 return NO_ERROR;
94 }
95 }
96 } else {
97 // just pick the first one
98 *outConfig = configs[0];
99 return NO_ERROR;
100 }
101 }
102
103 return NAME_NOT_FOUND;
104}
105
106static status_t selectEGLConfig(EGLDisplay display, EGLint format, EGLint renderableType,
107 EGLConfig* config) {
108 // select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
109 // it is to be used with WIFI displays
110 status_t err;
111 EGLint wantedAttribute;
112 EGLint wantedAttributeValue;
113
114 std::vector<EGLint> attribs;
115 if (renderableType) {
116 const ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(format);
117 const bool is1010102 = pixelFormat == ui::PixelFormat::RGBA_1010102;
118
119 // Default to 8 bits per channel.
120 const EGLint tmpAttribs[] = {
121 EGL_RENDERABLE_TYPE,
122 renderableType,
123 EGL_RECORDABLE_ANDROID,
124 EGL_TRUE,
125 EGL_SURFACE_TYPE,
126 EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
127 EGL_FRAMEBUFFER_TARGET_ANDROID,
128 EGL_TRUE,
129 EGL_RED_SIZE,
130 is1010102 ? 10 : 8,
131 EGL_GREEN_SIZE,
132 is1010102 ? 10 : 8,
133 EGL_BLUE_SIZE,
134 is1010102 ? 10 : 8,
135 EGL_ALPHA_SIZE,
136 is1010102 ? 2 : 8,
137 EGL_NONE,
138 };
139 std::copy(tmpAttribs, tmpAttribs + (sizeof(tmpAttribs) / sizeof(EGLint)),
140 std::back_inserter(attribs));
141 wantedAttribute = EGL_NONE;
142 wantedAttributeValue = EGL_NONE;
143 } else {
144 // if no renderable type specified, fallback to a simplified query
145 wantedAttribute = EGL_NATIVE_VISUAL_ID;
146 wantedAttributeValue = format;
147 }
148
149 err = selectConfigForAttribute(display, attribs.data(), wantedAttribute, wantedAttributeValue,
150 config);
151 if (err == NO_ERROR) {
152 EGLint caveat;
153 if (eglGetConfigAttrib(display, *config, EGL_CONFIG_CAVEAT, &caveat))
154 ALOGW_IF(caveat == EGL_SLOW_CONFIG, "EGL_SLOW_CONFIG selected!");
155 }
156
157 return err;
158}
159
160std::unique_ptr<SkiaGLRenderEngine> SkiaGLRenderEngine::create(
161 const RenderEngineCreationArgs& args) {
162 // initialize EGL for the default display
163 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
164 if (!eglInitialize(display, nullptr, nullptr)) {
165 LOG_ALWAYS_FATAL("failed to initialize EGL");
166 }
167
Yiwei Zhange2650962020-12-01 23:27:58 +0000168 const auto eglVersion = eglQueryString(display, EGL_VERSION);
John Reck67b1e2b2020-08-26 13:17:24 -0700169 if (!eglVersion) {
170 checkGlError(__FUNCTION__, __LINE__);
Yiwei Zhange2650962020-12-01 23:27:58 +0000171 LOG_ALWAYS_FATAL("eglQueryString(EGL_VERSION) failed");
John Reck67b1e2b2020-08-26 13:17:24 -0700172 }
173
Yiwei Zhange2650962020-12-01 23:27:58 +0000174 const auto eglExtensions = eglQueryString(display, EGL_EXTENSIONS);
John Reck67b1e2b2020-08-26 13:17:24 -0700175 if (!eglExtensions) {
176 checkGlError(__FUNCTION__, __LINE__);
Yiwei Zhange2650962020-12-01 23:27:58 +0000177 LOG_ALWAYS_FATAL("eglQueryString(EGL_EXTENSIONS) failed");
John Reck67b1e2b2020-08-26 13:17:24 -0700178 }
179
180 auto& extensions = gl::GLExtensions::getInstance();
181 extensions.initWithEGLStrings(eglVersion, eglExtensions);
182
183 // The code assumes that ES2 or later is available if this extension is
184 // supported.
185 EGLConfig config = EGL_NO_CONFIG_KHR;
186 if (!extensions.hasNoConfigContext()) {
187 config = chooseEglConfig(display, args.pixelFormat, /*logConfig*/ true);
188 }
189
John Reck67b1e2b2020-08-26 13:17:24 -0700190 EGLContext protectedContext = EGL_NO_CONTEXT;
Alec Mourid6f09462020-12-07 11:18:17 -0800191 const std::optional<RenderEngine::ContextPriority> priority = createContextPriority(args);
John Reck67b1e2b2020-08-26 13:17:24 -0700192 if (args.enableProtectedContext && extensions.hasProtectedContent()) {
Alec Mourid6f09462020-12-07 11:18:17 -0800193 protectedContext =
194 createEglContext(display, config, nullptr, priority, Protection::PROTECTED);
John Reck67b1e2b2020-08-26 13:17:24 -0700195 ALOGE_IF(protectedContext == EGL_NO_CONTEXT, "Can't create protected context");
196 }
197
Alec Mourid6f09462020-12-07 11:18:17 -0800198 EGLContext ctxt =
199 createEglContext(display, config, protectedContext, priority, Protection::UNPROTECTED);
John Reck67b1e2b2020-08-26 13:17:24 -0700200
201 // if can't create a GL context, we can only abort.
202 LOG_ALWAYS_FATAL_IF(ctxt == EGL_NO_CONTEXT, "EGLContext creation failed");
203
204 EGLSurface placeholder = EGL_NO_SURFACE;
205 if (!extensions.hasSurfacelessContext()) {
206 placeholder = createPlaceholderEglPbufferSurface(display, config, args.pixelFormat,
207 Protection::UNPROTECTED);
208 LOG_ALWAYS_FATAL_IF(placeholder == EGL_NO_SURFACE, "can't create placeholder pbuffer");
209 }
210 EGLBoolean success = eglMakeCurrent(display, placeholder, placeholder, ctxt);
211 LOG_ALWAYS_FATAL_IF(!success, "can't make placeholder pbuffer current");
212 extensions.initWithGLStrings(glGetString(GL_VENDOR), glGetString(GL_RENDERER),
213 glGetString(GL_VERSION), glGetString(GL_EXTENSIONS));
214
215 EGLSurface protectedPlaceholder = EGL_NO_SURFACE;
216 if (protectedContext != EGL_NO_CONTEXT && !extensions.hasSurfacelessContext()) {
217 protectedPlaceholder = createPlaceholderEglPbufferSurface(display, config, args.pixelFormat,
218 Protection::PROTECTED);
219 ALOGE_IF(protectedPlaceholder == EGL_NO_SURFACE,
220 "can't create protected placeholder pbuffer");
221 }
222
223 // initialize the renderer while GL is current
224 std::unique_ptr<SkiaGLRenderEngine> engine =
Lucas Dupind508e472020-11-04 04:32:06 +0000225 std::make_unique<SkiaGLRenderEngine>(args, display, ctxt, placeholder, protectedContext,
226 protectedPlaceholder);
John Reck67b1e2b2020-08-26 13:17:24 -0700227
228 ALOGI("OpenGL ES informations:");
229 ALOGI("vendor : %s", extensions.getVendor());
230 ALOGI("renderer : %s", extensions.getRenderer());
231 ALOGI("version : %s", extensions.getVersion());
232 ALOGI("extensions: %s", extensions.getExtensions());
233 ALOGI("GL_MAX_TEXTURE_SIZE = %zu", engine->getMaxTextureSize());
234 ALOGI("GL_MAX_VIEWPORT_DIMS = %zu", engine->getMaxViewportDims());
235
236 return engine;
237}
238
Ady Abrahamfe2a6db2021-06-09 15:41:37 -0700239std::future<void> SkiaGLRenderEngine::primeCache() {
Leon Scroggins IIIb9216dc2021-03-08 17:19:01 -0500240 Cache::primeShaderCache(this);
Ady Abrahamfe2a6db2021-06-09 15:41:37 -0700241 return {};
Leon Scroggins IIIb9216dc2021-03-08 17:19:01 -0500242}
243
John Reck67b1e2b2020-08-26 13:17:24 -0700244EGLConfig SkiaGLRenderEngine::chooseEglConfig(EGLDisplay display, int format, bool logConfig) {
245 status_t err;
246 EGLConfig config;
247
248 // First try to get an ES3 config
249 err = selectEGLConfig(display, format, EGL_OPENGL_ES3_BIT, &config);
250 if (err != NO_ERROR) {
251 // If ES3 fails, try to get an ES2 config
252 err = selectEGLConfig(display, format, EGL_OPENGL_ES2_BIT, &config);
253 if (err != NO_ERROR) {
254 // If ES2 still doesn't work, probably because we're on the emulator.
255 // try a simplified query
256 ALOGW("no suitable EGLConfig found, trying a simpler query");
257 err = selectEGLConfig(display, format, 0, &config);
258 if (err != NO_ERROR) {
259 // this EGL is too lame for android
260 LOG_ALWAYS_FATAL("no suitable EGLConfig found, giving up");
261 }
262 }
263 }
264
265 if (logConfig) {
266 // print some debugging info
267 EGLint r, g, b, a;
268 eglGetConfigAttrib(display, config, EGL_RED_SIZE, &r);
269 eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &g);
270 eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &b);
271 eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &a);
272 ALOGI("EGL information:");
273 ALOGI("vendor : %s", eglQueryString(display, EGL_VENDOR));
274 ALOGI("version : %s", eglQueryString(display, EGL_VERSION));
275 ALOGI("extensions: %s", eglQueryString(display, EGL_EXTENSIONS));
276 ALOGI("Client API: %s", eglQueryString(display, EGL_CLIENT_APIS) ?: "Not Supported");
277 ALOGI("EGLSurface: %d-%d-%d-%d, config=%p", r, g, b, a, config);
278 }
279
280 return config;
281}
282
Leon Scroggins III9f3072c2021-03-22 10:42:47 -0400283sk_sp<SkData> SkiaGLRenderEngine::SkSLCacheMonitor::load(const SkData& key) {
284 // This "cache" does not actually cache anything. It just allows us to
285 // monitor Skia's internal cache. So this method always returns null.
286 return nullptr;
287}
288
289void SkiaGLRenderEngine::SkSLCacheMonitor::store(const SkData& key, const SkData& data,
290 const SkString& description) {
291 mShadersCachedSinceLastCall++;
292}
293
294void SkiaGLRenderEngine::assertShadersCompiled(int numShaders) {
295 const int cached = mSkSLCacheMonitor.shadersCachedSinceLastCall();
296 LOG_ALWAYS_FATAL_IF(cached != numShaders, "Attempted to cache %i shaders; cached %i",
297 numShaders, cached);
298}
299
Nathaniel Nifongb9f27ef2021-04-01 16:44:12 -0400300int SkiaGLRenderEngine::reportShadersCompiled() {
301 return mSkSLCacheMonitor.shadersCachedSinceLastCall();
302}
303
Lucas Dupinf4cb4a02020-09-22 14:19:26 -0700304SkiaGLRenderEngine::SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display,
Lucas Dupind508e472020-11-04 04:32:06 +0000305 EGLContext ctxt, EGLSurface placeholder,
Lucas Dupinf4cb4a02020-09-22 14:19:26 -0700306 EGLContext protectedContext, EGLSurface protectedPlaceholder)
Alec Mouri0d995102021-02-24 16:53:38 -0800307 : SkiaRenderEngine(args.renderEngineType),
308 mEGLDisplay(display),
John Reck67b1e2b2020-08-26 13:17:24 -0700309 mEGLContext(ctxt),
310 mPlaceholderSurface(placeholder),
311 mProtectedEGLContext(protectedContext),
Alec Mourib5777452020-09-28 11:32:42 -0700312 mProtectedPlaceholderSurface(protectedPlaceholder),
Derek Sollenbergerc4a05e12021-03-24 16:45:20 -0400313 mDefaultPixelFormat(static_cast<PixelFormat>(args.pixelFormat)),
Alec Mouri0d995102021-02-24 16:53:38 -0800314 mUseColorManagement(args.useColorManagement) {
John Reck67b1e2b2020-08-26 13:17:24 -0700315 sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
316 LOG_ALWAYS_FATAL_IF(!glInterface.get());
317
318 GrContextOptions options;
Derek Sollenbergerc4a05e12021-03-24 16:45:20 -0400319 options.fDisableDriverCorrectnessWorkarounds = true;
John Reck67b1e2b2020-08-26 13:17:24 -0700320 options.fDisableDistanceFieldPaths = true;
Nathaniel Nifongf8d35e92021-06-08 15:02:25 -0400321 options.fReducedShaderVariations = true;
Leon Scroggins III9f3072c2021-03-22 10:42:47 -0400322 options.fPersistentCache = &mSkSLCacheMonitor;
Lucas Dupind508e472020-11-04 04:32:06 +0000323 mGrContext = GrDirectContext::MakeGL(glInterface, options);
Derek Sollenberger1ec2fb52021-06-16 15:11:27 -0400324 if (supportsProtectedContent()) {
325 useProtectedContext(true);
Lucas Dupind508e472020-11-04 04:32:06 +0000326 mProtectedGrContext = GrDirectContext::MakeGL(glInterface, options);
327 useProtectedContext(false);
328 }
Lucas Dupinf4cb4a02020-09-22 14:19:26 -0700329
330 if (args.supportsBackgroundBlur) {
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500331 ALOGD("Background Blurs Enabled");
Robin Lee026680a2021-07-26 12:49:53 +0200332 mBlurFilter = new KawaseBlurFilter();
Lucas Dupinf4cb4a02020-09-22 14:19:26 -0700333 }
Alec Mouric0aae732021-01-12 13:32:18 -0800334 mCapture = std::make_unique<SkiaCapture>();
335}
336
337SkiaGLRenderEngine::~SkiaGLRenderEngine() {
Marin Shalamanovcea12ef2021-03-15 17:00:51 +0100338 std::lock_guard<std::mutex> lock(mRenderingMutex);
Alec Mouric0aae732021-01-12 13:32:18 -0800339 if (mBlurFilter) {
340 delete mBlurFilter;
341 }
342
343 mCapture = nullptr;
344
345 mGrContext->flushAndSubmit(true);
346 mGrContext->abandonContext();
347
348 if (mProtectedGrContext) {
349 mProtectedGrContext->flushAndSubmit(true);
350 mProtectedGrContext->abandonContext();
351 }
352
353 if (mPlaceholderSurface != EGL_NO_SURFACE) {
354 eglDestroySurface(mEGLDisplay, mPlaceholderSurface);
355 }
356 if (mProtectedPlaceholderSurface != EGL_NO_SURFACE) {
357 eglDestroySurface(mEGLDisplay, mProtectedPlaceholderSurface);
358 }
359 if (mEGLContext != EGL_NO_CONTEXT) {
360 eglDestroyContext(mEGLDisplay, mEGLContext);
361 }
362 if (mProtectedEGLContext != EGL_NO_CONTEXT) {
363 eglDestroyContext(mEGLDisplay, mProtectedEGLContext);
364 }
365 eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
366 eglTerminate(mEGLDisplay);
367 eglReleaseThread();
John Reck67b1e2b2020-08-26 13:17:24 -0700368}
369
Lucas Dupind508e472020-11-04 04:32:06 +0000370bool SkiaGLRenderEngine::supportsProtectedContent() const {
371 return mProtectedEGLContext != EGL_NO_CONTEXT;
372}
373
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400374GrDirectContext* SkiaGLRenderEngine::getActiveGrContext() const {
375 return mInProtectedContext ? mProtectedGrContext.get() : mGrContext.get();
376}
377
Derek Sollenberger1ec2fb52021-06-16 15:11:27 -0400378void SkiaGLRenderEngine::useProtectedContext(bool useProtectedContext) {
379 if (useProtectedContext == mInProtectedContext ||
380 (useProtectedContext && !supportsProtectedContent())) {
381 return;
Lucas Dupind508e472020-11-04 04:32:06 +0000382 }
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400383
384 // release any scratch resources before switching into a new mode
385 if (getActiveGrContext()) {
386 getActiveGrContext()->purgeUnlockedResources(true);
387 }
388
Lucas Dupind508e472020-11-04 04:32:06 +0000389 const EGLSurface surface =
390 useProtectedContext ? mProtectedPlaceholderSurface : mPlaceholderSurface;
391 const EGLContext context = useProtectedContext ? mProtectedEGLContext : mEGLContext;
Alec Mouric0aae732021-01-12 13:32:18 -0800392
Derek Sollenberger1ec2fb52021-06-16 15:11:27 -0400393 if (eglMakeCurrent(mEGLDisplay, surface, surface, context) == EGL_TRUE) {
Lucas Dupind508e472020-11-04 04:32:06 +0000394 mInProtectedContext = useProtectedContext;
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400395 // given that we are sharing the same thread between two GrContexts we need to
396 // make sure that the thread state is reset when switching between the two.
397 if (getActiveGrContext()) {
398 getActiveGrContext()->resetContext();
399 }
Lucas Dupind508e472020-11-04 04:32:06 +0000400 }
Lucas Dupind508e472020-11-04 04:32:06 +0000401}
402
John Reck67b1e2b2020-08-26 13:17:24 -0700403base::unique_fd SkiaGLRenderEngine::flush() {
404 ATRACE_CALL();
405 if (!gl::GLExtensions::getInstance().hasNativeFenceSync()) {
406 return base::unique_fd();
407 }
408
409 EGLSyncKHR sync = eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, nullptr);
410 if (sync == EGL_NO_SYNC_KHR) {
411 ALOGW("failed to create EGL native fence sync: %#x", eglGetError());
412 return base::unique_fd();
413 }
414
415 // native fence fd will not be populated until flush() is done.
416 glFlush();
417
418 // get the fence fd
419 base::unique_fd fenceFd(eglDupNativeFenceFDANDROID(mEGLDisplay, sync));
420 eglDestroySyncKHR(mEGLDisplay, sync);
421 if (fenceFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
422 ALOGW("failed to dup EGL native fence sync: %#x", eglGetError());
423 }
424
425 return fenceFd;
426}
427
Alec Mouri4ee7b492021-08-11 10:36:55 -0700428void SkiaGLRenderEngine::waitFence(base::borrowed_fd fenceFd) {
429 if (fenceFd.get() >= 0 && !waitGpuFence(fenceFd)) {
430 ATRACE_NAME("SkiaGLRenderEngine::waitFence");
431 sync_wait(fenceFd.get(), -1);
432 }
433}
434
435bool SkiaGLRenderEngine::waitGpuFence(base::borrowed_fd fenceFd) {
John Reck67b1e2b2020-08-26 13:17:24 -0700436 if (!gl::GLExtensions::getInstance().hasNativeFenceSync() ||
437 !gl::GLExtensions::getInstance().hasWaitSync()) {
438 return false;
439 }
440
Alec Mouri4ee7b492021-08-11 10:36:55 -0700441 // Duplicate the fence for passing to eglCreateSyncKHR.
442 base::unique_fd fenceDup(dup(fenceFd.get()));
443 if (fenceDup.get() < 0) {
444 ALOGE("failed to create duplicate fence fd: %d", fenceDup.get());
445 return false;
446 }
447
John Reck67b1e2b2020-08-26 13:17:24 -0700448 // release the fd and transfer the ownership to EGLSync
Alec Mouri4ee7b492021-08-11 10:36:55 -0700449 EGLint attribs[] = {EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceDup.release(), EGL_NONE};
John Reck67b1e2b2020-08-26 13:17:24 -0700450 EGLSyncKHR sync = eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
451 if (sync == EGL_NO_SYNC_KHR) {
452 ALOGE("failed to create EGL native fence sync: %#x", eglGetError());
453 return false;
454 }
455
456 // XXX: The spec draft is inconsistent as to whether this should return an
457 // EGLint or void. Ignore the return value for now, as it's not strictly
458 // needed.
459 eglWaitSyncKHR(mEGLDisplay, sync, 0);
460 EGLint error = eglGetError();
461 eglDestroySyncKHR(mEGLDisplay, sync);
462 if (error != EGL_SUCCESS) {
463 ALOGE("failed to wait for EGL native fence sync: %#x", error);
464 return false;
465 }
466
467 return true;
468}
469
Alec Mouri678245d2020-09-30 16:58:23 -0700470static float toDegrees(uint32_t transform) {
471 switch (transform) {
472 case ui::Transform::ROT_90:
473 return 90.0;
474 case ui::Transform::ROT_180:
475 return 180.0;
476 case ui::Transform::ROT_270:
477 return 270.0;
478 default:
479 return 0.0;
480 }
481}
482
Alec Mourib34f0b72020-10-02 13:18:34 -0700483static SkColorMatrix toSkColorMatrix(const mat4& matrix) {
484 return SkColorMatrix(matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0], 0, matrix[0][1],
485 matrix[1][1], matrix[2][1], matrix[3][1], 0, matrix[0][2], matrix[1][2],
486 matrix[2][2], matrix[3][2], 0, matrix[0][3], matrix[1][3], matrix[2][3],
487 matrix[3][3], 0);
488}
489
Alec Mouri029d1952020-10-12 10:37:08 -0700490static bool needsToneMapping(ui::Dataspace sourceDataspace, ui::Dataspace destinationDataspace) {
491 int64_t sourceTransfer = sourceDataspace & HAL_DATASPACE_TRANSFER_MASK;
492 int64_t destTransfer = destinationDataspace & HAL_DATASPACE_TRANSFER_MASK;
493
494 // Treat unsupported dataspaces as srgb
495 if (destTransfer != HAL_DATASPACE_TRANSFER_LINEAR &&
496 destTransfer != HAL_DATASPACE_TRANSFER_HLG &&
497 destTransfer != HAL_DATASPACE_TRANSFER_ST2084) {
498 destTransfer = HAL_DATASPACE_TRANSFER_SRGB;
499 }
500
501 if (sourceTransfer != HAL_DATASPACE_TRANSFER_LINEAR &&
502 sourceTransfer != HAL_DATASPACE_TRANSFER_HLG &&
503 sourceTransfer != HAL_DATASPACE_TRANSFER_ST2084) {
504 sourceTransfer = HAL_DATASPACE_TRANSFER_SRGB;
505 }
506
507 const bool isSourceLinear = sourceTransfer == HAL_DATASPACE_TRANSFER_LINEAR;
508 const bool isSourceSRGB = sourceTransfer == HAL_DATASPACE_TRANSFER_SRGB;
509 const bool isDestLinear = destTransfer == HAL_DATASPACE_TRANSFER_LINEAR;
510 const bool isDestSRGB = destTransfer == HAL_DATASPACE_TRANSFER_SRGB;
511
512 return !(isSourceLinear && isDestSRGB) && !(isSourceSRGB && isDestLinear) &&
513 sourceTransfer != destTransfer;
514}
515
Alec Mouria90a5702021-04-16 16:36:21 +0000516void SkiaGLRenderEngine::mapExternalTextureBuffer(const sp<GraphicBuffer>& buffer,
517 bool isRenderable) {
Ana Krulecdfec8f52021-01-13 12:51:47 -0800518 // Only run this if RE is running on its own thread. This way the access to GL
519 // operations is guaranteed to be happening on the same thread.
520 if (mRenderEngineType != RenderEngineType::SKIA_GL_THREADED) {
521 return;
522 }
Derek Sollenbergerbc14f3c2021-05-21 14:29:16 -0400523 // We currently don't attempt to map a buffer if the buffer contains protected content
Derek Sollenberger45007182021-06-10 14:47:21 -0400524 // because GPU resources for protected buffers is much more limited.
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400525 const bool isProtectedBuffer = buffer->getUsage() & GRALLOC_USAGE_PROTECTED;
Derek Sollenberger45007182021-06-10 14:47:21 -0400526 if (isProtectedBuffer) {
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400527 return;
528 }
Ana Krulecdfec8f52021-01-13 12:51:47 -0800529 ATRACE_CALL();
530
Derek Sollenberger45007182021-06-10 14:47:21 -0400531 // If we were to support caching protected buffers then we will need to switch the
532 // currently bound context if we are not already using the protected context (and subsequently
533 // switch back after the buffer is cached). However, for non-protected content we can bind
534 // the texture in either GL context because they are initialized with the same share_context
535 // which allows the texture state to be shared between them.
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400536 auto grContext = getActiveGrContext();
Derek Sollenbergerbc14f3c2021-05-21 14:29:16 -0400537 auto& cache = mTextureCache;
Derek Sollenbergereb904d42021-03-22 12:58:53 -0400538
539 std::lock_guard<std::mutex> lock(mRenderingMutex);
Alec Mouria90a5702021-04-16 16:36:21 +0000540 mGraphicBufferExternalRefs[buffer->getId()]++;
541
542 if (const auto& iter = cache.find(buffer->getId()); iter == cache.end()) {
Ana Krulecdfec8f52021-01-13 12:51:47 -0800543 std::shared_ptr<AutoBackendTexture::LocalRef> imageTextureRef =
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400544 std::make_shared<AutoBackendTexture::LocalRef>(grContext,
Derek Sollenbergerd8fdae32021-04-09 13:52:59 -0400545 buffer->toAHardwareBuffer(),
Derek Sollenbergerd3f60652021-06-11 15:34:36 -0400546 isRenderable, mTextureCleanupMgr);
Derek Sollenbergereb904d42021-03-22 12:58:53 -0400547 cache.insert({buffer->getId(), imageTextureRef});
Ana Krulecdfec8f52021-01-13 12:51:47 -0800548 }
549}
550
Alec Mouria90a5702021-04-16 16:36:21 +0000551void SkiaGLRenderEngine::unmapExternalTextureBuffer(const sp<GraphicBuffer>& buffer) {
Ana Krulecdfec8f52021-01-13 12:51:47 -0800552 ATRACE_CALL();
John Reck67b1e2b2020-08-26 13:17:24 -0700553 std::lock_guard<std::mutex> lock(mRenderingMutex);
Alec Mouria90a5702021-04-16 16:36:21 +0000554 if (const auto& iter = mGraphicBufferExternalRefs.find(buffer->getId());
555 iter != mGraphicBufferExternalRefs.end()) {
556 if (iter->second == 0) {
557 ALOGW("Attempted to unmap GraphicBuffer <id: %" PRId64
558 "> from RenderEngine texture, but the "
559 "ref count was already zero!",
560 buffer->getId());
561 mGraphicBufferExternalRefs.erase(buffer->getId());
562 return;
563 }
564
565 iter->second--;
566
Alec Mouric2ffeb42021-06-17 17:42:27 -0700567 // Swap contexts if needed prior to deleting this buffer
568 // See Issue 1 of
569 // https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_protected_content.txt: even
570 // when a protected context and an unprotected context are part of the same share group,
571 // protected surfaces may not be accessed by an unprotected context, implying that protected
572 // surfaces may only be freed when a protected context is active.
573 const bool inProtected = mInProtectedContext;
574 useProtectedContext(buffer->getUsage() & GRALLOC_USAGE_PROTECTED);
575
Alec Mouria90a5702021-04-16 16:36:21 +0000576 if (iter->second == 0) {
577 mTextureCache.erase(buffer->getId());
Alec Mouria90a5702021-04-16 16:36:21 +0000578 mGraphicBufferExternalRefs.erase(buffer->getId());
579 }
Alec Mouric2ffeb42021-06-17 17:42:27 -0700580
581 // Swap back to the previous context so that cached values of isProtected in SurfaceFlinger
582 // are up-to-date.
583 if (inProtected != mInProtectedContext) {
584 useProtectedContext(inProtected);
585 }
Alec Mouria90a5702021-04-16 16:36:21 +0000586 }
John Reck67b1e2b2020-08-26 13:17:24 -0700587}
588
Derek Sollenbergerd3f60652021-06-11 15:34:36 -0400589bool SkiaGLRenderEngine::canSkipPostRenderCleanup() const {
590 std::lock_guard<std::mutex> lock(mRenderingMutex);
591 return mTextureCleanupMgr.isEmpty();
592}
593
594void SkiaGLRenderEngine::cleanupPostRender() {
595 ATRACE_CALL();
596 std::lock_guard<std::mutex> lock(mRenderingMutex);
597 mTextureCleanupMgr.cleanup();
598}
599
600// Helper class intended to be used on the stack to ensure that texture cleanup
601// is deferred until after this class goes out of scope.
602class DeferTextureCleanup final {
603public:
604 DeferTextureCleanup(AutoBackendTexture::CleanupManager& mgr) : mMgr(mgr) {
605 mMgr.setDeferredStatus(true);
606 }
607 ~DeferTextureCleanup() { mMgr.setDeferredStatus(false); }
608
609private:
610 DISALLOW_COPY_AND_ASSIGN(DeferTextureCleanup);
611 AutoBackendTexture::CleanupManager& mMgr;
612};
613
Sally Qi59a9f502021-10-12 18:53:23 +0000614sk_sp<SkShader> SkiaGLRenderEngine::createRuntimeEffectShader(sk_sp<SkShader> shader,
615 const LayerSettings& layer,
616 const DisplaySettings& display,
617 bool undoPremultipliedAlpha,
618 bool requiresLinearEffect) {
619 const auto stretchEffect = layer.stretchEffect;
Nader Jawad63644d32021-05-07 10:44:21 -0700620 // The given surface will be stretched by HWUI via matrix transformation
621 // which gets similar results for most surfaces
622 // Determine later on if we need to leverage the stertch shader within
623 // surface flinger
Nader Jawadc088bdc2021-05-10 13:24:46 -0700624 if (stretchEffect.hasEffect()) {
Sally Qi59a9f502021-10-12 18:53:23 +0000625 const auto targetBuffer = layer.source.buffer.buffer;
Nader Jawadc088bdc2021-05-10 13:24:46 -0700626 const auto graphicBuffer = targetBuffer ? targetBuffer->getBuffer() : nullptr;
627 if (graphicBuffer && shader) {
Nader Jawad2dfc98b2021-04-08 20:35:39 -0700628 shader = mStretchShaderFactory.createSkShader(shader, stretchEffect);
629 }
John Reckcdb4ed72021-02-04 13:39:33 -0500630 }
Nader Jawad2dfc98b2021-04-08 20:35:39 -0700631
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -0500632 if (requiresLinearEffect) {
633 const ui::Dataspace inputDataspace =
Sally Qi59a9f502021-10-12 18:53:23 +0000634 mUseColorManagement ? layer.sourceDataspace : ui::Dataspace::V0_SRGB_LINEAR;
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -0500635 const ui::Dataspace outputDataspace =
Alec Mourid2bcbae2021-06-28 17:02:17 -0700636 mUseColorManagement ? display.outputDataspace : ui::Dataspace::V0_SRGB_LINEAR;
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -0500637
638 LinearEffect effect = LinearEffect{.inputDataspace = inputDataspace,
639 .outputDataspace = outputDataspace,
Ana Krulec47814212021-01-06 19:00:10 -0800640 .undoPremultipliedAlpha = undoPremultipliedAlpha};
641
642 auto effectIter = mRuntimeEffects.find(effect);
643 sk_sp<SkRuntimeEffect> runtimeEffect = nullptr;
644 if (effectIter == mRuntimeEffects.end()) {
645 runtimeEffect = buildRuntimeEffect(effect);
646 mRuntimeEffects.insert({effect, runtimeEffect});
647 } else {
648 runtimeEffect = effectIter->second;
649 }
Sally Qi59a9f502021-10-12 18:53:23 +0000650 float maxLuminance = layer.source.buffer.maxLuminanceNits;
John Reckac09e452021-04-07 16:35:37 -0400651 // If the buffer doesn't have a max luminance, treat it as SDR & use the display's SDR
652 // white point
653 if (maxLuminance <= 0.f) {
654 maxLuminance = display.sdrWhitePointNits;
655 }
Sally Qi59a9f502021-10-12 18:53:23 +0000656 return createLinearEffectShader(shader, effect, runtimeEffect, layer.colorTransform,
John Reckac09e452021-04-07 16:35:37 -0400657 display.maxLuminance, maxLuminance);
Ana Krulec47814212021-01-06 19:00:10 -0800658 }
659 return shader;
660}
661
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500662void SkiaGLRenderEngine::initCanvas(SkCanvas* canvas, const DisplaySettings& display) {
Derek Sollenberger76664d62021-02-04 11:13:09 -0500663 if (CC_UNLIKELY(mCapture->isCaptureRunning())) {
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500664 // Record display settings when capture is running.
665 std::stringstream displaySettings;
666 PrintTo(display, &displaySettings);
667 // Store the DisplaySettings in additional information.
668 canvas->drawAnnotation(SkRect::MakeEmpty(), "DisplaySettings",
669 SkData::MakeWithCString(displaySettings.str().c_str()));
670 }
671
672 // Before doing any drawing, let's make sure that we'll start at the origin of the display.
673 // Some displays don't start at 0,0 for example when we're mirroring the screen. Also, virtual
674 // displays might have different scaling when compared to the physical screen.
675
676 canvas->clipRect(getSkRect(display.physicalDisplay));
677 canvas->translate(display.physicalDisplay.left, display.physicalDisplay.top);
678
679 const auto clipWidth = display.clip.width();
680 const auto clipHeight = display.clip.height();
681 auto rotatedClipWidth = clipWidth;
682 auto rotatedClipHeight = clipHeight;
683 // Scale is contingent on the rotation result.
684 if (display.orientation & ui::Transform::ROT_90) {
685 std::swap(rotatedClipWidth, rotatedClipHeight);
686 }
687 const auto scaleX = static_cast<SkScalar>(display.physicalDisplay.width()) /
688 static_cast<SkScalar>(rotatedClipWidth);
689 const auto scaleY = static_cast<SkScalar>(display.physicalDisplay.height()) /
690 static_cast<SkScalar>(rotatedClipHeight);
691 canvas->scale(scaleX, scaleY);
692
693 // Canvas rotation is done by centering the clip window at the origin, rotating, translating
694 // back so that the top left corner of the clip is at (0, 0).
695 canvas->translate(rotatedClipWidth / 2, rotatedClipHeight / 2);
696 canvas->rotate(toDegrees(display.orientation));
697 canvas->translate(-clipWidth / 2, -clipHeight / 2);
698 canvas->translate(-display.clip.left, -display.clip.top);
699}
700
Derek Sollenberger7c42bef2021-02-23 13:01:39 -0500701class AutoSaveRestore {
702public:
703 AutoSaveRestore(SkCanvas* canvas) : mCanvas(canvas) { mSaveCount = canvas->save(); }
704 ~AutoSaveRestore() { restore(); }
705 void replace(SkCanvas* canvas) {
706 mCanvas = canvas;
707 mSaveCount = canvas->save();
708 }
709 void restore() {
710 if (mCanvas) {
711 mCanvas->restoreToCount(mSaveCount);
712 mCanvas = nullptr;
713 }
714 }
715
716private:
717 SkCanvas* mCanvas;
718 int mSaveCount;
719};
720
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -0400721static SkRRect getBlurRRect(const BlurRegion& region) {
722 const auto rect = SkRect::MakeLTRB(region.left, region.top, region.right, region.bottom);
723 const SkVector radii[4] = {SkVector::Make(region.cornerRadiusTL, region.cornerRadiusTL),
724 SkVector::Make(region.cornerRadiusTR, region.cornerRadiusTR),
725 SkVector::Make(region.cornerRadiusBR, region.cornerRadiusBR),
726 SkVector::Make(region.cornerRadiusBL, region.cornerRadiusBL)};
727 SkRRect roundedRect;
728 roundedRect.setRectRadii(rect, radii);
729 return roundedRect;
730}
731
Sally Qi4cabdd02021-08-05 16:45:57 -0700732void SkiaGLRenderEngine::drawLayersInternal(
733 const std::shared_ptr<std::promise<RenderEngineResult>>&& resultPromise,
Sally Qi59a9f502021-10-12 18:53:23 +0000734 const DisplaySettings& display, const std::vector<LayerSettings>& layers,
Sally Qi4cabdd02021-08-05 16:45:57 -0700735 const std::shared_ptr<ExternalTexture>& buffer, const bool /*useFramebufferCache*/,
736 base::unique_fd&& bufferFence) {
John Reck67b1e2b2020-08-26 13:17:24 -0700737 ATRACE_NAME("SkiaGL::drawLayers");
Alec Mouric0aae732021-01-12 13:32:18 -0800738
John Reck67b1e2b2020-08-26 13:17:24 -0700739 std::lock_guard<std::mutex> lock(mRenderingMutex);
740 if (layers.empty()) {
741 ALOGV("Drawing empty layer stack");
Sally Qi4cabdd02021-08-05 16:45:57 -0700742 resultPromise->set_value({NO_ERROR, base::unique_fd()});
743 return;
John Reck67b1e2b2020-08-26 13:17:24 -0700744 }
745
John Reck67b1e2b2020-08-26 13:17:24 -0700746 if (buffer == nullptr) {
747 ALOGE("No output buffer provided. Aborting GPU composition.");
Sally Qi4cabdd02021-08-05 16:45:57 -0700748 resultPromise->set_value({BAD_VALUE, base::unique_fd()});
749 return;
John Reck67b1e2b2020-08-26 13:17:24 -0700750 }
751
Alec Mouria90a5702021-04-16 16:36:21 +0000752 validateOutputBufferUsage(buffer->getBuffer());
Ady Abraham193426d2021-02-18 14:01:53 -0800753
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400754 auto grContext = getActiveGrContext();
Derek Sollenberger45007182021-06-10 14:47:21 -0400755 auto& cache = mTextureCache;
John Reck67b1e2b2020-08-26 13:17:24 -0700756
Derek Sollenbergerd3f60652021-06-11 15:34:36 -0400757 // any AutoBackendTexture deletions will now be deferred until cleanupPostRender is called
758 DeferTextureCleanup dtc(mTextureCleanupMgr);
759
Alec Mouria90a5702021-04-16 16:36:21 +0000760 std::shared_ptr<AutoBackendTexture::LocalRef> surfaceTextureRef;
761 if (const auto& it = cache.find(buffer->getBuffer()->getId()); it != cache.end()) {
762 surfaceTextureRef = it->second;
763 } else {
Derek Sollenbergerd8fdae32021-04-09 13:52:59 -0400764 surfaceTextureRef =
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400765 std::make_shared<AutoBackendTexture::LocalRef>(grContext,
766 buffer->getBuffer()
767 ->toAHardwareBuffer(),
Derek Sollenbergerd3f60652021-06-11 15:34:36 -0400768 true, mTextureCleanupMgr);
John Reck67b1e2b2020-08-26 13:17:24 -0700769 }
Alec Mouric7f6c8b2020-11-09 18:35:20 -0800770
Alec Mouri4ee7b492021-08-11 10:36:55 -0700771 // wait on the buffer to be ready to use prior to using it
772 waitFence(bufferFence);
773
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -0500774 const ui::Dataspace dstDataspace =
Alec Mourid2bcbae2021-06-28 17:02:17 -0700775 mUseColorManagement ? display.outputDataspace : ui::Dataspace::V0_SRGB_LINEAR;
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400776 sk_sp<SkSurface> dstSurface = surfaceTextureRef->getOrCreateSurface(dstDataspace, grContext);
Alec Mouri678245d2020-09-30 16:58:23 -0700777
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500778 SkCanvas* dstCanvas = mCapture->tryCapture(dstSurface.get());
779 if (dstCanvas == nullptr) {
Ana Krulec6eab17a2020-12-09 15:52:36 -0800780 ALOGE("Cannot acquire canvas from Skia.");
Sally Qi4cabdd02021-08-05 16:45:57 -0700781 resultPromise->set_value({BAD_VALUE, base::unique_fd()});
782 return;
Ana Krulec6eab17a2020-12-09 15:52:36 -0800783 }
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500784
Derek Sollenbergerc20e0802021-05-19 16:20:59 -0400785 // setup color filter if necessary
786 sk_sp<SkColorFilter> displayColorTransform;
787 if (display.colorTransform != mat4()) {
788 displayColorTransform = SkColorFilters::Matrix(toSkColorMatrix(display.colorTransform));
789 }
790 const bool ctModifiesAlpha =
791 displayColorTransform && !displayColorTransform->isAlphaUnchanged();
792
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500793 // Find if any layers have requested blur, we'll use that info to decide when to render to an
794 // offscreen buffer and when to render to the native buffer.
795 sk_sp<SkSurface> activeSurface(dstSurface);
796 SkCanvas* canvas = dstCanvas;
Derek Sollenberger76664d62021-02-04 11:13:09 -0500797 SkiaCapture::OffscreenState offscreenCaptureState;
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500798 const LayerSettings* blurCompositionLayer = nullptr;
799 if (mBlurFilter) {
800 bool requiresCompositionLayer = false;
801 for (const auto& layer : layers) {
Derek Sollenbergerc20e0802021-05-19 16:20:59 -0400802 // if the layer doesn't have blur or it is not visible then continue
803 if (!layerHasBlur(layer, ctModifiesAlpha)) {
804 continue;
805 }
Sally Qi59a9f502021-10-12 18:53:23 +0000806 if (layer.backgroundBlurRadius > 0 &&
807 layer.backgroundBlurRadius < BlurFilter::kMaxCrossFadeRadius) {
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500808 requiresCompositionLayer = true;
809 }
Sally Qi59a9f502021-10-12 18:53:23 +0000810 for (auto region : layer.blurRegions) {
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500811 if (region.blurRadius < BlurFilter::kMaxCrossFadeRadius) {
812 requiresCompositionLayer = true;
813 }
814 }
815 if (requiresCompositionLayer) {
816 activeSurface = dstSurface->makeSurface(dstSurface->imageInfo());
Derek Sollenberger76664d62021-02-04 11:13:09 -0500817 canvas = mCapture->tryOffscreenCapture(activeSurface.get(), &offscreenCaptureState);
Sally Qi59a9f502021-10-12 18:53:23 +0000818 blurCompositionLayer = &layer;
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500819 break;
820 }
821 }
822 }
823
Derek Sollenberger7c42bef2021-02-23 13:01:39 -0500824 AutoSaveRestore surfaceAutoSaveRestore(canvas);
Alec Mouri678245d2020-09-30 16:58:23 -0700825 // Clear the entire canvas with a transparent black to prevent ghost images.
826 canvas->clear(SK_ColorTRANSPARENT);
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500827 initCanvas(canvas, display);
Alec Mouric0aae732021-01-12 13:32:18 -0800828
John Reck67b1e2b2020-08-26 13:17:24 -0700829 for (const auto& layer : layers) {
Sally Qi59a9f502021-10-12 18:53:23 +0000830 ATRACE_FORMAT("DrawLayer: %s", layer.name.c_str());
Galia Peychevaf7889b32020-11-25 22:22:40 +0100831
Nathaniel Nifongb9f27ef2021-04-01 16:44:12 -0400832 if (kPrintLayerSettings) {
833 std::stringstream ls;
Sally Qi59a9f502021-10-12 18:53:23 +0000834 PrintTo(layer, &ls);
Nathaniel Nifongb9f27ef2021-04-01 16:44:12 -0400835 auto debugs = ls.str();
836 int pos = 0;
837 while (pos < debugs.size()) {
838 ALOGD("cache_debug %s", debugs.substr(pos, 1000).c_str());
839 pos += 1000;
840 }
841 }
842
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500843 sk_sp<SkImage> blurInput;
Sally Qi59a9f502021-10-12 18:53:23 +0000844 if (blurCompositionLayer == &layer) {
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500845 LOG_ALWAYS_FATAL_IF(activeSurface == dstSurface);
846 LOG_ALWAYS_FATAL_IF(canvas == dstCanvas);
847
848 // save a snapshot of the activeSurface to use as input to the blur shaders
849 blurInput = activeSurface->makeImageSnapshot();
850
851 // TODO we could skip this step if we know the blur will cover the entire image
852 // blit the offscreen framebuffer into the destination AHB
853 SkPaint paint;
854 paint.setBlendMode(SkBlendMode::kSrc);
Derek Sollenberger76664d62021-02-04 11:13:09 -0500855 if (CC_UNLIKELY(mCapture->isCaptureRunning())) {
856 uint64_t id = mCapture->endOffscreenCapture(&offscreenCaptureState);
857 dstCanvas->drawAnnotation(SkRect::Make(dstCanvas->imageInfo().dimensions()),
858 String8::format("SurfaceID|%" PRId64, id).c_str(),
859 nullptr);
860 dstCanvas->drawImage(blurInput, 0, 0, SkSamplingOptions(), &paint);
861 } else {
862 activeSurface->draw(dstCanvas, 0, 0, SkSamplingOptions(), &paint);
863 }
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500864
865 // assign dstCanvas to canvas and ensure that the canvas state is up to date
866 canvas = dstCanvas;
Derek Sollenberger7c42bef2021-02-23 13:01:39 -0500867 surfaceAutoSaveRestore.replace(canvas);
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500868 initCanvas(canvas, display);
869
870 LOG_ALWAYS_FATAL_IF(activeSurface->getCanvas()->getSaveCount() !=
871 dstSurface->getCanvas()->getSaveCount());
872 LOG_ALWAYS_FATAL_IF(activeSurface->getCanvas()->getTotalMatrix() !=
873 dstSurface->getCanvas()->getTotalMatrix());
874
875 // assign dstSurface to activeSurface
876 activeSurface = dstSurface;
877 }
878
Derek Sollenberger7c42bef2021-02-23 13:01:39 -0500879 SkAutoCanvasRestore layerAutoSaveRestore(canvas, true);
Derek Sollenberger76664d62021-02-04 11:13:09 -0500880 if (CC_UNLIKELY(mCapture->isCaptureRunning())) {
Ana Krulec6eab17a2020-12-09 15:52:36 -0800881 // Record the name of the layer if the capture is running.
882 std::stringstream layerSettings;
Sally Qi59a9f502021-10-12 18:53:23 +0000883 PrintTo(layer, &layerSettings);
Ana Krulec6eab17a2020-12-09 15:52:36 -0800884 // Store the LayerSettings in additional information.
Sally Qi59a9f502021-10-12 18:53:23 +0000885 canvas->drawAnnotation(SkRect::MakeEmpty(), layer.name.c_str(),
Ana Krulec6eab17a2020-12-09 15:52:36 -0800886 SkData::MakeWithCString(layerSettings.str().c_str()));
887 }
Galia Peychevaf7889b32020-11-25 22:22:40 +0100888 // Layers have a local transform that should be applied to them
Sally Qi59a9f502021-10-12 18:53:23 +0000889 canvas->concat(getSkM44(layer.geometry.positionTransform).asM33());
Galia Peycheva6c460652020-11-03 19:42:42 +0100890
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400891 const auto [bounds, roundRectClip] =
Sally Qi59a9f502021-10-12 18:53:23 +0000892 getBoundsAndClip(layer.geometry.boundaries, layer.geometry.roundedCornersCrop,
893 layer.geometry.roundedCornersRadius);
Derek Sollenbergerc20e0802021-05-19 16:20:59 -0400894 if (mBlurFilter && layerHasBlur(layer, ctModifiesAlpha)) {
Derek Sollenbergerecb21462021-01-29 16:53:49 -0500895 std::unordered_map<uint32_t, sk_sp<SkImage>> cachedBlurs;
896
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500897 // if multiple layers have blur, then we need to take a snapshot now because
898 // only the lowest layer will have blurImage populated earlier
899 if (!blurInput) {
900 blurInput = activeSurface->makeImageSnapshot();
901 }
Derek Sollenbergerecb21462021-01-29 16:53:49 -0500902 // rect to be blurred in the coordinate space of blurInput
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -0400903 const auto blurRect = canvas->getTotalMatrix().mapRect(bounds.rect());
904
905 // if the clip needs to be applied then apply it now and make sure
906 // it is restored before we attempt to draw any shadows.
907 SkAutoCanvasRestore acr(canvas, true);
908 if (!roundRectClip.isEmpty()) {
909 canvas->clipRRect(roundRectClip, true);
910 }
Derek Sollenbergerecb21462021-01-29 16:53:49 -0500911
Galia Peychevae425ac82021-03-15 17:12:03 +0100912 // TODO(b/182216890): Filter out empty layers earlier
913 if (blurRect.width() > 0 && blurRect.height() > 0) {
Sally Qi59a9f502021-10-12 18:53:23 +0000914 if (layer.backgroundBlurRadius > 0) {
Galia Peychevae425ac82021-03-15 17:12:03 +0100915 ATRACE_NAME("BackgroundBlur");
Sally Qi59a9f502021-10-12 18:53:23 +0000916 auto blurredImage = mBlurFilter->generate(grContext, layer.backgroundBlurRadius,
917 blurInput, blurRect);
Galia Peycheva80116e52020-11-06 11:57:25 +0100918
Sally Qi59a9f502021-10-12 18:53:23 +0000919 cachedBlurs[layer.backgroundBlurRadius] = blurredImage;
Derek Sollenbergerecb21462021-01-29 16:53:49 -0500920
Sally Qi59a9f502021-10-12 18:53:23 +0000921 mBlurFilter->drawBlurRegion(canvas, bounds, layer.backgroundBlurRadius, 1.0f,
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -0400922 blurRect, blurredImage, blurInput);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700923 }
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -0400924
Sally Qi59a9f502021-10-12 18:53:23 +0000925 canvas->concat(getSkM44(layer.blurRegionTransform).asM33());
926 for (auto region : layer.blurRegions) {
Galia Peychevae425ac82021-03-15 17:12:03 +0100927 if (cachedBlurs[region.blurRadius] == nullptr) {
928 ATRACE_NAME("BlurRegion");
929 cachedBlurs[region.blurRadius] =
Derek Sollenbergerb24258c2021-05-04 13:47:34 -0400930 mBlurFilter->generate(grContext, region.blurRadius, blurInput,
Galia Peychevae425ac82021-03-15 17:12:03 +0100931 blurRect);
932 }
Derek Sollenberger3f77aa42021-02-04 11:06:34 -0500933
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -0400934 mBlurFilter->drawBlurRegion(canvas, getBlurRRect(region), region.blurRadius,
935 region.alpha, blurRect,
Galia Peychevae425ac82021-03-15 17:12:03 +0100936 cachedBlurs[region.blurRadius], blurInput);
937 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700938 }
Lucas Dupinf4cb4a02020-09-22 14:19:26 -0700939 }
940
Sally Qi59a9f502021-10-12 18:53:23 +0000941 if (layer.shadow.length > 0) {
Leon Scroggins IIIcf3d95c2021-03-19 13:06:32 -0400942 // This would require a new parameter/flag to SkShadowUtils::DrawShadow
Sally Qi59a9f502021-10-12 18:53:23 +0000943 LOG_ALWAYS_FATAL_IF(layer.disableBlending, "Cannot disableBlending with a shadow");
Leon Scroggins III63e86952021-05-12 10:45:08 -0400944
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400945 SkRRect shadowBounds, shadowClip;
Sally Qi59a9f502021-10-12 18:53:23 +0000946 if (layer.geometry.boundaries == layer.shadow.boundaries) {
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400947 shadowBounds = bounds;
948 shadowClip = roundRectClip;
949 } else {
950 std::tie(shadowBounds, shadowClip) =
Sally Qi59a9f502021-10-12 18:53:23 +0000951 getBoundsAndClip(layer.shadow.boundaries, layer.geometry.roundedCornersCrop,
952 layer.geometry.roundedCornersRadius);
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400953 }
954
Leon Scroggins III63e86952021-05-12 10:45:08 -0400955 // Technically, if bounds is a rect and roundRectClip is not empty,
956 // it means that the bounds and roundedCornersCrop were different
957 // enough that we should intersect them to find the proper shadow.
958 // In practice, this often happens when the two rectangles appear to
959 // not match due to rounding errors. Draw the rounded version, which
960 // looks more like the intent.
961 const auto& rrect =
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400962 shadowBounds.isRect() && !shadowClip.isEmpty() ? shadowClip : shadowBounds;
Sally Qi59a9f502021-10-12 18:53:23 +0000963 drawShadow(canvas, rrect, layer.shadow);
Derek Sollenberger4c331c82021-02-23 13:09:50 -0500964 }
965
Sally Qi59a9f502021-10-12 18:53:23 +0000966 const bool requiresLinearEffect = layer.colorTransform != mat4() ||
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -0500967 (mUseColorManagement &&
Sally Qi59a9f502021-10-12 18:53:23 +0000968 needsToneMapping(layer.sourceDataspace, display.outputDataspace)) ||
John Reckac09e452021-04-07 16:35:37 -0400969 (display.sdrWhitePointNits > 0.f &&
970 display.sdrWhitePointNits != display.maxLuminance);
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -0500971
972 // quick abort from drawing the remaining portion of the layer
Sally Qi59a9f502021-10-12 18:53:23 +0000973 if (layer.skipContentDraw ||
974 (layer.alpha == 0 && !requiresLinearEffect && !layer.disableBlending &&
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400975 (!displayColorTransform || displayColorTransform->isAlphaUnchanged()))) {
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -0500976 continue;
977 }
978
979 // If we need to map to linear space or color management is disabled, then mark the source
980 // image with the same colorspace as the destination surface so that Skia's color
981 // management is a no-op.
982 const ui::Dataspace layerDataspace = (!mUseColorManagement || requiresLinearEffect)
983 ? dstDataspace
Sally Qi59a9f502021-10-12 18:53:23 +0000984 : layer.sourceDataspace;
Alec Mouric0aae732021-01-12 13:32:18 -0800985
Derek Sollenbergerecb21462021-01-29 16:53:49 -0500986 SkPaint paint;
Sally Qi59a9f502021-10-12 18:53:23 +0000987 if (layer.source.buffer.buffer) {
John Reck67b1e2b2020-08-26 13:17:24 -0700988 ATRACE_NAME("DrawImage");
Sally Qi59a9f502021-10-12 18:53:23 +0000989 validateInputBufferUsage(layer.source.buffer.buffer->getBuffer());
990 const auto& item = layer.source.buffer;
Alec Mouric7f6c8b2020-11-09 18:35:20 -0800991 std::shared_ptr<AutoBackendTexture::LocalRef> imageTextureRef = nullptr;
Alec Mouria90a5702021-04-16 16:36:21 +0000992
993 if (const auto& iter = cache.find(item.buffer->getBuffer()->getId());
994 iter != cache.end()) {
Alec Mouric7f6c8b2020-11-09 18:35:20 -0800995 imageTextureRef = iter->second;
John Reck67b1e2b2020-08-26 13:17:24 -0700996 } else {
Alec Mouria90a5702021-04-16 16:36:21 +0000997 // If we didn't find the image in the cache, then create a local ref but don't cache
998 // it. If we're using skia, we're guaranteed to run on a dedicated GPU thread so if
999 // we didn't find anything in the cache then we intentionally did not cache this
1000 // buffer's resources.
Derek Sollenbergerd8fdae32021-04-09 13:52:59 -04001001 imageTextureRef = std::make_shared<
Derek Sollenbergerb24258c2021-05-04 13:47:34 -04001002 AutoBackendTexture::LocalRef>(grContext,
Derek Sollenbergerd8fdae32021-04-09 13:52:59 -04001003 item.buffer->getBuffer()->toAHardwareBuffer(),
Derek Sollenbergerd3f60652021-06-11 15:34:36 -04001004 false, mTextureCleanupMgr);
John Reck67b1e2b2020-08-26 13:17:24 -07001005 }
Alec Mouri1a4d0642020-11-13 17:42:01 -08001006
Alec Mouri4ee7b492021-08-11 10:36:55 -07001007 // if the layer's buffer has a fence, then we must must respect the fence prior to using
1008 // the buffer.
Sally Qi59a9f502021-10-12 18:53:23 +00001009 if (layer.source.buffer.fence != nullptr) {
1010 waitFence(layer.source.buffer.fence->get());
Alec Mouri4ee7b492021-08-11 10:36:55 -07001011 }
1012
Leon Scroggins IIIc4e0cbd2021-05-25 10:25:20 -04001013 // isOpaque means we need to ignore the alpha in the image,
1014 // replacing it with the alpha specified by the LayerSettings. See
1015 // https://developer.android.com/reference/android/view/SurfaceControl.Builder#setOpaque(boolean)
1016 // The proper way to do this is to use an SkColorType that ignores
1017 // alpha, like kRGB_888x_SkColorType, and that is used if the
1018 // incoming image is kRGBA_8888_SkColorType. However, the incoming
1019 // image may be kRGBA_F16_SkColorType, for which there is no RGBX
1020 // SkColorType, or kRGBA_1010102_SkColorType, for which we have
1021 // kRGB_101010x_SkColorType, but it is not yet supported as a source
1022 // on the GPU. (Adding both is tracked in skbug.com/12048.) In the
1023 // meantime, we'll use a workaround that works unless we need to do
1024 // any color conversion. The workaround requires that we pretend the
1025 // image is already premultiplied, so that we do not premultiply it
1026 // before applying SkBlendMode::kPlus.
1027 const bool useIsOpaqueWorkaround = item.isOpaque &&
1028 (imageTextureRef->colorType() == kRGBA_1010102_SkColorType ||
1029 imageTextureRef->colorType() == kRGBA_F16_SkColorType);
1030 const auto alphaType = useIsOpaqueWorkaround ? kPremul_SkAlphaType
1031 : item.isOpaque ? kOpaque_SkAlphaType
1032 : item.usePremultipliedAlpha ? kPremul_SkAlphaType
1033 : kUnpremul_SkAlphaType;
1034 sk_sp<SkImage> image = imageTextureRef->makeImage(layerDataspace, alphaType, grContext);
Alec Mouri678245d2020-09-30 16:58:23 -07001035
1036 auto texMatrix = getSkM44(item.textureTransform).asM33();
1037 // textureTansform was intended to be passed directly into a shader, so when
1038 // building the total matrix with the textureTransform we need to first
1039 // normalize it, then apply the textureTransform, then scale back up.
Derek Sollenbergerecb21462021-01-29 16:53:49 -05001040 texMatrix.preScale(1.0f / bounds.width(), 1.0f / bounds.height());
Huihong Luo3a3cf3c2020-12-07 17:05:41 -08001041 texMatrix.postScale(image->width(), image->height());
Alec Mouri678245d2020-09-30 16:58:23 -07001042
Huihong Luo3a3cf3c2020-12-07 17:05:41 -08001043 SkMatrix matrix;
1044 if (!texMatrix.invert(&matrix)) {
1045 matrix = texMatrix;
Alec Mouri678245d2020-09-30 16:58:23 -07001046 }
Ana Krulecf9a15d92020-12-11 08:35:00 -08001047 // The shader does not respect the translation, so we add it to the texture
1048 // transform for the SkImage. This will make sure that the correct layer contents
1049 // are drawn in the correct part of the screen.
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001050 matrix.postTranslate(bounds.rect().fLeft, bounds.rect().fTop);
Alec Mouri678245d2020-09-30 16:58:23 -07001051
Ana Krulecb7b28b22020-11-23 14:48:58 -08001052 sk_sp<SkShader> shader;
1053
Sally Qi59a9f502021-10-12 18:53:23 +00001054 if (layer.source.buffer.useTextureFiltering) {
Ana Krulecb7b28b22020-11-23 14:48:58 -08001055 shader = image->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
1056 SkSamplingOptions(
1057 {SkFilterMode::kLinear, SkMipmapMode::kNone}),
1058 &matrix);
1059 } else {
Mike Reed711e1f02020-12-11 13:06:19 -05001060 shader = image->makeShader(SkSamplingOptions(), matrix);
Ana Krulecb7b28b22020-11-23 14:48:58 -08001061 }
Alec Mouri029d1952020-10-12 10:37:08 -07001062
Leon Scroggins IIIc4e0cbd2021-05-25 10:25:20 -04001063 if (useIsOpaqueWorkaround) {
Alec Mouric0aae732021-01-12 13:32:18 -08001064 shader = SkShaders::Blend(SkBlendMode::kPlus, shader,
1065 SkShaders::Color(SkColors::kBlack,
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -05001066 toSkColorSpace(layerDataspace)));
Alec Mouric0aae732021-01-12 13:32:18 -08001067 }
1068
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -05001069 paint.setShader(createRuntimeEffectShader(shader, layer, display,
1070 !item.isOpaque && item.usePremultipliedAlpha,
1071 requiresLinearEffect));
Sally Qi59a9f502021-10-12 18:53:23 +00001072 paint.setAlphaf(layer.alpha);
John Reck67b1e2b2020-08-26 13:17:24 -07001073 } else {
1074 ATRACE_NAME("DrawColor");
Sally Qi59a9f502021-10-12 18:53:23 +00001075 const auto color = layer.source.solidColor;
Ana Krulec47814212021-01-06 19:00:10 -08001076 sk_sp<SkShader> shader = SkShaders::Color(SkColor4f{.fR = color.r,
1077 .fG = color.g,
1078 .fB = color.b,
Sally Qi59a9f502021-10-12 18:53:23 +00001079 .fA = layer.alpha},
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -05001080 toSkColorSpace(layerDataspace));
Ana Krulec47814212021-01-06 19:00:10 -08001081 paint.setShader(createRuntimeEffectShader(shader, layer, display,
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -05001082 /* undoPremultipliedAlpha */ false,
1083 requiresLinearEffect));
John Reck67b1e2b2020-08-26 13:17:24 -07001084 }
Lucas Dupin21f348e2020-09-16 17:31:26 -07001085
Sally Qi59a9f502021-10-12 18:53:23 +00001086 if (layer.disableBlending) {
Leon Scroggins IIIcf3d95c2021-03-19 13:06:32 -04001087 paint.setBlendMode(SkBlendMode::kSrc);
1088 }
1089
Derek Sollenbergere2fe78c2021-02-23 13:22:54 -05001090 paint.setColorFilter(displayColorTransform);
Alec Mourib34f0b72020-10-02 13:18:34 -07001091
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001092 if (!roundRectClip.isEmpty()) {
1093 canvas->clipRRect(roundRectClip, true);
1094 }
1095
1096 if (!bounds.isRect()) {
Derek Sollenberger4c331c82021-02-23 13:09:50 -05001097 paint.setAntiAlias(true);
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001098 canvas->drawRRect(bounds, paint);
Alec Mouribd17b3b2020-12-17 11:08:30 -08001099 } else {
Nader Jawad63644d32021-05-07 10:44:21 -07001100 canvas->drawRect(bounds.rect(), paint);
Lucas Dupin3f11e922020-09-22 17:31:04 -07001101 }
Nathaniel Nifongb9f27ef2021-04-01 16:44:12 -04001102 if (kFlushAfterEveryLayer) {
1103 ATRACE_NAME("flush surface");
1104 activeSurface->flush();
1105 }
John Reck67b1e2b2020-08-26 13:17:24 -07001106 }
Derek Sollenberger7c42bef2021-02-23 13:01:39 -05001107 surfaceAutoSaveRestore.restore();
Alec Mouric0aae732021-01-12 13:32:18 -08001108 mCapture->endCapture();
John Reck67b1e2b2020-08-26 13:17:24 -07001109 {
1110 ATRACE_NAME("flush surface");
Derek Sollenberger3f77aa42021-02-04 11:06:34 -05001111 LOG_ALWAYS_FATAL_IF(activeSurface != dstSurface);
1112 activeSurface->flush();
John Reck67b1e2b2020-08-26 13:17:24 -07001113 }
1114
Sally Qi4cabdd02021-08-05 16:45:57 -07001115 base::unique_fd drawFence = flush();
John Reck67b1e2b2020-08-26 13:17:24 -07001116
1117 // If flush failed or we don't support native fences, we need to force the
1118 // gl command stream to be executed.
Sally Qi4cabdd02021-08-05 16:45:57 -07001119 bool requireSync = drawFence.get() < 0;
John Reck67b1e2b2020-08-26 13:17:24 -07001120 if (requireSync) {
1121 ATRACE_BEGIN("Submit(sync=true)");
1122 } else {
1123 ATRACE_BEGIN("Submit(sync=false)");
1124 }
Lucas Dupind508e472020-11-04 04:32:06 +00001125 bool success = grContext->submit(requireSync);
John Reck67b1e2b2020-08-26 13:17:24 -07001126 ATRACE_END();
1127 if (!success) {
1128 ALOGE("Failed to flush RenderEngine commands");
1129 // Chances are, something illegal happened (either the caller passed
1130 // us bad parameters, or we messed up our shader generation).
Sally Qi4cabdd02021-08-05 16:45:57 -07001131 resultPromise->set_value({INVALID_OPERATION, std::move(drawFence)});
1132 return;
John Reck67b1e2b2020-08-26 13:17:24 -07001133 }
1134
1135 // checkErrors();
Sally Qi4cabdd02021-08-05 16:45:57 -07001136 resultPromise->set_value({NO_ERROR, std::move(drawFence)});
1137 return;
John Reck67b1e2b2020-08-26 13:17:24 -07001138}
1139
Lucas Dupin3f11e922020-09-22 17:31:04 -07001140inline SkRect SkiaGLRenderEngine::getSkRect(const FloatRect& rect) {
1141 return SkRect::MakeLTRB(rect.left, rect.top, rect.right, rect.bottom);
1142}
1143
1144inline SkRect SkiaGLRenderEngine::getSkRect(const Rect& rect) {
1145 return SkRect::MakeLTRB(rect.left, rect.top, rect.right, rect.bottom);
1146}
1147
Derek Sollenberger547d0a62021-07-27 14:09:17 -04001148/**
1149 * Verifies that common, simple bounds + clip combinations can be converted into
1150 * a single RRect draw call returning true if possible. If true the radii parameter
1151 * will be filled with the correct radii values that combined with bounds param will
1152 * produce the insected roundRect. If false, the returned state of the radii param is undefined.
1153 */
1154static bool intersectionIsRoundRect(const SkRect& bounds, const SkRect& crop,
1155 const SkRect& insetCrop, float cornerRadius,
1156 SkVector radii[4]) {
1157 const bool leftEqual = bounds.fLeft == crop.fLeft;
1158 const bool topEqual = bounds.fTop == crop.fTop;
1159 const bool rightEqual = bounds.fRight == crop.fRight;
1160 const bool bottomEqual = bounds.fBottom == crop.fBottom;
1161
1162 // In the event that the corners of the bounds only partially align with the crop we
1163 // need to ensure that the resulting shape can still be represented as a round rect.
1164 // In particular the round rect implementation will scale the value of all corner radii
1165 // if the sum of the radius along any edge is greater than the length of that edge.
1166 // See https://www.w3.org/TR/css-backgrounds-3/#corner-overlap
1167 const bool requiredWidth = bounds.width() > (cornerRadius * 2);
1168 const bool requiredHeight = bounds.height() > (cornerRadius * 2);
1169 if (!requiredWidth || !requiredHeight) {
1170 return false;
1171 }
1172
1173 // Check each cropped corner to ensure that it exactly matches the crop or its corner is
1174 // contained within the cropped shape and does not need rounded.
1175 // compute the UpperLeft corner radius
1176 if (leftEqual && topEqual) {
1177 radii[0].set(cornerRadius, cornerRadius);
1178 } else if ((leftEqual && bounds.fTop >= insetCrop.fTop) ||
1179 (topEqual && bounds.fLeft >= insetCrop.fLeft)) {
1180 radii[0].set(0, 0);
1181 } else {
1182 return false;
1183 }
1184 // compute the UpperRight corner radius
1185 if (rightEqual && topEqual) {
1186 radii[1].set(cornerRadius, cornerRadius);
1187 } else if ((rightEqual && bounds.fTop >= insetCrop.fTop) ||
1188 (topEqual && bounds.fRight <= insetCrop.fRight)) {
1189 radii[1].set(0, 0);
1190 } else {
1191 return false;
1192 }
1193 // compute the BottomRight corner radius
1194 if (rightEqual && bottomEqual) {
1195 radii[2].set(cornerRadius, cornerRadius);
1196 } else if ((rightEqual && bounds.fBottom <= insetCrop.fBottom) ||
1197 (bottomEqual && bounds.fRight <= insetCrop.fRight)) {
1198 radii[2].set(0, 0);
1199 } else {
1200 return false;
1201 }
1202 // compute the BottomLeft corner radius
1203 if (leftEqual && bottomEqual) {
1204 radii[3].set(cornerRadius, cornerRadius);
1205 } else if ((leftEqual && bounds.fBottom <= insetCrop.fBottom) ||
1206 (bottomEqual && bounds.fLeft >= insetCrop.fLeft)) {
1207 radii[3].set(0, 0);
1208 } else {
1209 return false;
1210 }
1211
1212 return true;
1213}
1214
Derek Sollenbergerc31985e2021-05-18 16:38:17 -04001215inline std::pair<SkRRect, SkRRect> SkiaGLRenderEngine::getBoundsAndClip(const FloatRect& boundsRect,
1216 const FloatRect& cropRect,
1217 const float cornerRadius) {
1218 const SkRect bounds = getSkRect(boundsRect);
1219 const SkRect crop = getSkRect(cropRect);
Lucas Dupin21f348e2020-09-16 17:31:26 -07001220
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001221 SkRRect clip;
1222 if (cornerRadius > 0) {
Derek Sollenberger4f9959f2021-05-12 16:47:37 -04001223 // it the crop and the bounds are equivalent or there is no crop then we don't need a clip
1224 if (bounds == crop || crop.isEmpty()) {
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001225 return {SkRRect::MakeRectXY(bounds, cornerRadius, cornerRadius), clip};
1226 }
1227
1228 // This makes an effort to speed up common, simple bounds + clip combinations by
1229 // converting them to a single RRect draw. It is possible there are other cases
1230 // that can be converted.
1231 if (crop.contains(bounds)) {
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001232 const auto insetCrop = crop.makeInset(cornerRadius, cornerRadius);
Derek Sollenberger547d0a62021-07-27 14:09:17 -04001233 if (insetCrop.contains(bounds)) {
1234 return {SkRRect::MakeRect(bounds), clip}; // clip is empty - no rounding required
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001235 }
1236
Derek Sollenberger547d0a62021-07-27 14:09:17 -04001237 SkVector radii[4];
1238 if (intersectionIsRoundRect(bounds, crop, insetCrop, cornerRadius, radii)) {
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001239 SkRRect intersectionBounds;
1240 intersectionBounds.setRectRadii(bounds, radii);
1241 return {intersectionBounds, clip};
1242 }
1243 }
1244
Derek Sollenberger547d0a62021-07-27 14:09:17 -04001245 // we didn't hit any of our fast paths so set the clip to the cropRect
Derek Sollenberger8e8b3bf2021-04-29 15:35:28 -04001246 clip.setRectXY(crop, cornerRadius, cornerRadius);
1247 }
1248
1249 // if we hit this point then we either don't have rounded corners or we are going to rely
1250 // on the clip to round the corners for us
1251 return {SkRRect::MakeRect(bounds), clip};
Galia Peycheva80116e52020-11-06 11:57:25 +01001252}
1253
Sally Qi59a9f502021-10-12 18:53:23 +00001254inline bool SkiaGLRenderEngine::layerHasBlur(const LayerSettings& layer,
Derek Sollenbergerc20e0802021-05-19 16:20:59 -04001255 bool colorTransformModifiesAlpha) {
Sally Qi59a9f502021-10-12 18:53:23 +00001256 if (layer.backgroundBlurRadius > 0 || layer.blurRegions.size()) {
Derek Sollenbergerc20e0802021-05-19 16:20:59 -04001257 // return false if the content is opaque and would therefore occlude the blur
Sally Qi59a9f502021-10-12 18:53:23 +00001258 const bool opaqueContent = !layer.source.buffer.buffer || layer.source.buffer.isOpaque;
1259 const bool opaqueAlpha = layer.alpha == 1.0f && !colorTransformModifiesAlpha;
1260 return layer.skipContentDraw || !(opaqueContent && opaqueAlpha);
Derek Sollenbergerc20e0802021-05-19 16:20:59 -04001261 }
1262 return false;
Derek Sollenbergerecb21462021-01-29 16:53:49 -05001263}
1264
Lucas Dupin3f11e922020-09-22 17:31:04 -07001265inline SkColor SkiaGLRenderEngine::getSkColor(const vec4& color) {
1266 return SkColorSetARGB(color.a * 255, color.r * 255, color.g * 255, color.b * 255);
1267}
1268
Lucas Dupinbb1a1d42020-09-18 15:17:02 -07001269inline SkM44 SkiaGLRenderEngine::getSkM44(const mat4& matrix) {
1270 return SkM44(matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0],
1271 matrix[0][1], matrix[1][1], matrix[2][1], matrix[3][1],
1272 matrix[0][2], matrix[1][2], matrix[2][2], matrix[3][2],
1273 matrix[0][3], matrix[1][3], matrix[2][3], matrix[3][3]);
1274}
1275
Lucas Dupin3f11e922020-09-22 17:31:04 -07001276inline SkPoint3 SkiaGLRenderEngine::getSkPoint3(const vec3& vector) {
1277 return SkPoint3::Make(vector.x, vector.y, vector.z);
1278}
1279
John Reck67b1e2b2020-08-26 13:17:24 -07001280size_t SkiaGLRenderEngine::getMaxTextureSize() const {
1281 return mGrContext->maxTextureSize();
1282}
1283
1284size_t SkiaGLRenderEngine::getMaxViewportDims() const {
1285 return mGrContext->maxRenderTargetSize();
1286}
1287
Derek Sollenbergerb0e764c2021-05-04 14:31:37 -04001288void SkiaGLRenderEngine::drawShadow(SkCanvas* canvas, const SkRRect& casterRRect,
Lucas Dupin3f11e922020-09-22 17:31:04 -07001289 const ShadowSettings& settings) {
1290 ATRACE_CALL();
1291 const float casterZ = settings.length / 2.0f;
Lucas Dupin3f11e922020-09-22 17:31:04 -07001292 const auto flags =
1293 settings.casterIsTranslucent ? kTransparentOccluder_ShadowFlag : kNone_ShadowFlag;
1294
Derek Sollenbergerb0e764c2021-05-04 14:31:37 -04001295 SkShadowUtils::DrawShadow(canvas, SkPath::RRect(casterRRect), SkPoint3::Make(0, 0, casterZ),
Lucas Dupin3f11e922020-09-22 17:31:04 -07001296 getSkPoint3(settings.lightPos), settings.lightRadius,
1297 getSkColor(settings.ambientColor), getSkColor(settings.spotColor),
1298 flags);
1299}
1300
John Reck67b1e2b2020-08-26 13:17:24 -07001301EGLContext SkiaGLRenderEngine::createEglContext(EGLDisplay display, EGLConfig config,
Alec Mourid6f09462020-12-07 11:18:17 -08001302 EGLContext shareContext,
1303 std::optional<ContextPriority> contextPriority,
John Reck67b1e2b2020-08-26 13:17:24 -07001304 Protection protection) {
1305 EGLint renderableType = 0;
1306 if (config == EGL_NO_CONFIG_KHR) {
1307 renderableType = EGL_OPENGL_ES3_BIT;
1308 } else if (!eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType)) {
1309 LOG_ALWAYS_FATAL("can't query EGLConfig RENDERABLE_TYPE");
1310 }
1311 EGLint contextClientVersion = 0;
1312 if (renderableType & EGL_OPENGL_ES3_BIT) {
1313 contextClientVersion = 3;
1314 } else if (renderableType & EGL_OPENGL_ES2_BIT) {
1315 contextClientVersion = 2;
1316 } else if (renderableType & EGL_OPENGL_ES_BIT) {
1317 contextClientVersion = 1;
1318 } else {
1319 LOG_ALWAYS_FATAL("no supported EGL_RENDERABLE_TYPEs");
1320 }
1321
1322 std::vector<EGLint> contextAttributes;
1323 contextAttributes.reserve(7);
1324 contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
1325 contextAttributes.push_back(contextClientVersion);
Alec Mourid6f09462020-12-07 11:18:17 -08001326 if (contextPriority) {
John Reck67b1e2b2020-08-26 13:17:24 -07001327 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_LEVEL_IMG);
Alec Mourid6f09462020-12-07 11:18:17 -08001328 switch (*contextPriority) {
1329 case ContextPriority::REALTIME:
1330 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_REALTIME_NV);
1331 break;
1332 case ContextPriority::MEDIUM:
1333 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_MEDIUM_IMG);
1334 break;
1335 case ContextPriority::LOW:
1336 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_LOW_IMG);
1337 break;
1338 case ContextPriority::HIGH:
1339 default:
1340 contextAttributes.push_back(EGL_CONTEXT_PRIORITY_HIGH_IMG);
1341 break;
1342 }
John Reck67b1e2b2020-08-26 13:17:24 -07001343 }
1344 if (protection == Protection::PROTECTED) {
1345 contextAttributes.push_back(EGL_PROTECTED_CONTENT_EXT);
1346 contextAttributes.push_back(EGL_TRUE);
1347 }
1348 contextAttributes.push_back(EGL_NONE);
1349
1350 EGLContext context = eglCreateContext(display, config, shareContext, contextAttributes.data());
1351
1352 if (contextClientVersion == 3 && context == EGL_NO_CONTEXT) {
1353 // eglGetConfigAttrib indicated we can create GLES 3 context, but we failed, thus
1354 // EGL_NO_CONTEXT so that we can abort.
1355 if (config != EGL_NO_CONFIG_KHR) {
1356 return context;
1357 }
1358 // If |config| is EGL_NO_CONFIG_KHR, we speculatively try to create GLES 3 context, so we
1359 // should try to fall back to GLES 2.
1360 contextAttributes[1] = 2;
1361 context = eglCreateContext(display, config, shareContext, contextAttributes.data());
1362 }
1363
1364 return context;
1365}
1366
Alec Mourid6f09462020-12-07 11:18:17 -08001367std::optional<RenderEngine::ContextPriority> SkiaGLRenderEngine::createContextPriority(
1368 const RenderEngineCreationArgs& args) {
1369 if (!gl::GLExtensions::getInstance().hasContextPriority()) {
1370 return std::nullopt;
1371 }
1372
1373 switch (args.contextPriority) {
1374 case RenderEngine::ContextPriority::REALTIME:
1375 if (gl::GLExtensions::getInstance().hasRealtimePriority()) {
1376 return RenderEngine::ContextPriority::REALTIME;
1377 } else {
1378 ALOGI("Realtime priority unsupported, degrading gracefully to high priority");
1379 return RenderEngine::ContextPriority::HIGH;
1380 }
1381 case RenderEngine::ContextPriority::HIGH:
1382 case RenderEngine::ContextPriority::MEDIUM:
1383 case RenderEngine::ContextPriority::LOW:
1384 return args.contextPriority;
1385 default:
1386 return std::nullopt;
1387 }
1388}
1389
John Reck67b1e2b2020-08-26 13:17:24 -07001390EGLSurface SkiaGLRenderEngine::createPlaceholderEglPbufferSurface(EGLDisplay display,
1391 EGLConfig config, int hwcFormat,
1392 Protection protection) {
1393 EGLConfig placeholderConfig = config;
1394 if (placeholderConfig == EGL_NO_CONFIG_KHR) {
1395 placeholderConfig = chooseEglConfig(display, hwcFormat, /*logConfig*/ true);
1396 }
1397 std::vector<EGLint> attributes;
1398 attributes.reserve(7);
1399 attributes.push_back(EGL_WIDTH);
1400 attributes.push_back(1);
1401 attributes.push_back(EGL_HEIGHT);
1402 attributes.push_back(1);
1403 if (protection == Protection::PROTECTED) {
1404 attributes.push_back(EGL_PROTECTED_CONTENT_EXT);
1405 attributes.push_back(EGL_TRUE);
1406 }
1407 attributes.push_back(EGL_NONE);
1408
1409 return eglCreatePbufferSurface(display, placeholderConfig, attributes.data());
1410}
1411
Alec Mourid6f09462020-12-07 11:18:17 -08001412int SkiaGLRenderEngine::getContextPriority() {
1413 int value;
1414 eglQueryContext(mEGLDisplay, mEGLContext, EGL_CONTEXT_PRIORITY_LEVEL_IMG, &value);
1415 return value;
1416}
1417
Ady Abrahamed3290f2021-05-17 15:12:14 -07001418void SkiaGLRenderEngine::onActiveDisplaySizeChanged(ui::Size size) {
Derek Sollenbergerc4a05e12021-03-24 16:45:20 -04001419 // This cache multiplier was selected based on review of cache sizes relative
1420 // to the screen resolution. Looking at the worst case memory needed by blur (~1.5x),
1421 // shadows (~1x), and general data structures (e.g. vertex buffers) we selected this as a
1422 // conservative default based on that analysis.
1423 const float SURFACE_SIZE_MULTIPLIER = 3.5f * bytesPerPixel(mDefaultPixelFormat);
1424 const int maxResourceBytes = size.width * size.height * SURFACE_SIZE_MULTIPLIER;
1425
1426 // start by resizing the current context
Derek Sollenbergerb24258c2021-05-04 13:47:34 -04001427 getActiveGrContext()->setResourceCacheLimit(maxResourceBytes);
Derek Sollenbergerc4a05e12021-03-24 16:45:20 -04001428
1429 // if it is possible to switch contexts then we will resize the other context
Derek Sollenberger1ec2fb52021-06-16 15:11:27 -04001430 const bool originalProtectedState = mInProtectedContext;
1431 useProtectedContext(!mInProtectedContext);
1432 if (mInProtectedContext != originalProtectedState) {
Derek Sollenbergerb24258c2021-05-04 13:47:34 -04001433 getActiveGrContext()->setResourceCacheLimit(maxResourceBytes);
Derek Sollenbergerc4a05e12021-03-24 16:45:20 -04001434 // reset back to the initial context that was active when this method was called
Derek Sollenberger1ec2fb52021-06-16 15:11:27 -04001435 useProtectedContext(originalProtectedState);
Derek Sollenbergerc4a05e12021-03-24 16:45:20 -04001436 }
1437}
1438
Ana Krulec1d12b3b2021-01-27 16:49:51 -08001439void SkiaGLRenderEngine::dump(std::string& result) {
1440 const gl::GLExtensions& extensions = gl::GLExtensions::getInstance();
1441
1442 StringAppendF(&result, "\n ------------RE-----------------\n");
1443 StringAppendF(&result, "EGL implementation : %s\n", extensions.getEGLVersion());
1444 StringAppendF(&result, "%s\n", extensions.getEGLExtensions());
1445 StringAppendF(&result, "GLES: %s, %s, %s\n", extensions.getVendor(), extensions.getRenderer(),
1446 extensions.getVersion());
1447 StringAppendF(&result, "%s\n", extensions.getExtensions());
1448 StringAppendF(&result, "RenderEngine supports protected context: %d\n",
1449 supportsProtectedContent());
1450 StringAppendF(&result, "RenderEngine is in protected context: %d\n", mInProtectedContext);
Leon Scroggins III9f3072c2021-03-22 10:42:47 -04001451 StringAppendF(&result, "RenderEngine shaders cached since last dump/primeCache: %d\n",
1452 mSkSLCacheMonitor.shadersCachedSinceLastCall());
Ana Krulec1d12b3b2021-01-27 16:49:51 -08001453
Derek Sollenberger0e6d3562021-04-07 19:34:39 -04001454 std::vector<ResourcePair> cpuResourceMap = {
1455 {"skia/sk_resource_cache/bitmap_", "Bitmaps"},
1456 {"skia/sk_resource_cache/rrect-blur_", "Masks"},
1457 {"skia/sk_resource_cache/rects-blur_", "Masks"},
1458 {"skia/sk_resource_cache/tessellated", "Shadows"},
1459 {"skia", "Other"},
1460 };
1461 SkiaMemoryReporter cpuReporter(cpuResourceMap, false);
1462 SkGraphics::DumpMemoryStatistics(&cpuReporter);
1463 StringAppendF(&result, "Skia CPU Caches: ");
1464 cpuReporter.logTotals(result);
1465 cpuReporter.logOutput(result);
1466
Ana Krulec1d12b3b2021-01-27 16:49:51 -08001467 {
1468 std::lock_guard<std::mutex> lock(mRenderingMutex);
Derek Sollenberger0e6d3562021-04-07 19:34:39 -04001469
1470 std::vector<ResourcePair> gpuResourceMap = {
1471 {"texture_renderbuffer", "Texture/RenderBuffer"},
1472 {"texture", "Texture"},
1473 {"gr_text_blob_cache", "Text"},
1474 {"skia", "Other"},
1475 };
1476 SkiaMemoryReporter gpuReporter(gpuResourceMap, true);
1477 mGrContext->dumpMemoryStatistics(&gpuReporter);
1478 StringAppendF(&result, "Skia's GPU Caches: ");
1479 gpuReporter.logTotals(result);
1480 gpuReporter.logOutput(result);
1481 StringAppendF(&result, "Skia's Wrapped Objects:\n");
1482 gpuReporter.logOutput(result, true);
1483
Alec Mouria90a5702021-04-16 16:36:21 +00001484 StringAppendF(&result, "RenderEngine tracked buffers: %zu\n",
1485 mGraphicBufferExternalRefs.size());
1486 StringAppendF(&result, "Dumping buffer ids...\n");
1487 for (const auto& [id, refCounts] : mGraphicBufferExternalRefs) {
1488 StringAppendF(&result, "- 0x%" PRIx64 " - %d refs \n", id, refCounts);
1489 }
Derek Sollenberger0e6d3562021-04-07 19:34:39 -04001490 StringAppendF(&result, "RenderEngine AHB/BackendTexture cache size: %zu\n",
1491 mTextureCache.size());
Ana Krulec1d12b3b2021-01-27 16:49:51 -08001492 StringAppendF(&result, "Dumping buffer ids...\n");
1493 // TODO(178539829): It would be nice to know which layer these are coming from and what
1494 // the texture sizes are.
1495 for (const auto& [id, unused] : mTextureCache) {
1496 StringAppendF(&result, "- 0x%" PRIx64 "\n", id);
1497 }
1498 StringAppendF(&result, "\n");
Derek Sollenberger0e6d3562021-04-07 19:34:39 -04001499
1500 SkiaMemoryReporter gpuProtectedReporter(gpuResourceMap, true);
Derek Sollenberger80a7a762021-04-14 10:22:58 -04001501 if (mProtectedGrContext) {
1502 mProtectedGrContext->dumpMemoryStatistics(&gpuProtectedReporter);
1503 }
Derek Sollenberger0e6d3562021-04-07 19:34:39 -04001504 StringAppendF(&result, "Skia's GPU Protected Caches: ");
1505 gpuProtectedReporter.logTotals(result);
1506 gpuProtectedReporter.logOutput(result);
1507 StringAppendF(&result, "Skia's Protected Wrapped Objects:\n");
1508 gpuProtectedReporter.logOutput(result, true);
1509
Ana Krulec1d12b3b2021-01-27 16:49:51 -08001510 StringAppendF(&result, "\n");
1511 StringAppendF(&result, "RenderEngine runtime effects: %zu\n", mRuntimeEffects.size());
1512 for (const auto& [linearEffect, unused] : mRuntimeEffects) {
1513 StringAppendF(&result, "- inputDataspace: %s\n",
1514 dataspaceDetails(
1515 static_cast<android_dataspace>(linearEffect.inputDataspace))
1516 .c_str());
1517 StringAppendF(&result, "- outputDataspace: %s\n",
1518 dataspaceDetails(
1519 static_cast<android_dataspace>(linearEffect.outputDataspace))
1520 .c_str());
1521 StringAppendF(&result, "undoPremultipliedAlpha: %s\n",
1522 linearEffect.undoPremultipliedAlpha ? "true" : "false");
1523 }
1524 }
1525 StringAppendF(&result, "\n");
1526}
1527
John Reck67b1e2b2020-08-26 13:17:24 -07001528} // namespace skia
1529} // namespace renderengine
Galia Peycheva6c460652020-11-03 19:42:42 +01001530} // namespace android