John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 17 | #define LOG_TAG "ThreadedRenderer" |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_VIEW |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 19 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 20 | #include <algorithm> |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 21 | #include <atomic> |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 22 | #include <inttypes.h> |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 23 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 24 | #include "jni.h" |
| 25 | #include <nativehelper/JNIHelp.h> |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 26 | #include "core_jni_helpers.h" |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 27 | #include <GraphicsJNI.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 28 | #include <nativehelper/ScopedPrimitiveArray.h> |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 29 | |
John Reck | 1fedd91 | 2017-05-23 14:45:22 -0700 | [diff] [blame] | 30 | #include <gui/BufferItemConsumer.h> |
| 31 | #include <gui/BufferQueue.h> |
| 32 | #include <gui/Surface.h> |
| 33 | |
Mathias Agopian | 04d0461 | 2017-03-08 23:21:54 -0800 | [diff] [blame] | 34 | #include <private/EGL/cache.h> |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 35 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 36 | #include <utils/Looper.h> |
| 37 | #include <utils/RefBase.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 38 | #include <utils/StrongPointer.h> |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 39 | #include <utils/Timers.h> |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 40 | #include <utils/TraceUtils.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 41 | #include <android_runtime/android_view_Surface.h> |
| 42 | #include <system/window.h> |
| 43 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 44 | #include "android_os_MessageQueue.h" |
John Reck | 66f0be6 | 2014-05-13 13:39:31 -0700 | [diff] [blame] | 45 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 46 | #include <Animator.h> |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 47 | #include <AnimationContext.h> |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 48 | #include <FrameInfo.h> |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 49 | #include <FrameMetricsObserver.h> |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 50 | #include <IContextFactory.h> |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 51 | #include <Properties.h> |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 52 | #include <PropertyValuesAnimatorSet.h> |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 53 | #include <RenderNode.h> |
John Reck | 66f0be6 | 2014-05-13 13:39:31 -0700 | [diff] [blame] | 54 | #include <renderthread/CanvasContext.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 55 | #include <renderthread/RenderProxy.h> |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 56 | #include <renderthread/RenderTask.h> |
| 57 | #include <renderthread/RenderThread.h> |
Stan Iliev | d495f43 | 2017-10-09 15:49:32 -0400 | [diff] [blame] | 58 | #include <pipeline/skia/ShaderCache.h> |
Derek Sollenberger | e216948 | 2018-11-20 10:57:20 -0500 | [diff] [blame^] | 59 | #include <utils/Color.h> |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 60 | |
| 61 | namespace android { |
| 62 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 63 | using namespace android::uirenderer; |
| 64 | using namespace android::uirenderer::renderthread; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 65 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 66 | struct { |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 67 | jfieldID frameMetrics; |
| 68 | jfieldID timingDataBuffer; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 69 | jfieldID messageQueue; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 70 | jmethodID callback; |
| 71 | } gFrameMetricsObserverClassInfo; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 72 | |
Mihai Popa | 9568800 | 2018-02-23 16:10:11 +0000 | [diff] [blame] | 73 | struct { |
| 74 | jmethodID onFrameDraw; |
| 75 | } gFrameDrawingCallback; |
| 76 | |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 77 | struct { |
| 78 | jmethodID onFrameComplete; |
| 79 | } gFrameCompleteCallback; |
| 80 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 81 | static JNIEnv* getenv(JavaVM* vm) { |
| 82 | JNIEnv* env; |
| 83 | if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
| 84 | LOG_ALWAYS_FATAL("Failed to get JNIEnv for JavaVM: %p", vm); |
| 85 | } |
| 86 | return env; |
| 87 | } |
| 88 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 89 | class OnFinishedEvent { |
| 90 | public: |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 91 | OnFinishedEvent(BaseRenderNodeAnimator* animator, AnimationListener* listener) |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 92 | : animator(animator), listener(listener) {} |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 93 | sp<BaseRenderNodeAnimator> animator; |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 94 | sp<AnimationListener> listener; |
| 95 | }; |
| 96 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 97 | class InvokeAnimationListeners : public MessageHandler { |
| 98 | public: |
Chih-Hung Hsieh | c6baf56 | 2016-04-27 11:29:23 -0700 | [diff] [blame] | 99 | explicit InvokeAnimationListeners(std::vector<OnFinishedEvent>& events) { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 100 | mOnFinishedEvents.swap(events); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 101 | } |
| 102 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 103 | static void callOnFinished(OnFinishedEvent& event) { |
| 104 | event.listener->onAnimationFinished(event.animator.get()); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | virtual void handleMessage(const Message& message) { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 108 | std::for_each(mOnFinishedEvents.begin(), mOnFinishedEvents.end(), callOnFinished); |
| 109 | mOnFinishedEvents.clear(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | private: |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 113 | std::vector<OnFinishedEvent> mOnFinishedEvents; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 116 | class FinishAndInvokeListener : public MessageHandler { |
| 117 | public: |
| 118 | explicit FinishAndInvokeListener(PropertyValuesAnimatorSet* anim) |
| 119 | : mAnimator(anim) { |
| 120 | mListener = anim->getOneShotListener(); |
| 121 | mRequestId = anim->getRequestId(); |
| 122 | } |
| 123 | |
| 124 | virtual void handleMessage(const Message& message) { |
| 125 | if (mAnimator->getRequestId() == mRequestId) { |
| 126 | // Request Id has not changed, meaning there's no animation lifecyle change since the |
| 127 | // message is posted, so go ahead and call finish to make sure the PlayState is properly |
| 128 | // updated. This is needed because before the next frame comes in from UI thread to |
| 129 | // trigger an animation update, there could be reverse/cancel etc. So we need to update |
| 130 | // the playstate in time to ensure all the subsequent events get chained properly. |
| 131 | mAnimator->end(); |
| 132 | } |
| 133 | mListener->onAnimationFinished(nullptr); |
| 134 | } |
| 135 | private: |
| 136 | sp<PropertyValuesAnimatorSet> mAnimator; |
| 137 | sp<AnimationListener> mListener; |
| 138 | uint32_t mRequestId; |
| 139 | }; |
| 140 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 141 | class RenderingException : public MessageHandler { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 142 | public: |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 143 | RenderingException(JavaVM* vm, const std::string& message) |
| 144 | : mVm(vm) |
| 145 | , mMessage(message) { |
| 146 | } |
| 147 | |
| 148 | virtual void handleMessage(const Message&) { |
| 149 | throwException(mVm, mMessage); |
| 150 | } |
| 151 | |
| 152 | static void throwException(JavaVM* vm, const std::string& message) { |
| 153 | JNIEnv* env = getenv(vm); |
| 154 | jniThrowException(env, "java/lang/IllegalStateException", message.c_str()); |
| 155 | } |
| 156 | |
| 157 | private: |
| 158 | JavaVM* mVm; |
| 159 | std::string mMessage; |
| 160 | }; |
| 161 | |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 162 | class FrameCompleteWrapper : public MessageHandler { |
| 163 | public: |
| 164 | FrameCompleteWrapper(JNIEnv* env, jobject jobject) { |
| 165 | mLooper = Looper::getForThread(); |
| 166 | LOG_ALWAYS_FATAL_IF(!mLooper.get(), "Must create runnable on a Looper thread!"); |
| 167 | env->GetJavaVM(&mVm); |
| 168 | mObject = env->NewGlobalRef(jobject); |
| 169 | LOG_ALWAYS_FATAL_IF(!mObject, "Failed to make global ref"); |
| 170 | } |
| 171 | |
| 172 | virtual ~FrameCompleteWrapper() { |
| 173 | releaseObject(); |
| 174 | } |
| 175 | |
| 176 | void postFrameComplete(int64_t frameNr) { |
| 177 | if (mObject) { |
| 178 | mFrameNr = frameNr; |
| 179 | mLooper->sendMessage(this, 0); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | virtual void handleMessage(const Message&) { |
| 184 | if (mObject) { |
| 185 | ATRACE_FORMAT("frameComplete %" PRId64, mFrameNr); |
| 186 | getenv(mVm)->CallVoidMethod(mObject, gFrameCompleteCallback.onFrameComplete, mFrameNr); |
| 187 | releaseObject(); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | private: |
| 192 | JavaVM* mVm; |
| 193 | jobject mObject; |
| 194 | sp<Looper> mLooper; |
| 195 | int64_t mFrameNr = -1; |
| 196 | |
| 197 | void releaseObject() { |
| 198 | if (mObject) { |
| 199 | getenv(mVm)->DeleteGlobalRef(mObject); |
| 200 | mObject = nullptr; |
| 201 | } |
| 202 | } |
| 203 | }; |
| 204 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 205 | class RootRenderNode : public RenderNode, ErrorHandler { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 206 | public: |
Chih-Hung Hsieh | c6baf56 | 2016-04-27 11:29:23 -0700 | [diff] [blame] | 207 | explicit RootRenderNode(JNIEnv* env) : RenderNode() { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 208 | mLooper = Looper::getForThread(); |
| 209 | LOG_ALWAYS_FATAL_IF(!mLooper.get(), |
| 210 | "Must create RootRenderNode on a thread with a looper!"); |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 211 | env->GetJavaVM(&mVm); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | virtual ~RootRenderNode() {} |
| 215 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 216 | virtual void onError(const std::string& message) override { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 217 | mLooper->sendMessage(new RenderingException(mVm, message), 0); |
| 218 | } |
| 219 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 220 | virtual void prepareTree(TreeInfo& info) override { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 221 | info.errorHandler = this; |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 222 | |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 223 | for (auto& anim : mRunningVDAnimators) { |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 224 | // Assume that the property change in VD from the animators will not be consumed. Mark |
| 225 | // otherwise if the VDs are found in the display list tree. For VDs that are not in |
| 226 | // the display list tree, we stop providing animation pulses by 1) removing them from |
| 227 | // the animation list, 2) post a delayed message to end them at end time so their |
| 228 | // listeners can receive the corresponding callbacks. |
| 229 | anim->getVectorDrawable()->setPropertyChangeWillBeConsumed(false); |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 230 | // Mark the VD dirty so it will damage itself during prepareTree. |
| 231 | anim->getVectorDrawable()->markDirty(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 232 | } |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 233 | if (info.mode == TreeInfo::MODE_FULL) { |
| 234 | for (auto &anim : mPausedVDAnimators) { |
| 235 | anim->getVectorDrawable()->setPropertyChangeWillBeConsumed(false); |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 236 | anim->getVectorDrawable()->markDirty(); |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 239 | // TODO: This is hacky |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 240 | info.updateWindowPositions = true; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 241 | RenderNode::prepareTree(info); |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 242 | info.updateWindowPositions = false; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 243 | info.errorHandler = nullptr; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 244 | } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 245 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 246 | void sendMessage(const sp<MessageHandler>& handler) { |
| 247 | mLooper->sendMessage(handler, 0); |
| 248 | } |
| 249 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 250 | void sendMessageDelayed(const sp<MessageHandler>& handler, nsecs_t delayInMs) { |
| 251 | mLooper->sendMessageDelayed(ms2ns(delayInMs), handler, 0); |
| 252 | } |
| 253 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 254 | void attachAnimatingNode(RenderNode* animatingNode) { |
| 255 | mPendingAnimatingRenderNodes.push_back(animatingNode); |
| 256 | } |
| 257 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 258 | void attachPendingVectorDrawableAnimators() { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 259 | mRunningVDAnimators.insert(mPendingVectorDrawableAnimators.begin(), |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 260 | mPendingVectorDrawableAnimators.end()); |
| 261 | mPendingVectorDrawableAnimators.clear(); |
| 262 | } |
| 263 | |
| 264 | void detachAnimators() { |
| 265 | // Remove animators from the list and post a delayed message in future to end the animator |
Doris Liu | 0bfce2c | 2017-05-30 18:52:26 -0700 | [diff] [blame] | 266 | // For infinite animators, remove the listener so we no longer hold a global ref to the AVD |
| 267 | // java object, and therefore the AVD objects in both native and Java can be properly |
| 268 | // released. |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 269 | for (auto& anim : mRunningVDAnimators) { |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 270 | detachVectorDrawableAnimator(anim.get()); |
Doris Liu | 0bfce2c | 2017-05-30 18:52:26 -0700 | [diff] [blame] | 271 | anim->clearOneShotListener(); |
| 272 | } |
| 273 | for (auto& anim : mPausedVDAnimators) { |
| 274 | anim->clearOneShotListener(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 275 | } |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 276 | mRunningVDAnimators.clear(); |
| 277 | mPausedVDAnimators.clear(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Doris Liu | c82e879 | 2016-07-29 16:45:24 -0700 | [diff] [blame] | 280 | // Move all the animators to the paused list, and send a delayed message to notify the finished |
| 281 | // listener. |
| 282 | void pauseAnimators() { |
| 283 | mPausedVDAnimators.insert(mRunningVDAnimators.begin(), mRunningVDAnimators.end()); |
| 284 | for (auto& anim : mRunningVDAnimators) { |
| 285 | detachVectorDrawableAnimator(anim.get()); |
| 286 | } |
| 287 | mRunningVDAnimators.clear(); |
| 288 | } |
| 289 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 290 | void doAttachAnimatingNodes(AnimationContext* context) { |
| 291 | for (size_t i = 0; i < mPendingAnimatingRenderNodes.size(); i++) { |
| 292 | RenderNode* node = mPendingAnimatingRenderNodes[i].get(); |
| 293 | context->addAnimatingRenderNode(*node); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 294 | } |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 295 | mPendingAnimatingRenderNodes.clear(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 298 | // Run VectorDrawable animators after prepareTree. |
| 299 | void runVectorDrawableAnimators(AnimationContext* context, TreeInfo& info) { |
| 300 | // Push staging. |
| 301 | if (info.mode == TreeInfo::MODE_FULL) { |
| 302 | pushStagingVectorDrawableAnimators(context); |
| 303 | } |
| 304 | |
| 305 | // Run the animators in the running list. |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 306 | for (auto it = mRunningVDAnimators.begin(); it != mRunningVDAnimators.end();) { |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 307 | if ((*it)->animate(*context)) { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 308 | it = mRunningVDAnimators.erase(it); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 309 | } else { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 310 | it++; |
| 311 | } |
| 312 | } |
| 313 | |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 314 | // Run the animators in paused list during full sync. |
| 315 | if (info.mode == TreeInfo::MODE_FULL) { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 316 | // During full sync we also need to pulse paused animators, in case their targets |
| 317 | // have been added back to the display list. All the animators that passed the |
| 318 | // scheduled finish time will be removed from the paused list. |
| 319 | for (auto it = mPausedVDAnimators.begin(); it != mPausedVDAnimators.end();) { |
| 320 | if ((*it)->animate(*context)) { |
| 321 | // Animator has finished, remove from the list. |
| 322 | it = mPausedVDAnimators.erase(it); |
| 323 | } else { |
| 324 | it++; |
| 325 | } |
| 326 | } |
| 327 | } |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 328 | |
| 329 | // Move the animators with a target not in DisplayList to paused list. |
| 330 | for (auto it = mRunningVDAnimators.begin(); it != mRunningVDAnimators.end();) { |
| 331 | if (!(*it)->getVectorDrawable()->getPropertyChangeWillBeConsumed()) { |
| 332 | // Vector Drawable is not in the display list, we should remove this animator from |
| 333 | // the list, put it in the paused list, and post a delayed message to end the |
| 334 | // animator. |
| 335 | detachVectorDrawableAnimator(it->get()); |
| 336 | mPausedVDAnimators.insert(*it); |
| 337 | it = mRunningVDAnimators.erase(it); |
| 338 | } else { |
| 339 | it++; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | // Move the animators with a target in DisplayList from paused list to running list, and |
| 344 | // trim paused list. |
| 345 | if (info.mode == TreeInfo::MODE_FULL) { |
| 346 | // Check whether any paused animator's target is back in Display List. If so, put the |
| 347 | // animator back in the running list. |
| 348 | for (auto it = mPausedVDAnimators.begin(); it != mPausedVDAnimators.end();) { |
| 349 | if ((*it)->getVectorDrawable()->getPropertyChangeWillBeConsumed()) { |
| 350 | mRunningVDAnimators.insert(*it); |
| 351 | it = mPausedVDAnimators.erase(it); |
| 352 | } else { |
| 353 | it++; |
| 354 | } |
| 355 | } |
| 356 | // Trim paused VD animators at full sync, so that when Java loses reference to an |
| 357 | // animator, we know we won't be requested to animate it any more, then we remove such |
| 358 | // animators from the paused list so they can be properly freed. We also remove the |
| 359 | // animators from paused list when the time elapsed since start has exceeded duration. |
| 360 | trimPausedVDAnimators(context); |
| 361 | } |
| 362 | |
| 363 | info.out.hasAnimations |= !mRunningVDAnimators.empty(); |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void trimPausedVDAnimators(AnimationContext* context) { |
| 367 | // Trim paused vector drawable animator list. |
| 368 | for (auto it = mPausedVDAnimators.begin(); it != mPausedVDAnimators.end();) { |
| 369 | // Remove paused VD animator if no one else is referencing it. Note that animators that |
| 370 | // have passed scheduled finish time are removed from list when they are being pulsed |
| 371 | // before prepare tree. |
| 372 | // TODO: this is a bit hacky, need to figure out a better way to track when the paused |
| 373 | // animators should be freed. |
| 374 | if ((*it)->getStrongCount() == 1) { |
| 375 | it = mPausedVDAnimators.erase(it); |
| 376 | } else { |
| 377 | it++; |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
Doris Liu | 7f2bf46 | 2016-06-21 16:06:06 -0700 | [diff] [blame] | 382 | void pushStagingVectorDrawableAnimators(AnimationContext* context) { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 383 | for (auto& anim : mRunningVDAnimators) { |
Doris Liu | 7f2bf46 | 2016-06-21 16:06:06 -0700 | [diff] [blame] | 384 | anim->pushStaging(*context); |
| 385 | } |
| 386 | } |
| 387 | |
Doris Liu | 350e652 | 2016-02-19 14:20:37 -0800 | [diff] [blame] | 388 | void destroy() { |
| 389 | for (auto& renderNode : mPendingAnimatingRenderNodes) { |
| 390 | renderNode->animators().endAllStagingAnimators(); |
| 391 | } |
| 392 | mPendingAnimatingRenderNodes.clear(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 393 | mPendingVectorDrawableAnimators.clear(); |
| 394 | } |
| 395 | |
| 396 | void addVectorDrawableAnimator(PropertyValuesAnimatorSet* anim) { |
| 397 | mPendingVectorDrawableAnimators.insert(anim); |
Doris Liu | 350e652 | 2016-02-19 14:20:37 -0800 | [diff] [blame] | 398 | } |
| 399 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 400 | private: |
| 401 | sp<Looper> mLooper; |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 402 | JavaVM* mVm; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 403 | std::vector< sp<RenderNode> > mPendingAnimatingRenderNodes; |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 404 | std::set< sp<PropertyValuesAnimatorSet> > mPendingVectorDrawableAnimators; |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 405 | std::set< sp<PropertyValuesAnimatorSet> > mRunningVDAnimators; |
| 406 | // mPausedVDAnimators stores a list of animators that have not yet passed the finish time, but |
| 407 | // their VectorDrawable targets are no longer in the DisplayList. We skip these animators when |
| 408 | // render thread runs animators independent of UI thread (i.e. RT_ONLY mode). These animators |
| 409 | // need to be re-activated once their VD target is added back into DisplayList. Since that could |
| 410 | // only happen when we do a full sync, we need to make sure to pulse these paused animators at |
| 411 | // full sync. If any animator's VD target is found in DisplayList during a full sync, we move |
| 412 | // the animator back to the running list. |
| 413 | std::set< sp<PropertyValuesAnimatorSet> > mPausedVDAnimators; |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 414 | void detachVectorDrawableAnimator(PropertyValuesAnimatorSet* anim) { |
| 415 | if (anim->isInfinite() || !anim->isRunning()) { |
| 416 | // Do not need to post anything if the animation is infinite (i.e. no meaningful |
| 417 | // end listener action), or if the animation has already ended. |
| 418 | return; |
| 419 | } |
| 420 | nsecs_t remainingTimeInMs = anim->getRemainingPlayTime(); |
| 421 | // Post a delayed onFinished event that is scheduled to be handled when the animator ends. |
| 422 | if (anim->getOneShotListener()) { |
| 423 | // VectorDrawable's oneshot listener is updated when there are user triggered animation |
| 424 | // lifecycle changes, such as start(), end(), etc. By using checking and clearing |
| 425 | // one shot listener, we ensure the same end listener event gets posted only once. |
| 426 | // Therefore no duplicates. Another benefit of using one shot listener is that no |
| 427 | // removal is necessary: the end time of animation will not change unless triggered by |
| 428 | // user events, in which case the already posted listener's id will become stale, and |
| 429 | // the onFinished callback will then be ignored. |
| 430 | sp<FinishAndInvokeListener> message |
| 431 | = new FinishAndInvokeListener(anim); |
| 432 | sendMessageDelayed(message, remainingTimeInMs); |
| 433 | anim->clearOneShotListener(); |
| 434 | } |
| 435 | } |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | class AnimationContextBridge : public AnimationContext { |
| 439 | public: |
| 440 | AnimationContextBridge(renderthread::TimeLord& clock, RootRenderNode* rootNode) |
| 441 | : AnimationContext(clock), mRootNode(rootNode) { |
| 442 | } |
| 443 | |
| 444 | virtual ~AnimationContextBridge() {} |
| 445 | |
| 446 | // Marks the start of a frame, which will update the frame time and move all |
| 447 | // next frame animations into the current frame |
John Reck | ec845a2 | 2014-09-05 15:23:38 -0700 | [diff] [blame] | 448 | virtual void startFrame(TreeInfo::TraversalMode mode) { |
| 449 | if (mode == TreeInfo::MODE_FULL) { |
| 450 | mRootNode->doAttachAnimatingNodes(this); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 451 | mRootNode->attachPendingVectorDrawableAnimators(); |
John Reck | ec845a2 | 2014-09-05 15:23:38 -0700 | [diff] [blame] | 452 | } |
| 453 | AnimationContext::startFrame(mode); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | // Runs any animations still left in mCurrentFrameAnimations |
| 457 | virtual void runRemainingAnimations(TreeInfo& info) { |
| 458 | AnimationContext::runRemainingAnimations(info); |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 459 | mRootNode->runVectorDrawableAnimators(this, info); |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 460 | postOnFinishedEvents(); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Doris Liu | c82e879 | 2016-07-29 16:45:24 -0700 | [diff] [blame] | 463 | virtual void pauseAnimators() override { |
| 464 | mRootNode->pauseAnimators(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 465 | } |
| 466 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 467 | virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) { |
| 468 | OnFinishedEvent event(animator, listener); |
| 469 | mOnFinishedEvents.push_back(event); |
| 470 | } |
| 471 | |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 472 | virtual void destroy() { |
| 473 | AnimationContext::destroy(); |
Doris Liu | c82e879 | 2016-07-29 16:45:24 -0700 | [diff] [blame] | 474 | mRootNode->detachAnimators(); |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 475 | postOnFinishedEvents(); |
| 476 | } |
| 477 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 478 | private: |
| 479 | sp<RootRenderNode> mRootNode; |
| 480 | std::vector<OnFinishedEvent> mOnFinishedEvents; |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 481 | |
| 482 | void postOnFinishedEvents() { |
| 483 | if (mOnFinishedEvents.size()) { |
| 484 | sp<InvokeAnimationListeners> message |
| 485 | = new InvokeAnimationListeners(mOnFinishedEvents); |
| 486 | mRootNode->sendMessage(message); |
| 487 | } |
| 488 | } |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 489 | }; |
| 490 | |
| 491 | class ContextFactoryImpl : public IContextFactory { |
| 492 | public: |
Chih-Hung Hsieh | c6baf56 | 2016-04-27 11:29:23 -0700 | [diff] [blame] | 493 | explicit ContextFactoryImpl(RootRenderNode* rootNode) : mRootNode(rootNode) {} |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 494 | |
| 495 | virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) { |
| 496 | return new AnimationContextBridge(clock, mRootNode); |
| 497 | } |
| 498 | |
| 499 | private: |
| 500 | RootRenderNode* mRootNode; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 501 | }; |
| 502 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 503 | class ObserverProxy; |
| 504 | |
| 505 | class NotifyHandler : public MessageHandler { |
| 506 | public: |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 507 | NotifyHandler(JavaVM* vm, ObserverProxy* observer) : mVm(vm), mObserver(observer) {} |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 508 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 509 | virtual void handleMessage(const Message& message); |
| 510 | |
| 511 | private: |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 512 | JavaVM* const mVm; |
| 513 | ObserverProxy* const mObserver; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 514 | }; |
| 515 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 516 | static jlongArray get_metrics_buffer(JNIEnv* env, jobject observer) { |
| 517 | jobject frameMetrics = env->GetObjectField( |
| 518 | observer, gFrameMetricsObserverClassInfo.frameMetrics); |
| 519 | LOG_ALWAYS_FATAL_IF(frameMetrics == nullptr, "unable to retrieve data sink object"); |
| 520 | jobject buffer = env->GetObjectField( |
| 521 | frameMetrics, gFrameMetricsObserverClassInfo.timingDataBuffer); |
| 522 | LOG_ALWAYS_FATAL_IF(buffer == nullptr, "unable to retrieve data sink buffer"); |
| 523 | return reinterpret_cast<jlongArray>(buffer); |
| 524 | } |
| 525 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 526 | /* |
| 527 | * Implements JNI layer for hwui frame metrics reporting. |
| 528 | */ |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 529 | class ObserverProxy : public FrameMetricsObserver { |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 530 | public: |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 531 | ObserverProxy(JavaVM *vm, jobject observer) : mVm(vm) { |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 532 | JNIEnv* env = getenv(mVm); |
| 533 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 534 | mObserverWeak = env->NewWeakGlobalRef(observer); |
| 535 | LOG_ALWAYS_FATAL_IF(mObserverWeak == nullptr, |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 536 | "unable to create frame stats observer reference"); |
| 537 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 538 | jlongArray buffer = get_metrics_buffer(env, observer); |
| 539 | jsize bufferSize = env->GetArrayLength(reinterpret_cast<jarray>(buffer)); |
| 540 | LOG_ALWAYS_FATAL_IF(bufferSize != kBufferSize, |
| 541 | "Mismatched Java/Native FrameMetrics data format."); |
| 542 | |
| 543 | jobject messageQueueLocal = env->GetObjectField( |
| 544 | observer, gFrameMetricsObserverClassInfo.messageQueue); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 545 | mMessageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueLocal); |
| 546 | LOG_ALWAYS_FATAL_IF(mMessageQueue == nullptr, "message queue not available"); |
| 547 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 548 | mMessageHandler = new NotifyHandler(mVm, this); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 549 | LOG_ALWAYS_FATAL_IF(mMessageHandler == nullptr, |
| 550 | "OOM: unable to allocate NotifyHandler"); |
| 551 | } |
| 552 | |
| 553 | ~ObserverProxy() { |
| 554 | JNIEnv* env = getenv(mVm); |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 555 | env->DeleteWeakGlobalRef(mObserverWeak); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 558 | jweak getObserverReference() { |
| 559 | return mObserverWeak; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 562 | bool getNextBuffer(JNIEnv* env, jlongArray sink, int* dropCount) { |
| 563 | FrameMetricsNotification& elem = mRingBuffer[mNextInQueue]; |
| 564 | |
| 565 | if (elem.hasData.load()) { |
| 566 | env->SetLongArrayRegion(sink, 0, kBufferSize, elem.buffer); |
| 567 | *dropCount = elem.dropCount; |
| 568 | mNextInQueue = (mNextInQueue + 1) % kRingSize; |
| 569 | elem.hasData = false; |
| 570 | return true; |
| 571 | } |
| 572 | |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | virtual void notify(const int64_t* stats) { |
| 577 | FrameMetricsNotification& elem = mRingBuffer[mNextFree]; |
| 578 | |
| 579 | if (!elem.hasData.load()) { |
| 580 | memcpy(elem.buffer, stats, kBufferSize * sizeof(stats[0])); |
| 581 | |
| 582 | elem.dropCount = mDroppedReports; |
| 583 | mDroppedReports = 0; |
| 584 | |
| 585 | incStrong(nullptr); |
| 586 | mNextFree = (mNextFree + 1) % kRingSize; |
| 587 | elem.hasData = true; |
| 588 | |
| 589 | mMessageQueue->getLooper()->sendMessage(mMessageHandler, mMessage); |
| 590 | } else { |
| 591 | mDroppedReports++; |
| 592 | } |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | private: |
| 596 | static const int kBufferSize = static_cast<int>(FrameInfoIndex::NumIndexes); |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 597 | static constexpr int kRingSize = 3; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 598 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 599 | class FrameMetricsNotification { |
| 600 | public: |
| 601 | FrameMetricsNotification() : hasData(false) {} |
| 602 | |
| 603 | std::atomic_bool hasData; |
| 604 | int64_t buffer[kBufferSize]; |
| 605 | int dropCount = 0; |
| 606 | }; |
| 607 | |
| 608 | JavaVM* const mVm; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 609 | jweak mObserverWeak; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 610 | |
| 611 | sp<MessageQueue> mMessageQueue; |
| 612 | sp<NotifyHandler> mMessageHandler; |
| 613 | Message mMessage; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 614 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 615 | int mNextFree = 0; |
| 616 | int mNextInQueue = 0; |
| 617 | FrameMetricsNotification mRingBuffer[kRingSize]; |
| 618 | |
| 619 | int mDroppedReports = 0; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 620 | }; |
| 621 | |
| 622 | void NotifyHandler::handleMessage(const Message& message) { |
| 623 | JNIEnv* env = getenv(mVm); |
| 624 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 625 | jobject target = env->NewLocalRef(mObserver->getObserverReference()); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 626 | |
| 627 | if (target != nullptr) { |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 628 | jlongArray javaBuffer = get_metrics_buffer(env, target); |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 629 | int dropCount = 0; |
| 630 | while (mObserver->getNextBuffer(env, javaBuffer, &dropCount)) { |
| 631 | env->CallVoidMethod(target, gFrameMetricsObserverClassInfo.callback, dropCount); |
| 632 | } |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 633 | env->DeleteLocalRef(target); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 634 | } |
| 635 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 636 | mObserver->decStrong(nullptr); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 637 | } |
| 638 | |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 639 | static void android_view_ThreadedRenderer_rotateProcessStatsBuffer(JNIEnv* env, jobject clazz) { |
| 640 | RenderProxy::rotateProcessStatsBuffer(); |
| 641 | } |
| 642 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 643 | static void android_view_ThreadedRenderer_setProcessStatsBuffer(JNIEnv* env, jobject clazz, |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 644 | jint fd) { |
| 645 | RenderProxy::setProcessStatsBuffer(fd); |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 648 | static jint android_view_ThreadedRenderer_getRenderThreadTid(JNIEnv* env, jobject clazz, |
| 649 | jlong proxyPtr) { |
| 650 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 651 | return proxy->getRenderThreadTid(); |
| 652 | } |
| 653 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 654 | static jlong android_view_ThreadedRenderer_createRootRenderNode(JNIEnv* env, jobject clazz) { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 655 | RootRenderNode* node = new RootRenderNode(env); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 656 | node->incStrong(0); |
| 657 | node->setName("RootRenderNode"); |
| 658 | return reinterpret_cast<jlong>(node); |
| 659 | } |
| 660 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 661 | static jlong android_view_ThreadedRenderer_createProxy(JNIEnv* env, jobject clazz, |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 662 | jboolean translucent, jlong rootRenderNodePtr) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 663 | RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootRenderNodePtr); |
| 664 | ContextFactoryImpl factory(rootRenderNode); |
| 665 | return (jlong) new RenderProxy(translucent, rootRenderNode, &factory); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static void android_view_ThreadedRenderer_deleteProxy(JNIEnv* env, jobject clazz, |
| 669 | jlong proxyPtr) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 670 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 671 | delete proxy; |
| 672 | } |
| 673 | |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 674 | static jboolean android_view_ThreadedRenderer_loadSystemProperties(JNIEnv* env, jobject clazz, |
| 675 | jlong proxyPtr) { |
| 676 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 677 | return proxy->loadSystemProperties(); |
| 678 | } |
| 679 | |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 680 | static void android_view_ThreadedRenderer_setName(JNIEnv* env, jobject clazz, |
| 681 | jlong proxyPtr, jstring jname) { |
| 682 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 683 | const char* name = env->GetStringUTFChars(jname, NULL); |
| 684 | proxy->setName(name); |
| 685 | env->ReleaseStringUTFChars(jname, name); |
| 686 | } |
| 687 | |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 688 | static void android_view_ThreadedRenderer_setSurface(JNIEnv* env, jobject clazz, |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 689 | jlong proxyPtr, jobject jsurface) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 690 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 691 | sp<Surface> surface; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 692 | if (jsurface) { |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 693 | surface = android_view_Surface_getSurface(env, jsurface); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 694 | } |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 695 | proxy->setSurface(surface); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 696 | } |
| 697 | |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 698 | static jboolean android_view_ThreadedRenderer_pause(JNIEnv* env, jobject clazz, |
| 699 | jlong proxyPtr) { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 700 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 701 | return proxy->pause(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 702 | } |
| 703 | |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 704 | static void android_view_ThreadedRenderer_setStopped(JNIEnv* env, jobject clazz, |
| 705 | jlong proxyPtr, jboolean stopped) { |
| 706 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 707 | proxy->setStopped(stopped); |
| 708 | } |
| 709 | |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 710 | static void android_view_ThreadedRenderer_setLightAlpha(JNIEnv* env, jobject clazz, jlong proxyPtr, |
| 711 | jfloat ambientShadowAlpha, jfloat spotShadowAlpha) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 712 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 713 | proxy->setLightAlpha((uint8_t) (255 * ambientShadowAlpha), (uint8_t) (255 * spotShadowAlpha)); |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 714 | } |
| 715 | |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 716 | static void android_view_ThreadedRenderer_setLightGeometry(JNIEnv* env, jobject clazz, |
| 717 | jlong proxyPtr, jfloat lightX, jfloat lightY, jfloat lightZ, jfloat lightRadius) { |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 718 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 719 | proxy->setLightGeometry((Vector3){lightX, lightY, lightZ}, lightRadius); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 720 | } |
| 721 | |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 722 | static void android_view_ThreadedRenderer_setOpaque(JNIEnv* env, jobject clazz, |
| 723 | jlong proxyPtr, jboolean opaque) { |
| 724 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 725 | proxy->setOpaque(opaque); |
| 726 | } |
| 727 | |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 728 | static void android_view_ThreadedRenderer_setWideGamut(JNIEnv* env, jobject clazz, |
| 729 | jlong proxyPtr, jboolean wideGamut) { |
| 730 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 731 | proxy->setWideGamut(wideGamut); |
| 732 | } |
| 733 | |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 734 | static int android_view_ThreadedRenderer_syncAndDrawFrame(JNIEnv* env, jobject clazz, |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 735 | jlong proxyPtr, jlongArray frameInfo, jint frameInfoSize) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 736 | LOG_ALWAYS_FATAL_IF(frameInfoSize != UI_THREAD_FRAME_INFO_SIZE, |
| 737 | "Mismatched size expectations, given %d expected %d", |
| 738 | frameInfoSize, UI_THREAD_FRAME_INFO_SIZE); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 739 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 740 | env->GetLongArrayRegion(frameInfo, 0, frameInfoSize, proxy->frameInfo()); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 741 | return proxy->syncAndDrawFrame(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 742 | } |
| 743 | |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 744 | static void android_view_ThreadedRenderer_destroy(JNIEnv* env, jobject clazz, |
Doris Liu | 350e652 | 2016-02-19 14:20:37 -0800 | [diff] [blame] | 745 | jlong proxyPtr, jlong rootNodePtr) { |
| 746 | RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootNodePtr); |
| 747 | rootRenderNode->destroy(); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 748 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 749 | proxy->destroy(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 750 | } |
| 751 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 752 | static void android_view_ThreadedRenderer_registerAnimatingRenderNode(JNIEnv* env, jobject clazz, |
| 753 | jlong rootNodePtr, jlong animatingNodePtr) { |
| 754 | RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootNodePtr); |
| 755 | RenderNode* animatingNode = reinterpret_cast<RenderNode*>(animatingNodePtr); |
| 756 | rootRenderNode->attachAnimatingNode(animatingNode); |
| 757 | } |
| 758 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 759 | static void android_view_ThreadedRenderer_registerVectorDrawableAnimator(JNIEnv* env, jobject clazz, |
| 760 | jlong rootNodePtr, jlong animatorPtr) { |
| 761 | RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootNodePtr); |
| 762 | PropertyValuesAnimatorSet* animator = reinterpret_cast<PropertyValuesAnimatorSet*>(animatorPtr); |
| 763 | rootRenderNode->addVectorDrawableAnimator(animator); |
| 764 | } |
| 765 | |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 766 | static void android_view_ThreadedRenderer_invokeFunctor(JNIEnv* env, jobject clazz, |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 767 | jlong functorPtr, jboolean waitForCompletion) { |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 768 | Functor* functor = reinterpret_cast<Functor*>(functorPtr); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 769 | RenderProxy::invokeFunctor(functor, waitForCompletion); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 770 | } |
| 771 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 772 | static jlong android_view_ThreadedRenderer_createTextureLayer(JNIEnv* env, jobject clazz, |
| 773 | jlong proxyPtr) { |
| 774 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 775 | DeferredLayerUpdater* layer = proxy->createTextureLayer(); |
| 776 | return reinterpret_cast<jlong>(layer); |
| 777 | } |
| 778 | |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 779 | static void android_view_ThreadedRenderer_buildLayer(JNIEnv* env, jobject clazz, |
| 780 | jlong proxyPtr, jlong nodePtr) { |
| 781 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 782 | RenderNode* node = reinterpret_cast<RenderNode*>(nodePtr); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 783 | proxy->buildLayer(node); |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 784 | } |
| 785 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 786 | static jboolean android_view_ThreadedRenderer_copyLayerInto(JNIEnv* env, jobject clazz, |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 787 | jlong proxyPtr, jlong layerPtr, jobject jbitmap) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 788 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 789 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 790 | SkBitmap bitmap; |
| 791 | GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 792 | return proxy->copyLayerInto(layer, bitmap); |
| 793 | } |
| 794 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 795 | static void android_view_ThreadedRenderer_pushLayerUpdate(JNIEnv* env, jobject clazz, |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 796 | jlong proxyPtr, jlong layerPtr) { |
| 797 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 798 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 799 | proxy->pushLayerUpdate(layer); |
| 800 | } |
| 801 | |
| 802 | static void android_view_ThreadedRenderer_cancelLayerUpdate(JNIEnv* env, jobject clazz, |
| 803 | jlong proxyPtr, jlong layerPtr) { |
| 804 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 805 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
| 806 | proxy->cancelLayerUpdate(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 807 | } |
| 808 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 809 | static void android_view_ThreadedRenderer_detachSurfaceTexture(JNIEnv* env, jobject clazz, |
| 810 | jlong proxyPtr, jlong layerPtr) { |
| 811 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 812 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
| 813 | proxy->detachSurfaceTexture(layer); |
| 814 | } |
| 815 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 816 | static void android_view_ThreadedRenderer_destroyHardwareResources(JNIEnv* env, jobject clazz, |
| 817 | jlong proxyPtr) { |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 818 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 819 | proxy->destroyHardwareResources(); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | static void android_view_ThreadedRenderer_trimMemory(JNIEnv* env, jobject clazz, |
| 823 | jint level) { |
| 824 | RenderProxy::trimMemory(level); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 827 | static void android_view_ThreadedRenderer_overrideProperty(JNIEnv* env, jobject clazz, |
| 828 | jstring name, jstring value) { |
| 829 | const char* nameCharArray = env->GetStringUTFChars(name, NULL); |
| 830 | const char* valueCharArray = env->GetStringUTFChars(value, NULL); |
| 831 | RenderProxy::overrideProperty(nameCharArray, valueCharArray); |
| 832 | env->ReleaseStringUTFChars(name, nameCharArray); |
| 833 | env->ReleaseStringUTFChars(name, valueCharArray); |
| 834 | } |
| 835 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 836 | static void android_view_ThreadedRenderer_fence(JNIEnv* env, jobject clazz, |
| 837 | jlong proxyPtr) { |
| 838 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 839 | proxy->fence(); |
| 840 | } |
| 841 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 842 | static void android_view_ThreadedRenderer_stopDrawing(JNIEnv* env, jobject clazz, |
| 843 | jlong proxyPtr) { |
| 844 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 845 | proxy->stopDrawing(); |
| 846 | } |
| 847 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 848 | static void android_view_ThreadedRenderer_notifyFramePending(JNIEnv* env, jobject clazz, |
| 849 | jlong proxyPtr) { |
| 850 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 851 | proxy->notifyFramePending(); |
| 852 | } |
| 853 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 854 | static void android_view_ThreadedRenderer_dumpProfileInfo(JNIEnv* env, jobject clazz, |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 855 | jlong proxyPtr, jobject javaFileDescriptor, jint dumpFlags) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 856 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 857 | int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 858 | proxy->dumpProfileInfo(fd, dumpFlags); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 861 | static void android_view_ThreadedRenderer_addRenderNode(JNIEnv* env, jobject clazz, |
| 862 | jlong proxyPtr, jlong renderNodePtr, jboolean placeFront) { |
| 863 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 864 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 865 | proxy->addRenderNode(renderNode, placeFront); |
| 866 | } |
| 867 | |
| 868 | static void android_view_ThreadedRenderer_removeRenderNode(JNIEnv* env, jobject clazz, |
| 869 | jlong proxyPtr, jlong renderNodePtr) { |
| 870 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 871 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 872 | proxy->removeRenderNode(renderNode); |
| 873 | } |
| 874 | |
| 875 | static void android_view_ThreadedRendererd_drawRenderNode(JNIEnv* env, jobject clazz, |
| 876 | jlong proxyPtr, jlong renderNodePtr) { |
| 877 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 878 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 879 | proxy->drawRenderNode(renderNode); |
| 880 | } |
| 881 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 882 | static void android_view_ThreadedRenderer_setContentDrawBounds(JNIEnv* env, |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 883 | jobject clazz, jlong proxyPtr, jint left, jint top, jint right, jint bottom) { |
| 884 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 885 | proxy->setContentDrawBounds(left, top, right, bottom); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 886 | } |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 887 | |
Mihai Popa | 9568800 | 2018-02-23 16:10:11 +0000 | [diff] [blame] | 888 | class JGlobalRefHolder { |
| 889 | public: |
| 890 | JGlobalRefHolder(JavaVM* vm, jobject object) : mVm(vm), mObject(object) {} |
| 891 | |
| 892 | virtual ~JGlobalRefHolder() { |
| 893 | getenv(mVm)->DeleteGlobalRef(mObject); |
| 894 | mObject = nullptr; |
| 895 | } |
| 896 | |
| 897 | jobject object() { return mObject; } |
| 898 | JavaVM* vm() { return mVm; } |
| 899 | |
| 900 | private: |
| 901 | JGlobalRefHolder(const JGlobalRefHolder&) = delete; |
| 902 | void operator=(const JGlobalRefHolder&) = delete; |
| 903 | |
| 904 | JavaVM* mVm; |
| 905 | jobject mObject; |
| 906 | }; |
| 907 | |
| 908 | static void android_view_ThreadedRenderer_setFrameCallback(JNIEnv* env, |
| 909 | jobject clazz, jlong proxyPtr, jobject frameCallback) { |
| 910 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 911 | if (!frameCallback) { |
| 912 | proxy->setFrameCallback(nullptr); |
| 913 | } else { |
| 914 | JavaVM* vm = nullptr; |
| 915 | LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&vm) != JNI_OK, "Unable to get Java VM"); |
| 916 | auto globalCallbackRef = std::make_shared<JGlobalRefHolder>(vm, |
| 917 | env->NewGlobalRef(frameCallback)); |
| 918 | proxy->setFrameCallback([globalCallbackRef](int64_t frameNr) { |
| 919 | JNIEnv* env = getenv(globalCallbackRef->vm()); |
| 920 | env->CallVoidMethod(globalCallbackRef->object(), gFrameDrawingCallback.onFrameDraw, |
| 921 | static_cast<jlong>(frameNr)); |
| 922 | }); |
| 923 | } |
| 924 | } |
| 925 | |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 926 | static void android_view_ThreadedRenderer_setFrameCompleteCallback(JNIEnv* env, |
| 927 | jobject clazz, jlong proxyPtr, jobject callback) { |
| 928 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 929 | if (!callback) { |
| 930 | proxy->setFrameCompleteCallback(nullptr); |
| 931 | } else { |
| 932 | sp<FrameCompleteWrapper> wrapper = new FrameCompleteWrapper{env, callback}; |
| 933 | proxy->setFrameCompleteCallback([wrapper](int64_t frameNr) { |
| 934 | wrapper->postFrameComplete(frameNr); |
| 935 | }); |
| 936 | } |
| 937 | } |
| 938 | |
John Reck | e94cbc7 | 2016-04-25 13:03:44 -0700 | [diff] [blame] | 939 | static jint android_view_ThreadedRenderer_copySurfaceInto(JNIEnv* env, |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 940 | jobject clazz, jobject jsurface, jint left, jint top, |
| 941 | jint right, jint bottom, jobject jbitmap) { |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 942 | SkBitmap bitmap; |
| 943 | GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); |
| 944 | sp<Surface> surface = android_view_Surface_getSurface(env, jsurface); |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 945 | return RenderProxy::copySurfaceInto(surface, left, top, right, bottom, &bitmap); |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 946 | } |
| 947 | |
John Reck | 1fedd91 | 2017-05-23 14:45:22 -0700 | [diff] [blame] | 948 | class ContextFactory : public IContextFactory { |
| 949 | public: |
| 950 | virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) { |
| 951 | return new AnimationContext(clock); |
| 952 | } |
| 953 | }; |
| 954 | |
| 955 | static jobject android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode(JNIEnv* env, |
| 956 | jobject clazz, jlong renderNodePtr, jint jwidth, jint jheight) { |
| 957 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 958 | if (jwidth <= 0 || jheight <= 0) { |
| 959 | ALOGW("Invalid width %d or height %d", jwidth, jheight); |
| 960 | return nullptr; |
| 961 | } |
| 962 | |
| 963 | uint32_t width = jwidth; |
| 964 | uint32_t height = jheight; |
| 965 | |
| 966 | // Create a Surface wired up to a BufferItemConsumer |
| 967 | sp<IGraphicBufferProducer> producer; |
| 968 | sp<IGraphicBufferConsumer> rawConsumer; |
| 969 | BufferQueue::createBufferQueue(&producer, &rawConsumer); |
John Reck | a67b62e | 2017-06-01 12:44:58 -0700 | [diff] [blame] | 970 | // We only need 1 buffer but some drivers have bugs so workaround it by setting max count to 2 |
| 971 | rawConsumer->setMaxBufferCount(2); |
John Reck | 1fedd91 | 2017-05-23 14:45:22 -0700 | [diff] [blame] | 972 | sp<BufferItemConsumer> consumer = new BufferItemConsumer(rawConsumer, |
| 973 | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER); |
| 974 | consumer->setDefaultBufferSize(width, height); |
| 975 | sp<Surface> surface = new Surface(producer); |
| 976 | |
| 977 | // Render into the surface |
| 978 | { |
| 979 | ContextFactory factory; |
John Reck | 226fcca | 2017-09-05 11:24:59 -0700 | [diff] [blame] | 980 | RenderProxy proxy{true, renderNode, &factory}; |
John Reck | 1fedd91 | 2017-05-23 14:45:22 -0700 | [diff] [blame] | 981 | proxy.setSwapBehavior(SwapBehavior::kSwap_discardBuffer); |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 982 | proxy.setSurface(surface); |
John Reck | 1fedd91 | 2017-05-23 14:45:22 -0700 | [diff] [blame] | 983 | // Shadows can't be used via this interface, so just set the light source |
| 984 | // to all 0s. |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 985 | proxy.setLightAlpha(0, 0); |
| 986 | proxy.setLightGeometry((Vector3){0, 0, 0}, 0); |
John Reck | 1fedd91 | 2017-05-23 14:45:22 -0700 | [diff] [blame] | 987 | nsecs_t vsync = systemTime(CLOCK_MONOTONIC); |
| 988 | UiFrameInfoBuilder(proxy.frameInfo()) |
| 989 | .setVsync(vsync, vsync) |
| 990 | .addFlag(FrameInfoFlags::SurfaceCanvas); |
| 991 | proxy.syncAndDrawFrame(); |
| 992 | } |
| 993 | |
| 994 | // Yank out the GraphicBuffer |
| 995 | BufferItem bufferItem; |
| 996 | status_t err; |
| 997 | if ((err = consumer->acquireBuffer(&bufferItem, 0, true)) != OK) { |
| 998 | ALOGW("Failed to acquireBuffer, error %d (%s)", err, strerror(-err)); |
| 999 | return nullptr; |
| 1000 | } |
| 1001 | sp<GraphicBuffer> buffer = bufferItem.mGraphicBuffer; |
| 1002 | // We don't really care if this fails or not since we're just going to destroy this anyway |
| 1003 | consumer->releaseBuffer(bufferItem); |
| 1004 | if (!buffer.get()) { |
| 1005 | ALOGW("GraphicBuffer is null?"); |
| 1006 | return nullptr; |
| 1007 | } |
| 1008 | if (buffer->getWidth() != width || buffer->getHeight() != height) { |
| 1009 | ALOGW("GraphicBuffer size mismatch, got %dx%d expected %dx%d", |
| 1010 | buffer->getWidth(), buffer->getHeight(), width, height); |
| 1011 | // Continue I guess? |
| 1012 | } |
Derek Sollenberger | e216948 | 2018-11-20 10:57:20 -0500 | [diff] [blame^] | 1013 | |
| 1014 | sk_sp<SkColorSpace> cs = uirenderer::DataSpaceToColorSpace(bufferItem.mDataSpace); |
| 1015 | sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer, cs); |
Stan Iliev | c231182 | 2017-08-23 16:25:33 -0400 | [diff] [blame] | 1016 | return bitmap::createBitmap(env, bitmap.release(), |
| 1017 | android::bitmap::kBitmapCreateFlag_Premultiplied); |
John Reck | 1fedd91 | 2017-05-23 14:45:22 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
John Reck | a896306 | 2017-06-14 10:47:50 -0700 | [diff] [blame] | 1020 | static void android_view_ThreadedRenderer_disableVsync(JNIEnv*, jclass) { |
| 1021 | RenderProxy::disableVsync(); |
| 1022 | } |
| 1023 | |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 1024 | static void android_view_ThreadedRenderer_setHighContrastText(JNIEnv*, jclass, jboolean enable) { |
| 1025 | Properties::enableHighContrastText = enable; |
| 1026 | } |
| 1027 | |
John Reck | 9f51644 | 2017-09-25 10:27:21 -0700 | [diff] [blame] | 1028 | static void android_view_ThreadedRenderer_hackySetRTAnimationsEnabled(JNIEnv*, jclass, |
| 1029 | jboolean enable) { |
| 1030 | Properties::enableRTAnimations = enable; |
| 1031 | } |
| 1032 | |
John Reck | 6afa009 | 2018-03-01 17:28:35 -0800 | [diff] [blame] | 1033 | static void android_view_ThreadedRenderer_setDebuggingEnabled(JNIEnv*, jclass, jboolean enable) { |
| 1034 | Properties::debuggingEnabled = enable; |
| 1035 | } |
| 1036 | |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 1037 | static void android_view_ThreadedRenderer_setIsolatedProcess(JNIEnv*, jclass, jboolean isolated) { |
| 1038 | Properties::isolatedProcess = isolated; |
| 1039 | } |
| 1040 | |
Jorim Jaggi | 767e25e | 2018-04-04 23:07:35 +0200 | [diff] [blame] | 1041 | static void android_view_ThreadedRenderer_setContextPriority(JNIEnv*, jclass, |
| 1042 | jint contextPriority) { |
| 1043 | Properties::contextPriority = contextPriority; |
| 1044 | } |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 1045 | |
Jorim Jaggi | 7823ee7 | 2018-07-17 15:24:16 +0200 | [diff] [blame] | 1046 | static void android_view_ThreadedRenderer_allocateBuffers(JNIEnv* env, jobject clazz, |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1047 | jlong proxyPtr) { |
Jorim Jaggi | 7823ee7 | 2018-07-17 15:24:16 +0200 | [diff] [blame] | 1048 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1049 | proxy->allocateBuffers(); |
Jorim Jaggi | 7823ee7 | 2018-07-17 15:24:16 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
John Reck | bb3a358 | 2018-09-26 11:21:08 -0700 | [diff] [blame] | 1052 | static void android_view_ThreadedRenderer_setForceDark(JNIEnv* env, jobject clazz, |
| 1053 | jlong proxyPtr, jboolean enable) { |
| 1054 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 1055 | proxy->setForceDark(enable); |
| 1056 | } |
| 1057 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1058 | // ---------------------------------------------------------------------------- |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1059 | // FrameMetricsObserver |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 1060 | // ---------------------------------------------------------------------------- |
| 1061 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1062 | static jlong android_view_ThreadedRenderer_addFrameMetricsObserver(JNIEnv* env, |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 1063 | jclass clazz, jlong proxyPtr, jobject fso) { |
| 1064 | JavaVM* vm = nullptr; |
| 1065 | if (env->GetJavaVM(&vm) != JNI_OK) { |
| 1066 | LOG_ALWAYS_FATAL("Unable to get Java VM"); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | renderthread::RenderProxy* renderProxy = |
| 1071 | reinterpret_cast<renderthread::RenderProxy*>(proxyPtr); |
| 1072 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1073 | FrameMetricsObserver* observer = new ObserverProxy(vm, fso); |
| 1074 | renderProxy->addFrameMetricsObserver(observer); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 1075 | return reinterpret_cast<jlong>(observer); |
| 1076 | } |
| 1077 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1078 | static void android_view_ThreadedRenderer_removeFrameMetricsObserver(JNIEnv* env, jclass clazz, |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 1079 | jlong proxyPtr, jlong observerPtr) { |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1080 | FrameMetricsObserver* observer = reinterpret_cast<FrameMetricsObserver*>(observerPtr); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 1081 | renderthread::RenderProxy* renderProxy = |
| 1082 | reinterpret_cast<renderthread::RenderProxy*>(proxyPtr); |
| 1083 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1084 | renderProxy->removeFrameMetricsObserver(observer); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | // ---------------------------------------------------------------------------- |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 1088 | // Shaders |
| 1089 | // ---------------------------------------------------------------------------- |
| 1090 | |
| 1091 | static void android_view_ThreadedRenderer_setupShadersDiskCache(JNIEnv* env, jobject clazz, |
Stan Iliev | d495f43 | 2017-10-09 15:49:32 -0400 | [diff] [blame] | 1092 | jstring diskCachePath, jstring skiaDiskCachePath) { |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 1093 | const char* cacheArray = env->GetStringUTFChars(diskCachePath, NULL); |
Mathias Agopian | 04d0461 | 2017-03-08 23:21:54 -0800 | [diff] [blame] | 1094 | android::egl_set_cache_filename(cacheArray); |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 1095 | env->ReleaseStringUTFChars(diskCachePath, cacheArray); |
Stan Iliev | d495f43 | 2017-10-09 15:49:32 -0400 | [diff] [blame] | 1096 | |
| 1097 | const char* skiaCacheArray = env->GetStringUTFChars(skiaDiskCachePath, NULL); |
| 1098 | uirenderer::skiapipeline::ShaderCache::get().setFilename(skiaCacheArray); |
| 1099 | env->ReleaseStringUTFChars(skiaDiskCachePath, skiaCacheArray); |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | // ---------------------------------------------------------------------------- |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1103 | // JNI Glue |
| 1104 | // ---------------------------------------------------------------------------- |
| 1105 | |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1106 | const char* const kClassPathName = "android/graphics/HardwareRenderer"; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1107 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1108 | static const JNINativeMethod gMethods[] = { |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 1109 | { "nRotateProcessStatsBuffer", "()V", (void*) android_view_ThreadedRenderer_rotateProcessStatsBuffer }, |
| 1110 | { "nSetProcessStatsBuffer", "(I)V", (void*) android_view_ThreadedRenderer_setProcessStatsBuffer }, |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 1111 | { "nGetRenderThreadTid", "(J)I", (void*) android_view_ThreadedRenderer_getRenderThreadTid }, |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 1112 | { "nCreateRootRenderNode", "()J", (void*) android_view_ThreadedRenderer_createRootRenderNode }, |
| 1113 | { "nCreateProxy", "(ZJ)J", (void*) android_view_ThreadedRenderer_createProxy }, |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 1114 | { "nDeleteProxy", "(J)V", (void*) android_view_ThreadedRenderer_deleteProxy }, |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 1115 | { "nLoadSystemProperties", "(J)Z", (void*) android_view_ThreadedRenderer_loadSystemProperties }, |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 1116 | { "nSetName", "(JLjava/lang/String;)V", (void*) android_view_ThreadedRenderer_setName }, |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1117 | { "nSetSurface", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_setSurface }, |
| 1118 | { "nPause", "(J)Z", (void*) android_view_ThreadedRenderer_pause }, |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 1119 | { "nSetStopped", "(JZ)V", (void*) android_view_ThreadedRenderer_setStopped }, |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1120 | { "nSetLightAlpha", "(JFF)V", (void*) android_view_ThreadedRenderer_setLightAlpha }, |
| 1121 | { "nSetLightGeometry", "(JFFFF)V", (void*) android_view_ThreadedRenderer_setLightGeometry }, |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 1122 | { "nSetOpaque", "(JZ)V", (void*) android_view_ThreadedRenderer_setOpaque }, |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 1123 | { "nSetWideGamut", "(JZ)V", (void*) android_view_ThreadedRenderer_setWideGamut }, |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 1124 | { "nSyncAndDrawFrame", "(J[JI)I", (void*) android_view_ThreadedRenderer_syncAndDrawFrame }, |
Doris Liu | 350e652 | 2016-02-19 14:20:37 -0800 | [diff] [blame] | 1125 | { "nDestroy", "(JJ)V", (void*) android_view_ThreadedRenderer_destroy }, |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 1126 | { "nRegisterAnimatingRenderNode", "(JJ)V", (void*) android_view_ThreadedRenderer_registerAnimatingRenderNode }, |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 1127 | { "nRegisterVectorDrawableAnimator", "(JJ)V", (void*) android_view_ThreadedRenderer_registerVectorDrawableAnimator }, |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 1128 | { "nInvokeFunctor", "(JZ)V", (void*) android_view_ThreadedRenderer_invokeFunctor }, |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 1129 | { "nCreateTextureLayer", "(J)J", (void*) android_view_ThreadedRenderer_createTextureLayer }, |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 1130 | { "nBuildLayer", "(JJ)V", (void*) android_view_ThreadedRenderer_buildLayer }, |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 1131 | { "nCopyLayerInto", "(JJLandroid/graphics/Bitmap;)Z", (void*) android_view_ThreadedRenderer_copyLayerInto }, |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 1132 | { "nPushLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_pushLayerUpdate }, |
| 1133 | { "nCancelLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_cancelLayerUpdate }, |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 1134 | { "nDetachSurfaceTexture", "(JJ)V", (void*) android_view_ThreadedRenderer_detachSurfaceTexture }, |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 1135 | { "nDestroyHardwareResources", "(J)V", (void*) android_view_ThreadedRenderer_destroyHardwareResources }, |
| 1136 | { "nTrimMemory", "(I)V", (void*) android_view_ThreadedRenderer_trimMemory }, |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 1137 | { "nOverrideProperty", "(Ljava/lang/String;Ljava/lang/String;)V", (void*) android_view_ThreadedRenderer_overrideProperty }, |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 1138 | { "nFence", "(J)V", (void*) android_view_ThreadedRenderer_fence }, |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 1139 | { "nStopDrawing", "(J)V", (void*) android_view_ThreadedRenderer_stopDrawing }, |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1140 | { "nNotifyFramePending", "(J)V", (void*) android_view_ThreadedRenderer_notifyFramePending }, |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1141 | { "nDumpProfileInfo", "(JLjava/io/FileDescriptor;I)V", (void*) android_view_ThreadedRenderer_dumpProfileInfo }, |
Stan Iliev | d495f43 | 2017-10-09 15:49:32 -0400 | [diff] [blame] | 1142 | { "setupShadersDiskCache", "(Ljava/lang/String;Ljava/lang/String;)V", |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 1143 | (void*) android_view_ThreadedRenderer_setupShadersDiskCache }, |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 1144 | { "nAddRenderNode", "(JJZ)V", (void*) android_view_ThreadedRenderer_addRenderNode}, |
| 1145 | { "nRemoveRenderNode", "(JJ)V", (void*) android_view_ThreadedRenderer_removeRenderNode}, |
| 1146 | { "nDrawRenderNode", "(JJ)V", (void*) android_view_ThreadedRendererd_drawRenderNode}, |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1147 | { "nSetContentDrawBounds", "(JIIII)V", (void*)android_view_ThreadedRenderer_setContentDrawBounds}, |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1148 | { "nSetFrameCallback", "(JLandroid/graphics/HardwareRenderer$FrameDrawingCallback;)V", |
Mihai Popa | 9568800 | 2018-02-23 16:10:11 +0000 | [diff] [blame] | 1149 | (void*)android_view_ThreadedRenderer_setFrameCallback}, |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1150 | { "nSetFrameCompleteCallback", "(JLandroid/graphics/HardwareRenderer$FrameCompleteCallback;)V", |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 1151 | (void*)android_view_ThreadedRenderer_setFrameCompleteCallback }, |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1152 | { "nAddFrameMetricsObserver", |
| 1153 | "(JLandroid/view/FrameMetricsObserver;)J", |
| 1154 | (void*)android_view_ThreadedRenderer_addFrameMetricsObserver }, |
| 1155 | { "nRemoveFrameMetricsObserver", |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 1156 | "(JJ)V", |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1157 | (void*)android_view_ThreadedRenderer_removeFrameMetricsObserver }, |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 1158 | { "nCopySurfaceInto", "(Landroid/view/Surface;IIIILandroid/graphics/Bitmap;)I", |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 1159 | (void*)android_view_ThreadedRenderer_copySurfaceInto }, |
John Reck | 1fedd91 | 2017-05-23 14:45:22 -0700 | [diff] [blame] | 1160 | { "nCreateHardwareBitmap", "(JII)Landroid/graphics/Bitmap;", |
| 1161 | (void*)android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode }, |
John Reck | a896306 | 2017-06-14 10:47:50 -0700 | [diff] [blame] | 1162 | { "disableVsync", "()V", (void*)android_view_ThreadedRenderer_disableVsync }, |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 1163 | { "nSetHighContrastText", "(Z)V", (void*)android_view_ThreadedRenderer_setHighContrastText }, |
John Reck | 9f51644 | 2017-09-25 10:27:21 -0700 | [diff] [blame] | 1164 | { "nHackySetRTAnimationsEnabled", "(Z)V", |
| 1165 | (void*)android_view_ThreadedRenderer_hackySetRTAnimationsEnabled }, |
John Reck | 6afa009 | 2018-03-01 17:28:35 -0800 | [diff] [blame] | 1166 | { "nSetDebuggingEnabled", "(Z)V", (void*)android_view_ThreadedRenderer_setDebuggingEnabled }, |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 1167 | { "nSetIsolatedProcess", "(Z)V", (void*)android_view_ThreadedRenderer_setIsolatedProcess }, |
Jorim Jaggi | 767e25e | 2018-04-04 23:07:35 +0200 | [diff] [blame] | 1168 | { "nSetContextPriority", "(I)V", (void*)android_view_ThreadedRenderer_setContextPriority }, |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1169 | { "nAllocateBuffers", "(J)V", (void*)android_view_ThreadedRenderer_allocateBuffers }, |
John Reck | bb3a358 | 2018-09-26 11:21:08 -0700 | [diff] [blame] | 1170 | { "nSetForceDark", "(JZ)V", (void*)android_view_ThreadedRenderer_setForceDark }, |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1171 | }; |
| 1172 | |
John Reck | 259b25a | 2017-12-01 16:18:53 -0800 | [diff] [blame] | 1173 | static JavaVM* mJvm = nullptr; |
| 1174 | |
| 1175 | static void attachRenderThreadToJvm() { |
| 1176 | LOG_ALWAYS_FATAL_IF(!mJvm, "No jvm but we set the hook??"); |
| 1177 | |
| 1178 | JavaVMAttachArgs args; |
| 1179 | args.version = JNI_VERSION_1_4; |
| 1180 | args.name = (char*) "RenderThread"; |
| 1181 | args.group = NULL; |
| 1182 | JNIEnv* env; |
| 1183 | mJvm->AttachCurrentThreadAsDaemon(&env, (void*) &args); |
| 1184 | } |
| 1185 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1186 | int register_android_view_ThreadedRenderer(JNIEnv* env) { |
John Reck | 259b25a | 2017-12-01 16:18:53 -0800 | [diff] [blame] | 1187 | env->GetJavaVM(&mJvm); |
| 1188 | RenderThread::setOnStartHook(&attachRenderThreadToJvm); |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 1189 | jclass observerClass = FindClassOrDie(env, "android/view/FrameMetricsObserver"); |
| 1190 | gFrameMetricsObserverClassInfo.frameMetrics = GetFieldIDOrDie( |
| 1191 | env, observerClass, "mFrameMetrics", "Landroid/view/FrameMetrics;"); |
| 1192 | gFrameMetricsObserverClassInfo.messageQueue = GetFieldIDOrDie( |
| 1193 | env, observerClass, "mMessageQueue", "Landroid/os/MessageQueue;"); |
| 1194 | gFrameMetricsObserverClassInfo.callback = GetMethodIDOrDie( |
| 1195 | env, observerClass, "notifyDataAvailable", "(I)V"); |
| 1196 | |
| 1197 | jclass metricsClass = FindClassOrDie(env, "android/view/FrameMetrics"); |
| 1198 | gFrameMetricsObserverClassInfo.timingDataBuffer = GetFieldIDOrDie( |
| 1199 | env, metricsClass, "mTimingData", "[J"); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 1200 | |
Mihai Popa | 9568800 | 2018-02-23 16:10:11 +0000 | [diff] [blame] | 1201 | jclass frameCallbackClass = FindClassOrDie(env, |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1202 | "android/graphics/HardwareRenderer$FrameDrawingCallback"); |
Mihai Popa | 9568800 | 2018-02-23 16:10:11 +0000 | [diff] [blame] | 1203 | gFrameDrawingCallback.onFrameDraw = GetMethodIDOrDie(env, frameCallbackClass, |
| 1204 | "onFrameDraw", "(J)V"); |
| 1205 | |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 1206 | jclass frameCompleteClass = FindClassOrDie(env, |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 1207 | "android/graphics/HardwareRenderer$FrameCompleteCallback"); |
John Reck | cc2eee8 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 1208 | gFrameCompleteCallback.onFrameComplete = GetMethodIDOrDie(env, frameCompleteClass, |
| 1209 | "onFrameComplete", "(J)V"); |
| 1210 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 1211 | return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | }; // namespace android |