blob: 9371656eda7fe9e0e1d1824d885f3aa2871b441b [file] [log] [blame]
John Reckcec24ae2013-11-05 13:27:50 -08001/*
2 * Copyright (C) 2013 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
John Reckcec24ae2013-11-05 13:27:50 -080017#include "RenderThread.h"
18
John Reck0fa0cbc2019-04-05 16:57:46 -070019#include "../HardwareBitmapUploader.h"
John Reck4f02bf42014-01-03 18:09:17 -080020#include "CanvasContext.h"
John Reck56428472018-03-16 17:27:17 -070021#include "DeviceInfo.h"
John Reck3b202512014-06-23 13:13:08 -070022#include "EglManager.h"
Stan Iliev1a025a72018-09-05 16:35:11 -040023#include "Readback.h"
John Reck4f02bf42014-01-03 18:09:17 -080024#include "RenderProxy.h"
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050025#include "VulkanManager.h"
John Reck1bcacfd2017-11-03 10:12:19 -070026#include "hwui/Bitmap.h"
27#include "pipeline/skia/SkiaOpenGLPipeline.h"
John Reck1a4a9812018-04-18 16:13:31 -070028#include "pipeline/skia/SkiaVulkanPipeline.h"
John Reck1bcacfd2017-11-03 10:12:19 -070029#include "renderstate/RenderState.h"
John Reck56428472018-03-16 17:27:17 -070030#include "utils/TimeUtils.h"
John Reck322b8ab2019-03-14 13:15:28 -070031#include "utils/TraceUtils.h"
John Reckcec24ae2013-11-05 13:27:50 -080032
John Reck1e510712018-04-23 08:15:03 -070033#include <GrContextOptions.h>
34#include <gl/GrGLInterface.h>
35
Chris Craik65fe5ee2015-01-26 18:06:29 -080036#include <sys/resource.h>
John Reckcba287b2015-11-10 12:52:44 -080037#include <utils/Condition.h>
Chris Craik65fe5ee2015-01-26 18:06:29 -080038#include <utils/Log.h>
John Reckcba287b2015-11-10 12:52:44 -080039#include <utils/Mutex.h>
Stan Iliev898123b2019-02-14 14:57:44 -050040#include <thread>
Chris Craik65fe5ee2015-01-26 18:06:29 -080041
Jagadeesh Pakaravoorb624af32020-05-01 00:01:40 +000042#include <ui/FatVector.h>
43
John Reckcec24ae2013-11-05 13:27:50 -080044namespace android {
John Reckcec24ae2013-11-05 13:27:50 -080045namespace uirenderer {
46namespace renderthread {
47
John Reck6b507802015-11-03 10:09:59 -080048static bool gHasRenderThreadInstance = false;
49
Stan Iliev80dbc352019-02-05 15:31:28 -050050static JVMAttachHook gOnStartHook = nullptr;
John Reck259b25a2017-12-01 16:18:53 -080051
Alec Mouri4a818f12019-11-19 16:17:53 -080052void RenderThread::frameCallback(int64_t frameTimeNanos, void* data) {
53 RenderThread* rt = reinterpret_cast<RenderThread*>(data);
Steven Thomas6fabb5a2020-08-21 16:56:08 -070054 int64_t vsyncId = AChoreographer_getVsyncId(rt->mChoreographer);
Alec Mouri4a818f12019-11-19 16:17:53 -080055 rt->mVsyncRequested = false;
Steven Thomas6fabb5a2020-08-21 16:56:08 -070056 if (rt->timeLord().vsyncReceived(frameTimeNanos, frameTimeNanos, vsyncId) &&
57 !rt->mFrameCallbackTaskPending) {
Alec Mouri4a818f12019-11-19 16:17:53 -080058 ATRACE_NAME("queue mFrameCallbackTask");
59 rt->mFrameCallbackTaskPending = true;
60 nsecs_t runAt = (frameTimeNanos + rt->mDispatchFrameDelay);
61 rt->queue().postAt(runAt, [=]() { rt->dispatchFrameCallbacks(); });
62 }
63}
64
65void RenderThread::refreshRateCallback(int64_t vsyncPeriod, void* data) {
66 ATRACE_NAME("refreshRateCallback");
67 RenderThread* rt = reinterpret_cast<RenderThread*>(data);
68 DeviceInfo::get()->onRefreshRateChanged(vsyncPeriod);
69 rt->setupFrameInterval();
70}
71
72class ChoreographerSource : public VsyncSource {
John Reck56428472018-03-16 17:27:17 -070073public:
Alec Mouri4a818f12019-11-19 16:17:53 -080074 ChoreographerSource(RenderThread* renderThread) : mRenderThread(renderThread) {}
John Reck56428472018-03-16 17:27:17 -070075
76 virtual void requestNextVsync() override {
Alec Mouri4a818f12019-11-19 16:17:53 -080077 AChoreographer_postFrameCallback64(mRenderThread->mChoreographer,
78 RenderThread::frameCallback, mRenderThread);
John Reck56428472018-03-16 17:27:17 -070079 }
80
Alec Mouri4a818f12019-11-19 16:17:53 -080081 virtual void drainPendingEvents() override {
82 AChoreographer_handlePendingEvents(mRenderThread->mChoreographer, mRenderThread);
John Reck56428472018-03-16 17:27:17 -070083 }
84
85private:
Alec Mouri4a818f12019-11-19 16:17:53 -080086 RenderThread* mRenderThread;
John Reck56428472018-03-16 17:27:17 -070087};
88
89class DummyVsyncSource : public VsyncSource {
90public:
91 DummyVsyncSource(RenderThread* renderThread) : mRenderThread(renderThread) {}
92
93 virtual void requestNextVsync() override {
Alec Mouri4a818f12019-11-19 16:17:53 -080094 mRenderThread->queue().postDelayed(16_ms, [this]() {
95 RenderThread::frameCallback(systemTime(SYSTEM_TIME_MONOTONIC), mRenderThread);
96 });
John Reck56428472018-03-16 17:27:17 -070097 }
98
Alec Mouri4a818f12019-11-19 16:17:53 -080099 virtual void drainPendingEvents() override {
100 RenderThread::frameCallback(systemTime(SYSTEM_TIME_MONOTONIC), mRenderThread);
101 }
John Reck56428472018-03-16 17:27:17 -0700102
103private:
104 RenderThread* mRenderThread;
105};
106
John Reck6b507802015-11-03 10:09:59 -0800107bool RenderThread::hasInstance() {
108 return gHasRenderThreadInstance;
109}
110
Stan Iliev80dbc352019-02-05 15:31:28 -0500111void RenderThread::setOnStartHook(JVMAttachHook onStartHook) {
John Reck259b25a2017-12-01 16:18:53 -0800112 LOG_ALWAYS_FATAL_IF(hasInstance(), "can't set an onStartHook after we've started...");
113 gOnStartHook = onStartHook;
114}
115
Stan Iliev80dbc352019-02-05 15:31:28 -0500116JVMAttachHook RenderThread::getOnStartHook() {
117 return gOnStartHook;
118}
119
John Reck6b507802015-11-03 10:09:59 -0800120RenderThread& RenderThread::getInstance() {
121 // This is a pointer because otherwise __cxa_finalize
122 // will try to delete it like a Good Citizen but that causes us to crash
123 // because we don't want to delete the RenderThread normally.
124 static RenderThread* sInstance = new RenderThread();
125 gHasRenderThreadInstance = true;
126 return *sInstance;
127}
128
John Reck1bcacfd2017-11-03 10:12:19 -0700129RenderThread::RenderThread()
130 : ThreadBase()
John Reck56428472018-03-16 17:27:17 -0700131 , mVsyncSource(nullptr)
John Recke45b1fd2014-04-15 09:50:16 -0700132 , mVsyncRequested(false)
133 , mFrameCallbackTaskPending(false)
Chris Craikd41c4d82015-01-05 15:51:13 -0800134 , mRenderState(nullptr)
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500135 , mEglManager(nullptr)
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400136 , mFunctorManager(WebViewFunctorManager::instance()) {
Chris Craik2507c342015-05-04 14:36:49 -0700137 Properties::load();
John Reckf8441e62017-10-23 13:10:41 -0700138 start("RenderThread");
John Reckcec24ae2013-11-05 13:27:50 -0800139}
140
141RenderThread::~RenderThread() {
Alec Mouri4a818f12019-11-19 16:17:53 -0800142 // Note that if this fatal assertion is removed then member variables must
143 // be properly destroyed.
John Reck3b202512014-06-23 13:13:08 -0700144 LOG_ALWAYS_FATAL("Can't destroy the render thread");
John Reckcec24ae2013-11-05 13:27:50 -0800145}
146
Alec Mouri4a818f12019-11-19 16:17:53 -0800147void RenderThread::initializeChoreographer() {
148 LOG_ALWAYS_FATAL_IF(mVsyncSource, "Initializing a second Choreographer?");
John Recke45b1fd2014-04-15 09:50:16 -0700149
John Reck56428472018-03-16 17:27:17 -0700150 if (!Properties::isolatedProcess) {
Alec Mouri4a818f12019-11-19 16:17:53 -0800151 mChoreographer = AChoreographer_create();
152 LOG_ALWAYS_FATAL_IF(mChoreographer == nullptr, "Initialization of Choreographer failed");
153 AChoreographer_registerRefreshRateCallback(mChoreographer,
154 RenderThread::refreshRateCallback, this);
John Reck56428472018-03-16 17:27:17 -0700155
156 // Register the FD
Alec Mouri4a818f12019-11-19 16:17:53 -0800157 mLooper->addFd(AChoreographer_getFd(mChoreographer), 0, Looper::EVENT_INPUT,
158 RenderThread::choreographerCallback, this);
159 mVsyncSource = new ChoreographerSource(this);
John Reck56428472018-03-16 17:27:17 -0700160 } else {
161 mVsyncSource = new DummyVsyncSource(this);
162 }
John Recke45b1fd2014-04-15 09:50:16 -0700163}
164
John Reck3b202512014-06-23 13:13:08 -0700165void RenderThread::initThreadLocals() {
John Reckcf185f52019-04-11 16:11:24 -0700166 setupFrameInterval();
Alec Mouri4a818f12019-11-19 16:17:53 -0800167 initializeChoreographer();
John Reck1e510712018-04-23 08:15:03 -0700168 mEglManager = new EglManager();
John Reck0e89e2b2014-10-31 14:49:06 -0700169 mRenderState = new RenderState(*this);
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400170 mVkManager = VulkanManager::getInstance();
Alec Mouri22d753f2019-09-05 17:11:45 -0700171 mCacheManager = new CacheManager();
John Reckcf185f52019-04-11 16:11:24 -0700172}
173
174void RenderThread::setupFrameInterval() {
Alec Mouri4a818f12019-11-19 16:17:53 -0800175 nsecs_t frameIntervalNanos = DeviceInfo::getVsyncPeriod();
John Reckcf185f52019-04-11 16:11:24 -0700176 mTimeLord.setFrameInterval(frameIntervalNanos);
177 mDispatchFrameDelay = static_cast<nsecs_t>(frameIntervalNanos * .25f);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400178}
179
John Reck1e510712018-04-23 08:15:03 -0700180void RenderThread::requireGlContext() {
181 if (mEglManager->hasEglContext()) {
182 return;
183 }
184 mEglManager->initialize();
John Reck1e510712018-04-23 08:15:03 -0700185
John Reckb5fc2092018-04-30 14:43:22 -0700186 sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
John Reckb5fc2092018-04-30 14:43:22 -0700187 LOG_ALWAYS_FATAL_IF(!glInterface.get());
John Reck1e510712018-04-23 08:15:03 -0700188
John Reckb5fc2092018-04-30 14:43:22 -0700189 GrContextOptions options;
Stan Iliev981afe72019-02-13 14:24:33 -0500190 initGrContextOptions(options);
Yichi Chen9f959552018-03-29 21:21:54 +0800191 auto glesVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
192 auto size = glesVersion ? strlen(glesVersion) : -1;
193 cacheManager().configureContext(&options, glesVersion, size);
Adlai Hollerf8c434e2020-07-27 11:42:45 -0400194 sk_sp<GrDirectContext> grContext(GrDirectContext::MakeGL(std::move(glInterface), options));
John Reckb5fc2092018-04-30 14:43:22 -0700195 LOG_ALWAYS_FATAL_IF(!grContext.get());
196 setGrContext(grContext);
John Reck1e510712018-04-23 08:15:03 -0700197}
198
Stan Iliev981afe72019-02-13 14:24:33 -0500199void RenderThread::requireVkContext() {
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400200 // the getter creates the context in the event it had been destroyed by destroyRenderingContext
201 if (vulkanManager().hasVkContext()) {
Stan Iliev981afe72019-02-13 14:24:33 -0500202 return;
203 }
204 mVkManager->initialize();
205 GrContextOptions options;
206 initGrContextOptions(options);
Stan Ilievbf99c442019-03-29 11:09:11 -0400207 auto vkDriverVersion = mVkManager->getDriverVersion();
208 cacheManager().configureContext(&options, &vkDriverVersion, sizeof(vkDriverVersion));
Adlai Hollerf8c434e2020-07-27 11:42:45 -0400209 sk_sp<GrDirectContext> grContext = mVkManager->createContext(options);
Stan Iliev981afe72019-02-13 14:24:33 -0500210 LOG_ALWAYS_FATAL_IF(!grContext.get());
211 setGrContext(grContext);
212}
213
214void RenderThread::initGrContextOptions(GrContextOptions& options) {
215 options.fPreferExternalImagesOverES3 = true;
216 options.fDisableDistanceFieldPaths = true;
217}
218
John Reck283bb462018-12-13 16:40:14 -0800219void RenderThread::destroyRenderingContext() {
220 mFunctorManager.onContextDestroyed();
Stan Iliev90276c82019-02-03 18:01:02 -0500221 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) {
222 if (mEglManager->hasEglContext()) {
223 setGrContext(nullptr);
224 mEglManager->destroy();
225 }
226 } else {
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400227 setGrContext(nullptr);
228 mVkManager.clear();
John Reck1e510712018-04-23 08:15:03 -0700229 }
230}
231
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400232VulkanManager& RenderThread::vulkanManager() {
233 if (!mVkManager.get()) {
234 mVkManager = VulkanManager::getInstance();
235 }
236 return *mVkManager.get();
237}
238
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400239void RenderThread::dumpGraphicsMemory(int fd) {
John Reck34781b22017-07-05 16:39:36 -0700240 globalProfileData()->dump(fd);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400241
242 String8 cachesOutput;
243 String8 pipeline;
244 auto renderType = Properties::getRenderPipelineType();
245 switch (renderType) {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400246 case RenderPipelineType::SkiaGL: {
247 mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState);
248 pipeline.appendFormat("Skia (OpenGL)");
249 break;
250 }
251 case RenderPipelineType::SkiaVulkan: {
252 mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState);
253 pipeline.appendFormat("Skia (Vulkan)");
254 break;
255 }
256 default:
John Reck1bcacfd2017-11-03 10:12:19 -0700257 LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400258 break;
259 }
260
John Reck47f5c3a2017-11-13 11:32:39 -0800261 dprintf(fd, "\n%s\n", cachesOutput.string());
262 dprintf(fd, "\nPipeline=%s\n", pipeline.string());
John Reck3b202512014-06-23 13:13:08 -0700263}
264
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500265Readback& RenderThread::readback() {
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500266 if (!mReadback) {
Stan Iliev1a025a72018-09-05 16:35:11 -0400267 mReadback = new Readback(*this);
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500268 }
269
270 return *mReadback;
271}
272
Adlai Hollerf8c434e2020-07-27 11:42:45 -0400273void RenderThread::setGrContext(sk_sp<GrDirectContext> context) {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400274 mCacheManager->reset(context);
Greg Daniel660d6ec2017-12-08 11:44:27 -0500275 if (mGrContext) {
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400276 mRenderState->onContextDestroyed();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400277 mGrContext->releaseResourcesAndAbandonContext();
278 }
Greg Daniel660d6ec2017-12-08 11:44:27 -0500279 mGrContext = std::move(context);
Derek Sollenberger17662382018-09-13 14:14:00 -0400280 if (mGrContext) {
281 DeviceInfo::setMaxTextureSize(mGrContext->maxRenderTargetSize());
282 }
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400283}
284
Alec Mouri4a818f12019-11-19 16:17:53 -0800285int RenderThread::choreographerCallback(int fd, int events, void* data) {
John Recke45b1fd2014-04-15 09:50:16 -0700286 if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
287 ALOGE("Display event receiver pipe was closed or an error occurred. "
John Reck1bcacfd2017-11-03 10:12:19 -0700288 "events=0x%x",
289 events);
290 return 0; // remove the callback
John Recke45b1fd2014-04-15 09:50:16 -0700291 }
292
293 if (!(events & Looper::EVENT_INPUT)) {
294 ALOGW("Received spurious callback for unhandled poll event. "
John Reck1bcacfd2017-11-03 10:12:19 -0700295 "events=0x%x",
296 events);
297 return 1; // keep the callback
John Recke45b1fd2014-04-15 09:50:16 -0700298 }
Alec Mouri4a818f12019-11-19 16:17:53 -0800299 RenderThread* rt = reinterpret_cast<RenderThread*>(data);
300 AChoreographer_handlePendingEvents(rt->mChoreographer, data);
John Recke45b1fd2014-04-15 09:50:16 -0700301
Alec Mouri4a818f12019-11-19 16:17:53 -0800302 return 1;
John Recke45b1fd2014-04-15 09:50:16 -0700303}
304
305void RenderThread::dispatchFrameCallbacks() {
John Recka5dda642014-05-22 15:43:54 -0700306 ATRACE_CALL();
John Recke45b1fd2014-04-15 09:50:16 -0700307 mFrameCallbackTaskPending = false;
308
309 std::set<IFrameCallback*> callbacks;
310 mFrameCallbacks.swap(callbacks);
311
John Recka733f892014-12-19 11:37:21 -0800312 if (callbacks.size()) {
313 // Assume one of them will probably animate again so preemptively
314 // request the next vsync in case it occurs mid-frame
315 requestVsync();
John Reck1bcacfd2017-11-03 10:12:19 -0700316 for (std::set<IFrameCallback*>::iterator it = callbacks.begin(); it != callbacks.end();
317 it++) {
John Recka733f892014-12-19 11:37:21 -0800318 (*it)->doFrame();
319 }
John Recke45b1fd2014-04-15 09:50:16 -0700320 }
321}
322
John Recka5dda642014-05-22 15:43:54 -0700323void RenderThread::requestVsync() {
324 if (!mVsyncRequested) {
325 mVsyncRequested = true;
John Reck56428472018-03-16 17:27:17 -0700326 mVsyncSource->requestNextVsync();
John Recka5dda642014-05-22 15:43:54 -0700327 }
328}
329
John Reckcec24ae2013-11-05 13:27:50 -0800330bool RenderThread::threadLoop() {
John Reck21be43e2014-08-14 10:25:16 -0700331 setpriority(PRIO_PROCESS, 0, PRIORITY_DISPLAY);
John Reck700079e2019-02-19 10:38:50 -0800332 Looper::setForThread(mLooper);
John Reck259b25a2017-12-01 16:18:53 -0800333 if (gOnStartHook) {
Stan Iliev978d5322019-02-06 12:02:28 -0500334 gOnStartHook("RenderThread");
John Reck259b25a2017-12-01 16:18:53 -0800335 }
John Reck3b202512014-06-23 13:13:08 -0700336 initThreadLocals();
John Recke45b1fd2014-04-15 09:50:16 -0700337
John Reckf8441e62017-10-23 13:10:41 -0700338 while (true) {
339 waitForWork();
340 processQueue();
John Recka5dda642014-05-22 15:43:54 -0700341
342 if (mPendingRegistrationFrameCallbacks.size() && !mFrameCallbackTaskPending) {
Alec Mouri4a818f12019-11-19 16:17:53 -0800343 mVsyncSource->drainPendingEvents();
John Reck1bcacfd2017-11-03 10:12:19 -0700344 mFrameCallbacks.insert(mPendingRegistrationFrameCallbacks.begin(),
345 mPendingRegistrationFrameCallbacks.end());
John Recka5dda642014-05-22 15:43:54 -0700346 mPendingRegistrationFrameCallbacks.clear();
347 requestVsync();
348 }
John Recka22c9b22015-01-14 10:40:15 -0800349
350 if (!mFrameCallbackTaskPending && !mVsyncRequested && mFrameCallbacks.size()) {
351 // TODO: Clean this up. This is working around an issue where a combination
352 // of bad timing and slow drawing can result in dropping a stale vsync
353 // on the floor (correct!) but fails to schedule to listen for the
354 // next vsync (oops), so none of the callbacks are run.
355 requestVsync();
356 }
John Reckcec24ae2013-11-05 13:27:50 -0800357 }
358
359 return false;
360}
361
John Recke45b1fd2014-04-15 09:50:16 -0700362void RenderThread::postFrameCallback(IFrameCallback* callback) {
John Recka5dda642014-05-22 15:43:54 -0700363 mPendingRegistrationFrameCallbacks.insert(callback);
John Recke45b1fd2014-04-15 09:50:16 -0700364}
365
John Reck01a5ea32014-12-03 13:01:07 -0800366bool RenderThread::removeFrameCallback(IFrameCallback* callback) {
367 size_t erased;
368 erased = mFrameCallbacks.erase(callback);
369 erased |= mPendingRegistrationFrameCallbacks.erase(callback);
370 return erased;
John Recka5dda642014-05-22 15:43:54 -0700371}
372
373void RenderThread::pushBackFrameCallback(IFrameCallback* callback) {
374 if (mFrameCallbacks.erase(callback)) {
375 mPendingRegistrationFrameCallbacks.insert(callback);
376 }
John Recke45b1fd2014-04-15 09:50:16 -0700377}
378
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400379sk_sp<Bitmap> RenderThread::allocateHardwareBitmap(SkBitmap& skBitmap) {
380 auto renderType = Properties::getRenderPipelineType();
381 switch (renderType) {
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400382 case RenderPipelineType::SkiaVulkan:
383 return skiapipeline::SkiaVulkanPipeline::allocateHardwareBitmap(*this, skBitmap);
384 default:
John Reck1bcacfd2017-11-03 10:12:19 -0700385 LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType);
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400386 break;
387 }
388 return nullptr;
389}
390
Stan Iliev6b894d72017-08-23 12:41:41 -0400391bool RenderThread::isCurrent() {
392 return gettid() == getInstance().getTid();
393}
394
Stan Iliev898123b2019-02-14 14:57:44 -0500395void RenderThread::preload() {
Stan Iliev30b90962019-03-29 14:25:09 -0400396 // EGL driver is always preloaded only if HWUI renders with GL.
397 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700398 std::thread eglInitThread([]() { eglGetDisplay(EGL_DEFAULT_DISPLAY); });
Stan Iliev30b90962019-03-29 14:25:09 -0400399 eglInitThread.detach();
Yiwei Zhangbf371752020-07-31 21:03:29 +0000400 } else {
401 requireVkContext();
Stan Iliev898123b2019-02-14 14:57:44 -0500402 }
Yiwei Zhangbf371752020-07-31 21:03:29 +0000403 HardwareBitmapUploader::initialize();
Stan Iliev898123b2019-02-14 14:57:44 -0500404}
405
John Reckcec24ae2013-11-05 13:27:50 -0800406} /* namespace renderthread */
407} /* namespace uirenderer */
408} /* namespace android */