blob: a446858ca5657459deb567f2b8c7a42e96e6038e [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();
Alec Mouri22d753f2019-09-05 17:11:45 -0700182 mCacheManager = new CacheManager();
John Reckcf185f52019-04-11 16:11:24 -0700183}
184
185void RenderThread::setupFrameInterval() {
Alec Mouri22d753f2019-09-05 17:11:45 -0700186 nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1000000000 / DeviceInfo::getRefreshRate());
John Reckcf185f52019-04-11 16:11:24 -0700187 mTimeLord.setFrameInterval(frameIntervalNanos);
188 mDispatchFrameDelay = static_cast<nsecs_t>(frameIntervalNanos * .25f);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400189}
190
John Reck1e510712018-04-23 08:15:03 -0700191void RenderThread::requireGlContext() {
192 if (mEglManager->hasEglContext()) {
193 return;
194 }
195 mEglManager->initialize();
John Reck1e510712018-04-23 08:15:03 -0700196
John Reckb5fc2092018-04-30 14:43:22 -0700197 sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
John Reckb5fc2092018-04-30 14:43:22 -0700198 LOG_ALWAYS_FATAL_IF(!glInterface.get());
John Reck1e510712018-04-23 08:15:03 -0700199
John Reckb5fc2092018-04-30 14:43:22 -0700200 GrContextOptions options;
Stan Iliev981afe72019-02-13 14:24:33 -0500201 initGrContextOptions(options);
Yichi Chen9f959552018-03-29 21:21:54 +0800202 auto glesVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
203 auto size = glesVersion ? strlen(glesVersion) : -1;
204 cacheManager().configureContext(&options, glesVersion, size);
John Reckb5fc2092018-04-30 14:43:22 -0700205 sk_sp<GrContext> grContext(GrContext::MakeGL(std::move(glInterface), options));
206 LOG_ALWAYS_FATAL_IF(!grContext.get());
207 setGrContext(grContext);
John Reck1e510712018-04-23 08:15:03 -0700208}
209
Stan Iliev981afe72019-02-13 14:24:33 -0500210void RenderThread::requireVkContext() {
211 if (mVkManager->hasVkContext()) {
212 return;
213 }
214 mVkManager->initialize();
215 GrContextOptions options;
216 initGrContextOptions(options);
Stan Ilievbf99c442019-03-29 11:09:11 -0400217 auto vkDriverVersion = mVkManager->getDriverVersion();
218 cacheManager().configureContext(&options, &vkDriverVersion, sizeof(vkDriverVersion));
Stan Iliev981afe72019-02-13 14:24:33 -0500219 sk_sp<GrContext> grContext = mVkManager->createContext(options);
220 LOG_ALWAYS_FATAL_IF(!grContext.get());
221 setGrContext(grContext);
222}
223
224void RenderThread::initGrContextOptions(GrContextOptions& options) {
225 options.fPreferExternalImagesOverES3 = true;
226 options.fDisableDistanceFieldPaths = true;
227}
228
John Reck283bb462018-12-13 16:40:14 -0800229void RenderThread::destroyRenderingContext() {
230 mFunctorManager.onContextDestroyed();
Stan Iliev90276c82019-02-03 18:01:02 -0500231 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) {
232 if (mEglManager->hasEglContext()) {
233 setGrContext(nullptr);
234 mEglManager->destroy();
235 }
236 } else {
237 if (vulkanManager().hasVkContext()) {
238 setGrContext(nullptr);
239 vulkanManager().destroy();
240 }
John Reck1e510712018-04-23 08:15:03 -0700241 }
242}
243
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400244void RenderThread::dumpGraphicsMemory(int fd) {
John Reck34781b22017-07-05 16:39:36 -0700245 globalProfileData()->dump(fd);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400246
247 String8 cachesOutput;
248 String8 pipeline;
249 auto renderType = Properties::getRenderPipelineType();
250 switch (renderType) {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400251 case RenderPipelineType::SkiaGL: {
252 mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState);
253 pipeline.appendFormat("Skia (OpenGL)");
254 break;
255 }
256 case RenderPipelineType::SkiaVulkan: {
257 mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState);
258 pipeline.appendFormat("Skia (Vulkan)");
259 break;
260 }
261 default:
John Reck1bcacfd2017-11-03 10:12:19 -0700262 LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400263 break;
264 }
265
John Reck47f5c3a2017-11-13 11:32:39 -0800266 dprintf(fd, "\n%s\n", cachesOutput.string());
267 dprintf(fd, "\nPipeline=%s\n", pipeline.string());
John Reck3b202512014-06-23 13:13:08 -0700268}
269
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500270Readback& RenderThread::readback() {
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500271 if (!mReadback) {
Stan Iliev1a025a72018-09-05 16:35:11 -0400272 mReadback = new Readback(*this);
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -0500273 }
274
275 return *mReadback;
276}
277
Greg Daniel660d6ec2017-12-08 11:44:27 -0500278void RenderThread::setGrContext(sk_sp<GrContext> context) {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400279 mCacheManager->reset(context);
Greg Daniel660d6ec2017-12-08 11:44:27 -0500280 if (mGrContext) {
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400281 mRenderState->onContextDestroyed();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400282 mGrContext->releaseResourcesAndAbandonContext();
283 }
Greg Daniel660d6ec2017-12-08 11:44:27 -0500284 mGrContext = std::move(context);
Derek Sollenberger17662382018-09-13 14:14:00 -0400285 if (mGrContext) {
Derek Sollenberger5a5a6482018-09-19 13:52:13 -0400286 mRenderState->onContextCreated();
Derek Sollenberger17662382018-09-13 14:14:00 -0400287 DeviceInfo::setMaxTextureSize(mGrContext->maxRenderTargetSize());
288 }
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -0400289}
290
John Recke45b1fd2014-04-15 09:50:16 -0700291int RenderThread::displayEventReceiverCallback(int fd, int events, void* data) {
292 if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
293 ALOGE("Display event receiver pipe was closed or an error occurred. "
John Reck1bcacfd2017-11-03 10:12:19 -0700294 "events=0x%x",
295 events);
296 return 0; // remove the callback
John Recke45b1fd2014-04-15 09:50:16 -0700297 }
298
299 if (!(events & Looper::EVENT_INPUT)) {
300 ALOGW("Received spurious callback for unhandled poll event. "
John Reck1bcacfd2017-11-03 10:12:19 -0700301 "events=0x%x",
302 events);
303 return 1; // keep the callback
John Recke45b1fd2014-04-15 09:50:16 -0700304 }
305
306 reinterpret_cast<RenderThread*>(data)->drainDisplayEventQueue();
307
John Reck1bcacfd2017-11-03 10:12:19 -0700308 return 1; // keep the callback
John Recke45b1fd2014-04-15 09:50:16 -0700309}
310
John Recka733f892014-12-19 11:37:21 -0800311void RenderThread::drainDisplayEventQueue() {
John Recka5dda642014-05-22 15:43:54 -0700312 ATRACE_CALL();
John Reck56428472018-03-16 17:27:17 -0700313 nsecs_t vsyncEvent = mVsyncSource->latestVsyncEvent();
John Recke45b1fd2014-04-15 09:50:16 -0700314 if (vsyncEvent > 0) {
315 mVsyncRequested = false;
John Recka733f892014-12-19 11:37:21 -0800316 if (mTimeLord.vsyncReceived(vsyncEvent) && !mFrameCallbackTaskPending) {
John Recka5dda642014-05-22 15:43:54 -0700317 ATRACE_NAME("queue mFrameCallbackTask");
John Recke45b1fd2014-04-15 09:50:16 -0700318 mFrameCallbackTaskPending = true;
John Reck3c0f5632019-03-15 16:36:01 -0700319 nsecs_t runAt = (vsyncEvent + mDispatchFrameDelay);
John Reck1bcacfd2017-11-03 10:12:19 -0700320 queue().postAt(runAt, [this]() { dispatchFrameCallbacks(); });
John Recke45b1fd2014-04-15 09:50:16 -0700321 }
322 }
323}
324
325void RenderThread::dispatchFrameCallbacks() {
John Recka5dda642014-05-22 15:43:54 -0700326 ATRACE_CALL();
John Recke45b1fd2014-04-15 09:50:16 -0700327 mFrameCallbackTaskPending = false;
328
329 std::set<IFrameCallback*> callbacks;
330 mFrameCallbacks.swap(callbacks);
331
John Recka733f892014-12-19 11:37:21 -0800332 if (callbacks.size()) {
333 // Assume one of them will probably animate again so preemptively
334 // request the next vsync in case it occurs mid-frame
335 requestVsync();
John Reck1bcacfd2017-11-03 10:12:19 -0700336 for (std::set<IFrameCallback*>::iterator it = callbacks.begin(); it != callbacks.end();
337 it++) {
John Recka733f892014-12-19 11:37:21 -0800338 (*it)->doFrame();
339 }
John Recke45b1fd2014-04-15 09:50:16 -0700340 }
341}
342
John Recka5dda642014-05-22 15:43:54 -0700343void RenderThread::requestVsync() {
344 if (!mVsyncRequested) {
345 mVsyncRequested = true;
John Reck56428472018-03-16 17:27:17 -0700346 mVsyncSource->requestNextVsync();
John Recka5dda642014-05-22 15:43:54 -0700347 }
348}
349
John Reckcec24ae2013-11-05 13:27:50 -0800350bool RenderThread::threadLoop() {
John Reck21be43e2014-08-14 10:25:16 -0700351 setpriority(PRIO_PROCESS, 0, PRIORITY_DISPLAY);
John Reck700079e2019-02-19 10:38:50 -0800352 Looper::setForThread(mLooper);
John Reck259b25a2017-12-01 16:18:53 -0800353 if (gOnStartHook) {
Stan Iliev978d5322019-02-06 12:02:28 -0500354 gOnStartHook("RenderThread");
John Reck259b25a2017-12-01 16:18:53 -0800355 }
John Reck3b202512014-06-23 13:13:08 -0700356 initThreadLocals();
John Recke45b1fd2014-04-15 09:50:16 -0700357
John Reckf8441e62017-10-23 13:10:41 -0700358 while (true) {
359 waitForWork();
360 processQueue();
John Recka5dda642014-05-22 15:43:54 -0700361
362 if (mPendingRegistrationFrameCallbacks.size() && !mFrameCallbackTaskPending) {
John Recka733f892014-12-19 11:37:21 -0800363 drainDisplayEventQueue();
John Reck1bcacfd2017-11-03 10:12:19 -0700364 mFrameCallbacks.insert(mPendingRegistrationFrameCallbacks.begin(),
365 mPendingRegistrationFrameCallbacks.end());
John Recka5dda642014-05-22 15:43:54 -0700366 mPendingRegistrationFrameCallbacks.clear();
367 requestVsync();
368 }
John Recka22c9b22015-01-14 10:40:15 -0800369
370 if (!mFrameCallbackTaskPending && !mVsyncRequested && mFrameCallbacks.size()) {
371 // TODO: Clean this up. This is working around an issue where a combination
372 // of bad timing and slow drawing can result in dropping a stale vsync
373 // on the floor (correct!) but fails to schedule to listen for the
374 // next vsync (oops), so none of the callbacks are run.
375 requestVsync();
376 }
John Reckcec24ae2013-11-05 13:27:50 -0800377 }
378
379 return false;
380}
381
John Recke45b1fd2014-04-15 09:50:16 -0700382void RenderThread::postFrameCallback(IFrameCallback* callback) {
John Recka5dda642014-05-22 15:43:54 -0700383 mPendingRegistrationFrameCallbacks.insert(callback);
John Recke45b1fd2014-04-15 09:50:16 -0700384}
385
John Reck01a5ea32014-12-03 13:01:07 -0800386bool RenderThread::removeFrameCallback(IFrameCallback* callback) {
387 size_t erased;
388 erased = mFrameCallbacks.erase(callback);
389 erased |= mPendingRegistrationFrameCallbacks.erase(callback);
390 return erased;
John Recka5dda642014-05-22 15:43:54 -0700391}
392
393void RenderThread::pushBackFrameCallback(IFrameCallback* callback) {
394 if (mFrameCallbacks.erase(callback)) {
395 mPendingRegistrationFrameCallbacks.insert(callback);
396 }
John Recke45b1fd2014-04-15 09:50:16 -0700397}
398
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400399sk_sp<Bitmap> RenderThread::allocateHardwareBitmap(SkBitmap& skBitmap) {
400 auto renderType = Properties::getRenderPipelineType();
401 switch (renderType) {
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400402 case RenderPipelineType::SkiaVulkan:
403 return skiapipeline::SkiaVulkanPipeline::allocateHardwareBitmap(*this, skBitmap);
404 default:
John Reck1bcacfd2017-11-03 10:12:19 -0700405 LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType);
Stan Iliev7bc3bc62017-05-24 13:28:36 -0400406 break;
407 }
408 return nullptr;
409}
410
Stan Iliev6b894d72017-08-23 12:41:41 -0400411bool RenderThread::isCurrent() {
412 return gettid() == getInstance().getTid();
413}
414
Stan Iliev898123b2019-02-14 14:57:44 -0500415void RenderThread::preload() {
Stan Iliev30b90962019-03-29 14:25:09 -0400416 // EGL driver is always preloaded only if HWUI renders with GL.
417 if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaGL) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700418 std::thread eglInitThread([]() { eglGetDisplay(EGL_DEFAULT_DISPLAY); });
Stan Iliev30b90962019-03-29 14:25:09 -0400419 eglInitThread.detach();
420 } else {
Stan Iliev898123b2019-02-14 14:57:44 -0500421 requireVkContext();
422 }
Greg Danielc0732522019-02-20 08:31:03 -0500423 HardwareBitmapUploader::initialize();
Stan Iliev898123b2019-02-14 14:57:44 -0500424}
425
John Reckcec24ae2013-11-05 13:27:50 -0800426} /* namespace renderthread */
427} /* namespace uirenderer */
428} /* namespace android */