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