blob: 1e7fc71a7f047953f24c7f3f4720316354282b89 [file] [log] [blame]
John Reck4f02bf42014-01-03 18:09:17 -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 Reck4f02bf42014-01-03 18:09:17 -080017#include "RenderProxy.h"
18
Derek Sollenberger8b994192019-07-16 13:23:29 -040019#include <gui/Surface.h>
20
John Reckba6adf62015-02-19 14:36:50 -080021#include "DeferredLayerUpdater.h"
22#include "DisplayList.h"
John Recka8963062017-06-14 10:47:50 -070023#include "Properties.h"
John Reck10dd0582016-03-31 16:36:16 -070024#include "Readback.h"
John Reckba6adf62015-02-19 14:36:50 -080025#include "Rect.h"
John Reck5cca8f22018-12-10 17:06:22 -080026#include "WebViewFunctorManager.h"
John Reckba6adf62015-02-19 14:36:50 -080027#include "renderthread/CanvasContext.h"
28#include "renderthread/RenderTask.h"
29#include "renderthread/RenderThread.h"
30#include "utils/Macros.h"
John Reck43871902016-08-01 14:39:24 -070031#include "utils/TimeUtils.h"
John Reck322b8ab2019-03-14 13:15:28 -070032#include "utils/TraceUtils.h"
John Reck4f02bf42014-01-03 18:09:17 -080033
34namespace android {
35namespace uirenderer {
36namespace renderthread {
37
John Reck1bcacfd2017-11-03 10:12:19 -070038RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode,
39 IContextFactory* contextFactory)
40 : mRenderThread(RenderThread::getInstance()), mContext(nullptr) {
John Reckf8441e62017-10-23 13:10:41 -070041 mContext = mRenderThread.queue().runSync([&]() -> CanvasContext* {
42 return CanvasContext::create(mRenderThread, translucent, rootRenderNode, contextFactory);
43 });
Skuhneea7a7fb2015-08-28 07:10:31 -070044 mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode);
John Reck4f02bf42014-01-03 18:09:17 -080045}
46
47RenderProxy::~RenderProxy() {
48 destroyContext();
49}
50
John Reck4f02bf42014-01-03 18:09:17 -080051void RenderProxy::destroyContext() {
52 if (mContext) {
Skuhneea7a7fb2015-08-28 07:10:31 -070053 mDrawFrameTask.setContext(nullptr, nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070054 // This is also a fence as we need to be certain that there are no
55 // outstanding mDrawFrame tasks posted before it is destroyed
John Reck1bcacfd2017-11-03 10:12:19 -070056 mRenderThread.queue().runSync([this]() { delete mContext; });
John Reckf8441e62017-10-23 13:10:41 -070057 mContext = nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080058 }
59}
60
John Reck1125d1f2014-10-23 11:02:19 -070061void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
John Reck1bcacfd2017-11-03 10:12:19 -070062 mRenderThread.queue().post([this, swapBehavior]() { mContext->setSwapBehavior(swapBehavior); });
John Recke4280ba2014-05-05 16:39:37 -070063}
64
65bool RenderProxy::loadSystemProperties() {
John Reckf8441e62017-10-23 13:10:41 -070066 return mRenderThread.queue().runSync([this]() -> bool {
John Reckd9d7f122018-05-03 14:40:56 -070067 bool needsRedraw = Properties::load();
John Reckf8441e62017-10-23 13:10:41 -070068 if (mContext->profiler().consumeProperties()) {
69 needsRedraw = true;
70 }
71 return needsRedraw;
72 });
John Reckb36016c2015-03-11 08:50:53 -070073}
74
75void RenderProxy::setName(const char* name) {
John Reckf8441e62017-10-23 13:10:41 -070076 // block since name/value pointers owned by caller
77 // TODO: Support move arguments
John Reck1bcacfd2017-11-03 10:12:19 -070078 mRenderThread.queue().runSync([this, name]() { mContext->setName(std::string(name)); });
John Reck4f02bf42014-01-03 18:09:17 -080079}
80
John Reckcd18c222019-11-21 14:40:53 -080081void RenderProxy::setSurface(const sp<Surface>& surface, bool enableTimeout) {
82 mRenderThread.queue().post([this, surf = surface, enableTimeout]() mutable {
83 mContext->setSurface(std::move(surf), enableTimeout);
84 });
John Reck4f02bf42014-01-03 18:09:17 -080085}
86
John Reck8785ceb2018-10-29 16:45:58 -070087void RenderProxy::allocateBuffers() {
88 mRenderThread.queue().post([=]() { mContext->allocateBuffers(); });
Jorim Jaggi7823ee72018-07-17 15:24:16 +020089}
90
John Reck8785ceb2018-10-29 16:45:58 -070091bool RenderProxy::pause() {
John Reck1bcacfd2017-11-03 10:12:19 -070092 return mRenderThread.queue().runSync([this]() -> bool { return mContext->pauseSurface(); });
John Reck8afcc762016-04-13 10:24:06 -070093}
94
95void RenderProxy::setStopped(bool stopped) {
John Reck1bcacfd2017-11-03 10:12:19 -070096 mRenderThread.queue().runSync([this, stopped]() { mContext->setStopped(stopped); });
John Reck8afcc762016-04-13 10:24:06 -070097}
98
John Reck8785ceb2018-10-29 16:45:58 -070099void RenderProxy::setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
John Reck1bcacfd2017-11-03 10:12:19 -0700100 mRenderThread.queue().post(
John Reck8785ceb2018-10-29 16:45:58 -0700101 [=]() { mContext->setLightAlpha(ambientShadowAlpha, spotShadowAlpha); });
Alan Viverette50210d92015-05-14 18:05:36 -0700102}
103
John Reck8785ceb2018-10-29 16:45:58 -0700104void RenderProxy::setLightGeometry(const Vector3& lightCenter, float lightRadius) {
105 mRenderThread.queue().post([=]() { mContext->setLightGeometry(lightCenter, lightRadius); });
John Reck63a06672014-05-07 13:45:54 -0700106}
107
108void RenderProxy::setOpaque(bool opaque) {
John Reck1bcacfd2017-11-03 10:12:19 -0700109 mRenderThread.queue().post([=]() { mContext->setOpaque(opaque); });
Romain Guy26a2b972017-04-17 09:39:51 -0700110}
111
112void RenderProxy::setWideGamut(bool wideGamut) {
John Reck1bcacfd2017-11-03 10:12:19 -0700113 mRenderThread.queue().post([=]() { mContext->setWideGamut(wideGamut); });
Romain Guy26a2b972017-04-17 09:39:51 -0700114}
115
John Reckba6adf62015-02-19 14:36:50 -0800116int64_t* RenderProxy::frameInfo() {
117 return mDrawFrameTask.frameInfo();
118}
119
John Reck2de950d2017-01-25 10:58:30 -0800120int RenderProxy::syncAndDrawFrame() {
121 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800122}
123
John Reck2de950d2017-01-25 10:58:30 -0800124void RenderProxy::destroy() {
John Reckfae904d2014-04-14 11:01:57 -0700125 // destroyCanvasAndSurface() needs a fence as when it returns the
126 // underlying BufferQueue is going to be released from under
127 // the render thread.
John Reck1bcacfd2017-11-03 10:12:19 -0700128 mRenderThread.queue().runSync([=]() { mContext->destroy(); });
John Reck0d1f6342014-03-28 20:30:27 -0700129}
130
131void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700132 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700133 RenderThread& thread = RenderThread::getInstance();
John Reckf8441e62017-10-23 13:10:41 -0700134 auto invoke = [&thread, functor]() { CanvasContext::invokeFunctor(thread, functor); };
John Reck0d1f6342014-03-28 20:30:27 -0700135 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700136 // waitForCompletion = true is expected to be fairly rare and only
137 // happen in destruction. Thus it should be fine to temporarily
138 // create a Mutex
John Reckf8441e62017-10-23 13:10:41 -0700139 thread.queue().runSync(std::move(invoke));
John Reck0d1f6342014-03-28 20:30:27 -0700140 } else {
John Reckf8441e62017-10-23 13:10:41 -0700141 thread.queue().post(std::move(invoke));
John Reck0d1f6342014-03-28 20:30:27 -0700142 }
143}
144
John Reck283bb462018-12-13 16:40:14 -0800145void RenderProxy::destroyFunctor(int functor) {
146 ATRACE_CALL();
147 RenderThread& thread = RenderThread::getInstance();
John Reck5cca8f22018-12-10 17:06:22 -0800148 thread.queue().post([=]() { WebViewFunctorManager::instance().destroyFunctor(functor); });
John Reck283bb462018-12-13 16:40:14 -0800149}
150
John Reck19b6bcf2014-02-14 20:03:38 -0800151DeferredLayerUpdater* RenderProxy::createTextureLayer() {
John Reckf8441e62017-10-23 13:10:41 -0700152 return mRenderThread.queue().runSync([this]() -> auto {
153 return mContext->createTextureLayer();
154 });
John Reck3e824952014-08-20 10:08:39 -0700155}
156
John Reck2de950d2017-01-25 10:58:30 -0800157void RenderProxy::buildLayer(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700158 mRenderThread.queue().runSync([&]() { mContext->buildLayer(node); });
John Reck19b6bcf2014-02-14 20:03:38 -0800159}
160
John Reck3731dc22015-04-13 15:20:29 -0700161bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
John Reckfbeac3c2019-03-29 11:24:56 -0700162 ATRACE_NAME("TextureView#getBitmap");
Stan Iliev1a025a72018-09-05 16:35:11 -0400163 auto& thread = RenderThread::getInstance();
John Reck5cca8f22018-12-10 17:06:22 -0800164 return thread.queue().runSync([&]() -> bool {
165 return thread.readback().copyLayerInto(layer, &bitmap) == CopyResult::Success;
166 });
John Reck19b6bcf2014-02-14 20:03:38 -0800167}
168
John Reckd72e0a32014-05-29 18:56:11 -0700169void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
170 mDrawFrameTask.pushLayerUpdate(layer);
171}
172
173void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
174 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800175}
176
John Reck918ad522014-06-27 14:45:25 -0700177void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
John Reck1bcacfd2017-11-03 10:12:19 -0700178 return mRenderThread.queue().runSync([&]() { layer->detachSurfaceTexture(); });
John Recke1628b72014-05-23 15:11:19 -0700179}
180
John Reck2de950d2017-01-25 10:58:30 -0800181void RenderProxy::destroyHardwareResources() {
John Reck1bcacfd2017-11-03 10:12:19 -0700182 return mRenderThread.queue().runSync([&]() { mContext->destroyHardwareResources(); });
John Reckf47a5942014-06-30 16:20:04 -0700183}
184
185void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700186 // Avoid creating a RenderThread to do a trimMemory.
187 if (RenderThread::hasInstance()) {
188 RenderThread& thread = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700189 thread.queue().post([&thread, level]() { CanvasContext::trimMemory(thread, level); });
John Reckcd3a22c2014-08-06 13:33:59 -0700190 }
John Reckf47a5942014-06-30 16:20:04 -0700191}
192
Chris Craik2507c342015-05-04 14:36:49 -0700193void RenderProxy::overrideProperty(const char* name, const char* value) {
John Reckf8441e62017-10-23 13:10:41 -0700194 // expensive, but block here since name/value pointers owned by caller
John Reck1bcacfd2017-11-03 10:12:19 -0700195 RenderThread::getInstance().queue().runSync(
196 [&]() { Properties::overrideProperty(name, value); });
Chris Craik2507c342015-05-04 14:36:49 -0700197}
198
John Reck28ad7b52014-04-07 16:59:25 -0700199void RenderProxy::fence() {
John Reck1bcacfd2017-11-03 10:12:19 -0700200 mRenderThread.queue().runSync([]() {});
John Reck28ad7b52014-04-07 16:59:25 -0700201}
202
John Recke4c1e6c2018-05-24 16:27:35 -0700203int RenderProxy::maxTextureSize() {
John Reck5cca8f22018-12-10 17:06:22 -0800204 static int maxTextureSize = RenderThread::getInstance().queue().runSync(
205 []() { return DeviceInfo::get()->maxTextureSize(); });
John Recke4c1e6c2018-05-24 16:27:35 -0700206 return maxTextureSize;
John Reckf47a5942014-06-30 16:20:04 -0700207}
208
209void RenderProxy::stopDrawing() {
John Reck1bcacfd2017-11-03 10:12:19 -0700210 mRenderThread.queue().runSync([this]() { mContext->stopDrawing(); });
John Recka5dda642014-05-22 15:43:54 -0700211}
212
213void RenderProxy::notifyFramePending() {
John Reck1bcacfd2017-11-03 10:12:19 -0700214 mRenderThread.queue().post([this]() { mContext->notifyFramePending(); });
John Reckfe5e7b72014-05-23 17:42:28 -0700215}
216
John Reckba6adf62015-02-19 14:36:50 -0800217void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckf8441e62017-10-23 13:10:41 -0700218 mRenderThread.queue().runSync([&]() {
219 mContext->profiler().dumpData(fd);
220 if (dumpFlags & DumpFlags::FrameStats) {
221 mContext->dumpFrames(fd);
222 }
223 if (dumpFlags & DumpFlags::JankStats) {
224 mRenderThread.globalProfileData()->dump(fd);
225 }
226 if (dumpFlags & DumpFlags::Reset) {
227 mContext->resetFrameStats();
228 }
229 });
John Reck7f2e5e32015-05-05 11:00:53 -0700230}
231
232void RenderProxy::resetProfileInfo() {
John Reck1bcacfd2017-11-03 10:12:19 -0700233 mRenderThread.queue().runSync([=]() { mContext->resetFrameStats(); });
John Reck7f2e5e32015-05-05 11:00:53 -0700234}
235
John Reckf8441e62017-10-23 13:10:41 -0700236uint32_t RenderProxy::frameTimePercentile(int percentile) {
237 return mRenderThread.queue().runSync([&]() -> auto {
238 return mRenderThread.globalProfileData()->findPercentile(percentile);
239 });
John Reck0e89e2b2014-10-31 14:49:06 -0700240}
241
Chris Craik2ae07332015-01-21 14:22:39 -0800242void RenderProxy::dumpGraphicsMemory(int fd) {
John Reckba7e9652019-01-23 10:33:41 -0800243 if (RenderThread::hasInstance()) {
244 auto& thread = RenderThread::getInstance();
245 thread.queue().runSync([&]() { thread.dumpGraphicsMemory(fd); });
246 }
John Reckedc524c2015-03-18 15:24:33 -0700247}
248
249void RenderProxy::setProcessStatsBuffer(int fd) {
John Reckdf1742e2017-01-19 15:56:21 -0800250 auto& rt = RenderThread::getInstance();
John Reck0fa0cbc2019-04-05 16:57:46 -0700251 rt.queue().post([&rt, fd = dup(fd)]() {
John Reckf8441e62017-10-23 13:10:41 -0700252 rt.globalProfileData().switchStorageToAshmem(fd);
253 close(fd);
254 });
John Reckdf1742e2017-01-19 15:56:21 -0800255}
256
257void RenderProxy::rotateProcessStatsBuffer() {
John Reckdf1742e2017-01-19 15:56:21 -0800258 auto& rt = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700259 rt.queue().post([&rt]() { rt.globalProfileData().rotateStorage(); });
John Reckedc524c2015-03-18 15:24:33 -0700260}
261
Tim Murray33eb07f2016-06-10 10:03:20 -0700262int RenderProxy::getRenderThreadTid() {
263 return mRenderThread.getTid();
264}
265
Skuhneea7a7fb2015-08-28 07:10:31 -0700266void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) {
John Reck1bcacfd2017-11-03 10:12:19 -0700267 mRenderThread.queue().post([=]() { mContext->addRenderNode(node, placeFront); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700268}
269
270void RenderProxy::removeRenderNode(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700271 mRenderThread.queue().post([=]() { mContext->removeRenderNode(node); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700272}
273
274void RenderProxy::drawRenderNode(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700275 mRenderThread.queue().runSync([=]() { mContext->prepareAndDraw(node); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700276}
277
Skuhneb8160872015-09-22 09:51:39 -0700278void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) {
John Reckf138b172017-09-08 11:00:42 -0700279 mDrawFrameTask.setContentDrawBounds(left, top, right, bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700280}
281
John Reck5cca8f22018-12-10 17:06:22 -0800282void RenderProxy::setPictureCapturedCallback(
283 const std::function<void(sk_sp<SkPicture>&&)>& callback) {
284 mRenderThread.queue().post(
John Reck0fa0cbc2019-04-05 16:57:46 -0700285 [this, cb = callback]() { mContext->setPictureCapturedCallback(cb); });
John Reck5cca8f22018-12-10 17:06:22 -0800286}
287
Mihai Popa95688002018-02-23 16:10:11 +0000288void RenderProxy::setFrameCallback(std::function<void(int64_t)>&& callback) {
289 mDrawFrameTask.setFrameCallback(std::move(callback));
290}
291
John Reckcc2eee82018-05-17 10:44:00 -0700292void RenderProxy::setFrameCompleteCallback(std::function<void(int64_t)>&& callback) {
293 mDrawFrameTask.setFrameCompleteCallback(std::move(callback));
294}
295
John Reckf8441e62017-10-23 13:10:41 -0700296void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observerPtr) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700297 mRenderThread.queue().post([this, observer = sp{observerPtr}]() {
John Reckf8441e62017-10-23 13:10:41 -0700298 mContext->addFrameMetricsObserver(observer.get());
299 });
Andres Morales06f5bc72015-12-15 15:21:31 -0800300}
301
John Reckf8441e62017-10-23 13:10:41 -0700302void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observerPtr) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700303 mRenderThread.queue().post([this, observer = sp{observerPtr}]() {
John Reckf8441e62017-10-23 13:10:41 -0700304 mContext->removeFrameMetricsObserver(observer.get());
305 });
John Reck10dd0582016-03-31 16:36:16 -0700306}
307
John Reckbb3a3582018-09-26 11:21:08 -0700308void RenderProxy::setForceDark(bool enable) {
John Reck5cca8f22018-12-10 17:06:22 -0800309 mRenderThread.queue().post([this, enable]() { mContext->setForceDark(enable); });
John Reckbb3a3582018-09-26 11:21:08 -0700310}
311
John Reck4d527222019-03-13 16:25:20 -0700312void RenderProxy::setRenderAheadDepth(int renderAhead) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700313 mRenderThread.queue().post(
314 [context = mContext, renderAhead] { context->setRenderAheadDepth(renderAhead); });
John Reck4d527222019-03-13 16:25:20 -0700315}
316
John Reck1bcacfd2017-11-03 10:12:19 -0700317int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, int right, int bottom,
318 SkBitmap* bitmap) {
John Reckf8441e62017-10-23 13:10:41 -0700319 auto& thread = RenderThread::getInstance();
Alec Mouri8a82b142019-12-17 09:41:48 -0800320 ANativeWindow* window = surface.get();
John Reckf8441e62017-10-23 13:10:41 -0700321 return static_cast<int>(thread.queue().runSync([&]() -> auto {
Alec Mouri8a82b142019-12-17 09:41:48 -0800322 return thread.readback().copySurfaceInto(window, Rect(left, top, right, bottom), bitmap);
John Reckf8441e62017-10-23 13:10:41 -0700323 }));
John Reck43871902016-08-01 14:39:24 -0700324}
325
sergeyvec4a4b12016-10-20 18:39:04 -0700326void RenderProxy::prepareToDraw(Bitmap& bitmap) {
John Reck43871902016-08-01 14:39:24 -0700327 // If we haven't spun up a hardware accelerated window yet, there's no
328 // point in precaching these bitmaps as it can't impact jank.
329 // We also don't know if we even will spin up a hardware-accelerated
330 // window or not.
331 if (!RenderThread::hasInstance()) return;
332 RenderThread* renderThread = &RenderThread::getInstance();
sergeyvec4a4b12016-10-20 18:39:04 -0700333 bitmap.ref();
John Reckf8441e62017-10-23 13:10:41 -0700334 auto task = [renderThread, &bitmap]() {
335 CanvasContext::prepareToDraw(*renderThread, &bitmap);
336 bitmap.unref();
337 };
John Reck43871902016-08-01 14:39:24 -0700338 nsecs_t lastVsync = renderThread->timeLord().latestVsync();
339 nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos();
Jerome Gaillarde218c692019-06-14 12:58:57 +0100340 nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(SYSTEM_TIME_MONOTONIC);
John Reck43871902016-08-01 14:39:24 -0700341 // We expect the UI thread to take 4ms and for RT to be active from VSYNC+4ms to
342 // VSYNC+12ms or so, so aim for the gap during which RT is expected to
343 // be idle
344 // TODO: Make this concept a first-class supported thing? RT could use
345 // knowledge of pending draws to better schedule this task
346 if (timeToNextVsync > -6_ms && timeToNextVsync < 1_ms) {
John Reckf8441e62017-10-23 13:10:41 -0700347 renderThread->queue().postAt(estimatedNextVsync + 8_ms, task);
John Reck43871902016-08-01 14:39:24 -0700348 } else {
John Reckf8441e62017-10-23 13:10:41 -0700349 renderThread->queue().post(task);
John Reck43871902016-08-01 14:39:24 -0700350 }
351}
352
Stan Iliev1a025a72018-09-05 16:35:11 -0400353int RenderProxy::copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap) {
John Reckfbeac3c2019-03-29 11:24:56 -0700354 ATRACE_NAME("HardwareBitmap readback");
Stan Iliev6983bc42017-02-02 14:11:53 -0500355 RenderThread& thread = RenderThread::getInstance();
John Reck1072fff2018-04-12 15:20:09 -0700356 if (gettid() == thread.getTid()) {
John Reck1bcacfd2017-11-03 10:12:19 -0700357 // TODO: fix everything that hits this. We should never be triggering a readback ourselves.
Stan Iliev1a025a72018-09-05 16:35:11 -0400358 return (int)thread.readback().copyHWBitmapInto(hwBitmap, bitmap);
Stan Iliev6983bc42017-02-02 14:11:53 -0500359 } else {
John Reck5cca8f22018-12-10 17:06:22 -0800360 return thread.queue().runSync(
361 [&]() -> int { return (int)thread.readback().copyHWBitmapInto(hwBitmap, bitmap); });
Stan Iliev6983bc42017-02-02 14:11:53 -0500362 }
sergeyv59eecb522016-11-17 17:54:57 -0800363}
364
John Recka8963062017-06-14 10:47:50 -0700365void RenderProxy::disableVsync() {
366 Properties::disableVsync = true;
367}
368
Stan Iliev898123b2019-02-14 14:57:44 -0500369void RenderProxy::preload() {
370 // Create RenderThread object and start the thread. Then preload Vulkan/EGL driver.
371 auto& thread = RenderThread::getInstance();
John Reck0fa0cbc2019-04-05 16:57:46 -0700372 thread.queue().post([&thread]() { thread.preload(); });
Stan Iliev898123b2019-02-14 14:57:44 -0500373}
374
John Reck4f02bf42014-01-03 18:09:17 -0800375} /* namespace renderthread */
376} /* namespace uirenderer */
377} /* namespace android */