John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 1 | /* |
| 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 Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 17 | #include "RenderProxy.h" |
| 18 | |
| 19 | #include "CanvasContext.h" |
| 20 | #include "RenderTask.h" |
| 21 | #include "RenderThread.h" |
| 22 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 23 | #include "../DeferredLayerUpdater.h" |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 24 | #include "../DisplayList.h" |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 25 | #include "../LayerRenderer.h" |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 26 | #include "../Rect.h" |
| 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | namespace renderthread { |
| 31 | |
| 32 | #define ARGS(method) method ## Args |
| 33 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 34 | #define CREATE_BRIDGE0(name) CREATE_BRIDGE(name,,,,,,,,) |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 35 | #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 Craik | 797b95b | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 39 | #define CREATE_BRIDGE5(name, a1, a2, a3, a4, a5) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,,,) |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 40 | #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 Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 42 | #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 Salyzyn | 546f353 | 2014-06-10 12:29:14 -0700 | [diff] [blame] | 50 | "METHOD_INVOKE_PAYLOAD_SIZE %zu is smaller than sizeof(" #method "Args) %zu", \ |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 51 | METHOD_INVOKE_PAYLOAD_SIZE, sizeof(ARGS(method))); \ |
John Reck | e2c4552 | 2014-04-07 17:31:44 -0700 | [diff] [blame] | 52 | MethodInvokeRenderTask* task = new MethodInvokeRenderTask((RunnableMethod) Bridge_ ## method); \ |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 53 | ARGS(method) *args = (ARGS(method) *) task->payload() |
| 54 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 55 | CREATE_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 Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 59 | } |
| 60 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 61 | RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory) |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 62 | : mRenderThread(RenderThread::getInstance()) |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 63 | , mContext(nullptr) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 64 | SETUP_TASK(createContext); |
| 65 | args->translucent = translucent; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 66 | args->rootRenderNode = rootRenderNode; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 67 | args->thread = &mRenderThread; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 68 | args->contextFactory = contextFactory; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 69 | mContext = (CanvasContext*) postAndWait(task); |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 70 | mDrawFrameTask.setContext(&mRenderThread, mContext); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | RenderProxy::~RenderProxy() { |
| 74 | destroyContext(); |
| 75 | } |
| 76 | |
| 77 | CREATE_BRIDGE1(destroyContext, CanvasContext* context) { |
| 78 | delete args->context; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 79 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void RenderProxy::destroyContext() { |
| 83 | if (mContext) { |
| 84 | SETUP_TASK(destroyContext); |
| 85 | args->context = mContext; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 86 | mContext = nullptr; |
| 87 | mDrawFrameTask.setContext(nullptr, nullptr); |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 88 | // 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 Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 94 | CREATE_BRIDGE2(setFrameInterval, RenderThread* thread, nsecs_t frameIntervalNanos) { |
| 95 | args->thread->timeLord().setFrameInterval(args->frameIntervalNanos); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 96 | return nullptr; |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void RenderProxy::setFrameInterval(nsecs_t frameIntervalNanos) { |
| 100 | SETUP_TASK(setFrameInterval); |
| 101 | args->thread = &mRenderThread; |
| 102 | args->frameIntervalNanos = frameIntervalNanos; |
| 103 | post(task); |
| 104 | } |
| 105 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 106 | CREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) { |
| 107 | args->context->setSwapBehavior(args->swapBehavior); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 108 | return nullptr; |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) { |
| 112 | SETUP_TASK(setSwapBehavior); |
| 113 | args->context = mContext; |
| 114 | args->swapBehavior = swapBehavior; |
| 115 | post(task); |
| 116 | } |
| 117 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 118 | CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) { |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 119 | bool needsRedraw = false; |
| 120 | if (Caches::hasInstance()) { |
| 121 | needsRedraw = Caches::getInstance().initProperties(); |
| 122 | } |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 123 | if (args->context->profiler().loadSystemProperties()) { |
| 124 | needsRedraw = true; |
| 125 | } |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 126 | return (void*) needsRedraw; |
| 127 | } |
| 128 | |
| 129 | bool RenderProxy::loadSystemProperties() { |
| 130 | SETUP_TASK(loadSystemProperties); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 131 | args->context = mContext; |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 132 | return (bool) postAndWait(task); |
| 133 | } |
| 134 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 135 | CREATE_BRIDGE2(initialize, CanvasContext* context, ANativeWindow* window) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 136 | return (void*) args->context->initialize(args->window); |
| 137 | } |
| 138 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 139 | bool RenderProxy::initialize(const sp<ANativeWindow>& window) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 140 | SETUP_TASK(initialize); |
| 141 | args->context = mContext; |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 142 | args->window = window.get(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 143 | return (bool) postAndWait(task); |
| 144 | } |
| 145 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 146 | CREATE_BRIDGE2(updateSurface, CanvasContext* context, ANativeWindow* window) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 147 | args->context->updateSurface(args->window); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 148 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 149 | } |
| 150 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 151 | void RenderProxy::updateSurface(const sp<ANativeWindow>& window) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 152 | SETUP_TASK(updateSurface); |
| 153 | args->context = mContext; |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 154 | args->window = window.get(); |
| 155 | postAndWait(task); |
| 156 | } |
| 157 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 158 | CREATE_BRIDGE2(pauseSurface, CanvasContext* context, ANativeWindow* window) { |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 159 | return (void*) args->context->pauseSurface(args->window); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 160 | } |
| 161 | |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 162 | bool RenderProxy::pauseSurface(const sp<ANativeWindow>& window) { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 163 | SETUP_TASK(pauseSurface); |
| 164 | args->context = mContext; |
| 165 | args->window = window.get(); |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 166 | return (bool) postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 169 | CREATE_BRIDGE7(setup, CanvasContext* context, int width, int height, |
| 170 | Vector3 lightCenter, float lightRadius, |
| 171 | uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { |
| 172 | args->context->setup(args->width, args->height, args->lightCenter, args->lightRadius, |
| 173 | args->ambientShadowAlpha, args->spotShadowAlpha); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 174 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 177 | void RenderProxy::setup(int width, int height, const Vector3& lightCenter, float lightRadius, |
| 178 | uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 179 | SETUP_TASK(setup); |
| 180 | args->context = mContext; |
| 181 | args->width = width; |
| 182 | args->height = height; |
Chris Craik | 797b95b | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 183 | args->lightCenter = lightCenter; |
| 184 | args->lightRadius = lightRadius; |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 185 | args->ambientShadowAlpha = ambientShadowAlpha; |
| 186 | args->spotShadowAlpha = spotShadowAlpha; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 187 | post(task); |
| 188 | } |
| 189 | |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 190 | CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) { |
| 191 | args->context->setOpaque(args->opaque); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 192 | return nullptr; |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void RenderProxy::setOpaque(bool opaque) { |
| 196 | SETUP_TASK(setOpaque); |
| 197 | args->context = mContext; |
| 198 | args->opaque = opaque; |
| 199 | post(task); |
| 200 | } |
| 201 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 202 | int RenderProxy::syncAndDrawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos, |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 203 | float density) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 204 | mDrawFrameTask.setDensity(density); |
| 205 | return mDrawFrameTask.drawFrame(frameTimeNanos, recordDurationNanos); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 206 | } |
| 207 | |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 208 | CREATE_BRIDGE1(destroy, CanvasContext* context) { |
| 209 | args->context->destroy(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 210 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 211 | } |
| 212 | |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 213 | void RenderProxy::destroy() { |
| 214 | SETUP_TASK(destroy); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 215 | args->context = mContext; |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 216 | // destroyCanvasAndSurface() needs a fence as when it returns the |
| 217 | // underlying BufferQueue is going to be released from under |
| 218 | // the render thread. |
| 219 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 220 | } |
| 221 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 222 | CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) { |
| 223 | CanvasContext::invokeFunctor(*args->thread, args->functor); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 224 | return nullptr; |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) { |
John Reck | d3d8daf | 2014-04-10 15:00:13 -0700 | [diff] [blame] | 228 | ATRACE_CALL(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 229 | RenderThread& thread = RenderThread::getInstance(); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 230 | SETUP_TASK(invokeFunctor); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 231 | args->thread = &thread; |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 232 | args->functor = functor; |
| 233 | if (waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 234 | // waitForCompletion = true is expected to be fairly rare and only |
| 235 | // happen in destruction. Thus it should be fine to temporarily |
| 236 | // create a Mutex |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 237 | staticPostAndWait(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 238 | } else { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 239 | thread.queue(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 243 | CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) { |
| 244 | args->context->runWithGlContext(args->task); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 245 | return nullptr; |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void RenderProxy::runWithGlContext(RenderTask* gltask) { |
| 249 | SETUP_TASK(runWithGlContext); |
| 250 | args->context = mContext; |
| 251 | args->task = gltask; |
| 252 | postAndWait(task); |
| 253 | } |
| 254 | |
John Reck | 749906b | 2014-10-03 15:02:19 -0700 | [diff] [blame] | 255 | CREATE_BRIDGE2(createTextureLayer, RenderThread* thread, CanvasContext* context) { |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 256 | Layer* layer = args->context->createTextureLayer(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 257 | if (!layer) return nullptr; |
John Reck | 749906b | 2014-10-03 15:02:19 -0700 | [diff] [blame] | 258 | return new DeferredLayerUpdater(*args->thread, layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | DeferredLayerUpdater* RenderProxy::createTextureLayer() { |
| 262 | SETUP_TASK(createTextureLayer); |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 263 | args->context = mContext; |
John Reck | 749906b | 2014-10-03 15:02:19 -0700 | [diff] [blame] | 264 | args->thread = &mRenderThread; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 265 | void* retval = postAndWait(task); |
| 266 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 267 | return layer; |
| 268 | } |
| 269 | |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 270 | CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) { |
| 271 | args->context->buildLayer(args->node); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 272 | return nullptr; |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void RenderProxy::buildLayer(RenderNode* node) { |
| 276 | SETUP_TASK(buildLayer); |
| 277 | args->context = mContext; |
| 278 | args->node = node; |
| 279 | postAndWait(task); |
| 280 | } |
| 281 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 282 | CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer, |
| 283 | SkBitmap* bitmap) { |
| 284 | bool success = args->context->copyLayerInto(args->layer, args->bitmap); |
| 285 | return (void*) success; |
| 286 | } |
| 287 | |
| 288 | bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) { |
| 289 | SETUP_TASK(copyLayerInto); |
| 290 | args->context = mContext; |
| 291 | args->layer = layer; |
| 292 | args->bitmap = bitmap; |
| 293 | return (bool) postAndWait(task); |
| 294 | } |
| 295 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 296 | void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) { |
| 297 | mDrawFrameTask.pushLayerUpdate(layer); |
| 298 | } |
| 299 | |
| 300 | void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) { |
| 301 | mDrawFrameTask.removeLayerUpdate(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 302 | } |
| 303 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 304 | CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) { |
| 305 | args->layer->detachSurfaceTexture(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 306 | return nullptr; |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) { |
| 310 | SETUP_TASK(detachSurfaceTexture); |
| 311 | args->layer = layer; |
| 312 | postAndWait(task); |
| 313 | } |
| 314 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 315 | CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) { |
| 316 | args->context->destroyHardwareResources(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 317 | return nullptr; |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 318 | } |
| 319 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 320 | void RenderProxy::destroyHardwareResources() { |
| 321 | SETUP_TASK(destroyHardwareResources); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 322 | args->context = mContext; |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 323 | post(task); |
| 324 | } |
| 325 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 326 | CREATE_BRIDGE2(timMemory, RenderThread* thread, int level) { |
| 327 | CanvasContext::trimMemory(*args->thread, args->level); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 328 | return nullptr; |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | void RenderProxy::trimMemory(int level) { |
John Reck | cd3a22c | 2014-08-06 13:33:59 -0700 | [diff] [blame] | 332 | // Avoid creating a RenderThread to do a trimMemory. |
| 333 | if (RenderThread::hasInstance()) { |
| 334 | RenderThread& thread = RenderThread::getInstance(); |
| 335 | SETUP_TASK(timMemory); |
| 336 | args->thread = &thread; |
| 337 | args->level = level; |
| 338 | thread.queue(task); |
| 339 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 340 | } |
| 341 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 342 | CREATE_BRIDGE0(fence) { |
| 343 | // Intentionally empty |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 344 | return nullptr; |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 347 | template <typename T> |
| 348 | void UNUSED(T t) {} |
| 349 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 350 | void RenderProxy::fence() { |
| 351 | SETUP_TASK(fence); |
Andreas Gampe | 1e19674 | 2014-11-10 15:23:43 -0800 | [diff] [blame] | 352 | UNUSED(args); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 353 | postAndWait(task); |
| 354 | } |
| 355 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 356 | CREATE_BRIDGE1(stopDrawing, CanvasContext* context) { |
| 357 | args->context->stopDrawing(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 358 | return nullptr; |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | void RenderProxy::stopDrawing() { |
| 362 | SETUP_TASK(stopDrawing); |
| 363 | args->context = mContext; |
| 364 | postAndWait(task); |
| 365 | } |
| 366 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 367 | CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) { |
| 368 | args->context->notifyFramePending(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 369 | return nullptr; |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void RenderProxy::notifyFramePending() { |
| 373 | SETUP_TASK(notifyFramePending); |
| 374 | args->context = mContext; |
| 375 | mRenderThread.queueAtFront(task); |
| 376 | } |
| 377 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 378 | CREATE_BRIDGE2(dumpProfileInfo, CanvasContext* context, int fd) { |
| 379 | args->context->profiler().dumpData(args->fd); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 380 | return nullptr; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void RenderProxy::dumpProfileInfo(int fd) { |
| 384 | SETUP_TASK(dumpProfileInfo); |
| 385 | args->context = mContext; |
| 386 | args->fd = fd; |
| 387 | postAndWait(task); |
| 388 | } |
| 389 | |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 390 | CREATE_BRIDGE1(dumpGraphicsMemory, int fd) { |
| 391 | FILE *file = fdopen(args->fd, "a"); |
| 392 | if (Caches::hasInstance()) { |
| 393 | String8 cachesLog; |
| 394 | Caches::getInstance().dumpMemoryUsage(cachesLog); |
| 395 | fprintf(file, "\nCaches:\n%s\n", cachesLog.string()); |
| 396 | } else { |
| 397 | fprintf(file, "\nNo caches instance.\n"); |
| 398 | } |
| 399 | fflush(file); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 400 | return nullptr; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 403 | void RenderProxy::dumpGraphicsMemory(int fd) { |
| 404 | SETUP_TASK(dumpGraphicsMemory); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 405 | args->fd = fd; |
| 406 | staticPostAndWait(task); |
| 407 | } |
| 408 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 409 | CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map, size_t size) { |
| 410 | CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 411 | args->buffer->decStrong(nullptr); |
| 412 | return nullptr; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) { |
| 416 | SETUP_TASK(setTextureAtlas); |
| 417 | args->thread = &mRenderThread; |
| 418 | args->buffer = buffer.get(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 419 | args->buffer->incStrong(nullptr); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 420 | args->map = map; |
| 421 | args->size = size; |
| 422 | post(task); |
| 423 | } |
| 424 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 425 | void RenderProxy::post(RenderTask* task) { |
| 426 | mRenderThread.queue(task); |
| 427 | } |
| 428 | |
| 429 | void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { |
| 430 | void* retval; |
| 431 | task->setReturnPtr(&retval); |
| 432 | SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); |
| 433 | AutoMutex _lock(mSyncMutex); |
Chris Craik | 738ec3a | 2014-07-25 18:25:02 +0000 | [diff] [blame] | 434 | mRenderThread.queue(&syncTask); |
| 435 | mSyncCondition.wait(mSyncMutex); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 436 | return retval; |
| 437 | } |
| 438 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 439 | void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) { |
| 440 | RenderThread& thread = RenderThread::getInstance(); |
| 441 | void* retval; |
| 442 | task->setReturnPtr(&retval); |
| 443 | Mutex mutex; |
| 444 | Condition condition; |
| 445 | SignalingRenderTask syncTask(task, &mutex, &condition); |
| 446 | AutoMutex _lock(mutex); |
| 447 | thread.queue(&syncTask); |
| 448 | condition.wait(mutex); |
| 449 | return retval; |
| 450 | } |
| 451 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 452 | } /* namespace renderthread */ |
| 453 | } /* namespace uirenderer */ |
| 454 | } /* namespace android */ |