blob: 149ddf6ddaaaa5eb3221dcbb2dc8c0ccf9834dd3 [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,
John Reck66010802016-03-30 14:19:44 -070059 JankStats = 1 << 2,
Chris Craik53e51e42015-06-01 10:35:35 -070060 };
John Reckc87be992015-02-20 10:57:22 -080061};
John Reckba6adf62015-02-19 14:36:50 -080062
John Reck119907c2014-08-14 09:02:01 -070063CREATE_BRIDGE4(createContext, RenderThread* thread, bool translucent,
64 RenderNode* rootRenderNode, IContextFactory* contextFactory) {
65 return new CanvasContext(*args->thread, args->translucent,
66 args->rootRenderNode, args->contextFactory);
John Reck4f02bf42014-01-03 18:09:17 -080067}
68
John Reck119907c2014-08-14 09:02:01 -070069RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory)
John Reck4f02bf42014-01-03 18:09:17 -080070 : mRenderThread(RenderThread::getInstance())
Chris Craikd41c4d82015-01-05 15:51:13 -080071 , mContext(nullptr) {
John Reck4f02bf42014-01-03 18:09:17 -080072 SETUP_TASK(createContext);
73 args->translucent = translucent;
John Recke45b1fd2014-04-15 09:50:16 -070074 args->rootRenderNode = rootRenderNode;
John Reck3b202512014-06-23 13:13:08 -070075 args->thread = &mRenderThread;
John Reck119907c2014-08-14 09:02:01 -070076 args->contextFactory = contextFactory;
John Reck4f02bf42014-01-03 18:09:17 -080077 mContext = (CanvasContext*) postAndWait(task);
Skuhneea7a7fb2015-08-28 07:10:31 -070078 mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode);
John Reck4f02bf42014-01-03 18:09:17 -080079}
80
81RenderProxy::~RenderProxy() {
82 destroyContext();
83}
84
85CREATE_BRIDGE1(destroyContext, CanvasContext* context) {
86 delete args->context;
Chris Craikd41c4d82015-01-05 15:51:13 -080087 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080088}
89
90void RenderProxy::destroyContext() {
91 if (mContext) {
92 SETUP_TASK(destroyContext);
93 args->context = mContext;
Chris Craikd41c4d82015-01-05 15:51:13 -080094 mContext = nullptr;
Skuhneea7a7fb2015-08-28 07:10:31 -070095 mDrawFrameTask.setContext(nullptr, nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070096 // This is also a fence as we need to be certain that there are no
97 // outstanding mDrawFrame tasks posted before it is destroyed
98 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -080099 }
100}
101
John Reck1125d1f2014-10-23 11:02:19 -0700102CREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) {
103 args->context->setSwapBehavior(args->swapBehavior);
Chris Craikd41c4d82015-01-05 15:51:13 -0800104 return nullptr;
John Reck1125d1f2014-10-23 11:02:19 -0700105}
106
107void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
108 SETUP_TASK(setSwapBehavior);
109 args->context = mContext;
110 args->swapBehavior = swapBehavior;
111 post(task);
112}
113
John Reckfe5e7b72014-05-23 17:42:28 -0700114CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) {
John Recke4280ba2014-05-05 16:39:37 -0700115 bool needsRedraw = false;
116 if (Caches::hasInstance()) {
Chris Craik2507c342015-05-04 14:36:49 -0700117 needsRedraw = Properties::load();
John Recke4280ba2014-05-05 16:39:37 -0700118 }
Chris Craik2507c342015-05-04 14:36:49 -0700119 if (args->context->profiler().consumeProperties()) {
John Reckfe5e7b72014-05-23 17:42:28 -0700120 needsRedraw = true;
121 }
John Recke4280ba2014-05-05 16:39:37 -0700122 return (void*) needsRedraw;
123}
124
125bool RenderProxy::loadSystemProperties() {
126 SETUP_TASK(loadSystemProperties);
John Reckfe5e7b72014-05-23 17:42:28 -0700127 args->context = mContext;
John Recke4280ba2014-05-05 16:39:37 -0700128 return (bool) postAndWait(task);
129}
130
John Reckb36016c2015-03-11 08:50:53 -0700131CREATE_BRIDGE2(setName, CanvasContext* context, const char* name) {
132 args->context->setName(std::string(args->name));
133 return nullptr;
134}
135
136void RenderProxy::setName(const char* name) {
137 SETUP_TASK(setName);
138 args->context = mContext;
139 args->name = name;
Chris Craik2507c342015-05-04 14:36:49 -0700140 postAndWait(task); // block since name/value pointers owned by caller
John Reckb36016c2015-03-11 08:50:53 -0700141}
142
John Reckf6481082016-02-02 15:18:23 -0800143CREATE_BRIDGE2(initialize, CanvasContext* context, Surface* surface) {
144 args->context->initialize(args->surface);
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100145 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800146}
147
John Reckf6481082016-02-02 15:18:23 -0800148void RenderProxy::initialize(const sp<Surface>& surface) {
John Reck4f02bf42014-01-03 18:09:17 -0800149 SETUP_TASK(initialize);
150 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800151 args->surface = surface.get();
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100152 post(task);
John Reck4f02bf42014-01-03 18:09:17 -0800153}
154
John Reckf6481082016-02-02 15:18:23 -0800155CREATE_BRIDGE2(updateSurface, CanvasContext* context, Surface* surface) {
156 args->context->updateSurface(args->surface);
Chris Craikd41c4d82015-01-05 15:51:13 -0800157 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800158}
159
John Reckf6481082016-02-02 15:18:23 -0800160void RenderProxy::updateSurface(const sp<Surface>& surface) {
John Reck4f02bf42014-01-03 18:09:17 -0800161 SETUP_TASK(updateSurface);
162 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800163 args->surface = surface.get();
John Reckf7d9c1d2014-04-09 10:01:03 -0700164 postAndWait(task);
165}
166
John Reckf6481082016-02-02 15:18:23 -0800167CREATE_BRIDGE2(pauseSurface, CanvasContext* context, Surface* surface) {
168 return (void*) args->context->pauseSurface(args->surface);
John Reckf7d9c1d2014-04-09 10:01:03 -0700169}
170
John Reckf6481082016-02-02 15:18:23 -0800171bool RenderProxy::pauseSurface(const sp<Surface>& surface) {
John Reckf7d9c1d2014-04-09 10:01:03 -0700172 SETUP_TASK(pauseSurface);
173 args->context = mContext;
John Reckf6481082016-02-02 15:18:23 -0800174 args->surface = surface.get();
John Reck01a5ea32014-12-03 13:01:07 -0800175 return (bool) postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800176}
177
John Reck945961f2016-04-07 16:02:33 -0700178CREATE_BRIDGE2(setStopped, CanvasContext* context, bool stopped) {
179 args->context->setStopped(args->stopped);
180 return nullptr;
181}
182
183void RenderProxy::setStopped(bool stopped) {
184 SETUP_TASK(setStopped);
185 args->context = mContext;
186 args->stopped = stopped;
187 postAndWait(task);
188}
189
Alan Viverette50210d92015-05-14 18:05:36 -0700190CREATE_BRIDGE6(setup, CanvasContext* context, int width, int height,
191 float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
192 args->context->setup(args->width, args->height, args->lightRadius,
Chris Craik058fc642014-07-23 18:19:28 -0700193 args->ambientShadowAlpha, args->spotShadowAlpha);
Chris Craikd41c4d82015-01-05 15:51:13 -0800194 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800195}
196
Alan Viverette50210d92015-05-14 18:05:36 -0700197void RenderProxy::setup(int width, int height, float lightRadius,
John Reckb36016c2015-03-11 08:50:53 -0700198 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
John Reck4f02bf42014-01-03 18:09:17 -0800199 SETUP_TASK(setup);
200 args->context = mContext;
201 args->width = width;
202 args->height = height;
Chris Craik797b95b2014-05-20 18:10:25 -0700203 args->lightRadius = lightRadius;
Chris Craik058fc642014-07-23 18:19:28 -0700204 args->ambientShadowAlpha = ambientShadowAlpha;
205 args->spotShadowAlpha = spotShadowAlpha;
John Reck4f02bf42014-01-03 18:09:17 -0800206 post(task);
207}
208
Alan Viverette50210d92015-05-14 18:05:36 -0700209CREATE_BRIDGE2(setLightCenter, CanvasContext* context, Vector3 lightCenter) {
210 args->context->setLightCenter(args->lightCenter);
211 return nullptr;
212}
213
214void RenderProxy::setLightCenter(const Vector3& lightCenter) {
215 SETUP_TASK(setLightCenter);
216 args->context = mContext;
217 args->lightCenter = lightCenter;
218 post(task);
219}
220
John Reck63a06672014-05-07 13:45:54 -0700221CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) {
222 args->context->setOpaque(args->opaque);
Chris Craikd41c4d82015-01-05 15:51:13 -0800223 return nullptr;
John Reck63a06672014-05-07 13:45:54 -0700224}
225
226void RenderProxy::setOpaque(bool opaque) {
227 SETUP_TASK(setOpaque);
228 args->context = mContext;
229 args->opaque = opaque;
230 post(task);
231}
232
John Reckba6adf62015-02-19 14:36:50 -0800233int64_t* RenderProxy::frameInfo() {
234 return mDrawFrameTask.frameInfo();
235}
236
237int RenderProxy::syncAndDrawFrame() {
238 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800239}
240
John Reck17035b02014-09-03 07:39:53 -0700241CREATE_BRIDGE1(destroy, CanvasContext* context) {
242 args->context->destroy();
Chris Craikd41c4d82015-01-05 15:51:13 -0800243 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800244}
245
John Reck17035b02014-09-03 07:39:53 -0700246void RenderProxy::destroy() {
247 SETUP_TASK(destroy);
John Reck4f02bf42014-01-03 18:09:17 -0800248 args->context = mContext;
John Reckfae904d2014-04-14 11:01:57 -0700249 // destroyCanvasAndSurface() needs a fence as when it returns the
250 // underlying BufferQueue is going to be released from under
251 // the render thread.
252 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800253}
254
John Reck3b202512014-06-23 13:13:08 -0700255CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) {
256 CanvasContext::invokeFunctor(*args->thread, args->functor);
Chris Craikd41c4d82015-01-05 15:51:13 -0800257 return nullptr;
John Reck0d1f6342014-03-28 20:30:27 -0700258}
259
260void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700261 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700262 RenderThread& thread = RenderThread::getInstance();
John Reck0d1f6342014-03-28 20:30:27 -0700263 SETUP_TASK(invokeFunctor);
John Reck3b202512014-06-23 13:13:08 -0700264 args->thread = &thread;
John Reck0d1f6342014-03-28 20:30:27 -0700265 args->functor = functor;
266 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700267 // waitForCompletion = true is expected to be fairly rare and only
268 // happen in destruction. Thus it should be fine to temporarily
269 // create a Mutex
John Reck0e89e2b2014-10-31 14:49:06 -0700270 staticPostAndWait(task);
John Reck0d1f6342014-03-28 20:30:27 -0700271 } else {
John Reck3b202512014-06-23 13:13:08 -0700272 thread.queue(task);
John Reck0d1f6342014-03-28 20:30:27 -0700273 }
274}
275
John Reckfc53ef272014-02-11 10:40:25 -0800276CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) {
277 args->context->runWithGlContext(args->task);
Chris Craikd41c4d82015-01-05 15:51:13 -0800278 return nullptr;
John Reckfc53ef272014-02-11 10:40:25 -0800279}
280
281void RenderProxy::runWithGlContext(RenderTask* gltask) {
282 SETUP_TASK(runWithGlContext);
283 args->context = mContext;
284 args->task = gltask;
285 postAndWait(task);
286}
287
John Reckc36df952015-07-29 10:09:36 -0700288CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) {
John Reck1949e792014-04-08 15:18:56 -0700289 Layer* layer = args->context->createTextureLayer();
Chris Craikd41c4d82015-01-05 15:51:13 -0800290 if (!layer) return nullptr;
John Reckc36df952015-07-29 10:09:36 -0700291 return new DeferredLayerUpdater(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800292}
293
294DeferredLayerUpdater* RenderProxy::createTextureLayer() {
295 SETUP_TASK(createTextureLayer);
John Reck1949e792014-04-08 15:18:56 -0700296 args->context = mContext;
John Reck19b6bcf2014-02-14 20:03:38 -0800297 void* retval = postAndWait(task);
298 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval);
John Reck19b6bcf2014-02-14 20:03:38 -0800299 return layer;
300}
301
John Reck3e824952014-08-20 10:08:39 -0700302CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) {
303 args->context->buildLayer(args->node);
Chris Craikd41c4d82015-01-05 15:51:13 -0800304 return nullptr;
John Reck3e824952014-08-20 10:08:39 -0700305}
306
307void RenderProxy::buildLayer(RenderNode* node) {
308 SETUP_TASK(buildLayer);
309 args->context = mContext;
310 args->node = node;
311 postAndWait(task);
312}
313
John Reck19b6bcf2014-02-14 20:03:38 -0800314CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer,
315 SkBitmap* bitmap) {
316 bool success = args->context->copyLayerInto(args->layer, args->bitmap);
317 return (void*) success;
318}
319
John Reck3731dc22015-04-13 15:20:29 -0700320bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
John Reck19b6bcf2014-02-14 20:03:38 -0800321 SETUP_TASK(copyLayerInto);
322 args->context = mContext;
323 args->layer = layer;
John Reck3731dc22015-04-13 15:20:29 -0700324 args->bitmap = &bitmap;
John Reck19b6bcf2014-02-14 20:03:38 -0800325 return (bool) postAndWait(task);
326}
327
John Reckd72e0a32014-05-29 18:56:11 -0700328void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
329 mDrawFrameTask.pushLayerUpdate(layer);
330}
331
332void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
333 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800334}
335
John Reck918ad522014-06-27 14:45:25 -0700336CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) {
337 args->layer->detachSurfaceTexture();
Chris Craikd41c4d82015-01-05 15:51:13 -0800338 return nullptr;
John Reck918ad522014-06-27 14:45:25 -0700339}
340
341void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
342 SETUP_TASK(detachSurfaceTexture);
343 args->layer = layer;
344 postAndWait(task);
345}
346
John Reckf47a5942014-06-30 16:20:04 -0700347CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) {
348 args->context->destroyHardwareResources();
Chris Craikd41c4d82015-01-05 15:51:13 -0800349 return nullptr;
John Recke1628b72014-05-23 15:11:19 -0700350}
351
John Reckf47a5942014-06-30 16:20:04 -0700352void RenderProxy::destroyHardwareResources() {
353 SETUP_TASK(destroyHardwareResources);
John Recke1628b72014-05-23 15:11:19 -0700354 args->context = mContext;
John Recke1628b72014-05-23 15:11:19 -0700355 post(task);
356}
357
Chris Craik2507c342015-05-04 14:36:49 -0700358CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) {
John Reckf47a5942014-06-30 16:20:04 -0700359 CanvasContext::trimMemory(*args->thread, args->level);
Chris Craikd41c4d82015-01-05 15:51:13 -0800360 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700361}
362
363void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700364 // Avoid creating a RenderThread to do a trimMemory.
365 if (RenderThread::hasInstance()) {
366 RenderThread& thread = RenderThread::getInstance();
Chris Craik2507c342015-05-04 14:36:49 -0700367 SETUP_TASK(trimMemory);
John Reckcd3a22c2014-08-06 13:33:59 -0700368 args->thread = &thread;
369 args->level = level;
370 thread.queue(task);
371 }
John Reckf47a5942014-06-30 16:20:04 -0700372}
373
Chris Craik2507c342015-05-04 14:36:49 -0700374CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) {
375 Properties::overrideProperty(args->name, args->value);
376 return nullptr;
377}
378
379void RenderProxy::overrideProperty(const char* name, const char* value) {
Chris Craik2507c342015-05-04 14:36:49 -0700380 SETUP_TASK(overrideProperty);
381 args->name = name;
382 args->value = value;
383 staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller
384}
385
John Reck28ad7b52014-04-07 16:59:25 -0700386CREATE_BRIDGE0(fence) {
387 // Intentionally empty
Chris Craikd41c4d82015-01-05 15:51:13 -0800388 return nullptr;
John Reck28ad7b52014-04-07 16:59:25 -0700389}
390
Andreas Gampe64bb4132014-11-22 00:35:09 +0000391template <typename T>
392void UNUSED(T t) {}
393
John Reck28ad7b52014-04-07 16:59:25 -0700394void RenderProxy::fence() {
395 SETUP_TASK(fence);
Andreas Gampe1e196742014-11-10 15:23:43 -0800396 UNUSED(args);
John Reck28ad7b52014-04-07 16:59:25 -0700397 postAndWait(task);
398}
399
Thomas Buhotc0a0e1a2016-01-18 10:31:58 +0100400void RenderProxy::staticFence() {
401 SETUP_TASK(fence);
402 UNUSED(args);
403 staticPostAndWait(task);
404}
405
John Reckf47a5942014-06-30 16:20:04 -0700406CREATE_BRIDGE1(stopDrawing, CanvasContext* context) {
407 args->context->stopDrawing();
Chris Craikd41c4d82015-01-05 15:51:13 -0800408 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700409}
410
411void RenderProxy::stopDrawing() {
412 SETUP_TASK(stopDrawing);
413 args->context = mContext;
414 postAndWait(task);
415}
416
John Recka5dda642014-05-22 15:43:54 -0700417CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) {
418 args->context->notifyFramePending();
Chris Craikd41c4d82015-01-05 15:51:13 -0800419 return nullptr;
John Recka5dda642014-05-22 15:43:54 -0700420}
421
422void RenderProxy::notifyFramePending() {
423 SETUP_TASK(notifyFramePending);
424 args->context = mContext;
425 mRenderThread.queueAtFront(task);
426}
427
John Reck7f2e5e32015-05-05 11:00:53 -0700428CREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread,
429 int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700430 args->context->profiler().dumpData(args->fd);
Chris Craik53e51e42015-06-01 10:35:35 -0700431 if (args->dumpFlags & DumpFlags::FrameStats) {
John Reckba6adf62015-02-19 14:36:50 -0800432 args->context->dumpFrames(args->fd);
433 }
Chris Craik53e51e42015-06-01 10:35:35 -0700434 if (args->dumpFlags & DumpFlags::Reset) {
John Reckba6adf62015-02-19 14:36:50 -0800435 args->context->resetFrameStats();
436 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800437 return nullptr;
John Reckfe5e7b72014-05-23 17:42:28 -0700438}
439
John Reckba6adf62015-02-19 14:36:50 -0800440void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700441 SETUP_TASK(dumpProfileInfo);
442 args->context = mContext;
John Reck7f2e5e32015-05-05 11:00:53 -0700443 args->thread = &mRenderThread;
John Reckfe5e7b72014-05-23 17:42:28 -0700444 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800445 args->dumpFlags = dumpFlags;
John Reckfe5e7b72014-05-23 17:42:28 -0700446 postAndWait(task);
447}
448
John Reck7f2e5e32015-05-05 11:00:53 -0700449CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) {
450 args->context->resetFrameStats();
451 return nullptr;
452}
453
454void RenderProxy::resetProfileInfo() {
455 SETUP_TASK(resetProfileInfo);
456 args->context = mContext;
457 postAndWait(task);
458}
459
John Reckba6adf62015-02-19 14:36:50 -0800460CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) {
461 args->thread->jankTracker().dump(args->fd);
462
Chris Craik2ae07332015-01-21 14:22:39 -0800463 FILE *file = fdopen(args->fd, "a");
464 if (Caches::hasInstance()) {
465 String8 cachesLog;
466 Caches::getInstance().dumpMemoryUsage(cachesLog);
467 fprintf(file, "\nCaches:\n%s\n", cachesLog.string());
468 } else {
469 fprintf(file, "\nNo caches instance.\n");
470 }
Chris Craikff3edce2016-01-14 10:04:08 -0800471#if HWUI_NEW_OPS
472 fprintf(file, "\nPipeline=FrameBuilder\n");
473#else
474 fprintf(file, "\nPipeline=OpenGLRenderer\n");
475#endif
Chris Craik2ae07332015-01-21 14:22:39 -0800476 fflush(file);
Chris Craikd41c4d82015-01-05 15:51:13 -0800477 return nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700478}
479
Chris Craik2ae07332015-01-21 14:22:39 -0800480void RenderProxy::dumpGraphicsMemory(int fd) {
youngmin0822.leec80c9ad2015-03-20 21:22:32 +0900481 if (!RenderThread::hasInstance()) return;
Chris Craik2ae07332015-01-21 14:22:39 -0800482 SETUP_TASK(dumpGraphicsMemory);
John Reck0e89e2b2014-10-31 14:49:06 -0700483 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800484 args->thread = &RenderThread::getInstance();
John Reck0e89e2b2014-10-31 14:49:06 -0700485 staticPostAndWait(task);
486}
487
Skuhneea7a7fb2015-08-28 07:10:31 -0700488CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map,
489 size_t size) {
John Reck3b202512014-06-23 13:13:08 -0700490 CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size);
Chris Craikd41c4d82015-01-05 15:51:13 -0800491 args->buffer->decStrong(nullptr);
492 return nullptr;
John Reck3b202512014-06-23 13:13:08 -0700493}
494
495void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) {
496 SETUP_TASK(setTextureAtlas);
497 args->thread = &mRenderThread;
498 args->buffer = buffer.get();
Chris Craikd41c4d82015-01-05 15:51:13 -0800499 args->buffer->incStrong(nullptr);
John Reck3b202512014-06-23 13:13:08 -0700500 args->map = map;
501 args->size = size;
502 post(task);
503}
504
John Reckedc524c2015-03-18 15:24:33 -0700505CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) {
506 args->thread->jankTracker().switchStorageToAshmem(args->fd);
507 close(args->fd);
508 return nullptr;
509}
510
511void RenderProxy::setProcessStatsBuffer(int fd) {
512 SETUP_TASK(setProcessStatsBuffer);
513 args->thread = &mRenderThread;
514 args->fd = dup(fd);
515 post(task);
516}
517
Skuhneea7a7fb2015-08-28 07:10:31 -0700518CREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) {
519 args->context->addRenderNode(args->node, args->placeFront);
520 return nullptr;
521}
522
523void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) {
524 SETUP_TASK(addRenderNode);
525 args->context = mContext;
526 args->node = node;
527 args->placeFront = placeFront;
528 post(task);
529}
530
531CREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) {
532 args->context->removeRenderNode(args->node);
533 return nullptr;
534}
535
536void RenderProxy::removeRenderNode(RenderNode* node) {
537 SETUP_TASK(removeRenderNode);
538 args->context = mContext;
539 args->node = node;
540 post(task);
541}
542
543CREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) {
544 args->context->prepareAndDraw(args->node);
545 return nullptr;
546}
547
548void RenderProxy::drawRenderNode(RenderNode* node) {
549 SETUP_TASK(drawRenderNode);
550 args->context = mContext;
551 args->node = node;
552 // Be pseudo-thread-safe and don't use any member variables
553 staticPostAndWait(task);
554}
555
Skuhneb8160872015-09-22 09:51:39 -0700556CREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top,
Skuhneea7a7fb2015-08-28 07:10:31 -0700557 int right, int bottom) {
Skuhneb8160872015-09-22 09:51:39 -0700558 args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700559 return nullptr;
560}
561
Skuhneb8160872015-09-22 09:51:39 -0700562void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) {
563 SETUP_TASK(setContentDrawBounds);
Skuhneea7a7fb2015-08-28 07:10:31 -0700564 args->context = mContext;
565 args->left = left;
566 args->top = top;
567 args->right = right;
568 args->bottom = bottom;
569 staticPostAndWait(task);
570}
571
John Recke248bd12015-08-05 13:53:53 -0700572CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) {
573 args->context->serializeDisplayListTree();
574 return nullptr;
575}
576
577void RenderProxy::serializeDisplayListTree() {
578 SETUP_TASK(serializeDisplayListTree);
579 args->context = mContext;
580 post(task);
581}
582
Andres Morales910beb82016-02-02 16:19:40 -0800583CREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context,
584 FrameMetricsObserver* frameStatsObserver) {
585 args->context->addFrameMetricsObserver(args->frameStatsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800586 if (args->frameStatsObserver != nullptr) {
587 args->frameStatsObserver->decStrong(args->context);
588 }
589 return nullptr;
590}
591
Andres Morales910beb82016-02-02 16:19:40 -0800592void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) {
593 SETUP_TASK(addFrameMetricsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800594 args->context = mContext;
595 args->frameStatsObserver = observer;
596 if (observer != nullptr) {
597 observer->incStrong(mContext);
598 }
599 post(task);
600}
601
Andres Morales910beb82016-02-02 16:19:40 -0800602CREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context,
603 FrameMetricsObserver* frameStatsObserver) {
604 args->context->removeFrameMetricsObserver(args->frameStatsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800605 if (args->frameStatsObserver != nullptr) {
606 args->frameStatsObserver->decStrong(args->context);
607 }
608 return nullptr;
609}
610
Andres Morales910beb82016-02-02 16:19:40 -0800611void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) {
612 SETUP_TASK(removeFrameMetricsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800613 args->context = mContext;
614 args->frameStatsObserver = observer;
615 if (observer != nullptr) {
616 observer->incStrong(mContext);
617 }
618 post(task);
619}
620
John Reck4f02bf42014-01-03 18:09:17 -0800621void RenderProxy::post(RenderTask* task) {
622 mRenderThread.queue(task);
623}
624
625void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
626 void* retval;
627 task->setReturnPtr(&retval);
John Reckcba287b2015-11-10 12:52:44 -0800628 SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
629 AutoMutex _lock(mSyncMutex);
630 mRenderThread.queue(&syncTask);
631 mSyncCondition.wait(mSyncMutex);
John Reck4f02bf42014-01-03 18:09:17 -0800632 return retval;
633}
634
John Reck0e89e2b2014-10-31 14:49:06 -0700635void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) {
636 RenderThread& thread = RenderThread::getInstance();
637 void* retval;
638 task->setReturnPtr(&retval);
Chris Craik0a24b142015-10-19 17:10:19 -0700639 thread.queueAndWait(task);
John Reck0e89e2b2014-10-31 14:49:06 -0700640 return retval;
641}
642
John Reck4f02bf42014-01-03 18:09:17 -0800643} /* namespace renderthread */
644} /* namespace uirenderer */
645} /* namespace android */