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