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 | 797b95b2 | 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()) |
| 63 | , mContext(0) { |
| 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; |
| 79 | return NULL; |
| 80 | } |
| 81 | |
| 82 | void RenderProxy::destroyContext() { |
| 83 | if (mContext) { |
| 84 | SETUP_TASK(destroyContext); |
| 85 | args->context = mContext; |
| 86 | mContext = 0; |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 87 | mDrawFrameTask.setContext(NULL, NULL); |
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); |
| 96 | return NULL; |
| 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); |
| 108 | return NULL; |
| 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); |
| 148 | return NULL; |
| 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 | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 159 | args->context->pauseSurface(args->window); |
| 160 | return NULL; |
| 161 | } |
| 162 | |
| 163 | void RenderProxy::pauseSurface(const sp<ANativeWindow>& window) { |
| 164 | SETUP_TASK(pauseSurface); |
| 165 | args->context = mContext; |
| 166 | args->window = window.get(); |
| 167 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 170 | CREATE_BRIDGE7(setup, CanvasContext* context, int width, int height, |
| 171 | Vector3 lightCenter, float lightRadius, |
| 172 | uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { |
| 173 | args->context->setup(args->width, args->height, args->lightCenter, args->lightRadius, |
| 174 | args->ambientShadowAlpha, args->spotShadowAlpha); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 175 | return NULL; |
| 176 | } |
| 177 | |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 178 | void RenderProxy::setup(int width, int height, const Vector3& lightCenter, float lightRadius, |
| 179 | uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 180 | SETUP_TASK(setup); |
| 181 | args->context = mContext; |
| 182 | args->width = width; |
| 183 | args->height = height; |
Chris Craik | 797b95b2 | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 184 | args->lightCenter = lightCenter; |
| 185 | args->lightRadius = lightRadius; |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 186 | args->ambientShadowAlpha = ambientShadowAlpha; |
| 187 | args->spotShadowAlpha = spotShadowAlpha; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 188 | post(task); |
| 189 | } |
| 190 | |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 191 | CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) { |
| 192 | args->context->setOpaque(args->opaque); |
| 193 | return NULL; |
| 194 | } |
| 195 | |
| 196 | void RenderProxy::setOpaque(bool opaque) { |
| 197 | SETUP_TASK(setOpaque); |
| 198 | args->context = mContext; |
| 199 | args->opaque = opaque; |
| 200 | post(task); |
| 201 | } |
| 202 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 203 | int RenderProxy::syncAndDrawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos, |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 204 | float density) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 205 | mDrawFrameTask.setDensity(density); |
| 206 | return mDrawFrameTask.drawFrame(frameTimeNanos, recordDurationNanos); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 207 | } |
| 208 | |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 209 | CREATE_BRIDGE1(destroy, CanvasContext* context) { |
| 210 | args->context->destroy(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 211 | return NULL; |
| 212 | } |
| 213 | |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 214 | void RenderProxy::destroy() { |
| 215 | SETUP_TASK(destroy); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 216 | args->context = mContext; |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 217 | // destroyCanvasAndSurface() needs a fence as when it returns the |
| 218 | // underlying BufferQueue is going to be released from under |
| 219 | // the render thread. |
| 220 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 221 | } |
| 222 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 223 | CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) { |
| 224 | CanvasContext::invokeFunctor(*args->thread, args->functor); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 225 | return NULL; |
| 226 | } |
| 227 | |
| 228 | void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) { |
John Reck | d3d8daf | 2014-04-10 15:00:13 -0700 | [diff] [blame] | 229 | ATRACE_CALL(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 230 | RenderThread& thread = RenderThread::getInstance(); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 231 | SETUP_TASK(invokeFunctor); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 232 | args->thread = &thread; |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 233 | args->functor = functor; |
| 234 | if (waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 235 | // waitForCompletion = true is expected to be fairly rare and only |
| 236 | // happen in destruction. Thus it should be fine to temporarily |
| 237 | // create a Mutex |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame^] | 238 | staticPostAndWait(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 239 | } else { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 240 | thread.queue(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 244 | CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) { |
| 245 | args->context->runWithGlContext(args->task); |
| 246 | return NULL; |
| 247 | } |
| 248 | |
| 249 | void RenderProxy::runWithGlContext(RenderTask* gltask) { |
| 250 | SETUP_TASK(runWithGlContext); |
| 251 | args->context = mContext; |
| 252 | args->task = gltask; |
| 253 | postAndWait(task); |
| 254 | } |
| 255 | |
John Reck | 749906b | 2014-10-03 15:02:19 -0700 | [diff] [blame] | 256 | CREATE_BRIDGE2(createTextureLayer, RenderThread* thread, CanvasContext* context) { |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 257 | Layer* layer = args->context->createTextureLayer(); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 258 | if (!layer) return 0; |
John Reck | 749906b | 2014-10-03 15:02:19 -0700 | [diff] [blame] | 259 | return new DeferredLayerUpdater(*args->thread, layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | DeferredLayerUpdater* RenderProxy::createTextureLayer() { |
| 263 | SETUP_TASK(createTextureLayer); |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 264 | args->context = mContext; |
John Reck | 749906b | 2014-10-03 15:02:19 -0700 | [diff] [blame] | 265 | args->thread = &mRenderThread; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 266 | void* retval = postAndWait(task); |
| 267 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 268 | return layer; |
| 269 | } |
| 270 | |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 271 | CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) { |
| 272 | args->context->buildLayer(args->node); |
| 273 | return NULL; |
| 274 | } |
| 275 | |
| 276 | void RenderProxy::buildLayer(RenderNode* node) { |
| 277 | SETUP_TASK(buildLayer); |
| 278 | args->context = mContext; |
| 279 | args->node = node; |
| 280 | postAndWait(task); |
| 281 | } |
| 282 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 283 | CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer, |
| 284 | SkBitmap* bitmap) { |
| 285 | bool success = args->context->copyLayerInto(args->layer, args->bitmap); |
| 286 | return (void*) success; |
| 287 | } |
| 288 | |
| 289 | bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) { |
| 290 | SETUP_TASK(copyLayerInto); |
| 291 | args->context = mContext; |
| 292 | args->layer = layer; |
| 293 | args->bitmap = bitmap; |
| 294 | return (bool) postAndWait(task); |
| 295 | } |
| 296 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 297 | void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) { |
| 298 | mDrawFrameTask.pushLayerUpdate(layer); |
| 299 | } |
| 300 | |
| 301 | void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) { |
| 302 | mDrawFrameTask.removeLayerUpdate(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 303 | } |
| 304 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 305 | CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) { |
| 306 | args->layer->detachSurfaceTexture(); |
| 307 | return NULL; |
| 308 | } |
| 309 | |
| 310 | void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) { |
| 311 | SETUP_TASK(detachSurfaceTexture); |
| 312 | args->layer = layer; |
| 313 | postAndWait(task); |
| 314 | } |
| 315 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 316 | CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) { |
| 317 | args->context->destroyHardwareResources(); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 318 | return NULL; |
| 319 | } |
| 320 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 321 | void RenderProxy::destroyHardwareResources() { |
| 322 | SETUP_TASK(destroyHardwareResources); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 323 | args->context = mContext; |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 324 | post(task); |
| 325 | } |
| 326 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 327 | CREATE_BRIDGE2(timMemory, RenderThread* thread, int level) { |
| 328 | CanvasContext::trimMemory(*args->thread, args->level); |
| 329 | return NULL; |
| 330 | } |
| 331 | |
| 332 | void RenderProxy::trimMemory(int level) { |
John Reck | cd3a22c | 2014-08-06 13:33:59 -0700 | [diff] [blame] | 333 | // Avoid creating a RenderThread to do a trimMemory. |
| 334 | if (RenderThread::hasInstance()) { |
| 335 | RenderThread& thread = RenderThread::getInstance(); |
| 336 | SETUP_TASK(timMemory); |
| 337 | args->thread = &thread; |
| 338 | args->level = level; |
| 339 | thread.queue(task); |
| 340 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 341 | } |
| 342 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 343 | CREATE_BRIDGE0(fence) { |
| 344 | // Intentionally empty |
| 345 | return NULL; |
| 346 | } |
| 347 | |
| 348 | void RenderProxy::fence() { |
| 349 | SETUP_TASK(fence); |
| 350 | postAndWait(task); |
| 351 | } |
| 352 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 353 | CREATE_BRIDGE1(stopDrawing, CanvasContext* context) { |
| 354 | args->context->stopDrawing(); |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | void RenderProxy::stopDrawing() { |
| 359 | SETUP_TASK(stopDrawing); |
| 360 | args->context = mContext; |
| 361 | postAndWait(task); |
| 362 | } |
| 363 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 364 | CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) { |
| 365 | args->context->notifyFramePending(); |
| 366 | return NULL; |
| 367 | } |
| 368 | |
| 369 | void RenderProxy::notifyFramePending() { |
| 370 | SETUP_TASK(notifyFramePending); |
| 371 | args->context = mContext; |
| 372 | mRenderThread.queueAtFront(task); |
| 373 | } |
| 374 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 375 | CREATE_BRIDGE2(dumpProfileInfo, CanvasContext* context, int fd) { |
| 376 | args->context->profiler().dumpData(args->fd); |
| 377 | return NULL; |
| 378 | } |
| 379 | |
| 380 | void RenderProxy::dumpProfileInfo(int fd) { |
| 381 | SETUP_TASK(dumpProfileInfo); |
| 382 | args->context = mContext; |
| 383 | args->fd = fd; |
| 384 | postAndWait(task); |
| 385 | } |
| 386 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame^] | 387 | CREATE_BRIDGE1(outputLogBuffer, int fd) { |
| 388 | RenderNode::outputLogBuffer(args->fd); |
| 389 | return NULL; |
| 390 | } |
| 391 | |
| 392 | void RenderProxy::outputLogBuffer(int fd) { |
| 393 | SETUP_TASK(outputLogBuffer); |
| 394 | args->fd = fd; |
| 395 | staticPostAndWait(task); |
| 396 | } |
| 397 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 398 | CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map, size_t size) { |
| 399 | CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size); |
| 400 | args->buffer->decStrong(0); |
| 401 | return NULL; |
| 402 | } |
| 403 | |
| 404 | void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) { |
| 405 | SETUP_TASK(setTextureAtlas); |
| 406 | args->thread = &mRenderThread; |
| 407 | args->buffer = buffer.get(); |
| 408 | args->buffer->incStrong(0); |
| 409 | args->map = map; |
| 410 | args->size = size; |
| 411 | post(task); |
| 412 | } |
| 413 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 414 | void RenderProxy::post(RenderTask* task) { |
| 415 | mRenderThread.queue(task); |
| 416 | } |
| 417 | |
| 418 | void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { |
| 419 | void* retval; |
| 420 | task->setReturnPtr(&retval); |
| 421 | SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); |
| 422 | AutoMutex _lock(mSyncMutex); |
Chris Craik | 738ec3a | 2014-07-25 18:25:02 +0000 | [diff] [blame] | 423 | mRenderThread.queue(&syncTask); |
| 424 | mSyncCondition.wait(mSyncMutex); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 425 | return retval; |
| 426 | } |
| 427 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame^] | 428 | void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) { |
| 429 | RenderThread& thread = RenderThread::getInstance(); |
| 430 | void* retval; |
| 431 | task->setReturnPtr(&retval); |
| 432 | Mutex mutex; |
| 433 | Condition condition; |
| 434 | SignalingRenderTask syncTask(task, &mutex, &condition); |
| 435 | AutoMutex _lock(mutex); |
| 436 | thread.queue(&syncTask); |
| 437 | condition.wait(mutex); |
| 438 | return retval; |
| 439 | } |
| 440 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 441 | } /* namespace renderthread */ |
| 442 | } /* namespace uirenderer */ |
| 443 | } /* namespace android */ |