Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc4bd823 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I5d41419a,I763be06c into oc-dev

* changes:
  Introduce android.anim thread in system_server
  Fix thread booster
parents e467be5e ed7993b5
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -31,7 +31,7 @@ public class SurfaceFlingerVsyncChoreographer {
    private static final long ONE_S_IN_NS = ONE_MS_IN_NS * 1000;
    private static final long ONE_S_IN_NS = ONE_MS_IN_NS * 1000;


    private final Handler mHandler;
    private final Handler mHandler;
    private final Choreographer mChoreographer = Choreographer.getInstance();
    private final Choreographer mChoreographer;


    /**
    /**
     * The offset between vsync-app and vsync-surfaceflinger. See
     * The offset between vsync-app and vsync-surfaceflinger. See
@@ -39,8 +39,10 @@ public class SurfaceFlingerVsyncChoreographer {
     */
     */
    private long mSurfaceFlingerOffsetMs;
    private long mSurfaceFlingerOffsetMs;


    public SurfaceFlingerVsyncChoreographer(Handler handler, Display display) {
    public SurfaceFlingerVsyncChoreographer(Handler handler, Display display,
            Choreographer choreographer) {
        mHandler = handler;
        mHandler = handler;
        mChoreographer = choreographer;
        mSurfaceFlingerOffsetMs = calculateAppSurfaceFlingerVsyncOffsetMs(display);
        mSurfaceFlingerOffsetMs = calculateAppSurfaceFlingerVsyncOffsetMs(display);
    }
    }


+3 −1
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.Choreographer;
import android.view.Display;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.DisplayInfo;
import android.view.GestureDetector;
import android.view.GestureDetector;
@@ -312,7 +313,8 @@ public class DividerView extends FrameLayout implements OnTouchListener,
    protected void onAttachedToWindow() {
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        super.onAttachedToWindow();
        EventBus.getDefault().register(this);
        EventBus.getDefault().register(this);
        mSfChoreographer = new SurfaceFlingerVsyncChoreographer(mHandler, getDisplay());
        mSfChoreographer = new SurfaceFlingerVsyncChoreographer(mHandler, getDisplay(),
                Choreographer.getInstance());
    }
    }


    @Override
    @Override
+58 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.server;

import static android.os.Process.THREAD_PRIORITY_DISPLAY;

import android.os.Handler;
import android.os.Trace;

/**
 * Thread for handling all window animations, or anything that's directly impacting animations like
 * starting windows or traversals.
 */
public final class AnimationThread extends ServiceThread {
    private static AnimationThread sInstance;
    private static Handler sHandler;

    private AnimationThread() {
        super("android.anim", THREAD_PRIORITY_DISPLAY, false /*allowIo*/);
    }

    private static void ensureThreadLocked() {
        if (sInstance == null) {
            sInstance = new AnimationThread();
            sInstance.start();
            sInstance.getLooper().setTraceTag(Trace.TRACE_TAG_WINDOW_MANAGER);
            sHandler = new Handler(sInstance.getLooper());
        }
    }

    public static AnimationThread get() {
        synchronized (AnimationThread.class) {
            ensureThreadLocked();
            return sInstance;
        }
    }

    public static Handler getHandler() {
        synchronized (AnimationThread.class) {
            ensureThreadLocked();
            return sHandler;
        }
    }
}
+4 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server;
package com.android.server;


import android.os.Handler;
import android.os.Handler;
import android.os.Process;
import android.os.Trace;
import android.os.Trace;


/**
/**
@@ -30,7 +31,9 @@ public final class DisplayThread extends ServiceThread {
    private static Handler sHandler;
    private static Handler sHandler;


    private DisplayThread() {
    private DisplayThread() {
        super("android.display", android.os.Process.THREAD_PRIORITY_DISPLAY, false /*allowIo*/);
        // DisplayThread runs important stuff, but these are not as important as things running in
        // AnimationThread. Thus, set the priority to one lower.
        super("android.display", Process.THREAD_PRIORITY_DISPLAY + 1, false /*allowIo*/);
    }
    }


    private static void ensureThreadLocked() {
    private static void ensureThreadLocked() {
+1 −1
Original line number Original line Diff line number Diff line
@@ -41,8 +41,8 @@ public class ThreadPriorityBooster {
        final int tid = Process.myTid();
        final int tid = Process.myTid();
        final int prevPriority = Process.getThreadPriority(tid);
        final int prevPriority = Process.getThreadPriority(tid);
        PriorityState state = mThreadState.get();
        PriorityState state = mThreadState.get();
        if (state.regionCounter == 0 && prevPriority > mBoostToPriority) {
        state.prevPriority = prevPriority;
        state.prevPriority = prevPriority;
        if (state.regionCounter == 0 && prevPriority > mBoostToPriority) {
            Process.setThreadPriority(tid, mBoostToPriority);
            Process.setThreadPriority(tid, mBoostToPriority);
        }
        }
        state.regionCounter++;
        state.regionCounter++;
Loading