1a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian/*
2a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * Copyright (C) 2010 The Android Open Source Project
3a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian *
4a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * you may not use this file except in compliance with the License.
6a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * You may obtain a copy of the License at
7a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian *
8a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian *
10a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * Unless required by applicable law or agreed to in writing, software
11a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * See the License for the specific language governing permissions and
14a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian * limitations under the License.
15a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian */
16edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
179414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian#if defined(HAVE_PTHREADS)
189414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian#include <sys/resource.h>
199414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian#endif
209414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian
219414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian#include <cutils/sched_policy.h>
224f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian#include <binder/IServiceManager.h>
234f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian#include <binder/IPCThreadState.h>
244f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian#include <binder/ProcessState.h>
254f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian#include <binder/IServiceManager.h>
267ffaa7c60d51cc0eb731158de2ac3df9c50cc0b4Mathias Agopian#include "SurfaceFlinger.h"
27edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
28edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectusing namespace android;
29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
30c751e92c56de5f335a36e68607c7a6c627dcd0dcAndy McFaddenint main(int, char**) {
3164a1e08b86d72cb375f9dfdf4eb6307f71817350Mathias Agopian    // When SF is launched in its own process, limit the number of
3264a1e08b86d72cb375f9dfdf4eb6307f71817350Mathias Agopian    // binder threads to 4.
3364a1e08b86d72cb375f9dfdf4eb6307f71817350Mathias Agopian    ProcessState::self()->setThreadPoolMaxThreadCount(4);
344f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian
359414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian    // start the thread pool
369414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian    sp<ProcessState> ps(ProcessState::self());
379414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian    ps->startThreadPool();
389414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian
394f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    // instantiate surfaceflinger
404f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    sp<SurfaceFlinger> flinger = new SurfaceFlinger();
414f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian
429414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian#if defined(HAVE_PTHREADS)
439414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian    setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);
449414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian#endif
459414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian    set_sched_policy(0, SP_FOREGROUND);
469414d67f46d315873502b909ee51bab7abf3f9ccMathias Agopian
474f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    // initialize before clients can connect
484f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    flinger->init();
494f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian
504f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    // publish surface flinger
514f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    sp<IServiceManager> sm(defaultServiceManager());
524f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false);
534f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian
544f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    // run in this thread
554f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian    flinger->run();
564f4f0943489d9113c66ac22b58cfba8c21dfa879Mathias Agopian
57a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian    return 0;
58edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
59