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" |
John Reck | a896306 | 2017-06-14 10:47:50 -0700 | [diff] [blame] | 21 | #include "Properties.h" |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 22 | #include "Readback.h" |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 23 | #include "Rect.h" |
| 24 | #include "renderthread/CanvasContext.h" |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 25 | #include "renderthread/EglManager.h" |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 26 | #include "renderthread/RenderTask.h" |
| 27 | #include "renderthread/RenderThread.h" |
John Reck | 9a81487 | 2017-05-22 15:04:21 -0700 | [diff] [blame] | 28 | #include "renderstate/RenderState.h" |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 29 | #include "utils/Macros.h" |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 30 | #include "utils/TimeUtils.h" |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 31 | |
sergeyv | 59eecb52 | 2016-11-17 17:54:57 -0800 | [diff] [blame] | 32 | #include <ui/GraphicBuffer.h> |
| 33 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 34 | namespace android { |
| 35 | namespace uirenderer { |
| 36 | namespace renderthread { |
| 37 | |
| 38 | #define ARGS(method) method ## Args |
| 39 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 40 | #define CREATE_BRIDGE0(name) CREATE_BRIDGE(name,,,,,,,,) |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 41 | #define CREATE_BRIDGE1(name, a1) CREATE_BRIDGE(name, a1,,,,,,,) |
| 42 | #define CREATE_BRIDGE2(name, a1, a2) CREATE_BRIDGE(name, a1,a2,,,,,,) |
| 43 | #define CREATE_BRIDGE3(name, a1, a2, a3) CREATE_BRIDGE(name, a1,a2,a3,,,,,) |
| 44 | #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] | 45 | #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] | 46 | #define CREATE_BRIDGE6(name, a1, a2, a3, a4, a5, a6) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,,) |
| 47 | #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] | 48 | #define CREATE_BRIDGE(name, a1, a2, a3, a4, a5, a6, a7, a8) \ |
| 49 | typedef struct { \ |
| 50 | a1; a2; a3; a4; a5; a6; a7; a8; \ |
| 51 | } ARGS(name); \ |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 52 | static_assert(std::is_trivially_destructible<ARGS(name)>::value, \ |
| 53 | "Error, ARGS must be trivially destructible!"); \ |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 54 | static void* Bridge_ ## name(ARGS(name)* args) |
| 55 | |
| 56 | #define SETUP_TASK(method) \ |
| 57 | LOG_ALWAYS_FATAL_IF( METHOD_INVOKE_PAYLOAD_SIZE < sizeof(ARGS(method)), \ |
Mark Salyzyn | 546f353 | 2014-06-10 12:29:14 -0700 | [diff] [blame] | 58 | "METHOD_INVOKE_PAYLOAD_SIZE %zu is smaller than sizeof(" #method "Args) %zu", \ |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 59 | METHOD_INVOKE_PAYLOAD_SIZE, sizeof(ARGS(method))); \ |
John Reck | e2c4552 | 2014-04-07 17:31:44 -0700 | [diff] [blame] | 60 | MethodInvokeRenderTask* task = new MethodInvokeRenderTask((RunnableMethod) Bridge_ ## method); \ |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 61 | ARGS(method) *args = (ARGS(method) *) task->payload() |
| 62 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 63 | CREATE_BRIDGE4(createContext, RenderThread* thread, bool translucent, |
| 64 | RenderNode* rootRenderNode, IContextFactory* contextFactory) { |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 65 | return CanvasContext::create(*args->thread, args->translucent, |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 66 | args->rootRenderNode, args->contextFactory); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 67 | } |
| 68 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 69 | RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode, IContextFactory* contextFactory) |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 70 | : mRenderThread(RenderThread::getInstance()) |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 71 | , mContext(nullptr) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 72 | SETUP_TASK(createContext); |
| 73 | args->translucent = translucent; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 74 | args->rootRenderNode = rootRenderNode; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 75 | args->thread = &mRenderThread; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 76 | args->contextFactory = contextFactory; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 77 | mContext = (CanvasContext*) postAndWait(task); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 78 | mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | RenderProxy::~RenderProxy() { |
| 82 | destroyContext(); |
| 83 | } |
| 84 | |
| 85 | CREATE_BRIDGE1(destroyContext, CanvasContext* context) { |
| 86 | delete args->context; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 87 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void RenderProxy::destroyContext() { |
| 91 | if (mContext) { |
| 92 | SETUP_TASK(destroyContext); |
| 93 | args->context = mContext; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 94 | mContext = nullptr; |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 95 | mDrawFrameTask.setContext(nullptr, nullptr, nullptr); |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 96 | // This is also a fence as we need to be certain that there are no |
| 97 | // outstanding mDrawFrame tasks posted before it is destroyed |
| 98 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 102 | CREATE_BRIDGE2(setSwapBehavior, CanvasContext* context, SwapBehavior swapBehavior) { |
| 103 | args->context->setSwapBehavior(args->swapBehavior); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 104 | return nullptr; |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void RenderProxy::setSwapBehavior(SwapBehavior swapBehavior) { |
| 108 | SETUP_TASK(setSwapBehavior); |
| 109 | args->context = mContext; |
| 110 | args->swapBehavior = swapBehavior; |
| 111 | post(task); |
| 112 | } |
| 113 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 114 | CREATE_BRIDGE1(loadSystemProperties, CanvasContext* context) { |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 115 | bool needsRedraw = false; |
| 116 | if (Caches::hasInstance()) { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 117 | needsRedraw = Properties::load(); |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 118 | } |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 119 | if (args->context->profiler().consumeProperties()) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 120 | needsRedraw = true; |
| 121 | } |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 122 | return (void*) needsRedraw; |
| 123 | } |
| 124 | |
| 125 | bool RenderProxy::loadSystemProperties() { |
| 126 | SETUP_TASK(loadSystemProperties); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 127 | args->context = mContext; |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 128 | return (bool) postAndWait(task); |
| 129 | } |
| 130 | |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 131 | CREATE_BRIDGE2(setName, CanvasContext* context, const char* name) { |
| 132 | args->context->setName(std::string(args->name)); |
| 133 | return nullptr; |
| 134 | } |
| 135 | |
| 136 | void RenderProxy::setName(const char* name) { |
| 137 | SETUP_TASK(setName); |
| 138 | args->context = mContext; |
| 139 | args->name = name; |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 140 | postAndWait(task); // block since name/value pointers owned by caller |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 141 | } |
| 142 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 143 | CREATE_BRIDGE2(initialize, CanvasContext* context, Surface* surface) { |
| 144 | args->context->initialize(args->surface); |
Thomas Buhot | 0bcd0cb | 2015-12-04 12:18:03 +0100 | [diff] [blame] | 145 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 146 | } |
| 147 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 148 | void RenderProxy::initialize(const sp<Surface>& surface) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 149 | SETUP_TASK(initialize); |
| 150 | args->context = mContext; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 151 | args->surface = surface.get(); |
Thomas Buhot | 0bcd0cb | 2015-12-04 12:18:03 +0100 | [diff] [blame] | 152 | post(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 153 | } |
| 154 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 155 | CREATE_BRIDGE2(updateSurface, CanvasContext* context, Surface* surface) { |
| 156 | args->context->updateSurface(args->surface); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 157 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 158 | } |
| 159 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 160 | void RenderProxy::updateSurface(const sp<Surface>& surface) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 161 | SETUP_TASK(updateSurface); |
| 162 | args->context = mContext; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 163 | args->surface = surface.get(); |
John Reck | cd68212 | 2016-08-09 12:09:03 -0700 | [diff] [blame] | 164 | post(task); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 165 | } |
| 166 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 167 | CREATE_BRIDGE2(pauseSurface, CanvasContext* context, Surface* surface) { |
| 168 | return (void*) args->context->pauseSurface(args->surface); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 169 | } |
| 170 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 171 | bool RenderProxy::pauseSurface(const sp<Surface>& surface) { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 172 | SETUP_TASK(pauseSurface); |
| 173 | args->context = mContext; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 174 | args->surface = surface.get(); |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 175 | return (bool) postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 176 | } |
| 177 | |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 178 | CREATE_BRIDGE2(setStopped, CanvasContext* context, bool stopped) { |
| 179 | args->context->setStopped(args->stopped); |
| 180 | return nullptr; |
| 181 | } |
| 182 | |
| 183 | void RenderProxy::setStopped(bool stopped) { |
| 184 | SETUP_TASK(setStopped); |
| 185 | args->context = mContext; |
| 186 | args->stopped = stopped; |
| 187 | postAndWait(task); |
| 188 | } |
| 189 | |
John Reck | ab1080c | 2016-06-21 16:24:20 -0700 | [diff] [blame] | 190 | CREATE_BRIDGE4(setup, CanvasContext* context, |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 191 | float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { |
John Reck | ab1080c | 2016-06-21 16:24:20 -0700 | [diff] [blame] | 192 | args->context->setup(args->lightRadius, |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 193 | args->ambientShadowAlpha, args->spotShadowAlpha); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 194 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 195 | } |
| 196 | |
John Reck | ab1080c | 2016-06-21 16:24:20 -0700 | [diff] [blame] | 197 | void RenderProxy::setup(float lightRadius, |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 198 | uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 199 | SETUP_TASK(setup); |
| 200 | args->context = mContext; |
Chris Craik | 797b95b | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 201 | args->lightRadius = lightRadius; |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 202 | args->ambientShadowAlpha = ambientShadowAlpha; |
| 203 | args->spotShadowAlpha = spotShadowAlpha; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 204 | post(task); |
| 205 | } |
| 206 | |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 207 | CREATE_BRIDGE2(setLightCenter, CanvasContext* context, Vector3 lightCenter) { |
| 208 | args->context->setLightCenter(args->lightCenter); |
| 209 | return nullptr; |
| 210 | } |
| 211 | |
| 212 | void RenderProxy::setLightCenter(const Vector3& lightCenter) { |
| 213 | SETUP_TASK(setLightCenter); |
| 214 | args->context = mContext; |
| 215 | args->lightCenter = lightCenter; |
| 216 | post(task); |
| 217 | } |
| 218 | |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 219 | CREATE_BRIDGE2(setOpaque, CanvasContext* context, bool opaque) { |
| 220 | args->context->setOpaque(args->opaque); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 221 | return nullptr; |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void RenderProxy::setOpaque(bool opaque) { |
| 225 | SETUP_TASK(setOpaque); |
| 226 | args->context = mContext; |
| 227 | args->opaque = opaque; |
| 228 | post(task); |
| 229 | } |
| 230 | |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 231 | CREATE_BRIDGE2(setWideGamut, CanvasContext* context, bool wideGamut) { |
| 232 | args->context->setWideGamut(args->wideGamut); |
| 233 | return nullptr; |
| 234 | } |
| 235 | |
| 236 | void RenderProxy::setWideGamut(bool wideGamut) { |
| 237 | SETUP_TASK(setWideGamut); |
| 238 | args->context = mContext; |
| 239 | args->wideGamut = wideGamut; |
| 240 | post(task); |
| 241 | } |
| 242 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 243 | int64_t* RenderProxy::frameInfo() { |
| 244 | return mDrawFrameTask.frameInfo(); |
| 245 | } |
| 246 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 247 | int RenderProxy::syncAndDrawFrame() { |
| 248 | return mDrawFrameTask.drawFrame(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 249 | } |
| 250 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 251 | CREATE_BRIDGE1(destroy, CanvasContext* context) { |
| 252 | args->context->destroy(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 253 | return nullptr; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 254 | } |
| 255 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 256 | void RenderProxy::destroy() { |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 257 | SETUP_TASK(destroy); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 258 | args->context = mContext; |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 259 | // destroyCanvasAndSurface() needs a fence as when it returns the |
| 260 | // underlying BufferQueue is going to be released from under |
| 261 | // the render thread. |
| 262 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 263 | } |
| 264 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 265 | CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) { |
| 266 | CanvasContext::invokeFunctor(*args->thread, args->functor); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 267 | return nullptr; |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) { |
John Reck | d3d8daf | 2014-04-10 15:00:13 -0700 | [diff] [blame] | 271 | ATRACE_CALL(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 272 | RenderThread& thread = RenderThread::getInstance(); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 273 | SETUP_TASK(invokeFunctor); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 274 | args->thread = &thread; |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 275 | args->functor = functor; |
| 276 | if (waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 277 | // waitForCompletion = true is expected to be fairly rare and only |
| 278 | // happen in destruction. Thus it should be fine to temporarily |
| 279 | // create a Mutex |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 280 | staticPostAndWait(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 281 | } else { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 282 | thread.queue(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
John Reck | c36df95 | 2015-07-29 10:09:36 -0700 | [diff] [blame] | 286 | CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) { |
Derek Sollenberger | 56ad6ec | 2016-07-22 12:13:32 -0400 | [diff] [blame] | 287 | return args->context->createTextureLayer(); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | DeferredLayerUpdater* RenderProxy::createTextureLayer() { |
| 291 | SETUP_TASK(createTextureLayer); |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 292 | args->context = mContext; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 293 | void* retval = postAndWait(task); |
| 294 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 295 | return layer; |
| 296 | } |
| 297 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 298 | CREATE_BRIDGE2(buildLayer, CanvasContext* context, RenderNode* node) { |
| 299 | args->context->buildLayer(args->node); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 300 | return nullptr; |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 301 | } |
| 302 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 303 | void RenderProxy::buildLayer(RenderNode* node) { |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 304 | SETUP_TASK(buildLayer); |
| 305 | args->context = mContext; |
| 306 | args->node = node; |
| 307 | postAndWait(task); |
| 308 | } |
| 309 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 310 | CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer, |
| 311 | SkBitmap* bitmap) { |
| 312 | bool success = args->context->copyLayerInto(args->layer, args->bitmap); |
| 313 | return (void*) success; |
| 314 | } |
| 315 | |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 316 | bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 317 | SETUP_TASK(copyLayerInto); |
| 318 | args->context = mContext; |
| 319 | args->layer = layer; |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 320 | args->bitmap = &bitmap; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 321 | return (bool) postAndWait(task); |
| 322 | } |
| 323 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 324 | void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) { |
| 325 | mDrawFrameTask.pushLayerUpdate(layer); |
| 326 | } |
| 327 | |
| 328 | void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) { |
| 329 | mDrawFrameTask.removeLayerUpdate(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 330 | } |
| 331 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 332 | CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) { |
| 333 | args->layer->detachSurfaceTexture(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 334 | return nullptr; |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) { |
| 338 | SETUP_TASK(detachSurfaceTexture); |
| 339 | args->layer = layer; |
| 340 | postAndWait(task); |
| 341 | } |
| 342 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 343 | CREATE_BRIDGE1(destroyHardwareResources, CanvasContext* context) { |
| 344 | args->context->destroyHardwareResources(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 345 | return nullptr; |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 346 | } |
| 347 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 348 | void RenderProxy::destroyHardwareResources() { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 349 | SETUP_TASK(destroyHardwareResources); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 350 | args->context = mContext; |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 351 | postAndWait(task); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 354 | CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 355 | CanvasContext::trimMemory(*args->thread, args->level); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 356 | return nullptr; |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void RenderProxy::trimMemory(int level) { |
John Reck | cd3a22c | 2014-08-06 13:33:59 -0700 | [diff] [blame] | 360 | // Avoid creating a RenderThread to do a trimMemory. |
| 361 | if (RenderThread::hasInstance()) { |
| 362 | RenderThread& thread = RenderThread::getInstance(); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 363 | SETUP_TASK(trimMemory); |
John Reck | cd3a22c | 2014-08-06 13:33:59 -0700 | [diff] [blame] | 364 | args->thread = &thread; |
| 365 | args->level = level; |
| 366 | thread.queue(task); |
| 367 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 370 | CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) { |
| 371 | Properties::overrideProperty(args->name, args->value); |
| 372 | return nullptr; |
| 373 | } |
| 374 | |
| 375 | void RenderProxy::overrideProperty(const char* name, const char* value) { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 376 | SETUP_TASK(overrideProperty); |
| 377 | args->name = name; |
| 378 | args->value = value; |
| 379 | staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller |
| 380 | } |
| 381 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 382 | CREATE_BRIDGE0(fence) { |
| 383 | // Intentionally empty |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 384 | return nullptr; |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 387 | template <typename T> |
| 388 | void UNUSED(T t) {} |
| 389 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 390 | void RenderProxy::fence() { |
| 391 | SETUP_TASK(fence); |
Andreas Gampe | 1e19674 | 2014-11-10 15:23:43 -0800 | [diff] [blame] | 392 | UNUSED(args); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 393 | postAndWait(task); |
| 394 | } |
| 395 | |
Thomas Buhot | c0a0e1a | 2016-01-18 10:31:58 +0100 | [diff] [blame] | 396 | void RenderProxy::staticFence() { |
| 397 | SETUP_TASK(fence); |
| 398 | UNUSED(args); |
| 399 | staticPostAndWait(task); |
| 400 | } |
| 401 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 402 | CREATE_BRIDGE1(stopDrawing, CanvasContext* context) { |
| 403 | args->context->stopDrawing(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 404 | return nullptr; |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void RenderProxy::stopDrawing() { |
| 408 | SETUP_TASK(stopDrawing); |
| 409 | args->context = mContext; |
| 410 | postAndWait(task); |
| 411 | } |
| 412 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 413 | CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) { |
| 414 | args->context->notifyFramePending(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 415 | return nullptr; |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | void RenderProxy::notifyFramePending() { |
| 419 | SETUP_TASK(notifyFramePending); |
| 420 | args->context = mContext; |
| 421 | mRenderThread.queueAtFront(task); |
| 422 | } |
| 423 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 424 | CREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread, |
| 425 | int fd, int dumpFlags) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 426 | args->context->profiler().dumpData(args->fd); |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 427 | if (args->dumpFlags & DumpFlags::FrameStats) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 428 | args->context->dumpFrames(args->fd); |
| 429 | } |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 430 | if (args->dumpFlags & DumpFlags::JankStats) { |
| 431 | args->thread->globalProfileData()->dump(args->fd); |
| 432 | } |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 433 | if (args->dumpFlags & DumpFlags::Reset) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 434 | args->context->resetFrameStats(); |
| 435 | } |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 436 | return nullptr; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 437 | } |
| 438 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 439 | void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 440 | SETUP_TASK(dumpProfileInfo); |
| 441 | args->context = mContext; |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 442 | args->thread = &mRenderThread; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 443 | args->fd = fd; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 444 | args->dumpFlags = dumpFlags; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 445 | postAndWait(task); |
| 446 | } |
| 447 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 448 | CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) { |
| 449 | args->context->resetFrameStats(); |
| 450 | return nullptr; |
| 451 | } |
| 452 | |
| 453 | void RenderProxy::resetProfileInfo() { |
| 454 | SETUP_TASK(resetProfileInfo); |
| 455 | args->context = mContext; |
| 456 | postAndWait(task); |
| 457 | } |
| 458 | |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 459 | CREATE_BRIDGE2(frameTimePercentile, RenderThread* thread, int percentile) { |
| 460 | return reinterpret_cast<void*>(static_cast<uintptr_t>( |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 461 | args->thread->globalProfileData()->findPercentile(args->percentile))); |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | uint32_t RenderProxy::frameTimePercentile(int p) { |
| 465 | SETUP_TASK(frameTimePercentile); |
| 466 | args->thread = &mRenderThread; |
| 467 | args->percentile = p; |
| 468 | return static_cast<uint32_t>(reinterpret_cast<uintptr_t>( |
| 469 | postAndWait(task))); |
| 470 | } |
| 471 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 472 | CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) { |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 473 | args->thread->dumpGraphicsMemory(args->fd); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 474 | return nullptr; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 477 | void RenderProxy::dumpGraphicsMemory(int fd) { |
youngmin0822.lee | c80c9ad | 2015-03-20 21:22:32 +0900 | [diff] [blame] | 478 | if (!RenderThread::hasInstance()) return; |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 479 | SETUP_TASK(dumpGraphicsMemory); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 480 | args->fd = fd; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 481 | args->thread = &RenderThread::getInstance(); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 482 | staticPostAndWait(task); |
| 483 | } |
| 484 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 485 | CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) { |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 486 | args->thread->globalProfileData().switchStorageToAshmem(args->fd); |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 487 | close(args->fd); |
| 488 | return nullptr; |
| 489 | } |
| 490 | |
| 491 | void RenderProxy::setProcessStatsBuffer(int fd) { |
| 492 | SETUP_TASK(setProcessStatsBuffer); |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 493 | auto& rt = RenderThread::getInstance(); |
| 494 | args->thread = &rt; |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 495 | args->fd = dup(fd); |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 496 | rt.queue(task); |
| 497 | } |
| 498 | |
| 499 | CREATE_BRIDGE1(rotateProcessStatsBuffer, RenderThread* thread) { |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 500 | args->thread->globalProfileData().rotateStorage(); |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 501 | return nullptr; |
| 502 | } |
| 503 | |
| 504 | void RenderProxy::rotateProcessStatsBuffer() { |
| 505 | SETUP_TASK(rotateProcessStatsBuffer); |
| 506 | auto& rt = RenderThread::getInstance(); |
| 507 | args->thread = &rt; |
| 508 | rt.queue(task); |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 511 | int RenderProxy::getRenderThreadTid() { |
| 512 | return mRenderThread.getTid(); |
| 513 | } |
| 514 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 515 | CREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) { |
| 516 | args->context->addRenderNode(args->node, args->placeFront); |
| 517 | return nullptr; |
| 518 | } |
| 519 | |
| 520 | void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) { |
| 521 | SETUP_TASK(addRenderNode); |
| 522 | args->context = mContext; |
| 523 | args->node = node; |
| 524 | args->placeFront = placeFront; |
| 525 | post(task); |
| 526 | } |
| 527 | |
| 528 | CREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) { |
| 529 | args->context->removeRenderNode(args->node); |
| 530 | return nullptr; |
| 531 | } |
| 532 | |
| 533 | void RenderProxy::removeRenderNode(RenderNode* node) { |
| 534 | SETUP_TASK(removeRenderNode); |
| 535 | args->context = mContext; |
| 536 | args->node = node; |
| 537 | post(task); |
| 538 | } |
| 539 | |
| 540 | CREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) { |
| 541 | args->context->prepareAndDraw(args->node); |
| 542 | return nullptr; |
| 543 | } |
| 544 | |
| 545 | void RenderProxy::drawRenderNode(RenderNode* node) { |
| 546 | SETUP_TASK(drawRenderNode); |
| 547 | args->context = mContext; |
| 548 | args->node = node; |
| 549 | // Be pseudo-thread-safe and don't use any member variables |
| 550 | staticPostAndWait(task); |
| 551 | } |
| 552 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 553 | CREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top, |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 554 | int right, int bottom) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 555 | args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 556 | return nullptr; |
| 557 | } |
| 558 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 559 | void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) { |
| 560 | SETUP_TASK(setContentDrawBounds); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 561 | args->context = mContext; |
| 562 | args->left = left; |
| 563 | args->top = top; |
| 564 | args->right = right; |
| 565 | args->bottom = bottom; |
| 566 | staticPostAndWait(task); |
| 567 | } |
| 568 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 569 | CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) { |
| 570 | args->context->serializeDisplayListTree(); |
| 571 | return nullptr; |
| 572 | } |
| 573 | |
| 574 | void RenderProxy::serializeDisplayListTree() { |
| 575 | SETUP_TASK(serializeDisplayListTree); |
| 576 | args->context = mContext; |
| 577 | post(task); |
| 578 | } |
| 579 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 580 | CREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context, |
| 581 | FrameMetricsObserver* frameStatsObserver) { |
| 582 | args->context->addFrameMetricsObserver(args->frameStatsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 583 | if (args->frameStatsObserver != nullptr) { |
| 584 | args->frameStatsObserver->decStrong(args->context); |
| 585 | } |
| 586 | return nullptr; |
| 587 | } |
| 588 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 589 | void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) { |
| 590 | SETUP_TASK(addFrameMetricsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 591 | args->context = mContext; |
| 592 | args->frameStatsObserver = observer; |
| 593 | if (observer != nullptr) { |
| 594 | observer->incStrong(mContext); |
| 595 | } |
| 596 | post(task); |
| 597 | } |
| 598 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 599 | CREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context, |
| 600 | FrameMetricsObserver* frameStatsObserver) { |
| 601 | args->context->removeFrameMetricsObserver(args->frameStatsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 602 | if (args->frameStatsObserver != nullptr) { |
| 603 | args->frameStatsObserver->decStrong(args->context); |
| 604 | } |
| 605 | return nullptr; |
| 606 | } |
| 607 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 608 | void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) { |
| 609 | SETUP_TASK(removeFrameMetricsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 610 | args->context = mContext; |
| 611 | args->frameStatsObserver = observer; |
| 612 | if (observer != nullptr) { |
| 613 | observer->incStrong(mContext); |
| 614 | } |
| 615 | post(task); |
| 616 | } |
| 617 | |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 618 | CREATE_BRIDGE4(copySurfaceInto, RenderThread* thread, |
| 619 | Surface* surface, Rect srcRect, SkBitmap* bitmap) { |
Derek Sollenberger | c4fbada | 2016-11-07 16:05:41 -0500 | [diff] [blame] | 620 | return (void*)args->thread->readback().copySurfaceInto(*args->surface, |
| 621 | args->srcRect, args->bitmap); |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 622 | } |
| 623 | |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 624 | int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, |
| 625 | int right, int bottom, SkBitmap* bitmap) { |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 626 | SETUP_TASK(copySurfaceInto); |
| 627 | args->bitmap = bitmap; |
| 628 | args->surface = surface.get(); |
| 629 | args->thread = &RenderThread::getInstance(); |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 630 | args->srcRect.set(left, top, right, bottom); |
John Reck | e94cbc7 | 2016-04-25 13:03:44 -0700 | [diff] [blame] | 631 | return static_cast<int>( |
| 632 | reinterpret_cast<intptr_t>( staticPostAndWait(task) )); |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 633 | } |
| 634 | |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 635 | CREATE_BRIDGE2(prepareToDraw, RenderThread* thread, Bitmap* bitmap) { |
Derek Sollenberger | daf7229 | 2016-10-25 12:09:18 -0400 | [diff] [blame] | 636 | CanvasContext::prepareToDraw(*args->thread, args->bitmap); |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 637 | args->bitmap->unref(); |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 638 | args->bitmap = nullptr; |
| 639 | return nullptr; |
| 640 | } |
| 641 | |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 642 | void RenderProxy::prepareToDraw(Bitmap& bitmap) { |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 643 | // If we haven't spun up a hardware accelerated window yet, there's no |
| 644 | // point in precaching these bitmaps as it can't impact jank. |
| 645 | // We also don't know if we even will spin up a hardware-accelerated |
| 646 | // window or not. |
| 647 | if (!RenderThread::hasInstance()) return; |
| 648 | RenderThread* renderThread = &RenderThread::getInstance(); |
| 649 | SETUP_TASK(prepareToDraw); |
| 650 | args->thread = renderThread; |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 651 | bitmap.ref(); |
| 652 | args->bitmap = &bitmap; |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 653 | nsecs_t lastVsync = renderThread->timeLord().latestVsync(); |
| 654 | nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos(); |
| 655 | nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(CLOCK_MONOTONIC); |
| 656 | // We expect the UI thread to take 4ms and for RT to be active from VSYNC+4ms to |
| 657 | // VSYNC+12ms or so, so aim for the gap during which RT is expected to |
| 658 | // be idle |
| 659 | // TODO: Make this concept a first-class supported thing? RT could use |
| 660 | // knowledge of pending draws to better schedule this task |
| 661 | if (timeToNextVsync > -6_ms && timeToNextVsync < 1_ms) { |
| 662 | renderThread->queueAt(task, estimatedNextVsync + 8_ms); |
| 663 | } else { |
| 664 | renderThread->queue(task); |
| 665 | } |
| 666 | } |
| 667 | |
sergeyv | 694d499 | 2016-10-27 10:23:13 -0700 | [diff] [blame] | 668 | CREATE_BRIDGE2(allocateHardwareBitmap, RenderThread* thread, SkBitmap* bitmap) { |
Stan Iliev | 7bc3bc6 | 2017-05-24 13:28:36 -0400 | [diff] [blame] | 669 | sk_sp<Bitmap> hardwareBitmap = args->thread->allocateHardwareBitmap(*args->bitmap); |
sergeyv | 694d499 | 2016-10-27 10:23:13 -0700 | [diff] [blame] | 670 | return hardwareBitmap.release(); |
| 671 | } |
| 672 | |
| 673 | sk_sp<Bitmap> RenderProxy::allocateHardwareBitmap(SkBitmap& bitmap) { |
| 674 | SETUP_TASK(allocateHardwareBitmap); |
| 675 | args->bitmap = &bitmap; |
| 676 | args->thread = &RenderThread::getInstance(); |
| 677 | sk_sp<Bitmap> hardwareBitmap(reinterpret_cast<Bitmap*>(staticPostAndWait(task))); |
| 678 | return hardwareBitmap; |
| 679 | } |
| 680 | |
sergeyv | 59eecb52 | 2016-11-17 17:54:57 -0800 | [diff] [blame] | 681 | CREATE_BRIDGE3(copyGraphicBufferInto, RenderThread* thread, GraphicBuffer* buffer, SkBitmap* bitmap) { |
| 682 | return (void*) args->thread->readback().copyGraphicBufferInto(args->buffer, args->bitmap); |
| 683 | } |
| 684 | |
| 685 | int RenderProxy::copyGraphicBufferInto(GraphicBuffer* buffer, SkBitmap* bitmap) { |
Stan Iliev | 6983bc4 | 2017-02-02 14:11:53 -0500 | [diff] [blame] | 686 | RenderThread& thread = RenderThread::getInstance(); |
| 687 | if (Properties::isSkiaEnabled() && gettid() == thread.getTid()) { |
| 688 | //TODO: fix everything that hits this. We should never be triggering a readback ourselves. |
| 689 | return (int) thread.readback().copyGraphicBufferInto(buffer, bitmap); |
| 690 | } else { |
| 691 | SETUP_TASK(copyGraphicBufferInto); |
| 692 | args->thread = &thread; |
| 693 | args->bitmap = bitmap; |
| 694 | args->buffer = buffer; |
| 695 | return static_cast<int>(reinterpret_cast<intptr_t>(staticPostAndWait(task))); |
| 696 | } |
sergeyv | 59eecb52 | 2016-11-17 17:54:57 -0800 | [diff] [blame] | 697 | } |
| 698 | |
John Reck | 9a81487 | 2017-05-22 15:04:21 -0700 | [diff] [blame] | 699 | CREATE_BRIDGE2(onBitmapDestroyed, RenderThread* thread, uint32_t pixelRefId) { |
| 700 | args->thread->renderState().onBitmapDestroyed(args->pixelRefId); |
| 701 | return nullptr; |
| 702 | } |
| 703 | |
| 704 | void RenderProxy::onBitmapDestroyed(uint32_t pixelRefId) { |
| 705 | if (!RenderThread::hasInstance()) return; |
| 706 | SETUP_TASK(onBitmapDestroyed); |
| 707 | RenderThread& thread = RenderThread::getInstance(); |
| 708 | args->thread = &thread; |
| 709 | args->pixelRefId = pixelRefId; |
| 710 | thread.queue(task); |
| 711 | } |
| 712 | |
John Reck | a896306 | 2017-06-14 10:47:50 -0700 | [diff] [blame] | 713 | void RenderProxy::disableVsync() { |
| 714 | Properties::disableVsync = true; |
| 715 | } |
| 716 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 717 | void RenderProxy::post(RenderTask* task) { |
| 718 | mRenderThread.queue(task); |
| 719 | } |
| 720 | |
| 721 | void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { |
| 722 | void* retval; |
| 723 | task->setReturnPtr(&retval); |
John Reck | cba287b | 2015-11-10 12:52:44 -0800 | [diff] [blame] | 724 | SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); |
| 725 | AutoMutex _lock(mSyncMutex); |
| 726 | mRenderThread.queue(&syncTask); |
Tom Cherry | 298a146 | 2017-02-28 14:07:09 -0800 | [diff] [blame] | 727 | while (!syncTask.hasRun()) { |
| 728 | mSyncCondition.wait(mSyncMutex); |
| 729 | } |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 730 | return retval; |
| 731 | } |
| 732 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 733 | void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) { |
| 734 | RenderThread& thread = RenderThread::getInstance(); |
Stan Iliev | 6983bc4 | 2017-02-02 14:11:53 -0500 | [diff] [blame] | 735 | LOG_ALWAYS_FATAL_IF(gettid() == thread.getTid()); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 736 | void* retval; |
| 737 | task->setReturnPtr(&retval); |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 738 | thread.queueAndWait(task); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 739 | return retval; |
| 740 | } |
| 741 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 742 | } /* namespace renderthread */ |
| 743 | } /* namespace uirenderer */ |
| 744 | } /* namespace android */ |