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 | |
| 17 | #define LOG_TAG "RenderProxy" |
| 18 | |
| 19 | #include "RenderProxy.h" |
| 20 | |
| 21 | #include "CanvasContext.h" |
| 22 | #include "RenderTask.h" |
| 23 | #include "RenderThread.h" |
| 24 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 25 | #include "../DeferredLayerUpdater.h" |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 26 | #include "../DisplayList.h" |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 27 | #include "../LayerRenderer.h" |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 28 | #include "../Rect.h" |
| 29 | |
| 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | namespace renderthread { |
| 33 | |
| 34 | #define ARGS(method) method ## Args |
| 35 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 36 | #define CREATE_BRIDGE0(name) CREATE_BRIDGE(name,,,,,,,,) |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 37 | #define CREATE_BRIDGE1(name, a1) CREATE_BRIDGE(name, a1,,,,,,,) |
| 38 | #define CREATE_BRIDGE2(name, a1, a2) CREATE_BRIDGE(name, a1,a2,,,,,,) |
| 39 | #define CREATE_BRIDGE3(name, a1, a2, a3) CREATE_BRIDGE(name, a1,a2,a3,,,,,) |
| 40 | #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] | 41 | #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] | 42 | #define CREATE_BRIDGE6(name, a1, a2, a3, a4, a5, a6) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,,) |
| 43 | #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] | 44 | #define CREATE_BRIDGE(name, a1, a2, a3, a4, a5, a6, a7, a8) \ |
| 45 | typedef struct { \ |
| 46 | a1; a2; a3; a4; a5; a6; a7; a8; \ |
| 47 | } ARGS(name); \ |
| 48 | static void* Bridge_ ## name(ARGS(name)* args) |
| 49 | |
| 50 | #define SETUP_TASK(method) \ |
| 51 | LOG_ALWAYS_FATAL_IF( METHOD_INVOKE_PAYLOAD_SIZE < sizeof(ARGS(method)), \ |
Mark Salyzyn | 546f353 | 2014-06-10 12:29:14 -0700 | [diff] [blame] | 52 | "METHOD_INVOKE_PAYLOAD_SIZE %zu is smaller than sizeof(" #method "Args) %zu", \ |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 53 | METHOD_INVOKE_PAYLOAD_SIZE, sizeof(ARGS(method))); \ |
John Reck | e2c4552 | 2014-04-07 17:31:44 -0700 | [diff] [blame] | 54 | MethodInvokeRenderTask* task = new MethodInvokeRenderTask((RunnableMethod) Bridge_ ## method); \ |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 55 | ARGS(method) *args = (ARGS(method) *) task->payload() |
| 56 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 57 | CREATE_BRIDGE3(createContext, RenderThread* thread, bool translucent, RenderNode* rootRenderNode) { |
| 58 | return new CanvasContext(*args->thread, args->translucent, args->rootRenderNode); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 59 | } |
| 60 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 61 | RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode) |
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 | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 68 | mContext = (CanvasContext*) postAndWait(task); |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 69 | mDrawFrameTask.setContext(&mRenderThread, mContext); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | RenderProxy::~RenderProxy() { |
| 73 | destroyContext(); |
| 74 | } |
| 75 | |
| 76 | CREATE_BRIDGE1(destroyContext, CanvasContext* context) { |
| 77 | delete args->context; |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | void RenderProxy::destroyContext() { |
| 82 | if (mContext) { |
| 83 | SETUP_TASK(destroyContext); |
| 84 | args->context = mContext; |
| 85 | mContext = 0; |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 86 | mDrawFrameTask.setContext(NULL, NULL); |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 87 | // This is also a fence as we need to be certain that there are no |
| 88 | // outstanding mDrawFrame tasks posted before it is destroyed |
| 89 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 93 | CREATE_BRIDGE2(setFrameInterval, RenderThread* thread, nsecs_t frameIntervalNanos) { |
| 94 | args->thread->timeLord().setFrameInterval(args->frameIntervalNanos); |
| 95 | return NULL; |
| 96 | } |
| 97 | |
| 98 | void RenderProxy::setFrameInterval(nsecs_t frameIntervalNanos) { |
| 99 | SETUP_TASK(setFrameInterval); |
| 100 | args->thread = &mRenderThread; |
| 101 | args->frameIntervalNanos = frameIntervalNanos; |
| 102 | post(task); |
| 103 | } |
| 104 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 105 | CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) { |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 106 | bool needsRedraw = false; |
| 107 | if (Caches::hasInstance()) { |
| 108 | needsRedraw = Caches::getInstance().initProperties(); |
| 109 | } |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 110 | if (args->context->profiler().loadSystemProperties()) { |
| 111 | needsRedraw = true; |
| 112 | } |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 113 | return (void*) needsRedraw; |
| 114 | } |
| 115 | |
| 116 | bool RenderProxy::loadSystemProperties() { |
| 117 | SETUP_TASK(loadSystemProperties); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 118 | args->context = mContext; |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 119 | return (bool) postAndWait(task); |
| 120 | } |
| 121 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 122 | CREATE_BRIDGE2(initialize, CanvasContext* context, ANativeWindow* window) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 123 | return (void*) args->context->initialize(args->window); |
| 124 | } |
| 125 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 126 | bool RenderProxy::initialize(const sp<ANativeWindow>& window) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 127 | SETUP_TASK(initialize); |
| 128 | args->context = mContext; |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 129 | args->window = window.get(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 130 | return (bool) postAndWait(task); |
| 131 | } |
| 132 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 133 | CREATE_BRIDGE2(updateSurface, CanvasContext* context, ANativeWindow* window) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 134 | args->context->updateSurface(args->window); |
| 135 | return NULL; |
| 136 | } |
| 137 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 138 | void RenderProxy::updateSurface(const sp<ANativeWindow>& window) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 139 | SETUP_TASK(updateSurface); |
| 140 | args->context = mContext; |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 141 | args->window = window.get(); |
| 142 | postAndWait(task); |
| 143 | } |
| 144 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 145 | CREATE_BRIDGE2(pauseSurface, CanvasContext* context, ANativeWindow* window) { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 146 | args->context->pauseSurface(args->window); |
| 147 | return NULL; |
| 148 | } |
| 149 | |
| 150 | void RenderProxy::pauseSurface(const sp<ANativeWindow>& window) { |
| 151 | SETUP_TASK(pauseSurface); |
| 152 | args->context = mContext; |
| 153 | args->window = window.get(); |
| 154 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 157 | CREATE_BRIDGE7(setup, CanvasContext* context, int width, int height, |
| 158 | Vector3 lightCenter, float lightRadius, |
| 159 | uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { |
| 160 | args->context->setup(args->width, args->height, args->lightCenter, args->lightRadius, |
| 161 | args->ambientShadowAlpha, args->spotShadowAlpha); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 162 | return NULL; |
| 163 | } |
| 164 | |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 165 | void RenderProxy::setup(int width, int height, const Vector3& lightCenter, float lightRadius, |
| 166 | uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 167 | SETUP_TASK(setup); |
| 168 | args->context = mContext; |
| 169 | args->width = width; |
| 170 | args->height = height; |
Chris Craik | 797b95b | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 171 | args->lightCenter = lightCenter; |
| 172 | args->lightRadius = lightRadius; |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 173 | args->ambientShadowAlpha = ambientShadowAlpha; |
| 174 | args->spotShadowAlpha = spotShadowAlpha; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 175 | post(task); |
| 176 | } |
| 177 | |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 178 | CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) { |
| 179 | args->context->setOpaque(args->opaque); |
| 180 | return NULL; |
| 181 | } |
| 182 | |
| 183 | void RenderProxy::setOpaque(bool opaque) { |
| 184 | SETUP_TASK(setOpaque); |
| 185 | args->context = mContext; |
| 186 | args->opaque = opaque; |
| 187 | post(task); |
| 188 | } |
| 189 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 190 | int RenderProxy::syncAndDrawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos, |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 191 | float density) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 192 | mDrawFrameTask.setDensity(density); |
| 193 | return mDrawFrameTask.drawFrame(frameTimeNanos, recordDurationNanos); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 194 | } |
| 195 | |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 196 | CREATE_BRIDGE1(destroyCanvasAndSurface, CanvasContext* context) { |
| 197 | args->context->destroyCanvasAndSurface(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 198 | return NULL; |
| 199 | } |
| 200 | |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 201 | void RenderProxy::destroyCanvasAndSurface() { |
| 202 | SETUP_TASK(destroyCanvasAndSurface); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 203 | args->context = mContext; |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 204 | // destroyCanvasAndSurface() needs a fence as when it returns the |
| 205 | // underlying BufferQueue is going to be released from under |
| 206 | // the render thread. |
| 207 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 208 | } |
| 209 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 210 | CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) { |
| 211 | CanvasContext::invokeFunctor(*args->thread, args->functor); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) { |
John Reck | d3d8daf | 2014-04-10 15:00:13 -0700 | [diff] [blame] | 216 | ATRACE_CALL(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 217 | RenderThread& thread = RenderThread::getInstance(); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 218 | SETUP_TASK(invokeFunctor); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 219 | args->thread = &thread; |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 220 | args->functor = functor; |
| 221 | if (waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 222 | // waitForCompletion = true is expected to be fairly rare and only |
| 223 | // happen in destruction. Thus it should be fine to temporarily |
| 224 | // create a Mutex |
| 225 | Mutex mutex; |
| 226 | Condition condition; |
| 227 | SignalingRenderTask syncTask(task, &mutex, &condition); |
| 228 | AutoMutex _lock(mutex); |
| 229 | thread.queue(&syncTask); |
| 230 | condition.wait(mutex); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 231 | } else { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 232 | thread.queue(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 236 | CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) { |
| 237 | args->context->runWithGlContext(args->task); |
| 238 | return NULL; |
| 239 | } |
| 240 | |
| 241 | void RenderProxy::runWithGlContext(RenderTask* gltask) { |
| 242 | SETUP_TASK(runWithGlContext); |
| 243 | args->context = mContext; |
| 244 | args->task = gltask; |
| 245 | postAndWait(task); |
| 246 | } |
| 247 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 248 | CREATE_BRIDGE1(destroyLayer, Layer* layer) { |
| 249 | LayerRenderer::destroyLayer(args->layer); |
| 250 | return NULL; |
| 251 | } |
| 252 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 253 | void RenderProxy::enqueueDestroyLayer(Layer* layer) { |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 254 | SETUP_TASK(destroyLayer); |
| 255 | args->layer = layer; |
| 256 | RenderThread::getInstance().queue(task); |
| 257 | } |
| 258 | |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 259 | CREATE_BRIDGE3(createDisplayListLayer, CanvasContext* context, int width, int height) { |
| 260 | Layer* layer = args->context->createRenderLayer(args->width, args->height); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 261 | if (!layer) return 0; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 262 | return new DeferredLayerUpdater(layer, RenderProxy::enqueueDestroyLayer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | DeferredLayerUpdater* RenderProxy::createDisplayListLayer(int width, int height) { |
| 266 | SETUP_TASK(createDisplayListLayer); |
| 267 | args->width = width; |
| 268 | args->height = height; |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 269 | args->context = mContext; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 270 | void* retval = postAndWait(task); |
| 271 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 272 | return layer; |
| 273 | } |
| 274 | |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 275 | CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) { |
| 276 | Layer* layer = args->context->createTextureLayer(); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 277 | if (!layer) return 0; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 278 | return new DeferredLayerUpdater(layer, RenderProxy::enqueueDestroyLayer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | DeferredLayerUpdater* RenderProxy::createTextureLayer() { |
| 282 | SETUP_TASK(createTextureLayer); |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 283 | args->context = mContext; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 284 | void* retval = postAndWait(task); |
| 285 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 286 | return layer; |
| 287 | } |
| 288 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 289 | CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer, |
| 290 | SkBitmap* bitmap) { |
| 291 | bool success = args->context->copyLayerInto(args->layer, args->bitmap); |
| 292 | return (void*) success; |
| 293 | } |
| 294 | |
| 295 | bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) { |
| 296 | SETUP_TASK(copyLayerInto); |
| 297 | args->context = mContext; |
| 298 | args->layer = layer; |
| 299 | args->bitmap = bitmap; |
| 300 | return (bool) postAndWait(task); |
| 301 | } |
| 302 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 303 | void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) { |
| 304 | mDrawFrameTask.pushLayerUpdate(layer); |
| 305 | } |
| 306 | |
| 307 | void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) { |
| 308 | mDrawFrameTask.removeLayerUpdate(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 309 | } |
| 310 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 311 | CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) { |
| 312 | args->layer->detachSurfaceTexture(); |
| 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) { |
| 317 | SETUP_TASK(detachSurfaceTexture); |
| 318 | args->layer = layer; |
| 319 | postAndWait(task); |
| 320 | } |
| 321 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 322 | CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) { |
| 323 | args->context->destroyHardwareResources(); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 324 | return NULL; |
| 325 | } |
| 326 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 327 | void RenderProxy::destroyHardwareResources() { |
| 328 | SETUP_TASK(destroyHardwareResources); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 329 | args->context = mContext; |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 330 | post(task); |
| 331 | } |
| 332 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 333 | CREATE_BRIDGE2(timMemory, RenderThread* thread, int level) { |
| 334 | CanvasContext::trimMemory(*args->thread, args->level); |
| 335 | return NULL; |
| 336 | } |
| 337 | |
| 338 | void RenderProxy::trimMemory(int level) { |
| 339 | RenderThread& thread = RenderThread::getInstance(); |
| 340 | SETUP_TASK(timMemory); |
| 341 | args->thread = &thread; |
| 342 | args->level = level; |
| 343 | thread.queue(task); |
| 344 | } |
| 345 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 346 | CREATE_BRIDGE0(fence) { |
| 347 | // Intentionally empty |
| 348 | return NULL; |
| 349 | } |
| 350 | |
| 351 | void RenderProxy::fence() { |
| 352 | SETUP_TASK(fence); |
| 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(); |
| 358 | return NULL; |
| 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(); |
| 369 | return NULL; |
| 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); |
| 380 | return NULL; |
| 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 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 390 | CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map, size_t size) { |
| 391 | CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size); |
| 392 | args->buffer->decStrong(0); |
| 393 | return NULL; |
| 394 | } |
| 395 | |
| 396 | void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) { |
| 397 | SETUP_TASK(setTextureAtlas); |
| 398 | args->thread = &mRenderThread; |
| 399 | args->buffer = buffer.get(); |
| 400 | args->buffer->incStrong(0); |
| 401 | args->map = map; |
| 402 | args->size = size; |
| 403 | post(task); |
| 404 | } |
| 405 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 406 | void RenderProxy::post(RenderTask* task) { |
| 407 | mRenderThread.queue(task); |
| 408 | } |
| 409 | |
| 410 | void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { |
| 411 | void* retval; |
| 412 | task->setReturnPtr(&retval); |
| 413 | SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); |
| 414 | AutoMutex _lock(mSyncMutex); |
Chris Craik | 738ec3a | 2014-07-25 18:25:02 +0000 | [diff] [blame] | 415 | mRenderThread.queue(&syncTask); |
| 416 | mSyncCondition.wait(mSyncMutex); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 417 | return retval; |
| 418 | } |
| 419 | |
| 420 | } /* namespace renderthread */ |
| 421 | } /* namespace uirenderer */ |
| 422 | } /* namespace android */ |