1 /*
2  * Copyright (C) 2018 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 #include "AnimatedImageThread.h"
18 
19 #ifdef __ANDROID__
20 #include <sys/resource.h>
21 #endif
22 
23 namespace android {
24 namespace uirenderer {
25 
getInstance()26 AnimatedImageThread& AnimatedImageThread::getInstance() {
27     static sp<AnimatedImageThread> sInstance = []() {
28         sp<AnimatedImageThread> thread = sp<AnimatedImageThread>::make();
29         thread->start("AnimatedImageThread");
30         return thread;
31     }();
32     return *sInstance;
33 }
34 
AnimatedImageThread()35 AnimatedImageThread::AnimatedImageThread() {
36 #ifdef __ANDROID__
37     setpriority(PRIO_PROCESS, 0, PRIORITY_NORMAL + PRIORITY_MORE_FAVORABLE);
38 #endif
39 }
40 
decodeNextFrame(const sk_sp<AnimatedImageDrawable> & drawable)41 std::future<AnimatedImageDrawable::Snapshot> AnimatedImageThread::decodeNextFrame(
42         const sk_sp<AnimatedImageDrawable>& drawable) {
43     return queue().async([drawable]() { return drawable->decodeNextFrame(); });
44 }
45 
reset(const sk_sp<AnimatedImageDrawable> & drawable)46 std::future<AnimatedImageDrawable::Snapshot> AnimatedImageThread::reset(
47         const sk_sp<AnimatedImageDrawable>& drawable) {
48     return queue().async([drawable]() { return drawable->reset(); });
49 }
50 
51 }  // namespace uirenderer
52 }  // namespace android
53