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