blob: 720c60362a55a92405b54de5ad664612f2019efd [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 Reck4f02bf42014-01-03 18:09:17 -080034
sergeyv59eecb522016-11-17 17:54:57 -080035#include <ui/GraphicBuffer.h>
36
John Reck4f02bf42014-01-03 18:09:17 -080037namespace android {
38namespace uirenderer {
39namespace renderthread {
40
John Reck1bcacfd2017-11-03 10:12:19 -070041RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode,
42 IContextFactory* contextFactory)
43 : mRenderThread(RenderThread::getInstance()), mContext(nullptr) {
John Reckf8441e62017-10-23 13:10:41 -070044 mContext = mRenderThread.queue().runSync([&]() -> CanvasContext* {
45 return CanvasContext::create(mRenderThread, translucent, rootRenderNode, contextFactory);
46 });
Skuhneea7a7fb2015-08-28 07:10:31 -070047 mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode);
John Reck4f02bf42014-01-03 18:09:17 -080048}
49
50RenderProxy::~RenderProxy() {
51 destroyContext();
52}
53
John Reck4f02bf42014-01-03 18:09:17 -080054void RenderProxy::destroyContext() {
55 if (mContext) {
Skuhneea7a7fb2015-08-28 07:10:31 -070056 mDrawFrameTask.setContext(nullptr, nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070057 // This is also a fence as we need to be certain that there are no
58 // outstanding mDrawFrame tasks posted before it is destroyed
John Reck1bcacfd2017-11-03 10:12:19 -070059 mRenderThread.queue().runSync([this]() { delete mContext; });
John Reckf8441e62017-10-23 13:10:41 -070060 mContext = nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080061 }
62}
63
John Reck1125d1f2014-10-23 11:02:19 -070064void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
John Reck1bcacfd2017-11-03 10:12:19 -070065 mRenderThread.queue().post([this, swapBehavior]() { mContext->setSwapBehavior(swapBehavior); });
John Recke4280ba2014-05-05 16:39:37 -070066}
67
68bool RenderProxy::loadSystemProperties() {
John Reckf8441e62017-10-23 13:10:41 -070069 return mRenderThread.queue().runSync([this]() -> bool {
John Reckd9d7f122018-05-03 14:40:56 -070070 bool needsRedraw = Properties::load();
John Reckf8441e62017-10-23 13:10:41 -070071 if (mContext->profiler().consumeProperties()) {
72 needsRedraw = true;
73 }
74 return needsRedraw;
75 });
John Reckb36016c2015-03-11 08:50:53 -070076}
77
78void RenderProxy::setName(const char* name) {
John Reckf8441e62017-10-23 13:10:41 -070079 // block since name/value pointers owned by caller
80 // TODO: Support move arguments
John Reck1bcacfd2017-11-03 10:12:19 -070081 mRenderThread.queue().runSync([this, name]() { mContext->setName(std::string(name)); });
John Reck4f02bf42014-01-03 18:09:17 -080082}
83
John Reck8785ceb2018-10-29 16:45:58 -070084void RenderProxy::setSurface(const sp<Surface>& surface) {
John Reck1bcacfd2017-11-03 10:12:19 -070085 mRenderThread.queue().post(
86 [ this, surf = surface ]() mutable { mContext->setSurface(std::move(surf)); });
John Reck4f02bf42014-01-03 18:09:17 -080087}
88
John Reck8785ceb2018-10-29 16:45:58 -070089void RenderProxy::allocateBuffers() {
90 mRenderThread.queue().post([=]() { mContext->allocateBuffers(); });
Jorim Jaggi7823ee72018-07-17 15:24:16 +020091}
92
John Reck8785ceb2018-10-29 16:45:58 -070093bool RenderProxy::pause() {
John Reck1bcacfd2017-11-03 10:12:19 -070094 return mRenderThread.queue().runSync([this]() -> bool { return mContext->pauseSurface(); });
John Reck8afcc762016-04-13 10:24:06 -070095}
96
97void RenderProxy::setStopped(bool stopped) {
John Reck1bcacfd2017-11-03 10:12:19 -070098 mRenderThread.queue().runSync([this, stopped]() { mContext->setStopped(stopped); });
John Reck8afcc762016-04-13 10:24:06 -070099}
100
John Reck8785ceb2018-10-29 16:45:58 -0700101void RenderProxy::setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
John Reck1bcacfd2017-11-03 10:12:19 -0700102 mRenderThread.queue().post(
John Reck8785ceb2018-10-29 16:45:58 -0700103 [=]() { mContext->setLightAlpha(ambientShadowAlpha, spotShadowAlpha); });
Alan Viverette50210d92015-05-14 18:05:36 -0700104}
105
John Reck8785ceb2018-10-29 16:45:58 -0700106void RenderProxy::setLightGeometry(const Vector3& lightCenter, float lightRadius) {
107 mRenderThread.queue().post([=]() { mContext->setLightGeometry(lightCenter, lightRadius); });
John Reck63a06672014-05-07 13:45:54 -0700108}
109
110void RenderProxy::setOpaque(bool opaque) {
John Reck1bcacfd2017-11-03 10:12:19 -0700111 mRenderThread.queue().post([=]() { mContext->setOpaque(opaque); });
Romain Guy26a2b972017-04-17 09:39:51 -0700112}
113
114void RenderProxy::setWideGamut(bool wideGamut) {
John Reck1bcacfd2017-11-03 10:12:19 -0700115 mRenderThread.queue().post([=]() { mContext->setWideGamut(wideGamut); });
Romain Guy26a2b972017-04-17 09:39:51 -0700116}
117
John Reckba6adf62015-02-19 14:36:50 -0800118int64_t* RenderProxy::frameInfo() {
119 return mDrawFrameTask.frameInfo();
120}
121
John Reck2de950d2017-01-25 10:58:30 -0800122int RenderProxy::syncAndDrawFrame() {
123 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800124}
125
John Reck2de950d2017-01-25 10:58:30 -0800126void RenderProxy::destroy() {
John Reckfae904d2014-04-14 11:01:57 -0700127 // destroyCanvasAndSurface() needs a fence as when it returns the
128 // underlying BufferQueue is going to be released from under
129 // the render thread.
John Reck1bcacfd2017-11-03 10:12:19 -0700130 mRenderThread.queue().runSync([=]() { mContext->destroy(); });
John Reck0d1f6342014-03-28 20:30:27 -0700131}
132
133void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700134 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700135 RenderThread& thread = RenderThread::getInstance();
John Reckf8441e62017-10-23 13:10:41 -0700136 auto invoke = [&thread, functor]() { CanvasContext::invokeFunctor(thread, functor); };
John Reck0d1f6342014-03-28 20:30:27 -0700137 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700138 // waitForCompletion = true is expected to be fairly rare and only
139 // happen in destruction. Thus it should be fine to temporarily
140 // create a Mutex
John Reckf8441e62017-10-23 13:10:41 -0700141 thread.queue().runSync(std::move(invoke));
John Reck0d1f6342014-03-28 20:30:27 -0700142 } else {
John Reckf8441e62017-10-23 13:10:41 -0700143 thread.queue().post(std::move(invoke));
John Reck0d1f6342014-03-28 20:30:27 -0700144 }
145}
146
John Reck283bb462018-12-13 16:40:14 -0800147void RenderProxy::destroyFunctor(int functor) {
148 ATRACE_CALL();
149 RenderThread& thread = RenderThread::getInstance();
John Reck5cca8f22018-12-10 17:06:22 -0800150 thread.queue().post([=]() { WebViewFunctorManager::instance().destroyFunctor(functor); });
John Reck283bb462018-12-13 16:40:14 -0800151}
152
John Reck19b6bcf2014-02-14 20:03:38 -0800153DeferredLayerUpdater* RenderProxy::createTextureLayer() {
John Reckf8441e62017-10-23 13:10:41 -0700154 return mRenderThread.queue().runSync([this]() -> auto {
155 return mContext->createTextureLayer();
156 });
John Reck3e824952014-08-20 10:08:39 -0700157}
158
John Reck2de950d2017-01-25 10:58:30 -0800159void RenderProxy::buildLayer(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700160 mRenderThread.queue().runSync([&]() { mContext->buildLayer(node); });
John Reck19b6bcf2014-02-14 20:03:38 -0800161}
162
John Reck3731dc22015-04-13 15:20:29 -0700163bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
Stan Iliev1a025a72018-09-05 16:35:11 -0400164 auto& thread = RenderThread::getInstance();
John Reck5cca8f22018-12-10 17:06:22 -0800165 return thread.queue().runSync([&]() -> bool {
166 return thread.readback().copyLayerInto(layer, &bitmap) == CopyResult::Success;
167 });
John Reck19b6bcf2014-02-14 20:03:38 -0800168}
169
John Reckd72e0a32014-05-29 18:56:11 -0700170void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
171 mDrawFrameTask.pushLayerUpdate(layer);
172}
173
174void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
175 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800176}
177
John Reck918ad522014-06-27 14:45:25 -0700178void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
John Reck1bcacfd2017-11-03 10:12:19 -0700179 return mRenderThread.queue().runSync([&]() { layer->detachSurfaceTexture(); });
John Recke1628b72014-05-23 15:11:19 -0700180}
181
John Reck2de950d2017-01-25 10:58:30 -0800182void RenderProxy::destroyHardwareResources() {
John Reck1bcacfd2017-11-03 10:12:19 -0700183 return mRenderThread.queue().runSync([&]() { mContext->destroyHardwareResources(); });
John Reckf47a5942014-06-30 16:20:04 -0700184}
185
186void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700187 // Avoid creating a RenderThread to do a trimMemory.
188 if (RenderThread::hasInstance()) {
189 RenderThread& thread = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700190 thread.queue().post([&thread, level]() { CanvasContext::trimMemory(thread, level); });
John Reckcd3a22c2014-08-06 13:33:59 -0700191 }
John Reckf47a5942014-06-30 16:20:04 -0700192}
193
Chris Craik2507c342015-05-04 14:36:49 -0700194void RenderProxy::overrideProperty(const char* name, const char* value) {
John Reckf8441e62017-10-23 13:10:41 -0700195 // expensive, but block here since name/value pointers owned by caller
John Reck1bcacfd2017-11-03 10:12:19 -0700196 RenderThread::getInstance().queue().runSync(
197 [&]() { Properties::overrideProperty(name, value); });
Chris Craik2507c342015-05-04 14:36:49 -0700198}
199
John Reck28ad7b52014-04-07 16:59:25 -0700200void RenderProxy::fence() {
John Reck1bcacfd2017-11-03 10:12:19 -0700201 mRenderThread.queue().runSync([]() {});
John Reck28ad7b52014-04-07 16:59:25 -0700202}
203
John Recke4c1e6c2018-05-24 16:27:35 -0700204int RenderProxy::maxTextureSize() {
John Reck5cca8f22018-12-10 17:06:22 -0800205 static int maxTextureSize = RenderThread::getInstance().queue().runSync(
206 []() { return DeviceInfo::get()->maxTextureSize(); });
John Recke4c1e6c2018-05-24 16:27:35 -0700207 return maxTextureSize;
John Reckf47a5942014-06-30 16:20:04 -0700208}
209
210void RenderProxy::stopDrawing() {
John Reck1bcacfd2017-11-03 10:12:19 -0700211 mRenderThread.queue().runSync([this]() { mContext->stopDrawing(); });
John Recka5dda642014-05-22 15:43:54 -0700212}
213
214void RenderProxy::notifyFramePending() {
John Reck1bcacfd2017-11-03 10:12:19 -0700215 mRenderThread.queue().post([this]() { mContext->notifyFramePending(); });
John Reckfe5e7b72014-05-23 17:42:28 -0700216}
217
John Reckba6adf62015-02-19 14:36:50 -0800218void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckf8441e62017-10-23 13:10:41 -0700219 mRenderThread.queue().runSync([&]() {
220 mContext->profiler().dumpData(fd);
221 if (dumpFlags & DumpFlags::FrameStats) {
222 mContext->dumpFrames(fd);
223 }
224 if (dumpFlags & DumpFlags::JankStats) {
225 mRenderThread.globalProfileData()->dump(fd);
226 }
227 if (dumpFlags & DumpFlags::Reset) {
228 mContext->resetFrameStats();
229 }
230 });
John Reck7f2e5e32015-05-05 11:00:53 -0700231}
232
233void RenderProxy::resetProfileInfo() {
John Reck1bcacfd2017-11-03 10:12:19 -0700234 mRenderThread.queue().runSync([=]() { mContext->resetFrameStats(); });
John Reck7f2e5e32015-05-05 11:00:53 -0700235}
236
John Reckf8441e62017-10-23 13:10:41 -0700237uint32_t RenderProxy::frameTimePercentile(int percentile) {
238 return mRenderThread.queue().runSync([&]() -> auto {
239 return mRenderThread.globalProfileData()->findPercentile(percentile);
240 });
John Reck0e89e2b2014-10-31 14:49:06 -0700241}
242
Chris Craik2ae07332015-01-21 14:22:39 -0800243void RenderProxy::dumpGraphicsMemory(int fd) {
John Reckba7e9652019-01-23 10:33:41 -0800244 if (RenderThread::hasInstance()) {
245 auto& thread = RenderThread::getInstance();
246 thread.queue().runSync([&]() { thread.dumpGraphicsMemory(fd); });
247 }
John Reckedc524c2015-03-18 15:24:33 -0700248}
249
250void RenderProxy::setProcessStatsBuffer(int fd) {
John Reckdf1742e2017-01-19 15:56:21 -0800251 auto& rt = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700252 rt.queue().post([&rt, fd = dup(fd) ]() {
John Reckf8441e62017-10-23 13:10:41 -0700253 rt.globalProfileData().switchStorageToAshmem(fd);
254 close(fd);
255 });
John Reckdf1742e2017-01-19 15:56:21 -0800256}
257
258void RenderProxy::rotateProcessStatsBuffer() {
John Reckdf1742e2017-01-19 15:56:21 -0800259 auto& rt = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700260 rt.queue().post([&rt]() { rt.globalProfileData().rotateStorage(); });
John Reckedc524c2015-03-18 15:24:33 -0700261}
262
Tim Murray33eb07f2016-06-10 10:03:20 -0700263int RenderProxy::getRenderThreadTid() {
264 return mRenderThread.getTid();
265}
266
Skuhneea7a7fb2015-08-28 07:10:31 -0700267void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) {
John Reck1bcacfd2017-11-03 10:12:19 -0700268 mRenderThread.queue().post([=]() { mContext->addRenderNode(node, placeFront); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700269}
270
271void RenderProxy::removeRenderNode(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700272 mRenderThread.queue().post([=]() { mContext->removeRenderNode(node); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700273}
274
275void RenderProxy::drawRenderNode(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700276 mRenderThread.queue().runSync([=]() { mContext->prepareAndDraw(node); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700277}
278
Skuhneb8160872015-09-22 09:51:39 -0700279void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) {
John Reckf138b172017-09-08 11:00:42 -0700280 mDrawFrameTask.setContentDrawBounds(left, top, right, bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700281}
282
John Reck5cca8f22018-12-10 17:06:22 -0800283void RenderProxy::setPictureCapturedCallback(
284 const std::function<void(sk_sp<SkPicture>&&)>& callback) {
285 mRenderThread.queue().post(
286 [ this, cb = callback ]() { mContext->setPictureCapturedCallback(cb); });
287}
288
Mihai Popa95688002018-02-23 16:10:11 +0000289void RenderProxy::setFrameCallback(std::function<void(int64_t)>&& callback) {
290 mDrawFrameTask.setFrameCallback(std::move(callback));
291}
292
John Reckcc2eee82018-05-17 10:44:00 -0700293void RenderProxy::setFrameCompleteCallback(std::function<void(int64_t)>&& callback) {
294 mDrawFrameTask.setFrameCompleteCallback(std::move(callback));
295}
296
John Reckf8441e62017-10-23 13:10:41 -0700297void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observerPtr) {
John Reck1bcacfd2017-11-03 10:12:19 -0700298 mRenderThread.queue().post([ this, observer = sp{observerPtr} ]() {
John Reckf8441e62017-10-23 13:10:41 -0700299 mContext->addFrameMetricsObserver(observer.get());
300 });
Andres Morales06f5bc72015-12-15 15:21:31 -0800301}
302
John Reckf8441e62017-10-23 13:10:41 -0700303void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observerPtr) {
John Reck1bcacfd2017-11-03 10:12:19 -0700304 mRenderThread.queue().post([ this, observer = sp{observerPtr} ]() {
John Reckf8441e62017-10-23 13:10:41 -0700305 mContext->removeFrameMetricsObserver(observer.get());
306 });
John Reck10dd0582016-03-31 16:36:16 -0700307}
308
John Reckbb3a3582018-09-26 11:21:08 -0700309void RenderProxy::setForceDark(bool enable) {
John Reck5cca8f22018-12-10 17:06:22 -0800310 mRenderThread.queue().post([this, enable]() { mContext->setForceDark(enable); });
John Reckbb3a3582018-09-26 11:21:08 -0700311}
312
John Reck1bcacfd2017-11-03 10:12:19 -0700313int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, int right, int bottom,
314 SkBitmap* bitmap) {
John Reckf8441e62017-10-23 13:10:41 -0700315 auto& thread = RenderThread::getInstance();
316 return static_cast<int>(thread.queue().runSync([&]() -> auto {
317 return thread.readback().copySurfaceInto(*surface, Rect(left, top, right, bottom), bitmap);
318 }));
John Reck43871902016-08-01 14:39:24 -0700319}
320
sergeyvec4a4b12016-10-20 18:39:04 -0700321void RenderProxy::prepareToDraw(Bitmap& bitmap) {
John Reck43871902016-08-01 14:39:24 -0700322 // If we haven't spun up a hardware accelerated window yet, there's no
323 // point in precaching these bitmaps as it can't impact jank.
324 // We also don't know if we even will spin up a hardware-accelerated
325 // window or not.
326 if (!RenderThread::hasInstance()) return;
327 RenderThread* renderThread = &RenderThread::getInstance();
sergeyvec4a4b12016-10-20 18:39:04 -0700328 bitmap.ref();
John Reckf8441e62017-10-23 13:10:41 -0700329 auto task = [renderThread, &bitmap]() {
330 CanvasContext::prepareToDraw(*renderThread, &bitmap);
331 bitmap.unref();
332 };
John Reck43871902016-08-01 14:39:24 -0700333 nsecs_t lastVsync = renderThread->timeLord().latestVsync();
334 nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos();
335 nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(CLOCK_MONOTONIC);
336 // We expect the UI thread to take 4ms and for RT to be active from VSYNC+4ms to
337 // VSYNC+12ms or so, so aim for the gap during which RT is expected to
338 // be idle
339 // TODO: Make this concept a first-class supported thing? RT could use
340 // knowledge of pending draws to better schedule this task
341 if (timeToNextVsync > -6_ms && timeToNextVsync < 1_ms) {
John Reckf8441e62017-10-23 13:10:41 -0700342 renderThread->queue().postAt(estimatedNextVsync + 8_ms, task);
John Reck43871902016-08-01 14:39:24 -0700343 } else {
John Reckf8441e62017-10-23 13:10:41 -0700344 renderThread->queue().post(task);
John Reck43871902016-08-01 14:39:24 -0700345 }
346}
347
Stan Iliev1a025a72018-09-05 16:35:11 -0400348int RenderProxy::copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap) {
Stan Iliev6983bc42017-02-02 14:11:53 -0500349 RenderThread& thread = RenderThread::getInstance();
John Reck1072fff2018-04-12 15:20:09 -0700350 if (gettid() == thread.getTid()) {
John Reck1bcacfd2017-11-03 10:12:19 -0700351 // TODO: fix everything that hits this. We should never be triggering a readback ourselves.
Stan Iliev1a025a72018-09-05 16:35:11 -0400352 return (int)thread.readback().copyHWBitmapInto(hwBitmap, bitmap);
Stan Iliev6983bc42017-02-02 14:11:53 -0500353 } else {
John Reck5cca8f22018-12-10 17:06:22 -0800354 return thread.queue().runSync(
355 [&]() -> int { return (int)thread.readback().copyHWBitmapInto(hwBitmap, bitmap); });
Stan Iliev6983bc42017-02-02 14:11:53 -0500356 }
sergeyv59eecb522016-11-17 17:54:57 -0800357}
358
John Recka8963062017-06-14 10:47:50 -0700359void RenderProxy::disableVsync() {
360 Properties::disableVsync = true;
361}
362
Stan Iliev3310fb12017-03-23 16:56:51 -0400363void RenderProxy::repackVectorDrawableAtlas() {
364 RenderThread& thread = RenderThread::getInstance();
John Reckf8441e62017-10-23 13:10:41 -0700365 thread.queue().post([&thread]() {
Stan Iliev6c4b6e82018-03-01 15:51:17 -0500366 // The context may be null if trimMemory executed, but then the atlas was deleted too.
367 if (thread.getGrContext() != nullptr) {
368 thread.cacheManager().acquireVectorDrawableAtlas()->repackIfNeeded(
369 thread.getGrContext());
370 }
John Reckf8441e62017-10-23 13:10:41 -0700371 });
Stan Iliev6b894d72017-08-23 12:41:41 -0400372}
373
374void RenderProxy::releaseVDAtlasEntries() {
375 RenderThread& thread = RenderThread::getInstance();
John Reckf8441e62017-10-23 13:10:41 -0700376 thread.queue().post([&thread]() {
Stan Iliev6c4b6e82018-03-01 15:51:17 -0500377 // The context may be null if trimMemory executed, but then the atlas was deleted too.
378 if (thread.getGrContext() != nullptr) {
379 thread.cacheManager().acquireVectorDrawableAtlas()->delayedReleaseEntries();
380 }
John Reckf8441e62017-10-23 13:10:41 -0700381 });
John Reck0e89e2b2014-10-31 14:49:06 -0700382}
383
John Reck4f02bf42014-01-03 18:09:17 -0800384} /* namespace renderthread */
385} /* namespace uirenderer */
386} /* namespace android */