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