blob: c5a2dc7bd8ce8f5bbf0e980b6d987f11b6a3acd2 [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
John Reck945961f2016-04-07 16:02:33 -0700170CREATE_BRIDGE2(setStopped, CanvasContext* context, bool stopped) {
171 args->context->setStopped(args->stopped);
172 return nullptr;
173}
174
175void RenderProxy::setStopped(bool stopped) {
176 SETUP_TASK(setStopped);
177 args->context = mContext;
178 args->stopped = stopped;
179 postAndWait(task);
180}
181
Alan Viverette50210d92015-05-14 18:05:36 -0700182CREATE_BRIDGE6(setup, CanvasContext* context, int width, int height,
183 float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
184 args->context->setup(args->width, args->height, args->lightRadius,
Chris Craik058fc642014-07-23 18:19:28 -0700185 args->ambientShadowAlpha, args->spotShadowAlpha);
Chris Craikd41c4d82015-01-05 15:51:13 -0800186 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800187}
188
Alan Viverette50210d92015-05-14 18:05:36 -0700189void RenderProxy::setup(int width, int height, float lightRadius,
John Reckb36016c2015-03-11 08:50:53 -0700190 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
John Reck4f02bf42014-01-03 18:09:17 -0800191 SETUP_TASK(setup);
192 args->context = mContext;
193 args->width = width;
194 args->height = height;
Chris Craik797b95b2014-05-20 18:10:25 -0700195 args->lightRadius = lightRadius;
Chris Craik058fc642014-07-23 18:19:28 -0700196 args->ambientShadowAlpha = ambientShadowAlpha;
197 args->spotShadowAlpha = spotShadowAlpha;
John Reck4f02bf42014-01-03 18:09:17 -0800198 post(task);
199}
200
Alan Viverette50210d92015-05-14 18:05:36 -0700201CREATE_BRIDGE2(setLightCenter, CanvasContext* context, Vector3 lightCenter) {
202 args->context->setLightCenter(args->lightCenter);
203 return nullptr;
204}
205
206void RenderProxy::setLightCenter(const Vector3& lightCenter) {
207 SETUP_TASK(setLightCenter);
208 args->context = mContext;
209 args->lightCenter = lightCenter;
210 post(task);
211}
212
John Reck63a06672014-05-07 13:45:54 -0700213CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) {
214 args->context->setOpaque(args->opaque);
Chris Craikd41c4d82015-01-05 15:51:13 -0800215 return nullptr;
John Reck63a06672014-05-07 13:45:54 -0700216}
217
218void RenderProxy::setOpaque(bool opaque) {
219 SETUP_TASK(setOpaque);
220 args->context = mContext;
221 args->opaque = opaque;
222 post(task);
223}
224
John Reckba6adf62015-02-19 14:36:50 -0800225int64_t* RenderProxy::frameInfo() {
226 return mDrawFrameTask.frameInfo();
227}
228
John Reck51f2d602016-04-06 07:50:47 -0700229int RenderProxy::syncAndDrawFrame(TreeObserver* observer) {
230 return mDrawFrameTask.drawFrame(observer);
John Reck4f02bf42014-01-03 18:09:17 -0800231}
232
John Reck51f2d602016-04-06 07:50:47 -0700233CREATE_BRIDGE2(destroy, CanvasContext* context, TreeObserver* observer) {
234 args->context->destroy(args->observer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800235 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800236}
237
John Reck51f2d602016-04-06 07:50:47 -0700238void RenderProxy::destroy(TreeObserver* observer) {
John Reck17035b02014-09-03 07:39:53 -0700239 SETUP_TASK(destroy);
John Reck4f02bf42014-01-03 18:09:17 -0800240 args->context = mContext;
John Reck51f2d602016-04-06 07:50:47 -0700241 args->observer = observer;
John Reckfae904d2014-04-14 11:01:57 -0700242 // destroyCanvasAndSurface() needs a fence as when it returns the
243 // underlying BufferQueue is going to be released from under
244 // the render thread.
245 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800246}
247
John Reck3b202512014-06-23 13:13:08 -0700248CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) {
249 CanvasContext::invokeFunctor(*args->thread, args->functor);
Chris Craikd41c4d82015-01-05 15:51:13 -0800250 return nullptr;
John Reck0d1f6342014-03-28 20:30:27 -0700251}
252
253void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700254 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700255 RenderThread& thread = RenderThread::getInstance();
John Reck0d1f6342014-03-28 20:30:27 -0700256 SETUP_TASK(invokeFunctor);
John Reck3b202512014-06-23 13:13:08 -0700257 args->thread = &thread;
John Reck0d1f6342014-03-28 20:30:27 -0700258 args->functor = functor;
259 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700260 // waitForCompletion = true is expected to be fairly rare and only
261 // happen in destruction. Thus it should be fine to temporarily
262 // create a Mutex
John Reck0e89e2b2014-10-31 14:49:06 -0700263 staticPostAndWait(task);
John Reck0d1f6342014-03-28 20:30:27 -0700264 } else {
John Reck3b202512014-06-23 13:13:08 -0700265 thread.queue(task);
John Reck0d1f6342014-03-28 20:30:27 -0700266 }
267}
268
John Reckfc53ef272014-02-11 10:40:25 -0800269CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) {
270 args->context->runWithGlContext(args->task);
Chris Craikd41c4d82015-01-05 15:51:13 -0800271 return nullptr;
John Reckfc53ef272014-02-11 10:40:25 -0800272}
273
274void RenderProxy::runWithGlContext(RenderTask* gltask) {
275 SETUP_TASK(runWithGlContext);
276 args->context = mContext;
277 args->task = gltask;
278 postAndWait(task);
279}
280
John Reckc36df952015-07-29 10:09:36 -0700281CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) {
John Reck1949e792014-04-08 15:18:56 -0700282 Layer* layer = args->context->createTextureLayer();
Chris Craikd41c4d82015-01-05 15:51:13 -0800283 if (!layer) return nullptr;
John Reckc36df952015-07-29 10:09:36 -0700284 return new DeferredLayerUpdater(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800285}
286
287DeferredLayerUpdater* RenderProxy::createTextureLayer() {
288 SETUP_TASK(createTextureLayer);
John Reck1949e792014-04-08 15:18:56 -0700289 args->context = mContext;
John Reck19b6bcf2014-02-14 20:03:38 -0800290 void* retval = postAndWait(task);
291 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval);
John Reck19b6bcf2014-02-14 20:03:38 -0800292 return layer;
293}
294
John Reck51f2d602016-04-06 07:50:47 -0700295CREATE_BRIDGE3(buildLayer, CanvasContext* context, RenderNode* node, TreeObserver* observer) {
296 args->context->buildLayer(args->node, args->observer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800297 return nullptr;
John Reck3e824952014-08-20 10:08:39 -0700298}
299
John Reck51f2d602016-04-06 07:50:47 -0700300void RenderProxy::buildLayer(RenderNode* node, TreeObserver* observer) {
John Reck3e824952014-08-20 10:08:39 -0700301 SETUP_TASK(buildLayer);
302 args->context = mContext;
303 args->node = node;
John Reck51f2d602016-04-06 07:50:47 -0700304 args->observer = observer;
John Reck3e824952014-08-20 10:08:39 -0700305 postAndWait(task);
306}
307
John Reck19b6bcf2014-02-14 20:03:38 -0800308CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer,
309 SkBitmap* bitmap) {
310 bool success = args->context->copyLayerInto(args->layer, args->bitmap);
311 return (void*) success;
312}
313
John Reck3731dc22015-04-13 15:20:29 -0700314bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
John Reck19b6bcf2014-02-14 20:03:38 -0800315 SETUP_TASK(copyLayerInto);
316 args->context = mContext;
317 args->layer = layer;
John Reck3731dc22015-04-13 15:20:29 -0700318 args->bitmap = &bitmap;
John Reck19b6bcf2014-02-14 20:03:38 -0800319 return (bool) postAndWait(task);
320}
321
John Reckd72e0a32014-05-29 18:56:11 -0700322void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
323 mDrawFrameTask.pushLayerUpdate(layer);
324}
325
326void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
327 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800328}
329
John Reck918ad522014-06-27 14:45:25 -0700330CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) {
331 args->layer->detachSurfaceTexture();
Chris Craikd41c4d82015-01-05 15:51:13 -0800332 return nullptr;
John Reck918ad522014-06-27 14:45:25 -0700333}
334
335void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
336 SETUP_TASK(detachSurfaceTexture);
337 args->layer = layer;
338 postAndWait(task);
339}
340
John Reck51f2d602016-04-06 07:50:47 -0700341CREATE_BRIDGE2(destroyHardwareResources, CanvasContext* context, TreeObserver* observer) {
342 args->context->destroyHardwareResources(args->observer);
Chris Craikd41c4d82015-01-05 15:51:13 -0800343 return nullptr;
John Recke1628b72014-05-23 15:11:19 -0700344}
345
John Reck51f2d602016-04-06 07:50:47 -0700346void RenderProxy::destroyHardwareResources(TreeObserver* observer) {
John Reckf47a5942014-06-30 16:20:04 -0700347 SETUP_TASK(destroyHardwareResources);
John Recke1628b72014-05-23 15:11:19 -0700348 args->context = mContext;
John Reck51f2d602016-04-06 07:50:47 -0700349 args->observer = observer;
350 postAndWait(task);
John Recke1628b72014-05-23 15:11:19 -0700351}
352
Chris Craik2507c342015-05-04 14:36:49 -0700353CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) {
John Reckf47a5942014-06-30 16:20:04 -0700354 CanvasContext::trimMemory(*args->thread, args->level);
Chris Craikd41c4d82015-01-05 15:51:13 -0800355 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700356}
357
358void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700359 // Avoid creating a RenderThread to do a trimMemory.
360 if (RenderThread::hasInstance()) {
361 RenderThread& thread = RenderThread::getInstance();
Chris Craik2507c342015-05-04 14:36:49 -0700362 SETUP_TASK(trimMemory);
John Reckcd3a22c2014-08-06 13:33:59 -0700363 args->thread = &thread;
364 args->level = level;
365 thread.queue(task);
366 }
John Reckf47a5942014-06-30 16:20:04 -0700367}
368
Chris Craik2507c342015-05-04 14:36:49 -0700369CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) {
370 Properties::overrideProperty(args->name, args->value);
371 return nullptr;
372}
373
374void RenderProxy::overrideProperty(const char* name, const char* value) {
Chris Craik2507c342015-05-04 14:36:49 -0700375 SETUP_TASK(overrideProperty);
376 args->name = name;
377 args->value = value;
378 staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller
379}
380
John Reck28ad7b52014-04-07 16:59:25 -0700381CREATE_BRIDGE0(fence) {
382 // Intentionally empty
Chris Craikd41c4d82015-01-05 15:51:13 -0800383 return nullptr;
John Reck28ad7b52014-04-07 16:59:25 -0700384}
385
Andreas Gampe64bb4132014-11-22 00:35:09 +0000386template <typename T>
387void UNUSED(T t) {}
388
John Reck28ad7b52014-04-07 16:59:25 -0700389void RenderProxy::fence() {
390 SETUP_TASK(fence);
Andreas Gampe1e196742014-11-10 15:23:43 -0800391 UNUSED(args);
John Reck28ad7b52014-04-07 16:59:25 -0700392 postAndWait(task);
393}
394
Thomas Buhotc0a0e1a2016-01-18 10:31:58 +0100395void RenderProxy::staticFence() {
396 SETUP_TASK(fence);
397 UNUSED(args);
398 staticPostAndWait(task);
399}
400
John Reckf47a5942014-06-30 16:20:04 -0700401CREATE_BRIDGE1(stopDrawing, CanvasContext* context) {
402 args->context->stopDrawing();
Chris Craikd41c4d82015-01-05 15:51:13 -0800403 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700404}
405
406void RenderProxy::stopDrawing() {
407 SETUP_TASK(stopDrawing);
408 args->context = mContext;
409 postAndWait(task);
410}
411
John Recka5dda642014-05-22 15:43:54 -0700412CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) {
413 args->context->notifyFramePending();
Chris Craikd41c4d82015-01-05 15:51:13 -0800414 return nullptr;
John Recka5dda642014-05-22 15:43:54 -0700415}
416
417void RenderProxy::notifyFramePending() {
418 SETUP_TASK(notifyFramePending);
419 args->context = mContext;
420 mRenderThread.queueAtFront(task);
421}
422
John Reck7f2e5e32015-05-05 11:00:53 -0700423CREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread,
424 int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700425 args->context->profiler().dumpData(args->fd);
Chris Craik53e51e42015-06-01 10:35:35 -0700426 if (args->dumpFlags & DumpFlags::FrameStats) {
John Reckba6adf62015-02-19 14:36:50 -0800427 args->context->dumpFrames(args->fd);
428 }
Chris Craik53e51e42015-06-01 10:35:35 -0700429 if (args->dumpFlags & DumpFlags::Reset) {
John Reckba6adf62015-02-19 14:36:50 -0800430 args->context->resetFrameStats();
431 }
John Recka41f2442016-04-07 16:36:57 -0700432 if (args->dumpFlags & DumpFlags::JankStats) {
433 args->thread->jankTracker().dump(args->fd);
434 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800435 return nullptr;
John Reckfe5e7b72014-05-23 17:42:28 -0700436}
437
John Reckba6adf62015-02-19 14:36:50 -0800438void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700439 SETUP_TASK(dumpProfileInfo);
440 args->context = mContext;
John Reck7f2e5e32015-05-05 11:00:53 -0700441 args->thread = &mRenderThread;
John Reckfe5e7b72014-05-23 17:42:28 -0700442 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800443 args->dumpFlags = dumpFlags;
John Reckfe5e7b72014-05-23 17:42:28 -0700444 postAndWait(task);
445}
446
John Reck7f2e5e32015-05-05 11:00:53 -0700447CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) {
448 args->context->resetFrameStats();
449 return nullptr;
450}
451
452void RenderProxy::resetProfileInfo() {
453 SETUP_TASK(resetProfileInfo);
454 args->context = mContext;
455 postAndWait(task);
456}
457
John Reckba6adf62015-02-19 14:36:50 -0800458CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) {
459 args->thread->jankTracker().dump(args->fd);
460
Chris Craik2ae07332015-01-21 14:22:39 -0800461 FILE *file = fdopen(args->fd, "a");
462 if (Caches::hasInstance()) {
463 String8 cachesLog;
464 Caches::getInstance().dumpMemoryUsage(cachesLog);
465 fprintf(file, "\nCaches:\n%s\n", cachesLog.string());
466 } else {
467 fprintf(file, "\nNo caches instance.\n");
468 }
Chris Craikff3edce2016-01-14 10:04:08 -0800469#if HWUI_NEW_OPS
470 fprintf(file, "\nPipeline=FrameBuilder\n");
471#else
472 fprintf(file, "\nPipeline=OpenGLRenderer\n");
473#endif
Chris Craik2ae07332015-01-21 14:22:39 -0800474 fflush(file);
Chris Craikd41c4d82015-01-05 15:51:13 -0800475 return nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700476}
477
Chris Craik2ae07332015-01-21 14:22:39 -0800478void RenderProxy::dumpGraphicsMemory(int fd) {
youngmin0822.leec80c9ad2015-03-20 21:22:32 +0900479 if (!RenderThread::hasInstance()) return;
Chris Craik2ae07332015-01-21 14:22:39 -0800480 SETUP_TASK(dumpGraphicsMemory);
John Reck0e89e2b2014-10-31 14:49:06 -0700481 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800482 args->thread = &RenderThread::getInstance();
John Reck0e89e2b2014-10-31 14:49:06 -0700483 staticPostAndWait(task);
484}
485
Skuhneea7a7fb2015-08-28 07:10:31 -0700486CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map,
487 size_t size) {
John Reck3b202512014-06-23 13:13:08 -0700488 CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size);
Chris Craikd41c4d82015-01-05 15:51:13 -0800489 args->buffer->decStrong(nullptr);
490 return nullptr;
John Reck3b202512014-06-23 13:13:08 -0700491}
492
493void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) {
494 SETUP_TASK(setTextureAtlas);
495 args->thread = &mRenderThread;
496 args->buffer = buffer.get();
Chris Craikd41c4d82015-01-05 15:51:13 -0800497 args->buffer->incStrong(nullptr);
John Reck3b202512014-06-23 13:13:08 -0700498 args->map = map;
499 args->size = size;
500 post(task);
501}
502
John Reckedc524c2015-03-18 15:24:33 -0700503CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) {
504 args->thread->jankTracker().switchStorageToAshmem(args->fd);
505 close(args->fd);
506 return nullptr;
507}
508
509void RenderProxy::setProcessStatsBuffer(int fd) {
510 SETUP_TASK(setProcessStatsBuffer);
511 args->thread = &mRenderThread;
512 args->fd = dup(fd);
513 post(task);
514}
515
Skuhneea7a7fb2015-08-28 07:10:31 -0700516CREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) {
517 args->context->addRenderNode(args->node, args->placeFront);
518 return nullptr;
519}
520
521void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) {
522 SETUP_TASK(addRenderNode);
523 args->context = mContext;
524 args->node = node;
525 args->placeFront = placeFront;
526 post(task);
527}
528
529CREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) {
530 args->context->removeRenderNode(args->node);
531 return nullptr;
532}
533
534void RenderProxy::removeRenderNode(RenderNode* node) {
535 SETUP_TASK(removeRenderNode);
536 args->context = mContext;
537 args->node = node;
538 post(task);
539}
540
541CREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) {
542 args->context->prepareAndDraw(args->node);
543 return nullptr;
544}
545
546void RenderProxy::drawRenderNode(RenderNode* node) {
547 SETUP_TASK(drawRenderNode);
548 args->context = mContext;
549 args->node = node;
550 // Be pseudo-thread-safe and don't use any member variables
551 staticPostAndWait(task);
552}
553
Skuhneb8160872015-09-22 09:51:39 -0700554CREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top,
Skuhneea7a7fb2015-08-28 07:10:31 -0700555 int right, int bottom) {
Skuhneb8160872015-09-22 09:51:39 -0700556 args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700557 return nullptr;
558}
559
Skuhneb8160872015-09-22 09:51:39 -0700560void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) {
561 SETUP_TASK(setContentDrawBounds);
Skuhneea7a7fb2015-08-28 07:10:31 -0700562 args->context = mContext;
563 args->left = left;
564 args->top = top;
565 args->right = right;
566 args->bottom = bottom;
567 staticPostAndWait(task);
568}
569
John Recke248bd12015-08-05 13:53:53 -0700570CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) {
571 args->context->serializeDisplayListTree();
572 return nullptr;
573}
574
575void RenderProxy::serializeDisplayListTree() {
576 SETUP_TASK(serializeDisplayListTree);
577 args->context = mContext;
578 post(task);
579}
580
Andres Morales910beb82016-02-02 16:19:40 -0800581CREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context,
582 FrameMetricsObserver* frameStatsObserver) {
583 args->context->addFrameMetricsObserver(args->frameStatsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800584 if (args->frameStatsObserver != nullptr) {
585 args->frameStatsObserver->decStrong(args->context);
586 }
587 return nullptr;
588}
589
Andres Morales910beb82016-02-02 16:19:40 -0800590void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) {
591 SETUP_TASK(addFrameMetricsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800592 args->context = mContext;
593 args->frameStatsObserver = observer;
594 if (observer != nullptr) {
595 observer->incStrong(mContext);
596 }
597 post(task);
598}
599
Andres Morales910beb82016-02-02 16:19:40 -0800600CREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context,
601 FrameMetricsObserver* frameStatsObserver) {
602 args->context->removeFrameMetricsObserver(args->frameStatsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800603 if (args->frameStatsObserver != nullptr) {
604 args->frameStatsObserver->decStrong(args->context);
605 }
606 return nullptr;
607}
608
Andres Morales910beb82016-02-02 16:19:40 -0800609void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) {
610 SETUP_TASK(removeFrameMetricsObserver);
Andres Morales06f5bc72015-12-15 15:21:31 -0800611 args->context = mContext;
612 args->frameStatsObserver = observer;
613 if (observer != nullptr) {
614 observer->incStrong(mContext);
615 }
616 post(task);
617}
618
John Reck4f02bf42014-01-03 18:09:17 -0800619void RenderProxy::post(RenderTask* task) {
620 mRenderThread.queue(task);
621}
622
623void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
624 void* retval;
625 task->setReturnPtr(&retval);
John Reckcba287b2015-11-10 12:52:44 -0800626 SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
627 AutoMutex _lock(mSyncMutex);
628 mRenderThread.queue(&syncTask);
629 mSyncCondition.wait(mSyncMutex);
John Reck4f02bf42014-01-03 18:09:17 -0800630 return retval;
631}
632
John Reck0e89e2b2014-10-31 14:49:06 -0700633void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) {
634 RenderThread& thread = RenderThread::getInstance();
635 void* retval;
636 task->setReturnPtr(&retval);
Chris Craik0a24b142015-10-19 17:10:19 -0700637 thread.queueAndWait(task);
John Reck0e89e2b2014-10-31 14:49:06 -0700638 return retval;
639}
640
John Reck4f02bf42014-01-03 18:09:17 -0800641} /* namespace renderthread */
642} /* namespace uirenderer */
643} /* namespace android */