blob: b8388116ff80dc07cd6762d4a8f8562d97c6a185 [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
Chris Craik53e51e42015-06-01 10:35:35 -070055namespace DumpFlags {
56 enum {
57 FrameStats = 1 << 0,
58 Reset = 1 << 1,
59 };
John Reckc87be992015-02-20 10:57:22 -080060};
John Reckba6adf62015-02-19 14:36:50 -080061
John Reck119907c2014-08-14 09:02:01 -070062CREATE_BRIDGE4(createContext, RenderThread* thread, bool translucent,
63 RenderNode* rootRenderNode, IContextFactory* contextFactory) {
64 return new CanvasContext(*args->thread, args->translucent,
65 args->rootRenderNode, args->contextFactory);
John Reck4f02bf42014-01-03 18:09:17 -080066}
67
John Reck119907c2014-08-14 09:02:01 -070068RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory)
John Reck4f02bf42014-01-03 18:09:17 -080069 : mRenderThread(RenderThread::getInstance())
Chris Craikd41c4d82015-01-05 15:51:13 -080070 , mContext(nullptr) {
John Reck4f02bf42014-01-03 18:09:17 -080071 SETUP_TASK(createContext);
72 args->translucent = translucent;
John Recke45b1fd2014-04-15 09:50:16 -070073 args->rootRenderNode = rootRenderNode;
John Reck3b202512014-06-23 13:13:08 -070074 args->thread = &mRenderThread;
John Reck119907c2014-08-14 09:02:01 -070075 args->contextFactory = contextFactory;
John Reck4f02bf42014-01-03 18:09:17 -080076 mContext = (CanvasContext*) postAndWait(task);
John Reck18f16e62014-05-02 16:46:41 -070077 mDrawFrameTask.setContext(&mRenderThread, mContext);
John Reck4f02bf42014-01-03 18:09:17 -080078}
79
80RenderProxy::~RenderProxy() {
81 destroyContext();
82}
83
84CREATE_BRIDGE1(destroyContext, CanvasContext* context) {
85 delete args->context;
Chris Craikd41c4d82015-01-05 15:51:13 -080086 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080087}
88
89void RenderProxy::destroyContext() {
90 if (mContext) {
91 SETUP_TASK(destroyContext);
92 args->context = mContext;
Chris Craikd41c4d82015-01-05 15:51:13 -080093 mContext = nullptr;
94 mDrawFrameTask.setContext(nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070095 // This is also a fence as we need to be certain that there are no
96 // outstanding mDrawFrame tasks posted before it is destroyed
97 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -080098 }
99}
100
John Reck1125d1f2014-10-23 11:02:19 -0700101CREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) {
102 args->context->setSwapBehavior(args->swapBehavior);
Chris Craikd41c4d82015-01-05 15:51:13 -0800103 return nullptr;
John Reck1125d1f2014-10-23 11:02:19 -0700104}
105
106void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
107 SETUP_TASK(setSwapBehavior);
108 args->context = mContext;
109 args->swapBehavior = swapBehavior;
110 post(task);
111}
112
John Reckfe5e7b72014-05-23 17:42:28 -0700113CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) {
John Recke4280ba2014-05-05 16:39:37 -0700114 bool needsRedraw = false;
115 if (Caches::hasInstance()) {
Chris Craik2507c342015-05-04 14:36:49 -0700116 needsRedraw = Properties::load();
John Recke4280ba2014-05-05 16:39:37 -0700117 }
Chris Craik2507c342015-05-04 14:36:49 -0700118 if (args->context->profiler().consumeProperties()) {
John Reckfe5e7b72014-05-23 17:42:28 -0700119 needsRedraw = true;
120 }
John Recke4280ba2014-05-05 16:39:37 -0700121 return (void*) needsRedraw;
122}
123
124bool RenderProxy::loadSystemProperties() {
125 SETUP_TASK(loadSystemProperties);
John Reckfe5e7b72014-05-23 17:42:28 -0700126 args->context = mContext;
John Recke4280ba2014-05-05 16:39:37 -0700127 return (bool) postAndWait(task);
128}
129
John Reckb36016c2015-03-11 08:50:53 -0700130CREATE_BRIDGE2(setName, CanvasContext* context, const char* name) {
131 args->context->setName(std::string(args->name));
132 return nullptr;
133}
134
135void RenderProxy::setName(const char* name) {
136 SETUP_TASK(setName);
137 args->context = mContext;
138 args->name = name;
Chris Craik2507c342015-05-04 14:36:49 -0700139 postAndWait(task); // block since name/value pointers owned by caller
John Reckb36016c2015-03-11 08:50:53 -0700140}
141
John Recka5dda642014-05-22 15:43:54 -0700142CREATE_BRIDGE2(initialize, CanvasContext* context, ANativeWindow* window) {
John Reck4f02bf42014-01-03 18:09:17 -0800143 return (void*) args->context->initialize(args->window);
144}
145
John Reckf7d9c1d2014-04-09 10:01:03 -0700146bool RenderProxy::initialize(const sp<ANativeWindow>& window) {
John Reck4f02bf42014-01-03 18:09:17 -0800147 SETUP_TASK(initialize);
148 args->context = mContext;
John Reckf7d9c1d2014-04-09 10:01:03 -0700149 args->window = window.get();
John Reck4f02bf42014-01-03 18:09:17 -0800150 return (bool) postAndWait(task);
151}
152
John Recka5dda642014-05-22 15:43:54 -0700153CREATE_BRIDGE2(updateSurface, CanvasContext* context, ANativeWindow* window) {
John Reck4f02bf42014-01-03 18:09:17 -0800154 args->context->updateSurface(args->window);
Chris Craikd41c4d82015-01-05 15:51:13 -0800155 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800156}
157
John Reckf7d9c1d2014-04-09 10:01:03 -0700158void RenderProxy::updateSurface(const sp<ANativeWindow>& window) {
John Reck4f02bf42014-01-03 18:09:17 -0800159 SETUP_TASK(updateSurface);
160 args->context = mContext;
John Reckf7d9c1d2014-04-09 10:01:03 -0700161 args->window = window.get();
162 postAndWait(task);
163}
164
John Recka5dda642014-05-22 15:43:54 -0700165CREATE_BRIDGE2(pauseSurface, CanvasContext* context, ANativeWindow* window) {
John Reck01a5ea32014-12-03 13:01:07 -0800166 return (void*) args->context->pauseSurface(args->window);
John Reckf7d9c1d2014-04-09 10:01:03 -0700167}
168
John Reck01a5ea32014-12-03 13:01:07 -0800169bool RenderProxy::pauseSurface(const sp<ANativeWindow>& window) {
John Reckf7d9c1d2014-04-09 10:01:03 -0700170 SETUP_TASK(pauseSurface);
171 args->context = mContext;
172 args->window = window.get();
John Reck01a5ea32014-12-03 13:01:07 -0800173 return (bool) postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800174}
175
Alan Viverette50210d92015-05-14 18:05:36 -0700176CREATE_BRIDGE6(setup, CanvasContext* context, int width, int height,
177 float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
178 args->context->setup(args->width, args->height, args->lightRadius,
Chris Craik058fc642014-07-23 18:19:28 -0700179 args->ambientShadowAlpha, args->spotShadowAlpha);
Chris Craikd41c4d82015-01-05 15:51:13 -0800180 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800181}
182
Alan Viverette50210d92015-05-14 18:05:36 -0700183void RenderProxy::setup(int width, int height, float lightRadius,
John Reckb36016c2015-03-11 08:50:53 -0700184 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
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->lightRadius = lightRadius;
Chris Craik058fc642014-07-23 18:19:28 -0700190 args->ambientShadowAlpha = ambientShadowAlpha;
191 args->spotShadowAlpha = spotShadowAlpha;
John Reck4f02bf42014-01-03 18:09:17 -0800192 post(task);
193}
194
Alan Viverette50210d92015-05-14 18:05:36 -0700195CREATE_BRIDGE2(setLightCenter, CanvasContext* context, Vector3 lightCenter) {
196 args->context->setLightCenter(args->lightCenter);
197 return nullptr;
198}
199
200void RenderProxy::setLightCenter(const Vector3& lightCenter) {
201 SETUP_TASK(setLightCenter);
202 args->context = mContext;
203 args->lightCenter = lightCenter;
204 post(task);
205}
206
John Reck63a06672014-05-07 13:45:54 -0700207CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) {
208 args->context->setOpaque(args->opaque);
Chris Craikd41c4d82015-01-05 15:51:13 -0800209 return nullptr;
John Reck63a06672014-05-07 13:45:54 -0700210}
211
212void RenderProxy::setOpaque(bool opaque) {
213 SETUP_TASK(setOpaque);
214 args->context = mContext;
215 args->opaque = opaque;
216 post(task);
217}
218
John Reckba6adf62015-02-19 14:36:50 -0800219int64_t* RenderProxy::frameInfo() {
220 return mDrawFrameTask.frameInfo();
221}
222
223int RenderProxy::syncAndDrawFrame() {
224 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800225}
226
John Reck17035b02014-09-03 07:39:53 -0700227CREATE_BRIDGE1(destroy, CanvasContext* context) {
228 args->context->destroy();
Chris Craikd41c4d82015-01-05 15:51:13 -0800229 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800230}
231
John Reck17035b02014-09-03 07:39:53 -0700232void RenderProxy::destroy() {
233 SETUP_TASK(destroy);
John Reck4f02bf42014-01-03 18:09:17 -0800234 args->context = mContext;
John Reckfae904d2014-04-14 11:01:57 -0700235 // destroyCanvasAndSurface() needs a fence as when it returns the
236 // underlying BufferQueue is going to be released from under
237 // the render thread.
238 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800239}
240
John Reck3b202512014-06-23 13:13:08 -0700241CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) {
242 CanvasContext::invokeFunctor(*args->thread, args->functor);
Chris Craikd41c4d82015-01-05 15:51:13 -0800243 return nullptr;
John Reck0d1f6342014-03-28 20:30:27 -0700244}
245
246void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700247 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700248 RenderThread& thread = RenderThread::getInstance();
John Reck0d1f6342014-03-28 20:30:27 -0700249 SETUP_TASK(invokeFunctor);
John Reck3b202512014-06-23 13:13:08 -0700250 args->thread = &thread;
John Reck0d1f6342014-03-28 20:30:27 -0700251 args->functor = functor;
252 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700253 // waitForCompletion = true is expected to be fairly rare and only
254 // happen in destruction. Thus it should be fine to temporarily
255 // create a Mutex
John Reck0e89e2b2014-10-31 14:49:06 -0700256 staticPostAndWait(task);
John Reck0d1f6342014-03-28 20:30:27 -0700257 } else {
John Reck3b202512014-06-23 13:13:08 -0700258 thread.queue(task);
John Reck0d1f6342014-03-28 20:30:27 -0700259 }
260}
261
John Reckfc53ef272014-02-11 10:40:25 -0800262CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) {
263 args->context->runWithGlContext(args->task);
Chris Craikd41c4d82015-01-05 15:51:13 -0800264 return nullptr;
John Reckfc53ef272014-02-11 10:40:25 -0800265}
266
267void RenderProxy::runWithGlContext(RenderTask* gltask) {
268 SETUP_TASK(runWithGlContext);
269 args->context = mContext;
270 args->task = gltask;
271 postAndWait(task);
272}
273
John Reckc36df952015-07-29 10:09:36 -0700274CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) {
John Reck1949e792014-04-08 15:18:56 -0700275 Layer* layer = args->context->createTextureLayer();
Chris Craikd41c4d82015-01-05 15:51:13 -0800276 if (!layer) return nullptr;
John Reckc36df952015-07-29 10:09:36 -0700277 return new DeferredLayerUpdater(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800278}
279
280DeferredLayerUpdater* RenderProxy::createTextureLayer() {
281 SETUP_TASK(createTextureLayer);
John Reck1949e792014-04-08 15:18:56 -0700282 args->context = mContext;
John Reck19b6bcf2014-02-14 20:03:38 -0800283 void* retval = postAndWait(task);
284 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval);
John Reck19b6bcf2014-02-14 20:03:38 -0800285 return layer;
286}
287
John Reck3e824952014-08-20 10:08:39 -0700288CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) {
289 args->context->buildLayer(args->node);
Chris Craikd41c4d82015-01-05 15:51:13 -0800290 return nullptr;
John Reck3e824952014-08-20 10:08:39 -0700291}
292
293void RenderProxy::buildLayer(RenderNode* node) {
294 SETUP_TASK(buildLayer);
295 args->context = mContext;
296 args->node = node;
297 postAndWait(task);
298}
299
John Reck19b6bcf2014-02-14 20:03:38 -0800300CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer,
301 SkBitmap* bitmap) {
302 bool success = args->context->copyLayerInto(args->layer, args->bitmap);
303 return (void*) success;
304}
305
John Reck3731dc22015-04-13 15:20:29 -0700306bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
John Reck19b6bcf2014-02-14 20:03:38 -0800307 SETUP_TASK(copyLayerInto);
308 args->context = mContext;
309 args->layer = layer;
John Reck3731dc22015-04-13 15:20:29 -0700310 args->bitmap = &bitmap;
John Reck19b6bcf2014-02-14 20:03:38 -0800311 return (bool) postAndWait(task);
312}
313
John Reckd72e0a32014-05-29 18:56:11 -0700314void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
315 mDrawFrameTask.pushLayerUpdate(layer);
316}
317
318void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
319 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800320}
321
John Reck918ad522014-06-27 14:45:25 -0700322CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) {
323 args->layer->detachSurfaceTexture();
Chris Craikd41c4d82015-01-05 15:51:13 -0800324 return nullptr;
John Reck918ad522014-06-27 14:45:25 -0700325}
326
327void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
328 SETUP_TASK(detachSurfaceTexture);
329 args->layer = layer;
330 postAndWait(task);
331}
332
John Reckf47a5942014-06-30 16:20:04 -0700333CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) {
334 args->context->destroyHardwareResources();
Chris Craikd41c4d82015-01-05 15:51:13 -0800335 return nullptr;
John Recke1628b72014-05-23 15:11:19 -0700336}
337
John Reckf47a5942014-06-30 16:20:04 -0700338void RenderProxy::destroyHardwareResources() {
339 SETUP_TASK(destroyHardwareResources);
John Recke1628b72014-05-23 15:11:19 -0700340 args->context = mContext;
John Recke1628b72014-05-23 15:11:19 -0700341 post(task);
342}
343
Chris Craik2507c342015-05-04 14:36:49 -0700344CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) {
John Reckf47a5942014-06-30 16:20:04 -0700345 CanvasContext::trimMemory(*args->thread, args->level);
Chris Craikd41c4d82015-01-05 15:51:13 -0800346 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700347}
348
349void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700350 // Avoid creating a RenderThread to do a trimMemory.
351 if (RenderThread::hasInstance()) {
352 RenderThread& thread = RenderThread::getInstance();
Chris Craik2507c342015-05-04 14:36:49 -0700353 SETUP_TASK(trimMemory);
John Reckcd3a22c2014-08-06 13:33:59 -0700354 args->thread = &thread;
355 args->level = level;
356 thread.queue(task);
357 }
John Reckf47a5942014-06-30 16:20:04 -0700358}
359
Chris Craik2507c342015-05-04 14:36:49 -0700360CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) {
361 Properties::overrideProperty(args->name, args->value);
362 return nullptr;
363}
364
365void RenderProxy::overrideProperty(const char* name, const char* value) {
Chris Craik2507c342015-05-04 14:36:49 -0700366 SETUP_TASK(overrideProperty);
367 args->name = name;
368 args->value = value;
369 staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller
370}
371
John Reck28ad7b52014-04-07 16:59:25 -0700372CREATE_BRIDGE0(fence) {
373 // Intentionally empty
Chris Craikd41c4d82015-01-05 15:51:13 -0800374 return nullptr;
John Reck28ad7b52014-04-07 16:59:25 -0700375}
376
Andreas Gampe64bb4132014-11-22 00:35:09 +0000377template <typename T>
378void UNUSED(T t) {}
379
John Reck28ad7b52014-04-07 16:59:25 -0700380void RenderProxy::fence() {
381 SETUP_TASK(fence);
Andreas Gampe1e196742014-11-10 15:23:43 -0800382 UNUSED(args);
John Reck28ad7b52014-04-07 16:59:25 -0700383 postAndWait(task);
384}
385
John Reckf47a5942014-06-30 16:20:04 -0700386CREATE_BRIDGE1(stopDrawing, CanvasContext* context) {
387 args->context->stopDrawing();
Chris Craikd41c4d82015-01-05 15:51:13 -0800388 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700389}
390
391void RenderProxy::stopDrawing() {
392 SETUP_TASK(stopDrawing);
393 args->context = mContext;
394 postAndWait(task);
395}
396
John Recka5dda642014-05-22 15:43:54 -0700397CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) {
398 args->context->notifyFramePending();
Chris Craikd41c4d82015-01-05 15:51:13 -0800399 return nullptr;
John Recka5dda642014-05-22 15:43:54 -0700400}
401
402void RenderProxy::notifyFramePending() {
403 SETUP_TASK(notifyFramePending);
404 args->context = mContext;
405 mRenderThread.queueAtFront(task);
406}
407
John Reck7f2e5e32015-05-05 11:00:53 -0700408CREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread,
409 int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700410 args->context->profiler().dumpData(args->fd);
John Reck7f2e5e32015-05-05 11:00:53 -0700411 args->thread->jankTracker().dump(args->fd);
Chris Craik53e51e42015-06-01 10:35:35 -0700412 if (args->dumpFlags & DumpFlags::FrameStats) {
John Reckba6adf62015-02-19 14:36:50 -0800413 args->context->dumpFrames(args->fd);
414 }
Chris Craik53e51e42015-06-01 10:35:35 -0700415 if (args->dumpFlags & DumpFlags::Reset) {
John Reckba6adf62015-02-19 14:36:50 -0800416 args->context->resetFrameStats();
417 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800418 return nullptr;
John Reckfe5e7b72014-05-23 17:42:28 -0700419}
420
John Reckba6adf62015-02-19 14:36:50 -0800421void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700422 SETUP_TASK(dumpProfileInfo);
423 args->context = mContext;
John Reck7f2e5e32015-05-05 11:00:53 -0700424 args->thread = &mRenderThread;
John Reckfe5e7b72014-05-23 17:42:28 -0700425 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800426 args->dumpFlags = dumpFlags;
John Reckfe5e7b72014-05-23 17:42:28 -0700427 postAndWait(task);
428}
429
John Reck7f2e5e32015-05-05 11:00:53 -0700430CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) {
431 args->context->resetFrameStats();
432 return nullptr;
433}
434
435void RenderProxy::resetProfileInfo() {
436 SETUP_TASK(resetProfileInfo);
437 args->context = mContext;
438 postAndWait(task);
439}
440
John Reckba6adf62015-02-19 14:36:50 -0800441CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) {
442 args->thread->jankTracker().dump(args->fd);
443
Chris Craik2ae07332015-01-21 14:22:39 -0800444 FILE *file = fdopen(args->fd, "a");
445 if (Caches::hasInstance()) {
446 String8 cachesLog;
447 Caches::getInstance().dumpMemoryUsage(cachesLog);
448 fprintf(file, "\nCaches:\n%s\n", cachesLog.string());
449 } else {
450 fprintf(file, "\nNo caches instance.\n");
451 }
452 fflush(file);
Chris Craikd41c4d82015-01-05 15:51:13 -0800453 return nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700454}
455
Chris Craik2ae07332015-01-21 14:22:39 -0800456void RenderProxy::dumpGraphicsMemory(int fd) {
youngmin0822.leec80c9ad2015-03-20 21:22:32 +0900457 if (!RenderThread::hasInstance()) return;
Chris Craik2ae07332015-01-21 14:22:39 -0800458 SETUP_TASK(dumpGraphicsMemory);
John Reck0e89e2b2014-10-31 14:49:06 -0700459 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800460 args->thread = &RenderThread::getInstance();
John Reck0e89e2b2014-10-31 14:49:06 -0700461 staticPostAndWait(task);
462}
463
John Reck3b202512014-06-23 13:13:08 -0700464CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map, size_t size) {
465 CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size);
Chris Craikd41c4d82015-01-05 15:51:13 -0800466 args->buffer->decStrong(nullptr);
467 return nullptr;
John Reck3b202512014-06-23 13:13:08 -0700468}
469
470void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) {
471 SETUP_TASK(setTextureAtlas);
472 args->thread = &mRenderThread;
473 args->buffer = buffer.get();
Chris Craikd41c4d82015-01-05 15:51:13 -0800474 args->buffer->incStrong(nullptr);
John Reck3b202512014-06-23 13:13:08 -0700475 args->map = map;
476 args->size = size;
477 post(task);
478}
479
John Reckedc524c2015-03-18 15:24:33 -0700480CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) {
481 args->thread->jankTracker().switchStorageToAshmem(args->fd);
482 close(args->fd);
483 return nullptr;
484}
485
486void RenderProxy::setProcessStatsBuffer(int fd) {
487 SETUP_TASK(setProcessStatsBuffer);
488 args->thread = &mRenderThread;
489 args->fd = dup(fd);
490 post(task);
491}
492
John Recke248bd12015-08-05 13:53:53 -0700493CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) {
494 args->context->serializeDisplayListTree();
495 return nullptr;
496}
497
498void RenderProxy::serializeDisplayListTree() {
499 SETUP_TASK(serializeDisplayListTree);
500 args->context = mContext;
501 post(task);
502}
503
John Reck4f02bf42014-01-03 18:09:17 -0800504void RenderProxy::post(RenderTask* task) {
505 mRenderThread.queue(task);
506}
507
508void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
509 void* retval;
510 task->setReturnPtr(&retval);
511 SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
512 AutoMutex _lock(mSyncMutex);
Chris Craik738ec3a2014-07-25 18:25:02 +0000513 mRenderThread.queue(&syncTask);
514 mSyncCondition.wait(mSyncMutex);
John Reck4f02bf42014-01-03 18:09:17 -0800515 return retval;
516}
517
John Reck0e89e2b2014-10-31 14:49:06 -0700518void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) {
519 RenderThread& thread = RenderThread::getInstance();
520 void* retval;
521 task->setReturnPtr(&retval);
522 Mutex mutex;
523 Condition condition;
524 SignalingRenderTask syncTask(task, &mutex, &condition);
525 AutoMutex _lock(mutex);
526 thread.queue(&syncTask);
527 condition.wait(mutex);
528 return retval;
529}
530
John Reck4f02bf42014-01-03 18:09:17 -0800531} /* namespace renderthread */
532} /* namespace uirenderer */
533} /* namespace android */