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