blob: 04223a7d51889d30025ccc1478699ed71eb47a5a [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);
Skuhneea7a7fb2015-08-28 07:10:31 -070077 mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode);
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;
Skuhneea7a7fb2015-08-28 07:10:31 -070094 mDrawFrameTask.setContext(nullptr, 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 Reckf6481082016-02-02 15:18:23 -0800142CREATE_BRIDGE2(initialize, CanvasContext* context, Surface* surface) {
143 args->context->initialize(args->surface);
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100144 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800145}
146
John Reckf6481082016-02-02 15:18:23 -0800147void RenderProxy::initialize(const sp<Surface>& surface) {
John Reck4f02bf42014-01-03 18:09:17 -0800148 SETUP_TASK(initialize);
149 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800150 args->surface = surface.get();
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100151 post(task);
John Reck4f02bf42014-01-03 18:09:17 -0800152}
153
John Reckf6481082016-02-02 15:18:23 -0800154CREATE_BRIDGE2(updateSurface, CanvasContext* context, Surface* surface) {
155 args->context->updateSurface(args->surface);
Chris Craikd41c4d82015-01-05 15:51:13 -0800156 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800157}
158
John Reckf6481082016-02-02 15:18:23 -0800159void RenderProxy::updateSurface(const sp<Surface>& surface) {
John Reck4f02bf42014-01-03 18:09:17 -0800160 SETUP_TASK(updateSurface);
161 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800162 args->surface = surface.get();
John Reckf7d9c1d2014-04-09 10:01:03 -0700163 postAndWait(task);
164}
165
John Reckf6481082016-02-02 15:18:23 -0800166CREATE_BRIDGE2(pauseSurface, CanvasContext* context, Surface* surface) {
167 return (void*) args->context->pauseSurface(args->surface);
John Reckf7d9c1d2014-04-09 10:01:03 -0700168}
169
John Reckf6481082016-02-02 15:18:23 -0800170bool RenderProxy::pauseSurface(const sp<Surface>& surface) {
John Reckf7d9c1d2014-04-09 10:01:03 -0700171 SETUP_TASK(pauseSurface);
172 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800173 args->surface = surface.get();
John Reck01a5ea32014-12-03 13:01:07 -0800174 return (bool) postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800175}
176
Alan Viverette50210d92015-05-14 18:05:36 -0700177CREATE_BRIDGE6(setup, CanvasContext* context, int width, int height,
178 float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
179 args->context->setup(args->width, args->height, args->lightRadius,
Chris Craik058fc642014-07-23 18:19:28 -0700180 args->ambientShadowAlpha, args->spotShadowAlpha);
Chris Craikd41c4d82015-01-05 15:51:13 -0800181 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800182}
183
Alan Viverette50210d92015-05-14 18:05:36 -0700184void RenderProxy::setup(int width, int height, float lightRadius,
John Reckb36016c2015-03-11 08:50:53 -0700185 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
John Reck4f02bf42014-01-03 18:09:17 -0800186 SETUP_TASK(setup);
187 args->context = mContext;
188 args->width = width;
189 args->height = height;
Chris Craik797b95b2014-05-20 18:10:25 -0700190 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
Alan Viverette50210d92015-05-14 18:05:36 -0700196CREATE_BRIDGE2(setLightCenter, CanvasContext* context, Vector3 lightCenter) {
197 args->context->setLightCenter(args->lightCenter);
198 return nullptr;
199}
200
201void RenderProxy::setLightCenter(const Vector3& lightCenter) {
202 SETUP_TASK(setLightCenter);
203 args->context = mContext;
204 args->lightCenter = lightCenter;
205 post(task);
206}
207
John Reck63a06672014-05-07 13:45:54 -0700208CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) {
209 args->context->setOpaque(args->opaque);
Chris Craikd41c4d82015-01-05 15:51:13 -0800210 return nullptr;
John Reck63a06672014-05-07 13:45:54 -0700211}
212
213void RenderProxy::setOpaque(bool opaque) {
214 SETUP_TASK(setOpaque);
215 args->context = mContext;
216 args->opaque = opaque;
217 post(task);
218}
219
John Reckba6adf62015-02-19 14:36:50 -0800220int64_t* RenderProxy::frameInfo() {
221 return mDrawFrameTask.frameInfo();
222}
223
224int RenderProxy::syncAndDrawFrame() {
225 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800226}
227
John Reck17035b02014-09-03 07:39:53 -0700228CREATE_BRIDGE1(destroy, CanvasContext* context) {
229 args->context->destroy();
Chris Craikd41c4d82015-01-05 15:51:13 -0800230 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800231}
232
John Reck17035b02014-09-03 07:39:53 -0700233void RenderProxy::destroy() {
234 SETUP_TASK(destroy);
John Reck4f02bf42014-01-03 18:09:17 -0800235 args->context = mContext;
John Reckfae904d2014-04-14 11:01:57 -0700236 // destroyCanvasAndSurface() needs a fence as when it returns the
237 // underlying BufferQueue is going to be released from under
238 // the render thread.
239 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800240}
241
John Reck3b202512014-06-23 13:13:08 -0700242CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) {
243 CanvasContext::invokeFunctor(*args->thread, args->functor);
Chris Craikd41c4d82015-01-05 15:51:13 -0800244 return nullptr;
John Reck0d1f6342014-03-28 20:30:27 -0700245}
246
247void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700248 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700249 RenderThread& thread = RenderThread::getInstance();
John Reck0d1f6342014-03-28 20:30:27 -0700250 SETUP_TASK(invokeFunctor);
John Reck3b202512014-06-23 13:13:08 -0700251 args->thread = &thread;
John Reck0d1f6342014-03-28 20:30:27 -0700252 args->functor = functor;
253 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700254 // waitForCompletion = true is expected to be fairly rare and only
255 // happen in destruction. Thus it should be fine to temporarily
256 // create a Mutex
John Reck0e89e2b2014-10-31 14:49:06 -0700257 staticPostAndWait(task);
John Reck0d1f6342014-03-28 20:30:27 -0700258 } else {
John Reck3b202512014-06-23 13:13:08 -0700259 thread.queue(task);
John Reck0d1f6342014-03-28 20:30:27 -0700260 }
261}
262
John Reckfc53ef272014-02-11 10:40:25 -0800263CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) {
264 args->context->runWithGlContext(args->task);
Chris Craikd41c4d82015-01-05 15:51:13 -0800265 return nullptr;
John Reckfc53ef272014-02-11 10:40:25 -0800266}
267
268void RenderProxy::runWithGlContext(RenderTask* gltask) {
269 SETUP_TASK(runWithGlContext);
270 args->context = mContext;
271 args->task = gltask;
272 postAndWait(task);
273}
274
John Reckc36df952015-07-29 10:09:36 -0700275CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) {
John Reck1949e792014-04-08 15:18:56 -0700276 Layer* layer = args->context->createTextureLayer();
Chris Craikd41c4d82015-01-05 15:51:13 -0800277 if (!layer) return nullptr;
John Reckc36df952015-07-29 10:09:36 -0700278 return new DeferredLayerUpdater(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800279}
280
281DeferredLayerUpdater* RenderProxy::createTextureLayer() {
282 SETUP_TASK(createTextureLayer);
John Reck1949e792014-04-08 15:18:56 -0700283 args->context = mContext;
John Reck19b6bcf2014-02-14 20:03:38 -0800284 void* retval = postAndWait(task);
285 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval);
John Reck19b6bcf2014-02-14 20:03:38 -0800286 return layer;
287}
288
John Reck3e824952014-08-20 10:08:39 -0700289CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) {
290 args->context->buildLayer(args->node);
Chris Craikd41c4d82015-01-05 15:51:13 -0800291 return nullptr;
John Reck3e824952014-08-20 10:08:39 -0700292}
293
294void RenderProxy::buildLayer(RenderNode* node) {
295 SETUP_TASK(buildLayer);
296 args->context = mContext;
297 args->node = node;
298 postAndWait(task);
299}
300
John Reck19b6bcf2014-02-14 20:03:38 -0800301CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer,
302 SkBitmap* bitmap) {
303 bool success = args->context->copyLayerInto(args->layer, args->bitmap);
304 return (void*) success;
305}
306
John Reck3731dc22015-04-13 15:20:29 -0700307bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
John Reck19b6bcf2014-02-14 20:03:38 -0800308 SETUP_TASK(copyLayerInto);
309 args->context = mContext;
310 args->layer = layer;
John Reck3731dc22015-04-13 15:20:29 -0700311 args->bitmap = &bitmap;
John Reck19b6bcf2014-02-14 20:03:38 -0800312 return (bool) postAndWait(task);
313}
314
John Reckd72e0a32014-05-29 18:56:11 -0700315void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
316 mDrawFrameTask.pushLayerUpdate(layer);
317}
318
319void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
320 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800321}
322
John Reck918ad522014-06-27 14:45:25 -0700323CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) {
324 args->layer->detachSurfaceTexture();
Chris Craikd41c4d82015-01-05 15:51:13 -0800325 return nullptr;
John Reck918ad522014-06-27 14:45:25 -0700326}
327
328void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
329 SETUP_TASK(detachSurfaceTexture);
330 args->layer = layer;
331 postAndWait(task);
332}
333
John Reckf47a5942014-06-30 16:20:04 -0700334CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) {
335 args->context->destroyHardwareResources();
Chris Craikd41c4d82015-01-05 15:51:13 -0800336 return nullptr;
John Recke1628b72014-05-23 15:11:19 -0700337}
338
John Reckf47a5942014-06-30 16:20:04 -0700339void RenderProxy::destroyHardwareResources() {
340 SETUP_TASK(destroyHardwareResources);
John Recke1628b72014-05-23 15:11:19 -0700341 args->context = mContext;
John Recke1628b72014-05-23 15:11:19 -0700342 post(task);
343}
344
Chris Craik2507c342015-05-04 14:36:49 -0700345CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) {
John Reckf47a5942014-06-30 16:20:04 -0700346 CanvasContext::trimMemory(*args->thread, args->level);
Chris Craikd41c4d82015-01-05 15:51:13 -0800347 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700348}
349
350void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700351 // Avoid creating a RenderThread to do a trimMemory.
352 if (RenderThread::hasInstance()) {
353 RenderThread& thread = RenderThread::getInstance();
Chris Craik2507c342015-05-04 14:36:49 -0700354 SETUP_TASK(trimMemory);
John Reckcd3a22c2014-08-06 13:33:59 -0700355 args->thread = &thread;
356 args->level = level;
357 thread.queue(task);
358 }
John Reckf47a5942014-06-30 16:20:04 -0700359}
360
Chris Craik2507c342015-05-04 14:36:49 -0700361CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) {
362 Properties::overrideProperty(args->name, args->value);
363 return nullptr;
364}
365
366void RenderProxy::overrideProperty(const char* name, const char* value) {
Chris Craik2507c342015-05-04 14:36:49 -0700367 SETUP_TASK(overrideProperty);
368 args->name = name;
369 args->value = value;
370 staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller
371}
372
John Reck28ad7b52014-04-07 16:59:25 -0700373CREATE_BRIDGE0(fence) {
374 // Intentionally empty
Chris Craikd41c4d82015-01-05 15:51:13 -0800375 return nullptr;
John Reck28ad7b52014-04-07 16:59:25 -0700376}
377
Andreas Gampe64bb4132014-11-22 00:35:09 +0000378template <typename T>
379void UNUSED(T t) {}
380
John Reck28ad7b52014-04-07 16:59:25 -0700381void RenderProxy::fence() {
382 SETUP_TASK(fence);
Andreas Gampe1e196742014-11-10 15:23:43 -0800383 UNUSED(args);
John Reck28ad7b52014-04-07 16:59:25 -0700384 postAndWait(task);
385}
386
Thomas Buhotc0a0e1a2016-01-18 10:31:58 +0100387void RenderProxy::staticFence() {
388 SETUP_TASK(fence);
389 UNUSED(args);
390 staticPostAndWait(task);
391}
392
John Reckf47a5942014-06-30 16:20:04 -0700393CREATE_BRIDGE1(stopDrawing, CanvasContext* context) {
394 args->context->stopDrawing();
Chris Craikd41c4d82015-01-05 15:51:13 -0800395 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700396}
397
398void RenderProxy::stopDrawing() {
399 SETUP_TASK(stopDrawing);
400 args->context = mContext;
401 postAndWait(task);
402}
403
John Recka5dda642014-05-22 15:43:54 -0700404CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) {
405 args->context->notifyFramePending();
Chris Craikd41c4d82015-01-05 15:51:13 -0800406 return nullptr;
John Recka5dda642014-05-22 15:43:54 -0700407}
408
409void RenderProxy::notifyFramePending() {
410 SETUP_TASK(notifyFramePending);
411 args->context = mContext;
412 mRenderThread.queueAtFront(task);
413}
414
John Reck7f2e5e32015-05-05 11:00:53 -0700415CREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread,
416 int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700417 args->context->profiler().dumpData(args->fd);
John Reck7f2e5e32015-05-05 11:00:53 -0700418 args->thread->jankTracker().dump(args->fd);
Chris Craik53e51e42015-06-01 10:35:35 -0700419 if (args->dumpFlags & DumpFlags::FrameStats) {
John Reckba6adf62015-02-19 14:36:50 -0800420 args->context->dumpFrames(args->fd);
421 }
Chris Craik53e51e42015-06-01 10:35:35 -0700422 if (args->dumpFlags & DumpFlags::Reset) {
John Reckba6adf62015-02-19 14:36:50 -0800423 args->context->resetFrameStats();
424 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800425 return nullptr;
John Reckfe5e7b72014-05-23 17:42:28 -0700426}
427
John Reckba6adf62015-02-19 14:36:50 -0800428void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700429 SETUP_TASK(dumpProfileInfo);
430 args->context = mContext;
John Reck7f2e5e32015-05-05 11:00:53 -0700431 args->thread = &mRenderThread;
John Reckfe5e7b72014-05-23 17:42:28 -0700432 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800433 args->dumpFlags = dumpFlags;
John Reckfe5e7b72014-05-23 17:42:28 -0700434 postAndWait(task);
435}
436
John Reck7f2e5e32015-05-05 11:00:53 -0700437CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) {
438 args->context->resetFrameStats();
439 return nullptr;
440}
441
442void RenderProxy::resetProfileInfo() {
443 SETUP_TASK(resetProfileInfo);
444 args->context = mContext;
445 postAndWait(task);
446}
447
John Reckba6adf62015-02-19 14:36:50 -0800448CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) {
449 args->thread->jankTracker().dump(args->fd);
450
Chris Craik2ae07332015-01-21 14:22:39 -0800451 FILE *file = fdopen(args->fd, "a");
452 if (Caches::hasInstance()) {
453 String8 cachesLog;
454 Caches::getInstance().dumpMemoryUsage(cachesLog);
455 fprintf(file, "\nCaches:\n%s\n", cachesLog.string());
456 } else {
457 fprintf(file, "\nNo caches instance.\n");
458 }
Chris Craikff3edce2016-01-14 10:04:08 -0800459#if HWUI_NEW_OPS
460 fprintf(file, "\nPipeline=FrameBuilder\n");
461#else
462 fprintf(file, "\nPipeline=OpenGLRenderer\n");
463#endif
Chris Craik2ae07332015-01-21 14:22:39 -0800464 fflush(file);
Chris Craikd41c4d82015-01-05 15:51:13 -0800465 return nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700466}
467
Chris Craik2ae07332015-01-21 14:22:39 -0800468void RenderProxy::dumpGraphicsMemory(int fd) {
youngmin0822.leec80c9ad2015-03-20 21:22:32 +0900469 if (!RenderThread::hasInstance()) return;
Chris Craik2ae07332015-01-21 14:22:39 -0800470 SETUP_TASK(dumpGraphicsMemory);
John Reck0e89e2b2014-10-31 14:49:06 -0700471 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800472 args->thread = &RenderThread::getInstance();
John Reck0e89e2b2014-10-31 14:49:06 -0700473 staticPostAndWait(task);
474}
475
Skuhneea7a7fb2015-08-28 07:10:31 -0700476CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map,
477 size_t size) {
John Reck3b202512014-06-23 13:13:08 -0700478 CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size);
Chris Craikd41c4d82015-01-05 15:51:13 -0800479 args->buffer->decStrong(nullptr);
480 return nullptr;
John Reck3b202512014-06-23 13:13:08 -0700481}
482
483void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) {
484 SETUP_TASK(setTextureAtlas);
485 args->thread = &mRenderThread;
486 args->buffer = buffer.get();
Chris Craikd41c4d82015-01-05 15:51:13 -0800487 args->buffer->incStrong(nullptr);
John Reck3b202512014-06-23 13:13:08 -0700488 args->map = map;
489 args->size = size;
490 post(task);
491}
492
John Reckedc524c2015-03-18 15:24:33 -0700493CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) {
494 args->thread->jankTracker().switchStorageToAshmem(args->fd);
495 close(args->fd);
496 return nullptr;
497}
498
499void RenderProxy::setProcessStatsBuffer(int fd) {
500 SETUP_TASK(setProcessStatsBuffer);
501 args->thread = &mRenderThread;
502 args->fd = dup(fd);
503 post(task);
504}
505
Skuhneea7a7fb2015-08-28 07:10:31 -0700506CREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) {
507 args->context->addRenderNode(args->node, args->placeFront);
508 return nullptr;
509}
510
511void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) {
512 SETUP_TASK(addRenderNode);
513 args->context = mContext;
514 args->node = node;
515 args->placeFront = placeFront;
516 post(task);
517}
518
519CREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) {
520 args->context->removeRenderNode(args->node);
521 return nullptr;
522}
523
524void RenderProxy::removeRenderNode(RenderNode* node) {
525 SETUP_TASK(removeRenderNode);
526 args->context = mContext;
527 args->node = node;
528 post(task);
529}
530
531CREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) {
532 args->context->prepareAndDraw(args->node);
533 return nullptr;
534}
535
536void RenderProxy::drawRenderNode(RenderNode* node) {
537 SETUP_TASK(drawRenderNode);
538 args->context = mContext;
539 args->node = node;
540 // Be pseudo-thread-safe and don't use any member variables
541 staticPostAndWait(task);
542}
543
Skuhneb8160872015-09-22 09:51:39 -0700544CREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top,
Skuhneea7a7fb2015-08-28 07:10:31 -0700545 int right, int bottom) {
Skuhneb8160872015-09-22 09:51:39 -0700546 args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700547 return nullptr;
548}
549
Skuhneb8160872015-09-22 09:51:39 -0700550void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) {
551 SETUP_TASK(setContentDrawBounds);
Skuhneea7a7fb2015-08-28 07:10:31 -0700552 args->context = mContext;
553 args->left = left;
554 args->top = top;
555 args->right = right;
556 args->bottom = bottom;
557 staticPostAndWait(task);
558}
559
John Recke248bd12015-08-05 13:53:53 -0700560CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) {
561 args->context->serializeDisplayListTree();
562 return nullptr;
563}
564
565void RenderProxy::serializeDisplayListTree() {
566 SETUP_TASK(serializeDisplayListTree);
567 args->context = mContext;
568 post(task);
569}
570
Andres Morales910beb82016-02-02 16:19:40 -0800571CREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context,
572 FrameMetricsObserver* frameStatsObserver) {
573 args->context->addFrameMetricsObserver(args->frameStatsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800574 if (args->frameStatsObserver != nullptr) {
575 args->frameStatsObserver->decStrong(args->context);
576 }
577 return nullptr;
578}
579
Andres Morales910beb82016-02-02 16:19:40 -0800580void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) {
581 SETUP_TASK(addFrameMetricsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800582 args->context = mContext;
583 args->frameStatsObserver = observer;
584 if (observer != nullptr) {
585 observer->incStrong(mContext);
586 }
587 post(task);
588}
589
Andres Morales910beb82016-02-02 16:19:40 -0800590CREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context,
591 FrameMetricsObserver* frameStatsObserver) {
592 args->context->removeFrameMetricsObserver(args->frameStatsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800593 if (args->frameStatsObserver != nullptr) {
594 args->frameStatsObserver->decStrong(args->context);
595 }
596 return nullptr;
597}
598
Andres Morales910beb82016-02-02 16:19:40 -0800599void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) {
600 SETUP_TASK(removeFrameMetricsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800601 args->context = mContext;
602 args->frameStatsObserver = observer;
603 if (observer != nullptr) {
604 observer->incStrong(mContext);
605 }
606 post(task);
607}
608
John Reck4f02bf42014-01-03 18:09:17 -0800609void RenderProxy::post(RenderTask* task) {
610 mRenderThread.queue(task);
611}
612
613void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
614 void* retval;
615 task->setReturnPtr(&retval);
John Reckcba287b2015-11-10 12:52:44 -0800616 SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
617 AutoMutex _lock(mSyncMutex);
618 mRenderThread.queue(&syncTask);
619 mSyncCondition.wait(mSyncMutex);
John Reck4f02bf42014-01-03 18:09:17 -0800620 return retval;
621}
622
John Reck0e89e2b2014-10-31 14:49:06 -0700623void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) {
624 RenderThread& thread = RenderThread::getInstance();
625 void* retval;
626 task->setReturnPtr(&retval);
Chris Craik0a24b142015-10-19 17:10:19 -0700627 thread.queueAndWait(task);
John Reck0e89e2b2014-10-31 14:49:06 -0700628 return retval;
629}
630
John Reck4f02bf42014-01-03 18:09:17 -0800631} /* namespace renderthread */
632} /* namespace uirenderer */
633} /* namespace android */