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