blob: 0c5599ed2d7999c0e8bb19052e2174ca10558fdb [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 Reck12efa552016-11-15 10:22:01 -080030#include "utils/FatVector.h"
John Reck56428472018-03-16 17:27:17 -070031#include "utils/TimeUtils.h"
John Reck322b8ab2019-03-14 13:15:28 -070032#include "utils/TraceUtils.h"
John Reckcec24ae2013-11-05 13:27:50 -080033
John Reck1e510712018-04-23 08:15:03 -070034#include <GrContextOptions.h>
35#include <gl/GrGLInterface.h>
36
Chris Craik65fe5ee2015-01-26 18:06:29 -080037#include <gui/DisplayEventReceiver.h>
38#include <sys/resource.h>
John Reckcba287b2015-11-10 12:52:44 -080039#include <utils/Condition.h>
Chris Craik65fe5ee2015-01-26 18:06:29 -080040#include <utils/Log.h>
John Reckcba287b2015-11-10 12:52:44 -080041#include <utils/Mutex.h>
Stan Iliev898123b2019-02-14 14:57:44 -050042#include <thread>
Chris Craik65fe5ee2015-01-26 18:06:29 -080043
John Reckcec24ae2013-11-05 13:27:50 -080044namespace android {
John Reckcec24ae2013-11-05 13:27:50 -080045namespace uirenderer {
46namespace renderthread {
47
John Recke45b1fd2014-04-15 09:50:16 -070048// Number of events to read at a time from the DisplayEventReceiver pipe.
49// The value should be large enough that we can quickly drain the pipe
50// using just a few large reads.
51static const size_t EVENT_BUFFER_SIZE = 100;
52
John Reck6b507802015-11-03 10:09:59 -080053static bool gHasRenderThreadInstance = false;
54
Stan Iliev80dbc352019-02-05 15:31:28 -050055static JVMAttachHook gOnStartHook = nullptr;
John Reck259b25a2017-12-01 16:18:53 -080056
John Reck56428472018-03-16 17:27:17 -070057class DisplayEventReceiverWrapper : public VsyncSource {
58public:
John Reckcf185f52019-04-11 16:11:24 -070059 DisplayEventReceiverWrapper(std::unique_ptr<DisplayEventReceiver>&& receiver,
60 const std::function<void()>& onDisplayConfigChanged)
61 : mDisplayEventReceiver(std::move(receiver))
62 , mOnDisplayConfigChanged(onDisplayConfigChanged) {}
John Reck56428472018-03-16 17:27:17 -070063
64 virtual void requestNextVsync() override {
65 status_t status = mDisplayEventReceiver->requestNextVsync();
66 LOG_ALWAYS_FATAL_IF(status != NO_ERROR, "requestNextVsync failed with status: %d", status);
67 }
68
69 virtual nsecs_t latestVsyncEvent() override {
70 DisplayEventReceiver::Event buf[EVENT_BUFFER_SIZE];
71 nsecs_t latest = 0;
72 ssize_t n;
73 while ((n = mDisplayEventReceiver->getEvents(buf, EVENT_BUFFER_SIZE)) > 0) {
74 for (ssize_t i = 0; i < n; i++) {
75 const DisplayEventReceiver::Event& ev = buf[i];
76 switch (ev.header.type) {
77 case DisplayEventReceiver::DISPLAY_EVENT_VSYNC:
78 latest = ev.header.timestamp;
79 break;
John Reckcf185f52019-04-11 16:11:24 -070080 case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED:
81 mOnDisplayConfigChanged();
82 break;
John Reck56428472018-03-16 17:27:17 -070083 }
84 }
85 }
86 if (n < 0) {
87 ALOGW("Failed to get events from display event receiver, status=%d", status_t(n));
88 }
89 return latest;
90 }
91
92private:
93 std::unique_ptr<DisplayEventReceiver> mDisplayEventReceiver;
John Reckcf185f52019-04-11 16:11:24 -070094 std::function<void()> mOnDisplayConfigChanged;
John Reck56428472018-03-16 17:27:17 -070095};
96
97class DummyVsyncSource : public VsyncSource {
98public:
99 DummyVsyncSource(RenderThread* renderThread) : mRenderThread(renderThread) {}
100
101 virtual void requestNextVsync() override {
John Reckb90d4cb2018-04-19 17:05:35 -0700102 mRenderThread->queue().postDelayed(16_ms,
103 [this]() { mRenderThread->drainDisplayEventQueue(); });
John Reck56428472018-03-16 17:27:17 -0700104 }
105
John Reckb90d4cb2018-04-19 17:05:35 -0700106 virtual nsecs_t latestVsyncEvent() override { return systemTime(CLOCK_MONOTONIC); }
John Reck56428472018-03-16 17:27:17 -0700107
108private:
109 RenderThread* mRenderThread;
110};
111
John Reck6b507802015-11-03 10:09:59 -0800112bool RenderThread::hasInstance() {
113 return gHasRenderThreadInstance;
114}
115
Stan Iliev80dbc352019-02-05 15:31:28 -0500116void RenderThread::setOnStartHook(JVMAttachHook onStartHook) {
John Reck259b25a2017-12-01 16:18:53 -0800117 LOG_ALWAYS_FATAL_IF(hasInstance(), "can't set an onStartHook after we've started...");
118 gOnStartHook = onStartHook;
119}
120
Stan Iliev80dbc352019-02-05 15:31:28 -0500121JVMAttachHook RenderThread::getOnStartHook() {
122 return gOnStartHook;
123}
124
John Reck6b507802015-11-03 10:09:59 -0800125RenderThread& RenderThread::getInstance() {
126 // This is a pointer because otherwise __cxa_finalize
127 // will try to delete it like a Good Citizen but that causes us to crash
128 // because we don't want to delete the RenderThread normally.
129 static RenderThread* sInstance = new RenderThread();
130 gHasRenderThreadInstance = true;
131 return *sInstance;
132}
133
John Reck1bcacfd2017-11-03 10:12:19 -0700134RenderThread::RenderThread()
135 : ThreadBase()
John Reck56428472018-03-16 17:27:17 -0700136 , mVsyncSource(nullptr)
John Recke45b1fd2014-04-15 09:50:16 -0700137 , mVsyncRequested(false)
138 , mFrameCallbackTaskPending(false)
Chris Craikd41c4d82015-01-05 15:51:13 -0800139 , mRenderState(nullptr)
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500140 , mEglManager(nullptr)
John Reck283bb462018-12-13 16:40:14 -0800141 , mFunctorManager(WebViewFunctorManager::instance())
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500142 , mVkManager(nullptr) {
Chris Craik2507c342015-05-04 14:36:49 -0700143 Properties::load();
John Reckf8441e62017-10-23 13:10:41 -0700144 start("RenderThread");
John Reckcec24ae2013-11-05 13:27:50 -0800145}
146
147RenderThread::~RenderThread() {
John Reck3b202512014-06-23 13:13:08 -0700148 LOG_ALWAYS_FATAL("Can't destroy the render thread");
John Reckcec24ae2013-11-05 13:27:50 -0800149}
150
John Recke45b1fd2014-04-15 09:50:16 -0700151void RenderThread::initializeDisplayEventReceiver() {
John Reck56428472018-03-16 17:27:17 -0700152 LOG_ALWAYS_FATAL_IF(mVsyncSource, "Initializing a second DisplayEventReceiver?");
John Recke45b1fd2014-04-15 09:50:16 -0700153
John Reck56428472018-03-16 17:27:17 -0700154 if (!Properties::isolatedProcess) {
155 auto receiver = std::make_unique<DisplayEventReceiver>();
156 status_t status = receiver->initCheck();
157 LOG_ALWAYS_FATAL_IF(status != NO_ERROR,
John Reckb90d4cb2018-04-19 17:05:35 -0700158 "Initialization of DisplayEventReceiver "
159 "failed with status: %d",
160 status);
John Reck56428472018-03-16 17:27:17 -0700161
162 // Register the FD
163 mLooper->addFd(receiver->getFd(), 0, Looper::EVENT_INPUT,
John Reckb90d4cb2018-04-19 17:05:35 -0700164 RenderThread::displayEventReceiverCallback, this);
John Reckcf185f52019-04-11 16:11:24 -0700165 mVsyncSource = new DisplayEventReceiverWrapper(std::move(receiver), [this] {
166 DeviceInfo::get()->onDisplayConfigChanged();
167 setupFrameInterval();
168 });
John Reck56428472018-03-16 17:27:17 -0700169 } else {
170 mVsyncSource = new DummyVsyncSource(this);
171 }
John Recke45b1fd2014-04-15 09:50:16 -0700172}
173
John Reck3b202512014-06-23 13:13:08 -0700174void RenderThread::initThreadLocals() {
John Reckcf185f52019-04-11 16:11:24 -0700175 setupFrameInterval();
John Reck3b202512014-06-23 13:13:08 -0700176 initializeDisplayEventReceiver();
John Reck1e510712018-04-23 08:15:03 -0700177 mEglManager = new EglManager();
John Reck0e89e2b2014-10-31 14:49:06 -0700178 mRenderState = new RenderState(*this);
Stan Iliev981afe72019-02-13 14:24:33 -0500179 mVkManager = new VulkanManager();
John Reckcf185f52019-04-11 16:11:24 -0700180 mCacheManager = new CacheManager(DeviceInfo::get()->displayInfo());
181}
182
183void RenderThread::setupFrameInterval() {
184 auto& displayInfo = DeviceInfo::get()->displayInfo();
185 nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1000000000 / displayInfo.fps);
186 mTimeLord.setFrameInterval(frameIntervalNanos);
187 mDispatchFrameDelay = static_cast<nsecs_t>(frameIntervalNanos * .25f);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400188}
189
John Reck1e510712018-04-23 08:15:03 -0700190void RenderThread::requireGlContext() {
191 if (mEglManager->hasEglContext()) {
192 return;
193 }
194 mEglManager->initialize();
John Reck1e510712018-04-23 08:15:03 -0700195
John Reckb5fc2092018-04-30 14:43:22 -0700196 sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
John Reckb5fc2092018-04-30 14:43:22 -0700197 LOG_ALWAYS_FATAL_IF(!glInterface.get());
John Reck1e510712018-04-23 08:15:03 -0700198
John Reckb5fc2092018-04-30 14:43:22 -0700199 GrContextOptions options;
Stan Iliev981afe72019-02-13 14:24:33 -0500200 initGrContextOptions(options);
Yichi Chen9f959552018-03-29 21:21:54 +0800201 auto glesVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
202 auto size = glesVersion ? strlen(glesVersion) : -1;
203 cacheManager().configureContext(&options, glesVersion, size);
John Reckb5fc2092018-04-30 14:43:22 -0700204 sk_sp<GrContext> grContext(GrContext::MakeGL(std::move(glInterface), options));
205 LOG_ALWAYS_FATAL_IF(!grContext.get());
206 setGrContext(grContext);
John Reck1e510712018-04-23 08:15:03 -0700207}
208
Stan Iliev981afe72019-02-13 14:24:33 -0500209void RenderThread::requireVkContext() {
210 if (mVkManager->hasVkContext()) {
211 return;
212 }
213 mVkManager->initialize();
214 GrContextOptions options;
215 initGrContextOptions(options);
Stan Ilievbf99c442019-03-29 11:09:11 -0400216 auto vkDriverVersion = mVkManager->getDriverVersion();
217 cacheManager().configureContext(&options, &vkDriverVersion, sizeof(vkDriverVersion));
Stan Iliev981afe72019-02-13 14:24:33 -0500218 sk_sp<GrContext> grContext = mVkManager->createContext(options);
219 LOG_ALWAYS_FATAL_IF(!grContext.get());
220 setGrContext(grContext);
221}
222
223void RenderThread::initGrContextOptions(GrContextOptions& options) {
224 options.fPreferExternalImagesOverES3 = true;
225 options.fDisableDistanceFieldPaths = true;
226}
227
John Reck283bb462018-12-13 16:40:14 -0800228void RenderThread::destroyRenderingContext() {
229 mFunctorManager.onContextDestroyed();
Stan Iliev90276c82019-02-03 18:01:02 -0500230 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) {
231 if (mEglManager->hasEglContext()) {
232 setGrContext(nullptr);
233 mEglManager->destroy();
234 }
235 } else {
236 if (vulkanManager().hasVkContext()) {
237 setGrContext(nullptr);
238 vulkanManager().destroy();
239 }
John Reck1e510712018-04-23 08:15:03 -0700240 }
241}
242
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400243void RenderThread::dumpGraphicsMemory(int fd) {
John Reck34781b22017-07-05 16:39:36 -0700244 globalProfileData()->dump(fd);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400245
246 String8 cachesOutput;
247 String8 pipeline;
248 auto renderType = Properties::getRenderPipelineType();
249 switch (renderType) {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400250 case RenderPipelineType::SkiaGL: {
251 mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState);
252 pipeline.appendFormat("Skia (OpenGL)");
253 break;
254 }
255 case RenderPipelineType::SkiaVulkan: {
256 mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState);
257 pipeline.appendFormat("Skia (Vulkan)");
258 break;
259 }
260 default:
John Reck1bcacfd2017-11-03 10:12:19 -0700261 LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400262 break;
263 }
264
John Reck47f5c3a2017-11-13 11:32:39 -0800265 dprintf(fd, "\n%s\n", cachesOutput.string());
266 dprintf(fd, "\nPipeline=%s\n", pipeline.string());
John Reck3b202512014-06-23 13:13:08 -0700267}
268
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500269Readback& RenderThread::readback() {
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500270 if (!mReadback) {
Stan Iliev1a025a72018-09-05 16:35:11 -0400271 mReadback = new Readback(*this);
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500272 }
273
274 return *mReadback;
275}
276
Greg Daniel660d6ec2017-12-08 11:44:27 -0500277void RenderThread::setGrContext(sk_sp<GrContext> context) {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400278 mCacheManager->reset(context);
Greg Daniel660d6ec2017-12-08 11:44:27 -0500279 if (mGrContext) {
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400280 mRenderState->onContextDestroyed();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400281 mGrContext->releaseResourcesAndAbandonContext();
282 }
Greg Daniel660d6ec2017-12-08 11:44:27 -0500283 mGrContext = std::move(context);
Derek Sollenberger17662382018-09-13 14:14:00 -0400284 if (mGrContext) {
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400285 mRenderState->onContextCreated();
Derek Sollenberger17662382018-09-13 14:14:00 -0400286 DeviceInfo::setMaxTextureSize(mGrContext->maxRenderTargetSize());
287 }
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400288}
289
John Recke45b1fd2014-04-15 09:50:16 -0700290int RenderThread::displayEventReceiverCallback(int fd, int events, void* data) {
291 if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
292 ALOGE("Display event receiver pipe was closed or an error occurred. "
John Reck1bcacfd2017-11-03 10:12:19 -0700293 "events=0x%x",
294 events);
295 return 0; // remove the callback
John Recke45b1fd2014-04-15 09:50:16 -0700296 }
297
298 if (!(events & Looper::EVENT_INPUT)) {
299 ALOGW("Received spurious callback for unhandled poll event. "
John Reck1bcacfd2017-11-03 10:12:19 -0700300 "events=0x%x",
301 events);
302 return 1; // keep the callback
John Recke45b1fd2014-04-15 09:50:16 -0700303 }
304
305 reinterpret_cast<RenderThread*>(data)->drainDisplayEventQueue();
306
John Reck1bcacfd2017-11-03 10:12:19 -0700307 return 1; // keep the callback
John Recke45b1fd2014-04-15 09:50:16 -0700308}
309
John Recka733f892014-12-19 11:37:21 -0800310void RenderThread::drainDisplayEventQueue() {
John Recka5dda642014-05-22 15:43:54 -0700311 ATRACE_CALL();
John Reck56428472018-03-16 17:27:17 -0700312 nsecs_t vsyncEvent = mVsyncSource->latestVsyncEvent();
John Recke45b1fd2014-04-15 09:50:16 -0700313 if (vsyncEvent > 0) {
314 mVsyncRequested = false;
John Recka733f892014-12-19 11:37:21 -0800315 if (mTimeLord.vsyncReceived(vsyncEvent) && !mFrameCallbackTaskPending) {
John Recka5dda642014-05-22 15:43:54 -0700316 ATRACE_NAME("queue mFrameCallbackTask");
John Recke45b1fd2014-04-15 09:50:16 -0700317 mFrameCallbackTaskPending = true;
John Reck3c0f5632019-03-15 16:36:01 -0700318 nsecs_t runAt = (vsyncEvent + mDispatchFrameDelay);
John Reck1bcacfd2017-11-03 10:12:19 -0700319 queue().postAt(runAt, [this]() { dispatchFrameCallbacks(); });
John Recke45b1fd2014-04-15 09:50:16 -0700320 }
321 }
322}
323
324void RenderThread::dispatchFrameCallbacks() {
John Recka5dda642014-05-22 15:43:54 -0700325 ATRACE_CALL();
John Recke45b1fd2014-04-15 09:50:16 -0700326 mFrameCallbackTaskPending = false;
327
328 std::set<IFrameCallback*> callbacks;
329 mFrameCallbacks.swap(callbacks);
330
John Recka733f892014-12-19 11:37:21 -0800331 if (callbacks.size()) {
332 // Assume one of them will probably animate again so preemptively
333 // request the next vsync in case it occurs mid-frame
334 requestVsync();
John Reck1bcacfd2017-11-03 10:12:19 -0700335 for (std::set<IFrameCallback*>::iterator it = callbacks.begin(); it != callbacks.end();
336 it++) {
John Recka733f892014-12-19 11:37:21 -0800337 (*it)->doFrame();
338 }
John Recke45b1fd2014-04-15 09:50:16 -0700339 }
340}
341
John Recka5dda642014-05-22 15:43:54 -0700342void RenderThread::requestVsync() {
343 if (!mVsyncRequested) {
344 mVsyncRequested = true;
John Reck56428472018-03-16 17:27:17 -0700345 mVsyncSource->requestNextVsync();
John Recka5dda642014-05-22 15:43:54 -0700346 }
347}
348
John Reckcec24ae2013-11-05 13:27:50 -0800349bool RenderThread::threadLoop() {
John Reck21be43e2014-08-14 10:25:16 -0700350 setpriority(PRIO_PROCESS, 0, PRIORITY_DISPLAY);
John Reck700079e2019-02-19 10:38:50 -0800351 Looper::setForThread(mLooper);
John Reck259b25a2017-12-01 16:18:53 -0800352 if (gOnStartHook) {
Stan Iliev978d5322019-02-06 12:02:28 -0500353 gOnStartHook("RenderThread");
John Reck259b25a2017-12-01 16:18:53 -0800354 }
John Reck3b202512014-06-23 13:13:08 -0700355 initThreadLocals();
John Recke45b1fd2014-04-15 09:50:16 -0700356
John Reckf8441e62017-10-23 13:10:41 -0700357 while (true) {
358 waitForWork();
359 processQueue();
John Recka5dda642014-05-22 15:43:54 -0700360
361 if (mPendingRegistrationFrameCallbacks.size() && !mFrameCallbackTaskPending) {
John Recka733f892014-12-19 11:37:21 -0800362 drainDisplayEventQueue();
John Reck1bcacfd2017-11-03 10:12:19 -0700363 mFrameCallbacks.insert(mPendingRegistrationFrameCallbacks.begin(),
364 mPendingRegistrationFrameCallbacks.end());
John Recka5dda642014-05-22 15:43:54 -0700365 mPendingRegistrationFrameCallbacks.clear();
366 requestVsync();
367 }
John Recka22c9b22015-01-14 10:40:15 -0800368
369 if (!mFrameCallbackTaskPending && !mVsyncRequested && mFrameCallbacks.size()) {
370 // TODO: Clean this up. This is working around an issue where a combination
371 // of bad timing and slow drawing can result in dropping a stale vsync
372 // on the floor (correct!) but fails to schedule to listen for the
373 // next vsync (oops), so none of the callbacks are run.
374 requestVsync();
375 }
John Reckcec24ae2013-11-05 13:27:50 -0800376 }
377
378 return false;
379}
380
John Recke45b1fd2014-04-15 09:50:16 -0700381void RenderThread::postFrameCallback(IFrameCallback* callback) {
John Recka5dda642014-05-22 15:43:54 -0700382 mPendingRegistrationFrameCallbacks.insert(callback);
John Recke45b1fd2014-04-15 09:50:16 -0700383}
384
John Reck01a5ea32014-12-03 13:01:07 -0800385bool RenderThread::removeFrameCallback(IFrameCallback* callback) {
386 size_t erased;
387 erased = mFrameCallbacks.erase(callback);
388 erased |= mPendingRegistrationFrameCallbacks.erase(callback);
389 return erased;
John Recka5dda642014-05-22 15:43:54 -0700390}
391
392void RenderThread::pushBackFrameCallback(IFrameCallback* callback) {
393 if (mFrameCallbacks.erase(callback)) {
394 mPendingRegistrationFrameCallbacks.insert(callback);
395 }
John Recke45b1fd2014-04-15 09:50:16 -0700396}
397
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400398sk_sp<Bitmap> RenderThread::allocateHardwareBitmap(SkBitmap& skBitmap) {
399 auto renderType = Properties::getRenderPipelineType();
400 switch (renderType) {
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400401 case RenderPipelineType::SkiaVulkan:
402 return skiapipeline::SkiaVulkanPipeline::allocateHardwareBitmap(*this, skBitmap);
403 default:
John Reck1bcacfd2017-11-03 10:12:19 -0700404 LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType);
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400405 break;
406 }
407 return nullptr;
408}
409
Stan Iliev6b894d72017-08-23 12:41:41 -0400410bool RenderThread::isCurrent() {
411 return gettid() == getInstance().getTid();
412}
413
Stan Iliev898123b2019-02-14 14:57:44 -0500414void RenderThread::preload() {
Stan Iliev30b90962019-03-29 14:25:09 -0400415 // EGL driver is always preloaded only if HWUI renders with GL.
416 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700417 std::thread eglInitThread([]() { eglGetDisplay(EGL_DEFAULT_DISPLAY); });
Stan Iliev30b90962019-03-29 14:25:09 -0400418 eglInitThread.detach();
419 } else {
Stan Iliev898123b2019-02-14 14:57:44 -0500420 requireVkContext();
421 }
Greg Danielc0732522019-02-20 08:31:03 -0500422 HardwareBitmapUploader::initialize();
Stan Iliev898123b2019-02-14 14:57:44 -0500423}
424
John Reckcec24ae2013-11-05 13:27:50 -0800425} /* namespace renderthread */
426} /* namespace uirenderer */
427} /* namespace android */