blob: 1bcb819509afd532ea95c8de41dab9b7b5bd2fc8 [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
John Reckba6adf62015-02-19 14:36:50 -080019#include "DeferredLayerUpdater.h"
20#include "DisplayList.h"
John Recka8963062017-06-14 10:47:50 -070021#include "Properties.h"
John Reck10dd0582016-03-31 16:36:16 -070022#include "Readback.h"
John Reckba6adf62015-02-19 14:36:50 -080023#include "Rect.h"
John Reck5cca8f22018-12-10 17:06:22 -080024#include "WebViewFunctorManager.h"
John Reckb90d4cb2018-04-19 17:05:35 -070025#include "pipeline/skia/SkiaOpenGLPipeline.h"
Stan Iliev3310fb12017-03-23 16:56:51 -040026#include "pipeline/skia/VectorDrawableAtlas.h"
John Reck1bcacfd2017-11-03 10:12:19 -070027#include "renderstate/RenderState.h"
John Reckba6adf62015-02-19 14:36:50 -080028#include "renderthread/CanvasContext.h"
John Reck43871902016-08-01 14:39:24 -070029#include "renderthread/EglManager.h"
John Reckba6adf62015-02-19 14:36:50 -080030#include "renderthread/RenderTask.h"
31#include "renderthread/RenderThread.h"
32#include "utils/Macros.h"
John Reck43871902016-08-01 14:39:24 -070033#include "utils/TimeUtils.h"
John Reck322b8ab2019-03-14 13:15:28 -070034#include "utils/TraceUtils.h"
John Reck4f02bf42014-01-03 18:09:17 -080035
sergeyv59eecb522016-11-17 17:54:57 -080036#include <ui/GraphicBuffer.h>
37
John Reck4f02bf42014-01-03 18:09:17 -080038namespace android {
39namespace uirenderer {
40namespace renderthread {
41
John Reck1bcacfd2017-11-03 10:12:19 -070042RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode,
43 IContextFactory* contextFactory)
44 : mRenderThread(RenderThread::getInstance()), mContext(nullptr) {
John Reckf8441e62017-10-23 13:10:41 -070045 mContext = mRenderThread.queue().runSync([&]() -> CanvasContext* {
46 return CanvasContext::create(mRenderThread, translucent, rootRenderNode, contextFactory);
47 });
Skuhneea7a7fb2015-08-28 07:10:31 -070048 mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode);
John Reck4f02bf42014-01-03 18:09:17 -080049}
50
51RenderProxy::~RenderProxy() {
52 destroyContext();
53}
54
John Reck4f02bf42014-01-03 18:09:17 -080055void RenderProxy::destroyContext() {
56 if (mContext) {
Skuhneea7a7fb2015-08-28 07:10:31 -070057 mDrawFrameTask.setContext(nullptr, nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070058 // This is also a fence as we need to be certain that there are no
59 // outstanding mDrawFrame tasks posted before it is destroyed
John Reck1bcacfd2017-11-03 10:12:19 -070060 mRenderThread.queue().runSync([this]() { delete mContext; });
John Reckf8441e62017-10-23 13:10:41 -070061 mContext = nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080062 }
63}
64
John Reck1125d1f2014-10-23 11:02:19 -070065void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
John Reck1bcacfd2017-11-03 10:12:19 -070066 mRenderThread.queue().post([this, swapBehavior]() { mContext->setSwapBehavior(swapBehavior); });
John Recke4280ba2014-05-05 16:39:37 -070067}
68
69bool RenderProxy::loadSystemProperties() {
John Reckf8441e62017-10-23 13:10:41 -070070 return mRenderThread.queue().runSync([this]() -> bool {
John Reckd9d7f122018-05-03 14:40:56 -070071 bool needsRedraw = Properties::load();
John Reckf8441e62017-10-23 13:10:41 -070072 if (mContext->profiler().consumeProperties()) {
73 needsRedraw = true;
74 }
75 return needsRedraw;
76 });
John Reckb36016c2015-03-11 08:50:53 -070077}
78
79void RenderProxy::setName(const char* name) {
John Reckf8441e62017-10-23 13:10:41 -070080 // block since name/value pointers owned by caller
81 // TODO: Support move arguments
John Reck1bcacfd2017-11-03 10:12:19 -070082 mRenderThread.queue().runSync([this, name]() { mContext->setName(std::string(name)); });
John Reck4f02bf42014-01-03 18:09:17 -080083}
84
John Reck8785ceb2018-10-29 16:45:58 -070085void RenderProxy::setSurface(const sp<Surface>& surface) {
John Reck1bcacfd2017-11-03 10:12:19 -070086 mRenderThread.queue().post(
87 [ this, surf = surface ]() mutable { mContext->setSurface(std::move(surf)); });
John Reck4f02bf42014-01-03 18:09:17 -080088}
89
John Reck8785ceb2018-10-29 16:45:58 -070090void RenderProxy::allocateBuffers() {
91 mRenderThread.queue().post([=]() { mContext->allocateBuffers(); });
Jorim Jaggi7823ee72018-07-17 15:24:16 +020092}
93
John Reck8785ceb2018-10-29 16:45:58 -070094bool RenderProxy::pause() {
John Reck1bcacfd2017-11-03 10:12:19 -070095 return mRenderThread.queue().runSync([this]() -> bool { return mContext->pauseSurface(); });
John Reck8afcc762016-04-13 10:24:06 -070096}
97
98void RenderProxy::setStopped(bool stopped) {
John Reck1bcacfd2017-11-03 10:12:19 -070099 mRenderThread.queue().runSync([this, stopped]() { mContext->setStopped(stopped); });
John Reck8afcc762016-04-13 10:24:06 -0700100}
101
John Reck8785ceb2018-10-29 16:45:58 -0700102void RenderProxy::setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
John Reck1bcacfd2017-11-03 10:12:19 -0700103 mRenderThread.queue().post(
John Reck8785ceb2018-10-29 16:45:58 -0700104 [=]() { mContext->setLightAlpha(ambientShadowAlpha, spotShadowAlpha); });
Alan Viverette50210d92015-05-14 18:05:36 -0700105}
106
John Reck8785ceb2018-10-29 16:45:58 -0700107void RenderProxy::setLightGeometry(const Vector3& lightCenter, float lightRadius) {
108 mRenderThread.queue().post([=]() { mContext->setLightGeometry(lightCenter, lightRadius); });
John Reck63a06672014-05-07 13:45:54 -0700109}
110
111void RenderProxy::setOpaque(bool opaque) {
John Reck1bcacfd2017-11-03 10:12:19 -0700112 mRenderThread.queue().post([=]() { mContext->setOpaque(opaque); });
Romain Guy26a2b972017-04-17 09:39:51 -0700113}
114
115void RenderProxy::setWideGamut(bool wideGamut) {
John Reck1bcacfd2017-11-03 10:12:19 -0700116 mRenderThread.queue().post([=]() { mContext->setWideGamut(wideGamut); });
Romain Guy26a2b972017-04-17 09:39:51 -0700117}
118
John Reckba6adf62015-02-19 14:36:50 -0800119int64_t* RenderProxy::frameInfo() {
120 return mDrawFrameTask.frameInfo();
121}
122
John Reck2de950d2017-01-25 10:58:30 -0800123int RenderProxy::syncAndDrawFrame() {
124 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800125}
126
John Reck2de950d2017-01-25 10:58:30 -0800127void RenderProxy::destroy() {
John Reckfae904d2014-04-14 11:01:57 -0700128 // destroyCanvasAndSurface() needs a fence as when it returns the
129 // underlying BufferQueue is going to be released from under
130 // the render thread.
John Reck1bcacfd2017-11-03 10:12:19 -0700131 mRenderThread.queue().runSync([=]() { mContext->destroy(); });
John Reck0d1f6342014-03-28 20:30:27 -0700132}
133
134void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700135 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700136 RenderThread& thread = RenderThread::getInstance();
John Reckf8441e62017-10-23 13:10:41 -0700137 auto invoke = [&thread, functor]() { CanvasContext::invokeFunctor(thread, functor); };
John Reck0d1f6342014-03-28 20:30:27 -0700138 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700139 // waitForCompletion = true is expected to be fairly rare and only
140 // happen in destruction. Thus it should be fine to temporarily
141 // create a Mutex
John Reckf8441e62017-10-23 13:10:41 -0700142 thread.queue().runSync(std::move(invoke));
John Reck0d1f6342014-03-28 20:30:27 -0700143 } else {
John Reckf8441e62017-10-23 13:10:41 -0700144 thread.queue().post(std::move(invoke));
John Reck0d1f6342014-03-28 20:30:27 -0700145 }
146}
147
John Reck283bb462018-12-13 16:40:14 -0800148void RenderProxy::destroyFunctor(int functor) {
149 ATRACE_CALL();
150 RenderThread& thread = RenderThread::getInstance();
John Reck5cca8f22018-12-10 17:06:22 -0800151 thread.queue().post([=]() { WebViewFunctorManager::instance().destroyFunctor(functor); });
John Reck283bb462018-12-13 16:40:14 -0800152}
153
John Reck19b6bcf2014-02-14 20:03:38 -0800154DeferredLayerUpdater* RenderProxy::createTextureLayer() {
John Reckf8441e62017-10-23 13:10:41 -0700155 return mRenderThread.queue().runSync([this]() -> auto {
156 return mContext->createTextureLayer();
157 });
John Reck3e824952014-08-20 10:08:39 -0700158}
159
John Reck2de950d2017-01-25 10:58:30 -0800160void RenderProxy::buildLayer(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700161 mRenderThread.queue().runSync([&]() { mContext->buildLayer(node); });
John Reck19b6bcf2014-02-14 20:03:38 -0800162}
163
John Reck3731dc22015-04-13 15:20:29 -0700164bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
Stan Iliev1a025a72018-09-05 16:35:11 -0400165 auto& thread = RenderThread::getInstance();
John Reck5cca8f22018-12-10 17:06:22 -0800166 return thread.queue().runSync([&]() -> bool {
167 return thread.readback().copyLayerInto(layer, &bitmap) == CopyResult::Success;
168 });
John Reck19b6bcf2014-02-14 20:03:38 -0800169}
170
John Reckd72e0a32014-05-29 18:56:11 -0700171void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
172 mDrawFrameTask.pushLayerUpdate(layer);
173}
174
175void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
176 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800177}
178
John Reck918ad522014-06-27 14:45:25 -0700179void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
John Reck1bcacfd2017-11-03 10:12:19 -0700180 return mRenderThread.queue().runSync([&]() { layer->detachSurfaceTexture(); });
John Recke1628b72014-05-23 15:11:19 -0700181}
182
John Reck2de950d2017-01-25 10:58:30 -0800183void RenderProxy::destroyHardwareResources() {
John Reck1bcacfd2017-11-03 10:12:19 -0700184 return mRenderThread.queue().runSync([&]() { mContext->destroyHardwareResources(); });
John Reckf47a5942014-06-30 16:20:04 -0700185}
186
187void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700188 // Avoid creating a RenderThread to do a trimMemory.
189 if (RenderThread::hasInstance()) {
190 RenderThread& thread = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700191 thread.queue().post([&thread, level]() { CanvasContext::trimMemory(thread, level); });
John Reckcd3a22c2014-08-06 13:33:59 -0700192 }
John Reckf47a5942014-06-30 16:20:04 -0700193}
194
Chris Craik2507c342015-05-04 14:36:49 -0700195void RenderProxy::overrideProperty(const char* name, const char* value) {
John Reckf8441e62017-10-23 13:10:41 -0700196 // expensive, but block here since name/value pointers owned by caller
John Reck1bcacfd2017-11-03 10:12:19 -0700197 RenderThread::getInstance().queue().runSync(
198 [&]() { Properties::overrideProperty(name, value); });
Chris Craik2507c342015-05-04 14:36:49 -0700199}
200
John Reck28ad7b52014-04-07 16:59:25 -0700201void RenderProxy::fence() {
John Reck1bcacfd2017-11-03 10:12:19 -0700202 mRenderThread.queue().runSync([]() {});
John Reck28ad7b52014-04-07 16:59:25 -0700203}
204
John Recke4c1e6c2018-05-24 16:27:35 -0700205int RenderProxy::maxTextureSize() {
John Reck5cca8f22018-12-10 17:06:22 -0800206 static int maxTextureSize = RenderThread::getInstance().queue().runSync(
207 []() { return DeviceInfo::get()->maxTextureSize(); });
John Recke4c1e6c2018-05-24 16:27:35 -0700208 return maxTextureSize;
John Reckf47a5942014-06-30 16:20:04 -0700209}
210
211void RenderProxy::stopDrawing() {
John Reck1bcacfd2017-11-03 10:12:19 -0700212 mRenderThread.queue().runSync([this]() { mContext->stopDrawing(); });
John Recka5dda642014-05-22 15:43:54 -0700213}
214
215void RenderProxy::notifyFramePending() {
John Reck1bcacfd2017-11-03 10:12:19 -0700216 mRenderThread.queue().post([this]() { mContext->notifyFramePending(); });
John Reckfe5e7b72014-05-23 17:42:28 -0700217}
218
John Reckba6adf62015-02-19 14:36:50 -0800219void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckf8441e62017-10-23 13:10:41 -0700220 mRenderThread.queue().runSync([&]() {
221 mContext->profiler().dumpData(fd);
222 if (dumpFlags & DumpFlags::FrameStats) {
223 mContext->dumpFrames(fd);
224 }
225 if (dumpFlags & DumpFlags::JankStats) {
226 mRenderThread.globalProfileData()->dump(fd);
227 }
228 if (dumpFlags & DumpFlags::Reset) {
229 mContext->resetFrameStats();
230 }
231 });
John Reck7f2e5e32015-05-05 11:00:53 -0700232}
233
234void RenderProxy::resetProfileInfo() {
John Reck1bcacfd2017-11-03 10:12:19 -0700235 mRenderThread.queue().runSync([=]() { mContext->resetFrameStats(); });
John Reck7f2e5e32015-05-05 11:00:53 -0700236}
237
John Reckf8441e62017-10-23 13:10:41 -0700238uint32_t RenderProxy::frameTimePercentile(int percentile) {
239 return mRenderThread.queue().runSync([&]() -> auto {
240 return mRenderThread.globalProfileData()->findPercentile(percentile);
241 });
John Reck0e89e2b2014-10-31 14:49:06 -0700242}
243
Chris Craik2ae07332015-01-21 14:22:39 -0800244void RenderProxy::dumpGraphicsMemory(int fd) {
John Reckba7e9652019-01-23 10:33:41 -0800245 if (RenderThread::hasInstance()) {
246 auto& thread = RenderThread::getInstance();
247 thread.queue().runSync([&]() { thread.dumpGraphicsMemory(fd); });
248 }
John Reckedc524c2015-03-18 15:24:33 -0700249}
250
251void RenderProxy::setProcessStatsBuffer(int fd) {
John Reckdf1742e2017-01-19 15:56:21 -0800252 auto& rt = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700253 rt.queue().post([&rt, fd = dup(fd) ]() {
John Reckf8441e62017-10-23 13:10:41 -0700254 rt.globalProfileData().switchStorageToAshmem(fd);
255 close(fd);
256 });
John Reckdf1742e2017-01-19 15:56:21 -0800257}
258
259void RenderProxy::rotateProcessStatsBuffer() {
John Reckdf1742e2017-01-19 15:56:21 -0800260 auto& rt = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700261 rt.queue().post([&rt]() { rt.globalProfileData().rotateStorage(); });
John Reckedc524c2015-03-18 15:24:33 -0700262}
263
Tim Murray33eb07f2016-06-10 10:03:20 -0700264int RenderProxy::getRenderThreadTid() {
265 return mRenderThread.getTid();
266}
267
Skuhneea7a7fb2015-08-28 07:10:31 -0700268void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) {
John Reck1bcacfd2017-11-03 10:12:19 -0700269 mRenderThread.queue().post([=]() { mContext->addRenderNode(node, placeFront); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700270}
271
272void RenderProxy::removeRenderNode(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700273 mRenderThread.queue().post([=]() { mContext->removeRenderNode(node); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700274}
275
276void RenderProxy::drawRenderNode(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700277 mRenderThread.queue().runSync([=]() { mContext->prepareAndDraw(node); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700278}
279
Skuhneb8160872015-09-22 09:51:39 -0700280void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) {
John Reckf138b172017-09-08 11:00:42 -0700281 mDrawFrameTask.setContentDrawBounds(left, top, right, bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700282}
283
John Reck5cca8f22018-12-10 17:06:22 -0800284void RenderProxy::setPictureCapturedCallback(
285 const std::function<void(sk_sp<SkPicture>&&)>& callback) {
286 mRenderThread.queue().post(
287 [ this, cb = callback ]() { mContext->setPictureCapturedCallback(cb); });
288}
289
Mihai Popa95688002018-02-23 16:10:11 +0000290void RenderProxy::setFrameCallback(std::function<void(int64_t)>&& callback) {
291 mDrawFrameTask.setFrameCallback(std::move(callback));
292}
293
John Reckcc2eee82018-05-17 10:44:00 -0700294void RenderProxy::setFrameCompleteCallback(std::function<void(int64_t)>&& callback) {
295 mDrawFrameTask.setFrameCompleteCallback(std::move(callback));
296}
297
John Reckf8441e62017-10-23 13:10:41 -0700298void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observerPtr) {
John Reck1bcacfd2017-11-03 10:12:19 -0700299 mRenderThread.queue().post([ this, observer = sp{observerPtr} ]() {
John Reckf8441e62017-10-23 13:10:41 -0700300 mContext->addFrameMetricsObserver(observer.get());
301 });
Andres Morales06f5bc72015-12-15 15:21:31 -0800302}
303
John Reckf8441e62017-10-23 13:10:41 -0700304void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observerPtr) {
John Reck1bcacfd2017-11-03 10:12:19 -0700305 mRenderThread.queue().post([ this, observer = sp{observerPtr} ]() {
John Reckf8441e62017-10-23 13:10:41 -0700306 mContext->removeFrameMetricsObserver(observer.get());
307 });
John Reck10dd0582016-03-31 16:36:16 -0700308}
309
John Reckbb3a3582018-09-26 11:21:08 -0700310void RenderProxy::setForceDark(bool enable) {
John Reck5cca8f22018-12-10 17:06:22 -0800311 mRenderThread.queue().post([this, enable]() { mContext->setForceDark(enable); });
John Reckbb3a3582018-09-26 11:21:08 -0700312}
313
John Reck1bcacfd2017-11-03 10:12:19 -0700314int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, int right, int bottom,
315 SkBitmap* bitmap) {
John Reckf8441e62017-10-23 13:10:41 -0700316 auto& thread = RenderThread::getInstance();
317 return static_cast<int>(thread.queue().runSync([&]() -> auto {
318 return thread.readback().copySurfaceInto(*surface, Rect(left, top, right, bottom), bitmap);
319 }));
John Reck43871902016-08-01 14:39:24 -0700320}
321
sergeyvec4a4b12016-10-20 18:39:04 -0700322void RenderProxy::prepareToDraw(Bitmap& bitmap) {
John Reck43871902016-08-01 14:39:24 -0700323 // If we haven't spun up a hardware accelerated window yet, there's no
324 // point in precaching these bitmaps as it can't impact jank.
325 // We also don't know if we even will spin up a hardware-accelerated
326 // window or not.
327 if (!RenderThread::hasInstance()) return;
328 RenderThread* renderThread = &RenderThread::getInstance();
sergeyvec4a4b12016-10-20 18:39:04 -0700329 bitmap.ref();
John Reckf8441e62017-10-23 13:10:41 -0700330 auto task = [renderThread, &bitmap]() {
331 CanvasContext::prepareToDraw(*renderThread, &bitmap);
332 bitmap.unref();
333 };
John Reck43871902016-08-01 14:39:24 -0700334 nsecs_t lastVsync = renderThread->timeLord().latestVsync();
335 nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos();
336 nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(CLOCK_MONOTONIC);
337 // We expect the UI thread to take 4ms and for RT to be active from VSYNC+4ms to
338 // VSYNC+12ms or so, so aim for the gap during which RT is expected to
339 // be idle
340 // TODO: Make this concept a first-class supported thing? RT could use
341 // knowledge of pending draws to better schedule this task
342 if (timeToNextVsync > -6_ms && timeToNextVsync < 1_ms) {
John Reckf8441e62017-10-23 13:10:41 -0700343 renderThread->queue().postAt(estimatedNextVsync + 8_ms, task);
John Reck43871902016-08-01 14:39:24 -0700344 } else {
John Reckf8441e62017-10-23 13:10:41 -0700345 renderThread->queue().post(task);
John Reck43871902016-08-01 14:39:24 -0700346 }
347}
348
Stan Iliev1a025a72018-09-05 16:35:11 -0400349int RenderProxy::copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap) {
Stan Iliev6983bc42017-02-02 14:11:53 -0500350 RenderThread& thread = RenderThread::getInstance();
John Reck1072fff2018-04-12 15:20:09 -0700351 if (gettid() == thread.getTid()) {
John Reck1bcacfd2017-11-03 10:12:19 -0700352 // TODO: fix everything that hits this. We should never be triggering a readback ourselves.
Stan Iliev1a025a72018-09-05 16:35:11 -0400353 return (int)thread.readback().copyHWBitmapInto(hwBitmap, bitmap);
Stan Iliev6983bc42017-02-02 14:11:53 -0500354 } else {
John Reck5cca8f22018-12-10 17:06:22 -0800355 return thread.queue().runSync(
356 [&]() -> int { return (int)thread.readback().copyHWBitmapInto(hwBitmap, bitmap); });
Stan Iliev6983bc42017-02-02 14:11:53 -0500357 }
sergeyv59eecb522016-11-17 17:54:57 -0800358}
359
John Recka8963062017-06-14 10:47:50 -0700360void RenderProxy::disableVsync() {
361 Properties::disableVsync = true;
362}
363
Stan Iliev3310fb12017-03-23 16:56:51 -0400364void RenderProxy::repackVectorDrawableAtlas() {
365 RenderThread& thread = RenderThread::getInstance();
John Reckf8441e62017-10-23 13:10:41 -0700366 thread.queue().post([&thread]() {
Stan Iliev6c4b6e82018-03-01 15:51:17 -0500367 // The context may be null if trimMemory executed, but then the atlas was deleted too.
368 if (thread.getGrContext() != nullptr) {
369 thread.cacheManager().acquireVectorDrawableAtlas()->repackIfNeeded(
370 thread.getGrContext());
371 }
John Reckf8441e62017-10-23 13:10:41 -0700372 });
Stan Iliev6b894d72017-08-23 12:41:41 -0400373}
374
375void RenderProxy::releaseVDAtlasEntries() {
376 RenderThread& thread = RenderThread::getInstance();
John Reckf8441e62017-10-23 13:10:41 -0700377 thread.queue().post([&thread]() {
Stan Iliev6c4b6e82018-03-01 15:51:17 -0500378 // The context may be null if trimMemory executed, but then the atlas was deleted too.
379 if (thread.getGrContext() != nullptr) {
380 thread.cacheManager().acquireVectorDrawableAtlas()->delayedReleaseEntries();
381 }
John Reckf8441e62017-10-23 13:10:41 -0700382 });
John Reck0e89e2b2014-10-31 14:49:06 -0700383}
384
Stan Iliev898123b2019-02-14 14:57:44 -0500385void RenderProxy::preload() {
386 // Create RenderThread object and start the thread. Then preload Vulkan/EGL driver.
387 auto& thread = RenderThread::getInstance();
388 thread.queue().post([&thread]() {
389 thread.preload();
390 });
391}
392
John Reck4f02bf42014-01-03 18:09:17 -0800393} /* namespace renderthread */
394} /* namespace uirenderer */
395} /* namespace android */