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