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