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