blob: ee1a7ce19e826e24426ed882f75c35fae1c54d59 [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
Jerome Gaillarde218c692019-06-14 12:58:57 +0100106 virtual nsecs_t latestVsyncEvent() override { return systemTime(SYSTEM_TIME_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) {
Ady Abraham9c501aa2019-06-04 16:07:44 -0700155 auto receiver = std::make_unique<DisplayEventReceiver>(
156 ISurfaceComposer::eVsyncSourceApp,
157 ISurfaceComposer::eConfigChangedDispatch);
John Reck56428472018-03-16 17:27:17 -0700158 status_t status = receiver->initCheck();
159 LOG_ALWAYS_FATAL_IF(status != NO_ERROR,
John Reckb90d4cb2018-04-19 17:05:35 -0700160 "Initialization of DisplayEventReceiver "
161 "failed with status: %d",
162 status);
John Reck56428472018-03-16 17:27:17 -0700163
164 // Register the FD
165 mLooper->addFd(receiver->getFd(), 0, Looper::EVENT_INPUT,
John Reckb90d4cb2018-04-19 17:05:35 -0700166 RenderThread::displayEventReceiverCallback, this);
John Reckcf185f52019-04-11 16:11:24 -0700167 mVsyncSource = new DisplayEventReceiverWrapper(std::move(receiver), [this] {
168 DeviceInfo::get()->onDisplayConfigChanged();
169 setupFrameInterval();
170 });
John Reck56428472018-03-16 17:27:17 -0700171 } else {
172 mVsyncSource = new DummyVsyncSource(this);
173 }
John Recke45b1fd2014-04-15 09:50:16 -0700174}
175
John Reck3b202512014-06-23 13:13:08 -0700176void RenderThread::initThreadLocals() {
John Reckcf185f52019-04-11 16:11:24 -0700177 setupFrameInterval();
John Reck3b202512014-06-23 13:13:08 -0700178 initializeDisplayEventReceiver();
John Reck1e510712018-04-23 08:15:03 -0700179 mEglManager = new EglManager();
John Reck0e89e2b2014-10-31 14:49:06 -0700180 mRenderState = new RenderState(*this);
Stan Iliev981afe72019-02-13 14:24:33 -0500181 mVkManager = new VulkanManager();
John Reckcf185f52019-04-11 16:11:24 -0700182 mCacheManager = new CacheManager(DeviceInfo::get()->displayInfo());
183}
184
185void RenderThread::setupFrameInterval() {
186 auto& displayInfo = DeviceInfo::get()->displayInfo();
187 nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1000000000 / displayInfo.fps);
188 mTimeLord.setFrameInterval(frameIntervalNanos);
189 mDispatchFrameDelay = static_cast<nsecs_t>(frameIntervalNanos * .25f);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400190}
191
John Reck1e510712018-04-23 08:15:03 -0700192void RenderThread::requireGlContext() {
193 if (mEglManager->hasEglContext()) {
194 return;
195 }
196 mEglManager->initialize();
John Reck1e510712018-04-23 08:15:03 -0700197
John Reckb5fc2092018-04-30 14:43:22 -0700198 sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
John Reckb5fc2092018-04-30 14:43:22 -0700199 LOG_ALWAYS_FATAL_IF(!glInterface.get());
John Reck1e510712018-04-23 08:15:03 -0700200
John Reckb5fc2092018-04-30 14:43:22 -0700201 GrContextOptions options;
Stan Iliev981afe72019-02-13 14:24:33 -0500202 initGrContextOptions(options);
Yichi Chen9f959552018-03-29 21:21:54 +0800203 auto glesVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
204 auto size = glesVersion ? strlen(glesVersion) : -1;
205 cacheManager().configureContext(&options, glesVersion, size);
John Reckb5fc2092018-04-30 14:43:22 -0700206 sk_sp<GrContext> grContext(GrContext::MakeGL(std::move(glInterface), options));
207 LOG_ALWAYS_FATAL_IF(!grContext.get());
208 setGrContext(grContext);
John Reck1e510712018-04-23 08:15:03 -0700209}
210
Stan Iliev981afe72019-02-13 14:24:33 -0500211void RenderThread::requireVkContext() {
212 if (mVkManager->hasVkContext()) {
213 return;
214 }
215 mVkManager->initialize();
216 GrContextOptions options;
217 initGrContextOptions(options);
Stan Ilievbf99c442019-03-29 11:09:11 -0400218 auto vkDriverVersion = mVkManager->getDriverVersion();
219 cacheManager().configureContext(&options, &vkDriverVersion, sizeof(vkDriverVersion));
Stan Iliev981afe72019-02-13 14:24:33 -0500220 sk_sp<GrContext> grContext = mVkManager->createContext(options);
221 LOG_ALWAYS_FATAL_IF(!grContext.get());
222 setGrContext(grContext);
223}
224
225void RenderThread::initGrContextOptions(GrContextOptions& options) {
226 options.fPreferExternalImagesOverES3 = true;
227 options.fDisableDistanceFieldPaths = true;
228}
229
John Reck283bb462018-12-13 16:40:14 -0800230void RenderThread::destroyRenderingContext() {
231 mFunctorManager.onContextDestroyed();
Stan Iliev90276c82019-02-03 18:01:02 -0500232 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) {
233 if (mEglManager->hasEglContext()) {
234 setGrContext(nullptr);
235 mEglManager->destroy();
236 }
237 } else {
238 if (vulkanManager().hasVkContext()) {
239 setGrContext(nullptr);
240 vulkanManager().destroy();
241 }
John Reck1e510712018-04-23 08:15:03 -0700242 }
243}
244
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400245void RenderThread::dumpGraphicsMemory(int fd) {
John Reck34781b22017-07-05 16:39:36 -0700246 globalProfileData()->dump(fd);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400247
248 String8 cachesOutput;
249 String8 pipeline;
250 auto renderType = Properties::getRenderPipelineType();
251 switch (renderType) {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400252 case RenderPipelineType::SkiaGL: {
253 mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState);
254 pipeline.appendFormat("Skia (OpenGL)");
255 break;
256 }
257 case RenderPipelineType::SkiaVulkan: {
258 mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState);
259 pipeline.appendFormat("Skia (Vulkan)");
260 break;
261 }
262 default:
John Reck1bcacfd2017-11-03 10:12:19 -0700263 LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400264 break;
265 }
266
John Reck47f5c3a2017-11-13 11:32:39 -0800267 dprintf(fd, "\n%s\n", cachesOutput.string());
268 dprintf(fd, "\nPipeline=%s\n", pipeline.string());
John Reck3b202512014-06-23 13:13:08 -0700269}
270
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500271Readback& RenderThread::readback() {
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500272 if (!mReadback) {
Stan Iliev1a025a72018-09-05 16:35:11 -0400273 mReadback = new Readback(*this);
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500274 }
275
276 return *mReadback;
277}
278
Greg Daniel660d6ec2017-12-08 11:44:27 -0500279void RenderThread::setGrContext(sk_sp<GrContext> context) {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400280 mCacheManager->reset(context);
Greg Daniel660d6ec2017-12-08 11:44:27 -0500281 if (mGrContext) {
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400282 mRenderState->onContextDestroyed();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400283 mGrContext->releaseResourcesAndAbandonContext();
284 }
Greg Daniel660d6ec2017-12-08 11:44:27 -0500285 mGrContext = std::move(context);
Derek Sollenberger17662382018-09-13 14:14:00 -0400286 if (mGrContext) {
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400287 mRenderState->onContextCreated();
Derek Sollenberger17662382018-09-13 14:14:00 -0400288 DeviceInfo::setMaxTextureSize(mGrContext->maxRenderTargetSize());
289 }
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400290}
291
John Recke45b1fd2014-04-15 09:50:16 -0700292int RenderThread::displayEventReceiverCallback(int fd, int events, void* data) {
293 if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
294 ALOGE("Display event receiver pipe was closed or an error occurred. "
John Reck1bcacfd2017-11-03 10:12:19 -0700295 "events=0x%x",
296 events);
297 return 0; // remove the callback
John Recke45b1fd2014-04-15 09:50:16 -0700298 }
299
300 if (!(events & Looper::EVENT_INPUT)) {
301 ALOGW("Received spurious callback for unhandled poll event. "
John Reck1bcacfd2017-11-03 10:12:19 -0700302 "events=0x%x",
303 events);
304 return 1; // keep the callback
John Recke45b1fd2014-04-15 09:50:16 -0700305 }
306
307 reinterpret_cast<RenderThread*>(data)->drainDisplayEventQueue();
308
John Reck1bcacfd2017-11-03 10:12:19 -0700309 return 1; // keep the callback
John Recke45b1fd2014-04-15 09:50:16 -0700310}
311
John Recka733f892014-12-19 11:37:21 -0800312void RenderThread::drainDisplayEventQueue() {
John Recka5dda642014-05-22 15:43:54 -0700313 ATRACE_CALL();
John Reck56428472018-03-16 17:27:17 -0700314 nsecs_t vsyncEvent = mVsyncSource->latestVsyncEvent();
John Recke45b1fd2014-04-15 09:50:16 -0700315 if (vsyncEvent > 0) {
316 mVsyncRequested = false;
John Recka733f892014-12-19 11:37:21 -0800317 if (mTimeLord.vsyncReceived(vsyncEvent) && !mFrameCallbackTaskPending) {
John Recka5dda642014-05-22 15:43:54 -0700318 ATRACE_NAME("queue mFrameCallbackTask");
John Recke45b1fd2014-04-15 09:50:16 -0700319 mFrameCallbackTaskPending = true;
John Reck3c0f5632019-03-15 16:36:01 -0700320 nsecs_t runAt = (vsyncEvent + mDispatchFrameDelay);
John Reck1bcacfd2017-11-03 10:12:19 -0700321 queue().postAt(runAt, [this]() { dispatchFrameCallbacks(); });
John Recke45b1fd2014-04-15 09:50:16 -0700322 }
323 }
324}
325
326void RenderThread::dispatchFrameCallbacks() {
John Recka5dda642014-05-22 15:43:54 -0700327 ATRACE_CALL();
John Recke45b1fd2014-04-15 09:50:16 -0700328 mFrameCallbackTaskPending = false;
329
330 std::set<IFrameCallback*> callbacks;
331 mFrameCallbacks.swap(callbacks);
332
John Recka733f892014-12-19 11:37:21 -0800333 if (callbacks.size()) {
334 // Assume one of them will probably animate again so preemptively
335 // request the next vsync in case it occurs mid-frame
336 requestVsync();
John Reck1bcacfd2017-11-03 10:12:19 -0700337 for (std::set<IFrameCallback*>::iterator it = callbacks.begin(); it != callbacks.end();
338 it++) {
John Recka733f892014-12-19 11:37:21 -0800339 (*it)->doFrame();
340 }
John Recke45b1fd2014-04-15 09:50:16 -0700341 }
342}
343
John Recka5dda642014-05-22 15:43:54 -0700344void RenderThread::requestVsync() {
345 if (!mVsyncRequested) {
346 mVsyncRequested = true;
John Reck56428472018-03-16 17:27:17 -0700347 mVsyncSource->requestNextVsync();
John Recka5dda642014-05-22 15:43:54 -0700348 }
349}
350
John Reckcec24ae2013-11-05 13:27:50 -0800351bool RenderThread::threadLoop() {
John Reck21be43e2014-08-14 10:25:16 -0700352 setpriority(PRIO_PROCESS, 0, PRIORITY_DISPLAY);
John Reck700079e2019-02-19 10:38:50 -0800353 Looper::setForThread(mLooper);
John Reck259b25a2017-12-01 16:18:53 -0800354 if (gOnStartHook) {
Stan Iliev978d5322019-02-06 12:02:28 -0500355 gOnStartHook("RenderThread");
John Reck259b25a2017-12-01 16:18:53 -0800356 }
John Reck3b202512014-06-23 13:13:08 -0700357 initThreadLocals();
John Recke45b1fd2014-04-15 09:50:16 -0700358
John Reckf8441e62017-10-23 13:10:41 -0700359 while (true) {
360 waitForWork();
361 processQueue();
John Recka5dda642014-05-22 15:43:54 -0700362
363 if (mPendingRegistrationFrameCallbacks.size() && !mFrameCallbackTaskPending) {
John Recka733f892014-12-19 11:37:21 -0800364 drainDisplayEventQueue();
John Reck1bcacfd2017-11-03 10:12:19 -0700365 mFrameCallbacks.insert(mPendingRegistrationFrameCallbacks.begin(),
366 mPendingRegistrationFrameCallbacks.end());
John Recka5dda642014-05-22 15:43:54 -0700367 mPendingRegistrationFrameCallbacks.clear();
368 requestVsync();
369 }
John Recka22c9b22015-01-14 10:40:15 -0800370
371 if (!mFrameCallbackTaskPending && !mVsyncRequested && mFrameCallbacks.size()) {
372 // TODO: Clean this up. This is working around an issue where a combination
373 // of bad timing and slow drawing can result in dropping a stale vsync
374 // on the floor (correct!) but fails to schedule to listen for the
375 // next vsync (oops), so none of the callbacks are run.
376 requestVsync();
377 }
John Reckcec24ae2013-11-05 13:27:50 -0800378 }
379
380 return false;
381}
382
John Recke45b1fd2014-04-15 09:50:16 -0700383void RenderThread::postFrameCallback(IFrameCallback* callback) {
John Recka5dda642014-05-22 15:43:54 -0700384 mPendingRegistrationFrameCallbacks.insert(callback);
John Recke45b1fd2014-04-15 09:50:16 -0700385}
386
John Reck01a5ea32014-12-03 13:01:07 -0800387bool RenderThread::removeFrameCallback(IFrameCallback* callback) {
388 size_t erased;
389 erased = mFrameCallbacks.erase(callback);
390 erased |= mPendingRegistrationFrameCallbacks.erase(callback);
391 return erased;
John Recka5dda642014-05-22 15:43:54 -0700392}
393
394void RenderThread::pushBackFrameCallback(IFrameCallback* callback) {
395 if (mFrameCallbacks.erase(callback)) {
396 mPendingRegistrationFrameCallbacks.insert(callback);
397 }
John Recke45b1fd2014-04-15 09:50:16 -0700398}
399
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400400sk_sp<Bitmap> RenderThread::allocateHardwareBitmap(SkBitmap& skBitmap) {
401 auto renderType = Properties::getRenderPipelineType();
402 switch (renderType) {
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400403 case RenderPipelineType::SkiaVulkan:
404 return skiapipeline::SkiaVulkanPipeline::allocateHardwareBitmap(*this, skBitmap);
405 default:
John Reck1bcacfd2017-11-03 10:12:19 -0700406 LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType);
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400407 break;
408 }
409 return nullptr;
410}
411
Stan Iliev6b894d72017-08-23 12:41:41 -0400412bool RenderThread::isCurrent() {
413 return gettid() == getInstance().getTid();
414}
415
Stan Iliev898123b2019-02-14 14:57:44 -0500416void RenderThread::preload() {
Stan Iliev30b90962019-03-29 14:25:09 -0400417 // EGL driver is always preloaded only if HWUI renders with GL.
418 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700419 std::thread eglInitThread([]() { eglGetDisplay(EGL_DEFAULT_DISPLAY); });
Stan Iliev30b90962019-03-29 14:25:09 -0400420 eglInitThread.detach();
421 } else {
Stan Iliev898123b2019-02-14 14:57:44 -0500422 requireVkContext();
423 }
Greg Danielc0732522019-02-20 08:31:03 -0500424 HardwareBitmapUploader::initialize();
Stan Iliev898123b2019-02-14 14:57:44 -0500425}
426
John Reckcec24ae2013-11-05 13:27:50 -0800427} /* namespace renderthread */
428} /* namespace uirenderer */
429} /* namespace android */