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 | 797b95b | 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 | 797b95b | 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 | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 233 | int RenderProxy::syncAndDrawFrame(TreeObserver* observer) { |
| 234 | return mDrawFrameTask.drawFrame(observer); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 235 | } |
| 236 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 237 | CREATE_BRIDGE2(destroy, CanvasContext* context, TreeObserver* observer) { |
| 238 | args->context->destroy(args->observer); |
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 | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 242 | void RenderProxy::destroy(TreeObserver* observer) { |
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 | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 245 | args->observer = observer; |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 246 | // destroyCanvasAndSurface() needs a fence as when it returns the |
| 247 | // underlying BufferQueue is going to be released from under |
| 248 | // the render thread. |
| 249 | postAndWait(task); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 250 | } |
| 251 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 252 | CREATE_BRIDGE2(invokeFunctor, RenderThread* thread, Functor* functor) { |
| 253 | CanvasContext::invokeFunctor(*args->thread, args->functor); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 254 | return nullptr; |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) { |
John Reck | d3d8daf | 2014-04-10 15:00:13 -0700 | [diff] [blame] | 258 | ATRACE_CALL(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 259 | RenderThread& thread = RenderThread::getInstance(); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 260 | SETUP_TASK(invokeFunctor); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 261 | args->thread = &thread; |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 262 | args->functor = functor; |
| 263 | if (waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 264 | // waitForCompletion = true is expected to be fairly rare and only |
| 265 | // happen in destruction. Thus it should be fine to temporarily |
| 266 | // create a Mutex |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 267 | staticPostAndWait(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 268 | } else { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 269 | thread.queue(task); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
John Reck | c36df95 | 2015-07-29 10:09:36 -0700 | [diff] [blame] | 273 | CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) { |
Derek Sollenberger | 56ad6ec | 2016-07-22 12:13:32 -0400 | [diff] [blame] | 274 | return args->context->createTextureLayer(); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | DeferredLayerUpdater* RenderProxy::createTextureLayer() { |
| 278 | SETUP_TASK(createTextureLayer); |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 279 | args->context = mContext; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 280 | void* retval = postAndWait(task); |
| 281 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 282 | return layer; |
| 283 | } |
| 284 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 285 | CREATE_BRIDGE3(buildLayer, CanvasContext* context, RenderNode* node, TreeObserver* observer) { |
| 286 | args->context->buildLayer(args->node, args->observer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 287 | return nullptr; |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 288 | } |
| 289 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 290 | void RenderProxy::buildLayer(RenderNode* node, TreeObserver* observer) { |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 291 | SETUP_TASK(buildLayer); |
| 292 | args->context = mContext; |
| 293 | args->node = node; |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 294 | args->observer = observer; |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 295 | postAndWait(task); |
| 296 | } |
| 297 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 298 | CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer, |
| 299 | SkBitmap* bitmap) { |
| 300 | bool success = args->context->copyLayerInto(args->layer, args->bitmap); |
| 301 | return (void*) success; |
| 302 | } |
| 303 | |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 304 | bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 305 | SETUP_TASK(copyLayerInto); |
| 306 | args->context = mContext; |
| 307 | args->layer = layer; |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 308 | args->bitmap = &bitmap; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 309 | return (bool) postAndWait(task); |
| 310 | } |
| 311 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 312 | void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) { |
| 313 | mDrawFrameTask.pushLayerUpdate(layer); |
| 314 | } |
| 315 | |
| 316 | void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) { |
| 317 | mDrawFrameTask.removeLayerUpdate(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 318 | } |
| 319 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 320 | CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) { |
| 321 | args->layer->detachSurfaceTexture(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 322 | return nullptr; |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) { |
| 326 | SETUP_TASK(detachSurfaceTexture); |
| 327 | args->layer = layer; |
| 328 | postAndWait(task); |
| 329 | } |
| 330 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 331 | CREATE_BRIDGE2(destroyHardwareResources, CanvasContext* context, TreeObserver* observer) { |
| 332 | args->context->destroyHardwareResources(args->observer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 333 | return nullptr; |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 334 | } |
| 335 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 336 | void RenderProxy::destroyHardwareResources(TreeObserver* observer) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 337 | SETUP_TASK(destroyHardwareResources); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 338 | args->context = mContext; |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 339 | args->observer = observer; |
| 340 | postAndWait(task); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 343 | CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 344 | CanvasContext::trimMemory(*args->thread, args->level); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 345 | return nullptr; |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void RenderProxy::trimMemory(int level) { |
John Reck | cd3a22c | 2014-08-06 13:33:59 -0700 | [diff] [blame] | 349 | // Avoid creating a RenderThread to do a trimMemory. |
| 350 | if (RenderThread::hasInstance()) { |
| 351 | RenderThread& thread = RenderThread::getInstance(); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 352 | SETUP_TASK(trimMemory); |
John Reck | cd3a22c | 2014-08-06 13:33:59 -0700 | [diff] [blame] | 353 | args->thread = &thread; |
| 354 | args->level = level; |
| 355 | thread.queue(task); |
| 356 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 359 | CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) { |
| 360 | Properties::overrideProperty(args->name, args->value); |
| 361 | return nullptr; |
| 362 | } |
| 363 | |
| 364 | void RenderProxy::overrideProperty(const char* name, const char* value) { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 365 | SETUP_TASK(overrideProperty); |
| 366 | args->name = name; |
| 367 | args->value = value; |
| 368 | staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller |
| 369 | } |
| 370 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 371 | CREATE_BRIDGE0(fence) { |
| 372 | // Intentionally empty |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 373 | return nullptr; |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 376 | template <typename T> |
| 377 | void UNUSED(T t) {} |
| 378 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 379 | void RenderProxy::fence() { |
| 380 | SETUP_TASK(fence); |
Andreas Gampe | 1e19674 | 2014-11-10 15:23:43 -0800 | [diff] [blame] | 381 | UNUSED(args); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 382 | postAndWait(task); |
| 383 | } |
| 384 | |
Thomas Buhot | c0a0e1a | 2016-01-18 10:31:58 +0100 | [diff] [blame] | 385 | void RenderProxy::staticFence() { |
| 386 | SETUP_TASK(fence); |
| 387 | UNUSED(args); |
| 388 | staticPostAndWait(task); |
| 389 | } |
| 390 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 391 | CREATE_BRIDGE1(stopDrawing, CanvasContext* context) { |
| 392 | args->context->stopDrawing(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 393 | return nullptr; |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void RenderProxy::stopDrawing() { |
| 397 | SETUP_TASK(stopDrawing); |
| 398 | args->context = mContext; |
| 399 | postAndWait(task); |
| 400 | } |
| 401 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 402 | CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) { |
| 403 | args->context->notifyFramePending(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 404 | return nullptr; |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void RenderProxy::notifyFramePending() { |
| 408 | SETUP_TASK(notifyFramePending); |
| 409 | args->context = mContext; |
| 410 | mRenderThread.queueAtFront(task); |
| 411 | } |
| 412 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 413 | CREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread, |
| 414 | int fd, int dumpFlags) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 415 | args->context->profiler().dumpData(args->fd); |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 416 | if (args->dumpFlags & DumpFlags::FrameStats) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 417 | args->context->dumpFrames(args->fd); |
| 418 | } |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 419 | if (args->dumpFlags & DumpFlags::Reset) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 420 | args->context->resetFrameStats(); |
| 421 | } |
John Reck | a41f244 | 2016-04-07 16:36:57 -0700 | [diff] [blame] | 422 | if (args->dumpFlags & DumpFlags::JankStats) { |
| 423 | args->thread->jankTracker().dump(args->fd); |
| 424 | } |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 425 | return nullptr; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 426 | } |
| 427 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 428 | void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 429 | SETUP_TASK(dumpProfileInfo); |
| 430 | args->context = mContext; |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 431 | args->thread = &mRenderThread; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 432 | args->fd = fd; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 433 | args->dumpFlags = dumpFlags; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 434 | postAndWait(task); |
| 435 | } |
| 436 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 437 | CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) { |
| 438 | args->context->resetFrameStats(); |
| 439 | return nullptr; |
| 440 | } |
| 441 | |
| 442 | void RenderProxy::resetProfileInfo() { |
| 443 | SETUP_TASK(resetProfileInfo); |
| 444 | args->context = mContext; |
| 445 | postAndWait(task); |
| 446 | } |
| 447 | |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 448 | CREATE_BRIDGE2(frameTimePercentile, RenderThread* thread, int percentile) { |
| 449 | return reinterpret_cast<void*>(static_cast<uintptr_t>( |
| 450 | args->thread->jankTracker().findPercentile(args->percentile))); |
| 451 | } |
| 452 | |
| 453 | uint32_t RenderProxy::frameTimePercentile(int p) { |
| 454 | SETUP_TASK(frameTimePercentile); |
| 455 | args->thread = &mRenderThread; |
| 456 | args->percentile = p; |
| 457 | return static_cast<uint32_t>(reinterpret_cast<uintptr_t>( |
| 458 | postAndWait(task))); |
| 459 | } |
| 460 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 461 | CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) { |
| 462 | args->thread->jankTracker().dump(args->fd); |
| 463 | |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 464 | FILE *file = fdopen(args->fd, "a"); |
| 465 | if (Caches::hasInstance()) { |
| 466 | String8 cachesLog; |
| 467 | Caches::getInstance().dumpMemoryUsage(cachesLog); |
| 468 | fprintf(file, "\nCaches:\n%s\n", cachesLog.string()); |
| 469 | } else { |
| 470 | fprintf(file, "\nNo caches instance.\n"); |
| 471 | } |
Chris Craik | ff3edce | 2016-01-14 10:04:08 -0800 | [diff] [blame] | 472 | fprintf(file, "\nPipeline=FrameBuilder\n"); |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 473 | fflush(file); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 474 | return nullptr; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 477 | void RenderProxy::dumpGraphicsMemory(int fd) { |
youngmin0822.lee | c80c9ad | 2015-03-20 21:22:32 +0900 | [diff] [blame] | 478 | if (!RenderThread::hasInstance()) return; |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 479 | SETUP_TASK(dumpGraphicsMemory); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 480 | args->fd = fd; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 481 | args->thread = &RenderThread::getInstance(); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 482 | staticPostAndWait(task); |
| 483 | } |
| 484 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 485 | CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) { |
| 486 | args->thread->jankTracker().switchStorageToAshmem(args->fd); |
| 487 | close(args->fd); |
| 488 | return nullptr; |
| 489 | } |
| 490 | |
| 491 | void RenderProxy::setProcessStatsBuffer(int fd) { |
| 492 | SETUP_TASK(setProcessStatsBuffer); |
| 493 | args->thread = &mRenderThread; |
| 494 | args->fd = dup(fd); |
| 495 | post(task); |
| 496 | } |
| 497 | |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 498 | int RenderProxy::getRenderThreadTid() { |
| 499 | return mRenderThread.getTid(); |
| 500 | } |
| 501 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 502 | CREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) { |
| 503 | args->context->addRenderNode(args->node, args->placeFront); |
| 504 | return nullptr; |
| 505 | } |
| 506 | |
| 507 | void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) { |
| 508 | SETUP_TASK(addRenderNode); |
| 509 | args->context = mContext; |
| 510 | args->node = node; |
| 511 | args->placeFront = placeFront; |
| 512 | post(task); |
| 513 | } |
| 514 | |
| 515 | CREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) { |
| 516 | args->context->removeRenderNode(args->node); |
| 517 | return nullptr; |
| 518 | } |
| 519 | |
| 520 | void RenderProxy::removeRenderNode(RenderNode* node) { |
| 521 | SETUP_TASK(removeRenderNode); |
| 522 | args->context = mContext; |
| 523 | args->node = node; |
| 524 | post(task); |
| 525 | } |
| 526 | |
| 527 | CREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) { |
| 528 | args->context->prepareAndDraw(args->node); |
| 529 | return nullptr; |
| 530 | } |
| 531 | |
| 532 | void RenderProxy::drawRenderNode(RenderNode* node) { |
| 533 | SETUP_TASK(drawRenderNode); |
| 534 | args->context = mContext; |
| 535 | args->node = node; |
| 536 | // Be pseudo-thread-safe and don't use any member variables |
| 537 | staticPostAndWait(task); |
| 538 | } |
| 539 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 540 | CREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top, |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 541 | int right, int bottom) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 542 | args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 543 | return nullptr; |
| 544 | } |
| 545 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 546 | void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) { |
| 547 | SETUP_TASK(setContentDrawBounds); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 548 | args->context = mContext; |
| 549 | args->left = left; |
| 550 | args->top = top; |
| 551 | args->right = right; |
| 552 | args->bottom = bottom; |
| 553 | staticPostAndWait(task); |
| 554 | } |
| 555 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 556 | CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) { |
| 557 | args->context->serializeDisplayListTree(); |
| 558 | return nullptr; |
| 559 | } |
| 560 | |
| 561 | void RenderProxy::serializeDisplayListTree() { |
| 562 | SETUP_TASK(serializeDisplayListTree); |
| 563 | args->context = mContext; |
| 564 | post(task); |
| 565 | } |
| 566 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 567 | CREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context, |
| 568 | FrameMetricsObserver* frameStatsObserver) { |
| 569 | args->context->addFrameMetricsObserver(args->frameStatsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 570 | if (args->frameStatsObserver != nullptr) { |
| 571 | args->frameStatsObserver->decStrong(args->context); |
| 572 | } |
| 573 | return nullptr; |
| 574 | } |
| 575 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 576 | void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) { |
| 577 | SETUP_TASK(addFrameMetricsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 578 | args->context = mContext; |
| 579 | args->frameStatsObserver = observer; |
| 580 | if (observer != nullptr) { |
| 581 | observer->incStrong(mContext); |
| 582 | } |
| 583 | post(task); |
| 584 | } |
| 585 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 586 | CREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context, |
| 587 | FrameMetricsObserver* frameStatsObserver) { |
| 588 | args->context->removeFrameMetricsObserver(args->frameStatsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 589 | if (args->frameStatsObserver != nullptr) { |
| 590 | args->frameStatsObserver->decStrong(args->context); |
| 591 | } |
| 592 | return nullptr; |
| 593 | } |
| 594 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 595 | void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) { |
| 596 | SETUP_TASK(removeFrameMetricsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 597 | args->context = mContext; |
| 598 | args->frameStatsObserver = observer; |
| 599 | if (observer != nullptr) { |
| 600 | observer->incStrong(mContext); |
| 601 | } |
| 602 | post(task); |
| 603 | } |
| 604 | |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 605 | CREATE_BRIDGE4(copySurfaceInto, RenderThread* thread, |
| 606 | Surface* surface, Rect srcRect, SkBitmap* bitmap) { |
Derek Sollenberger | c4fbada | 2016-11-07 16:05:41 -0500 | [diff] [blame] | 607 | return (void*)args->thread->readback().copySurfaceInto(*args->surface, |
| 608 | args->srcRect, args->bitmap); |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 609 | } |
| 610 | |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 611 | int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, |
| 612 | int right, int bottom, SkBitmap* bitmap) { |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 613 | SETUP_TASK(copySurfaceInto); |
| 614 | args->bitmap = bitmap; |
| 615 | args->surface = surface.get(); |
| 616 | args->thread = &RenderThread::getInstance(); |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 617 | args->srcRect.set(left, top, right, bottom); |
John Reck | e94cbc7 | 2016-04-25 13:03:44 -0700 | [diff] [blame] | 618 | return static_cast<int>( |
| 619 | reinterpret_cast<intptr_t>( staticPostAndWait(task) )); |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 620 | } |
| 621 | |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 622 | CREATE_BRIDGE2(prepareToDraw, RenderThread* thread, Bitmap* bitmap) { |
Derek Sollenberger | daf7229 | 2016-10-25 12:09:18 -0400 | [diff] [blame] | 623 | CanvasContext::prepareToDraw(*args->thread, args->bitmap); |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 624 | args->bitmap->unref(); |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 625 | args->bitmap = nullptr; |
| 626 | return nullptr; |
| 627 | } |
| 628 | |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 629 | void RenderProxy::prepareToDraw(Bitmap& bitmap) { |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 630 | // If we haven't spun up a hardware accelerated window yet, there's no |
| 631 | // point in precaching these bitmaps as it can't impact jank. |
| 632 | // We also don't know if we even will spin up a hardware-accelerated |
| 633 | // window or not. |
| 634 | if (!RenderThread::hasInstance()) return; |
| 635 | RenderThread* renderThread = &RenderThread::getInstance(); |
| 636 | SETUP_TASK(prepareToDraw); |
| 637 | args->thread = renderThread; |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 638 | bitmap.ref(); |
| 639 | args->bitmap = &bitmap; |
John Reck | 4387190 | 2016-08-01 14:39:24 -0700 | [diff] [blame] | 640 | nsecs_t lastVsync = renderThread->timeLord().latestVsync(); |
| 641 | nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos(); |
| 642 | nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(CLOCK_MONOTONIC); |
| 643 | // We expect the UI thread to take 4ms and for RT to be active from VSYNC+4ms to |
| 644 | // VSYNC+12ms or so, so aim for the gap during which RT is expected to |
| 645 | // be idle |
| 646 | // TODO: Make this concept a first-class supported thing? RT could use |
| 647 | // knowledge of pending draws to better schedule this task |
| 648 | if (timeToNextVsync > -6_ms && timeToNextVsync < 1_ms) { |
| 649 | renderThread->queueAt(task, estimatedNextVsync + 8_ms); |
| 650 | } else { |
| 651 | renderThread->queue(task); |
| 652 | } |
| 653 | } |
| 654 | |
sergeyv | 694d499 | 2016-10-27 10:23:13 -0700 | [diff] [blame] | 655 | CREATE_BRIDGE2(allocateHardwareBitmap, RenderThread* thread, SkBitmap* bitmap) { |
| 656 | sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(*args->thread, *args->bitmap); |
| 657 | return hardwareBitmap.release(); |
| 658 | } |
| 659 | |
| 660 | sk_sp<Bitmap> RenderProxy::allocateHardwareBitmap(SkBitmap& bitmap) { |
| 661 | SETUP_TASK(allocateHardwareBitmap); |
| 662 | args->bitmap = &bitmap; |
| 663 | args->thread = &RenderThread::getInstance(); |
| 664 | sk_sp<Bitmap> hardwareBitmap(reinterpret_cast<Bitmap*>(staticPostAndWait(task))); |
| 665 | return hardwareBitmap; |
| 666 | } |
| 667 | |
sergeyv | 59eecb52 | 2016-11-17 17:54:57 -0800 | [diff] [blame] | 668 | CREATE_BRIDGE3(copyGraphicBufferInto, RenderThread* thread, GraphicBuffer* buffer, SkBitmap* bitmap) { |
| 669 | return (void*) args->thread->readback().copyGraphicBufferInto(args->buffer, args->bitmap); |
| 670 | } |
| 671 | |
| 672 | int RenderProxy::copyGraphicBufferInto(GraphicBuffer* buffer, SkBitmap* bitmap) { |
| 673 | SETUP_TASK(copyGraphicBufferInto); |
| 674 | args->thread = &RenderThread::getInstance(); |
| 675 | args->bitmap = bitmap; |
| 676 | args->buffer = buffer; |
| 677 | return static_cast<int>(reinterpret_cast<intptr_t>(staticPostAndWait(task))); |
| 678 | } |
| 679 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 680 | void RenderProxy::post(RenderTask* task) { |
| 681 | mRenderThread.queue(task); |
| 682 | } |
| 683 | |
| 684 | void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { |
| 685 | void* retval; |
| 686 | task->setReturnPtr(&retval); |
John Reck | cba287b | 2015-11-10 12:52:44 -0800 | [diff] [blame] | 687 | SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); |
| 688 | AutoMutex _lock(mSyncMutex); |
| 689 | mRenderThread.queue(&syncTask); |
| 690 | mSyncCondition.wait(mSyncMutex); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 691 | return retval; |
| 692 | } |
| 693 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 694 | void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) { |
| 695 | RenderThread& thread = RenderThread::getInstance(); |
| 696 | void* retval; |
| 697 | task->setReturnPtr(&retval); |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 698 | thread.queueAndWait(task); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 699 | return retval; |
| 700 | } |
| 701 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 702 | } /* namespace renderthread */ |
| 703 | } /* namespace uirenderer */ |
| 704 | } /* namespace android */ |