blob: 060b83de7427a78c65a8d2216a876468027ed4cf [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 Reck119907c2014-08-14 09:02:01 -070055CREATE_BRIDGE4(createContext, RenderThread* thread, bool translucent,
56 RenderNode* rootRenderNode, IContextFactory* contextFactory) {
57 return new CanvasContext(*args->thread, args->translucent,
58 args->rootRenderNode, args->contextFactory);
John Reck4f02bf42014-01-03 18:09:17 -080059}
60
John Reck119907c2014-08-14 09:02:01 -070061RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory)
John Reck4f02bf42014-01-03 18:09:17 -080062 : mRenderThread(RenderThread::getInstance())
Chris Craikd41c4d82015-01-05 15:51:13 -080063 , mContext(nullptr) {
John Reck4f02bf42014-01-03 18:09:17 -080064 SETUP_TASK(createContext);
65 args->translucent = translucent;
John Recke45b1fd2014-04-15 09:50:16 -070066 args->rootRenderNode = rootRenderNode;
John Reck3b202512014-06-23 13:13:08 -070067 args->thread = &mRenderThread;
John Reck119907c2014-08-14 09:02:01 -070068 args->contextFactory = contextFactory;
John Reck4f02bf42014-01-03 18:09:17 -080069 mContext = (CanvasContext*) postAndWait(task);
Skuhneea7a7fb2015-08-28 07:10:31 -070070 mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode);
John Reck4f02bf42014-01-03 18:09:17 -080071}
72
73RenderProxy::~RenderProxy() {
74 destroyContext();
75}
76
77CREATE_BRIDGE1(destroyContext, CanvasContext* context) {
78 delete args->context;
Chris Craikd41c4d82015-01-05 15:51:13 -080079 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080080}
81
82void RenderProxy::destroyContext() {
83 if (mContext) {
84 SETUP_TASK(destroyContext);
85 args->context = mContext;
Chris Craikd41c4d82015-01-05 15:51:13 -080086 mContext = nullptr;
Skuhneea7a7fb2015-08-28 07:10:31 -070087 mDrawFrameTask.setContext(nullptr, nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070088 // This is also a fence as we need to be certain that there are no
89 // outstanding mDrawFrame tasks posted before it is destroyed
90 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -080091 }
92}
93
John Reck1125d1f2014-10-23 11:02:19 -070094CREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) {
95 args->context->setSwapBehavior(args->swapBehavior);
Chris Craikd41c4d82015-01-05 15:51:13 -080096 return nullptr;
John Reck1125d1f2014-10-23 11:02:19 -070097}
98
99void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
100 SETUP_TASK(setSwapBehavior);
101 args->context = mContext;
102 args->swapBehavior = swapBehavior;
103 post(task);
104}
105
John Reckfe5e7b72014-05-23 17:42:28 -0700106CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) {
John Recke4280ba2014-05-05 16:39:37 -0700107 bool needsRedraw = false;
108 if (Caches::hasInstance()) {
Chris Craik2507c342015-05-04 14:36:49 -0700109 needsRedraw = Properties::load();
John Recke4280ba2014-05-05 16:39:37 -0700110 }
Chris Craik2507c342015-05-04 14:36:49 -0700111 if (args->context->profiler().consumeProperties()) {
John Reckfe5e7b72014-05-23 17:42:28 -0700112 needsRedraw = true;
113 }
John Recke4280ba2014-05-05 16:39:37 -0700114 return (void*) needsRedraw;
115}
116
117bool RenderProxy::loadSystemProperties() {
118 SETUP_TASK(loadSystemProperties);
John Reckfe5e7b72014-05-23 17:42:28 -0700119 args->context = mContext;
John Recke4280ba2014-05-05 16:39:37 -0700120 return (bool) postAndWait(task);
121}
122
John Reckb36016c2015-03-11 08:50:53 -0700123CREATE_BRIDGE2(setName, CanvasContext* context, const char* name) {
124 args->context->setName(std::string(args->name));
125 return nullptr;
126}
127
128void RenderProxy::setName(const char* name) {
129 SETUP_TASK(setName);
130 args->context = mContext;
131 args->name = name;
Chris Craik2507c342015-05-04 14:36:49 -0700132 postAndWait(task); // block since name/value pointers owned by caller
John Reckb36016c2015-03-11 08:50:53 -0700133}
134
John Reckf6481082016-02-02 15:18:23 -0800135CREATE_BRIDGE2(initialize, CanvasContext* context, Surface* surface) {
136 args->context->initialize(args->surface);
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100137 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800138}
139
John Reckf6481082016-02-02 15:18:23 -0800140void RenderProxy::initialize(const sp<Surface>& surface) {
John Reck4f02bf42014-01-03 18:09:17 -0800141 SETUP_TASK(initialize);
142 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800143 args->surface = surface.get();
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100144 post(task);
John Reck4f02bf42014-01-03 18:09:17 -0800145}
146
John Reckf6481082016-02-02 15:18:23 -0800147CREATE_BRIDGE2(updateSurface, CanvasContext* context, Surface* surface) {
148 args->context->updateSurface(args->surface);
Chris Craikd41c4d82015-01-05 15:51:13 -0800149 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800150}
151
John Reckf6481082016-02-02 15:18:23 -0800152void RenderProxy::updateSurface(const sp<Surface>& surface) {
John Reck4f02bf42014-01-03 18:09:17 -0800153 SETUP_TASK(updateSurface);
154 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800155 args->surface = surface.get();
John Reckf7d9c1d2014-04-09 10:01:03 -0700156 postAndWait(task);
157}
158
John Reckf6481082016-02-02 15:18:23 -0800159CREATE_BRIDGE2(pauseSurface, CanvasContext* context, Surface* surface) {
160 return (void*) args->context->pauseSurface(args->surface);
John Reckf7d9c1d2014-04-09 10:01:03 -0700161}
162
John Reckf6481082016-02-02 15:18:23 -0800163bool RenderProxy::pauseSurface(const sp<Surface>& surface) {
John Reckf7d9c1d2014-04-09 10:01:03 -0700164 SETUP_TASK(pauseSurface);
165 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800166 args->surface = surface.get();
John Reck01a5ea32014-12-03 13:01:07 -0800167 return (bool) postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800168}
169
Alan Viverette50210d92015-05-14 18:05:36 -0700170CREATE_BRIDGE6(setup, CanvasContext* context, int width, int height,
171 float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
172 args->context->setup(args->width, args->height, args->lightRadius,
Chris Craik058fc642014-07-23 18:19:28 -0700173 args->ambientShadowAlpha, args->spotShadowAlpha);
Chris Craikd41c4d82015-01-05 15:51:13 -0800174 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800175}
176
Alan Viverette50210d92015-05-14 18:05:36 -0700177void RenderProxy::setup(int width, int height, float lightRadius,
John Reckb36016c2015-03-11 08:50:53 -0700178 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
John Reck4f02bf42014-01-03 18:09:17 -0800179 SETUP_TASK(setup);
180 args->context = mContext;
181 args->width = width;
182 args->height = height;
Chris Craik797b95b2014-05-20 18:10:25 -0700183 args->lightRadius = lightRadius;
Chris Craik058fc642014-07-23 18:19:28 -0700184 args->ambientShadowAlpha = ambientShadowAlpha;
185 args->spotShadowAlpha = spotShadowAlpha;
John Reck4f02bf42014-01-03 18:09:17 -0800186 post(task);
187}
188
Alan Viverette50210d92015-05-14 18:05:36 -0700189CREATE_BRIDGE2(setLightCenter, CanvasContext* context, Vector3 lightCenter) {
190 args->context->setLightCenter(args->lightCenter);
191 return nullptr;
192}
193
194void RenderProxy::setLightCenter(const Vector3& lightCenter) {
195 SETUP_TASK(setLightCenter);
196 args->context = mContext;
197 args->lightCenter = lightCenter;
198 post(task);
199}
200
John Reck63a06672014-05-07 13:45:54 -0700201CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) {
202 args->context->setOpaque(args->opaque);
Chris Craikd41c4d82015-01-05 15:51:13 -0800203 return nullptr;
John Reck63a06672014-05-07 13:45:54 -0700204}
205
206void RenderProxy::setOpaque(bool opaque) {
207 SETUP_TASK(setOpaque);
208 args->context = mContext;
209 args->opaque = opaque;
210 post(task);
211}
212
John Reckba6adf62015-02-19 14:36:50 -0800213int64_t* RenderProxy::frameInfo() {
214 return mDrawFrameTask.frameInfo();
215}
216
217int RenderProxy::syncAndDrawFrame() {
218 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800219}
220
John Reck17035b02014-09-03 07:39:53 -0700221CREATE_BRIDGE1(destroy, CanvasContext* context) {
222 args->context->destroy();
Chris Craikd41c4d82015-01-05 15:51:13 -0800223 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800224}
225
John Reck17035b02014-09-03 07:39:53 -0700226void RenderProxy::destroy() {
227 SETUP_TASK(destroy);
John Reck4f02bf42014-01-03 18:09:17 -0800228 args->context = mContext;
John Reckfae904d2014-04-14 11:01:57 -0700229 // destroyCanvasAndSurface() needs a fence as when it returns the
230 // underlying BufferQueue is going to be released from under
231 // the render thread.
232 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800233}
234
John Reck3b202512014-06-23 13:13:08 -0700235CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) {
236 CanvasContext::invokeFunctor(*args->thread, args->functor);
Chris Craikd41c4d82015-01-05 15:51:13 -0800237 return nullptr;
John Reck0d1f6342014-03-28 20:30:27 -0700238}
239
240void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700241 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700242 RenderThread& thread = RenderThread::getInstance();
John Reck0d1f6342014-03-28 20:30:27 -0700243 SETUP_TASK(invokeFunctor);
John Reck3b202512014-06-23 13:13:08 -0700244 args->thread = &thread;
John Reck0d1f6342014-03-28 20:30:27 -0700245 args->functor = functor;
246 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700247 // waitForCompletion = true is expected to be fairly rare and only
248 // happen in destruction. Thus it should be fine to temporarily
249 // create a Mutex
John Reck0e89e2b2014-10-31 14:49:06 -0700250 staticPostAndWait(task);
John Reck0d1f6342014-03-28 20:30:27 -0700251 } else {
John Reck3b202512014-06-23 13:13:08 -0700252 thread.queue(task);
John Reck0d1f6342014-03-28 20:30:27 -0700253 }
254}
255
John Reckfc53ef272014-02-11 10:40:25 -0800256CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) {
257 args->context->runWithGlContext(args->task);
Chris Craikd41c4d82015-01-05 15:51:13 -0800258 return nullptr;
John Reckfc53ef272014-02-11 10:40:25 -0800259}
260
261void RenderProxy::runWithGlContext(RenderTask* gltask) {
262 SETUP_TASK(runWithGlContext);
263 args->context = mContext;
264 args->task = gltask;
265 postAndWait(task);
266}
267
John Reckc36df952015-07-29 10:09:36 -0700268CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) {
John Reck1949e792014-04-08 15:18:56 -0700269 Layer* layer = args->context->createTextureLayer();
Chris Craikd41c4d82015-01-05 15:51:13 -0800270 if (!layer) return nullptr;
John Reckc36df952015-07-29 10:09:36 -0700271 return new DeferredLayerUpdater(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800272}
273
274DeferredLayerUpdater* RenderProxy::createTextureLayer() {
275 SETUP_TASK(createTextureLayer);
John Reck1949e792014-04-08 15:18:56 -0700276 args->context = mContext;
John Reck19b6bcf2014-02-14 20:03:38 -0800277 void* retval = postAndWait(task);
278 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval);
John Reck19b6bcf2014-02-14 20:03:38 -0800279 return layer;
280}
281
John Reck3e824952014-08-20 10:08:39 -0700282CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) {
283 args->context->buildLayer(args->node);
Chris Craikd41c4d82015-01-05 15:51:13 -0800284 return nullptr;
John Reck3e824952014-08-20 10:08:39 -0700285}
286
287void RenderProxy::buildLayer(RenderNode* node) {
288 SETUP_TASK(buildLayer);
289 args->context = mContext;
290 args->node = node;
291 postAndWait(task);
292}
293
John Reck19b6bcf2014-02-14 20:03:38 -0800294CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer,
295 SkBitmap* bitmap) {
296 bool success = args->context->copyLayerInto(args->layer, args->bitmap);
297 return (void*) success;
298}
299
John Reck3731dc22015-04-13 15:20:29 -0700300bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
John Reck19b6bcf2014-02-14 20:03:38 -0800301 SETUP_TASK(copyLayerInto);
302 args->context = mContext;
303 args->layer = layer;
John Reck3731dc22015-04-13 15:20:29 -0700304 args->bitmap = &bitmap;
John Reck19b6bcf2014-02-14 20:03:38 -0800305 return (bool) postAndWait(task);
306}
307
John Reckd72e0a32014-05-29 18:56:11 -0700308void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
309 mDrawFrameTask.pushLayerUpdate(layer);
310}
311
312void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
313 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800314}
315
John Reck918ad522014-06-27 14:45:25 -0700316CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) {
317 args->layer->detachSurfaceTexture();
Chris Craikd41c4d82015-01-05 15:51:13 -0800318 return nullptr;
John Reck918ad522014-06-27 14:45:25 -0700319}
320
321void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
322 SETUP_TASK(detachSurfaceTexture);
323 args->layer = layer;
324 postAndWait(task);
325}
326
John Reckf47a5942014-06-30 16:20:04 -0700327CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) {
328 args->context->destroyHardwareResources();
Chris Craikd41c4d82015-01-05 15:51:13 -0800329 return nullptr;
John Recke1628b72014-05-23 15:11:19 -0700330}
331
John Reckf47a5942014-06-30 16:20:04 -0700332void RenderProxy::destroyHardwareResources() {
333 SETUP_TASK(destroyHardwareResources);
John Recke1628b72014-05-23 15:11:19 -0700334 args->context = mContext;
John Recke1628b72014-05-23 15:11:19 -0700335 post(task);
336}
337
Chris Craik2507c342015-05-04 14:36:49 -0700338CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) {
John Reckf47a5942014-06-30 16:20:04 -0700339 CanvasContext::trimMemory(*args->thread, args->level);
Chris Craikd41c4d82015-01-05 15:51:13 -0800340 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700341}
342
343void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700344 // Avoid creating a RenderThread to do a trimMemory.
345 if (RenderThread::hasInstance()) {
346 RenderThread& thread = RenderThread::getInstance();
Chris Craik2507c342015-05-04 14:36:49 -0700347 SETUP_TASK(trimMemory);
John Reckcd3a22c2014-08-06 13:33:59 -0700348 args->thread = &thread;
349 args->level = level;
350 thread.queue(task);
351 }
John Reckf47a5942014-06-30 16:20:04 -0700352}
353
Chris Craik2507c342015-05-04 14:36:49 -0700354CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) {
355 Properties::overrideProperty(args->name, args->value);
356 return nullptr;
357}
358
359void RenderProxy::overrideProperty(const char* name, const char* value) {
Chris Craik2507c342015-05-04 14:36:49 -0700360 SETUP_TASK(overrideProperty);
361 args->name = name;
362 args->value = value;
363 staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller
364}
365
John Reck28ad7b52014-04-07 16:59:25 -0700366CREATE_BRIDGE0(fence) {
367 // Intentionally empty
Chris Craikd41c4d82015-01-05 15:51:13 -0800368 return nullptr;
John Reck28ad7b52014-04-07 16:59:25 -0700369}
370
Andreas Gampe64bb4132014-11-22 00:35:09 +0000371template <typename T>
372void UNUSED(T t) {}
373
John Reck28ad7b52014-04-07 16:59:25 -0700374void RenderProxy::fence() {
375 SETUP_TASK(fence);
Andreas Gampe1e196742014-11-10 15:23:43 -0800376 UNUSED(args);
John Reck28ad7b52014-04-07 16:59:25 -0700377 postAndWait(task);
378}
379
Thomas Buhotc0a0e1a2016-01-18 10:31:58 +0100380void RenderProxy::staticFence() {
381 SETUP_TASK(fence);
382 UNUSED(args);
383 staticPostAndWait(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);
Chris Craik53e51e42015-06-01 10:35:35 -0700411 if (args->dumpFlags & DumpFlags::FrameStats) {
John Reckba6adf62015-02-19 14:36:50 -0800412 args->context->dumpFrames(args->fd);
413 }
Chris Craik53e51e42015-06-01 10:35:35 -0700414 if (args->dumpFlags & DumpFlags::Reset) {
John Reckba6adf62015-02-19 14:36:50 -0800415 args->context->resetFrameStats();
416 }
John Recka41f2442016-04-07 16:36:57 -0700417 if (args->dumpFlags & DumpFlags::JankStats) {
418 args->thread->jankTracker().dump(args->fd);
419 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800420 return nullptr;
John Reckfe5e7b72014-05-23 17:42:28 -0700421}
422
John Reckba6adf62015-02-19 14:36:50 -0800423void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700424 SETUP_TASK(dumpProfileInfo);
425 args->context = mContext;
John Reck7f2e5e32015-05-05 11:00:53 -0700426 args->thread = &mRenderThread;
John Reckfe5e7b72014-05-23 17:42:28 -0700427 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800428 args->dumpFlags = dumpFlags;
John Reckfe5e7b72014-05-23 17:42:28 -0700429 postAndWait(task);
430}
431
John Reck7f2e5e32015-05-05 11:00:53 -0700432CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) {
433 args->context->resetFrameStats();
434 return nullptr;
435}
436
437void RenderProxy::resetProfileInfo() {
438 SETUP_TASK(resetProfileInfo);
439 args->context = mContext;
440 postAndWait(task);
441}
442
John Reckba6adf62015-02-19 14:36:50 -0800443CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) {
444 args->thread->jankTracker().dump(args->fd);
445
Chris Craik2ae07332015-01-21 14:22:39 -0800446 FILE *file = fdopen(args->fd, "a");
447 if (Caches::hasInstance()) {
448 String8 cachesLog;
449 Caches::getInstance().dumpMemoryUsage(cachesLog);
450 fprintf(file, "\nCaches:\n%s\n", cachesLog.string());
451 } else {
452 fprintf(file, "\nNo caches instance.\n");
453 }
Chris Craikff3edce2016-01-14 10:04:08 -0800454#if HWUI_NEW_OPS
455 fprintf(file, "\nPipeline=FrameBuilder\n");
456#else
457 fprintf(file, "\nPipeline=OpenGLRenderer\n");
458#endif
Chris Craik2ae07332015-01-21 14:22:39 -0800459 fflush(file);
Chris Craikd41c4d82015-01-05 15:51:13 -0800460 return nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700461}
462
Chris Craik2ae07332015-01-21 14:22:39 -0800463void RenderProxy::dumpGraphicsMemory(int fd) {
youngmin0822.leec80c9ad2015-03-20 21:22:32 +0900464 if (!RenderThread::hasInstance()) return;
Chris Craik2ae07332015-01-21 14:22:39 -0800465 SETUP_TASK(dumpGraphicsMemory);
John Reck0e89e2b2014-10-31 14:49:06 -0700466 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800467 args->thread = &RenderThread::getInstance();
John Reck0e89e2b2014-10-31 14:49:06 -0700468 staticPostAndWait(task);
469}
470
Skuhneea7a7fb2015-08-28 07:10:31 -0700471CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map,
472 size_t size) {
John Reck3b202512014-06-23 13:13:08 -0700473 CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size);
Chris Craikd41c4d82015-01-05 15:51:13 -0800474 args->buffer->decStrong(nullptr);
475 return nullptr;
John Reck3b202512014-06-23 13:13:08 -0700476}
477
478void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) {
479 SETUP_TASK(setTextureAtlas);
480 args->thread = &mRenderThread;
481 args->buffer = buffer.get();
Chris Craikd41c4d82015-01-05 15:51:13 -0800482 args->buffer->incStrong(nullptr);
John Reck3b202512014-06-23 13:13:08 -0700483 args->map = map;
484 args->size = size;
485 post(task);
486}
487
John Reckedc524c2015-03-18 15:24:33 -0700488CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) {
489 args->thread->jankTracker().switchStorageToAshmem(args->fd);
490 close(args->fd);
491 return nullptr;
492}
493
494void RenderProxy::setProcessStatsBuffer(int fd) {
495 SETUP_TASK(setProcessStatsBuffer);
496 args->thread = &mRenderThread;
497 args->fd = dup(fd);
498 post(task);
499}
500
Skuhneea7a7fb2015-08-28 07:10:31 -0700501CREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) {
502 args->context->addRenderNode(args->node, args->placeFront);
503 return nullptr;
504}
505
506void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) {
507 SETUP_TASK(addRenderNode);
508 args->context = mContext;
509 args->node = node;
510 args->placeFront = placeFront;
511 post(task);
512}
513
514CREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) {
515 args->context->removeRenderNode(args->node);
516 return nullptr;
517}
518
519void RenderProxy::removeRenderNode(RenderNode* node) {
520 SETUP_TASK(removeRenderNode);
521 args->context = mContext;
522 args->node = node;
523 post(task);
524}
525
526CREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) {
527 args->context->prepareAndDraw(args->node);
528 return nullptr;
529}
530
531void RenderProxy::drawRenderNode(RenderNode* node) {
532 SETUP_TASK(drawRenderNode);
533 args->context = mContext;
534 args->node = node;
535 // Be pseudo-thread-safe and don't use any member variables
536 staticPostAndWait(task);
537}
538
Skuhneb8160872015-09-22 09:51:39 -0700539CREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top,
Skuhneea7a7fb2015-08-28 07:10:31 -0700540 int right, int bottom) {
Skuhneb8160872015-09-22 09:51:39 -0700541 args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700542 return nullptr;
543}
544
Skuhneb8160872015-09-22 09:51:39 -0700545void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) {
546 SETUP_TASK(setContentDrawBounds);
Skuhneea7a7fb2015-08-28 07:10:31 -0700547 args->context = mContext;
548 args->left = left;
549 args->top = top;
550 args->right = right;
551 args->bottom = bottom;
552 staticPostAndWait(task);
553}
554
John Recke248bd12015-08-05 13:53:53 -0700555CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) {
556 args->context->serializeDisplayListTree();
557 return nullptr;
558}
559
560void RenderProxy::serializeDisplayListTree() {
561 SETUP_TASK(serializeDisplayListTree);
562 args->context = mContext;
563 post(task);
564}
565
Andres Morales910beb82016-02-02 16:19:40 -0800566CREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context,
567 FrameMetricsObserver* frameStatsObserver) {
568 args->context->addFrameMetricsObserver(args->frameStatsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800569 if (args->frameStatsObserver != nullptr) {
570 args->frameStatsObserver->decStrong(args->context);
571 }
572 return nullptr;
573}
574
Andres Morales910beb82016-02-02 16:19:40 -0800575void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) {
576 SETUP_TASK(addFrameMetricsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800577 args->context = mContext;
578 args->frameStatsObserver = observer;
579 if (observer != nullptr) {
580 observer->incStrong(mContext);
581 }
582 post(task);
583}
584
Andres Morales910beb82016-02-02 16:19:40 -0800585CREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context,
586 FrameMetricsObserver* frameStatsObserver) {
587 args->context->removeFrameMetricsObserver(args->frameStatsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800588 if (args->frameStatsObserver != nullptr) {
589 args->frameStatsObserver->decStrong(args->context);
590 }
591 return nullptr;
592}
593
Andres Morales910beb82016-02-02 16:19:40 -0800594void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) {
595 SETUP_TASK(removeFrameMetricsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800596 args->context = mContext;
597 args->frameStatsObserver = observer;
598 if (observer != nullptr) {
599 observer->incStrong(mContext);
600 }
601 post(task);
602}
603
John Reck4f02bf42014-01-03 18:09:17 -0800604void RenderProxy::post(RenderTask* task) {
605 mRenderThread.queue(task);
606}
607
608void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
609 void* retval;
610 task->setReturnPtr(&retval);
John Reckcba287b2015-11-10 12:52:44 -0800611 SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
612 AutoMutex _lock(mSyncMutex);
613 mRenderThread.queue(&syncTask);
614 mSyncCondition.wait(mSyncMutex);
John Reck4f02bf42014-01-03 18:09:17 -0800615 return retval;
616}
617
John Reck0e89e2b2014-10-31 14:49:06 -0700618void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) {
619 RenderThread& thread = RenderThread::getInstance();
620 void* retval;
621 task->setReturnPtr(&retval);
Chris Craik0a24b142015-10-19 17:10:19 -0700622 thread.queueAndWait(task);
John Reck0e89e2b2014-10-31 14:49:06 -0700623 return retval;
624}
625
John Reck4f02bf42014-01-03 18:09:17 -0800626} /* namespace renderthread */
627} /* namespace uirenderer */
628} /* namespace android */