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