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