blob: 6eca8d2f346f3c0c14eced0920f0545e84e9add3 [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 Reckb90d4cb2018-04-19 17:05:35 -070024#include "pipeline/skia/SkiaOpenGLPipeline.h"
Stan Iliev3310fb12017-03-23 16:56:51 -040025#include "pipeline/skia/VectorDrawableAtlas.h"
John Reck1bcacfd2017-11-03 10:12:19 -070026#include "renderstate/RenderState.h"
John Reckba6adf62015-02-19 14:36:50 -080027#include "renderthread/CanvasContext.h"
John Reck43871902016-08-01 14:39:24 -070028#include "renderthread/EglManager.h"
John Reckba6adf62015-02-19 14:36:50 -080029#include "renderthread/RenderTask.h"
30#include "renderthread/RenderThread.h"
31#include "utils/Macros.h"
John Reck43871902016-08-01 14:39:24 -070032#include "utils/TimeUtils.h"
John Reck4f02bf42014-01-03 18:09:17 -080033
sergeyv59eecb522016-11-17 17:54:57 -080034#include <ui/GraphicBuffer.h>
35
John Reck4f02bf42014-01-03 18:09:17 -080036namespace android {
37namespace uirenderer {
38namespace renderthread {
39
John Reck1bcacfd2017-11-03 10:12:19 -070040RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode,
41 IContextFactory* contextFactory)
42 : mRenderThread(RenderThread::getInstance()), mContext(nullptr) {
John Reckf8441e62017-10-23 13:10:41 -070043 mContext = mRenderThread.queue().runSync([&]() -> CanvasContext* {
44 return CanvasContext::create(mRenderThread, translucent, rootRenderNode, contextFactory);
45 });
Skuhneea7a7fb2015-08-28 07:10:31 -070046 mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode);
John Reck4f02bf42014-01-03 18:09:17 -080047}
48
49RenderProxy::~RenderProxy() {
50 destroyContext();
51}
52
John Reck4f02bf42014-01-03 18:09:17 -080053void RenderProxy::destroyContext() {
54 if (mContext) {
Skuhneea7a7fb2015-08-28 07:10:31 -070055 mDrawFrameTask.setContext(nullptr, nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070056 // This is also a fence as we need to be certain that there are no
57 // outstanding mDrawFrame tasks posted before it is destroyed
John Reck1bcacfd2017-11-03 10:12:19 -070058 mRenderThread.queue().runSync([this]() { delete mContext; });
John Reckf8441e62017-10-23 13:10:41 -070059 mContext = nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080060 }
61}
62
John Reck1125d1f2014-10-23 11:02:19 -070063void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
John Reck1bcacfd2017-11-03 10:12:19 -070064 mRenderThread.queue().post([this, swapBehavior]() { mContext->setSwapBehavior(swapBehavior); });
John Recke4280ba2014-05-05 16:39:37 -070065}
66
67bool RenderProxy::loadSystemProperties() {
John Reckf8441e62017-10-23 13:10:41 -070068 return mRenderThread.queue().runSync([this]() -> bool {
John Reckd9d7f122018-05-03 14:40:56 -070069 bool needsRedraw = Properties::load();
John Reckf8441e62017-10-23 13:10:41 -070070 if (mContext->profiler().consumeProperties()) {
71 needsRedraw = true;
72 }
73 return needsRedraw;
74 });
John Reckb36016c2015-03-11 08:50:53 -070075}
76
77void RenderProxy::setName(const char* name) {
John Reckf8441e62017-10-23 13:10:41 -070078 // block since name/value pointers owned by caller
79 // TODO: Support move arguments
John Reck1bcacfd2017-11-03 10:12:19 -070080 mRenderThread.queue().runSync([this, name]() { mContext->setName(std::string(name)); });
John Reck4f02bf42014-01-03 18:09:17 -080081}
82
John Reckf6481082016-02-02 15:18:23 -080083void RenderProxy::initialize(const sp<Surface>& surface) {
John Reck1bcacfd2017-11-03 10:12:19 -070084 mRenderThread.queue().post(
85 [ this, surf = surface ]() mutable { mContext->setSurface(std::move(surf)); });
John Reck4f02bf42014-01-03 18:09:17 -080086}
87
John Reckf6481082016-02-02 15:18:23 -080088void RenderProxy::updateSurface(const sp<Surface>& surface) {
John Reck1bcacfd2017-11-03 10:12:19 -070089 mRenderThread.queue().post(
90 [ this, surf = surface ]() mutable { mContext->setSurface(std::move(surf)); });
John Reckf7d9c1d2014-04-09 10:01:03 -070091}
92
John Reckf6481082016-02-02 15:18:23 -080093bool RenderProxy::pauseSurface(const sp<Surface>& surface) {
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 Reckf8441e62017-10-23 13:10:41 -0700101void RenderProxy::setup(float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
John Reck1bcacfd2017-11-03 10:12:19 -0700102 mRenderThread.queue().post(
103 [=]() { mContext->setup(lightRadius, ambientShadowAlpha, spotShadowAlpha); });
Alan Viverette50210d92015-05-14 18:05:36 -0700104}
105
106void RenderProxy::setLightCenter(const Vector3& lightCenter) {
John Reck1bcacfd2017-11-03 10:12:19 -0700107 mRenderThread.queue().post([=]() { mContext->setLightCenter(lightCenter); });
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 Reck19b6bcf2014-02-14 20:03:38 -0800147DeferredLayerUpdater* RenderProxy::createTextureLayer() {
John Reckf8441e62017-10-23 13:10:41 -0700148 return mRenderThread.queue().runSync([this]() -> auto {
149 return mContext->createTextureLayer();
150 });
John Reck3e824952014-08-20 10:08:39 -0700151}
152
John Reck2de950d2017-01-25 10:58:30 -0800153void RenderProxy::buildLayer(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700154 mRenderThread.queue().runSync([&]() { mContext->buildLayer(node); });
John Reck19b6bcf2014-02-14 20:03:38 -0800155}
156
John Reck3731dc22015-04-13 15:20:29 -0700157bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
John Reck1bcacfd2017-11-03 10:12:19 -0700158 return mRenderThread.queue().runSync(
159 [&]() -> bool { return mContext->copyLayerInto(layer, &bitmap); });
John Reck19b6bcf2014-02-14 20:03:38 -0800160}
161
John Reckd72e0a32014-05-29 18:56:11 -0700162void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
163 mDrawFrameTask.pushLayerUpdate(layer);
164}
165
166void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
167 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800168}
169
John Reck918ad522014-06-27 14:45:25 -0700170void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
John Reck1bcacfd2017-11-03 10:12:19 -0700171 return mRenderThread.queue().runSync([&]() { layer->detachSurfaceTexture(); });
John Recke1628b72014-05-23 15:11:19 -0700172}
173
John Reck2de950d2017-01-25 10:58:30 -0800174void RenderProxy::destroyHardwareResources() {
John Reck1bcacfd2017-11-03 10:12:19 -0700175 return mRenderThread.queue().runSync([&]() { mContext->destroyHardwareResources(); });
John Reckf47a5942014-06-30 16:20:04 -0700176}
177
178void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700179 // Avoid creating a RenderThread to do a trimMemory.
180 if (RenderThread::hasInstance()) {
181 RenderThread& thread = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700182 thread.queue().post([&thread, level]() { CanvasContext::trimMemory(thread, level); });
John Reckcd3a22c2014-08-06 13:33:59 -0700183 }
John Reckf47a5942014-06-30 16:20:04 -0700184}
185
Chris Craik2507c342015-05-04 14:36:49 -0700186void RenderProxy::overrideProperty(const char* name, const char* value) {
John Reckf8441e62017-10-23 13:10:41 -0700187 // expensive, but block here since name/value pointers owned by caller
John Reck1bcacfd2017-11-03 10:12:19 -0700188 RenderThread::getInstance().queue().runSync(
189 [&]() { Properties::overrideProperty(name, value); });
Chris Craik2507c342015-05-04 14:36:49 -0700190}
191
John Reck28ad7b52014-04-07 16:59:25 -0700192void RenderProxy::fence() {
John Reck1bcacfd2017-11-03 10:12:19 -0700193 mRenderThread.queue().runSync([]() {});
John Reck28ad7b52014-04-07 16:59:25 -0700194}
195
John Recke4c1e6c2018-05-24 16:27:35 -0700196int RenderProxy::maxTextureSize() {
197 static int maxTextureSize = RenderThread::getInstance().queue().runSync([]() {
198 return DeviceInfo::get()->maxTextureSize();
199 });
200 return maxTextureSize;
John Reckf47a5942014-06-30 16:20:04 -0700201}
202
203void RenderProxy::stopDrawing() {
John Reck1bcacfd2017-11-03 10:12:19 -0700204 mRenderThread.queue().runSync([this]() { mContext->stopDrawing(); });
John Recka5dda642014-05-22 15:43:54 -0700205}
206
207void RenderProxy::notifyFramePending() {
John Reck1bcacfd2017-11-03 10:12:19 -0700208 mRenderThread.queue().post([this]() { mContext->notifyFramePending(); });
John Reckfe5e7b72014-05-23 17:42:28 -0700209}
210
John Reckba6adf62015-02-19 14:36:50 -0800211void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckf8441e62017-10-23 13:10:41 -0700212 mRenderThread.queue().runSync([&]() {
213 mContext->profiler().dumpData(fd);
214 if (dumpFlags & DumpFlags::FrameStats) {
215 mContext->dumpFrames(fd);
216 }
217 if (dumpFlags & DumpFlags::JankStats) {
218 mRenderThread.globalProfileData()->dump(fd);
219 }
220 if (dumpFlags & DumpFlags::Reset) {
221 mContext->resetFrameStats();
222 }
223 });
John Reck7f2e5e32015-05-05 11:00:53 -0700224}
225
226void RenderProxy::resetProfileInfo() {
John Reck1bcacfd2017-11-03 10:12:19 -0700227 mRenderThread.queue().runSync([=]() { mContext->resetFrameStats(); });
John Reck7f2e5e32015-05-05 11:00:53 -0700228}
229
John Reckf8441e62017-10-23 13:10:41 -0700230uint32_t RenderProxy::frameTimePercentile(int percentile) {
231 return mRenderThread.queue().runSync([&]() -> auto {
232 return mRenderThread.globalProfileData()->findPercentile(percentile);
233 });
John Reck0e89e2b2014-10-31 14:49:06 -0700234}
235
Chris Craik2ae07332015-01-21 14:22:39 -0800236void RenderProxy::dumpGraphicsMemory(int fd) {
John Reckf8441e62017-10-23 13:10:41 -0700237 auto& thread = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700238 thread.queue().runSync([&]() { thread.dumpGraphicsMemory(fd); });
John Reckedc524c2015-03-18 15:24:33 -0700239}
240
241void RenderProxy::setProcessStatsBuffer(int fd) {
John Reckdf1742e2017-01-19 15:56:21 -0800242 auto& rt = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700243 rt.queue().post([&rt, fd = dup(fd) ]() {
John Reckf8441e62017-10-23 13:10:41 -0700244 rt.globalProfileData().switchStorageToAshmem(fd);
245 close(fd);
246 });
John Reckdf1742e2017-01-19 15:56:21 -0800247}
248
249void RenderProxy::rotateProcessStatsBuffer() {
John Reckdf1742e2017-01-19 15:56:21 -0800250 auto& rt = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700251 rt.queue().post([&rt]() { rt.globalProfileData().rotateStorage(); });
John Reckedc524c2015-03-18 15:24:33 -0700252}
253
Tim Murray33eb07f2016-06-10 10:03:20 -0700254int RenderProxy::getRenderThreadTid() {
255 return mRenderThread.getTid();
256}
257
Skuhneea7a7fb2015-08-28 07:10:31 -0700258void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) {
John Reck1bcacfd2017-11-03 10:12:19 -0700259 mRenderThread.queue().post([=]() { mContext->addRenderNode(node, placeFront); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700260}
261
262void RenderProxy::removeRenderNode(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700263 mRenderThread.queue().post([=]() { mContext->removeRenderNode(node); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700264}
265
266void RenderProxy::drawRenderNode(RenderNode* node) {
John Reck1bcacfd2017-11-03 10:12:19 -0700267 mRenderThread.queue().runSync([=]() { mContext->prepareAndDraw(node); });
Skuhneea7a7fb2015-08-28 07:10:31 -0700268}
269
Skuhneb8160872015-09-22 09:51:39 -0700270void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) {
John Reckf138b172017-09-08 11:00:42 -0700271 mDrawFrameTask.setContentDrawBounds(left, top, right, bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700272}
273
Mihai Popa95688002018-02-23 16:10:11 +0000274void RenderProxy::setFrameCallback(std::function<void(int64_t)>&& callback) {
275 mDrawFrameTask.setFrameCallback(std::move(callback));
276}
277
John Reckcc2eee82018-05-17 10:44:00 -0700278void RenderProxy::setFrameCompleteCallback(std::function<void(int64_t)>&& callback) {
279 mDrawFrameTask.setFrameCompleteCallback(std::move(callback));
280}
281
John Reckf8441e62017-10-23 13:10:41 -0700282void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observerPtr) {
John Reck1bcacfd2017-11-03 10:12:19 -0700283 mRenderThread.queue().post([ this, observer = sp{observerPtr} ]() {
John Reckf8441e62017-10-23 13:10:41 -0700284 mContext->addFrameMetricsObserver(observer.get());
285 });
Andres Morales06f5bc72015-12-15 15:21:31 -0800286}
287
John Reckf8441e62017-10-23 13:10:41 -0700288void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observerPtr) {
John Reck1bcacfd2017-11-03 10:12:19 -0700289 mRenderThread.queue().post([ this, observer = sp{observerPtr} ]() {
John Reckf8441e62017-10-23 13:10:41 -0700290 mContext->removeFrameMetricsObserver(observer.get());
291 });
John Reck10dd0582016-03-31 16:36:16 -0700292}
293
John Reck1bcacfd2017-11-03 10:12:19 -0700294int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, int right, int bottom,
295 SkBitmap* bitmap) {
John Reckf8441e62017-10-23 13:10:41 -0700296 auto& thread = RenderThread::getInstance();
297 return static_cast<int>(thread.queue().runSync([&]() -> auto {
298 return thread.readback().copySurfaceInto(*surface, Rect(left, top, right, bottom), bitmap);
299 }));
John Reck43871902016-08-01 14:39:24 -0700300}
301
sergeyvec4a4b12016-10-20 18:39:04 -0700302void RenderProxy::prepareToDraw(Bitmap& bitmap) {
John Reck43871902016-08-01 14:39:24 -0700303 // If we haven't spun up a hardware accelerated window yet, there's no
304 // point in precaching these bitmaps as it can't impact jank.
305 // We also don't know if we even will spin up a hardware-accelerated
306 // window or not.
307 if (!RenderThread::hasInstance()) return;
308 RenderThread* renderThread = &RenderThread::getInstance();
sergeyvec4a4b12016-10-20 18:39:04 -0700309 bitmap.ref();
John Reckf8441e62017-10-23 13:10:41 -0700310 auto task = [renderThread, &bitmap]() {
311 CanvasContext::prepareToDraw(*renderThread, &bitmap);
312 bitmap.unref();
313 };
John Reck43871902016-08-01 14:39:24 -0700314 nsecs_t lastVsync = renderThread->timeLord().latestVsync();
315 nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos();
316 nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(CLOCK_MONOTONIC);
317 // We expect the UI thread to take 4ms and for RT to be active from VSYNC+4ms to
318 // VSYNC+12ms or so, so aim for the gap during which RT is expected to
319 // be idle
320 // TODO: Make this concept a first-class supported thing? RT could use
321 // knowledge of pending draws to better schedule this task
322 if (timeToNextVsync > -6_ms && timeToNextVsync < 1_ms) {
John Reckf8441e62017-10-23 13:10:41 -0700323 renderThread->queue().postAt(estimatedNextVsync + 8_ms, task);
John Reck43871902016-08-01 14:39:24 -0700324 } else {
John Reckf8441e62017-10-23 13:10:41 -0700325 renderThread->queue().post(task);
John Reck43871902016-08-01 14:39:24 -0700326 }
327}
328
sergeyv59eecb522016-11-17 17:54:57 -0800329int RenderProxy::copyGraphicBufferInto(GraphicBuffer* buffer, SkBitmap* bitmap) {
Stan Iliev6983bc42017-02-02 14:11:53 -0500330 RenderThread& thread = RenderThread::getInstance();
John Reck1072fff2018-04-12 15:20:09 -0700331 if (gettid() == thread.getTid()) {
John Reck1bcacfd2017-11-03 10:12:19 -0700332 // TODO: fix everything that hits this. We should never be triggering a readback ourselves.
333 return (int)thread.readback().copyGraphicBufferInto(buffer, bitmap);
Stan Iliev6983bc42017-02-02 14:11:53 -0500334 } else {
John Reckf8441e62017-10-23 13:10:41 -0700335 return thread.queue().runSync([&]() -> int {
John Reck1bcacfd2017-11-03 10:12:19 -0700336 return (int)thread.readback().copyGraphicBufferInto(buffer, bitmap);
John Reckf8441e62017-10-23 13:10:41 -0700337 });
Stan Iliev6983bc42017-02-02 14:11:53 -0500338 }
sergeyv59eecb522016-11-17 17:54:57 -0800339}
340
John Reck9a814872017-05-22 15:04:21 -0700341void RenderProxy::onBitmapDestroyed(uint32_t pixelRefId) {
342 if (!RenderThread::hasInstance()) return;
John Reck9a814872017-05-22 15:04:21 -0700343 RenderThread& thread = RenderThread::getInstance();
John Reck1bcacfd2017-11-03 10:12:19 -0700344 thread.queue().post(
345 [&thread, pixelRefId]() { thread.renderState().onBitmapDestroyed(pixelRefId); });
John Reck9a814872017-05-22 15:04:21 -0700346}
347
John Recka8963062017-06-14 10:47:50 -0700348void RenderProxy::disableVsync() {
349 Properties::disableVsync = true;
350}
351
Stan Iliev3310fb12017-03-23 16:56:51 -0400352void RenderProxy::repackVectorDrawableAtlas() {
353 RenderThread& thread = RenderThread::getInstance();
John Reckf8441e62017-10-23 13:10:41 -0700354 thread.queue().post([&thread]() {
Stan Iliev6c4b6e82018-03-01 15:51:17 -0500355 // The context may be null if trimMemory executed, but then the atlas was deleted too.
356 if (thread.getGrContext() != nullptr) {
357 thread.cacheManager().acquireVectorDrawableAtlas()->repackIfNeeded(
358 thread.getGrContext());
359 }
John Reckf8441e62017-10-23 13:10:41 -0700360 });
Stan Iliev6b894d72017-08-23 12:41:41 -0400361}
362
363void RenderProxy::releaseVDAtlasEntries() {
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()->delayedReleaseEntries();
369 }
John Reckf8441e62017-10-23 13:10:41 -0700370 });
John Reck0e89e2b2014-10-31 14:49:06 -0700371}
372
John Reck4f02bf42014-01-03 18:09:17 -0800373} /* namespace renderthread */
374} /* namespace uirenderer */
375} /* namespace android */