blob: 0fa2f23b97525803ac14d7805667fdf56b256f65 [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 Reckc87be992015-02-20 10:57:22 -080055enum class DumpFlags {
John Reckba6adf62015-02-19 14:36:50 -080056 kFrameStats = 1 << 0,
57 kReset = 1 << 1,
John Reckc87be992015-02-20 10:57:22 -080058};
59MAKE_FLAGS_ENUM(DumpFlags)
John Reckba6adf62015-02-19 14:36:50 -080060
John Reck119907c2014-08-14 09:02:01 -070061CREATE_BRIDGE4(createContext, RenderThread* thread, bool translucent,
62 RenderNode* rootRenderNode, IContextFactory* contextFactory) {
63 return new CanvasContext(*args->thread, args->translucent,
64 args->rootRenderNode, args->contextFactory);
John Reck4f02bf42014-01-03 18:09:17 -080065}
66
John Reck119907c2014-08-14 09:02:01 -070067RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory)
John Reck4f02bf42014-01-03 18:09:17 -080068 : mRenderThread(RenderThread::getInstance())
Chris Craikd41c4d82015-01-05 15:51:13 -080069 , mContext(nullptr) {
John Reck4f02bf42014-01-03 18:09:17 -080070 SETUP_TASK(createContext);
71 args->translucent = translucent;
John Recke45b1fd2014-04-15 09:50:16 -070072 args->rootRenderNode = rootRenderNode;
John Reck3b202512014-06-23 13:13:08 -070073 args->thread = &mRenderThread;
John Reck119907c2014-08-14 09:02:01 -070074 args->contextFactory = contextFactory;
John Reck4f02bf42014-01-03 18:09:17 -080075 mContext = (CanvasContext*) postAndWait(task);
John Reck18f16e62014-05-02 16:46:41 -070076 mDrawFrameTask.setContext(&mRenderThread, mContext);
John Reck4f02bf42014-01-03 18:09:17 -080077}
78
79RenderProxy::~RenderProxy() {
80 destroyContext();
81}
82
83CREATE_BRIDGE1(destroyContext, CanvasContext* context) {
84 delete args->context;
Chris Craikd41c4d82015-01-05 15:51:13 -080085 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -080086}
87
88void RenderProxy::destroyContext() {
89 if (mContext) {
90 SETUP_TASK(destroyContext);
91 args->context = mContext;
Chris Craikd41c4d82015-01-05 15:51:13 -080092 mContext = nullptr;
93 mDrawFrameTask.setContext(nullptr, nullptr);
John Reck668f0e32014-03-26 15:10:40 -070094 // This is also a fence as we need to be certain that there are no
95 // outstanding mDrawFrame tasks posted before it is destroyed
96 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -080097 }
98}
99
John Reck18f16e62014-05-02 16:46:41 -0700100CREATE_BRIDGE2(setFrameInterval, RenderThread* thread, nsecs_t frameIntervalNanos) {
John Reckba6adf62015-02-19 14:36:50 -0800101 args->thread->setFrameInterval(args->frameIntervalNanos);
Chris Craikd41c4d82015-01-05 15:51:13 -0800102 return nullptr;
John Reck18f16e62014-05-02 16:46:41 -0700103}
104
105void RenderProxy::setFrameInterval(nsecs_t frameIntervalNanos) {
106 SETUP_TASK(setFrameInterval);
107 args->thread = &mRenderThread;
108 args->frameIntervalNanos = frameIntervalNanos;
109 post(task);
110}
111
John Reck1125d1f2014-10-23 11:02:19 -0700112CREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) {
113 args->context->setSwapBehavior(args->swapBehavior);
Chris Craikd41c4d82015-01-05 15:51:13 -0800114 return nullptr;
John Reck1125d1f2014-10-23 11:02:19 -0700115}
116
117void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) {
118 SETUP_TASK(setSwapBehavior);
119 args->context = mContext;
120 args->swapBehavior = swapBehavior;
121 post(task);
122}
123
John Reckfe5e7b72014-05-23 17:42:28 -0700124CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) {
John Recke4280ba2014-05-05 16:39:37 -0700125 bool needsRedraw = false;
126 if (Caches::hasInstance()) {
127 needsRedraw = Caches::getInstance().initProperties();
128 }
John Reckfe5e7b72014-05-23 17:42:28 -0700129 if (args->context->profiler().loadSystemProperties()) {
130 needsRedraw = true;
131 }
John Recke4280ba2014-05-05 16:39:37 -0700132 return (void*) needsRedraw;
133}
134
135bool RenderProxy::loadSystemProperties() {
136 SETUP_TASK(loadSystemProperties);
John Reckfe5e7b72014-05-23 17:42:28 -0700137 args->context = mContext;
John Recke4280ba2014-05-05 16:39:37 -0700138 return (bool) postAndWait(task);
139}
140
John Recka5dda642014-05-22 15:43:54 -0700141CREATE_BRIDGE2(initialize, CanvasContext* context, ANativeWindow* window) {
John Reck4f02bf42014-01-03 18:09:17 -0800142 return (void*) args->context->initialize(args->window);
143}
144
John Reckf7d9c1d2014-04-09 10:01:03 -0700145bool RenderProxy::initialize(const sp<ANativeWindow>& window) {
John Reck4f02bf42014-01-03 18:09:17 -0800146 SETUP_TASK(initialize);
147 args->context = mContext;
John Reckf7d9c1d2014-04-09 10:01:03 -0700148 args->window = window.get();
John Reck4f02bf42014-01-03 18:09:17 -0800149 return (bool) postAndWait(task);
150}
151
John Recka5dda642014-05-22 15:43:54 -0700152CREATE_BRIDGE2(updateSurface, CanvasContext* context, ANativeWindow* window) {
John Reck4f02bf42014-01-03 18:09:17 -0800153 args->context->updateSurface(args->window);
Chris Craikd41c4d82015-01-05 15:51:13 -0800154 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800155}
156
John Reckf7d9c1d2014-04-09 10:01:03 -0700157void RenderProxy::updateSurface(const sp<ANativeWindow>& window) {
John Reck4f02bf42014-01-03 18:09:17 -0800158 SETUP_TASK(updateSurface);
159 args->context = mContext;
John Reckf7d9c1d2014-04-09 10:01:03 -0700160 args->window = window.get();
161 postAndWait(task);
162}
163
John Recka5dda642014-05-22 15:43:54 -0700164CREATE_BRIDGE2(pauseSurface, CanvasContext* context, ANativeWindow* window) {
John Reck01a5ea32014-12-03 13:01:07 -0800165 return (void*) args->context->pauseSurface(args->window);
John Reckf7d9c1d2014-04-09 10:01:03 -0700166}
167
John Reck01a5ea32014-12-03 13:01:07 -0800168bool RenderProxy::pauseSurface(const sp<ANativeWindow>& window) {
John Reckf7d9c1d2014-04-09 10:01:03 -0700169 SETUP_TASK(pauseSurface);
170 args->context = mContext;
171 args->window = window.get();
John Reck01a5ea32014-12-03 13:01:07 -0800172 return (bool) postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800173}
174
Chris Craik058fc642014-07-23 18:19:28 -0700175CREATE_BRIDGE7(setup, CanvasContext* context, int width, int height,
176 Vector3 lightCenter, float lightRadius,
177 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
178 args->context->setup(args->width, args->height, args->lightCenter, args->lightRadius,
179 args->ambientShadowAlpha, args->spotShadowAlpha);
Chris Craikd41c4d82015-01-05 15:51:13 -0800180 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800181}
182
Chris Craik058fc642014-07-23 18:19:28 -0700183void RenderProxy::setup(int width, int height, const Vector3& lightCenter, float lightRadius,
John Reckba6adf62015-02-19 14:36:50 -0800184 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha, float density) {
185 mDrawFrameTask.setDensity(density);
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->lightCenter = lightCenter;
191 args->lightRadius = lightRadius;
Chris Craik058fc642014-07-23 18:19:28 -0700192 args->ambientShadowAlpha = ambientShadowAlpha;
193 args->spotShadowAlpha = spotShadowAlpha;
John Reck4f02bf42014-01-03 18:09:17 -0800194 post(task);
195}
196
John Reck63a06672014-05-07 13:45:54 -0700197CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) {
198 args->context->setOpaque(args->opaque);
Chris Craikd41c4d82015-01-05 15:51:13 -0800199 return nullptr;
John Reck63a06672014-05-07 13:45:54 -0700200}
201
202void RenderProxy::setOpaque(bool opaque) {
203 SETUP_TASK(setOpaque);
204 args->context = mContext;
205 args->opaque = opaque;
206 post(task);
207}
208
John Reckba6adf62015-02-19 14:36:50 -0800209int64_t* RenderProxy::frameInfo() {
210 return mDrawFrameTask.frameInfo();
211}
212
213int RenderProxy::syncAndDrawFrame() {
214 return mDrawFrameTask.drawFrame();
John Reck4f02bf42014-01-03 18:09:17 -0800215}
216
John Reck17035b02014-09-03 07:39:53 -0700217CREATE_BRIDGE1(destroy, CanvasContext* context) {
218 args->context->destroy();
Chris Craikd41c4d82015-01-05 15:51:13 -0800219 return nullptr;
John Reck4f02bf42014-01-03 18:09:17 -0800220}
221
John Reck17035b02014-09-03 07:39:53 -0700222void RenderProxy::destroy() {
223 SETUP_TASK(destroy);
John Reck4f02bf42014-01-03 18:09:17 -0800224 args->context = mContext;
John Reckfae904d2014-04-14 11:01:57 -0700225 // destroyCanvasAndSurface() needs a fence as when it returns the
226 // underlying BufferQueue is going to be released from under
227 // the render thread.
228 postAndWait(task);
John Reck4f02bf42014-01-03 18:09:17 -0800229}
230
John Reck3b202512014-06-23 13:13:08 -0700231CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) {
232 CanvasContext::invokeFunctor(*args->thread, args->functor);
Chris Craikd41c4d82015-01-05 15:51:13 -0800233 return nullptr;
John Reck0d1f6342014-03-28 20:30:27 -0700234}
235
236void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
John Reckd3d8daf2014-04-10 15:00:13 -0700237 ATRACE_CALL();
John Reck3b202512014-06-23 13:13:08 -0700238 RenderThread& thread = RenderThread::getInstance();
John Reck0d1f6342014-03-28 20:30:27 -0700239 SETUP_TASK(invokeFunctor);
John Reck3b202512014-06-23 13:13:08 -0700240 args->thread = &thread;
John Reck0d1f6342014-03-28 20:30:27 -0700241 args->functor = functor;
242 if (waitForCompletion) {
John Reck3b202512014-06-23 13:13:08 -0700243 // waitForCompletion = true is expected to be fairly rare and only
244 // happen in destruction. Thus it should be fine to temporarily
245 // create a Mutex
John Reck0e89e2b2014-10-31 14:49:06 -0700246 staticPostAndWait(task);
John Reck0d1f6342014-03-28 20:30:27 -0700247 } else {
John Reck3b202512014-06-23 13:13:08 -0700248 thread.queue(task);
John Reck0d1f6342014-03-28 20:30:27 -0700249 }
250}
251
John Reckfc53ef272014-02-11 10:40:25 -0800252CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) {
253 args->context->runWithGlContext(args->task);
Chris Craikd41c4d82015-01-05 15:51:13 -0800254 return nullptr;
John Reckfc53ef272014-02-11 10:40:25 -0800255}
256
257void RenderProxy::runWithGlContext(RenderTask* gltask) {
258 SETUP_TASK(runWithGlContext);
259 args->context = mContext;
260 args->task = gltask;
261 postAndWait(task);
262}
263
John Reck749906b2014-10-03 15:02:19 -0700264CREATE_BRIDGE2(createTextureLayer, RenderThread* thread, CanvasContext* context) {
John Reck1949e792014-04-08 15:18:56 -0700265 Layer* layer = args->context->createTextureLayer();
Chris Craikd41c4d82015-01-05 15:51:13 -0800266 if (!layer) return nullptr;
John Reck749906b2014-10-03 15:02:19 -0700267 return new DeferredLayerUpdater(*args->thread, layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800268}
269
270DeferredLayerUpdater* RenderProxy::createTextureLayer() {
271 SETUP_TASK(createTextureLayer);
John Reck1949e792014-04-08 15:18:56 -0700272 args->context = mContext;
John Reck749906b2014-10-03 15:02:19 -0700273 args->thread = &mRenderThread;
John Reck19b6bcf2014-02-14 20:03:38 -0800274 void* retval = postAndWait(task);
275 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval);
John Reck19b6bcf2014-02-14 20:03:38 -0800276 return layer;
277}
278
John Reck3e824952014-08-20 10:08:39 -0700279CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) {
280 args->context->buildLayer(args->node);
Chris Craikd41c4d82015-01-05 15:51:13 -0800281 return nullptr;
John Reck3e824952014-08-20 10:08:39 -0700282}
283
284void RenderProxy::buildLayer(RenderNode* node) {
285 SETUP_TASK(buildLayer);
286 args->context = mContext;
287 args->node = node;
288 postAndWait(task);
289}
290
John Reck19b6bcf2014-02-14 20:03:38 -0800291CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer,
292 SkBitmap* bitmap) {
293 bool success = args->context->copyLayerInto(args->layer, args->bitmap);
294 return (void*) success;
295}
296
297bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) {
298 SETUP_TASK(copyLayerInto);
299 args->context = mContext;
300 args->layer = layer;
301 args->bitmap = bitmap;
302 return (bool) postAndWait(task);
303}
304
John Reckd72e0a32014-05-29 18:56:11 -0700305void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) {
306 mDrawFrameTask.pushLayerUpdate(layer);
307}
308
309void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
310 mDrawFrameTask.removeLayerUpdate(layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800311}
312
John Reck918ad522014-06-27 14:45:25 -0700313CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) {
314 args->layer->detachSurfaceTexture();
Chris Craikd41c4d82015-01-05 15:51:13 -0800315 return nullptr;
John Reck918ad522014-06-27 14:45:25 -0700316}
317
318void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
319 SETUP_TASK(detachSurfaceTexture);
320 args->layer = layer;
321 postAndWait(task);
322}
323
John Reckf47a5942014-06-30 16:20:04 -0700324CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) {
325 args->context->destroyHardwareResources();
Chris Craikd41c4d82015-01-05 15:51:13 -0800326 return nullptr;
John Recke1628b72014-05-23 15:11:19 -0700327}
328
John Reckf47a5942014-06-30 16:20:04 -0700329void RenderProxy::destroyHardwareResources() {
330 SETUP_TASK(destroyHardwareResources);
John Recke1628b72014-05-23 15:11:19 -0700331 args->context = mContext;
John Recke1628b72014-05-23 15:11:19 -0700332 post(task);
333}
334
John Reckf47a5942014-06-30 16:20:04 -0700335CREATE_BRIDGE2(timMemory, RenderThread* thread, int level) {
336 CanvasContext::trimMemory(*args->thread, args->level);
Chris Craikd41c4d82015-01-05 15:51:13 -0800337 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700338}
339
340void RenderProxy::trimMemory(int level) {
John Reckcd3a22c2014-08-06 13:33:59 -0700341 // Avoid creating a RenderThread to do a trimMemory.
342 if (RenderThread::hasInstance()) {
343 RenderThread& thread = RenderThread::getInstance();
344 SETUP_TASK(timMemory);
345 args->thread = &thread;
346 args->level = level;
347 thread.queue(task);
348 }
John Reckf47a5942014-06-30 16:20:04 -0700349}
350
John Reck28ad7b52014-04-07 16:59:25 -0700351CREATE_BRIDGE0(fence) {
352 // Intentionally empty
Chris Craikd41c4d82015-01-05 15:51:13 -0800353 return nullptr;
John Reck28ad7b52014-04-07 16:59:25 -0700354}
355
Andreas Gampe64bb4132014-11-22 00:35:09 +0000356template <typename T>
357void UNUSED(T t) {}
358
John Reck28ad7b52014-04-07 16:59:25 -0700359void RenderProxy::fence() {
360 SETUP_TASK(fence);
Andreas Gampe1e196742014-11-10 15:23:43 -0800361 UNUSED(args);
John Reck28ad7b52014-04-07 16:59:25 -0700362 postAndWait(task);
363}
364
John Reckf47a5942014-06-30 16:20:04 -0700365CREATE_BRIDGE1(stopDrawing, CanvasContext* context) {
366 args->context->stopDrawing();
Chris Craikd41c4d82015-01-05 15:51:13 -0800367 return nullptr;
John Reckf47a5942014-06-30 16:20:04 -0700368}
369
370void RenderProxy::stopDrawing() {
371 SETUP_TASK(stopDrawing);
372 args->context = mContext;
373 postAndWait(task);
374}
375
John Recka5dda642014-05-22 15:43:54 -0700376CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) {
377 args->context->notifyFramePending();
Chris Craikd41c4d82015-01-05 15:51:13 -0800378 return nullptr;
John Recka5dda642014-05-22 15:43:54 -0700379}
380
381void RenderProxy::notifyFramePending() {
382 SETUP_TASK(notifyFramePending);
383 args->context = mContext;
384 mRenderThread.queueAtFront(task);
385}
386
John Reckba6adf62015-02-19 14:36:50 -0800387CREATE_BRIDGE3(dumpProfileInfo, CanvasContext* context, int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700388 args->context->profiler().dumpData(args->fd);
John Reckba6adf62015-02-19 14:36:50 -0800389 if (args->dumpFlags & DumpFlags::kFrameStats) {
390 args->context->dumpFrames(args->fd);
391 }
392 if (args->dumpFlags & DumpFlags::kReset) {
393 args->context->resetFrameStats();
394 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800395 return nullptr;
John Reckfe5e7b72014-05-23 17:42:28 -0700396}
397
John Reckba6adf62015-02-19 14:36:50 -0800398void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
John Reckfe5e7b72014-05-23 17:42:28 -0700399 SETUP_TASK(dumpProfileInfo);
400 args->context = mContext;
401 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800402 args->dumpFlags = dumpFlags;
John Reckfe5e7b72014-05-23 17:42:28 -0700403 postAndWait(task);
404}
405
John Reckba6adf62015-02-19 14:36:50 -0800406CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) {
407 args->thread->jankTracker().dump(args->fd);
408
Chris Craik2ae07332015-01-21 14:22:39 -0800409 FILE *file = fdopen(args->fd, "a");
410 if (Caches::hasInstance()) {
411 String8 cachesLog;
412 Caches::getInstance().dumpMemoryUsage(cachesLog);
413 fprintf(file, "\nCaches:\n%s\n", cachesLog.string());
414 } else {
415 fprintf(file, "\nNo caches instance.\n");
416 }
417 fflush(file);
Chris Craikd41c4d82015-01-05 15:51:13 -0800418 return nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700419}
420
Chris Craik2ae07332015-01-21 14:22:39 -0800421void RenderProxy::dumpGraphicsMemory(int fd) {
422 SETUP_TASK(dumpGraphicsMemory);
John Reck0e89e2b2014-10-31 14:49:06 -0700423 args->fd = fd;
John Reckba6adf62015-02-19 14:36:50 -0800424 args->thread = &RenderThread::getInstance();
John Reck0e89e2b2014-10-31 14:49:06 -0700425 staticPostAndWait(task);
426}
427
John Reck3b202512014-06-23 13:13:08 -0700428CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map, size_t size) {
429 CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size);
Chris Craikd41c4d82015-01-05 15:51:13 -0800430 args->buffer->decStrong(nullptr);
431 return nullptr;
John Reck3b202512014-06-23 13:13:08 -0700432}
433
434void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) {
435 SETUP_TASK(setTextureAtlas);
436 args->thread = &mRenderThread;
437 args->buffer = buffer.get();
Chris Craikd41c4d82015-01-05 15:51:13 -0800438 args->buffer->incStrong(nullptr);
John Reck3b202512014-06-23 13:13:08 -0700439 args->map = map;
440 args->size = size;
441 post(task);
442}
443
John Reck4f02bf42014-01-03 18:09:17 -0800444void RenderProxy::post(RenderTask* task) {
445 mRenderThread.queue(task);
446}
447
448void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
449 void* retval;
450 task->setReturnPtr(&retval);
451 SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
452 AutoMutex _lock(mSyncMutex);
Chris Craik738ec3a2014-07-25 18:25:02 +0000453 mRenderThread.queue(&syncTask);
454 mSyncCondition.wait(mSyncMutex);
John Reck4f02bf42014-01-03 18:09:17 -0800455 return retval;
456}
457
John Reck0e89e2b2014-10-31 14:49:06 -0700458void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) {
459 RenderThread& thread = RenderThread::getInstance();
460 void* retval;
461 task->setReturnPtr(&retval);
462 Mutex mutex;
463 Condition condition;
464 SignalingRenderTask syncTask(task, &mutex, &condition);
465 AutoMutex _lock(mutex);
466 thread.queue(&syncTask);
467 condition.wait(mutex);
468 return retval;
469}
470
John Reck4f02bf42014-01-03 18:09:17 -0800471} /* namespace renderthread */
472} /* namespace uirenderer */
473} /* namespace android */