blob: 3a31db0814c2cecb6c103916e67599aef2c0d8b4 [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"
21#include "LayerRenderer.h"
22#include "Rect.h"
23#include "renderthread/CanvasContext.h"
24#include "renderthread/RenderTask.h"
25#include "renderthread/RenderThread.h"
26#include "utils/Macros.h"
John Reck4f02bf42014-01-03 18:09:17 -080027
28namespace android {
29namespace uirenderer {
30namespace renderthread {
31
32#define ARGS(method) method ## Args
33
John Reck19b6bcf2014-02-14 20:03:38 -080034#define CREATE_BRIDGE0(name) CREATE_BRIDGE(name,,,,,,,,)
John Reck4f02bf42014-01-03 18:09:17 -080035#define CREATE_BRIDGE1(name, a1) CREATE_BRIDGE(name, a1,,,,,,,)
36#define CREATE_BRIDGE2(name, a1, a2) CREATE_BRIDGE(name, a1,a2,,,,,,)
37#define CREATE_BRIDGE3(name, a1, a2, a3) CREATE_BRIDGE(name, a1,a2,a3,,,,,)
38#define CREATE_BRIDGE4(name, a1, a2, a3, a4) CREATE_BRIDGE(name, a1,a2,a3,a4,,,,)
Chris Craik797b95b2014-05-20 18:10:25 -070039#define CREATE_BRIDGE5(name, a1, a2, a3, a4, a5) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,,,)
Chris Craik058fc642014-07-23 18:19:28 -070040#define CREATE_BRIDGE6(name, a1, a2, a3, a4, a5, a6) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,,)
41#define CREATE_BRIDGE7(name, a1, a2, a3, a4, a5, a6, a7) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,a7,)
John Reck4f02bf42014-01-03 18:09:17 -080042#define CREATE_BRIDGE(name, a1, a2, a3, a4, a5, a6, a7, a8) \
43 typedef struct { \
44 a1; a2; a3; a4; a5; a6; a7; a8; \
45 } ARGS(name); \
46 static void* Bridge_ ## name(ARGS(name)* args)
47
48#define SETUP_TASK(method) \
49 LOG_ALWAYS_FATAL_IF( METHOD_INVOKE_PAYLOAD_SIZE < sizeof(ARGS(method)), \
Mark Salyzyn546f3532014-06-10 12:29:14 -070050 "METHOD_INVOKE_PAYLOAD_SIZE %zu is smaller than sizeof(" #method "Args) %zu", \
John Reck4f02bf42014-01-03 18:09:17 -080051 METHOD_INVOKE_PAYLOAD_SIZE, sizeof(ARGS(method))); \
John Recke2c45522014-04-07 17:31:44 -070052 MethodInvokeRenderTask* task = new MethodInvokeRenderTask((RunnableMethod) Bridge_ ## method); \
John Reck4f02bf42014-01-03 18:09:17 -080053 ARGS(method) *args = (ARGS(method) *) task->payload()
54
John Reckba6adf62015-02-19 14:36:50 -080055HWUI_ENUM(DumpFlags,
56 kFrameStats = 1 << 0,
57 kReset = 1 << 1,
58);
59
John Reck119907c2014-08-14 09:02:01 -070060CREATE_BRIDGE4(createContext, RenderThread* thread, bool translucent,
61 RenderNode* rootRenderNode, IContextFactory* contextFactory) {
62 return new CanvasContext(*args->thread, args->translucent,
63 args->rootRenderNode, args->contextFactory);
John Reck4f02bf42014-01-03 18:09:17 -080064}
65
John Reck119907c2014-08-14 09:02:01 -070066RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory)
John Reck4f02bf42014-01-03 18:09:17 -080067 : mRenderThread(RenderThread::getInstance())
Chris Craikd41c4d82015-01-05 15:51:13 -080068 , mContext(nullptr) {
John Reck4f02bf42014-01-03 18:09:17 -080069 SETUP_TASK(createContext);
70 args->translucent = translucent;
John Recke45b1fd2014-04-15 09:50:16 -070071 args->rootRenderNode = rootRenderNode;
John Reck3b202512014-06-23 13:13:08 -070072 args->thread = &mRenderThread;
John Reck119907c2014-08-14 09:02:01 -070073 args->contextFactory = contextFactory;
John Reck4f02bf42014-01-03 18:09:17 -080074 mContext = (CanvasContext*) postAndWait(task);
John Reck18f16e62014-05-02 16:46:41 -070075 mDrawFrameTask.setContext(&mRenderThread, mContext);
John Reck4f02bf42014-01-03 18:09:17 -080076}
77
78RenderProxy::~RenderProxy() {
79 destroyContext();
80}
81
82CREATE_BRIDGE1(destroyContext, CanvasContext* context) {
83 delete args->context;
Chris Craikd41c4d82015-01-05 15:51:13 -080084 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080085}
86
87void RenderProxy::destroyContext() {
88 if (mContext) {
89 SETUP_TASK(destroyContext);
90 args->context = mContext;
Chris Craikd41c4d82015-01-05 15:51:13 -080091 mContext = nullptr;
92 mDrawFrameTask.setContext(nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070093 // This is also a fence as we need to be certain that there are no
94 // outstanding mDrawFrame tasks posted before it is destroyed
95 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -080096 }
97}
98
John Reck18f16e62014-05-02 16:46:41 -070099CREATE_BRIDGE2(setFrameInterval, RenderThread* thread, nsecs_t frameIntervalNanos) {
John Reckba6adf62015-02-19 14:36:50 -0800100 args->thread->setFrameInterval(args->frameIntervalNanos);
Chris Craikd41c4d82015-01-05 15:51:13 -0800101 return nullptr;
John Reck18f16e62014-05-02 16:46:41 -0700102}
103
104void RenderProxy::setFrameInterval(nsecs_t frameIntervalNanos) {
105 SETUP_TASK(setFrameInterval);
106 args->thread = &mRenderThread;
107 args->frameIntervalNanos = frameIntervalNanos;
108 post(task);
109}
110
John Reck1125d1f2014-10-23 11:02:19 -0700111CREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) {
112 args->context->setSwapBehavior(args->swapBehavior);
Chris Craikd41c4d82015-01-05 15:51:13 -0800113 return nullptr;
John Reck1125d1f2014-10-23 11:02:19 -0700114}
115
116void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
117 SETUP_TASK(setSwapBehavior);
118 args->context = mContext;
119 args->swapBehavior = swapBehavior;
120 post(task);
121}
122
John Reckfe5e7b72014-05-23 17:42:28 -0700123CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) {
John Recke4280ba2014-05-05 16:39:37 -0700124 bool needsRedraw = false;
125 if (Caches::hasInstance()) {
126 needsRedraw = Caches::getInstance().initProperties();
127 }
John Reckfe5e7b72014-05-23 17:42:28 -0700128 if (args->context->profiler().loadSystemProperties()) {
129 needsRedraw = true;
130 }
John Recke4280ba2014-05-05 16:39:37 -0700131 return (void*) needsRedraw;
132}
133
134bool RenderProxy::loadSystemProperties() {
135 SETUP_TASK(loadSystemProperties);
John Reckfe5e7b72014-05-23 17:42:28 -0700136 args->context = mContext;
John Recke4280ba2014-05-05 16:39:37 -0700137 return (bool) postAndWait(task);
138}
139
John Recka5dda642014-05-22 15:43:54 -0700140CREATE_BRIDGE2(initialize, CanvasContext* context, ANativeWindow* window) {
John Reck4f02bf42014-01-03 18:09:17 -0800141 return (void*) args->context->initialize(args->window);
142}
143
John Reckf7d9c1d2014-04-09 10:01:03 -0700144bool RenderProxy::initialize(const sp<ANativeWindow>& window) {
John Reck4f02bf42014-01-03 18:09:17 -0800145 SETUP_TASK(initialize);
146 args->context = mContext;
John Reckf7d9c1d2014-04-09 10:01:03 -0700147 args->window = window.get();
John Reck4f02bf42014-01-03 18:09:17 -0800148 return (bool) postAndWait(task);
149}
150
John Recka5dda642014-05-22 15:43:54 -0700151CREATE_BRIDGE2(updateSurface, CanvasContext* context, ANativeWindow* window) {
John Reck4f02bf42014-01-03 18:09:17 -0800152 args->context->updateSurface(args->window);
Chris Craikd41c4d82015-01-05 15:51:13 -0800153 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800154}
155
John Reckf7d9c1d2014-04-09 10:01:03 -0700156void RenderProxy::updateSurface(const sp<ANativeWindow>& window) {
John Reck4f02bf42014-01-03 18:09:17 -0800157 SETUP_TASK(updateSurface);
158 args->context = mContext;
John Reckf7d9c1d2014-04-09 10:01:03 -0700159 args->window = window.get();
160 postAndWait(task);
161}
162
John Recka5dda642014-05-22 15:43:54 -0700163CREATE_BRIDGE2(pauseSurface, CanvasContext* context, ANativeWindow* window) {
John Reck01a5ea32014-12-03 13:01:07 -0800164 return (void*) args->context->pauseSurface(args->window);
John Reckf7d9c1d2014-04-09 10:01:03 -0700165}
166
John Reck01a5ea32014-12-03 13:01:07 -0800167bool RenderProxy::pauseSurface(const sp<ANativeWindow>& window) {
John Reckf7d9c1d2014-04-09 10:01:03 -0700168 SETUP_TASK(pauseSurface);
169 args->context = mContext;
170 args->window = window.get();
John Reck01a5ea32014-12-03 13:01:07 -0800171 return (bool) postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800172}
173
Chris Craik058fc642014-07-23 18:19:28 -0700174CREATE_BRIDGE7(setup, CanvasContext* context, int width, int height,
175 Vector3 lightCenter, float lightRadius,
176 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
177 args->context->setup(args->width, args->height, args->lightCenter, args->lightRadius,
178 args->ambientShadowAlpha, args->spotShadowAlpha);
Chris Craikd41c4d82015-01-05 15:51:13 -0800179 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800180}
181
Chris Craik058fc642014-07-23 18:19:28 -0700182void RenderProxy::setup(int width, int height, const Vector3& lightCenter, float lightRadius,
John Reckba6adf62015-02-19 14:36:50 -0800183 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha, float density) {
184 mDrawFrameTask.setDensity(density);
John Reck4f02bf42014-01-03 18:09:17 -0800185 SETUP_TASK(setup);
186 args->context = mContext;
187 args->width = width;
188 args->height = height;
Chris Craik797b95b2014-05-20 18:10:25 -0700189 args->lightCenter = lightCenter;
190 args->lightRadius = lightRadius;
Chris Craik058fc642014-07-23 18:19:28 -0700191 args->ambientShadowAlpha = ambientShadowAlpha;
192 args->spotShadowAlpha = spotShadowAlpha;
John Reck4f02bf42014-01-03 18:09:17 -0800193 post(task);
194}
195
John Reck63a06672014-05-07 13:45:54 -0700196CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) {
197 args->context->setOpaque(args->opaque);
Chris Craikd41c4d82015-01-05 15:51:13 -0800198 return nullptr;
John Reck63a06672014-05-07 13:45:54 -0700199}
200
201void RenderProxy::setOpaque(bool opaque) {
202 SETUP_TASK(setOpaque);
203 args->context = mContext;
204 args->opaque = opaque;
205 post(task);
206}
207
John Reckba6adf62015-02-19 14:36:50 -0800208int64_t* RenderProxy::frameInfo() {
209 return mDrawFrameTask.frameInfo();
210}
211
212int RenderProxy::syncAndDrawFrame() {
213 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800214}
215
John Reck17035b02014-09-03 07:39:53 -0700216CREATE_BRIDGE1(destroy, CanvasContext* context) {
217 args->context->destroy();
Chris Craikd41c4d82015-01-05 15:51:13 -0800218 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800219}
220
John Reck17035b02014-09-03 07:39:53 -0700221void RenderProxy::destroy() {
222 SETUP_TASK(destroy);
John Reck4f02bf42014-01-03 18:09:17 -0800223 args->context = mContext;
John Reckfae904d2014-04-14 11:01:57 -0700224 // destroyCanvasAndSurface() needs a fence as when it returns the
225 // underlying BufferQueue is going to be released from under
226 // the render thread.
227 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800228}
229
John Reck3b202512014-06-23 13:13:08 -0700230CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) {
231 CanvasContext::invokeFunctor(*args->thread, args->functor);
Chris Craikd41c4d82015-01-05 15:51:13 -0800232 return nullptr;
John Reck0d1f6342014-03-28 20:30:27 -0700233}
234
235void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700236 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700237 RenderThread& thread = RenderThread::getInstance();
John Reck0d1f6342014-03-28 20:30:27 -0700238 SETUP_TASK(invokeFunctor);
John Reck3b202512014-06-23 13:13:08 -0700239 args->thread = &thread;
John Reck0d1f6342014-03-28 20:30:27 -0700240 args->functor = functor;
241 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700242 // waitForCompletion = true is expected to be fairly rare and only
243 // happen in destruction. Thus it should be fine to temporarily
244 // create a Mutex
John Reck0e89e2b2014-10-31 14:49:06 -0700245 staticPostAndWait(task);
John Reck0d1f6342014-03-28 20:30:27 -0700246 } else {
John Reck3b202512014-06-23 13:13:08 -0700247 thread.queue(task);
John Reck0d1f6342014-03-28 20:30:27 -0700248 }
249}
250
John Reckfc53ef272014-02-11 10:40:25 -0800251CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) {
252 args->context->runWithGlContext(args->task);
Chris Craikd41c4d82015-01-05 15:51:13 -0800253 return nullptr;
John Reckfc53ef272014-02-11 10:40:25 -0800254}
255
256void RenderProxy::runWithGlContext(RenderTask* gltask) {
257 SETUP_TASK(runWithGlContext);
258 args->context = mContext;
259 args->task = gltask;
260 postAndWait(task);
261}
262
John Reck749906b2014-10-03 15:02:19 -0700263CREATE_BRIDGE2(createTextureLayer, RenderThread* thread, CanvasContext* context) {
John Reck1949e792014-04-08 15:18:56 -0700264 Layer* layer = args->context->createTextureLayer();
Chris Craikd41c4d82015-01-05 15:51:13 -0800265 if (!layer) return nullptr;
John Reck749906b2014-10-03 15:02:19 -0700266 return new DeferredLayerUpdater(*args->thread, layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800267}
268
269DeferredLayerUpdater* RenderProxy::createTextureLayer() {
270 SETUP_TASK(createTextureLayer);
John Reck1949e792014-04-08 15:18:56 -0700271 args->context = mContext;
John Reck749906b2014-10-03 15:02:19 -0700272 args->thread = &mRenderThread;
John Reck19b6bcf2014-02-14 20:03:38 -0800273 void* retval = postAndWait(task);
274 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval);
John Reck19b6bcf2014-02-14 20:03:38 -0800275 return layer;
276}
277
John Reck3e824952014-08-20 10:08:39 -0700278CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) {
279 args->context->buildLayer(args->node);
Chris Craikd41c4d82015-01-05 15:51:13 -0800280 return nullptr;
John Reck3e824952014-08-20 10:08:39 -0700281}
282
283void RenderProxy::buildLayer(RenderNode* node) {
284 SETUP_TASK(buildLayer);
285 args->context = mContext;
286 args->node = node;
287 postAndWait(task);
288}
289
John Reck19b6bcf2014-02-14 20:03:38 -0800290CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer,
291 SkBitmap* bitmap) {
292 bool success = args->context->copyLayerInto(args->layer, args->bitmap);
293 return (void*) success;
294}
295
296bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) {
297 SETUP_TASK(copyLayerInto);
298 args->context = mContext;
299 args->layer = layer;
300 args->bitmap = bitmap;
301 return (bool) postAndWait(task);
302}
303
John Reckd72e0a32014-05-29 18:56:11 -0700304void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
305 mDrawFrameTask.pushLayerUpdate(layer);
306}
307
308void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
309 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800310}
311
John Reck918ad522014-06-27 14:45:25 -0700312CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) {
313 args->layer->detachSurfaceTexture();
Chris Craikd41c4d82015-01-05 15:51:13 -0800314 return nullptr;
John Reck918ad522014-06-27 14:45:25 -0700315}
316
317void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
318 SETUP_TASK(detachSurfaceTexture);
319 args->layer = layer;
320 postAndWait(task);
321}
322
John Reckf47a5942014-06-30 16:20:04 -0700323CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) {
324 args->context->destroyHardwareResources();
Chris Craikd41c4d82015-01-05 15:51:13 -0800325 return nullptr;
John Recke1628b72014-05-23 15:11:19 -0700326}
327
John Reckf47a5942014-06-30 16:20:04 -0700328void RenderProxy::destroyHardwareResources() {
329 SETUP_TASK(destroyHardwareResources);
John Recke1628b72014-05-23 15:11:19 -0700330 args->context = mContext;
John Recke1628b72014-05-23 15:11:19 -0700331 post(task);
332}
333
John Reckf47a5942014-06-30 16:20:04 -0700334CREATE_BRIDGE2(timMemory, RenderThread* thread, int level) {
335 CanvasContext::trimMemory(*args->thread, args->level);
Chris Craikd41c4d82015-01-05 15:51:13 -0800336 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700337}
338
339void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700340 // Avoid creating a RenderThread to do a trimMemory.
341 if (RenderThread::hasInstance()) {
342 RenderThread& thread = RenderThread::getInstance();
343 SETUP_TASK(timMemory);
344 args->thread = &thread;
345 args->level = level;
346 thread.queue(task);
347 }
John Reckf47a5942014-06-30 16:20:04 -0700348}
349
John Reck28ad7b52014-04-07 16:59:25 -0700350CREATE_BRIDGE0(fence) {
351 // Intentionally empty
Chris Craikd41c4d82015-01-05 15:51:13 -0800352 return nullptr;
John Reck28ad7b52014-04-07 16:59:25 -0700353}
354
Andreas Gampe64bb4132014-11-22 00:35:09 +0000355template <typename T>
356void UNUSED(T t) {}
357
John Reck28ad7b52014-04-07 16:59:25 -0700358void RenderProxy::fence() {
359 SETUP_TASK(fence);
Andreas Gampe1e196742014-11-10 15:23:43 -0800360 UNUSED(args);
John Reck28ad7b52014-04-07 16:59:25 -0700361 postAndWait(task);
362}
363
John Reckf47a5942014-06-30 16:20:04 -0700364CREATE_BRIDGE1(stopDrawing, CanvasContext* context) {
365 args->context->stopDrawing();
Chris Craikd41c4d82015-01-05 15:51:13 -0800366 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700367}
368
369void RenderProxy::stopDrawing() {
370 SETUP_TASK(stopDrawing);
371 args->context = mContext;
372 postAndWait(task);
373}
374
John Recka5dda642014-05-22 15:43:54 -0700375CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) {
376 args->context->notifyFramePending();
Chris Craikd41c4d82015-01-05 15:51:13 -0800377 return nullptr;
John Recka5dda642014-05-22 15:43:54 -0700378}
379
380void RenderProxy::notifyFramePending() {
381 SETUP_TASK(notifyFramePending);
382 args->context = mContext;
383 mRenderThread.queueAtFront(task);
384}
385
John Reckba6adf62015-02-19 14:36:50 -0800386CREATE_BRIDGE3(dumpProfileInfo, CanvasContext* context, int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700387 args->context->profiler().dumpData(args->fd);
John Reckba6adf62015-02-19 14:36:50 -0800388 if (args->dumpFlags & DumpFlags::kFrameStats) {
389 args->context->dumpFrames(args->fd);
390 }
391 if (args->dumpFlags & DumpFlags::kReset) {
392 args->context->resetFrameStats();
393 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800394 return nullptr;
John Reckfe5e7b72014-05-23 17:42:28 -0700395}
396
John Reckba6adf62015-02-19 14:36:50 -0800397void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700398 SETUP_TASK(dumpProfileInfo);
399 args->context = mContext;
400 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800401 args->dumpFlags = dumpFlags;
John Reckfe5e7b72014-05-23 17:42:28 -0700402 postAndWait(task);
403}
404
John Reckba6adf62015-02-19 14:36:50 -0800405CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) {
406 args->thread->jankTracker().dump(args->fd);
407
Chris Craik2ae07332015-01-21 14:22:39 -0800408 FILE *file = fdopen(args->fd, "a");
409 if (Caches::hasInstance()) {
410 String8 cachesLog;
411 Caches::getInstance().dumpMemoryUsage(cachesLog);
412 fprintf(file, "\nCaches:\n%s\n", cachesLog.string());
413 } else {
414 fprintf(file, "\nNo caches instance.\n");
415 }
416 fflush(file);
Chris Craikd41c4d82015-01-05 15:51:13 -0800417 return nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700418}
419
Chris Craik2ae07332015-01-21 14:22:39 -0800420void RenderProxy::dumpGraphicsMemory(int fd) {
421 SETUP_TASK(dumpGraphicsMemory);
John Reck0e89e2b2014-10-31 14:49:06 -0700422 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800423 args->thread = &RenderThread::getInstance();
John Reck0e89e2b2014-10-31 14:49:06 -0700424 staticPostAndWait(task);
425}
426
John Reck3b202512014-06-23 13:13:08 -0700427CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map, size_t size) {
428 CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size);
Chris Craikd41c4d82015-01-05 15:51:13 -0800429 args->buffer->decStrong(nullptr);
430 return nullptr;
John Reck3b202512014-06-23 13:13:08 -0700431}
432
433void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) {
434 SETUP_TASK(setTextureAtlas);
435 args->thread = &mRenderThread;
436 args->buffer = buffer.get();
Chris Craikd41c4d82015-01-05 15:51:13 -0800437 args->buffer->incStrong(nullptr);
John Reck3b202512014-06-23 13:13:08 -0700438 args->map = map;
439 args->size = size;
440 post(task);
441}
442
John Reck4f02bf42014-01-03 18:09:17 -0800443void RenderProxy::post(RenderTask* task) {
444 mRenderThread.queue(task);
445}
446
447void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
448 void* retval;
449 task->setReturnPtr(&retval);
450 SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
451 AutoMutex _lock(mSyncMutex);
Chris Craik738ec3a2014-07-25 18:25:02 +0000452 mRenderThread.queue(&syncTask);
453 mSyncCondition.wait(mSyncMutex);
John Reck4f02bf42014-01-03 18:09:17 -0800454 return retval;
455}
456
John Reck0e89e2b2014-10-31 14:49:06 -0700457void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) {
458 RenderThread& thread = RenderThread::getInstance();
459 void* retval;
460 task->setReturnPtr(&retval);
461 Mutex mutex;
462 Condition condition;
463 SignalingRenderTask syncTask(task, &mutex, &condition);
464 AutoMutex _lock(mutex);
465 thread.queue(&syncTask);
466 condition.wait(mutex);
467 return retval;
468}
469
John Reck4f02bf42014-01-03 18:09:17 -0800470} /* namespace renderthread */
471} /* namespace uirenderer */
472} /* namespace android */