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