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 | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 18 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 19 | #include <algorithm> |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 20 | #include <atomic> |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 21 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 22 | #include "jni.h" |
| 23 | #include <nativehelper/JNIHelp.h> |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 24 | #include "core_jni_helpers.h" |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 25 | #include <GraphicsJNI.h> |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 26 | #include <ScopedPrimitiveArray.h> |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 27 | |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 28 | #include <EGL/egl.h> |
| 29 | #include <EGL/eglext.h> |
| 30 | #include <EGL/egl_cache.h> |
| 31 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 32 | #include <utils/Looper.h> |
| 33 | #include <utils/RefBase.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 34 | #include <utils/StrongPointer.h> |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 35 | #include <utils/Timers.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 36 | #include <android_runtime/android_view_Surface.h> |
| 37 | #include <system/window.h> |
| 38 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 39 | #include "android_os_MessageQueue.h" |
John Reck | 66f0be6 | 2014-05-13 13:39:31 -0700 | [diff] [blame] | 40 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 41 | #include <Animator.h> |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 42 | #include <AnimationContext.h> |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 43 | #include <FrameInfo.h> |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 44 | #include <FrameMetricsObserver.h> |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 45 | #include <IContextFactory.h> |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 46 | #include <JankTracker.h> |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 47 | #include <PropertyValuesAnimatorSet.h> |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 48 | #include <RenderNode.h> |
John Reck | 66f0be6 | 2014-05-13 13:39:31 -0700 | [diff] [blame] | 49 | #include <renderthread/CanvasContext.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 50 | #include <renderthread/RenderProxy.h> |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 51 | #include <renderthread/RenderTask.h> |
| 52 | #include <renderthread/RenderThread.h> |
| 53 | |
| 54 | namespace android { |
| 55 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 56 | using namespace android::uirenderer; |
| 57 | using namespace android::uirenderer::renderthread; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 58 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 59 | struct { |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 60 | jfieldID frameMetrics; |
| 61 | jfieldID timingDataBuffer; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 62 | jfieldID messageQueue; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 63 | jmethodID callback; |
| 64 | } gFrameMetricsObserverClassInfo; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 65 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 66 | static JNIEnv* getenv(JavaVM* vm) { |
| 67 | JNIEnv* env; |
| 68 | if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
| 69 | LOG_ALWAYS_FATAL("Failed to get JNIEnv for JavaVM: %p", vm); |
| 70 | } |
| 71 | return env; |
| 72 | } |
| 73 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 74 | class OnFinishedEvent { |
| 75 | public: |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 76 | OnFinishedEvent(BaseRenderNodeAnimator* animator, AnimationListener* listener) |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 77 | : animator(animator), listener(listener) {} |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 78 | sp<BaseRenderNodeAnimator> animator; |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 79 | sp<AnimationListener> listener; |
| 80 | }; |
| 81 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 82 | class InvokeAnimationListeners : public MessageHandler { |
| 83 | public: |
Chih-Hung Hsieh | c6baf56 | 2016-04-27 11:29:23 -0700 | [diff] [blame] | 84 | explicit InvokeAnimationListeners(std::vector<OnFinishedEvent>& events) { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 85 | mOnFinishedEvents.swap(events); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 86 | } |
| 87 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 88 | static void callOnFinished(OnFinishedEvent& event) { |
| 89 | event.listener->onAnimationFinished(event.animator.get()); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | virtual void handleMessage(const Message& message) { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 93 | std::for_each(mOnFinishedEvents.begin(), mOnFinishedEvents.end(), callOnFinished); |
| 94 | mOnFinishedEvents.clear(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | private: |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 98 | std::vector<OnFinishedEvent> mOnFinishedEvents; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 101 | class FinishAndInvokeListener : public MessageHandler { |
| 102 | public: |
| 103 | explicit FinishAndInvokeListener(PropertyValuesAnimatorSet* anim) |
| 104 | : mAnimator(anim) { |
| 105 | mListener = anim->getOneShotListener(); |
| 106 | mRequestId = anim->getRequestId(); |
| 107 | } |
| 108 | |
| 109 | virtual void handleMessage(const Message& message) { |
| 110 | if (mAnimator->getRequestId() == mRequestId) { |
| 111 | // Request Id has not changed, meaning there's no animation lifecyle change since the |
| 112 | // message is posted, so go ahead and call finish to make sure the PlayState is properly |
| 113 | // updated. This is needed because before the next frame comes in from UI thread to |
| 114 | // trigger an animation update, there could be reverse/cancel etc. So we need to update |
| 115 | // the playstate in time to ensure all the subsequent events get chained properly. |
| 116 | mAnimator->end(); |
| 117 | } |
| 118 | mListener->onAnimationFinished(nullptr); |
| 119 | } |
| 120 | private: |
| 121 | sp<PropertyValuesAnimatorSet> mAnimator; |
| 122 | sp<AnimationListener> mListener; |
| 123 | uint32_t mRequestId; |
| 124 | }; |
| 125 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 126 | class RenderingException : public MessageHandler { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 127 | public: |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 128 | RenderingException(JavaVM* vm, const std::string& message) |
| 129 | : mVm(vm) |
| 130 | , mMessage(message) { |
| 131 | } |
| 132 | |
| 133 | virtual void handleMessage(const Message&) { |
| 134 | throwException(mVm, mMessage); |
| 135 | } |
| 136 | |
| 137 | static void throwException(JavaVM* vm, const std::string& message) { |
| 138 | JNIEnv* env = getenv(vm); |
| 139 | jniThrowException(env, "java/lang/IllegalStateException", message.c_str()); |
| 140 | } |
| 141 | |
| 142 | private: |
| 143 | JavaVM* mVm; |
| 144 | std::string mMessage; |
| 145 | }; |
| 146 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 147 | class RootRenderNode : public RenderNode, ErrorHandler { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 148 | public: |
Chih-Hung Hsieh | c6baf56 | 2016-04-27 11:29:23 -0700 | [diff] [blame] | 149 | explicit RootRenderNode(JNIEnv* env) : RenderNode() { |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 150 | mLooper = Looper::getForThread(); |
| 151 | LOG_ALWAYS_FATAL_IF(!mLooper.get(), |
| 152 | "Must create RootRenderNode on a thread with a looper!"); |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 153 | env->GetJavaVM(&mVm); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | virtual ~RootRenderNode() {} |
| 157 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 158 | virtual void onError(const std::string& message) override { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 159 | mLooper->sendMessage(new RenderingException(mVm, message), 0); |
| 160 | } |
| 161 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 162 | virtual void prepareTree(TreeInfo& info) override { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 163 | info.errorHandler = this; |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 164 | |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 165 | for (auto& anim : mRunningVDAnimators) { |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 166 | // Assume that the property change in VD from the animators will not be consumed. Mark |
| 167 | // otherwise if the VDs are found in the display list tree. For VDs that are not in |
| 168 | // the display list tree, we stop providing animation pulses by 1) removing them from |
| 169 | // the animation list, 2) post a delayed message to end them at end time so their |
| 170 | // listeners can receive the corresponding callbacks. |
| 171 | anim->getVectorDrawable()->setPropertyChangeWillBeConsumed(false); |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 172 | // Mark the VD dirty so it will damage itself during prepareTree. |
| 173 | anim->getVectorDrawable()->markDirty(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 174 | } |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 175 | if (info.mode == TreeInfo::MODE_FULL) { |
| 176 | for (auto &anim : mPausedVDAnimators) { |
| 177 | anim->getVectorDrawable()->setPropertyChangeWillBeConsumed(false); |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 178 | anim->getVectorDrawable()->markDirty(); |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 181 | // TODO: This is hacky |
| 182 | info.windowInsetLeft = -stagingProperties().getLeft(); |
| 183 | info.windowInsetTop = -stagingProperties().getTop(); |
| 184 | info.updateWindowPositions = true; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 185 | RenderNode::prepareTree(info); |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 186 | info.updateWindowPositions = false; |
| 187 | info.windowInsetLeft = 0; |
| 188 | info.windowInsetTop = 0; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 189 | info.errorHandler = nullptr; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 190 | } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 191 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 192 | void sendMessage(const sp<MessageHandler>& handler) { |
| 193 | mLooper->sendMessage(handler, 0); |
| 194 | } |
| 195 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 196 | void sendMessageDelayed(const sp<MessageHandler>& handler, nsecs_t delayInMs) { |
| 197 | mLooper->sendMessageDelayed(ms2ns(delayInMs), handler, 0); |
| 198 | } |
| 199 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 200 | void attachAnimatingNode(RenderNode* animatingNode) { |
| 201 | mPendingAnimatingRenderNodes.push_back(animatingNode); |
| 202 | } |
| 203 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 204 | void attachPendingVectorDrawableAnimators() { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 205 | mRunningVDAnimators.insert(mPendingVectorDrawableAnimators.begin(), |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 206 | mPendingVectorDrawableAnimators.end()); |
| 207 | mPendingVectorDrawableAnimators.clear(); |
| 208 | } |
| 209 | |
| 210 | void detachAnimators() { |
| 211 | // Remove animators from the list and post a delayed message in future to end the animator |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 212 | for (auto& anim : mRunningVDAnimators) { |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 213 | detachVectorDrawableAnimator(anim.get()); |
| 214 | } |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 215 | mRunningVDAnimators.clear(); |
| 216 | mPausedVDAnimators.clear(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Doris Liu | c82e879 | 2016-07-29 16:45:24 -0700 | [diff] [blame] | 219 | // Move all the animators to the paused list, and send a delayed message to notify the finished |
| 220 | // listener. |
| 221 | void pauseAnimators() { |
| 222 | mPausedVDAnimators.insert(mRunningVDAnimators.begin(), mRunningVDAnimators.end()); |
| 223 | for (auto& anim : mRunningVDAnimators) { |
| 224 | detachVectorDrawableAnimator(anim.get()); |
| 225 | } |
| 226 | mRunningVDAnimators.clear(); |
| 227 | } |
| 228 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 229 | void doAttachAnimatingNodes(AnimationContext* context) { |
| 230 | for (size_t i = 0; i < mPendingAnimatingRenderNodes.size(); i++) { |
| 231 | RenderNode* node = mPendingAnimatingRenderNodes[i].get(); |
| 232 | context->addAnimatingRenderNode(*node); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 233 | } |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 234 | mPendingAnimatingRenderNodes.clear(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 237 | // Run VectorDrawable animators after prepareTree. |
| 238 | void runVectorDrawableAnimators(AnimationContext* context, TreeInfo& info) { |
| 239 | // Push staging. |
| 240 | if (info.mode == TreeInfo::MODE_FULL) { |
| 241 | pushStagingVectorDrawableAnimators(context); |
| 242 | } |
| 243 | |
| 244 | // Run the animators in the running list. |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 245 | for (auto it = mRunningVDAnimators.begin(); it != mRunningVDAnimators.end();) { |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 246 | if ((*it)->animate(*context)) { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 247 | it = mRunningVDAnimators.erase(it); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 248 | } else { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 249 | it++; |
| 250 | } |
| 251 | } |
| 252 | |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 253 | // Run the animators in paused list during full sync. |
| 254 | if (info.mode == TreeInfo::MODE_FULL) { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 255 | // During full sync we also need to pulse paused animators, in case their targets |
| 256 | // have been added back to the display list. All the animators that passed the |
| 257 | // scheduled finish time will be removed from the paused list. |
| 258 | for (auto it = mPausedVDAnimators.begin(); it != mPausedVDAnimators.end();) { |
| 259 | if ((*it)->animate(*context)) { |
| 260 | // Animator has finished, remove from the list. |
| 261 | it = mPausedVDAnimators.erase(it); |
| 262 | } else { |
| 263 | it++; |
| 264 | } |
| 265 | } |
| 266 | } |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 267 | |
| 268 | // Move the animators with a target not in DisplayList to paused list. |
| 269 | for (auto it = mRunningVDAnimators.begin(); it != mRunningVDAnimators.end();) { |
| 270 | if (!(*it)->getVectorDrawable()->getPropertyChangeWillBeConsumed()) { |
| 271 | // Vector Drawable is not in the display list, we should remove this animator from |
| 272 | // the list, put it in the paused list, and post a delayed message to end the |
| 273 | // animator. |
| 274 | detachVectorDrawableAnimator(it->get()); |
| 275 | mPausedVDAnimators.insert(*it); |
| 276 | it = mRunningVDAnimators.erase(it); |
| 277 | } else { |
| 278 | it++; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // Move the animators with a target in DisplayList from paused list to running list, and |
| 283 | // trim paused list. |
| 284 | if (info.mode == TreeInfo::MODE_FULL) { |
| 285 | // Check whether any paused animator's target is back in Display List. If so, put the |
| 286 | // animator back in the running list. |
| 287 | for (auto it = mPausedVDAnimators.begin(); it != mPausedVDAnimators.end();) { |
| 288 | if ((*it)->getVectorDrawable()->getPropertyChangeWillBeConsumed()) { |
| 289 | mRunningVDAnimators.insert(*it); |
| 290 | it = mPausedVDAnimators.erase(it); |
| 291 | } else { |
| 292 | it++; |
| 293 | } |
| 294 | } |
| 295 | // Trim paused VD animators at full sync, so that when Java loses reference to an |
| 296 | // animator, we know we won't be requested to animate it any more, then we remove such |
| 297 | // animators from the paused list so they can be properly freed. We also remove the |
| 298 | // animators from paused list when the time elapsed since start has exceeded duration. |
| 299 | trimPausedVDAnimators(context); |
| 300 | } |
| 301 | |
| 302 | info.out.hasAnimations |= !mRunningVDAnimators.empty(); |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void trimPausedVDAnimators(AnimationContext* context) { |
| 306 | // Trim paused vector drawable animator list. |
| 307 | for (auto it = mPausedVDAnimators.begin(); it != mPausedVDAnimators.end();) { |
| 308 | // Remove paused VD animator if no one else is referencing it. Note that animators that |
| 309 | // have passed scheduled finish time are removed from list when they are being pulsed |
| 310 | // before prepare tree. |
| 311 | // TODO: this is a bit hacky, need to figure out a better way to track when the paused |
| 312 | // animators should be freed. |
| 313 | if ((*it)->getStrongCount() == 1) { |
| 314 | it = mPausedVDAnimators.erase(it); |
| 315 | } else { |
| 316 | it++; |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
Doris Liu | 7f2bf46 | 2016-06-21 16:06:06 -0700 | [diff] [blame] | 321 | void pushStagingVectorDrawableAnimators(AnimationContext* context) { |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 322 | for (auto& anim : mRunningVDAnimators) { |
Doris Liu | 7f2bf46 | 2016-06-21 16:06:06 -0700 | [diff] [blame] | 323 | anim->pushStaging(*context); |
| 324 | } |
| 325 | } |
| 326 | |
Doris Liu | 350e652 | 2016-02-19 14:20:37 -0800 | [diff] [blame] | 327 | void destroy() { |
| 328 | for (auto& renderNode : mPendingAnimatingRenderNodes) { |
| 329 | renderNode->animators().endAllStagingAnimators(); |
| 330 | } |
| 331 | mPendingAnimatingRenderNodes.clear(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 332 | mPendingVectorDrawableAnimators.clear(); |
| 333 | } |
| 334 | |
| 335 | void addVectorDrawableAnimator(PropertyValuesAnimatorSet* anim) { |
| 336 | mPendingVectorDrawableAnimators.insert(anim); |
Doris Liu | 350e652 | 2016-02-19 14:20:37 -0800 | [diff] [blame] | 337 | } |
| 338 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 339 | private: |
| 340 | sp<Looper> mLooper; |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 341 | JavaVM* mVm; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 342 | std::vector< sp<RenderNode> > mPendingAnimatingRenderNodes; |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 343 | std::set< sp<PropertyValuesAnimatorSet> > mPendingVectorDrawableAnimators; |
Doris Liu | 3bb5ddd | 2016-07-19 19:04:31 -0700 | [diff] [blame] | 344 | std::set< sp<PropertyValuesAnimatorSet> > mRunningVDAnimators; |
| 345 | // mPausedVDAnimators stores a list of animators that have not yet passed the finish time, but |
| 346 | // their VectorDrawable targets are no longer in the DisplayList. We skip these animators when |
| 347 | // render thread runs animators independent of UI thread (i.e. RT_ONLY mode). These animators |
| 348 | // need to be re-activated once their VD target is added back into DisplayList. Since that could |
| 349 | // only happen when we do a full sync, we need to make sure to pulse these paused animators at |
| 350 | // full sync. If any animator's VD target is found in DisplayList during a full sync, we move |
| 351 | // the animator back to the running list. |
| 352 | std::set< sp<PropertyValuesAnimatorSet> > mPausedVDAnimators; |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 353 | void detachVectorDrawableAnimator(PropertyValuesAnimatorSet* anim) { |
| 354 | if (anim->isInfinite() || !anim->isRunning()) { |
| 355 | // Do not need to post anything if the animation is infinite (i.e. no meaningful |
| 356 | // end listener action), or if the animation has already ended. |
| 357 | return; |
| 358 | } |
| 359 | nsecs_t remainingTimeInMs = anim->getRemainingPlayTime(); |
| 360 | // Post a delayed onFinished event that is scheduled to be handled when the animator ends. |
| 361 | if (anim->getOneShotListener()) { |
| 362 | // VectorDrawable's oneshot listener is updated when there are user triggered animation |
| 363 | // lifecycle changes, such as start(), end(), etc. By using checking and clearing |
| 364 | // one shot listener, we ensure the same end listener event gets posted only once. |
| 365 | // Therefore no duplicates. Another benefit of using one shot listener is that no |
| 366 | // removal is necessary: the end time of animation will not change unless triggered by |
| 367 | // user events, in which case the already posted listener's id will become stale, and |
| 368 | // the onFinished callback will then be ignored. |
| 369 | sp<FinishAndInvokeListener> message |
| 370 | = new FinishAndInvokeListener(anim); |
| 371 | sendMessageDelayed(message, remainingTimeInMs); |
| 372 | anim->clearOneShotListener(); |
| 373 | } |
| 374 | } |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | class AnimationContextBridge : public AnimationContext { |
| 378 | public: |
| 379 | AnimationContextBridge(renderthread::TimeLord& clock, RootRenderNode* rootNode) |
| 380 | : AnimationContext(clock), mRootNode(rootNode) { |
| 381 | } |
| 382 | |
| 383 | virtual ~AnimationContextBridge() {} |
| 384 | |
| 385 | // Marks the start of a frame, which will update the frame time and move all |
| 386 | // next frame animations into the current frame |
John Reck | ec845a2 | 2014-09-05 15:23:38 -0700 | [diff] [blame] | 387 | virtual void startFrame(TreeInfo::TraversalMode mode) { |
| 388 | if (mode == TreeInfo::MODE_FULL) { |
| 389 | mRootNode->doAttachAnimatingNodes(this); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 390 | mRootNode->attachPendingVectorDrawableAnimators(); |
John Reck | ec845a2 | 2014-09-05 15:23:38 -0700 | [diff] [blame] | 391 | } |
| 392 | AnimationContext::startFrame(mode); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // Runs any animations still left in mCurrentFrameAnimations |
| 396 | virtual void runRemainingAnimations(TreeInfo& info) { |
| 397 | AnimationContext::runRemainingAnimations(info); |
Doris Liu | 7c7052d | 2016-07-25 17:19:24 -0700 | [diff] [blame] | 398 | mRootNode->runVectorDrawableAnimators(this, info); |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 399 | postOnFinishedEvents(); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Doris Liu | c82e879 | 2016-07-29 16:45:24 -0700 | [diff] [blame] | 402 | virtual void pauseAnimators() override { |
| 403 | mRootNode->pauseAnimators(); |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 404 | } |
| 405 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 406 | virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) { |
| 407 | OnFinishedEvent event(animator, listener); |
| 408 | mOnFinishedEvents.push_back(event); |
| 409 | } |
| 410 | |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 411 | virtual void destroy() { |
| 412 | AnimationContext::destroy(); |
Doris Liu | c82e879 | 2016-07-29 16:45:24 -0700 | [diff] [blame] | 413 | mRootNode->detachAnimators(); |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 414 | postOnFinishedEvents(); |
| 415 | } |
| 416 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 417 | private: |
| 418 | sp<RootRenderNode> mRootNode; |
| 419 | std::vector<OnFinishedEvent> mOnFinishedEvents; |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 420 | |
| 421 | void postOnFinishedEvents() { |
| 422 | if (mOnFinishedEvents.size()) { |
| 423 | sp<InvokeAnimationListeners> message |
| 424 | = new InvokeAnimationListeners(mOnFinishedEvents); |
| 425 | mRootNode->sendMessage(message); |
| 426 | } |
| 427 | } |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 428 | }; |
| 429 | |
| 430 | class ContextFactoryImpl : public IContextFactory { |
| 431 | public: |
Chih-Hung Hsieh | c6baf56 | 2016-04-27 11:29:23 -0700 | [diff] [blame] | 432 | explicit ContextFactoryImpl(RootRenderNode* rootNode) : mRootNode(rootNode) {} |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 433 | |
| 434 | virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) { |
| 435 | return new AnimationContextBridge(clock, mRootNode); |
| 436 | } |
| 437 | |
| 438 | private: |
| 439 | RootRenderNode* mRootNode; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 440 | }; |
| 441 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 442 | class ObserverProxy; |
| 443 | |
| 444 | class NotifyHandler : public MessageHandler { |
| 445 | public: |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 446 | NotifyHandler(JavaVM* vm, ObserverProxy* observer) : mVm(vm), mObserver(observer) {} |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 447 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 448 | virtual void handleMessage(const Message& message); |
| 449 | |
| 450 | private: |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 451 | JavaVM* const mVm; |
| 452 | ObserverProxy* const mObserver; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 453 | }; |
| 454 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 455 | static jlongArray get_metrics_buffer(JNIEnv* env, jobject observer) { |
| 456 | jobject frameMetrics = env->GetObjectField( |
| 457 | observer, gFrameMetricsObserverClassInfo.frameMetrics); |
| 458 | LOG_ALWAYS_FATAL_IF(frameMetrics == nullptr, "unable to retrieve data sink object"); |
| 459 | jobject buffer = env->GetObjectField( |
| 460 | frameMetrics, gFrameMetricsObserverClassInfo.timingDataBuffer); |
| 461 | LOG_ALWAYS_FATAL_IF(buffer == nullptr, "unable to retrieve data sink buffer"); |
| 462 | return reinterpret_cast<jlongArray>(buffer); |
| 463 | } |
| 464 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 465 | /* |
| 466 | * Implements JNI layer for hwui frame metrics reporting. |
| 467 | */ |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 468 | class ObserverProxy : public FrameMetricsObserver { |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 469 | public: |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 470 | ObserverProxy(JavaVM *vm, jobject observer) : mVm(vm) { |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 471 | JNIEnv* env = getenv(mVm); |
| 472 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 473 | mObserverWeak = env->NewWeakGlobalRef(observer); |
| 474 | LOG_ALWAYS_FATAL_IF(mObserverWeak == nullptr, |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 475 | "unable to create frame stats observer reference"); |
| 476 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 477 | jlongArray buffer = get_metrics_buffer(env, observer); |
| 478 | jsize bufferSize = env->GetArrayLength(reinterpret_cast<jarray>(buffer)); |
| 479 | LOG_ALWAYS_FATAL_IF(bufferSize != kBufferSize, |
| 480 | "Mismatched Java/Native FrameMetrics data format."); |
| 481 | |
| 482 | jobject messageQueueLocal = env->GetObjectField( |
| 483 | observer, gFrameMetricsObserverClassInfo.messageQueue); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 484 | mMessageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueLocal); |
| 485 | LOG_ALWAYS_FATAL_IF(mMessageQueue == nullptr, "message queue not available"); |
| 486 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 487 | mMessageHandler = new NotifyHandler(mVm, this); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 488 | LOG_ALWAYS_FATAL_IF(mMessageHandler == nullptr, |
| 489 | "OOM: unable to allocate NotifyHandler"); |
| 490 | } |
| 491 | |
| 492 | ~ObserverProxy() { |
| 493 | JNIEnv* env = getenv(mVm); |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 494 | env->DeleteWeakGlobalRef(mObserverWeak); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 495 | } |
| 496 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 497 | jweak getObserverReference() { |
| 498 | return mObserverWeak; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 499 | } |
| 500 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 501 | bool getNextBuffer(JNIEnv* env, jlongArray sink, int* dropCount) { |
| 502 | FrameMetricsNotification& elem = mRingBuffer[mNextInQueue]; |
| 503 | |
| 504 | if (elem.hasData.load()) { |
| 505 | env->SetLongArrayRegion(sink, 0, kBufferSize, elem.buffer); |
| 506 | *dropCount = elem.dropCount; |
| 507 | mNextInQueue = (mNextInQueue + 1) % kRingSize; |
| 508 | elem.hasData = false; |
| 509 | return true; |
| 510 | } |
| 511 | |
| 512 | return false; |
| 513 | } |
| 514 | |
| 515 | virtual void notify(const int64_t* stats) { |
| 516 | FrameMetricsNotification& elem = mRingBuffer[mNextFree]; |
| 517 | |
| 518 | if (!elem.hasData.load()) { |
| 519 | memcpy(elem.buffer, stats, kBufferSize * sizeof(stats[0])); |
| 520 | |
| 521 | elem.dropCount = mDroppedReports; |
| 522 | mDroppedReports = 0; |
| 523 | |
| 524 | incStrong(nullptr); |
| 525 | mNextFree = (mNextFree + 1) % kRingSize; |
| 526 | elem.hasData = true; |
| 527 | |
| 528 | mMessageQueue->getLooper()->sendMessage(mMessageHandler, mMessage); |
| 529 | } else { |
| 530 | mDroppedReports++; |
| 531 | } |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | private: |
| 535 | static const int kBufferSize = static_cast<int>(FrameInfoIndex::NumIndexes); |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 536 | static constexpr int kRingSize = 3; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 537 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 538 | class FrameMetricsNotification { |
| 539 | public: |
| 540 | FrameMetricsNotification() : hasData(false) {} |
| 541 | |
| 542 | std::atomic_bool hasData; |
| 543 | int64_t buffer[kBufferSize]; |
| 544 | int dropCount = 0; |
| 545 | }; |
| 546 | |
| 547 | JavaVM* const mVm; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 548 | jweak mObserverWeak; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 549 | |
| 550 | sp<MessageQueue> mMessageQueue; |
| 551 | sp<NotifyHandler> mMessageHandler; |
| 552 | Message mMessage; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 553 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 554 | int mNextFree = 0; |
| 555 | int mNextInQueue = 0; |
| 556 | FrameMetricsNotification mRingBuffer[kRingSize]; |
| 557 | |
| 558 | int mDroppedReports = 0; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 559 | }; |
| 560 | |
| 561 | void NotifyHandler::handleMessage(const Message& message) { |
| 562 | JNIEnv* env = getenv(mVm); |
| 563 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 564 | jobject target = env->NewLocalRef(mObserver->getObserverReference()); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 565 | |
| 566 | if (target != nullptr) { |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 567 | jlongArray javaBuffer = get_metrics_buffer(env, target); |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 568 | int dropCount = 0; |
| 569 | while (mObserver->getNextBuffer(env, javaBuffer, &dropCount)) { |
| 570 | env->CallVoidMethod(target, gFrameMetricsObserverClassInfo.callback, dropCount); |
| 571 | } |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 572 | env->DeleteLocalRef(target); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 575 | mObserver->decStrong(nullptr); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 576 | } |
| 577 | |
Derek Sollenberger | f64c34e | 2016-06-28 16:39:13 -0400 | [diff] [blame] | 578 | static jboolean android_view_ThreadedRenderer_supportsOpenGL(JNIEnv* env, jobject clazz) { |
| 579 | char prop[PROPERTY_VALUE_MAX]; |
| 580 | if (property_get("ro.kernel.qemu", prop, NULL) == 0) { |
| 581 | // not in the emulator |
| 582 | return JNI_TRUE; |
| 583 | } |
| 584 | // In the emulator this property will be set > 0 when OpenGL ES 2.0 is |
| 585 | // enabled, 0 otherwise. On old emulator versions it will be undefined. |
| 586 | property_get("qemu.gles", prop, "0"); |
| 587 | return atoi(prop) > 0 ? JNI_TRUE : JNI_FALSE; |
| 588 | } |
| 589 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 590 | static void android_view_ThreadedRenderer_setProcessStatsBuffer(JNIEnv* env, jobject clazz, |
| 591 | jlong proxyPtr, jint fd) { |
| 592 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 593 | proxy->setProcessStatsBuffer(fd); |
| 594 | } |
| 595 | |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 596 | static jint android_view_ThreadedRenderer_getRenderThreadTid(JNIEnv* env, jobject clazz, |
| 597 | jlong proxyPtr) { |
| 598 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 599 | return proxy->getRenderThreadTid(); |
| 600 | } |
| 601 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 602 | static jlong android_view_ThreadedRenderer_createRootRenderNode(JNIEnv* env, jobject clazz) { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 603 | RootRenderNode* node = new RootRenderNode(env); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 604 | node->incStrong(0); |
| 605 | node->setName("RootRenderNode"); |
| 606 | return reinterpret_cast<jlong>(node); |
| 607 | } |
| 608 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 609 | static jlong android_view_ThreadedRenderer_createProxy(JNIEnv* env, jobject clazz, |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 610 | jboolean translucent, jlong rootRenderNodePtr) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 611 | RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootRenderNodePtr); |
| 612 | ContextFactoryImpl factory(rootRenderNode); |
| 613 | return (jlong) new RenderProxy(translucent, rootRenderNode, &factory); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static void android_view_ThreadedRenderer_deleteProxy(JNIEnv* env, jobject clazz, |
| 617 | jlong proxyPtr) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 618 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 619 | delete proxy; |
| 620 | } |
| 621 | |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 622 | static jboolean android_view_ThreadedRenderer_loadSystemProperties(JNIEnv* env, jobject clazz, |
| 623 | jlong proxyPtr) { |
| 624 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 625 | return proxy->loadSystemProperties(); |
| 626 | } |
| 627 | |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 628 | static void android_view_ThreadedRenderer_setName(JNIEnv* env, jobject clazz, |
| 629 | jlong proxyPtr, jstring jname) { |
| 630 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 631 | const char* name = env->GetStringUTFChars(jname, NULL); |
| 632 | proxy->setName(name); |
| 633 | env->ReleaseStringUTFChars(jname, name); |
| 634 | } |
| 635 | |
Thomas Buhot | 0bcd0cb | 2015-12-04 12:18:03 +0100 | [diff] [blame] | 636 | static void android_view_ThreadedRenderer_initialize(JNIEnv* env, jobject clazz, |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 637 | jlong proxyPtr, jobject jsurface) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 638 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 639 | sp<Surface> surface = android_view_Surface_getSurface(env, jsurface); |
| 640 | proxy->initialize(surface); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static void android_view_ThreadedRenderer_updateSurface(JNIEnv* env, jobject clazz, |
| 644 | jlong proxyPtr, jobject jsurface) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 645 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 646 | sp<Surface> surface; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 647 | if (jsurface) { |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 648 | surface = android_view_Surface_getSurface(env, jsurface); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 649 | } |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 650 | proxy->updateSurface(surface); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 651 | } |
| 652 | |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 653 | static jboolean android_view_ThreadedRenderer_pauseSurface(JNIEnv* env, jobject clazz, |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 654 | jlong proxyPtr, jobject jsurface) { |
| 655 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 656 | sp<Surface> surface; |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 657 | if (jsurface) { |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 658 | surface = android_view_Surface_getSurface(env, jsurface); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 659 | } |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 660 | return proxy->pauseSurface(surface); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 661 | } |
| 662 | |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 663 | static void android_view_ThreadedRenderer_setStopped(JNIEnv* env, jobject clazz, |
| 664 | jlong proxyPtr, jboolean stopped) { |
| 665 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 666 | proxy->setStopped(stopped); |
| 667 | } |
| 668 | |
Chris Craik | 797b95b | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 669 | static void android_view_ThreadedRenderer_setup(JNIEnv* env, jobject clazz, jlong proxyPtr, |
John Reck | ab1080c | 2016-06-21 16:24:20 -0700 | [diff] [blame] | 670 | jfloat lightRadius, jint ambientShadowAlpha, jint spotShadowAlpha) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 671 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | ab1080c | 2016-06-21 16:24:20 -0700 | [diff] [blame] | 672 | proxy->setup(lightRadius, ambientShadowAlpha, spotShadowAlpha); |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static void android_view_ThreadedRenderer_setLightCenter(JNIEnv* env, jobject clazz, |
| 676 | jlong proxyPtr, jfloat lightX, jfloat lightY, jfloat lightZ) { |
| 677 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 678 | proxy->setLightCenter((Vector3){lightX, lightY, lightZ}); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 679 | } |
| 680 | |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 681 | static void android_view_ThreadedRenderer_setOpaque(JNIEnv* env, jobject clazz, |
| 682 | jlong proxyPtr, jboolean opaque) { |
| 683 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 684 | proxy->setOpaque(opaque); |
| 685 | } |
| 686 | |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 687 | static int android_view_ThreadedRenderer_syncAndDrawFrame(JNIEnv* env, jobject clazz, |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 688 | jlong proxyPtr, jlongArray frameInfo, jint frameInfoSize) { |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 689 | LOG_ALWAYS_FATAL_IF(frameInfoSize != UI_THREAD_FRAME_INFO_SIZE, |
| 690 | "Mismatched size expectations, given %d expected %d", |
| 691 | frameInfoSize, UI_THREAD_FRAME_INFO_SIZE); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 692 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 693 | env->GetLongArrayRegion(frameInfo, 0, frameInfoSize, proxy->frameInfo()); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 694 | return proxy->syncAndDrawFrame(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 695 | } |
| 696 | |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 697 | static void android_view_ThreadedRenderer_destroy(JNIEnv* env, jobject clazz, |
Doris Liu | 350e652 | 2016-02-19 14:20:37 -0800 | [diff] [blame] | 698 | jlong proxyPtr, jlong rootNodePtr) { |
| 699 | RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootNodePtr); |
| 700 | rootRenderNode->destroy(); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 701 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 702 | proxy->destroy(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 703 | } |
| 704 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 705 | static void android_view_ThreadedRenderer_registerAnimatingRenderNode(JNIEnv* env, jobject clazz, |
| 706 | jlong rootNodePtr, jlong animatingNodePtr) { |
| 707 | RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootNodePtr); |
| 708 | RenderNode* animatingNode = reinterpret_cast<RenderNode*>(animatingNodePtr); |
| 709 | rootRenderNode->attachAnimatingNode(animatingNode); |
| 710 | } |
| 711 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 712 | static void android_view_ThreadedRenderer_registerVectorDrawableAnimator(JNIEnv* env, jobject clazz, |
| 713 | jlong rootNodePtr, jlong animatorPtr) { |
| 714 | RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootNodePtr); |
| 715 | PropertyValuesAnimatorSet* animator = reinterpret_cast<PropertyValuesAnimatorSet*>(animatorPtr); |
| 716 | rootRenderNode->addVectorDrawableAnimator(animator); |
| 717 | } |
| 718 | |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 719 | static void android_view_ThreadedRenderer_invokeFunctor(JNIEnv* env, jobject clazz, |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 720 | jlong functorPtr, jboolean waitForCompletion) { |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 721 | Functor* functor = reinterpret_cast<Functor*>(functorPtr); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 722 | RenderProxy::invokeFunctor(functor, waitForCompletion); |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 723 | } |
| 724 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 725 | static jlong android_view_ThreadedRenderer_createTextureLayer(JNIEnv* env, jobject clazz, |
| 726 | jlong proxyPtr) { |
| 727 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 728 | DeferredLayerUpdater* layer = proxy->createTextureLayer(); |
| 729 | return reinterpret_cast<jlong>(layer); |
| 730 | } |
| 731 | |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 732 | static void android_view_ThreadedRenderer_buildLayer(JNIEnv* env, jobject clazz, |
| 733 | jlong proxyPtr, jlong nodePtr) { |
| 734 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 735 | RenderNode* node = reinterpret_cast<RenderNode*>(nodePtr); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 736 | proxy->buildLayer(node); |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 737 | } |
| 738 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 739 | static jboolean android_view_ThreadedRenderer_copyLayerInto(JNIEnv* env, jobject clazz, |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 740 | jlong proxyPtr, jlong layerPtr, jobject jbitmap) { |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 741 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 742 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 743 | SkBitmap bitmap; |
| 744 | GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 745 | return proxy->copyLayerInto(layer, bitmap); |
| 746 | } |
| 747 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 748 | static void android_view_ThreadedRenderer_pushLayerUpdate(JNIEnv* env, jobject clazz, |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 749 | jlong proxyPtr, jlong layerPtr) { |
| 750 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 751 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 752 | proxy->pushLayerUpdate(layer); |
| 753 | } |
| 754 | |
| 755 | static void android_view_ThreadedRenderer_cancelLayerUpdate(JNIEnv* env, jobject clazz, |
| 756 | jlong proxyPtr, jlong layerPtr) { |
| 757 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 758 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
| 759 | proxy->cancelLayerUpdate(layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 760 | } |
| 761 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 762 | static void android_view_ThreadedRenderer_detachSurfaceTexture(JNIEnv* env, jobject clazz, |
| 763 | jlong proxyPtr, jlong layerPtr) { |
| 764 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 765 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
| 766 | proxy->detachSurfaceTexture(layer); |
| 767 | } |
| 768 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 769 | static void android_view_ThreadedRenderer_destroyHardwareResources(JNIEnv* env, jobject clazz, |
| 770 | jlong proxyPtr) { |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 771 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 772 | proxy->destroyHardwareResources(); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | static void android_view_ThreadedRenderer_trimMemory(JNIEnv* env, jobject clazz, |
| 776 | jint level) { |
| 777 | RenderProxy::trimMemory(level); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 780 | static void android_view_ThreadedRenderer_overrideProperty(JNIEnv* env, jobject clazz, |
| 781 | jstring name, jstring value) { |
| 782 | const char* nameCharArray = env->GetStringUTFChars(name, NULL); |
| 783 | const char* valueCharArray = env->GetStringUTFChars(value, NULL); |
| 784 | RenderProxy::overrideProperty(nameCharArray, valueCharArray); |
| 785 | env->ReleaseStringUTFChars(name, nameCharArray); |
| 786 | env->ReleaseStringUTFChars(name, valueCharArray); |
| 787 | } |
| 788 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 789 | static void android_view_ThreadedRenderer_fence(JNIEnv* env, jobject clazz, |
| 790 | jlong proxyPtr) { |
| 791 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 792 | proxy->fence(); |
| 793 | } |
| 794 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 795 | static void android_view_ThreadedRenderer_stopDrawing(JNIEnv* env, jobject clazz, |
| 796 | jlong proxyPtr) { |
| 797 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 798 | proxy->stopDrawing(); |
| 799 | } |
| 800 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 801 | static void android_view_ThreadedRenderer_notifyFramePending(JNIEnv* env, jobject clazz, |
| 802 | jlong proxyPtr) { |
| 803 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 804 | proxy->notifyFramePending(); |
| 805 | } |
| 806 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 807 | static void android_view_ThreadedRenderer_serializeDisplayListTree(JNIEnv* env, jobject clazz, |
| 808 | jlong proxyPtr) { |
| 809 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 810 | proxy->serializeDisplayListTree(); |
| 811 | } |
| 812 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 813 | static void android_view_ThreadedRenderer_dumpProfileInfo(JNIEnv* env, jobject clazz, |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 814 | jlong proxyPtr, jobject javaFileDescriptor, jint dumpFlags) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 815 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 816 | int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 817 | proxy->dumpProfileInfo(fd, dumpFlags); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 818 | } |
| 819 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 820 | static void android_view_ThreadedRenderer_dumpProfileData(JNIEnv* env, jobject clazz, |
| 821 | jbyteArray jdata, jobject javaFileDescriptor) { |
| 822 | int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); |
| 823 | ScopedByteArrayRO buffer(env, jdata); |
| 824 | if (buffer.get()) { |
| 825 | JankTracker::dumpBuffer(buffer.get(), buffer.size(), fd); |
| 826 | } |
| 827 | } |
| 828 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 829 | static void android_view_ThreadedRenderer_addRenderNode(JNIEnv* env, jobject clazz, |
| 830 | jlong proxyPtr, jlong renderNodePtr, jboolean placeFront) { |
| 831 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 832 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 833 | proxy->addRenderNode(renderNode, placeFront); |
| 834 | } |
| 835 | |
| 836 | static void android_view_ThreadedRenderer_removeRenderNode(JNIEnv* env, jobject clazz, |
| 837 | jlong proxyPtr, jlong renderNodePtr) { |
| 838 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 839 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 840 | proxy->removeRenderNode(renderNode); |
| 841 | } |
| 842 | |
| 843 | static void android_view_ThreadedRendererd_drawRenderNode(JNIEnv* env, jobject clazz, |
| 844 | jlong proxyPtr, jlong renderNodePtr) { |
| 845 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
| 846 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 847 | proxy->drawRenderNode(renderNode); |
| 848 | } |
| 849 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 850 | static void android_view_ThreadedRenderer_setContentDrawBounds(JNIEnv* env, |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 851 | jobject clazz, jlong proxyPtr, jint left, jint top, jint right, jint bottom) { |
| 852 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 853 | proxy->setContentDrawBounds(left, top, right, bottom); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 854 | } |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 855 | |
John Reck | e94cbc7 | 2016-04-25 13:03:44 -0700 | [diff] [blame] | 856 | static jint android_view_ThreadedRenderer_copySurfaceInto(JNIEnv* env, |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 857 | jobject clazz, jobject jsurface, jint left, jint top, |
| 858 | jint right, jint bottom, jobject jbitmap) { |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 859 | SkBitmap bitmap; |
| 860 | GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); |
| 861 | sp<Surface> surface = android_view_Surface_getSurface(env, jsurface); |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 862 | return RenderProxy::copySurfaceInto(surface, left, top, right, bottom, &bitmap); |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 863 | } |
| 864 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 865 | // ---------------------------------------------------------------------------- |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 866 | // FrameMetricsObserver |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 867 | // ---------------------------------------------------------------------------- |
| 868 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 869 | static jlong android_view_ThreadedRenderer_addFrameMetricsObserver(JNIEnv* env, |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 870 | jclass clazz, jlong proxyPtr, jobject fso) { |
| 871 | JavaVM* vm = nullptr; |
| 872 | if (env->GetJavaVM(&vm) != JNI_OK) { |
| 873 | LOG_ALWAYS_FATAL("Unable to get Java VM"); |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | renderthread::RenderProxy* renderProxy = |
| 878 | reinterpret_cast<renderthread::RenderProxy*>(proxyPtr); |
| 879 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 880 | FrameMetricsObserver* observer = new ObserverProxy(vm, fso); |
| 881 | renderProxy->addFrameMetricsObserver(observer); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 882 | return reinterpret_cast<jlong>(observer); |
| 883 | } |
| 884 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 885 | static void android_view_ThreadedRenderer_removeFrameMetricsObserver(JNIEnv* env, jclass clazz, |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 886 | jlong proxyPtr, jlong observerPtr) { |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 887 | FrameMetricsObserver* observer = reinterpret_cast<FrameMetricsObserver*>(observerPtr); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 888 | renderthread::RenderProxy* renderProxy = |
| 889 | reinterpret_cast<renderthread::RenderProxy*>(proxyPtr); |
| 890 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 891 | renderProxy->removeFrameMetricsObserver(observer); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | // ---------------------------------------------------------------------------- |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 895 | // Shaders |
| 896 | // ---------------------------------------------------------------------------- |
| 897 | |
| 898 | static void android_view_ThreadedRenderer_setupShadersDiskCache(JNIEnv* env, jobject clazz, |
| 899 | jstring diskCachePath) { |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 900 | const char* cacheArray = env->GetStringUTFChars(diskCachePath, NULL); |
| 901 | egl_cache_t::get()->setCacheFilename(cacheArray); |
| 902 | env->ReleaseStringUTFChars(diskCachePath, cacheArray); |
| 903 | } |
| 904 | |
| 905 | // ---------------------------------------------------------------------------- |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 906 | // JNI Glue |
| 907 | // ---------------------------------------------------------------------------- |
| 908 | |
| 909 | const char* const kClassPathName = "android/view/ThreadedRenderer"; |
| 910 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 911 | static const JNINativeMethod gMethods[] = { |
John Reck | 6ccb38b | 2016-10-03 15:51:08 -0700 | [diff] [blame] | 912 | { "nSupportsOpenGL", "()Z", (void*) android_view_ThreadedRenderer_supportsOpenGL }, |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 913 | { "nSetProcessStatsBuffer", "(JI)V", (void*) android_view_ThreadedRenderer_setProcessStatsBuffer }, |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 914 | { "nGetRenderThreadTid", "(J)I", (void*) android_view_ThreadedRenderer_getRenderThreadTid }, |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 915 | { "nCreateRootRenderNode", "()J", (void*) android_view_ThreadedRenderer_createRootRenderNode }, |
| 916 | { "nCreateProxy", "(ZJ)J", (void*) android_view_ThreadedRenderer_createProxy }, |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 917 | { "nDeleteProxy", "(J)V", (void*) android_view_ThreadedRenderer_deleteProxy }, |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 918 | { "nLoadSystemProperties", "(J)Z", (void*) android_view_ThreadedRenderer_loadSystemProperties }, |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 919 | { "nSetName", "(JLjava/lang/String;)V", (void*) android_view_ThreadedRenderer_setName }, |
Thomas Buhot | 0bcd0cb | 2015-12-04 12:18:03 +0100 | [diff] [blame] | 920 | { "nInitialize", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_initialize }, |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 921 | { "nUpdateSurface", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_updateSurface }, |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 922 | { "nPauseSurface", "(JLandroid/view/Surface;)Z", (void*) android_view_ThreadedRenderer_pauseSurface }, |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 923 | { "nSetStopped", "(JZ)V", (void*) android_view_ThreadedRenderer_setStopped }, |
John Reck | ab1080c | 2016-06-21 16:24:20 -0700 | [diff] [blame] | 924 | { "nSetup", "(JFII)V", (void*) android_view_ThreadedRenderer_setup }, |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 925 | { "nSetLightCenter", "(JFFF)V", (void*) android_view_ThreadedRenderer_setLightCenter }, |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 926 | { "nSetOpaque", "(JZ)V", (void*) android_view_ThreadedRenderer_setOpaque }, |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 927 | { "nSyncAndDrawFrame", "(J[JI)I", (void*) android_view_ThreadedRenderer_syncAndDrawFrame }, |
Doris Liu | 350e652 | 2016-02-19 14:20:37 -0800 | [diff] [blame] | 928 | { "nDestroy", "(JJ)V", (void*) android_view_ThreadedRenderer_destroy }, |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 929 | { "nRegisterAnimatingRenderNode", "(JJ)V", (void*) android_view_ThreadedRenderer_registerAnimatingRenderNode }, |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 930 | { "nRegisterVectorDrawableAnimator", "(JJ)V", (void*) android_view_ThreadedRenderer_registerVectorDrawableAnimator }, |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 931 | { "nInvokeFunctor", "(JZ)V", (void*) android_view_ThreadedRenderer_invokeFunctor }, |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 932 | { "nCreateTextureLayer", "(J)J", (void*) android_view_ThreadedRenderer_createTextureLayer }, |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 933 | { "nBuildLayer", "(JJ)V", (void*) android_view_ThreadedRenderer_buildLayer }, |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 934 | { "nCopyLayerInto", "(JJLandroid/graphics/Bitmap;)Z", (void*) android_view_ThreadedRenderer_copyLayerInto }, |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 935 | { "nPushLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_pushLayerUpdate }, |
| 936 | { "nCancelLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_cancelLayerUpdate }, |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 937 | { "nDetachSurfaceTexture", "(JJ)V", (void*) android_view_ThreadedRenderer_detachSurfaceTexture }, |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 938 | { "nDestroyHardwareResources", "(J)V", (void*) android_view_ThreadedRenderer_destroyHardwareResources }, |
| 939 | { "nTrimMemory", "(I)V", (void*) android_view_ThreadedRenderer_trimMemory }, |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 940 | { "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] | 941 | { "nFence", "(J)V", (void*) android_view_ThreadedRenderer_fence }, |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 942 | { "nStopDrawing", "(J)V", (void*) android_view_ThreadedRenderer_stopDrawing }, |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 943 | { "nNotifyFramePending", "(J)V", (void*) android_view_ThreadedRenderer_notifyFramePending }, |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 944 | { "nSerializeDisplayListTree", "(J)V", (void*) android_view_ThreadedRenderer_serializeDisplayListTree }, |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 945 | { "nDumpProfileInfo", "(JLjava/io/FileDescriptor;I)V", (void*) android_view_ThreadedRenderer_dumpProfileInfo }, |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 946 | { "nDumpProfileData", "([BLjava/io/FileDescriptor;)V", (void*) android_view_ThreadedRenderer_dumpProfileData }, |
John Reck | 84a4c88 | 2014-05-30 14:34:03 -0700 | [diff] [blame] | 947 | { "setupShadersDiskCache", "(Ljava/lang/String;)V", |
| 948 | (void*) android_view_ThreadedRenderer_setupShadersDiskCache }, |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 949 | { "nAddRenderNode", "(JJZ)V", (void*) android_view_ThreadedRenderer_addRenderNode}, |
| 950 | { "nRemoveRenderNode", "(JJ)V", (void*) android_view_ThreadedRenderer_removeRenderNode}, |
| 951 | { "nDrawRenderNode", "(JJ)V", (void*) android_view_ThreadedRendererd_drawRenderNode}, |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 952 | { "nSetContentDrawBounds", "(JIIII)V", (void*)android_view_ThreadedRenderer_setContentDrawBounds}, |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 953 | { "nAddFrameMetricsObserver", |
| 954 | "(JLandroid/view/FrameMetricsObserver;)J", |
| 955 | (void*)android_view_ThreadedRenderer_addFrameMetricsObserver }, |
| 956 | { "nRemoveFrameMetricsObserver", |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 957 | "(JJ)V", |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 958 | (void*)android_view_ThreadedRenderer_removeFrameMetricsObserver }, |
John Reck | 9580146 | 2016-09-01 09:44:09 -0700 | [diff] [blame] | 959 | { "nCopySurfaceInto", "(Landroid/view/Surface;IIIILandroid/graphics/Bitmap;)I", |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 960 | (void*)android_view_ThreadedRenderer_copySurfaceInto }, |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 961 | }; |
| 962 | |
| 963 | int register_android_view_ThreadedRenderer(JNIEnv* env) { |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 964 | jclass observerClass = FindClassOrDie(env, "android/view/FrameMetricsObserver"); |
| 965 | gFrameMetricsObserverClassInfo.frameMetrics = GetFieldIDOrDie( |
| 966 | env, observerClass, "mFrameMetrics", "Landroid/view/FrameMetrics;"); |
| 967 | gFrameMetricsObserverClassInfo.messageQueue = GetFieldIDOrDie( |
| 968 | env, observerClass, "mMessageQueue", "Landroid/os/MessageQueue;"); |
| 969 | gFrameMetricsObserverClassInfo.callback = GetMethodIDOrDie( |
| 970 | env, observerClass, "notifyDataAvailable", "(I)V"); |
| 971 | |
| 972 | jclass metricsClass = FindClassOrDie(env, "android/view/FrameMetrics"); |
| 973 | gFrameMetricsObserverClassInfo.timingDataBuffer = GetFieldIDOrDie( |
| 974 | env, metricsClass, "mTimingData", "[J"); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 975 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 976 | return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | }; // namespace android |