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 | 797b95b | 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 | 797b95b | 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 | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 268 | CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) { |
| 269 | args->context->runWithGlContext(args->task); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 270 | return nullptr; |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void RenderProxy::runWithGlContext(RenderTask* gltask) { |
| 274 | SETUP_TASK(runWithGlContext); |
| 275 | args->context = mContext; |
| 276 | args->task = gltask; |
| 277 | postAndWait(task); |
| 278 | } |
| 279 | |
John Reck | c36df95 | 2015-07-29 10:09:36 -0700 | [diff] [blame] | 280 | CREATE_BRIDGE1(createTextureLayer, CanvasContext* context) { |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 281 | Layer* layer = args->context->createTextureLayer(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 282 | if (!layer) return nullptr; |
John Reck | c36df95 | 2015-07-29 10:09:36 -0700 | [diff] [blame] | 283 | return new DeferredLayerUpdater(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | DeferredLayerUpdater* RenderProxy::createTextureLayer() { |
| 287 | SETUP_TASK(createTextureLayer); |
John Reck | 1949e79 | 2014-04-08 15:18:56 -0700 | [diff] [blame] | 288 | args->context = mContext; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 289 | void* retval = postAndWait(task); |
| 290 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(retval); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 291 | return layer; |
| 292 | } |
| 293 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 294 | CREATE_BRIDGE3(buildLayer, CanvasContext* context, RenderNode* node, TreeObserver* observer) { |
| 295 | args->context->buildLayer(args->node, args->observer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 296 | return nullptr; |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 297 | } |
| 298 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 299 | void RenderProxy::buildLayer(RenderNode* node, TreeObserver* observer) { |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 300 | SETUP_TASK(buildLayer); |
| 301 | args->context = mContext; |
| 302 | args->node = node; |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 303 | args->observer = observer; |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 304 | postAndWait(task); |
| 305 | } |
| 306 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 307 | CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* layer, |
| 308 | SkBitmap* bitmap) { |
| 309 | bool success = args->context->copyLayerInto(args->layer, args->bitmap); |
| 310 | return (void*) success; |
| 311 | } |
| 312 | |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 313 | bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 314 | SETUP_TASK(copyLayerInto); |
| 315 | args->context = mContext; |
| 316 | args->layer = layer; |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 317 | args->bitmap = &bitmap; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 318 | return (bool) postAndWait(task); |
| 319 | } |
| 320 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 321 | void RenderProxy::pushLayerUpdate(DeferredLayerUpdater* layer) { |
| 322 | mDrawFrameTask.pushLayerUpdate(layer); |
| 323 | } |
| 324 | |
| 325 | void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) { |
| 326 | mDrawFrameTask.removeLayerUpdate(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 327 | } |
| 328 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 329 | CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) { |
| 330 | args->layer->detachSurfaceTexture(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 331 | return nullptr; |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) { |
| 335 | SETUP_TASK(detachSurfaceTexture); |
| 336 | args->layer = layer; |
| 337 | postAndWait(task); |
| 338 | } |
| 339 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 340 | CREATE_BRIDGE2(destroyHardwareResources, CanvasContext* context, TreeObserver* observer) { |
| 341 | args->context->destroyHardwareResources(args->observer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 342 | return nullptr; |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 343 | } |
| 344 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 345 | void RenderProxy::destroyHardwareResources(TreeObserver* observer) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 346 | SETUP_TASK(destroyHardwareResources); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 347 | args->context = mContext; |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 348 | args->observer = observer; |
| 349 | postAndWait(task); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 352 | CREATE_BRIDGE2(trimMemory, RenderThread* thread, int level) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 353 | CanvasContext::trimMemory(*args->thread, args->level); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 354 | return nullptr; |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void RenderProxy::trimMemory(int level) { |
John Reck | cd3a22c | 2014-08-06 13:33:59 -0700 | [diff] [blame] | 358 | // Avoid creating a RenderThread to do a trimMemory. |
| 359 | if (RenderThread::hasInstance()) { |
| 360 | RenderThread& thread = RenderThread::getInstance(); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 361 | SETUP_TASK(trimMemory); |
John Reck | cd3a22c | 2014-08-06 13:33:59 -0700 | [diff] [blame] | 362 | args->thread = &thread; |
| 363 | args->level = level; |
| 364 | thread.queue(task); |
| 365 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 368 | CREATE_BRIDGE2(overrideProperty, const char* name, const char* value) { |
| 369 | Properties::overrideProperty(args->name, args->value); |
| 370 | return nullptr; |
| 371 | } |
| 372 | |
| 373 | void RenderProxy::overrideProperty(const char* name, const char* value) { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 374 | SETUP_TASK(overrideProperty); |
| 375 | args->name = name; |
| 376 | args->value = value; |
| 377 | staticPostAndWait(task); // expensive, but block here since name/value pointers owned by caller |
| 378 | } |
| 379 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 380 | CREATE_BRIDGE0(fence) { |
| 381 | // Intentionally empty |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 382 | return nullptr; |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 385 | template <typename T> |
| 386 | void UNUSED(T t) {} |
| 387 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 388 | void RenderProxy::fence() { |
| 389 | SETUP_TASK(fence); |
Andreas Gampe | 1e19674 | 2014-11-10 15:23:43 -0800 | [diff] [blame] | 390 | UNUSED(args); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 391 | postAndWait(task); |
| 392 | } |
| 393 | |
Thomas Buhot | c0a0e1a | 2016-01-18 10:31:58 +0100 | [diff] [blame] | 394 | void RenderProxy::staticFence() { |
| 395 | SETUP_TASK(fence); |
| 396 | UNUSED(args); |
| 397 | staticPostAndWait(task); |
| 398 | } |
| 399 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 400 | CREATE_BRIDGE1(stopDrawing, CanvasContext* context) { |
| 401 | args->context->stopDrawing(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 402 | return nullptr; |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void RenderProxy::stopDrawing() { |
| 406 | SETUP_TASK(stopDrawing); |
| 407 | args->context = mContext; |
| 408 | postAndWait(task); |
| 409 | } |
| 410 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 411 | CREATE_BRIDGE1(notifyFramePending, CanvasContext* context) { |
| 412 | args->context->notifyFramePending(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 413 | return nullptr; |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void RenderProxy::notifyFramePending() { |
| 417 | SETUP_TASK(notifyFramePending); |
| 418 | args->context = mContext; |
| 419 | mRenderThread.queueAtFront(task); |
| 420 | } |
| 421 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 422 | CREATE_BRIDGE4(dumpProfileInfo, CanvasContext* context, RenderThread* thread, |
| 423 | int fd, int dumpFlags) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 424 | args->context->profiler().dumpData(args->fd); |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 425 | if (args->dumpFlags & DumpFlags::FrameStats) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 426 | args->context->dumpFrames(args->fd); |
| 427 | } |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 428 | if (args->dumpFlags & DumpFlags::Reset) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 429 | args->context->resetFrameStats(); |
| 430 | } |
John Reck | a41f244 | 2016-04-07 16:36:57 -0700 | [diff] [blame] | 431 | if (args->dumpFlags & DumpFlags::JankStats) { |
| 432 | args->thread->jankTracker().dump(args->fd); |
| 433 | } |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 434 | return nullptr; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 435 | } |
| 436 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 437 | void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 438 | SETUP_TASK(dumpProfileInfo); |
| 439 | args->context = mContext; |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 440 | args->thread = &mRenderThread; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 441 | args->fd = fd; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 442 | args->dumpFlags = dumpFlags; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 443 | postAndWait(task); |
| 444 | } |
| 445 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 446 | CREATE_BRIDGE1(resetProfileInfo, CanvasContext* context) { |
| 447 | args->context->resetFrameStats(); |
| 448 | return nullptr; |
| 449 | } |
| 450 | |
| 451 | void RenderProxy::resetProfileInfo() { |
| 452 | SETUP_TASK(resetProfileInfo); |
| 453 | args->context = mContext; |
| 454 | postAndWait(task); |
| 455 | } |
| 456 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 457 | CREATE_BRIDGE2(dumpGraphicsMemory, int fd, RenderThread* thread) { |
| 458 | args->thread->jankTracker().dump(args->fd); |
| 459 | |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 460 | FILE *file = fdopen(args->fd, "a"); |
| 461 | if (Caches::hasInstance()) { |
| 462 | String8 cachesLog; |
| 463 | Caches::getInstance().dumpMemoryUsage(cachesLog); |
| 464 | fprintf(file, "\nCaches:\n%s\n", cachesLog.string()); |
| 465 | } else { |
| 466 | fprintf(file, "\nNo caches instance.\n"); |
| 467 | } |
Chris Craik | ff3edce | 2016-01-14 10:04:08 -0800 | [diff] [blame] | 468 | #if HWUI_NEW_OPS |
| 469 | fprintf(file, "\nPipeline=FrameBuilder\n"); |
| 470 | #else |
| 471 | fprintf(file, "\nPipeline=OpenGLRenderer\n"); |
| 472 | #endif |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 473 | fflush(file); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 474 | return nullptr; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 477 | void RenderProxy::dumpGraphicsMemory(int fd) { |
youngmin0822.lee | c80c9ad | 2015-03-20 21:22:32 +0900 | [diff] [blame] | 478 | if (!RenderThread::hasInstance()) return; |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 479 | SETUP_TASK(dumpGraphicsMemory); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 480 | args->fd = fd; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 481 | args->thread = &RenderThread::getInstance(); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 482 | staticPostAndWait(task); |
| 483 | } |
| 484 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 485 | CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map, |
| 486 | size_t size) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 487 | CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 488 | args->buffer->decStrong(nullptr); |
| 489 | return nullptr; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) { |
| 493 | SETUP_TASK(setTextureAtlas); |
| 494 | args->thread = &mRenderThread; |
| 495 | args->buffer = buffer.get(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 496 | args->buffer->incStrong(nullptr); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 497 | args->map = map; |
| 498 | args->size = size; |
| 499 | post(task); |
| 500 | } |
| 501 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 502 | CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) { |
| 503 | args->thread->jankTracker().switchStorageToAshmem(args->fd); |
| 504 | close(args->fd); |
| 505 | return nullptr; |
| 506 | } |
| 507 | |
| 508 | void RenderProxy::setProcessStatsBuffer(int fd) { |
| 509 | SETUP_TASK(setProcessStatsBuffer); |
| 510 | args->thread = &mRenderThread; |
| 511 | args->fd = dup(fd); |
| 512 | post(task); |
| 513 | } |
| 514 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 515 | CREATE_BRIDGE3(addRenderNode, CanvasContext* context, RenderNode* node, bool placeFront) { |
| 516 | args->context->addRenderNode(args->node, args->placeFront); |
| 517 | return nullptr; |
| 518 | } |
| 519 | |
| 520 | void RenderProxy::addRenderNode(RenderNode* node, bool placeFront) { |
| 521 | SETUP_TASK(addRenderNode); |
| 522 | args->context = mContext; |
| 523 | args->node = node; |
| 524 | args->placeFront = placeFront; |
| 525 | post(task); |
| 526 | } |
| 527 | |
| 528 | CREATE_BRIDGE2(removeRenderNode, CanvasContext* context, RenderNode* node) { |
| 529 | args->context->removeRenderNode(args->node); |
| 530 | return nullptr; |
| 531 | } |
| 532 | |
| 533 | void RenderProxy::removeRenderNode(RenderNode* node) { |
| 534 | SETUP_TASK(removeRenderNode); |
| 535 | args->context = mContext; |
| 536 | args->node = node; |
| 537 | post(task); |
| 538 | } |
| 539 | |
| 540 | CREATE_BRIDGE2(drawRenderNode, CanvasContext* context, RenderNode* node) { |
| 541 | args->context->prepareAndDraw(args->node); |
| 542 | return nullptr; |
| 543 | } |
| 544 | |
| 545 | void RenderProxy::drawRenderNode(RenderNode* node) { |
| 546 | SETUP_TASK(drawRenderNode); |
| 547 | args->context = mContext; |
| 548 | args->node = node; |
| 549 | // Be pseudo-thread-safe and don't use any member variables |
| 550 | staticPostAndWait(task); |
| 551 | } |
| 552 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 553 | CREATE_BRIDGE5(setContentDrawBounds, CanvasContext* context, int left, int top, |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 554 | int right, int bottom) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 555 | args->context->setContentDrawBounds(args->left, args->top, args->right, args->bottom); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 556 | return nullptr; |
| 557 | } |
| 558 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 559 | void RenderProxy::setContentDrawBounds(int left, int top, int right, int bottom) { |
| 560 | SETUP_TASK(setContentDrawBounds); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 561 | args->context = mContext; |
| 562 | args->left = left; |
| 563 | args->top = top; |
| 564 | args->right = right; |
| 565 | args->bottom = bottom; |
| 566 | staticPostAndWait(task); |
| 567 | } |
| 568 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 569 | CREATE_BRIDGE1(serializeDisplayListTree, CanvasContext* context) { |
| 570 | args->context->serializeDisplayListTree(); |
| 571 | return nullptr; |
| 572 | } |
| 573 | |
| 574 | void RenderProxy::serializeDisplayListTree() { |
| 575 | SETUP_TASK(serializeDisplayListTree); |
| 576 | args->context = mContext; |
| 577 | post(task); |
| 578 | } |
| 579 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 580 | CREATE_BRIDGE2(addFrameMetricsObserver, CanvasContext* context, |
| 581 | FrameMetricsObserver* frameStatsObserver) { |
| 582 | args->context->addFrameMetricsObserver(args->frameStatsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 583 | if (args->frameStatsObserver != nullptr) { |
| 584 | args->frameStatsObserver->decStrong(args->context); |
| 585 | } |
| 586 | return nullptr; |
| 587 | } |
| 588 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 589 | void RenderProxy::addFrameMetricsObserver(FrameMetricsObserver* observer) { |
| 590 | SETUP_TASK(addFrameMetricsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 591 | args->context = mContext; |
| 592 | args->frameStatsObserver = observer; |
| 593 | if (observer != nullptr) { |
| 594 | observer->incStrong(mContext); |
| 595 | } |
| 596 | post(task); |
| 597 | } |
| 598 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 599 | CREATE_BRIDGE2(removeFrameMetricsObserver, CanvasContext* context, |
| 600 | FrameMetricsObserver* frameStatsObserver) { |
| 601 | args->context->removeFrameMetricsObserver(args->frameStatsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 602 | if (args->frameStatsObserver != nullptr) { |
| 603 | args->frameStatsObserver->decStrong(args->context); |
| 604 | } |
| 605 | return nullptr; |
| 606 | } |
| 607 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 608 | void RenderProxy::removeFrameMetricsObserver(FrameMetricsObserver* observer) { |
| 609 | SETUP_TASK(removeFrameMetricsObserver); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 610 | args->context = mContext; |
| 611 | args->frameStatsObserver = observer; |
| 612 | if (observer != nullptr) { |
| 613 | observer->incStrong(mContext); |
| 614 | } |
| 615 | post(task); |
| 616 | } |
| 617 | |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 618 | CREATE_BRIDGE3(copySurfaceInto, RenderThread* thread, |
| 619 | Surface* surface, SkBitmap* bitmap) { |
| 620 | return (void*) Readback::copySurfaceInto(*args->thread, |
| 621 | *args->surface, args->bitmap); |
| 622 | } |
| 623 | |
John Reck | e94cbc7 | 2016-04-25 13:03:44 -0700 | [diff] [blame] | 624 | int RenderProxy::copySurfaceInto(sp<Surface>& surface, SkBitmap* bitmap) { |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 625 | SETUP_TASK(copySurfaceInto); |
| 626 | args->bitmap = bitmap; |
| 627 | args->surface = surface.get(); |
| 628 | args->thread = &RenderThread::getInstance(); |
John Reck | e94cbc7 | 2016-04-25 13:03:44 -0700 | [diff] [blame] | 629 | return static_cast<int>( |
| 630 | reinterpret_cast<intptr_t>( staticPostAndWait(task) )); |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 631 | } |
| 632 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 633 | void RenderProxy::post(RenderTask* task) { |
| 634 | mRenderThread.queue(task); |
| 635 | } |
| 636 | |
| 637 | void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { |
| 638 | void* retval; |
| 639 | task->setReturnPtr(&retval); |
John Reck | cba287b | 2015-11-10 12:52:44 -0800 | [diff] [blame] | 640 | SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); |
| 641 | AutoMutex _lock(mSyncMutex); |
| 642 | mRenderThread.queue(&syncTask); |
| 643 | mSyncCondition.wait(mSyncMutex); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 644 | return retval; |
| 645 | } |
| 646 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 647 | void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) { |
| 648 | RenderThread& thread = RenderThread::getInstance(); |
| 649 | void* retval; |
| 650 | task->setReturnPtr(&retval); |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 651 | thread.queueAndWait(task); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 652 | return retval; |
| 653 | } |
| 654 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 655 | } /* namespace renderthread */ |
| 656 | } /* namespace uirenderer */ |
| 657 | } /* namespace android */ |